| 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/raster/tile_task_worker_pool.h" | 5 #include "cc/raster/tile_task_worker_pool.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "cc/base/unique_notifier.h" | 20 #include "cc/base/unique_notifier.h" |
| 21 #include "cc/raster/bitmap_tile_task_worker_pool.h" | 21 #include "cc/raster/bitmap_tile_task_worker_pool.h" |
| 22 #include "cc/raster/gpu_rasterizer.h" | 22 #include "cc/raster/gpu_rasterizer.h" |
| 23 #include "cc/raster/gpu_tile_task_worker_pool.h" | 23 #include "cc/raster/gpu_tile_task_worker_pool.h" |
| 24 #include "cc/raster/one_copy_tile_task_worker_pool.h" | 24 #include "cc/raster/one_copy_tile_task_worker_pool.h" |
| 25 #include "cc/raster/synchronous_task_graph_runner.h" | 25 #include "cc/raster/synchronous_task_graph_runner.h" |
| 26 #include "cc/raster/tile_task_runner.h" | |
| 27 #include "cc/raster/zero_copy_tile_task_worker_pool.h" | 26 #include "cc/raster/zero_copy_tile_task_worker_pool.h" |
| 28 #include "cc/resources/resource_pool.h" | 27 #include "cc/resources/resource_pool.h" |
| 29 #include "cc/resources/resource_provider.h" | 28 #include "cc/resources/resource_provider.h" |
| 30 #include "cc/resources/scoped_resource.h" | 29 #include "cc/resources/scoped_resource.h" |
| 31 #include "cc/test/fake_output_surface.h" | 30 #include "cc/test/fake_output_surface.h" |
| 32 #include "cc/test/fake_output_surface_client.h" | 31 #include "cc/test/fake_output_surface_client.h" |
| 33 #include "cc/test/fake_raster_source.h" | 32 #include "cc/test/fake_raster_source.h" |
| 34 #include "cc/test/fake_resource_provider.h" | 33 #include "cc/test/fake_resource_provider.h" |
| 35 #include "cc/test/test_gpu_memory_buffer_manager.h" | 34 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 36 #include "cc/test/test_shared_bitmap_manager.h" | 35 #include "cc/test/test_shared_bitmap_manager.h" |
| 37 #include "cc/test/test_web_graphics_context_3d.h" | 36 #include "cc/test/test_web_graphics_context_3d.h" |
| 38 #include "gpu/GLES2/gl2extchromium.h" | 37 #include "gpu/GLES2/gl2extchromium.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 39 |
| 41 namespace cc { | 40 namespace cc { |
| 42 namespace { | 41 namespace { |
| 43 | 42 |
| 44 const size_t kMaxBytesPerCopyOperation = 1000U; | 43 const size_t kMaxBytesPerCopyOperation = 1000U; |
| 45 const size_t kMaxStagingBuffers = 32U; | 44 const size_t kMaxStagingBuffers = 32U; |
| 46 | 45 |
| 47 enum TileTaskWorkerPoolType { | 46 enum TileTaskWorkerPoolType { |
| 48 TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, | 47 TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, |
| 49 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, | 48 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, |
| 50 TILE_TASK_WORKER_POOL_TYPE_GPU, | 49 TILE_TASK_WORKER_POOL_TYPE_GPU, |
| 51 TILE_TASK_WORKER_POOL_TYPE_BITMAP | 50 TILE_TASK_WORKER_POOL_TYPE_BITMAP |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 class TileTaskWorkerPoolTest; | 53 class TileTaskWorkerPoolTest; |
| 55 | 54 |
| 56 class TestRasterTaskImpl : public RasterTask { | 55 class TestRasterTaskImpl : public Task { |
| 57 public: | 56 public: |
| 58 TestRasterTaskImpl(std::unique_ptr<ScopedResource> resource, | 57 TestRasterTaskImpl(std::unique_ptr<ScopedResource> resource, |
| 59 std::unique_ptr<RasterBuffer> raster_buffer, | 58 std::unique_ptr<RasterBuffer> raster_buffer, |
| 60 ImageDecodeTask::Vector* dependencies) | 59 Task::Vector* dependencies) |
| 61 : RasterTask(dependencies), | 60 : Task(dependencies), |
| 62 resource_(std::move(resource)), | 61 resource_(std::move(resource)), |
| 63 raster_buffer_(std::move(raster_buffer)), | 62 raster_buffer_(std::move(raster_buffer)), |
| 64 raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) { | 63 raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) { |
| 65 SetTaskTypeId(TASK_TYPE_RASTER); | 64 SetTaskType(TASK_TYPE_RASTER); |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Overridden from Task: | 67 // Overridden from Task: |
| 69 void RunOnWorkerThread() override { | 68 void RunOnWorkerThread() override { |
| 70 uint64_t new_content_id = 0; | 69 uint64_t new_content_id = 0; |
| 71 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), | 70 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), |
| 72 gfx::Rect(1, 1), new_content_id, 1.f, | 71 gfx::Rect(1, 1), new_content_id, 1.f, |
| 73 RasterSource::PlaybackSettings()); | 72 RasterSource::PlaybackSettings()); |
| 74 } | 73 } |
| 75 | 74 |
| 76 protected: | 75 protected: |
| 77 ~TestRasterTaskImpl() override {} | 76 ~TestRasterTaskImpl() override {} |
| 78 | 77 |
| 79 private: | 78 private: |
| 80 friend class TileTaskWorkerPoolTest; | 79 friend class TileTaskWorkerPoolTest; |
| 81 std::unique_ptr<ScopedResource> resource_; | 80 std::unique_ptr<ScopedResource> resource_; |
| 82 std::unique_ptr<RasterBuffer> raster_buffer_; | 81 std::unique_ptr<RasterBuffer> raster_buffer_; |
| 83 scoped_refptr<RasterSource> raster_source_; | 82 scoped_refptr<RasterSource> raster_source_; |
| 84 | 83 |
| 85 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); | 84 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { | 87 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
| 89 public: | 88 public: |
| 90 BlockingTestRasterTaskImpl(std::unique_ptr<ScopedResource> resource, | 89 BlockingTestRasterTaskImpl(std::unique_ptr<ScopedResource> resource, |
| 91 std::unique_ptr<RasterBuffer> raster_buffer, | 90 std::unique_ptr<RasterBuffer> raster_buffer, |
| 92 base::Lock* lock, | 91 base::Lock* lock, |
| 93 ImageDecodeTask::Vector* dependencies) | 92 Task::Vector* dependencies) |
| 94 : TestRasterTaskImpl(std::move(resource), | 93 : TestRasterTaskImpl(std::move(resource), |
| 95 std::move(raster_buffer), | 94 std::move(raster_buffer), |
| 96 dependencies), | 95 dependencies), |
| 97 lock_(lock) {} | 96 lock_(lock) {} |
| 98 | 97 |
| 99 // Overridden from Task: | 98 // Overridden from Task: |
| 100 void RunOnWorkerThread() override { | 99 void RunOnWorkerThread() override { |
| 101 base::AutoLock lock(*lock_); | 100 base::AutoLock lock(*lock_); |
| 102 TestRasterTaskImpl::RunOnWorkerThread(); | 101 TestRasterTaskImpl::RunOnWorkerThread(); |
| 103 } | 102 } |
| 104 | 103 |
| 105 protected: | 104 protected: |
| 106 ~BlockingTestRasterTaskImpl() override {} | 105 ~BlockingTestRasterTaskImpl() override {} |
| 107 | 106 |
| 108 private: | 107 private: |
| 109 base::Lock* lock_; | 108 base::Lock* lock_; |
| 110 | 109 |
| 111 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterTaskImpl); | 110 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterTaskImpl); |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 class TileTaskWorkerPoolTest | 113 class TileTaskWorkerPoolTest |
| 115 : public testing::TestWithParam<TileTaskWorkerPoolType> { | 114 : public testing::TestWithParam<TileTaskWorkerPoolType> { |
| 116 public: | 115 public: |
| 117 struct RasterTaskResult { | 116 struct RasterTaskResult { |
| 118 unsigned id; | 117 unsigned id; |
| 119 bool canceled; | 118 bool canceled; |
| 120 }; | 119 }; |
| 121 | 120 |
| 122 typedef std::vector<scoped_refptr<RasterTask>> RasterTaskVector; | 121 typedef Task::Vector RasterTaskVector; |
| 123 | 122 |
| 124 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; | 123 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; |
| 125 | 124 |
| 126 TileTaskWorkerPoolTest() | 125 TileTaskWorkerPoolTest() |
| 127 : context_provider_(TestContextProvider::Create()), | 126 : context_provider_(TestContextProvider::Create()), |
| 128 worker_context_provider_(TestContextProvider::CreateWorker()), | 127 worker_context_provider_(TestContextProvider::CreateWorker()), |
| 129 all_tile_tasks_finished_( | 128 all_tile_tasks_finished_( |
| 130 base::ThreadTaskRunnerHandle::Get() | 129 base::ThreadTaskRunnerHandle::Get() |
| 131 .get(), | 130 .get(), |
| 132 base::Bind(&TileTaskWorkerPoolTest::AllTileTasksFinished, | 131 base::Bind(&TileTaskWorkerPoolTest::AllTileTasksFinished, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 base::MessageLoop::current()->QuitWhenIdle(); | 177 base::MessageLoop::current()->QuitWhenIdle(); |
| 179 } | 178 } |
| 180 | 179 |
| 181 void CheckAndProcessCompletedTasks() { | 180 void CheckAndProcessCompletedTasks() { |
| 182 Task::Vector completed_tasks; | 181 Task::Vector completed_tasks; |
| 183 tile_task_worker_pool_->CollectCompletedTasks(&completed_tasks); | 182 tile_task_worker_pool_->CollectCompletedTasks(&completed_tasks); |
| 184 | 183 |
| 185 for (auto task : completed_tasks) { | 184 for (auto task : completed_tasks) { |
| 186 // Don't process image decode tasks as there are no dependencies for | 185 // Don't process image decode tasks as there are no dependencies for |
| 187 // raster tasks in the tests. | 186 // raster tasks in the tests. |
| 188 if (task->GetTaskTypeId() == TASK_TYPE_RASTER) { | 187 if (task->GetTaskType() == TASK_TYPE_RASTER) { |
| 189 TestRasterTaskImpl* raster_task = | 188 TestRasterTaskImpl* raster_task = |
| 190 static_cast<TestRasterTaskImpl*>(task.get()); | 189 static_cast<TestRasterTaskImpl*>(task.get()); |
| 191 RasterTaskCompleted(0, !raster_task->HasFinishedRunning()); | 190 RasterTaskCompleted(0, !raster_task->HasFinishedRunning()); |
| 192 } | 191 } |
| 193 static_cast<TileTask*>(task.get())->DidComplete(); | 192 task->DidComplete(); |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 | 195 |
| 197 void RunMessageLoopUntilAllTasksHaveCompleted() { | 196 void RunMessageLoopUntilAllTasksHaveCompleted() { |
| 198 task_graph_runner_.RunUntilIdle(); | 197 task_graph_runner_.RunUntilIdle(); |
| 199 CheckAndProcessCompletedTasks(); | 198 CheckAndProcessCompletedTasks(); |
| 200 } | 199 } |
| 201 | 200 |
| 202 void ScheduleTasks() { | 201 void ScheduleTasks() { |
| 203 graph_.Reset(); | 202 graph_.Reset(); |
| 204 | 203 |
| 205 size_t priority = 0; | 204 size_t priority = 0; |
| 206 | 205 |
| 207 for (RasterTaskVector::const_iterator it = tasks_.begin(); | 206 for (RasterTaskVector::const_iterator it = tasks_.begin(); |
| 208 it != tasks_.end(); ++it) { | 207 it != tasks_.end(); ++it) { |
| 209 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, | 208 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, |
| 210 0 /* dependencies */); | 209 0 /* dependencies */); |
| 211 } | 210 } |
| 212 | 211 |
| 213 tile_task_worker_pool_->ScheduleTasks(&graph_); | 212 tile_task_worker_pool_->ScheduleTasks(&graph_); |
| 214 } | 213 } |
| 215 | 214 |
| 216 void AppendTask(unsigned id, const gfx::Size& size) { | 215 void AppendTask(unsigned id, const gfx::Size& size) { |
| 217 std::unique_ptr<ScopedResource> resource( | 216 std::unique_ptr<ScopedResource> resource( |
| 218 ScopedResource::Create(resource_provider_.get())); | 217 ScopedResource::Create(resource_provider_.get())); |
| 219 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 218 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 220 RGBA_8888); | 219 RGBA_8888); |
| 221 | 220 |
| 222 ImageDecodeTask::Vector empty; | 221 Task::Vector empty; |
| 223 std::unique_ptr<RasterBuffer> raster_buffer = | 222 std::unique_ptr<RasterBuffer> raster_buffer = |
| 224 tile_task_worker_pool_->AsRasterBufferProvider() | 223 tile_task_worker_pool_->AsRasterBufferProvider() |
| 225 ->AcquireBufferForRaster(resource.get(), 0, 0); | 224 ->AcquireBufferForRaster(resource.get(), 0, 0); |
| 226 tasks_.push_back(new TestRasterTaskImpl(std::move(resource), | 225 tasks_.push_back(new TestRasterTaskImpl(std::move(resource), |
| 227 std::move(raster_buffer), &empty)); | 226 std::move(raster_buffer), &empty)); |
| 228 } | 227 } |
| 229 | 228 |
| 230 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } | 229 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
| 231 | 230 |
| 232 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 231 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
| 233 const gfx::Size size(1, 1); | 232 const gfx::Size size(1, 1); |
| 234 | 233 |
| 235 std::unique_ptr<ScopedResource> resource( | 234 std::unique_ptr<ScopedResource> resource( |
| 236 ScopedResource::Create(resource_provider_.get())); | 235 ScopedResource::Create(resource_provider_.get())); |
| 237 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 236 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 238 RGBA_8888); | 237 RGBA_8888); |
| 239 | 238 |
| 240 ImageDecodeTask::Vector empty; | 239 Task::Vector empty; |
| 241 std::unique_ptr<RasterBuffer> raster_buffer = | 240 std::unique_ptr<RasterBuffer> raster_buffer = |
| 242 tile_task_worker_pool_->AsRasterBufferProvider() | 241 tile_task_worker_pool_->AsRasterBufferProvider() |
| 243 ->AcquireBufferForRaster(resource.get(), 0, 0); | 242 ->AcquireBufferForRaster(resource.get(), 0, 0); |
| 244 | 243 |
| 245 tasks_.push_back(new BlockingTestRasterTaskImpl( | 244 tasks_.push_back(new BlockingTestRasterTaskImpl( |
| 246 std::move(resource), std::move(raster_buffer), lock, &empty)); | 245 std::move(resource), std::move(raster_buffer), lock, &empty)); |
| 247 } | 246 } |
| 248 | 247 |
| 249 const std::vector<RasterTaskResult>& completed_tasks() const { | 248 const std::vector<RasterTaskResult>& completed_tasks() const { |
| 250 return completed_tasks_; | 249 return completed_tasks_; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 375 |
| 377 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, | 376 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, |
| 378 TileTaskWorkerPoolTest, | 377 TileTaskWorkerPoolTest, |
| 379 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, | 378 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, |
| 380 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, | 379 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, |
| 381 TILE_TASK_WORKER_POOL_TYPE_GPU, | 380 TILE_TASK_WORKER_POOL_TYPE_GPU, |
| 382 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); | 381 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); |
| 383 | 382 |
| 384 } // namespace | 383 } // namespace |
| 385 } // namespace cc | 384 } // namespace cc |
| OLD | NEW |