| 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> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const size_t kMaxBytesPerCopyOperation = 1000U; | 44 const size_t kMaxBytesPerCopyOperation = 1000U; |
| 45 const size_t kMaxStagingBuffers = 32U; | 45 const size_t kMaxStagingBuffers = 32U; |
| 46 | 46 |
| 47 enum TileTaskWorkerPoolType { | 47 enum TileTaskWorkerPoolType { |
| 48 TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, | 48 TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, |
| 49 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, | 49 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, |
| 50 TILE_TASK_WORKER_POOL_TYPE_GPU, | 50 TILE_TASK_WORKER_POOL_TYPE_GPU, |
| 51 TILE_TASK_WORKER_POOL_TYPE_BITMAP | 51 TILE_TASK_WORKER_POOL_TYPE_BITMAP |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class TestRasterTaskImpl : public RasterTask { | 54 class TestRasterTaskImpl : public DependencyTask { |
| 55 public: | 55 public: |
| 56 typedef base::Callback<void(bool was_canceled)> Reply; | 56 typedef base::Callback<void(bool was_canceled)> Reply; |
| 57 | 57 |
| 58 TestRasterTaskImpl(const Resource* resource, | 58 TestRasterTaskImpl(const Resource* resource, |
| 59 const Reply& reply, | 59 const Reply& reply, |
| 60 ImageDecodeTask::Vector* dependencies) | 60 DependencyTask::Vector* dependencies) |
| 61 : RasterTask(dependencies), | 61 : DependencyTask(dependencies), |
| 62 resource_(resource), | 62 resource_(resource), |
| 63 reply_(reply), | 63 reply_(reply), |
| 64 raster_source_( | 64 raster_source_( |
| 65 FakeDisplayListRasterSource::CreateFilled(gfx::Size(1, 1))) {} | 65 FakeDisplayListRasterSource::CreateFilled(gfx::Size(1, 1))) {} |
| 66 | 66 |
| 67 // Overridden from Task: | 67 // Overridden from Task: |
| 68 void RunOnWorkerThread() override { | 68 void RunOnWorkerThread() override { |
| 69 uint64_t new_content_id = 0; | 69 uint64_t new_content_id = 0; |
| 70 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), | 70 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), |
| 71 gfx::Rect(1, 1), new_content_id, 1.f, true); | 71 gfx::Rect(1, 1), new_content_id, 1.f, true); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Overridden from TileTask: | 74 // Overridden from DependencyTask: |
| 75 void ScheduleOnOriginThread(TileTaskClient* client) override { | 75 void ScheduleOnOriginThread(DependencyTaskClient* client) override { |
| 76 // The raster buffer has no tile ids associated with it for partial update, | 76 // The raster buffer has no tile ids associated with it for partial update, |
| 77 // so doesn't need to provide a valid dirty rect. | 77 // so doesn't need to provide a valid dirty rect. |
| 78 raster_buffer_ = client->AcquireBufferForRaster(resource_, 0, 0); | 78 raster_buffer_ = client->AcquireBufferForRaster(resource_, 0, 0); |
| 79 } | 79 } |
| 80 void CompleteOnOriginThread(TileTaskClient* client) override { | 80 void CompleteOnOriginThread(DependencyTaskClient* client) override { |
| 81 client->ReleaseBufferForRaster(std::move(raster_buffer_)); | 81 client->ReleaseBufferForRaster(std::move(raster_buffer_)); |
| 82 reply_.Run(!HasFinishedRunning()); | 82 reply_.Run(!HasFinishedRunning()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 protected: | 85 protected: |
| 86 ~TestRasterTaskImpl() override {} | 86 ~TestRasterTaskImpl() override {} |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 const Resource* resource_; | 89 const Resource* resource_; |
| 90 const Reply reply_; | 90 const Reply reply_; |
| 91 scoped_ptr<RasterBuffer> raster_buffer_; | 91 scoped_ptr<RasterBuffer> raster_buffer_; |
| 92 scoped_refptr<DisplayListRasterSource> raster_source_; | 92 scoped_refptr<DisplayListRasterSource> raster_source_; |
| 93 | 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); | 94 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { | 97 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
| 98 public: | 98 public: |
| 99 BlockingTestRasterTaskImpl(const Resource* resource, | 99 BlockingTestRasterTaskImpl(const Resource* resource, |
| 100 const Reply& reply, | 100 const Reply& reply, |
| 101 base::Lock* lock, | 101 base::Lock* lock, |
| 102 ImageDecodeTask::Vector* dependencies) | 102 DependencyTask::Vector* dependencies) |
| 103 : TestRasterTaskImpl(resource, reply, dependencies), lock_(lock) {} | 103 : TestRasterTaskImpl(resource, reply, dependencies), lock_(lock) {} |
| 104 | 104 |
| 105 // Overridden from Task: | 105 // Overridden from Task: |
| 106 void RunOnWorkerThread() override { | 106 void RunOnWorkerThread() override { |
| 107 base::AutoLock lock(*lock_); | 107 base::AutoLock lock(*lock_); |
| 108 TestRasterTaskImpl::RunOnWorkerThread(); | 108 TestRasterTaskImpl::RunOnWorkerThread(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 protected: | 111 protected: |
| 112 ~BlockingTestRasterTaskImpl() override {} | 112 ~BlockingTestRasterTaskImpl() override {} |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 base::Lock* lock_; | 115 base::Lock* lock_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterTaskImpl); | 117 DISALLOW_COPY_AND_ASSIGN(BlockingTestRasterTaskImpl); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 class TileTaskWorkerPoolTest | 120 class TileTaskWorkerPoolTest |
| 121 : public testing::TestWithParam<TileTaskWorkerPoolType> { | 121 : public testing::TestWithParam<TileTaskWorkerPoolType> { |
| 122 public: | 122 public: |
| 123 struct RasterTaskResult { | 123 struct RasterTaskResult { |
| 124 unsigned id; | 124 unsigned id; |
| 125 bool canceled; | 125 bool canceled; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 typedef std::vector<scoped_refptr<RasterTask>> RasterTaskVector; | 128 typedef std::vector<scoped_refptr<DependencyTask>> RasterTaskVector; |
| 129 | 129 |
| 130 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; | 130 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, REQUIRED_FOR_DRAW, ALL }; |
| 131 | 131 |
| 132 TileTaskWorkerPoolTest() | 132 TileTaskWorkerPoolTest() |
| 133 : context_provider_(TestContextProvider::Create()), | 133 : context_provider_(TestContextProvider::Create()), |
| 134 worker_context_provider_(TestContextProvider::CreateWorker()), | 134 worker_context_provider_(TestContextProvider::CreateWorker()), |
| 135 all_tile_tasks_finished_( | 135 all_tile_tasks_finished_( |
| 136 base::ThreadTaskRunnerHandle::Get() | 136 base::ThreadTaskRunnerHandle::Get() |
| 137 .get(), | 137 .get(), |
| 138 base::Bind(&TileTaskWorkerPoolTest::AllTileTasksFinished, | 138 base::Bind(&TileTaskWorkerPoolTest::AllTileTasksFinished, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph_); | 203 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph_); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void AppendTask(unsigned id, const gfx::Size& size) { | 206 void AppendTask(unsigned id, const gfx::Size& size) { |
| 207 scoped_ptr<ScopedResource> resource( | 207 scoped_ptr<ScopedResource> resource( |
| 208 ScopedResource::Create(resource_provider_.get())); | 208 ScopedResource::Create(resource_provider_.get())); |
| 209 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 209 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 210 RGBA_8888); | 210 RGBA_8888); |
| 211 const Resource* const_resource = resource.get(); | 211 const Resource* const_resource = resource.get(); |
| 212 | 212 |
| 213 ImageDecodeTask::Vector empty; | 213 DependencyTask::Vector empty; |
| 214 tasks_.push_back(new TestRasterTaskImpl( | 214 tasks_.push_back(new TestRasterTaskImpl( |
| 215 const_resource, | 215 const_resource, |
| 216 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, | 216 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, |
| 217 base::Unretained(this), base::Passed(&resource), id), | 217 base::Unretained(this), base::Passed(&resource), id), |
| 218 &empty)); | 218 &empty)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } | 221 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
| 222 | 222 |
| 223 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 223 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
| 224 const gfx::Size size(1, 1); | 224 const gfx::Size size(1, 1); |
| 225 | 225 |
| 226 scoped_ptr<ScopedResource> resource( | 226 scoped_ptr<ScopedResource> resource( |
| 227 ScopedResource::Create(resource_provider_.get())); | 227 ScopedResource::Create(resource_provider_.get())); |
| 228 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 228 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 229 RGBA_8888); | 229 RGBA_8888); |
| 230 const Resource* const_resource = resource.get(); | 230 const Resource* const_resource = resource.get(); |
| 231 | 231 |
| 232 ImageDecodeTask::Vector empty; | 232 DependencyTask::Vector empty; |
| 233 tasks_.push_back(new BlockingTestRasterTaskImpl( | 233 tasks_.push_back(new BlockingTestRasterTaskImpl( |
| 234 const_resource, | 234 const_resource, |
| 235 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, | 235 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, |
| 236 base::Unretained(this), base::Passed(&resource), id), | 236 base::Unretained(this), base::Passed(&resource), id), |
| 237 lock, &empty)); | 237 lock, &empty)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 const std::vector<RasterTaskResult>& completed_tasks() const { | 240 const std::vector<RasterTaskResult>& completed_tasks() const { |
| 241 return completed_tasks_; | 241 return completed_tasks_; |
| 242 } | 242 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 370 |
| 371 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, | 371 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, |
| 372 TileTaskWorkerPoolTest, | 372 TileTaskWorkerPoolTest, |
| 373 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, | 373 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, |
| 374 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, | 374 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, |
| 375 TILE_TASK_WORKER_POOL_TYPE_GPU, | 375 TILE_TASK_WORKER_POOL_TYPE_GPU, |
| 376 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); | 376 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); |
| 377 | 377 |
| 378 } // namespace | 378 } // namespace |
| 379 } // namespace cc | 379 } // namespace cc |
| OLD | NEW |