Add ICU message format support
[chromium-blink-merge.git] / content / common / gpu / gpu_command_buffer_stub.h
blobf5720b78f4582de1b905b974aea92be6a918f2a0
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_manager.h"
17 #include "content/common/gpu/gpu_memory_manager_client.h"
18 #include "gpu/command_buffer/common/constants.h"
19 #include "gpu/command_buffer/common/gpu_memory_allocation.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/geometry/size.h"
28 #include "ui/gfx/gpu_memory_buffer.h"
29 #include "ui/gfx/native_widget_types.h"
30 #include "ui/gfx/swap_result.h"
31 #include "ui/gl/gl_surface.h"
32 #include "ui/gl/gpu_preference.h"
33 #include "url/gurl.h"
35 namespace gpu {
36 struct Mailbox;
37 class ValueStateMap;
38 namespace gles2 {
39 class MailboxManager;
40 class SubscriptionRefSet;
44 namespace content {
46 class GpuChannel;
47 class GpuVideoDecodeAccelerator;
48 class GpuVideoEncodeAccelerator;
49 class GpuWatchdog;
50 struct WaitForCommandState;
52 class GpuCommandBufferStub
53 : public GpuMemoryManagerClient,
54 public IPC::Listener,
55 public IPC::Sender,
56 public base::SupportsWeakPtr<GpuCommandBufferStub> {
57 public:
58 class DestructionObserver {
59 public:
60 // Called in Destroy(), before the context/surface are released.
61 virtual void OnWillDestroyStub() = 0;
63 protected:
64 virtual ~DestructionObserver() {}
67 typedef base::Callback<void(const std::vector<ui::LatencyInfo>&)>
68 LatencyInfoCallback;
70 GpuCommandBufferStub(
71 GpuChannel* channel,
72 GpuCommandBufferStub* share_group,
73 const gfx::GLSurfaceHandle& handle,
74 gpu::gles2::MailboxManager* mailbox_manager,
75 gpu::gles2::SubscriptionRefSet* subscription_ref_set,
76 gpu::ValueStateMap* pending_valuebuffer_state,
77 const gfx::Size& size,
78 const gpu::gles2::DisallowedFeatures& disallowed_features,
79 const std::vector<int32>& attribs,
80 gfx::GpuPreference gpu_preference,
81 bool use_virtualized_gl_context,
82 int32 route_id,
83 int32 surface_id,
84 GpuWatchdog* watchdog,
85 bool software,
86 const GURL& active_url);
88 ~GpuCommandBufferStub() override;
90 // IPC::Listener implementation:
91 bool OnMessageReceived(const IPC::Message& message) override;
93 // IPC::Sender implementation:
94 bool Send(IPC::Message* msg) override;
96 // GpuMemoryManagerClient implementation:
97 gfx::Size GetSurfaceSize() const override;
98 gpu::gles2::MemoryTracker* GetMemoryTracker() const override;
99 void SetMemoryAllocation(const gpu::MemoryAllocation& allocation) override;
100 void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override;
101 bool GetTotalGpuMemory(uint64* bytes) override;
103 // Whether this command buffer can currently handle IPC messages.
104 bool IsScheduled();
106 // If the command buffer is pre-empted and cannot process commands.
107 bool IsPreempted() const {
108 return scheduler_.get() && scheduler_->IsPreempted();
111 // Whether there are commands in the buffer that haven't been processed.
112 bool HasUnprocessedCommands();
114 gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); }
115 gpu::GpuScheduler* scheduler() const { return scheduler_.get(); }
116 GpuChannel* channel() const { return channel_; }
118 // Identifies the target surface.
119 int32 surface_id() const { return surface_id_; }
121 // Identifies the various GpuCommandBufferStubs in the GPU process belonging
122 // to the same renderer process.
123 int32 route_id() const { return route_id_; }
125 gfx::GpuPreference gpu_preference() { return gpu_preference_; }
127 int32 GetRequestedAttribute(int attr) const;
129 // Sends a message to the console.
130 void SendConsoleMessage(int32 id, const std::string& message);
132 void SendCachedShader(const std::string& key, const std::string& shader);
134 gfx::GLSurface* surface() const { return surface_.get(); }
136 void AddDestructionObserver(DestructionObserver* observer);
137 void RemoveDestructionObserver(DestructionObserver* observer);
139 // Associates a sync point to this stub. When the stub is destroyed, it will
140 // retire all sync points that haven't been previously retired.
141 void AddSyncPoint(uint32 sync_point);
143 void SetPreemptByFlag(scoped_refptr<gpu::PreemptionFlag> flag);
145 void SetLatencyInfoCallback(const LatencyInfoCallback& callback);
147 void MarkContextLost();
149 const gpu::gles2::FeatureInfo* GetFeatureInfo() const;
151 void SendSwapBuffersCompleted(
152 const std::vector<ui::LatencyInfo>& latency_info,
153 gfx::SwapResult result);
154 void SendUpdateVSyncParameters(base::TimeTicks timebase,
155 base::TimeDelta interval);
157 private:
158 GpuMemoryManager* GetMemoryManager() const;
159 bool MakeCurrent();
160 void Destroy();
162 // Cleans up and sends reply if OnInitialize failed.
163 void OnInitializeFailed(IPC::Message* reply_message);
165 // Message handlers:
166 void OnInitialize(base::SharedMemoryHandle shared_state_shm,
167 IPC::Message* reply_message);
168 void OnSetGetBuffer(int32 shm_id, IPC::Message* reply_message);
169 void OnProduceFrontBuffer(const gpu::Mailbox& mailbox);
170 void OnGetState(IPC::Message* reply_message);
171 void OnWaitForTokenInRange(int32 start,
172 int32 end,
173 IPC::Message* reply_message);
174 void OnWaitForGetOffsetInRange(int32 start,
175 int32 end,
176 IPC::Message* reply_message);
177 void OnAsyncFlush(int32 put_offset, uint32 flush_count,
178 const std::vector<ui::LatencyInfo>& latency_info);
179 void OnRescheduled();
180 void OnRegisterTransferBuffer(int32 id,
181 base::SharedMemoryHandle transfer_buffer,
182 uint32 size);
183 void OnDestroyTransferBuffer(int32 id);
184 void OnGetTransferBuffer(int32 id, IPC::Message* reply_message);
186 void OnCreateVideoDecoder(media::VideoCodecProfile profile,
187 int32 route_id,
188 IPC::Message* reply_message);
189 void OnCreateVideoEncoder(media::VideoPixelFormat input_format,
190 const gfx::Size& input_visible_size,
191 media::VideoCodecProfile output_profile,
192 uint32 initial_bitrate,
193 int32 route_id,
194 IPC::Message* reply_message);
196 void OnSetSurfaceVisible(bool visible);
198 void OnEnsureBackbuffer();
200 void OnRetireSyncPoint(uint32 sync_point);
201 bool OnWaitSyncPoint(uint32 sync_point);
202 void OnWaitSyncPointCompleted(uint32 sync_point);
203 void OnSignalSyncPoint(uint32 sync_point, uint32 id);
204 void OnSignalSyncPointAck(uint32 id);
205 void OnSignalQuery(uint32 query, uint32 id);
207 void OnSetClientHasMemoryAllocationChangedCallback(bool has_callback);
209 void OnCreateImage(int32 id,
210 gfx::GpuMemoryBufferHandle handle,
211 gfx::Size size,
212 gfx::BufferFormat format,
213 uint32 internalformat);
214 void OnDestroyImage(int32 id);
216 void OnCommandProcessed();
217 void OnParseError();
218 void OnCreateStreamTexture(
219 uint32 texture_id, int32 stream_id, bool* succeeded);
221 void ReportState();
223 // Wrapper for GpuScheduler::PutChanged that sets the crash report URL.
224 void PutChanged();
226 // Poll the command buffer to execute work.
227 void PollWork();
229 // Whether this command buffer needs to be polled again in the future.
230 bool HasMoreWork();
232 void ScheduleDelayedWork(int64 delay);
234 bool CheckContextLost();
235 void CheckCompleteWaits();
236 void PullTextureUpdates(uint32 sync_point);
238 // The lifetime of objects of this class is managed by a GpuChannel. The
239 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they
240 // are destroyed. So a raw pointer is safe.
241 GpuChannel* channel_;
243 // The group of contexts that share namespaces with this context.
244 scoped_refptr<gpu::gles2::ContextGroup> context_group_;
246 gfx::GLSurfaceHandle handle_;
247 gfx::Size initial_size_;
248 gpu::gles2::DisallowedFeatures disallowed_features_;
249 std::vector<int32> requested_attribs_;
250 gfx::GpuPreference gpu_preference_;
251 bool use_virtualized_gl_context_;
252 int32 route_id_;
253 int32 surface_id_;
254 bool software_;
255 uint32 last_flush_count_;
257 scoped_ptr<gpu::CommandBufferService> command_buffer_;
258 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_;
259 scoped_ptr<gpu::GpuScheduler> scheduler_;
260 scoped_refptr<gfx::GLSurface> surface_;
262 scoped_ptr<GpuMemoryManagerClientState> memory_manager_client_state_;
263 // The last memory allocation received from the GpuMemoryManager (used to
264 // elide redundant work).
265 bool last_memory_allocation_valid_;
266 gpu::MemoryAllocation last_memory_allocation_;
268 GpuWatchdog* watchdog_;
270 base::ObserverList<DestructionObserver> destruction_observers_;
272 // A queue of sync points associated with this stub.
273 std::deque<uint32> sync_points_;
274 int sync_point_wait_count_;
276 bool delayed_work_scheduled_;
277 uint64 previous_messages_processed_;
278 base::TimeTicks last_idle_time_;
280 scoped_refptr<gpu::PreemptionFlag> preemption_flag_;
282 LatencyInfoCallback latency_info_callback_;
284 GURL active_url_;
285 size_t active_url_hash_;
287 size_t total_gpu_memory_;
288 scoped_ptr<WaitForCommandState> wait_for_token_;
289 scoped_ptr<WaitForCommandState> wait_for_get_offset_;
291 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub);
294 } // namespace content
296 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_