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 TileTaskWorkerPoolTest; |
| 55 |
54 class TestRasterTaskImpl : public RasterTask { | 56 class TestRasterTaskImpl : public RasterTask { |
55 public: | 57 public: |
56 typedef base::Callback<void(bool was_canceled)> Reply; | |
57 | |
58 TestRasterTaskImpl(const Resource* resource, | 58 TestRasterTaskImpl(const Resource* resource, |
59 const Reply& reply, | 59 scoped_ptr<RasterBuffer> raster_buffer, |
60 ImageDecodeTask::Vector* dependencies) | 60 ImageDecodeTask::Vector* dependencies) |
61 : RasterTask(dependencies), | 61 : RasterTask(dependencies), |
62 resource_(resource), | 62 resource_(resource), |
63 reply_(reply), | 63 raster_buffer_(std::move(raster_buffer)), |
64 raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) {} | 64 raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) {} |
65 | 65 |
66 // Overridden from Task: | 66 // Overridden from Task: |
67 void RunOnWorkerThread() override { | 67 void RunOnWorkerThread() override { |
68 uint64_t new_content_id = 0; | 68 uint64_t new_content_id = 0; |
69 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), | 69 raster_buffer_->Playback(raster_source_.get(), gfx::Rect(1, 1), |
70 gfx::Rect(1, 1), new_content_id, 1.f, | 70 gfx::Rect(1, 1), new_content_id, 1.f, |
71 RasterSource::PlaybackSettings()); | 71 RasterSource::PlaybackSettings()); |
72 } | 72 } |
73 | 73 |
74 // Overridden from TileTask: | |
75 void ScheduleOnOriginThread(TileTaskClient* client) override { | |
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. | |
78 raster_buffer_ = client->AcquireBufferForRaster(resource_, 0, 0); | |
79 } | |
80 void CompleteOnOriginThread(TileTaskClient* client) override { | |
81 client->ReleaseBufferForRaster(std::move(raster_buffer_)); | |
82 reply_.Run(!HasFinishedRunning()); | |
83 } | |
84 | |
85 protected: | 74 protected: |
86 ~TestRasterTaskImpl() override {} | 75 ~TestRasterTaskImpl() override {} |
87 | 76 |
88 private: | 77 private: |
| 78 friend class TileTaskWorkerPoolTest; |
89 const Resource* resource_; | 79 const Resource* resource_; |
90 const Reply reply_; | |
91 scoped_ptr<RasterBuffer> raster_buffer_; | 80 scoped_ptr<RasterBuffer> raster_buffer_; |
92 scoped_refptr<RasterSource> raster_source_; | 81 scoped_refptr<RasterSource> raster_source_; |
93 | 82 |
94 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); | 83 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); |
95 }; | 84 }; |
96 | 85 |
97 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { | 86 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
98 public: | 87 public: |
99 BlockingTestRasterTaskImpl(const Resource* resource, | 88 BlockingTestRasterTaskImpl(const Resource* resource, |
100 const Reply& reply, | 89 scoped_ptr<RasterBuffer> raster_buffer, |
101 base::Lock* lock, | 90 base::Lock* lock, |
102 ImageDecodeTask::Vector* dependencies) | 91 ImageDecodeTask::Vector* dependencies) |
103 : TestRasterTaskImpl(resource, reply, dependencies), lock_(lock) {} | 92 : TestRasterTaskImpl(resource, std::move(raster_buffer), dependencies), |
| 93 lock_(lock) {} |
104 | 94 |
105 // Overridden from Task: | 95 // Overridden from Task: |
106 void RunOnWorkerThread() override { | 96 void RunOnWorkerThread() override { |
107 base::AutoLock lock(*lock_); | 97 base::AutoLock lock(*lock_); |
108 TestRasterTaskImpl::RunOnWorkerThread(); | 98 TestRasterTaskImpl::RunOnWorkerThread(); |
109 } | 99 } |
110 | 100 |
111 protected: | 101 protected: |
112 ~BlockingTestRasterTaskImpl() override {} | 102 ~BlockingTestRasterTaskImpl() override {} |
113 | 103 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 base::ThreadTaskRunnerHandle::Get().get(), &task_graph_runner_, | 159 base::ThreadTaskRunnerHandle::Get().get(), &task_graph_runner_, |
170 resource_provider_.get()); | 160 resource_provider_.get()); |
171 break; | 161 break; |
172 } | 162 } |
173 | 163 |
174 DCHECK(tile_task_worker_pool_); | 164 DCHECK(tile_task_worker_pool_); |
175 } | 165 } |
176 | 166 |
177 void TearDown() override { | 167 void TearDown() override { |
178 tile_task_worker_pool_->AsTileTaskRunner()->Shutdown(); | 168 tile_task_worker_pool_->AsTileTaskRunner()->Shutdown(); |
179 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | 169 CheckForCompletedTasks(); |
180 } | 170 } |
181 | 171 |
182 void AllTileTasksFinished() { | 172 void AllTileTasksFinished() { |
183 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | 173 CheckForCompletedTasks(); |
184 base::MessageLoop::current()->QuitWhenIdle(); | 174 base::MessageLoop::current()->QuitWhenIdle(); |
185 } | 175 } |
186 | 176 |
| 177 void CheckForCompletedTasks() { |
| 178 Task::Vector completed_tasks; |
| 179 tile_task_worker_pool_->AsTileTaskRunner()->CollectCompletedTasks( |
| 180 &completed_tasks); |
| 181 |
| 182 for (auto task : completed_tasks) { |
| 183 TestRasterTaskImpl* raster_task = |
| 184 static_cast<TestRasterTaskImpl*>(task.get()); |
| 185 CompleteRasterTask(0, !raster_task->HasFinishedRunning()); |
| 186 static_cast<TileTask*>(task.get())->DidComplete(); |
| 187 } |
| 188 } |
| 189 |
187 void RunMessageLoopUntilAllTasksHaveCompleted() { | 190 void RunMessageLoopUntilAllTasksHaveCompleted() { |
188 task_graph_runner_.RunUntilIdle(); | 191 task_graph_runner_.RunUntilIdle(); |
189 tile_task_worker_pool_->AsTileTaskRunner()->CheckForCompletedTasks(); | 192 CheckForCompletedTasks(); |
190 } | 193 } |
191 | 194 |
192 void ScheduleTasks() { | 195 void ScheduleTasks() { |
193 graph_.Reset(); | 196 graph_.Reset(); |
194 | 197 |
195 size_t priority = 0; | 198 size_t priority = 0; |
196 | 199 |
197 for (RasterTaskVector::const_iterator it = tasks_.begin(); | 200 for (RasterTaskVector::const_iterator it = tasks_.begin(); |
198 it != tasks_.end(); ++it) { | 201 it != tasks_.end(); ++it) { |
199 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, | 202 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, |
200 0 /* dependencies */); | 203 0 /* dependencies */); |
201 } | 204 } |
202 | 205 |
203 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph_); | 206 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph_); |
204 } | 207 } |
205 | 208 |
206 void AppendTask(unsigned id, const gfx::Size& size) { | 209 void AppendTask(unsigned id, const gfx::Size& size) { |
207 scoped_ptr<ScopedResource> resource( | 210 scoped_ptr<ScopedResource> resource( |
208 ScopedResource::Create(resource_provider_.get())); | 211 ScopedResource::Create(resource_provider_.get())); |
209 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 212 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
210 RGBA_8888); | 213 RGBA_8888); |
211 const Resource* const_resource = resource.get(); | 214 const Resource* const_resource = resource.get(); |
212 | 215 |
213 ImageDecodeTask::Vector empty; | 216 ImageDecodeTask::Vector empty; |
214 tasks_.push_back(new TestRasterTaskImpl( | 217 TileTaskClient* client = |
215 const_resource, | 218 reinterpret_cast<TileTaskClient*>(tile_task_worker_pool_.get()); |
216 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, | 219 scoped_ptr<RasterBuffer> raster_buffer = |
217 base::Unretained(this), base::Passed(&resource), id), | 220 client->AcquireBufferForRaster(const_resource, 0, 0); |
218 &empty)); | 221 tasks_.push_back(new TestRasterTaskImpl(const_resource, |
| 222 std::move(raster_buffer), &empty)); |
219 } | 223 } |
220 | 224 |
221 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } | 225 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
222 | 226 |
223 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 227 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
224 const gfx::Size size(1, 1); | 228 const gfx::Size size(1, 1); |
225 | 229 |
226 scoped_ptr<ScopedResource> resource( | 230 scoped_ptr<ScopedResource> resource( |
227 ScopedResource::Create(resource_provider_.get())); | 231 ScopedResource::Create(resource_provider_.get())); |
228 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 232 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
229 RGBA_8888); | 233 RGBA_8888); |
230 const Resource* const_resource = resource.get(); | 234 const Resource* const_resource = resource.get(); |
231 | 235 |
232 ImageDecodeTask::Vector empty; | 236 ImageDecodeTask::Vector empty; |
| 237 TileTaskClient* client = |
| 238 reinterpret_cast<TileTaskClient*>(tile_task_worker_pool_.get()); |
| 239 scoped_ptr<RasterBuffer> raster_buffer = |
| 240 client->AcquireBufferForRaster(const_resource, 0, 0); |
233 tasks_.push_back(new BlockingTestRasterTaskImpl( | 241 tasks_.push_back(new BlockingTestRasterTaskImpl( |
234 const_resource, | 242 const_resource, std::move(raster_buffer), lock, &empty)); |
235 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, | |
236 base::Unretained(this), base::Passed(&resource), id), | |
237 lock, &empty)); | |
238 } | 243 } |
239 | 244 |
240 const std::vector<RasterTaskResult>& completed_tasks() const { | 245 const std::vector<RasterTaskResult>& completed_tasks() const { |
241 return completed_tasks_; | 246 return completed_tasks_; |
242 } | 247 } |
243 | 248 |
244 void LoseContext(ContextProvider* context_provider) { | 249 void LoseContext(ContextProvider* context_provider) { |
245 if (!context_provider) | 250 if (!context_provider) |
246 return; | 251 return; |
247 context_provider->ContextGL()->LoseContextCHROMIUM( | 252 context_provider->ContextGL()->LoseContextCHROMIUM( |
(...skipping 13 matching lines...) Expand all Loading... |
261 } | 266 } |
262 | 267 |
263 void CreateSoftwareOutputSurfaceAndResourceProvider() { | 268 void CreateSoftwareOutputSurfaceAndResourceProvider() { |
264 output_surface_ = FakeOutputSurface::CreateSoftware( | 269 output_surface_ = FakeOutputSurface::CreateSoftware( |
265 make_scoped_ptr(new SoftwareOutputDevice)); | 270 make_scoped_ptr(new SoftwareOutputDevice)); |
266 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 271 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
267 resource_provider_ = FakeResourceProvider::Create( | 272 resource_provider_ = FakeResourceProvider::Create( |
268 output_surface_.get(), &shared_bitmap_manager_, nullptr); | 273 output_surface_.get(), &shared_bitmap_manager_, nullptr); |
269 } | 274 } |
270 | 275 |
271 void OnTaskCompleted( | 276 void CompleteRasterTask(unsigned id, bool was_canceled) { |
272 scoped_ptr<ScopedResource> resource, | |
273 unsigned id, | |
274 bool was_canceled) { | |
275 RasterTaskResult result; | 277 RasterTaskResult result; |
276 result.id = id; | 278 result.id = id; |
277 result.canceled = was_canceled; | 279 result.canceled = was_canceled; |
278 completed_tasks_.push_back(result); | 280 completed_tasks_.push_back(result); |
279 } | 281 } |
280 | 282 |
281 void OnTimeout() { | 283 void OnTimeout() { |
282 timed_out_ = true; | 284 timed_out_ = true; |
283 base::MessageLoop::current()->QuitWhenIdle(); | 285 base::MessageLoop::current()->QuitWhenIdle(); |
284 } | 286 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 372 |
371 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, | 373 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, |
372 TileTaskWorkerPoolTest, | 374 TileTaskWorkerPoolTest, |
373 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, | 375 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, |
374 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, | 376 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, |
375 TILE_TASK_WORKER_POOL_TYPE_GPU, | 377 TILE_TASK_WORKER_POOL_TYPE_GPU, |
376 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); | 378 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); |
377 | 379 |
378 } // namespace | 380 } // namespace |
379 } // namespace cc | 381 } // namespace cc |
OLD | NEW |