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 : synthetic_delay_(base::debug::TraceEventSyntheticDelay::Lookup( | |
| 23 "cc.RasterRequiredForActivation")) { | |
| 33 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); | 24 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); |
| 34 while (workers_.size() < num_threads) { | 25 while (workers_.size() < num_threads) { |
| 35 scoped_ptr<base::DelegateSimpleThread> worker = | 26 scoped_ptr<base::DelegateSimpleThread> worker = |
| 36 make_scoped_ptr(new base::DelegateSimpleThread( | 27 make_scoped_ptr(new base::DelegateSimpleThread( |
| 37 this, | 28 this, |
| 38 base::StringPrintf("CompositorRasterWorker%u", | 29 base::StringPrintf("CompositorRasterWorker%u", |
| 39 static_cast<unsigned>(workers_.size() + 1)) | 30 static_cast<unsigned>(workers_.size() + 1)) |
| 40 .c_str())); | 31 .c_str())); |
| 41 worker->Start(); | 32 worker->Start(); |
| 42 #if defined(OS_ANDROID) || defined(OS_LINUX) | 33 #if defined(OS_ANDROID) || defined(OS_LINUX) |
| 43 worker->SetThreadPriority(base::kThreadPriority_Background); | 34 worker->SetThreadPriority(base::kThreadPriority_Background); |
| 44 #endif | 35 #endif |
| 45 workers_.push_back(worker.Pass()); | 36 workers_.push_back(worker.Pass()); |
| 46 } | 37 } |
| 47 } | 38 } |
| 48 | 39 |
| 49 virtual ~RasterTaskGraphRunner() { NOTREACHED(); } | 40 virtual ~RasterTaskGraphRunner() { NOTREACHED(); } |
| 50 | 41 |
| 42 base::debug::TraceEventSyntheticDelay* synthetic_delay() { | |
|
boliu
2014/08/27 01:14:49
Removed const here. Learned today that returning a
| |
| 43 return synthetic_delay_; | |
| 44 } | |
| 45 | |
| 51 private: | 46 private: |
| 52 // Overridden from base::DelegateSimpleThread::Delegate: | 47 // Overridden from base::DelegateSimpleThread::Delegate: |
| 53 virtual void Run() OVERRIDE { | 48 virtual void Run() OVERRIDE { |
| 54 TaskGraphRunner::Run(); | 49 TaskGraphRunner::Run(); |
| 55 } | 50 } |
| 56 | 51 |
| 57 ScopedPtrDeque<base::DelegateSimpleThread> workers_; | 52 ScopedPtrDeque<base::DelegateSimpleThread> workers_; |
| 53 base::debug::TraceEventSyntheticDelay* synthetic_delay_; | |
| 58 }; | 54 }; |
| 59 | 55 |
| 60 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = | 56 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = |
| 61 LAZY_INSTANCE_INITIALIZER; | 57 LAZY_INSTANCE_INITIALIZER; |
| 62 | 58 |
| 63 const int kDefaultNumRasterThreads = 1; | 59 const int kDefaultNumRasterThreads = 1; |
| 64 | 60 |
| 65 int g_num_raster_threads = 0; | 61 int g_num_raster_threads = 0; |
| 66 | 62 |
| 67 class RasterFinishedTaskImpl : public RasterizerTask { | 63 class RasterFinishedTaskImpl : public RasterizerTask { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 : public RasterFinishedTaskImpl { | 97 : public RasterFinishedTaskImpl { |
| 102 public: | 98 public: |
| 103 RasterRequiredForActivationFinishedTaskImpl( | 99 RasterRequiredForActivationFinishedTaskImpl( |
| 104 base::SequencedTaskRunner* task_runner, | 100 base::SequencedTaskRunner* task_runner, |
| 105 const base::Closure& on_raster_finished_callback, | 101 const base::Closure& on_raster_finished_callback, |
| 106 size_t tasks_required_for_activation_count) | 102 size_t tasks_required_for_activation_count) |
| 107 : RasterFinishedTaskImpl(task_runner, on_raster_finished_callback), | 103 : RasterFinishedTaskImpl(task_runner, on_raster_finished_callback), |
| 108 tasks_required_for_activation_count_( | 104 tasks_required_for_activation_count_( |
| 109 tasks_required_for_activation_count) { | 105 tasks_required_for_activation_count) { |
| 110 if (tasks_required_for_activation_count_) { | 106 if (tasks_required_for_activation_count_) { |
| 111 g_raster_required_for_activation_delay.Get().delay->BeginParallel( | 107 g_task_graph_runner.Get().synthetic_delay()->BeginParallel( |
| 112 &activation_delay_end_time_); | 108 &activation_delay_end_time_); |
| 113 } | 109 } |
| 114 } | 110 } |
| 115 | 111 |
| 116 // Overridden from Task: | 112 // Overridden from Task: |
| 117 virtual void RunOnWorkerThread() OVERRIDE { | 113 virtual void RunOnWorkerThread() OVERRIDE { |
| 118 TRACE_EVENT0( | 114 TRACE_EVENT0( |
| 119 "cc", "RasterRequiredForActivationFinishedTaskImpl::RunOnWorkerThread"); | 115 "cc", "RasterRequiredForActivationFinishedTaskImpl::RunOnWorkerThread"); |
| 120 | 116 |
| 121 if (tasks_required_for_activation_count_) { | 117 if (tasks_required_for_activation_count_) { |
| 122 g_raster_required_for_activation_delay.Get().delay->EndParallel( | 118 g_task_graph_runner.Get().synthetic_delay()->EndParallel( |
| 123 activation_delay_end_time_); | 119 activation_delay_end_time_); |
| 124 } | 120 } |
| 125 RasterFinished(); | 121 RasterFinished(); |
| 126 } | 122 } |
| 127 | 123 |
| 128 private: | 124 private: |
| 129 virtual ~RasterRequiredForActivationFinishedTaskImpl() {} | 125 virtual ~RasterRequiredForActivationFinishedTaskImpl() {} |
| 130 | 126 |
| 131 base::TimeTicks activation_delay_end_time_; | 127 base::TimeTicks activation_delay_end_time_; |
| 132 const size_t tasks_required_for_activation_count_; | 128 const size_t tasks_required_for_activation_count_; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (decode_it == graph->nodes.end()) | 249 if (decode_it == graph->nodes.end()) |
| 254 InsertNodeForTask(graph, decode_task, priority, 0u); | 250 InsertNodeForTask(graph, decode_task, priority, 0u); |
| 255 | 251 |
| 256 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); | 252 graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); |
| 257 } | 253 } |
| 258 | 254 |
| 259 InsertNodeForTask(graph, raster_task, priority, dependencies); | 255 InsertNodeForTask(graph, raster_task, priority, dependencies); |
| 260 } | 256 } |
| 261 | 257 |
| 262 } // namespace cc | 258 } // namespace cc |
| OLD | NEW |