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 #include "cc/resources/raster_worker_pool.h" | 5 #include "cc/resources/raster_worker_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event_synthetic_delay.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
13 #include "cc/base/scoped_ptr_deque.h" | 13 #include "cc/base/scoped_ptr_deque.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 namespace { | 16 namespace { |
17 | 17 |
18 class RasterTaskGraphRunner : public TaskGraphRunner, | 18 class RasterTaskGraphRunner : public TaskGraphRunner, |
19 public base::DelegateSimpleThread::Delegate { | 19 public base::DelegateSimpleThread::Delegate { |
20 public: | 20 public: |
21 RasterTaskGraphRunner() | 21 RasterTaskGraphRunner() { |
22 : synthetic_delay_(base::debug::TraceEventSyntheticDelay::Lookup( | |
23 "cc.RasterRequiredForActivation")) { | |
24 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); | 22 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); |
25 while (workers_.size() < num_threads) { | 23 while (workers_.size() < num_threads) { |
26 scoped_ptr<base::DelegateSimpleThread> worker = | 24 scoped_ptr<base::DelegateSimpleThread> worker = |
27 make_scoped_ptr(new base::DelegateSimpleThread( | 25 make_scoped_ptr(new base::DelegateSimpleThread( |
28 this, | 26 this, |
29 base::StringPrintf("CompositorRasterWorker%u", | 27 base::StringPrintf("CompositorRasterWorker%u", |
30 static_cast<unsigned>(workers_.size() + 1)) | 28 static_cast<unsigned>(workers_.size() + 1)) |
31 .c_str())); | 29 .c_str())); |
32 worker->Start(); | 30 worker->Start(); |
33 #if defined(OS_ANDROID) || defined(OS_LINUX) | 31 #if defined(OS_ANDROID) || defined(OS_LINUX) |
34 worker->SetThreadPriority(base::kThreadPriority_Background); | 32 worker->SetThreadPriority(base::kThreadPriority_Background); |
35 #endif | 33 #endif |
36 workers_.push_back(worker.Pass()); | 34 workers_.push_back(worker.Pass()); |
37 } | 35 } |
38 } | 36 } |
39 | 37 |
40 virtual ~RasterTaskGraphRunner() { NOTREACHED(); } | 38 virtual ~RasterTaskGraphRunner() { NOTREACHED(); } |
41 | 39 |
42 base::debug::TraceEventSyntheticDelay* synthetic_delay() { | |
43 return synthetic_delay_; | |
44 } | |
45 | |
46 private: | 40 private: |
47 // Overridden from base::DelegateSimpleThread::Delegate: | 41 // Overridden from base::DelegateSimpleThread::Delegate: |
48 virtual void Run() OVERRIDE { | 42 virtual void Run() OVERRIDE { |
49 TaskGraphRunner::Run(); | 43 TaskGraphRunner::Run(); |
50 } | 44 } |
51 | 45 |
52 ScopedPtrDeque<base::DelegateSimpleThread> workers_; | 46 ScopedPtrDeque<base::DelegateSimpleThread> workers_; |
53 base::debug::TraceEventSyntheticDelay* synthetic_delay_; | |
54 }; | 47 }; |
55 | 48 |
56 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = | 49 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = |
57 LAZY_INSTANCE_INITIALIZER; | 50 LAZY_INSTANCE_INITIALIZER; |
58 | 51 |
59 const int kDefaultNumRasterThreads = 1; | 52 const int kDefaultNumRasterThreads = 1; |
60 | 53 |
61 int g_num_raster_threads = 0; | 54 int g_num_raster_threads = 0; |
62 | 55 |
63 class RasterFinishedTaskImpl : public RasterizerTask { | 56 class RasterFinishedTaskImpl : public RasterizerTask { |
(...skipping 22 matching lines...) Expand all Loading... |
86 task_runner_->PostTask(FROM_HERE, on_raster_finished_callback_); | 79 task_runner_->PostTask(FROM_HERE, on_raster_finished_callback_); |
87 } | 80 } |
88 | 81 |
89 private: | 82 private: |
90 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 83 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
91 const base::Closure on_raster_finished_callback_; | 84 const base::Closure on_raster_finished_callback_; |
92 | 85 |
93 DISALLOW_COPY_AND_ASSIGN(RasterFinishedTaskImpl); | 86 DISALLOW_COPY_AND_ASSIGN(RasterFinishedTaskImpl); |
94 }; | 87 }; |
95 | 88 |
96 class RasterRequiredForActivationFinishedTaskImpl | |
97 : public RasterFinishedTaskImpl { | |
98 public: | |
99 RasterRequiredForActivationFinishedTaskImpl( | |
100 base::SequencedTaskRunner* task_runner, | |
101 const base::Closure& on_raster_finished_callback, | |
102 size_t tasks_required_for_activation_count) | |
103 : RasterFinishedTaskImpl(task_runner, on_raster_finished_callback), | |
104 tasks_required_for_activation_count_( | |
105 tasks_required_for_activation_count) { | |
106 if (tasks_required_for_activation_count_) { | |
107 g_task_graph_runner.Get().synthetic_delay()->BeginParallel( | |
108 &activation_delay_end_time_); | |
109 } | |
110 } | |
111 | |
112 // Overridden from Task: | |
113 virtual void RunOnWorkerThread() OVERRIDE { | |
114 TRACE_EVENT0( | |
115 "cc", "RasterRequiredForActivationFinishedTaskImpl::RunOnWorkerThread"); | |
116 | |
117 if (tasks_required_for_activation_count_) { | |
118 g_task_graph_runner.Get().synthetic_delay()->EndParallel( | |
119 activation_delay_end_time_); | |
120 } | |
121 RasterFinished(); | |
122 } | |
123 | |
124 private: | |
125 virtual ~RasterRequiredForActivationFinishedTaskImpl() {} | |
126 | |
127 base::TimeTicks activation_delay_end_time_; | |
128 const size_t tasks_required_for_activation_count_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(RasterRequiredForActivationFinishedTaskImpl); | |
131 }; | |
132 | |
133 } // namespace | 89 } // namespace |
134 | 90 |
135 // This allows an external rasterize on-demand system to run raster tasks | 91 // This allows an external rasterize on-demand system to run raster tasks |
136 // with highest priority using the same task graph runner instance. | 92 // with highest priority using the same task graph runner instance. |
137 unsigned RasterWorkerPool::kOnDemandRasterTaskPriority = 0u; | 93 unsigned RasterWorkerPool::kOnDemandRasterTaskPriority = 0u; |
138 // This allows a micro benchmark system to run tasks with highest priority, | 94 // This allows a micro benchmark system to run tasks with highest priority, |
139 // since it should finish as quickly as possible. | 95 // since it should finish as quickly as possible. |
140 unsigned RasterWorkerPool::kBenchmarkRasterTaskPriority = 0u; | 96 unsigned RasterWorkerPool::kBenchmarkRasterTaskPriority = 0u; |
141 // Task priorities that make sure raster finished tasks run before any | 97 // Task priorities that make sure raster finished tasks run before any |
142 // remaining raster tasks. | 98 // remaining raster tasks. |
(...skipping 29 matching lines...) Expand all Loading... |
172 | 128 |
173 // static | 129 // static |
174 scoped_refptr<RasterizerTask> RasterWorkerPool::CreateRasterFinishedTask( | 130 scoped_refptr<RasterizerTask> RasterWorkerPool::CreateRasterFinishedTask( |
175 base::SequencedTaskRunner* task_runner, | 131 base::SequencedTaskRunner* task_runner, |
176 const base::Closure& on_raster_finished_callback) { | 132 const base::Closure& on_raster_finished_callback) { |
177 return make_scoped_refptr( | 133 return make_scoped_refptr( |
178 new RasterFinishedTaskImpl(task_runner, on_raster_finished_callback)); | 134 new RasterFinishedTaskImpl(task_runner, on_raster_finished_callback)); |
179 } | 135 } |
180 | 136 |
181 // static | 137 // static |
182 scoped_refptr<RasterizerTask> | |
183 RasterWorkerPool::CreateRasterRequiredForActivationFinishedTask( | |
184 size_t tasks_required_for_activation_count, | |
185 base::SequencedTaskRunner* task_runner, | |
186 const base::Closure& on_raster_finished_callback) { | |
187 return make_scoped_refptr(new RasterRequiredForActivationFinishedTaskImpl( | |
188 task_runner, | |
189 on_raster_finished_callback, | |
190 tasks_required_for_activation_count)); | |
191 } | |
192 | |
193 // static | |
194 void RasterWorkerPool::ScheduleTasksOnOriginThread(RasterizerTaskClient* client, | 138 void RasterWorkerPool::ScheduleTasksOnOriginThread(RasterizerTaskClient* client, |
195 TaskGraph* graph) { | 139 TaskGraph* graph) { |
196 TRACE_EVENT0("cc", "Rasterizer::ScheduleTasksOnOriginThread"); | 140 TRACE_EVENT0("cc", "Rasterizer::ScheduleTasksOnOriginThread"); |
197 | 141 |
198 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); | 142 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); |
199 it != graph->nodes.end(); | 143 it != graph->nodes.end(); |
200 ++it) { | 144 ++it) { |
201 TaskGraph::Node& node = *it; | 145 TaskGraph::Node& node = *it; |
202 RasterizerTask* task = static_cast<RasterizerTask*>(node.task); | 146 RasterizerTask* task = static_cast<RasterizerTask*>(node.task); |
203 | 147 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (decode_it == graph->nodes.end()) | 193 if (decode_it == graph->nodes.end()) |
250 InsertNodeForTask(graph, decode_task, priority, 0u); | 194 InsertNodeForTask(graph, decode_task, priority, 0u); |
251 | 195 |
252 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); | 196 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); |
253 } | 197 } |
254 | 198 |
255 InsertNodeForTask(graph, raster_task, priority, dependencies); | 199 InsertNodeForTask(graph, raster_task, priority, dependencies); |
256 } | 200 } |
257 | 201 |
258 } // namespace cc | 202 } // namespace cc |
OLD | NEW |