Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: gpu/ipc/service/gpu_command_buffer_stub.h

Issue 1845563005: Refactor content/common/gpu into gpu/ipc/service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop ref to deleted content_tests_gypi_values.content_unittests_ozone_sources Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/ipc/service/gpu_channel_unittest.cc ('k') | gpu/ipc/service/gpu_command_buffer_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ 5 #ifndef GPU_IPC_SERVICE_GPU_COMMAND_BUFFER_STUB_H_
6 #define CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ 6 #define GPU_IPC_SERVICE_GPU_COMMAND_BUFFER_STUB_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <deque> 11 #include <deque>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h" 17 #include "base/observer_list.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "content/common/content_export.h"
20 #include "content/common/gpu/gpu_memory_manager.h"
21 #include "gpu/command_buffer/common/command_buffer_id.h" 19 #include "gpu/command_buffer/common/command_buffer_id.h"
22 #include "gpu/command_buffer/common/constants.h" 20 #include "gpu/command_buffer/common/constants.h"
23 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 21 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
24 #include "gpu/command_buffer/service/command_buffer_service.h" 22 #include "gpu/command_buffer/service/command_buffer_service.h"
25 #include "gpu/command_buffer/service/command_executor.h" 23 #include "gpu/command_buffer/service/command_executor.h"
26 #include "gpu/command_buffer/service/context_group.h" 24 #include "gpu/command_buffer/service/context_group.h"
25 #include "gpu/gpu_export.h"
27 #include "gpu/ipc/common/surface_handle.h" 26 #include "gpu/ipc/common/surface_handle.h"
27 #include "gpu/ipc/service/gpu_memory_manager.h"
28 #include "ipc/ipc_listener.h" 28 #include "ipc/ipc_listener.h"
29 #include "ipc/ipc_sender.h" 29 #include "ipc/ipc_sender.h"
30 #include "ui/events/latency_info.h" 30 #include "ui/events/latency_info.h"
31 #include "ui/gfx/geometry/size.h" 31 #include "ui/gfx/geometry/size.h"
32 #include "ui/gfx/gpu_memory_buffer.h" 32 #include "ui/gfx/gpu_memory_buffer.h"
33 #include "ui/gfx/swap_result.h" 33 #include "ui/gfx/swap_result.h"
34 #include "ui/gl/gl_surface.h" 34 #include "ui/gl/gl_surface.h"
35 #include "ui/gl/gpu_preference.h" 35 #include "ui/gl/gpu_preference.h"
36 #include "url/gurl.h" 36 #include "url/gurl.h"
37 37
38 namespace gpu { 38 namespace gpu {
39 struct Mailbox; 39 struct Mailbox;
40 struct SyncToken; 40 struct SyncToken;
41 class SyncPointClient; 41 class SyncPointClient;
42 class SyncPointManager; 42 class SyncPointManager;
43 class ValueStateMap; 43 class ValueStateMap;
44 namespace gles2 { 44 namespace gles2 {
45 class MailboxManager; 45 class MailboxManager;
46 class SubscriptionRefSet; 46 class SubscriptionRefSet;
47 } 47 }
48 } 48 }
49 49
50 struct GpuCommandBufferMsg_CreateImage_Params; 50 struct GpuCommandBufferMsg_CreateImage_Params;
51 51
52 namespace content { 52 namespace gpu {
53 53
54 class GpuChannel; 54 class GpuChannel;
55 class GpuWatchdog; 55 class GpuWatchdog;
56 struct WaitForCommandState; 56 struct WaitForCommandState;
57 57
58 class GpuCommandBufferStub 58 class GPU_EXPORT GpuCommandBufferStub
59 : public IPC::Listener, 59 : public IPC::Listener,
60 public IPC::Sender, 60 public IPC::Sender,
61 public base::SupportsWeakPtr<GpuCommandBufferStub> { 61 public base::SupportsWeakPtr<GpuCommandBufferStub> {
62 public: 62 public:
63 class DestructionObserver { 63 class DestructionObserver {
64 public: 64 public:
65 // Called in Destroy(), before the context/surface are released. 65 // Called in Destroy(), before the context/surface are released.
66 virtual void OnWillDestroyStub() = 0; 66 virtual void OnWillDestroyStub() = 0;
67 67
68 protected: 68 protected:
69 virtual ~DestructionObserver() {} 69 virtual ~DestructionObserver() {}
70 }; 70 };
71 71
72 typedef base::Callback<void(const std::vector<ui::LatencyInfo>&)> 72 typedef base::Callback<void(const std::vector<ui::LatencyInfo>&)>
73 LatencyInfoCallback; 73 LatencyInfoCallback;
74 74
75 GpuCommandBufferStub( 75 GpuCommandBufferStub(
76 GpuChannel* channel, 76 GpuChannel* channel,
77 gpu::SyncPointManager* sync_point_manager, 77 SyncPointManager* sync_point_manager,
78 base::SingleThreadTaskRunner* task_runner, 78 base::SingleThreadTaskRunner* task_runner,
79 GpuCommandBufferStub* share_group, 79 GpuCommandBufferStub* share_group,
80 gpu::SurfaceHandle surface_handle, 80 SurfaceHandle surface_handle,
81 gpu::gles2::MailboxManager* mailbox_manager, 81 gles2::MailboxManager* mailbox_manager,
82 gpu::PreemptionFlag* preempt_by_flag, 82 PreemptionFlag* preempt_by_flag,
83 gpu::gles2::SubscriptionRefSet* subscription_ref_set, 83 gles2::SubscriptionRefSet* subscription_ref_set,
84 gpu::ValueStateMap* pending_valuebuffer_state, 84 ValueStateMap* pending_valuebuffer_state,
85 const gfx::Size& size, 85 const gfx::Size& size,
86 const gpu::gles2::DisallowedFeatures& disallowed_features, 86 const gles2::DisallowedFeatures& disallowed_features,
87 const std::vector<int32_t>& attribs, 87 const std::vector<int32_t>& attribs,
88 gfx::GpuPreference gpu_preference, 88 gfx::GpuPreference gpu_preference,
89 int32_t stream_id, 89 int32_t stream_id,
90 int32_t route_id, 90 int32_t route_id,
91 GpuWatchdog* watchdog, 91 GpuWatchdog* watchdog,
92 const GURL& active_url); 92 const GURL& active_url);
93 93
94 ~GpuCommandBufferStub() override; 94 ~GpuCommandBufferStub() override;
95 95
96 // IPC::Listener implementation: 96 // IPC::Listener implementation:
97 bool OnMessageReceived(const IPC::Message& message) override; 97 bool OnMessageReceived(const IPC::Message& message) override;
98 98
99 // IPC::Sender implementation: 99 // IPC::Sender implementation:
100 bool Send(IPC::Message* msg) override; 100 bool Send(IPC::Message* msg) override;
101 101
102 gpu::gles2::MemoryTracker* GetMemoryTracker() const; 102 gles2::MemoryTracker* GetMemoryTracker() const;
103 103
104 // Whether this command buffer can currently handle IPC messages. 104 // Whether this command buffer can currently handle IPC messages.
105 bool IsScheduled(); 105 bool IsScheduled();
106 106
107 // Whether there are commands in the buffer that haven't been processed. 107 // Whether there are commands in the buffer that haven't been processed.
108 bool HasUnprocessedCommands(); 108 bool HasUnprocessedCommands();
109 109
110 gpu::gles2::GLES2Decoder* decoder() const { return decoder_.get(); } 110 gles2::GLES2Decoder* decoder() const { return decoder_.get(); }
111 gpu::CommandExecutor* scheduler() const { return executor_.get(); } 111 CommandExecutor* scheduler() const { return executor_.get(); }
112 GpuChannel* channel() const { return channel_; } 112 GpuChannel* channel() const { return channel_; }
113 113
114 // Unique command buffer ID for this command buffer stub. 114 // Unique command buffer ID for this command buffer stub.
115 gpu::CommandBufferId command_buffer_id() const { return command_buffer_id_; } 115 CommandBufferId command_buffer_id() const { return command_buffer_id_; }
116 116
117 // Identifies the various GpuCommandBufferStubs in the GPU process belonging 117 // Identifies the various GpuCommandBufferStubs in the GPU process belonging
118 // to the same renderer process. 118 // to the same renderer process.
119 int32_t route_id() const { return route_id_; } 119 int32_t route_id() const { return route_id_; }
120 120
121 // Identifies the stream for this command buffer. 121 // Identifies the stream for this command buffer.
122 int32_t stream_id() const { return stream_id_; } 122 int32_t stream_id() const { return stream_id_; }
123 123
124 gfx::GpuPreference gpu_preference() { return gpu_preference_; } 124 gfx::GpuPreference gpu_preference() { return gpu_preference_; }
125 125
126 int32_t GetRequestedAttribute(int attr) const; 126 int32_t GetRequestedAttribute(int attr) const;
127 127
128 // Sends a message to the console. 128 // Sends a message to the console.
129 void SendConsoleMessage(int32_t id, const std::string& message); 129 void SendConsoleMessage(int32_t id, const std::string& message);
130 130
131 void SendCachedShader(const std::string& key, const std::string& shader); 131 void SendCachedShader(const std::string& key, const std::string& shader);
132 132
133 gfx::GLSurface* surface() const { return surface_.get(); } 133 gfx::GLSurface* surface() const { return surface_.get(); }
134 134
135 void AddDestructionObserver(DestructionObserver* observer); 135 void AddDestructionObserver(DestructionObserver* observer);
136 void RemoveDestructionObserver(DestructionObserver* observer); 136 void RemoveDestructionObserver(DestructionObserver* observer);
137 137
138 void SetLatencyInfoCallback(const LatencyInfoCallback& callback); 138 void SetLatencyInfoCallback(const LatencyInfoCallback& callback);
139 139
140 void MarkContextLost(); 140 void MarkContextLost();
141 141
142 const gpu::gles2::FeatureInfo* GetFeatureInfo() const; 142 const gles2::FeatureInfo* GetFeatureInfo() const;
143 143
144 void SendSwapBuffersCompleted( 144 void SendSwapBuffersCompleted(
145 const std::vector<ui::LatencyInfo>& latency_info, 145 const std::vector<ui::LatencyInfo>& latency_info,
146 gfx::SwapResult result); 146 gfx::SwapResult result);
147 void SendUpdateVSyncParameters(base::TimeTicks timebase, 147 void SendUpdateVSyncParameters(base::TimeTicks timebase,
148 base::TimeDelta interval); 148 base::TimeDelta interval);
149 149
150 private: 150 private:
151 GpuMemoryManager* GetMemoryManager() const; 151 GpuMemoryManager* GetMemoryManager() const;
152 152
153 void Destroy(); 153 void Destroy();
154 154
155 bool MakeCurrent(); 155 bool MakeCurrent();
156 156
157 // Cleans up and sends reply if OnInitialize failed. 157 // Cleans up and sends reply if OnInitialize failed.
158 void OnInitializeFailed(IPC::Message* reply_message); 158 void OnInitializeFailed(IPC::Message* reply_message);
159 159
160 scoped_refptr<gfx::GLSurface> CreateSurface(); 160 scoped_refptr<gfx::GLSurface> CreateSurface();
161 161
162 // Message handlers: 162 // Message handlers:
163 void OnInitialize(base::SharedMemoryHandle shared_state_shm, 163 void OnInitialize(base::SharedMemoryHandle shared_state_shm,
164 IPC::Message* reply_message); 164 IPC::Message* reply_message);
165 void OnSetGetBuffer(int32_t shm_id, IPC::Message* reply_message); 165 void OnSetGetBuffer(int32_t shm_id, IPC::Message* reply_message);
166 void OnProduceFrontBuffer(const gpu::Mailbox& mailbox); 166 void OnProduceFrontBuffer(const Mailbox& mailbox);
167 void OnGetState(IPC::Message* reply_message); 167 void OnGetState(IPC::Message* reply_message);
168 void OnWaitForTokenInRange(int32_t start, 168 void OnWaitForTokenInRange(int32_t start,
169 int32_t end, 169 int32_t end,
170 IPC::Message* reply_message); 170 IPC::Message* reply_message);
171 void OnWaitForGetOffsetInRange(int32_t start, 171 void OnWaitForGetOffsetInRange(int32_t start,
172 int32_t end, 172 int32_t end,
173 IPC::Message* reply_message); 173 IPC::Message* reply_message);
174 void OnAsyncFlush(int32_t put_offset, 174 void OnAsyncFlush(int32_t put_offset,
175 uint32_t flush_count, 175 uint32_t flush_count,
176 const std::vector<ui::LatencyInfo>& latency_info); 176 const std::vector<ui::LatencyInfo>& latency_info);
177 void OnRegisterTransferBuffer(int32_t id, 177 void OnRegisterTransferBuffer(int32_t id,
178 base::SharedMemoryHandle transfer_buffer, 178 base::SharedMemoryHandle transfer_buffer,
179 uint32_t size); 179 uint32_t size);
180 void OnDestroyTransferBuffer(int32_t id); 180 void OnDestroyTransferBuffer(int32_t id);
181 void OnGetTransferBuffer(int32_t id, IPC::Message* reply_message); 181 void OnGetTransferBuffer(int32_t id, IPC::Message* reply_message);
182 182
183 void OnEnsureBackbuffer(); 183 void OnEnsureBackbuffer();
184 184
185 void OnSignalSyncToken(const gpu::SyncToken& sync_token, uint32_t id); 185 void OnSignalSyncToken(const SyncToken& sync_token, uint32_t id);
186 void OnSignalAck(uint32_t id); 186 void OnSignalAck(uint32_t id);
187 void OnSignalQuery(uint32_t query, uint32_t id); 187 void OnSignalQuery(uint32_t query, uint32_t id);
188 188
189 void OnFenceSyncRelease(uint64_t release); 189 void OnFenceSyncRelease(uint64_t release);
190 bool OnWaitFenceSync(gpu::CommandBufferNamespace namespace_id, 190 bool OnWaitFenceSync(CommandBufferNamespace namespace_id,
191 gpu::CommandBufferId command_buffer_id, 191 CommandBufferId command_buffer_id,
192 uint64_t release); 192 uint64_t release);
193 void OnWaitFenceSyncCompleted(gpu::CommandBufferNamespace namespace_id, 193 void OnWaitFenceSyncCompleted(CommandBufferNamespace namespace_id,
194 gpu::CommandBufferId command_buffer_id, 194 CommandBufferId command_buffer_id,
195 uint64_t release); 195 uint64_t release);
196 196
197 void OnCreateImage(const GpuCommandBufferMsg_CreateImage_Params& params); 197 void OnCreateImage(const GpuCommandBufferMsg_CreateImage_Params& params);
198 void OnDestroyImage(int32_t id); 198 void OnDestroyImage(int32_t id);
199 void OnCreateStreamTexture(uint32_t texture_id, 199 void OnCreateStreamTexture(uint32_t texture_id,
200 int32_t stream_id, 200 int32_t stream_id,
201 bool* succeeded); 201 bool* succeeded);
202 202
203 void OnCommandProcessed(); 203 void OnCommandProcessed();
204 void OnParseError(); 204 void OnParseError();
205 void OnSchedulingChanged(bool scheduled); 205 void OnSchedulingChanged(bool scheduled);
206 206
207 void ReportState(); 207 void ReportState();
208 208
209 // Wrapper for CommandExecutor::PutChanged that sets the crash report URL. 209 // Wrapper for CommandExecutor::PutChanged that sets the crash report URL.
210 void PutChanged(); 210 void PutChanged();
211 211
212 // Poll the command buffer to execute work. 212 // Poll the command buffer to execute work.
213 void PollWork(); 213 void PollWork();
214 void PerformWork(); 214 void PerformWork();
215 215
216 // Schedule processing of delayed work. This updates the time at which 216 // Schedule processing of delayed work. This updates the time at which
217 // delayed work should be processed. |process_delayed_work_time_| is 217 // delayed work should be processed. |process_delayed_work_time_| is
218 // updated to current time + delay. Call this after processing some amount 218 // updated to current time + delay. Call this after processing some amount
219 // of delayed work. 219 // of delayed work.
220 void ScheduleDelayedWork(base::TimeDelta delay); 220 void ScheduleDelayedWork(base::TimeDelta delay);
221 221
222 bool CheckContextLost(); 222 bool CheckContextLost();
223 void CheckCompleteWaits(); 223 void CheckCompleteWaits();
224 void PullTextureUpdates(gpu::CommandBufferNamespace namespace_id, 224 void PullTextureUpdates(CommandBufferNamespace namespace_id,
225 gpu::CommandBufferId command_buffer_id, 225 CommandBufferId command_buffer_id,
226 uint32_t release); 226 uint32_t release);
227 227
228 // The lifetime of objects of this class is managed by a GpuChannel. The 228 // The lifetime of objects of this class is managed by a GpuChannel. The
229 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they 229 // GpuChannels destroy all the GpuCommandBufferStubs that they own when they
230 // are destroyed. So a raw pointer is safe. 230 // are destroyed. So a raw pointer is safe.
231 GpuChannel* const channel_; 231 GpuChannel* const channel_;
232 232
233 // Outlives the stub. 233 // Outlives the stub.
234 gpu::SyncPointManager* const sync_point_manager_; 234 SyncPointManager* const sync_point_manager_;
235 235
236 // Task runner for main thread. 236 // Task runner for main thread.
237 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 237 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
238 238
239 // The group of contexts that share namespaces with this context. 239 // The group of contexts that share namespaces with this context.
240 scoped_refptr<gpu::gles2::ContextGroup> context_group_; 240 scoped_refptr<gles2::ContextGroup> context_group_;
241 241
242 bool initialized_; 242 bool initialized_;
243 const gpu::SurfaceHandle surface_handle_; 243 const SurfaceHandle surface_handle_;
244 gfx::Size initial_size_; 244 gfx::Size initial_size_;
245 gpu::gles2::DisallowedFeatures disallowed_features_; 245 gles2::DisallowedFeatures disallowed_features_;
246 std::vector<int32_t> requested_attribs_; 246 std::vector<int32_t> requested_attribs_;
247 gfx::GpuPreference gpu_preference_; 247 gfx::GpuPreference gpu_preference_;
248 bool use_virtualized_gl_context_; 248 bool use_virtualized_gl_context_;
249 const gpu::CommandBufferId command_buffer_id_; 249 const CommandBufferId command_buffer_id_;
250 const int32_t stream_id_; 250 const int32_t stream_id_;
251 const int32_t route_id_; 251 const int32_t route_id_;
252 uint32_t last_flush_count_; 252 uint32_t last_flush_count_;
253 253
254 scoped_ptr<gpu::CommandBufferService> command_buffer_; 254 scoped_ptr<CommandBufferService> command_buffer_;
255 scoped_ptr<gpu::gles2::GLES2Decoder> decoder_; 255 scoped_ptr<gles2::GLES2Decoder> decoder_;
256 scoped_ptr<gpu::CommandExecutor> executor_; 256 scoped_ptr<CommandExecutor> executor_;
257 scoped_ptr<gpu::SyncPointClient> sync_point_client_; 257 scoped_ptr<SyncPointClient> sync_point_client_;
258 scoped_refptr<gfx::GLSurface> surface_; 258 scoped_refptr<gfx::GLSurface> surface_;
259 gfx::GLSurface::Format surface_format_; 259 gfx::GLSurface::Format surface_format_;
260 260
261 GpuWatchdog* watchdog_; 261 GpuWatchdog* watchdog_;
262 262
263 base::ObserverList<DestructionObserver> destruction_observers_; 263 base::ObserverList<DestructionObserver> destruction_observers_;
264 264
265 bool waiting_for_sync_point_; 265 bool waiting_for_sync_point_;
266 266
267 base::TimeTicks process_delayed_work_time_; 267 base::TimeTicks process_delayed_work_time_;
268 uint32_t previous_processed_num_; 268 uint32_t previous_processed_num_;
269 base::TimeTicks last_idle_time_; 269 base::TimeTicks last_idle_time_;
270 270
271 scoped_refptr<gpu::PreemptionFlag> preemption_flag_; 271 scoped_refptr<PreemptionFlag> preemption_flag_;
272 272
273 LatencyInfoCallback latency_info_callback_; 273 LatencyInfoCallback latency_info_callback_;
274 274
275 GURL active_url_; 275 GURL active_url_;
276 size_t active_url_hash_; 276 size_t active_url_hash_;
277 277
278 scoped_ptr<WaitForCommandState> wait_for_token_; 278 scoped_ptr<WaitForCommandState> wait_for_token_;
279 scoped_ptr<WaitForCommandState> wait_for_get_offset_; 279 scoped_ptr<WaitForCommandState> wait_for_get_offset_;
280 280
281 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub); 281 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferStub);
282 }; 282 };
283 283
284 } // namespace content 284 } // namespace gpu
285 285
286 #endif // CONTENT_COMMON_GPU_GPU_COMMAND_BUFFER_STUB_H_ 286 #endif // GPU_IPC_SERVICE_GPU_COMMAND_BUFFER_STUB_H_
OLDNEW
« no previous file with comments | « gpu/ipc/service/gpu_channel_unittest.cc ('k') | gpu/ipc/service/gpu_command_buffer_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698