OLD | NEW |
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 uint32_t current_order_num() const { return current_order_num_; } | 173 uint32_t current_order_num() const { return current_order_num_; } |
174 | 174 |
175 // Returns the global order number for the last processed IPC message. | 175 // Returns the global order number for the last processed IPC message. |
176 uint32_t GetProcessedOrderNum() const; | 176 uint32_t GetProcessedOrderNum() const; |
177 | 177 |
178 // Returns the global order number for the last unprocessed IPC message. | 178 // Returns the global order number for the last unprocessed IPC message. |
179 uint32_t GetUnprocessedOrderNum() const; | 179 uint32_t GetUnprocessedOrderNum() const; |
180 | 180 |
181 void HandleMessage(); | 181 void HandleMessage(); |
182 | 182 |
| 183 // Some messages such as WaitForGetOffsetInRange and WaitForTokenInRange are |
| 184 // processed as soon as possible because the client is blocked until they |
| 185 // are completed. |
| 186 void HandleOutOfOrderMessage(const IPC::Message& msg); |
| 187 |
183 protected: | 188 protected: |
184 // The message filter on the io thread. | 189 // The message filter on the io thread. |
185 scoped_refptr<GpuChannelMessageFilter> filter_; | 190 scoped_refptr<GpuChannelMessageFilter> filter_; |
186 | 191 |
187 // Map of routing id to command buffer stub. | 192 // Map of routing id to command buffer stub. |
188 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; | 193 base::ScopedPtrHashMap<int32, scoped_ptr<GpuCommandBufferStub>> stubs_; |
189 | 194 |
190 private: | 195 private: |
191 class StreamState { | 196 class StreamState { |
192 public: | 197 public: |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // process. To guarantee fairness, we must wait a minimum amount of time | 300 // process. To guarantee fairness, we must wait a minimum amount of time |
296 // before preempting and we limit the amount of time that we can preempt in | 301 // before preempting and we limit the amount of time that we can preempt in |
297 // one shot (see constants above). | 302 // one shot (see constants above). |
298 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO | 303 // - it handles the GpuCommandBufferMsg_InsertSyncPoint message on the IO |
299 // thread, generating the sync point ID and responding immediately, and then | 304 // thread, generating the sync point ID and responding immediately, and then |
300 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message | 305 // posting a task to insert the GpuCommandBufferMsg_RetireSyncPoint message |
301 // into the channel's queue. | 306 // into the channel's queue. |
302 // - it generates mailbox names for clients of the GPU process on the IO thread. | 307 // - it generates mailbox names for clients of the GPU process on the IO thread. |
303 class GpuChannelMessageFilter : public IPC::MessageFilter { | 308 class GpuChannelMessageFilter : public IPC::MessageFilter { |
304 public: | 309 public: |
305 GpuChannelMessageFilter(GpuChannelMessageQueue* message_queue, | 310 GpuChannelMessageFilter(const base::WeakPtr<GpuChannel>& gpu_channel, |
| 311 GpuChannelMessageQueue* message_queue, |
306 gpu::SyncPointManager* sync_point_manager, | 312 gpu::SyncPointManager* sync_point_manager, |
307 base::SingleThreadTaskRunner* task_runner, | 313 base::SingleThreadTaskRunner* task_runner, |
308 bool future_sync_points); | 314 bool future_sync_points); |
309 | 315 |
310 // IPC::MessageFilter implementation. | 316 // IPC::MessageFilter implementation. |
311 void OnFilterAdded(IPC::Sender* sender) override; | 317 void OnFilterAdded(IPC::Sender* sender) override; |
312 void OnFilterRemoved() override; | 318 void OnFilterRemoved() override; |
313 void OnChannelConnected(int32 peer_pid) override; | 319 void OnChannelConnected(int32 peer_pid) override; |
314 void OnChannelError() override; | 320 void OnChannelError() override; |
315 void OnChannelClosing() override; | 321 void OnChannelClosing() override; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 void TransitionToChecking(); | 361 void TransitionToChecking(); |
356 void TransitionToPreempting(); | 362 void TransitionToPreempting(); |
357 void TransitionToWouldPreemptDescheduled(); | 363 void TransitionToWouldPreemptDescheduled(); |
358 | 364 |
359 PreemptionState preemption_state_; | 365 PreemptionState preemption_state_; |
360 | 366 |
361 // Maximum amount of time that we can spend in PREEMPTING. | 367 // Maximum amount of time that we can spend in PREEMPTING. |
362 // It is reset when we transition to IDLE. | 368 // It is reset when we transition to IDLE. |
363 base::TimeDelta max_preemption_time_; | 369 base::TimeDelta max_preemption_time_; |
364 | 370 |
| 371 base::WeakPtr<GpuChannel> gpu_channel_; |
365 // The message_queue_ is used to handle messages on the main thread. | 372 // The message_queue_ is used to handle messages on the main thread. |
366 scoped_refptr<GpuChannelMessageQueue> message_queue_; | 373 scoped_refptr<GpuChannelMessageQueue> message_queue_; |
367 IPC::Sender* sender_; | 374 IPC::Sender* sender_; |
368 base::ProcessId peer_pid_; | 375 base::ProcessId peer_pid_; |
369 gpu::SyncPointManager* sync_point_manager_; | 376 gpu::SyncPointManager* sync_point_manager_; |
370 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 377 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
371 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; | 378 scoped_refptr<gpu::PreemptionFlag> preempting_flag_; |
372 std::vector<scoped_refptr<IPC::MessageFilter>> channel_filters_; | 379 std::vector<scoped_refptr<IPC::MessageFilter>> channel_filters_; |
373 | 380 |
374 // This timer is created and destroyed on the IO thread. | 381 // This timer is created and destroyed on the IO thread. |
375 scoped_ptr<base::OneShotTimer<GpuChannelMessageFilter>> timer_; | 382 scoped_ptr<base::OneShotTimer<GpuChannelMessageFilter>> timer_; |
376 | 383 |
377 bool a_stub_is_descheduled_; | 384 bool a_stub_is_descheduled_; |
378 | 385 |
379 // True if this channel can create future sync points. | 386 // True if this channel can create future sync points. |
380 bool future_sync_points_; | 387 bool future_sync_points_; |
381 | |
382 // This number is only ever incremented/read on the IO thread. | |
383 static uint32_t global_order_counter_; | |
384 }; | 388 }; |
385 | 389 |
386 struct GpuChannelMessage { | 390 struct GpuChannelMessage { |
387 uint32_t order_number; | 391 uint32_t order_number; |
388 base::TimeTicks time_received; | 392 base::TimeTicks time_received; |
389 IPC::Message message; | 393 IPC::Message message; |
390 | 394 |
391 // TODO(dyen): Temporary sync point data, remove once new sync point lands. | 395 // TODO(dyen): Temporary sync point data, remove once new sync point lands. |
392 bool retire_sync_point; | 396 bool retire_sync_point; |
393 uint32 sync_point; | 397 uint32 sync_point; |
394 | 398 |
395 GpuChannelMessage(uint32_t order_num, const IPC::Message& msg) | 399 GpuChannelMessage(const IPC::Message& msg) |
396 : order_number(order_num), | 400 : order_number(0), |
397 time_received(base::TimeTicks::Now()), | 401 time_received(base::TimeTicks()), |
398 message(msg), | 402 message(msg), |
399 retire_sync_point(false), | 403 retire_sync_point(false), |
400 sync_point(0) {} | 404 sync_point(0) {} |
401 | 405 |
402 private: | 406 private: |
403 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage); | 407 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage); |
404 }; | 408 }; |
405 | 409 |
406 class GpuChannelMessageQueue | 410 class GpuChannelMessageQueue |
407 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> { | 411 : public base::RefCountedThreadSafe<GpuChannelMessageQueue> { |
408 public: | 412 public: |
409 static scoped_refptr<GpuChannelMessageQueue> Create( | 413 static scoped_refptr<GpuChannelMessageQueue> Create( |
410 const base::WeakPtr<GpuChannel>& gpu_channel, | 414 const base::WeakPtr<GpuChannel>& gpu_channel, |
411 base::SingleThreadTaskRunner* task_runner); | 415 base::SingleThreadTaskRunner* task_runner); |
412 | 416 |
413 // Returns the global order number for the last processed IPC message. | 417 // Returns the global order number for the last processed IPC message. |
414 uint32_t GetUnprocessedOrderNum() const; | 418 uint32_t GetUnprocessedOrderNum() const; |
415 | 419 |
416 // Returns the global order number for the last unprocessed IPC message. | 420 // Returns the global order number for the last unprocessed IPC message. |
417 uint32_t processed_order_num() const { return processed_order_num_; } | 421 uint32_t processed_order_num() const { return processed_order_num_; } |
418 | 422 |
419 bool HasQueuedMessages() const; | 423 bool HasQueuedMessages() const; |
420 | 424 |
421 base::TimeTicks GetNextMessageTimeTick() const; | 425 base::TimeTicks GetNextMessageTimeTick() const; |
422 | 426 |
423 GpuChannelMessage* GetNextMessage() const; | 427 GpuChannelMessage* GetNextMessage() const; |
424 | 428 |
425 // Should be called after a message returned by GetNextMessage is processed. | 429 // Should be called after a message returned by GetNextMessage is processed. |
426 // Returns true if there are more messages on the queue. | 430 // Returns true if there are more messages on the queue. |
427 bool MessageProcessed(uint32_t order_number); | 431 bool MessageProcessed(); |
428 | 432 |
429 void PushBackMessage(uint32_t order_number, const IPC::Message& message); | 433 void PushBackMessage(const IPC::Message& message); |
430 | 434 |
431 bool GenerateSyncPointMessage(gpu::SyncPointManager* sync_point_manager, | 435 bool GenerateSyncPointMessage(gpu::SyncPointManager* sync_point_manager, |
432 uint32_t order_number, | |
433 const IPC::Message& message, | 436 const IPC::Message& message, |
434 bool retire_sync_point, | 437 bool retire_sync_point, |
435 uint32_t* sync_point_number); | 438 uint32_t* sync_point_number); |
436 | 439 |
437 void DeleteAndDisableMessages(GpuChannelManager* gpu_channel_manager); | 440 void DeleteAndDisableMessages(GpuChannelManager* gpu_channel_manager); |
438 | 441 |
439 private: | 442 private: |
440 friend class base::RefCountedThreadSafe<GpuChannelMessageQueue>; | 443 friend class base::RefCountedThreadSafe<GpuChannelMessageQueue>; |
441 | 444 |
442 GpuChannelMessageQueue(const base::WeakPtr<GpuChannel>& gpu_channel, | 445 GpuChannelMessageQueue(const base::WeakPtr<GpuChannel>& gpu_channel, |
443 base::SingleThreadTaskRunner* task_runner); | 446 base::SingleThreadTaskRunner* task_runner); |
444 ~GpuChannelMessageQueue(); | 447 ~GpuChannelMessageQueue(); |
445 | 448 |
446 void ScheduleHandleMessage(); | 449 void ScheduleHandleMessage(); |
447 | 450 |
448 void PushMessageHelper(scoped_ptr<GpuChannelMessage> msg); | 451 void PushMessageHelper(scoped_ptr<GpuChannelMessage> msg); |
449 | 452 |
450 bool HasQueuedMessagesHelper() const; | 453 // This number is only ever incremented/read on the IO thread. |
| 454 static uint32_t global_order_counter_; |
451 | 455 |
452 bool enabled_; | 456 bool enabled_; |
453 | 457 |
454 // Highest IPC order number seen, set when queued on the IO thread. | 458 // Highest IPC order number seen, set when queued on the IO thread. |
455 uint32_t unprocessed_order_num_; | 459 uint32_t unprocessed_order_num_; |
456 // Both deques own the messages. | 460 // Both deques own the messages. |
457 std::deque<GpuChannelMessage*> channel_messages_; | 461 std::deque<GpuChannelMessage*> channel_messages_; |
458 std::deque<GpuChannelMessage*> out_of_order_messages_; | |
459 | 462 |
460 // This lock protects enabled_, unprocessed_order_num_, and both deques. | 463 // This lock protects enabled_, unprocessed_order_num_, and channel_messages_. |
461 mutable base::Lock channel_messages_lock_; | 464 mutable base::Lock channel_messages_lock_; |
462 | 465 |
463 // Last finished IPC order number. Not protected by a lock as it's only | 466 // Last finished IPC order number. Not protected by a lock as it's only |
464 // accessed on the main thread. | 467 // accessed on the main thread. |
465 uint32_t processed_order_num_; | 468 uint32_t processed_order_num_; |
466 | 469 |
467 base::WeakPtr<GpuChannel> gpu_channel_; | 470 base::WeakPtr<GpuChannel> gpu_channel_; |
468 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 471 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
469 | 472 |
470 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue); | 473 DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageQueue); |
471 }; | 474 }; |
472 | 475 |
473 } // namespace content | 476 } // namespace content |
474 | 477 |
475 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ | 478 #endif // CONTENT_COMMON_GPU_GPU_CHANNEL_H_ |
OLD | NEW |