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

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

Issue 1028333002: Chromium -> Mojo roll. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 months 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
« no previous file with comments | « cc/resources/tile_task_worker_pool.h ('k') | cc/resources/tile_task_worker_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tile_task_worker_pool.h" 5 #include "cc/resources/tile_task_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/lazy_instance.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/threading/simple_thread.h"
12 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
13 #include "cc/base/scoped_ptr_deque.h"
14 #include "cc/resources/raster_source.h" 10 #include "cc/resources/raster_source.h"
15 #include "skia/ext/refptr.h" 11 #include "skia/ext/refptr.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 12 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/core/SkSurface.h" 13 #include "third_party/skia/include/core/SkSurface.h"
18 14
19 namespace cc { 15 namespace cc {
20 namespace { 16 namespace {
21 17
22 base::ThreadPriority g_worker_thread_priority = base::kThreadPriority_Normal;
23
24 class TileTaskGraphRunner : public TaskGraphRunner,
25 public base::DelegateSimpleThread::Delegate {
26 public:
27 TileTaskGraphRunner() {
28 size_t num_threads = TileTaskWorkerPool::GetNumWorkerThreads();
29 while (workers_.size() < num_threads) {
30 scoped_ptr<base::DelegateSimpleThread> worker =
31 make_scoped_ptr(new base::DelegateSimpleThread(
32 this, base::StringPrintf(
33 "CompositorTileWorker%u",
34 static_cast<unsigned>(workers_.size() + 1)).c_str()));
35 worker->Start();
36 worker->SetThreadPriority(g_worker_thread_priority);
37 workers_.push_back(worker.Pass());
38 }
39 }
40
41 ~TileTaskGraphRunner() override { NOTREACHED(); }
42
43 private:
44 // Overridden from base::DelegateSimpleThread::Delegate:
45 void Run() override { TaskGraphRunner::Run(); }
46
47 ScopedPtrDeque<base::DelegateSimpleThread> workers_;
48 };
49
50 base::LazyInstance<TileTaskGraphRunner>::Leaky g_task_graph_runner =
51 LAZY_INSTANCE_INITIALIZER;
52
53 const int kDefaultNumWorkerThreads = 1;
54
55 int g_num_worker_threads = 0;
56
57 class TaskSetFinishedTaskImpl : public TileTask { 18 class TaskSetFinishedTaskImpl : public TileTask {
58 public: 19 public:
59 explicit TaskSetFinishedTaskImpl( 20 explicit TaskSetFinishedTaskImpl(
60 base::SequencedTaskRunner* task_runner, 21 base::SequencedTaskRunner* task_runner,
61 const base::Closure& on_task_set_finished_callback) 22 const base::Closure& on_task_set_finished_callback)
62 : task_runner_(task_runner), 23 : task_runner_(task_runner),
63 on_task_set_finished_callback_(on_task_set_finished_callback) {} 24 on_task_set_finished_callback_(on_task_set_finished_callback) {}
64 25
65 // Overridden from Task: 26 // Overridden from Task:
66 void RunOnWorkerThread() override { 27 void RunOnWorkerThread() override {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // |kTaskSetFinishedTaskPriorityBase + kNumberOfTaskSets|. 61 // |kTaskSetFinishedTaskPriorityBase + kNumberOfTaskSets|.
101 unsigned TileTaskWorkerPool::kTileTaskPriorityBase = 10u; 62 unsigned TileTaskWorkerPool::kTileTaskPriorityBase = 10u;
102 63
103 TileTaskWorkerPool::TileTaskWorkerPool() { 64 TileTaskWorkerPool::TileTaskWorkerPool() {
104 } 65 }
105 66
106 TileTaskWorkerPool::~TileTaskWorkerPool() { 67 TileTaskWorkerPool::~TileTaskWorkerPool() {
107 } 68 }
108 69
109 // static 70 // static
110 void TileTaskWorkerPool::SetNumWorkerThreads(int num_threads) {
111 DCHECK_LT(0, num_threads);
112 DCHECK_EQ(0, g_num_worker_threads);
113
114 g_num_worker_threads = num_threads;
115 }
116
117 // static
118 int TileTaskWorkerPool::GetNumWorkerThreads() {
119 if (!g_num_worker_threads)
120 g_num_worker_threads = kDefaultNumWorkerThreads;
121
122 return g_num_worker_threads;
123 }
124
125 // static
126 void TileTaskWorkerPool::SetWorkerThreadPriority(
127 base::ThreadPriority priority) {
128 g_worker_thread_priority = priority;
129 }
130
131 // static
132 TaskGraphRunner* TileTaskWorkerPool::GetTaskGraphRunner() {
133 return g_task_graph_runner.Pointer();
134 }
135
136 // static
137 scoped_refptr<TileTask> TileTaskWorkerPool::CreateTaskSetFinishedTask( 71 scoped_refptr<TileTask> TileTaskWorkerPool::CreateTaskSetFinishedTask(
138 base::SequencedTaskRunner* task_runner, 72 base::SequencedTaskRunner* task_runner,
139 const base::Closure& on_task_set_finished_callback) { 73 const base::Closure& on_task_set_finished_callback) {
140 return make_scoped_refptr( 74 return make_scoped_refptr(
141 new TaskSetFinishedTaskImpl(task_runner, on_task_set_finished_callback)); 75 new TaskSetFinishedTaskImpl(task_runner, on_task_set_finished_callback));
142 } 76 }
143 77
144 // static 78 // static
145 void TileTaskWorkerPool::ScheduleTasksOnOriginThread(TileTaskClient* client, 79 void TileTaskWorkerPool::ScheduleTasksOnOriginThread(TileTaskClient* client,
146 TaskGraph* graph) { 80 TaskGraph* graph) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the 197 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
264 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728 198 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728
265 // is fixed. 199 // is fixed.
266 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes()); 200 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes());
267 DCHECK_EQ(0u, dst_row_bytes % 4); 201 DCHECK_EQ(0u, dst_row_bytes % 4);
268 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0); 202 bool success = canvas->readPixels(dst_info, memory, dst_row_bytes, 0, 0);
269 DCHECK_EQ(true, success); 203 DCHECK_EQ(true, success);
270 } 204 }
271 205
272 } // namespace cc 206 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_task_worker_pool.h ('k') | cc/resources/tile_task_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698