Chromium Code Reviews| 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_synthetic_delay.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 // Synthetic delay for raster tasks that are required for activation. Global to | |
| 19 // avoid static initializer on critical path. | |
| 20 struct RasterRequiredForActivationSyntheticDelayInitializer { | |
| 21 RasterRequiredForActivationSyntheticDelayInitializer() | |
| 22 : delay(base::debug::TraceEventSyntheticDelay::Lookup( | |
| 23 "cc.RasterRequiredForActivation")) {} | |
| 24 base::debug::TraceEventSyntheticDelay* delay; | |
| 25 }; | |
| 26 static base::LazyInstance<RasterRequiredForActivationSyntheticDelayInitializer> | |
| 27 g_raster_required_for_activation_delay = LAZY_INSTANCE_INITIALIZER; | |
| 28 | |
| 29 class RasterTaskGraphRunner : public TaskGraphRunner, | 18 class RasterTaskGraphRunner : public TaskGraphRunner, |
| 30 public base::DelegateSimpleThread::Delegate { | 19 public base::DelegateSimpleThread::Delegate { |
| 31 public: | 20 public: |
| 32 RasterTaskGraphRunner() { | 21 RasterTaskGraphRunner() |
| 22 : trace_event_synthetic_delay_( | |
| 23 base::debug::TraceEventSyntheticDelay::Lookup( | |
| 24 "cc.RasterRequiredForActivation")) { | |
| 33 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); | 25 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); |
| 34 while (workers_.size() < num_threads) { | 26 while (workers_.size() < num_threads) { |
| 35 scoped_ptr<base::DelegateSimpleThread> worker = | 27 scoped_ptr<base::DelegateSimpleThread> worker = |
| 36 make_scoped_ptr(new base::DelegateSimpleThread( | 28 make_scoped_ptr(new base::DelegateSimpleThread( |
| 37 this, | 29 this, |
| 38 base::StringPrintf("CompositorRasterWorker%u", | 30 base::StringPrintf("CompositorRasterWorker%u", |
| 39 static_cast<unsigned>(workers_.size() + 1)) | 31 static_cast<unsigned>(workers_.size() + 1)) |
| 40 .c_str())); | 32 .c_str())); |
| 41 worker->Start(); | 33 worker->Start(); |
| 42 #if defined(OS_ANDROID) || defined(OS_LINUX) | 34 #if defined(OS_ANDROID) || defined(OS_LINUX) |
| 43 worker->SetThreadPriority(base::kThreadPriority_Background); | 35 worker->SetThreadPriority(base::kThreadPriority_Background); |
| 44 #endif | 36 #endif |
| 45 workers_.push_back(worker.Pass()); | 37 workers_.push_back(worker.Pass()); |
| 46 } | 38 } |
| 47 } | 39 } |
| 48 | 40 |
| 49 virtual ~RasterTaskGraphRunner() { NOTREACHED(); } | 41 virtual ~RasterTaskGraphRunner() { NOTREACHED(); } |
| 50 | 42 |
| 43 base::debug::TraceEventSyntheticDelay* trace_event_synthetic_delay() const { | |
| 44 return trace_event_synthetic_delay_; | |
| 45 } | |
| 46 | |
| 51 private: | 47 private: |
| 52 // Overridden from base::DelegateSimpleThread::Delegate: | 48 // Overridden from base::DelegateSimpleThread::Delegate: |
| 53 virtual void Run() OVERRIDE { | 49 virtual void Run() OVERRIDE { |
| 54 TaskGraphRunner::Run(); | 50 TaskGraphRunner::Run(); |
| 55 } | 51 } |
| 56 | 52 |
| 57 ScopedPtrDeque<base::DelegateSimpleThread> workers_; | 53 ScopedPtrDeque<base::DelegateSimpleThread> workers_; |
| 54 base::debug::TraceEventSyntheticDelay* trace_event_synthetic_delay_; | |
|
reveman
2014/08/27 00:34:37
I think |synthetic_delay_| is verbose enough.
boliu
2014/08/27 01:14:49
Done.
| |
| 58 }; | 55 }; |
| 59 | 56 |
| 60 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = | 57 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = |
| 61 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
| 62 | 59 |
| 63 const int kDefaultNumRasterThreads = 1; | 60 const int kDefaultNumRasterThreads = 1; |
| 64 | 61 |
| 65 int g_num_raster_threads = 0; | 62 int g_num_raster_threads = 0; |
| 66 | 63 |
| 67 class RasterFinishedTaskImpl : public RasterizerTask { | 64 class RasterFinishedTaskImpl : public RasterizerTask { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 96 | 93 |
| 97 DISALLOW_COPY_AND_ASSIGN(RasterFinishedTaskImpl); | 94 DISALLOW_COPY_AND_ASSIGN(RasterFinishedTaskImpl); |
| 98 }; | 95 }; |
| 99 | 96 |
| 100 class RasterRequiredForActivationFinishedTaskImpl | 97 class RasterRequiredForActivationFinishedTaskImpl |
| 101 : public RasterFinishedTaskImpl { | 98 : public RasterFinishedTaskImpl { |
| 102 public: | 99 public: |
| 103 RasterRequiredForActivationFinishedTaskImpl( | 100 RasterRequiredForActivationFinishedTaskImpl( |
| 104 base::SequencedTaskRunner* task_runner, | 101 base::SequencedTaskRunner* task_runner, |
| 105 const base::Closure& on_raster_finished_callback, | 102 const base::Closure& on_raster_finished_callback, |
| 106 size_t tasks_required_for_activation_count) | 103 size_t tasks_required_for_activation_count, |
| 104 base::debug::TraceEventSyntheticDelay* delay) | |
| 107 : RasterFinishedTaskImpl(task_runner, on_raster_finished_callback), | 105 : RasterFinishedTaskImpl(task_runner, on_raster_finished_callback), |
| 106 delay_(delay), | |
| 108 tasks_required_for_activation_count_( | 107 tasks_required_for_activation_count_( |
| 109 tasks_required_for_activation_count) { | 108 tasks_required_for_activation_count) { |
| 110 if (tasks_required_for_activation_count_) { | 109 if (tasks_required_for_activation_count_) { |
| 111 g_raster_required_for_activation_delay.Get().delay->BeginParallel( | 110 delay_->BeginParallel(&activation_delay_end_time_); |
| 112 &activation_delay_end_time_); | |
| 113 } | 111 } |
| 114 } | 112 } |
| 115 | 113 |
| 116 // Overridden from Task: | 114 // Overridden from Task: |
| 117 virtual void RunOnWorkerThread() OVERRIDE { | 115 virtual void RunOnWorkerThread() OVERRIDE { |
| 118 TRACE_EVENT0( | 116 TRACE_EVENT0( |
| 119 "cc", "RasterRequiredForActivationFinishedTaskImpl::RunOnWorkerThread"); | 117 "cc", "RasterRequiredForActivationFinishedTaskImpl::RunOnWorkerThread"); |
| 120 | 118 |
| 121 if (tasks_required_for_activation_count_) { | 119 if (tasks_required_for_activation_count_) { |
| 122 g_raster_required_for_activation_delay.Get().delay->EndParallel( | 120 delay_->EndParallel(activation_delay_end_time_); |
| 123 activation_delay_end_time_); | |
| 124 } | 121 } |
| 125 RasterFinished(); | 122 RasterFinished(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 private: | 125 private: |
| 129 virtual ~RasterRequiredForActivationFinishedTaskImpl() {} | 126 virtual ~RasterRequiredForActivationFinishedTaskImpl() {} |
| 130 | 127 |
| 128 base::debug::TraceEventSyntheticDelay* delay_; | |
|
reveman
2014/08/27 00:34:37
How about just using g_task_graph_runner.Get().syn
boliu
2014/08/27 01:14:49
Done.
| |
| 131 base::TimeTicks activation_delay_end_time_; | 129 base::TimeTicks activation_delay_end_time_; |
| 132 const size_t tasks_required_for_activation_count_; | 130 const size_t tasks_required_for_activation_count_; |
| 133 | 131 |
| 134 DISALLOW_COPY_AND_ASSIGN(RasterRequiredForActivationFinishedTaskImpl); | 132 DISALLOW_COPY_AND_ASSIGN(RasterRequiredForActivationFinishedTaskImpl); |
| 135 }; | 133 }; |
| 136 | 134 |
| 137 } // namespace | 135 } // namespace |
| 138 | 136 |
| 139 // This allows an external rasterize on-demand system to run raster tasks | 137 // This allows an external rasterize on-demand system to run raster tasks |
| 140 // with highest priority using the same task graph runner instance. | 138 // with highest priority using the same task graph runner instance. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 | 182 |
| 185 // static | 183 // static |
| 186 scoped_refptr<RasterizerTask> | 184 scoped_refptr<RasterizerTask> |
| 187 RasterWorkerPool::CreateRasterRequiredForActivationFinishedTask( | 185 RasterWorkerPool::CreateRasterRequiredForActivationFinishedTask( |
| 188 size_t tasks_required_for_activation_count, | 186 size_t tasks_required_for_activation_count, |
| 189 base::SequencedTaskRunner* task_runner, | 187 base::SequencedTaskRunner* task_runner, |
| 190 const base::Closure& on_raster_finished_callback) { | 188 const base::Closure& on_raster_finished_callback) { |
| 191 return make_scoped_refptr(new RasterRequiredForActivationFinishedTaskImpl( | 189 return make_scoped_refptr(new RasterRequiredForActivationFinishedTaskImpl( |
| 192 task_runner, | 190 task_runner, |
| 193 on_raster_finished_callback, | 191 on_raster_finished_callback, |
| 194 tasks_required_for_activation_count)); | 192 tasks_required_for_activation_count, |
| 193 g_task_graph_runner.Get().trace_event_synthetic_delay())); | |
| 195 } | 194 } |
| 196 | 195 |
| 197 // static | 196 // static |
| 198 void RasterWorkerPool::ScheduleTasksOnOriginThread(RasterizerTaskClient* client, | 197 void RasterWorkerPool::ScheduleTasksOnOriginThread(RasterizerTaskClient* client, |
| 199 TaskGraph* graph) { | 198 TaskGraph* graph) { |
| 200 TRACE_EVENT0("cc", "Rasterizer::ScheduleTasksOnOriginThread"); | 199 TRACE_EVENT0("cc", "Rasterizer::ScheduleTasksOnOriginThread"); |
| 201 | 200 |
| 202 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); | 201 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); |
| 203 it != graph->nodes.end(); | 202 it != graph->nodes.end(); |
| 204 ++it) { | 203 ++it) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (decode_it == graph->nodes.end()) | 252 if (decode_it == graph->nodes.end()) |
| 254 InsertNodeForTask(graph, decode_task, priority, 0u); | 253 InsertNodeForTask(graph, decode_task, priority, 0u); |
| 255 | 254 |
| 256 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); | 255 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); |
| 257 } | 256 } |
| 258 | 257 |
| 259 InsertNodeForTask(graph, raster_task, priority, dependencies); | 258 InsertNodeForTask(graph, raster_task, priority, dependencies); |
| 260 } | 259 } |
| 261 | 260 |
| 262 } // namespace cc | 261 } // namespace cc |
| OLD | NEW |