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 "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "cc/resources/direct_raster_worker_pool.h" | 8 #include "cc/resources/direct_raster_worker_pool.h" |
9 #include "cc/resources/image_raster_worker_pool.h" | 9 #include "cc/resources/image_raster_worker_pool.h" |
10 #include "cc/resources/pixel_buffer_raster_worker_pool.h" | 10 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 public: | 122 public: |
123 PerfDirectRasterWorkerPoolImpl(ResourceProvider* resource_provider, | 123 PerfDirectRasterWorkerPoolImpl(ResourceProvider* resource_provider, |
124 ContextProvider* context_provider) | 124 ContextProvider* context_provider) |
125 : DirectRasterWorkerPool(resource_provider, context_provider) {} | 125 : DirectRasterWorkerPool(resource_provider, context_provider) {} |
126 }; | 126 }; |
127 | 127 |
128 class RasterWorkerPoolPerfTest | 128 class RasterWorkerPoolPerfTest |
129 : public testing::TestWithParam<RasterWorkerPoolType>, | 129 : public testing::TestWithParam<RasterWorkerPoolType>, |
130 public RasterWorkerPoolClient { | 130 public RasterWorkerPoolClient { |
131 public: | 131 public: |
132 class Task : public RasterWorkerPool::Task { | 132 typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > |
133 public: | 133 RasterTaskVector; |
134 typedef std::vector<Task> Vector; | |
135 | |
136 static Task Create() { return Task(new PerfWorkerPoolTaskImpl); } | |
137 | |
138 void AppendTo(internal::WorkerPoolTask::Vector* dependencies) const { | |
139 dependencies->push_back(internal_); | |
140 } | |
141 | |
142 private: | |
143 explicit Task(internal::WorkerPoolTask* task) | |
144 : RasterWorkerPool::Task(task) {} | |
145 }; | |
146 | |
147 class RasterTask : public RasterWorkerPool::RasterTask { | |
148 public: | |
149 typedef std::vector<RasterTask> Vector; | |
150 | |
151 static RasterTask Create(scoped_ptr<ScopedResource> resource, | |
152 const Task::Vector& image_decode_tasks) { | |
153 internal::WorkerPoolTask::Vector dependencies; | |
154 for (Task::Vector::const_iterator it = image_decode_tasks.begin(); | |
155 it != image_decode_tasks.end(); | |
156 ++it) | |
157 it->AppendTo(&dependencies); | |
158 | |
159 return RasterTask( | |
160 new PerfRasterWorkerPoolTaskImpl(resource.Pass(), &dependencies)); | |
161 } | |
162 | |
163 private: | |
164 explicit RasterTask(internal::RasterWorkerPoolTask* task) | |
165 : RasterWorkerPool::RasterTask(task) {} | |
166 }; | |
167 | 134 |
168 RasterWorkerPoolPerfTest() | 135 RasterWorkerPoolPerfTest() |
169 : context_provider_(TestContextProvider::Create()), | 136 : context_provider_(TestContextProvider::Create()), |
170 task_graph_runner_(new PerfTaskGraphRunnerImpl), | 137 task_graph_runner_(new PerfTaskGraphRunnerImpl), |
171 timer_(kWarmupRuns, | 138 timer_(kWarmupRuns, |
172 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 139 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
173 kTimeCheckInterval) { | 140 kTimeCheckInterval) { |
174 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | 141 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); |
175 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 142 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
176 | 143 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 base::MessageLoop::current()->Quit(); | 180 base::MessageLoop::current()->Quit(); |
214 } | 181 } |
215 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE {} | 182 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE {} |
216 | 183 |
217 void RunMessageLoopUntilAllTasksHaveCompleted() { | 184 void RunMessageLoopUntilAllTasksHaveCompleted() { |
218 while (task_graph_runner_->RunTaskForTesting()) | 185 while (task_graph_runner_->RunTaskForTesting()) |
219 continue; | 186 continue; |
220 base::MessageLoop::current()->Run(); | 187 base::MessageLoop::current()->Run(); |
221 } | 188 } |
222 | 189 |
223 void CreateImageDecodeTasks(unsigned num_image_decode_tasks, | 190 void CreateImageDecodeTasks( |
224 Task::Vector* image_decode_tasks) { | 191 unsigned num_image_decode_tasks, |
| 192 internal::WorkerPoolTask::Vector* image_decode_tasks) { |
225 for (unsigned i = 0; i < num_image_decode_tasks; ++i) | 193 for (unsigned i = 0; i < num_image_decode_tasks; ++i) |
226 image_decode_tasks->push_back(Task::Create()); | 194 image_decode_tasks->push_back(new PerfWorkerPoolTaskImpl); |
227 } | 195 } |
228 | 196 |
229 void CreateRasterTasks(unsigned num_raster_tasks, | 197 void CreateRasterTasks( |
230 const Task::Vector& image_decode_tasks, | 198 unsigned num_raster_tasks, |
231 RasterTask::Vector* raster_tasks) { | 199 const internal::WorkerPoolTask::Vector& image_decode_tasks, |
| 200 RasterTaskVector* raster_tasks) { |
232 const gfx::Size size(1, 1); | 201 const gfx::Size size(1, 1); |
233 | 202 |
234 for (unsigned i = 0; i < num_raster_tasks; ++i) { | 203 for (unsigned i = 0; i < num_raster_tasks; ++i) { |
235 scoped_ptr<ScopedResource> resource( | 204 scoped_ptr<ScopedResource> resource( |
236 ScopedResource::Create(resource_provider_.get())); | 205 ScopedResource::Create(resource_provider_.get())); |
237 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); | 206 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); |
238 | 207 |
| 208 internal::WorkerPoolTask::Vector dependencies = image_decode_tasks; |
239 raster_tasks->push_back( | 209 raster_tasks->push_back( |
240 RasterTask::Create(resource.Pass(), image_decode_tasks)); | 210 new PerfRasterWorkerPoolTaskImpl(resource.Pass(), &dependencies)); |
241 } | 211 } |
242 } | 212 } |
243 | 213 |
244 void BuildTaskQueue(RasterWorkerPool::RasterTask::Queue* tasks, | 214 void BuildTaskQueue(RasterTaskQueue* queue, |
245 const RasterTask::Vector& raster_tasks) { | 215 const RasterTaskVector& raster_tasks) { |
246 for (RasterTask::Vector::const_iterator it = raster_tasks.begin(); | 216 for (RasterTaskVector::const_iterator it = raster_tasks.begin(); |
247 it != raster_tasks.end(); | 217 it != raster_tasks.end(); |
248 ++it) | 218 ++it) |
249 tasks->Append(*it, false); | 219 queue->items.push_back(RasterTaskQueue::Item(it->get(), false)); |
250 } | 220 } |
251 | 221 |
252 void RunScheduleTasksTest(const std::string& test_name, | 222 void RunScheduleTasksTest(const std::string& test_name, |
253 unsigned num_raster_tasks, | 223 unsigned num_raster_tasks, |
254 unsigned num_image_decode_tasks) { | 224 unsigned num_image_decode_tasks) { |
255 Task::Vector image_decode_tasks; | 225 internal::WorkerPoolTask::Vector image_decode_tasks; |
256 RasterTask::Vector raster_tasks; | 226 RasterTaskVector raster_tasks; |
257 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 227 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
258 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 228 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); |
259 | 229 |
260 // Avoid unnecessary heap allocations by reusing the same queue. | 230 // Avoid unnecessary heap allocations by reusing the same queue. |
261 RasterWorkerPool::RasterTask::Queue queue; | 231 RasterTaskQueue queue; |
262 | 232 |
263 timer_.Reset(); | 233 timer_.Reset(); |
264 do { | 234 do { |
265 queue.Reset(); | 235 queue.Reset(); |
266 BuildTaskQueue(&queue, raster_tasks); | 236 BuildTaskQueue(&queue, raster_tasks); |
267 raster_worker_pool_->ScheduleTasks(&queue); | 237 raster_worker_pool_->ScheduleTasks(&queue); |
268 raster_worker_pool_->CheckForCompletedTasks(); | 238 raster_worker_pool_->CheckForCompletedTasks(); |
269 timer_.NextLap(); | 239 timer_.NextLap(); |
270 } while (!timer_.HasTimeLimitExpired()); | 240 } while (!timer_.HasTimeLimitExpired()); |
271 | 241 |
272 RasterWorkerPool::RasterTask::Queue empty; | 242 RasterTaskQueue empty; |
273 raster_worker_pool_->ScheduleTasks(&empty); | 243 raster_worker_pool_->ScheduleTasks(&empty); |
274 RunMessageLoopUntilAllTasksHaveCompleted(); | 244 RunMessageLoopUntilAllTasksHaveCompleted(); |
275 | 245 |
276 perf_test::PrintResult("schedule_tasks", | 246 perf_test::PrintResult("schedule_tasks", |
277 "", | 247 "", |
278 test_name, | 248 test_name, |
279 timer_.LapsPerSecond(), | 249 timer_.LapsPerSecond(), |
280 "runs/s", | 250 "runs/s", |
281 true); | 251 true); |
282 } | 252 } |
283 | 253 |
284 void RunScheduleAlternateTasksTest(const std::string& test_name, | 254 void RunScheduleAlternateTasksTest(const std::string& test_name, |
285 unsigned num_raster_tasks, | 255 unsigned num_raster_tasks, |
286 unsigned num_image_decode_tasks) { | 256 unsigned num_image_decode_tasks) { |
287 const size_t kNumVersions = 2; | 257 const size_t kNumVersions = 2; |
288 Task::Vector image_decode_tasks[kNumVersions]; | 258 internal::WorkerPoolTask::Vector image_decode_tasks[kNumVersions]; |
289 RasterTask::Vector raster_tasks[kNumVersions]; | 259 RasterTaskVector raster_tasks[kNumVersions]; |
290 for (size_t i = 0; i < kNumVersions; ++i) { | 260 for (size_t i = 0; i < kNumVersions; ++i) { |
291 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]); | 261 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]); |
292 CreateRasterTasks( | 262 CreateRasterTasks( |
293 num_raster_tasks, image_decode_tasks[i], &raster_tasks[i]); | 263 num_raster_tasks, image_decode_tasks[i], &raster_tasks[i]); |
294 } | 264 } |
295 | 265 |
296 // Avoid unnecessary heap allocations by reusing the same queue. | 266 // Avoid unnecessary heap allocations by reusing the same queue. |
297 RasterWorkerPool::RasterTask::Queue queue; | 267 RasterTaskQueue queue; |
298 | 268 |
299 size_t count = 0; | 269 size_t count = 0; |
300 timer_.Reset(); | 270 timer_.Reset(); |
301 do { | 271 do { |
302 queue.Reset(); | 272 queue.Reset(); |
303 BuildTaskQueue(&queue, raster_tasks[count % kNumVersions]); | 273 BuildTaskQueue(&queue, raster_tasks[count % kNumVersions]); |
304 raster_worker_pool_->ScheduleTasks(&queue); | 274 raster_worker_pool_->ScheduleTasks(&queue); |
305 raster_worker_pool_->CheckForCompletedTasks(); | 275 raster_worker_pool_->CheckForCompletedTasks(); |
306 ++count; | 276 ++count; |
307 timer_.NextLap(); | 277 timer_.NextLap(); |
308 } while (!timer_.HasTimeLimitExpired()); | 278 } while (!timer_.HasTimeLimitExpired()); |
309 | 279 |
310 RasterWorkerPool::RasterTask::Queue empty; | 280 RasterTaskQueue empty; |
311 raster_worker_pool_->ScheduleTasks(&empty); | 281 raster_worker_pool_->ScheduleTasks(&empty); |
312 RunMessageLoopUntilAllTasksHaveCompleted(); | 282 RunMessageLoopUntilAllTasksHaveCompleted(); |
313 | 283 |
314 perf_test::PrintResult("schedule_alternate_tasks", | 284 perf_test::PrintResult("schedule_alternate_tasks", |
315 "", | 285 "", |
316 test_name, | 286 test_name, |
317 timer_.LapsPerSecond(), | 287 timer_.LapsPerSecond(), |
318 "runs/s", | 288 "runs/s", |
319 true); | 289 true); |
320 } | 290 } |
321 | 291 |
322 void RunScheduleAndExecuteTasksTest(const std::string& test_name, | 292 void RunScheduleAndExecuteTasksTest(const std::string& test_name, |
323 unsigned num_raster_tasks, | 293 unsigned num_raster_tasks, |
324 unsigned num_image_decode_tasks) { | 294 unsigned num_image_decode_tasks) { |
325 Task::Vector image_decode_tasks; | 295 internal::WorkerPoolTask::Vector image_decode_tasks; |
326 RasterTask::Vector raster_tasks; | 296 RasterTaskVector raster_tasks; |
327 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); | 297 CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks); |
328 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); | 298 CreateRasterTasks(num_raster_tasks, image_decode_tasks, &raster_tasks); |
329 | 299 |
330 // Avoid unnecessary heap allocations by reusing the same queue. | 300 // Avoid unnecessary heap allocations by reusing the same queue. |
331 RasterWorkerPool::RasterTask::Queue queue; | 301 RasterTaskQueue queue; |
332 | 302 |
333 timer_.Reset(); | 303 timer_.Reset(); |
334 do { | 304 do { |
335 queue.Reset(); | 305 queue.Reset(); |
336 BuildTaskQueue(&queue, raster_tasks); | 306 BuildTaskQueue(&queue, raster_tasks); |
337 raster_worker_pool_->ScheduleTasks(&queue); | 307 raster_worker_pool_->ScheduleTasks(&queue); |
338 RunMessageLoopUntilAllTasksHaveCompleted(); | 308 RunMessageLoopUntilAllTasksHaveCompleted(); |
339 timer_.NextLap(); | 309 timer_.NextLap(); |
340 } while (!timer_.HasTimeLimitExpired()); | 310 } while (!timer_.HasTimeLimitExpired()); |
341 | 311 |
342 RasterWorkerPool::RasterTask::Queue empty; | 312 RasterTaskQueue empty; |
343 raster_worker_pool_->ScheduleTasks(&empty); | 313 raster_worker_pool_->ScheduleTasks(&empty); |
344 RunMessageLoopUntilAllTasksHaveCompleted(); | 314 RunMessageLoopUntilAllTasksHaveCompleted(); |
345 | 315 |
346 perf_test::PrintResult("schedule_and_execute_tasks", | 316 perf_test::PrintResult("schedule_and_execute_tasks", |
347 "", | 317 "", |
348 test_name, | 318 test_name, |
349 timer_.LapsPerSecond(), | 319 timer_.LapsPerSecond(), |
350 "runs/s", | 320 "runs/s", |
351 true); | 321 true); |
352 } | 322 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 } | 359 } |
390 | 360 |
391 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolPerfTests, | 361 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolPerfTests, |
392 RasterWorkerPoolPerfTest, | 362 RasterWorkerPoolPerfTest, |
393 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 363 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
394 RASTER_WORKER_POOL_TYPE_IMAGE, | 364 RASTER_WORKER_POOL_TYPE_IMAGE, |
395 RASTER_WORKER_POOL_TYPE_DIRECT)); | 365 RASTER_WORKER_POOL_TYPE_DIRECT)); |
396 | 366 |
397 } // namespace | 367 } // namespace |
398 } // namespace cc | 368 } // namespace cc |
OLD | NEW |