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 <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
11 #include "cc/resources/gpu_raster_worker_pool.h" | 11 #include "cc/resources/gpu_raster_worker_pool.h" |
12 #include "cc/resources/image_copy_raster_worker_pool.h" | 12 #include "cc/resources/image_copy_raster_worker_pool.h" |
13 #include "cc/resources/image_raster_worker_pool.h" | 13 #include "cc/resources/image_raster_worker_pool.h" |
14 #include "cc/resources/picture_pile.h" | 14 #include "cc/resources/picture_pile.h" |
15 #include "cc/resources/picture_pile_impl.h" | 15 #include "cc/resources/picture_pile_impl.h" |
16 #include "cc/resources/pixel_buffer_raster_worker_pool.h" | 16 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
17 #include "cc/resources/rasterizer.h" | 17 #include "cc/resources/rasterizer.h" |
18 #include "cc/resources/resource_pool.h" | 18 #include "cc/resources/resource_pool.h" |
19 #include "cc/resources/resource_provider.h" | 19 #include "cc/resources/resource_provider.h" |
20 #include "cc/resources/scoped_resource.h" | 20 #include "cc/resources/scoped_resource.h" |
21 #include "cc/test/fake_output_surface.h" | 21 #include "cc/test/fake_output_surface.h" |
22 #include "cc/test/fake_output_surface_client.h" | 22 #include "cc/test/fake_output_surface_client.h" |
23 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
24 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace cc { | 27 namespace cc { |
28 namespace { | 28 namespace { |
29 | 29 |
| 30 const size_t kMaxTransferBufferUsageBytes = 10000U; |
| 31 // A resource of this dimension^2 * 4 must be greater than the above transfer |
| 32 // buffer constant. |
| 33 const size_t kLargeResourceDimension = 1000U; |
| 34 |
30 enum RasterWorkerPoolType { | 35 enum RasterWorkerPoolType { |
31 RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 36 RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
32 RASTER_WORKER_POOL_TYPE_IMAGE, | 37 RASTER_WORKER_POOL_TYPE_IMAGE, |
33 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, | 38 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, |
34 RASTER_WORKER_POOL_TYPE_GPU | 39 RASTER_WORKER_POOL_TYPE_GPU |
35 }; | 40 }; |
36 | 41 |
37 class TestRasterTaskImpl : public RasterTask { | 42 class TestRasterTaskImpl : public RasterTask { |
38 public: | 43 public: |
39 typedef base::Callback< | 44 typedef base::Callback< |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 staging_resource_pool_ = ResourcePool::Create( | 124 staging_resource_pool_ = ResourcePool::Create( |
120 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | 125 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); |
121 | 126 |
122 switch (GetParam()) { | 127 switch (GetParam()) { |
123 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: | 128 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: |
124 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( | 129 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( |
125 base::MessageLoopProxy::current().get(), | 130 base::MessageLoopProxy::current().get(), |
126 RasterWorkerPool::GetTaskGraphRunner(), | 131 RasterWorkerPool::GetTaskGraphRunner(), |
127 context_provider_.get(), | 132 context_provider_.get(), |
128 resource_provider_.get(), | 133 resource_provider_.get(), |
129 std::numeric_limits<size_t>::max()); | 134 kMaxTransferBufferUsageBytes); |
130 break; | 135 break; |
131 case RASTER_WORKER_POOL_TYPE_IMAGE: | 136 case RASTER_WORKER_POOL_TYPE_IMAGE: |
132 raster_worker_pool_ = ImageRasterWorkerPool::Create( | 137 raster_worker_pool_ = ImageRasterWorkerPool::Create( |
133 base::MessageLoopProxy::current().get(), | 138 base::MessageLoopProxy::current().get(), |
134 RasterWorkerPool::GetTaskGraphRunner(), | 139 RasterWorkerPool::GetTaskGraphRunner(), |
135 resource_provider_.get()); | 140 resource_provider_.get()); |
136 break; | 141 break; |
137 case RASTER_WORKER_POOL_TYPE_IMAGE_COPY: | 142 case RASTER_WORKER_POOL_TYPE_IMAGE_COPY: |
138 raster_worker_pool_ = ImageCopyRasterWorkerPool::Create( | 143 raster_worker_pool_ = ImageCopyRasterWorkerPool::Create( |
139 base::MessageLoopProxy::current().get(), | 144 base::MessageLoopProxy::current().get(), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 RasterTaskQueue queue; | 201 RasterTaskQueue queue; |
197 | 202 |
198 for (RasterTaskVector::const_iterator it = tasks_.begin(); | 203 for (RasterTaskVector::const_iterator it = tasks_.begin(); |
199 it != tasks_.end(); | 204 it != tasks_.end(); |
200 ++it) | 205 ++it) |
201 queue.items.push_back(RasterTaskQueue::Item(*it, false)); | 206 queue.items.push_back(RasterTaskQueue::Item(*it, false)); |
202 | 207 |
203 raster_worker_pool_->AsRasterizer()->ScheduleTasks(&queue); | 208 raster_worker_pool_->AsRasterizer()->ScheduleTasks(&queue); |
204 } | 209 } |
205 | 210 |
206 void AppendTask(unsigned id) { | 211 void AppendTask(unsigned id, const gfx::Size& size) { |
207 const gfx::Size size(1, 1); | |
208 | |
209 scoped_ptr<ScopedResource> resource( | 212 scoped_ptr<ScopedResource> resource( |
210 ScopedResource::Create(resource_provider_.get())); | 213 ScopedResource::Create(resource_provider_.get())); |
211 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); | 214 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); |
212 const Resource* const_resource = resource.get(); | 215 const Resource* const_resource = resource.get(); |
213 | 216 |
214 ImageDecodeTask::Vector empty; | 217 ImageDecodeTask::Vector empty; |
215 tasks_.push_back(new TestRasterTaskImpl( | 218 tasks_.push_back(new TestRasterTaskImpl( |
216 const_resource, | 219 const_resource, |
217 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted, | 220 base::Bind(&RasterWorkerPoolTest::OnTaskCompleted, |
218 base::Unretained(this), | 221 base::Unretained(this), |
219 base::Passed(&resource), | 222 base::Passed(&resource), |
220 id), | 223 id), |
221 &empty)); | 224 &empty)); |
222 } | 225 } |
223 | 226 |
| 227 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
| 228 |
224 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 229 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
225 const gfx::Size size(1, 1); | 230 const gfx::Size size(1, 1); |
226 | 231 |
227 scoped_ptr<ScopedResource> resource( | 232 scoped_ptr<ScopedResource> resource( |
228 ScopedResource::Create(resource_provider_.get())); | 233 ScopedResource::Create(resource_provider_.get())); |
229 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); | 234 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); |
230 const Resource* const_resource = resource.get(); | 235 const Resource* const_resource = resource.get(); |
231 | 236 |
232 ImageDecodeTask::Vector empty; | 237 ImageDecodeTask::Vector empty; |
233 tasks_.push_back(new BlockingTestRasterTaskImpl( | 238 tasks_.push_back(new BlockingTestRasterTaskImpl( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 tasks.swap(tasks_); | 322 tasks.swap(tasks_); |
318 AppendTask(1u); | 323 AppendTask(1u); |
319 ScheduleTasks(); | 324 ScheduleTasks(); |
320 | 325 |
321 // Unblock the first task to allow the second task to complete. | 326 // Unblock the first task to allow the second task to complete. |
322 lock.Release(); | 327 lock.Release(); |
323 | 328 |
324 RunMessageLoopUntilAllTasksHaveCompleted(); | 329 RunMessageLoopUntilAllTasksHaveCompleted(); |
325 } | 330 } |
326 | 331 |
| 332 TEST_P(RasterWorkerPoolTest, LargeResources) { |
| 333 gfx::Size size(kLargeResourceDimension, kLargeResourceDimension); |
| 334 |
| 335 { |
| 336 // Verify a resource of this size is larger than the transfer buffer. |
| 337 scoped_ptr<ScopedResource> resource( |
| 338 ScopedResource::Create(resource_provider_.get())); |
| 339 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); |
| 340 EXPECT_GE(resource->bytes(), kMaxTransferBufferUsageBytes); |
| 341 } |
| 342 |
| 343 AppendTask(0u, size); |
| 344 AppendTask(1u, size); |
| 345 AppendTask(2u, size); |
| 346 ScheduleTasks(); |
| 347 |
| 348 // This will time out if a resource that is larger than the throttle limit |
| 349 // never gets scheduled. |
| 350 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 351 } |
| 352 |
327 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, | 353 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, |
328 RasterWorkerPoolTest, | 354 RasterWorkerPoolTest, |
329 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 355 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
330 RASTER_WORKER_POOL_TYPE_IMAGE, | 356 RASTER_WORKER_POOL_TYPE_IMAGE, |
331 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, | 357 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, |
332 RASTER_WORKER_POOL_TYPE_GPU)); | 358 RASTER_WORKER_POOL_TYPE_GPU)); |
333 | 359 |
334 } // namespace | 360 } // namespace |
335 } // namespace cc | 361 } // namespace cc |
OLD | NEW |