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