Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / common / gpu / gpu_command_buffer_stub.h
blob7414b26d6ebb5e4689e02436f763febec5f24e96
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_
6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_
8 #include <deque>
9 #include <string>
10 #include <vector>
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "content/common/content_export.h"
16 #include "content/common/gpu/gpu_memory_allocation.h"
17 #include "content/common/gpu/gpu_memory_manager.h"
18 #include "content/common/gpu/gpu_memory_manager_client.h"
19 #include "gpu/command_buffer/common/constants.h"
20 #include "gpu/command_buffer/service/command_buffer_service.h"
21 #include "gpu/command_buffer/service/context_group.h"
22 #include "gpu/command_buffer/service/gpu_scheduler.h"
23 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_sender.h"
25 #include "media/base/video_decoder_config.h"
26 #include "ui/events/latency_info.h"
27 #include "ui/gfx/native_widget_types.h"
28 #include "ui/gfx/size.h"
29 #include "ui/gl/gl_surface.h"
30 #include "ui/gl/gpu_preference.h"
31 #include "url/gurl.h"
33 namespace gpu {
34 struct Mailbox;
35 namespace gles2 {
36 class ImageManager;
37 class MailboxManager;
41 namespace content {
43 class GpuChannel;
44 class GpuVideoDecodeAccelerator;
45 class GpuWatchdog;
47 class GpuCommandBufferStub
48 : public GpuMemoryManagerClient,
49 public IPC::Listener,
50 public IPC::Sender,
51 public base::SupportsWeakPtr<GpuCommandBufferStub> {
52 public:
53 class DestructionObserver {
54 public:
55 // Called in Destroy(), before the context/surface are released.
56 virtual void OnWillDestroyStub() = 0;
58 protected:
59 virtual ~DestructionObserver() {}
62 typedef base::Callback<void(const ui::LatencyInfo&)>
63 LatencyInfoCallback;
65 GpuCommandBufferStub(
66 GpuChannel* channel,
67 GpuCommandBufferStub* share_group,
68 const gfx::GLSurfaceHandle& handle,
69 gpu::gles2::MailboxManager* mailbox_manager,
70 gpu::gles2::ImageManager* image_manager,
71 const gfx::Size& size,
72 const gpu::gles2::DisallowedFeatures& disallowed_features,
73 const std::vector<int32>& attribs,
74 gfx::GpuPreference gpu_preference,
75 bool use_virtualized_gl_context,
76 int32 route_id,
77 int32 surface_id,
78 GpuWatchdog* watchdog,
79 bool software,
80 const GURL& active_url);
82 virtual ~GpuCommandBufferStub();
84 // IPC::Listener implementation:
85 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
87 // IPC::Sender implementation:
88 virtual bool Send(IPC::Message* msg) OVERRIDE;
90 // GpuMemoryManagerClient implementation:
91 virtual gfx::Size GetSurfaceSize() const OVERRIDE;
92 virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const OVERRIDE;
93 virtual void SetMemoryAllocation(
94 const GpuMemoryAllocation& allocation) OVERRIDE;
95 virtual bool GetTotalGpuMemory(uint64* bytes) OVERRIDE;
97 // Whether this command buffer can currently handle IPC messages.
98 bool IsScheduled();
100 // If the command buffer is pre-empted and cannot process commands.
101 bool IsPreempted() const {
102 return scheduler_.get() && scheduler_->IsPreempted();
105 // Whether there are commands in the buffer that haven't been processed.
106 bool HasUnprocessedCommands();
108 gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); }
109 gpu::GpuScheduler* scheduler() const { return scheduler_.get(); }
110 GpuChannel* channel() const { return channel_; }
112 // Identifies the target surface.
113 int32 surface_id() const { return surface_id_; }
115 // Identifies the various GpuCommandBufferStubs in the GPU process belonging
116 // to the same renderer process.
117 int32 route_id() const { return route_id_; }
119 gfx::GpuPreference gpu_preference() { return gpu_preference_; }
121 // Sends a message to the console.
122 void SendConsoleMessage(int32 id, const std::string& message);
124 void SendCachedShader(const std::string& key, const std::string& shader);
126 gfx::GLSurface* surface() const { return surface_.get(); }
128 void AddDestructionObserver(DestructionObserver* observer);
129 void RemoveDestructionObserver(DestructionObserver* observer);
131 // Associates a sync point to this stub. When the stub is destroyed, it will
132 // retire all sync points that haven't been previously retired.
133 void AddSyncPoint(uint32 sync_point);
135 void SetPreemptByFlag(scoped_refptr<gpu::PreemptionFlag> flag);
137 void SetLatencyInfoCallback(const LatencyInfoCallback& callback);
139 void MarkContextLost();
141 private:
142 GpuMemoryManager* GetMemoryManager();
143 bool MakeCurrent();
144 void Destroy();
146 // Cleans up and sends reply if OnInitialize failed.
147 void OnInitializeFailed(IPC::Message* reply_message);
149 // Message handlers:
150 void OnInitialize(base::SharedMemoryHandle shared_state_shm,
151 IPC::Message* reply_message);
152 void OnSetGetBuffer(int32 shm_id, IPC::Message* reply_message);
153 void OnProduceFrontBuffer(const gpu::Mailbox& mailbox);
154 void OnGetState(IPC::Message* reply_message);
155 void OnGetStateFast(IPC::Message* reply_message);
156 void OnAsyncFlush(int32 put_offset, uint32 flush_count);
157 void OnEcho(const IPC::Message& message);
158 void OnRescheduled();
159 void OnRegisterTransferBuffer(int32 id,
160 base::SharedMemoryHandle transfer_buffer,
161 uint32 size);
162 void OnDestroyTransferBuffer(int32 id);
163 void OnGetTransferBuffer(int32 id, IPC::Message* reply_message);
165 void OnCreateVideoDecoder(
166 media::VideoCodecProfile profile,
167 IPC::Message* reply_message);
169 void OnCreateSurfaceCapturer(IPC::Message* reply_message);
171 void OnSetSurfaceVisible(bool visible);
173 void OnDiscardBackbuffer();
174 void OnEnsureBackbuffer();
176 void OnRetireSyncPoint(uint32 sync_point);
177 bool OnWaitSyncPoint(uint32 sync_point);
178 void OnSyncPointRetired();
179 void OnSignalSyncPoint(uint32 sync_point, uint32 id);
180 void OnSignalSyncPointAck(uint32 id);
181 void OnSignalQuery(uint32 query, uint32 id);
183 void OnReceivedClientManagedMemoryStats(const GpuManagedMemoryStats& stats);
184 void OnSetClientHasMemoryAllocationChangedCallback(bool has_callback);
186 void OnCommandProcessed();
187 void OnParseError();
188 void OnSetLatencyInfo(const ui::LatencyInfo& latency_info);
190 void ReportState();
192 // Wrapper for GpuScheduler::PutChanged that sets the crash report URL.
193 void PutChanged();
195 // Poll the command buffer to execute work.
196 void PollWork();
198 // Whether this command buffer needs to be polled again in the future.
199 bool HasMoreWork();
201 void ScheduleDelayedWork(int64 delay);
203 bool CheckContextLost();
205 // The lifetime of objects of this class is managed by a GpuChannel. The
206 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they
207 // are destroyed. So a raw pointer is safe.
208 GpuChannel* channel_;
210 // The group of contexts that share namespaces with this context.
211 scoped_refptr<gpu::gles2::ContextGroup> context_group_;
213 gfx::GLSurfaceHandle handle_;
214 gfx::Size initial_size_;
215 gpu::gles2::DisallowedFeatures disallowed_features_;
216 std::vector<int32> requested_attribs_;
217 gfx::GpuPreference gpu_preference_;
218 bool use_virtualized_gl_context_;
219 int32 route_id_;
220 int32 surface_id_;
221 bool software_;
222 uint32 last_flush_count_;
224 scoped_ptr<gpu::CommandBufferService> command_buffer_;
225 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_;
226 scoped_ptr<gpu::GpuScheduler> scheduler_;
227 scoped_refptr<gfx::GLSurface> surface_;
229 scoped_ptr<GpuMemoryManagerClientState> memory_manager_client_state_;
230 // The last memory allocation received from the GpuMemoryManager (used to
231 // elide redundant work).
232 bool last_memory_allocation_valid_;
233 GpuMemoryAllocation last_memory_allocation_;
235 GpuWatchdog* watchdog_;
237 ObserverList<DestructionObserver> destruction_observers_;
239 // A queue of sync points associated with this stub.
240 std::deque<uint32> sync_points_;
241 int sync_point_wait_count_;
243 bool delayed_work_scheduled_;
244 uint64 previous_messages_processed_;
245 base::TimeTicks last_idle_time_;
247 scoped_refptr<gpu::PreemptionFlag> preemption_flag_;
249 LatencyInfoCallback latency_info_callback_;
251 GURL active_url_;
252 size_t active_url_hash_;
254 size_t total_gpu_memory_;
256 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub);
259 } // namespace content
261 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_