| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CC_WORKER_POOL_H_ | 5 #ifndef CC_WORKER_POOL_H_ |
| 6 #define CC_WORKER_POOL_H_ | 6 #define CC_WORKER_POOL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "cc/cc_export.h" | 14 #include "cc/cc_export.h" |
| 15 #include "cc/scoped_ptr_deque.h" | 15 #include "cc/scoped_ptr_deque.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 struct RenderingStats; | |
| 19 | 18 |
| 20 namespace internal { | 19 namespace internal { |
| 21 | 20 |
| 22 class WorkerPoolTask { | 21 class WorkerPoolTask { |
| 23 public: | 22 public: |
| 24 virtual ~WorkerPoolTask(); | 23 virtual ~WorkerPoolTask(); |
| 25 | 24 |
| 26 virtual bool IsCheap() = 0; | 25 virtual bool IsCheap() = 0; |
| 27 | 26 |
| 28 // Called before running the task on a thread that isn't the origin thread. | 27 // Called before running the task on a thread that isn't the origin thread. |
| 29 virtual void WillRunOnThread(unsigned thread_index) = 0; | 28 virtual void WillRunOnThread(unsigned thread_index) = 0; |
| 30 | 29 |
| 31 virtual void Run(RenderingStats* rendering_stats) = 0; | 30 virtual void Run() = 0; |
| 32 | 31 |
| 33 void DidComplete(); | 32 void DidComplete(); |
| 34 | 33 |
| 35 protected: | 34 protected: |
| 36 WorkerPoolTask(const base::Closure& reply); | 35 WorkerPoolTask(const base::Closure& reply); |
| 37 | 36 |
| 38 const base::Closure reply_; | 37 const base::Closure reply_; |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 } // namespace internal | 40 } // namespace internal |
| 42 | 41 |
| 43 class CC_EXPORT WorkerPoolClient { | 42 class CC_EXPORT WorkerPoolClient { |
| 44 public: | 43 public: |
| 45 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() = 0; | 44 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() = 0; |
| 46 | 45 |
| 47 protected: | 46 protected: |
| 48 virtual ~WorkerPoolClient() {} | 47 virtual ~WorkerPoolClient() {} |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 // A worker thread pool that runs rendering tasks and guarantees completion | 50 // A worker thread pool that runs rendering tasks and guarantees completion |
| 52 // of all pending tasks at shutdown. | 51 // of all pending tasks at shutdown. |
| 53 class WorkerPool { | 52 class WorkerPool { |
| 54 public: | 53 public: |
| 55 typedef base::Callback<void(RenderingStats*)> Callback; | 54 typedef base::Callback<void()> Callback; |
| 56 | 55 |
| 57 virtual ~WorkerPool(); | 56 virtual ~WorkerPool(); |
| 58 | 57 |
| 59 static scoped_ptr<WorkerPool> Create( | 58 static scoped_ptr<WorkerPool> Create( |
| 60 WorkerPoolClient* client, | 59 WorkerPoolClient* client, |
| 61 size_t num_threads, | 60 size_t num_threads, |
| 62 base::TimeDelta check_for_completed_tasks_delay, | 61 base::TimeDelta check_for_completed_tasks_delay, |
| 63 const std::string& thread_name_prefix) { | 62 const std::string& thread_name_prefix) { |
| 64 return make_scoped_ptr(new WorkerPool(client, | 63 return make_scoped_ptr(new WorkerPool(client, |
| 65 num_threads, | 64 num_threads, |
| 66 check_for_completed_tasks_delay, | 65 check_for_completed_tasks_delay, |
| 67 thread_name_prefix)); | 66 thread_name_prefix)); |
| 68 } | 67 } |
| 69 | 68 |
| 70 // Tells the worker pool to shutdown and returns once all pending tasks have | 69 // Tells the worker pool to shutdown and returns once all pending tasks have |
| 71 // completed. | 70 // completed. |
| 72 void Shutdown(); | 71 void Shutdown(); |
| 73 | 72 |
| 74 // Posts |task| to worker pool. On completion, |reply| | 73 // Posts |task| to worker pool. On completion, |reply| |
| 75 // is posted to the thread that called PostTaskAndReply(). | 74 // is posted to the thread that called PostTaskAndReply(). |
| 76 void PostTaskAndReply(const Callback& task, const base::Closure& reply); | 75 void PostTaskAndReply(const Callback& task, const base::Closure& reply); |
| 77 | 76 |
| 78 // Set time limit for running cheap tasks. | 77 // Set time limit for running cheap tasks. |
| 79 void SetRunCheapTasksTimeLimit(base::TimeTicks run_cheap_tasks_time_limit); | 78 void SetRunCheapTasksTimeLimit(base::TimeTicks run_cheap_tasks_time_limit); |
| 80 | 79 |
| 81 // Toggle rendering stats collection. | |
| 82 void SetRecordRenderingStats(bool record_rendering_stats); | |
| 83 | |
| 84 // Collect rendering stats of all completed tasks. | |
| 85 void GetRenderingStats(RenderingStats* stats); | |
| 86 | |
| 87 protected: | 80 protected: |
| 88 WorkerPool(WorkerPoolClient* client, | 81 WorkerPool(WorkerPoolClient* client, |
| 89 size_t num_threads, | 82 size_t num_threads, |
| 90 base::TimeDelta check_for_completed_tasks_delay, | 83 base::TimeDelta check_for_completed_tasks_delay, |
| 91 const std::string& thread_name_prefix); | 84 const std::string& thread_name_prefix); |
| 92 | 85 |
| 93 void PostTask(scoped_ptr<internal::WorkerPoolTask> task); | 86 void PostTask(scoped_ptr<internal::WorkerPoolTask> task); |
| 94 | 87 |
| 95 private: | 88 private: |
| 96 class Inner; | 89 class Inner; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 122 | 115 |
| 123 // Hide the gory details of the worker pool in |inner_|. | 116 // Hide the gory details of the worker pool in |inner_|. |
| 124 const scoped_ptr<Inner> inner_; | 117 const scoped_ptr<Inner> inner_; |
| 125 | 118 |
| 126 DISALLOW_COPY_AND_ASSIGN(WorkerPool); | 119 DISALLOW_COPY_AND_ASSIGN(WorkerPool); |
| 127 }; | 120 }; |
| 128 | 121 |
| 129 } // namespace cc | 122 } // namespace cc |
| 130 | 123 |
| 131 #endif // CC_WORKER_POOL_H_ | 124 #endif // CC_WORKER_POOL_H_ |
| OLD | NEW |