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

Side by Side Diff: content/common/gpu/gpu_channel.h

Issue 1336623004: content/gpu: Simplify gpu channel message handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: piman Created 5 years, 3 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 | « no previous file | content/common/gpu/gpu_channel.cc » ('j') | content/common/gpu/gpu_channel.cc » ('J')
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_CHANNEL_H_ 5 #ifndef CONTENT_COMMON_GPU_GPU_CHANNEL_H_
6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_H_ 6 #define CONTENT_COMMON_GPU_GPU_CHANNEL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return io_task_runner_; 99 return io_task_runner_;
100 } 100 }
101 101
102 // IPC::Listener implementation: 102 // IPC::Listener implementation:
103 bool OnMessageReceived(const IPC::Message& msg) override; 103 bool OnMessageReceived(const IPC::Message& msg) override;
104 void OnChannelError() override; 104 void OnChannelError() override;
105 105
106 // IPC::Sender implementation: 106 // IPC::Sender implementation:
107 bool Send(IPC::Message* msg) override; 107 bool Send(IPC::Message* msg) override;
108 108
109 // Requeue the message that is currently being processed to the beginning of
110 // the queue. Used when the processing of a message gets aborted because of
111 // unscheduling conditions.
112 void RequeueMessage();
113
114 // SubscriptionRefSet::Observer implementation 109 // SubscriptionRefSet::Observer implementation
115 void OnAddSubscription(unsigned int target) override; 110 void OnAddSubscription(unsigned int target) override;
116 void OnRemoveSubscription(unsigned int target) override; 111 void OnRemoveSubscription(unsigned int target) override;
117 112
118 // This is called when a command buffer transitions from the unscheduled 113 // This is called when a command buffer transitions from the unscheduled
119 // state to the scheduled state, which potentially means the channel 114 // state to the scheduled state, which potentially means the channel
120 // transitions from the unscheduled to the scheduled state. When this occurs 115 // transitions from the unscheduled to the scheduled state. When this occurs
121 // deferred IPC messaged are handled. 116 // deferred IPC messaged are handled.
122 void OnScheduled(); 117 void OnScheduled();
123 118
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 const gpu::ValueState& state); 167 const gpu::ValueState& state);
173 168
174 // Visible for testing. 169 // Visible for testing.
175 const gpu::ValueStateMap* pending_valuebuffer_state() const { 170 const gpu::ValueStateMap* pending_valuebuffer_state() const {
176 return pending_valuebuffer_state_.get(); 171 return pending_valuebuffer_state_.get();
177 } 172 }
178 173
179 // Visible for testing. 174 // Visible for testing.
180 GpuChannelMessageFilter* filter() const { return filter_.get(); } 175 GpuChannelMessageFilter* filter() const { return filter_.get(); }
181 176
182 uint32_t GetCurrentOrderNum() const { return current_order_num_; } 177 // Returns the global order number of the IPC message that started processing
183 uint32_t GetProcessedOrderNum() const { return processed_order_num_; } 178 // last.
179 uint32_t current_order_num() const { return current_order_num_; }
180
181 // Returns the global order number for the last processed IPC message.
182 uint32_t GetProcessedOrderNum() const;
183
184 // Returns the global order number for the last unprocessed IPC message.
184 uint32_t GetUnprocessedOrderNum() const; 185 uint32_t GetUnprocessedOrderNum() const;
185 186
187 void HandleMessage();
188
186 protected: 189 protected:
187 // The message filter on the io thread. 190 // The message filter on the io thread.
188 scoped_refptr<GpuChannelMessageFilter> filter_; 191 scoped_refptr<GpuChannelMessageFilter> filter_;
189 192
190 // Map of routing id to command buffer stub. 193 // Map of routing id to command buffer stub.
191 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; 194 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_;
192 195
193 private: 196 private:
194 class StreamState { 197 class StreamState {
195 public: 198 public:
196 StreamState(int32 id, GpuStreamPriority priority); 199 StreamState(int32 id, GpuStreamPriority priority);
197 ~StreamState(); 200 ~StreamState();
198 201
199 int32 id() const { return id_; } 202 int32 id() const { return id_; }
200 GpuStreamPriority priority() const { return priority_; } 203 GpuStreamPriority priority() const { return priority_; }
201 204
202 void AddRoute(int32 route_id); 205 void AddRoute(int32 route_id);
203 void RemoveRoute(int32 route_id); 206 void RemoveRoute(int32 route_id);
204 bool HasRoute(int32 route_id) const; 207 bool HasRoute(int32 route_id) const;
205 bool HasRoutes() const; 208 bool HasRoutes() const;
206 209
207 private: 210 private:
208 int32 id_; 211 int32 id_;
209 GpuStreamPriority priority_; 212 GpuStreamPriority priority_;
210 base::hash_set<int32> routes_; 213 base::hash_set<int32> routes_;
211 }; 214 };
212 215
213 friend class GpuChannelMessageFilter;
214 friend class GpuChannelMessageQueue;
215
216 void OnDestroy(); 216 void OnDestroy();
217 217
218 bool OnControlMessageReceived(const IPC::Message& msg); 218 bool OnControlMessageReceived(const IPC::Message& msg);
219 219
220 void HandleMessage(); 220 void ScheduleHandleMessage();
221 221
222 // Message handlers. 222 // Message handlers.
223 void OnCreateOffscreenCommandBuffer( 223 void OnCreateOffscreenCommandBuffer(
224 const gfx::Size& size, 224 const gfx::Size& size,
225 const GPUCreateCommandBufferConfig& init_params, 225 const GPUCreateCommandBufferConfig& init_params,
226 int32 route_id, 226 int32 route_id,
227 bool* succeeded); 227 bool* succeeded);
228 void OnDestroyCommandBuffer(int32 route_id); 228 void OnDestroyCommandBuffer(int32 route_id);
229 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg); 229 void OnCreateJpegDecoder(int32 route_id, IPC::Message* reply_msg);
230 230
231 // Update processed order number and defer preemption.
232 void MessageProcessed(uint32_t order_number);
233
234 // The lifetime of objects of this class is managed by a GpuChannelManager. 231 // The lifetime of objects of this class is managed by a GpuChannelManager.
235 // The GpuChannelManager destroy all the GpuChannels that they own when they 232 // The GpuChannelManager destroy all the GpuChannels that they own when they
236 // are destroyed. So a raw pointer is safe. 233 // are destroyed. So a raw pointer is safe.
237 GpuChannelManager* gpu_channel_manager_; 234 GpuChannelManager* gpu_channel_manager_;
238 235
239 scoped_ptr<IPC::SyncChannel> channel_; 236 scoped_ptr<IPC::SyncChannel> channel_;
240 237
241 // Uniquely identifies the channel within this GPU process. 238 // Uniquely identifies the channel within this GPU process.
242 std::string channel_id_; 239 std::string channel_id_;
243 240
(...skipping 29 matching lines...) Expand all
273 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_; 270 scoped_refptr<gpu::gles2::SubscriptionRefSet> subscription_ref_set_;
274 271
275 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_; 272 scoped_refptr<gpu::ValueStateMap> pending_valuebuffer_state_;
276 273
277 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_; 274 scoped_ptr<GpuJpegDecodeAccelerator> jpeg_decoder_;
278 275
279 gpu::gles2::DisallowedFeatures disallowed_features_; 276 gpu::gles2::DisallowedFeatures disallowed_features_;
280 GpuWatchdog* watchdog_; 277 GpuWatchdog* watchdog_;
281 bool software_; 278 bool software_;
282 279
283 // Current IPC order number being processed.
284 uint32_t current_order_num_;
285
286 // Last finished IPC order number.
287 uint32_t processed_order_num_;
288
289 size_t num_stubs_descheduled_; 280 size_t num_stubs_descheduled_;
290 281
291 // Map of stream id to stream state. 282 // Map of stream id to stream state.
292 base::hash_map<int32, StreamState> streams_; 283 base::hash_map<int32, StreamState> streams_;
293 284
285 uint32_t current_order_num_;
286
294 bool allow_future_sync_points_; 287 bool allow_future_sync_points_;
295 bool allow_real_time_streams_; 288 bool allow_real_time_streams_;
296 289
297 // Member variables should appear before the WeakPtrFactory, to ensure 290 // Member variables should appear before the WeakPtrFactory, to ensure
298 // that any WeakPtrs to Controller are invalidated before its members 291 // that any WeakPtrs to Controller are invalidated before its members
299 // variable's destructors are executed, rendering them invalid. 292 // variable's destructors are executed, rendering them invalid.
300 base::WeakPtrFactory<GpuChannel> weak_factory_; 293 base::WeakPtrFactory<GpuChannel> weak_factory_;
301 294
302 DISALLOW_COPY_AND_ASSIGN(GpuChannel); 295 DISALLOW_COPY_AND_ASSIGN(GpuChannel);
303 }; 296 };
304 297
305 // This filter does three things: 298 // This filter does three things:
306 // - it counts and timestamps each message forwarded to the channel 299 // - it counts and timestamps each message forwarded to the channel
307 // so that we can preempt other channels if a message takes too long to 300 // so that we can preempt other channels if a message takes too long to
308 // process. To guarantee fairness, we must wait a minimum amount of time 301 // process. To guarantee fairness, we must wait a minimum amount of time
309 // before preempting and we limit the amount of time that we can preempt in 302 // before preempting and we limit the amount of time that we can preempt in
310 // one shot (see constants above). 303 // one shot (see constants above).
311 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO 304 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO
312 // thread, generating the sync point ID and responding immediately, and then 305 // thread, generating the sync point ID and responding immediately, and then
313 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message 306 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message
314 // into the channel's queue. 307 // into the channel's queue.
315 // - it generates mailbox names for clients of the GPU process on the IO thread. 308 // - it generates mailbox names for clients of the GPU process on the IO thread.
316 class GpuChannelMessageFilter : public IPC::MessageFilter { 309 class GpuChannelMessageFilter : public IPC::MessageFilter {
317 public: 310 public:
318 GpuChannelMessageFilter( 311 GpuChannelMessageFilter(GpuChannelMessageQueue* message_queue,
319 scoped_refptr<GpuChannelMessageQueue> message_queue, 312 gpu::SyncPointManager* sync_point_manager,
320 gpu::SyncPointManager* sync_point_manager, 313 base::SingleThreadTaskRunner* task_runner,
321 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 314 bool future_sync_points);
322 bool future_sync_points);
323 315
324 // IPC::MessageFilter implementation. 316 // IPC::MessageFilter implementation.
325 void OnFilterAdded(IPC::Sender* sender) override; 317 void OnFilterAdded(IPC::Sender* sender) override;
326 void OnFilterRemoved() override; 318 void OnFilterRemoved() override;
327 void OnChannelConnected(int32 peer_pid) override; 319 void OnChannelConnected(int32 peer_pid) override;
328 void OnChannelError() override; 320 void OnChannelError() override;
329 void OnChannelClosing() override; 321 void OnChannelClosing() override;
330 bool OnMessageReceived(const IPC::Message& message) override; 322 bool OnMessageReceived(const IPC::Message& message) override;
331 323
332 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter); 324 void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 382
391 bool a_stub_is_descheduled_; 383 bool a_stub_is_descheduled_;
392 384
393 // True if this channel can create future sync points. 385 // True if this channel can create future sync points.
394 bool future_sync_points_; 386 bool future_sync_points_;
395 387
396 // This number is only ever incremented/read on the IO thread. 388 // This number is only ever incremented/read on the IO thread.
397 static uint32_t global_order_counter_; 389 static uint32_t global_order_counter_;
398 }; 390 };
399 391
392 struct GpuChannelMessage {
393 uint32_t order_number;
394 base::TimeTicks time_received;
395 IPC::Message message;
396
397 // TODO(dyen): Temporary sync point data, remove once new sync point lands.
398 bool retire_sync_point;
399 uint32 sync_point;
400
401 GpuChannelMessage(uint32_t order_num, const IPC::Message& msg)
402 : order_number(order_num),
403 time_received(base::TimeTicks::Now()),
404 message(msg),
405 retire_sync_point(false),
406 sync_point(0) {}
407 };
dcheng 2015/09/17 00:15:18 DISALLOW_COPY_AND_ASSIGN? Since it looks like the
sunnyps 2015/09/17 00:32:39 Done.
408
409 class GpuChannelMessageQueue
410 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> {
411 public:
412 static scoped_refptr<GpuChannelMessageQueue> Create(
413 const base::WeakPtr<GpuChannel>& gpu_channel,
414 base::SingleThreadTaskRunner* task_runner);
415
416 // Returns the global order number for the last processed IPC message.
417 uint32_t GetUnprocessedOrderNum() const;
418
419 // Returns the global order number for the last unprocessed IPC message.
420 uint32_t processed_order_num() const { return processed_order_num_; }
421
422 bool HasQueuedMessages() const;
423
424 base::TimeTicks GetNextMessageTimeTick() const;
425
426 GpuChannelMessage* GetNextMessage() const;
427
428 // Should be called after a message returned by GetNextMessage is processed.
429 // Returns true if there are more messages on the queue.
430 bool MessageProcessed(uint32_t order_number);
431
432 void PushBackMessage(uint32_t order_number, const IPC::Message& message);
433
434 bool GenerateSyncPointMessage(gpu::SyncPointManager* sync_point_manager,
435 uint32_t order_number,
436 const IPC::Message& message,
437 bool retire_sync_point,
438 uint32_t* sync_point_number);
439
440 void DeleteAndDisableMessages(GpuChannelManager* gpu_channel_manager);
441
442 private:
443 friend class base::RefCountedThreadSafe<GpuChannelMessageQueue>;
444
445 GpuChannelMessageQueue(const base::WeakPtr<GpuChannel>& gpu_channel,
446 base::SingleThreadTaskRunner* task_runner);
447 ~GpuChannelMessageQueue();
448
449 void ScheduleHandleMessage();
450
451 void PushMessageHelper(scoped_ptr<GpuChannelMessage> msg);
452
453 bool HasQueuedMessagesHelper() const;
454
455 bool enabled_;
456
457 // Highest IPC order number seen, set when queued on the IO thread.
458 uint32_t unprocessed_order_num_;
459 // Both deques own the messages.
460 std::deque<GpuChannelMessage*> channel_messages_;
461 std::deque<GpuChannelMessage*> out_of_order_messages_;
462
463 // This lock protects enabled_, unprocessed_order_num_, and both deques.
464 mutable base::Lock channel_messages_lock_;
465
466 // Last finished IPC order number. Not protected by a lock as it's only
467 // accessed on the main thread.
468 uint32_t processed_order_num_;
469
470 base::WeakPtr<GpuChannel> gpu_channel_;
471 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
472
473 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue);
474 };
475
400 } // namespace content 476 } // namespace content
401 477
402 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ 478 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/gpu_channel.cc » ('j') | content/common/gpu/gpu_channel.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698