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 29 matching lines...) Expand all Loading... | |
263 protected: | 268 protected: |
264 scoped_refptr<TestContextProvider> context_provider_; | 269 scoped_refptr<TestContextProvider> context_provider_; |
265 FakeOutputSurfaceClient output_surface_client_; | 270 FakeOutputSurfaceClient output_surface_client_; |
266 scoped_ptr<FakeOutputSurface> output_surface_; | 271 scoped_ptr<FakeOutputSurface> output_surface_; |
267 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 272 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
268 scoped_ptr<ResourceProvider> resource_provider_; | 273 scoped_ptr<ResourceProvider> resource_provider_; |
269 scoped_ptr<ResourcePool> staging_resource_pool_; | 274 scoped_ptr<ResourcePool> staging_resource_pool_; |
270 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 275 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
271 base::CancelableClosure timeout_; | 276 base::CancelableClosure timeout_; |
272 int timeout_seconds_; | 277 int timeout_seconds_; |
278 size_t throttle_bytes_; | |
reveman
2014/08/21 02:07:00
unused, right?
enne (OOO)
2014/08/21 17:10:51
Done.
| |
273 bool timed_out_; | 279 bool timed_out_; |
274 RasterTaskVector tasks_; | 280 RasterTaskVector tasks_; |
275 std::vector<RasterTaskResult> completed_tasks_; | 281 std::vector<RasterTaskResult> completed_tasks_; |
276 }; | 282 }; |
277 | 283 |
278 TEST_P(RasterWorkerPoolTest, Basic) { | 284 TEST_P(RasterWorkerPoolTest, Basic) { |
279 AppendTask(0u); | 285 AppendTask(0u); |
280 AppendTask(1u); | 286 AppendTask(1u); |
281 ScheduleTasks(); | 287 ScheduleTasks(); |
282 | 288 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 tasks.swap(tasks_); | 323 tasks.swap(tasks_); |
318 AppendTask(1u); | 324 AppendTask(1u); |
319 ScheduleTasks(); | 325 ScheduleTasks(); |
320 | 326 |
321 // Unblock the first task to allow the second task to complete. | 327 // Unblock the first task to allow the second task to complete. |
322 lock.Release(); | 328 lock.Release(); |
323 | 329 |
324 RunMessageLoopUntilAllTasksHaveCompleted(); | 330 RunMessageLoopUntilAllTasksHaveCompleted(); |
325 } | 331 } |
326 | 332 |
333 TEST_P(RasterWorkerPoolTest, LargeResources) { | |
334 gfx::Size size(kLargeResourceDimension, kLargeResourceDimension); | |
335 | |
336 { | |
337 // Verify a resource of this size is larger than the transfer buffer. | |
338 scoped_ptr<ScopedResource> resource( | |
339 ScopedResource::Create(resource_provider_.get())); | |
340 resource->Allocate(size, ResourceProvider::TextureUsageAny, RGBA_8888); | |
341 EXPECT_GE(resource->bytes(), kMaxTransferBufferUsageBytes); | |
342 } | |
343 | |
344 AppendTask(0u, size); | |
345 AppendTask(1u, size); | |
346 AppendTask(2u, size); | |
347 ScheduleTasks(); | |
348 | |
349 // This will time out if a resource that is larger than the throttle limit | |
350 // never gets scheduled. | |
351 RunMessageLoopUntilAllTasksHaveCompleted(); | |
352 } | |
353 | |
327 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, | 354 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, |
328 RasterWorkerPoolTest, | 355 RasterWorkerPoolTest, |
329 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 356 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
330 RASTER_WORKER_POOL_TYPE_IMAGE, | 357 RASTER_WORKER_POOL_TYPE_IMAGE, |
331 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, | 358 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, |
332 RASTER_WORKER_POOL_TYPE_GPU)); | 359 RASTER_WORKER_POOL_TYPE_GPU)); |
333 | 360 |
334 } // namespace | 361 } // namespace |
335 } // namespace cc | 362 } // namespace cc |
OLD | NEW |