Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: cc/resources/raster_worker_pool.cc

Issue 786583002: cc: Renaming Rasterizer and RasterWorkerPool interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.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 #include "cc/resources/raster_source.h" 14 #include "cc/resources/raster_source.h"
15 #include "skia/ext/refptr.h" 15 #include "skia/ext/refptr.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/core/SkSurface.h" 17 #include "third_party/skia/include/core/SkSurface.h"
18 18
19 namespace cc { 19 namespace cc {
20 namespace { 20 namespace {
21 21
22 class RasterTaskGraphRunner : public TaskGraphRunner, 22 class RasterTaskGraphRunner : public TaskGraphRunner,
23 public base::DelegateSimpleThread::Delegate { 23 public base::DelegateSimpleThread::Delegate {
24 public: 24 public:
25 RasterTaskGraphRunner() { 25 RasterTaskGraphRunner() {
26 size_t num_threads = RasterWorkerPool::GetNumRasterThreads(); 26 size_t num_threads = TileTaskWorkerPool::GetNumRasterThreads();
27 while (workers_.size() < num_threads) { 27 while (workers_.size() < num_threads) {
28 scoped_ptr<base::DelegateSimpleThread> worker = 28 scoped_ptr<base::DelegateSimpleThread> worker =
29 make_scoped_ptr(new base::DelegateSimpleThread( 29 make_scoped_ptr(new base::DelegateSimpleThread(
30 this, 30 this,
31 base::StringPrintf("CompositorRasterWorker%u", 31 base::StringPrintf("CompositorRasterWorker%u",
32 static_cast<unsigned>(workers_.size() + 1)) 32 static_cast<unsigned>(workers_.size() + 1))
33 .c_str())); 33 .c_str()));
34 worker->Start(); 34 worker->Start();
35 #if defined(OS_ANDROID) || defined(OS_LINUX) 35 #if defined(OS_ANDROID) || defined(OS_LINUX)
36 worker->SetThreadPriority(base::kThreadPriority_Background); 36 worker->SetThreadPriority(base::kThreadPriority_Background);
(...skipping 11 matching lines...) Expand all
48 ScopedPtrDeque<base::DelegateSimpleThread> workers_; 48 ScopedPtrDeque<base::DelegateSimpleThread> workers_;
49 }; 49 };
50 50
51 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner = 51 base::LazyInstance<RasterTaskGraphRunner>::Leaky g_task_graph_runner =
52 LAZY_INSTANCE_INITIALIZER; 52 LAZY_INSTANCE_INITIALIZER;
53 53
54 const int kDefaultNumRasterThreads = 1; 54 const int kDefaultNumRasterThreads = 1;
55 55
56 int g_num_raster_threads = 0; 56 int g_num_raster_threads = 0;
57 57
58 class RasterFinishedTaskImpl : public RasterizerTask { 58 class RasterFinishedTaskImpl : public TileTask {
59 public: 59 public:
60 explicit RasterFinishedTaskImpl( 60 explicit RasterFinishedTaskImpl(
61 base::SequencedTaskRunner* task_runner, 61 base::SequencedTaskRunner* task_runner,
62 const base::Closure& on_raster_finished_callback) 62 const base::Closure& on_raster_finished_callback)
63 : task_runner_(task_runner), 63 : task_runner_(task_runner),
64 on_raster_finished_callback_(on_raster_finished_callback) {} 64 on_raster_finished_callback_(on_raster_finished_callback) {}
65 65
66 // Overridden from Task: 66 // Overridden from Task:
67 void RunOnWorkerThread() override { 67 void RunOnWorkerThread() override {
68 TRACE_EVENT0("cc", "RasterFinishedTaskImpl::RunOnWorkerThread"); 68 TRACE_EVENT0("cc", "RasterFinishedTaskImpl::RunOnWorkerThread");
69 RasterFinished(); 69 RasterFinished();
70 } 70 }
71 71
72 // Overridden from RasterizerTask: 72 // Overridden from TileTask:
73 void ScheduleOnOriginThread(RasterizerTaskClient* client) override {} 73 void ScheduleOnOriginThread(TileTaskClient* client) override {}
74 void CompleteOnOriginThread(RasterizerTaskClient* client) override {} 74 void CompleteOnOriginThread(TileTaskClient* client) override {}
75 void RunReplyOnOriginThread() override {} 75 void RunReplyOnOriginThread() override {}
76 76
77 protected: 77 protected:
78 ~RasterFinishedTaskImpl() override {} 78 ~RasterFinishedTaskImpl() override {}
79 79
80 void RasterFinished() { 80 void RasterFinished() {
81 task_runner_->PostTask(FROM_HERE, on_raster_finished_callback_); 81 task_runner_->PostTask(FROM_HERE, on_raster_finished_callback_);
82 } 82 }
83 83
84 private: 84 private:
85 scoped_refptr<base::SequencedTaskRunner> task_runner_; 85 scoped_refptr<base::SequencedTaskRunner> task_runner_;
86 const base::Closure on_raster_finished_callback_; 86 const base::Closure on_raster_finished_callback_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(RasterFinishedTaskImpl); 88 DISALLOW_COPY_AND_ASSIGN(RasterFinishedTaskImpl);
89 }; 89 };
90 90
91 } // namespace 91 } // namespace
92 92
93 // This allows a micro benchmark system to run tasks with highest priority, 93 // This allows a micro benchmark system to run tasks with highest priority,
94 // since it should finish as quickly as possible. 94 // since it should finish as quickly as possible.
95 unsigned RasterWorkerPool::kBenchmarkRasterTaskPriority = 0u; 95 unsigned TileTaskWorkerPool::kBenchmarkTaskPriority = 0u;
96 // Task priorities that make sure raster finished tasks run before any 96 // Task priorities that make sure raster finished tasks run before any
97 // remaining raster tasks. 97 // remaining raster tasks.
98 unsigned RasterWorkerPool::kRasterFinishedTaskPriority = 1u; 98 unsigned TileTaskWorkerPool::kTaskSetFinishedTaskPriority = 1u;
99 unsigned RasterWorkerPool::kRasterTaskPriorityBase = 2u; 99 unsigned TileTaskWorkerPool::kTileTaskPriorityBase = 2u;
100 100
101 RasterWorkerPool::RasterWorkerPool() {} 101 TileTaskWorkerPool::TileTaskWorkerPool() {
102 }
102 103
103 RasterWorkerPool::~RasterWorkerPool() {} 104 TileTaskWorkerPool::~TileTaskWorkerPool() {
105 }
104 106
105 // static 107 // static
106 void RasterWorkerPool::SetNumRasterThreads(int num_threads) { 108 void TileTaskWorkerPool::SetNumRasterThreads(int num_threads) {
107 DCHECK_LT(0, num_threads); 109 DCHECK_LT(0, num_threads);
108 DCHECK_EQ(0, g_num_raster_threads); 110 DCHECK_EQ(0, g_num_raster_threads);
109 111
110 g_num_raster_threads = num_threads; 112 g_num_raster_threads = num_threads;
111 } 113 }
112 114
113 // static 115 // static
114 int RasterWorkerPool::GetNumRasterThreads() { 116 int TileTaskWorkerPool::GetNumRasterThreads() {
115 if (!g_num_raster_threads) 117 if (!g_num_raster_threads)
116 g_num_raster_threads = kDefaultNumRasterThreads; 118 g_num_raster_threads = kDefaultNumRasterThreads;
117 119
118 return g_num_raster_threads; 120 return g_num_raster_threads;
119 } 121 }
120 122
121 // static 123 // static
122 TaskGraphRunner* RasterWorkerPool::GetTaskGraphRunner() { 124 TaskGraphRunner* TileTaskWorkerPool::GetTaskGraphRunner() {
123 return g_task_graph_runner.Pointer(); 125 return g_task_graph_runner.Pointer();
124 } 126 }
125 127
126 // static 128 // static
127 scoped_refptr<RasterizerTask> RasterWorkerPool::CreateRasterFinishedTask( 129 scoped_refptr<TileTask> TileTaskWorkerPool::CreateTaskSetFinishedTask(
128 base::SequencedTaskRunner* task_runner, 130 base::SequencedTaskRunner* task_runner,
129 const base::Closure& on_raster_finished_callback) { 131 const base::Closure& on_raster_finished_callback) {
130 return make_scoped_refptr( 132 return make_scoped_refptr(
131 new RasterFinishedTaskImpl(task_runner, on_raster_finished_callback)); 133 new RasterFinishedTaskImpl(task_runner, on_raster_finished_callback));
132 } 134 }
133 135
134 // static 136 // static
135 void RasterWorkerPool::ScheduleTasksOnOriginThread(RasterizerTaskClient* client, 137 void TileTaskWorkerPool::ScheduleTasksOnOriginThread(TileTaskClient* client,
136 TaskGraph* graph) { 138 TaskGraph* graph) {
137 TRACE_EVENT0("cc", "Rasterizer::ScheduleTasksOnOriginThread"); 139 TRACE_EVENT0("cc", "TileTaskWorkerPool::ScheduleTasksOnOriginThread");
138 140
139 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); 141 for (TaskGraph::Node::Vector::iterator it = graph->nodes.begin();
140 it != graph->nodes.end(); 142 it != graph->nodes.end();
141 ++it) { 143 ++it) {
142 TaskGraph::Node& node = *it; 144 TaskGraph::Node& node = *it;
143 RasterizerTask* task = static_cast<RasterizerTask*>(node.task); 145 TileTask* task = static_cast<TileTask*>(node.task);
144 146
145 if (!task->HasBeenScheduled()) { 147 if (!task->HasBeenScheduled()) {
146 task->WillSchedule(); 148 task->WillSchedule();
147 task->ScheduleOnOriginThread(client); 149 task->ScheduleOnOriginThread(client);
148 task->DidSchedule(); 150 task->DidSchedule();
149 } 151 }
150 } 152 }
151 } 153 }
152 154
153 // static 155 // static
154 void RasterWorkerPool::InsertNodeForTask(TaskGraph* graph, 156 void TileTaskWorkerPool::InsertNodeForTask(TaskGraph* graph,
155 RasterizerTask* task, 157 TileTask* task,
156 unsigned priority, 158 unsigned priority,
157 size_t dependencies) { 159 size_t dependencies) {
158 DCHECK(std::find_if(graph->nodes.begin(), 160 DCHECK(std::find_if(graph->nodes.begin(),
159 graph->nodes.end(), 161 graph->nodes.end(),
160 TaskGraph::Node::TaskComparator(task)) == 162 TaskGraph::Node::TaskComparator(task)) ==
161 graph->nodes.end()); 163 graph->nodes.end());
162 graph->nodes.push_back(TaskGraph::Node(task, priority, dependencies)); 164 graph->nodes.push_back(TaskGraph::Node(task, priority, dependencies));
163 } 165 }
164 166
165 // static 167 // static
166 void RasterWorkerPool::InsertNodesForRasterTask( 168 void TileTaskWorkerPool::InsertNodesForRasterTask(
167 TaskGraph* graph, 169 TaskGraph* graph,
168 RasterTask* raster_task, 170 RasterTask* raster_task,
169 const ImageDecodeTask::Vector& decode_tasks, 171 const ImageDecodeTask::Vector& decode_tasks,
170 unsigned priority) { 172 unsigned priority) {
171 size_t dependencies = 0u; 173 size_t dependencies = 0u;
172 174
173 // Insert image decode tasks. 175 // Insert image decode tasks.
174 for (ImageDecodeTask::Vector::const_iterator it = decode_tasks.begin(); 176 for (ImageDecodeTask::Vector::const_iterator it = decode_tasks.begin();
175 it != decode_tasks.end(); 177 it != decode_tasks.end();
176 ++it) { 178 ++it) {
(...skipping 30 matching lines...) Expand all
207 case RGB_565: 209 case RGB_565:
208 case ETC1: 210 case ETC1:
209 case RED_8: 211 case RED_8:
210 return false; 212 return false;
211 } 213 }
212 NOTREACHED(); 214 NOTREACHED();
213 return false; 215 return false;
214 } 216 }
215 217
216 // static 218 // static
217 void RasterWorkerPool::PlaybackToMemory(void* memory, 219 void TileTaskWorkerPool::PlaybackToMemory(void* memory,
218 ResourceFormat format, 220 ResourceFormat format,
219 const gfx::Size& size, 221 const gfx::Size& size,
220 int stride, 222 int stride,
221 const RasterSource* raster_source, 223 const RasterSource* raster_source,
222 const gfx::Rect& rect, 224 const gfx::Rect& rect,
223 float scale) { 225 float scale) {
224 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format; 226 DCHECK(IsSupportedPlaybackToMemoryFormat(format)) << format;
225 227
226 // Uses kPremul_SkAlphaType since the result is not known to be opaque. 228 // Uses kPremul_SkAlphaType since the result is not known to be opaque.
227 SkImageInfo info = 229 SkImageInfo info =
228 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType); 230 SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType);
229 SkColorType buffer_color_type = ResourceFormatToSkColorType(format); 231 SkColorType buffer_color_type = ResourceFormatToSkColorType(format);
230 bool needs_copy = buffer_color_type != info.colorType(); 232 bool needs_copy = buffer_color_type != info.colorType();
231 233
232 // Use unknown pixel geometry to disable LCD text. 234 // Use unknown pixel geometry to disable LCD text.
233 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry); 235 SkSurfaceProps surface_props(0, kUnknown_SkPixelGeometry);
(...skipping 23 matching lines...) Expand all
257 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the 259 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
258 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 260 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728
259 // is fixed. 261 // is fixed.
260 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); 262 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes());
261 DCHECK_EQ(0u, dst_row_bytes % 4); 263 DCHECK_EQ(0u, dst_row_bytes % 4);
262 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); 264 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0);
263 DCHECK_EQ(true, success); 265 DCHECK_EQ(true, success);
264 } 266 }
265 267
266 } // namespace cc 268 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698