| 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/bitmap_raster_worker_pool.h" |
| 11 #include "cc/resources/gpu_raster_worker_pool.h" | 12 #include "cc/resources/gpu_raster_worker_pool.h" |
| 12 #include "cc/resources/one_copy_raster_worker_pool.h" | 13 #include "cc/resources/one_copy_raster_worker_pool.h" |
| 13 #include "cc/resources/picture_pile.h" | 14 #include "cc/resources/picture_pile.h" |
| 14 #include "cc/resources/picture_pile_impl.h" | 15 #include "cc/resources/picture_pile_impl.h" |
| 15 #include "cc/resources/pixel_buffer_raster_worker_pool.h" | 16 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
| 16 #include "cc/resources/raster_buffer.h" | 17 #include "cc/resources/raster_buffer.h" |
| 17 #include "cc/resources/rasterizer.h" | 18 #include "cc/resources/rasterizer.h" |
| 18 #include "cc/resources/resource_pool.h" | 19 #include "cc/resources/resource_pool.h" |
| 19 #include "cc/resources/resource_provider.h" | 20 #include "cc/resources/resource_provider.h" |
| 20 #include "cc/resources/scoped_resource.h" | 21 #include "cc/resources/scoped_resource.h" |
| 21 #include "cc/resources/zero_copy_raster_worker_pool.h" | 22 #include "cc/resources/zero_copy_raster_worker_pool.h" |
| 22 #include "cc/test/fake_output_surface.h" | 23 #include "cc/test/fake_output_surface.h" |
| 23 #include "cc/test/fake_output_surface_client.h" | 24 #include "cc/test/fake_output_surface_client.h" |
| 24 #include "cc/test/test_shared_bitmap_manager.h" | 25 #include "cc/test/test_shared_bitmap_manager.h" |
| 25 #include "cc/test/test_web_graphics_context_3d.h" | 26 #include "cc/test/test_web_graphics_context_3d.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 const size_t kMaxTransferBufferUsageBytes = 10000U; | 32 const size_t kMaxTransferBufferUsageBytes = 10000U; |
| 32 // A resource of this dimension^2 * 4 must be greater than the above transfer | 33 // A resource of this dimension^2 * 4 must be greater than the above transfer |
| 33 // buffer constant. | 34 // buffer constant. |
| 34 const size_t kLargeResourceDimension = 1000U; | 35 const size_t kLargeResourceDimension = 1000U; |
| 35 | 36 |
| 36 enum RasterWorkerPoolType { | 37 enum RasterWorkerPoolType { |
| 37 RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 38 RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
| 38 RASTER_WORKER_POOL_TYPE_ZERO_COPY, | 39 RASTER_WORKER_POOL_TYPE_ZERO_COPY, |
| 39 RASTER_WORKER_POOL_TYPE_ONE_COPY, | 40 RASTER_WORKER_POOL_TYPE_ONE_COPY, |
| 40 RASTER_WORKER_POOL_TYPE_GPU | 41 RASTER_WORKER_POOL_TYPE_GPU, |
| 42 RASTER_WORKER_POOL_TYPE_BITMAP |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 class TestRasterTaskImpl : public RasterTask { | 45 class TestRasterTaskImpl : public RasterTask { |
| 44 public: | 46 public: |
| 45 typedef base::Callback< | 47 typedef base::Callback< |
| 46 void(const PicturePileImpl::Analysis& analysis, bool was_canceled)> Reply; | 48 void(const PicturePileImpl::Analysis& analysis, bool was_canceled)> Reply; |
| 47 | 49 |
| 48 TestRasterTaskImpl(const Resource* resource, | 50 TestRasterTaskImpl(const Resource* resource, |
| 49 const Reply& reply, | 51 const Reply& reply, |
| 50 ImageDecodeTask::Vector* dependencies) | 52 ImageDecodeTask::Vector* dependencies) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool canceled; | 116 bool canceled; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 typedef std::vector<scoped_refptr<RasterTask> > RasterTaskVector; | 119 typedef std::vector<scoped_refptr<RasterTask> > RasterTaskVector; |
| 118 | 120 |
| 119 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION = 0, ALL = 1 }; | 121 enum NamedTaskSet { REQUIRED_FOR_ACTIVATION = 0, ALL = 1 }; |
| 120 | 122 |
| 121 RasterWorkerPoolTest() | 123 RasterWorkerPoolTest() |
| 122 : context_provider_(TestContextProvider::Create()), | 124 : context_provider_(TestContextProvider::Create()), |
| 123 timeout_seconds_(5), | 125 timeout_seconds_(5), |
| 124 timed_out_(false) { | 126 timed_out_(false) {} |
| 125 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | |
| 126 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 127 | 127 |
| 128 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); | 128 // Overridden from testing::Test: |
| 129 context3d->set_support_sync_query(true); | 129 virtual void SetUp() OVERRIDE { |
| 130 | |
| 131 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | |
| 132 resource_provider_ = ResourceProvider::Create(output_surface_.get(), | |
| 133 shared_bitmap_manager_.get(), | |
| 134 NULL, | |
| 135 0, | |
| 136 false, | |
| 137 1, | |
| 138 false).Pass(); | |
| 139 staging_resource_pool_ = ResourcePool::Create( | |
| 140 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
| 141 | |
| 142 switch (GetParam()) { | 130 switch (GetParam()) { |
| 143 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: | 131 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: |
| 132 Create3dOutputSurfaceAndResourceProvider(); |
| 144 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( | 133 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( |
| 145 base::MessageLoopProxy::current().get(), | 134 base::MessageLoopProxy::current().get(), |
| 146 RasterWorkerPool::GetTaskGraphRunner(), | 135 RasterWorkerPool::GetTaskGraphRunner(), |
| 147 context_provider_.get(), | 136 context_provider_.get(), |
| 148 resource_provider_.get(), | 137 resource_provider_.get(), |
| 149 kMaxTransferBufferUsageBytes); | 138 kMaxTransferBufferUsageBytes); |
| 150 break; | 139 break; |
| 151 case RASTER_WORKER_POOL_TYPE_ZERO_COPY: | 140 case RASTER_WORKER_POOL_TYPE_ZERO_COPY: |
| 141 Create3dOutputSurfaceAndResourceProvider(); |
| 152 raster_worker_pool_ = ZeroCopyRasterWorkerPool::Create( | 142 raster_worker_pool_ = ZeroCopyRasterWorkerPool::Create( |
| 153 base::MessageLoopProxy::current().get(), | 143 base::MessageLoopProxy::current().get(), |
| 154 RasterWorkerPool::GetTaskGraphRunner(), | 144 RasterWorkerPool::GetTaskGraphRunner(), |
| 155 resource_provider_.get()); | 145 resource_provider_.get()); |
| 156 break; | 146 break; |
| 157 case RASTER_WORKER_POOL_TYPE_ONE_COPY: | 147 case RASTER_WORKER_POOL_TYPE_ONE_COPY: |
| 148 Create3dOutputSurfaceAndResourceProvider(); |
| 149 staging_resource_pool_ = ResourcePool::Create( |
| 150 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); |
| 158 raster_worker_pool_ = OneCopyRasterWorkerPool::Create( | 151 raster_worker_pool_ = OneCopyRasterWorkerPool::Create( |
| 159 base::MessageLoopProxy::current().get(), | 152 base::MessageLoopProxy::current().get(), |
| 160 RasterWorkerPool::GetTaskGraphRunner(), | 153 RasterWorkerPool::GetTaskGraphRunner(), |
| 161 context_provider_.get(), | 154 context_provider_.get(), |
| 162 resource_provider_.get(), | 155 resource_provider_.get(), |
| 163 staging_resource_pool_.get()); | 156 staging_resource_pool_.get()); |
| 164 break; | 157 break; |
| 165 case RASTER_WORKER_POOL_TYPE_GPU: | 158 case RASTER_WORKER_POOL_TYPE_GPU: |
| 159 Create3dOutputSurfaceAndResourceProvider(); |
| 166 raster_worker_pool_ = | 160 raster_worker_pool_ = |
| 167 GpuRasterWorkerPool::Create(base::MessageLoopProxy::current().get(), | 161 GpuRasterWorkerPool::Create(base::MessageLoopProxy::current().get(), |
| 168 context_provider_.get(), | 162 context_provider_.get(), |
| 169 resource_provider_.get()); | 163 resource_provider_.get()); |
| 170 break; | 164 break; |
| 165 case RASTER_WORKER_POOL_TYPE_BITMAP: |
| 166 CreateSoftwareOutputSurfaceAndResourceProvider(); |
| 167 raster_worker_pool_ = BitmapRasterWorkerPool::Create( |
| 168 base::MessageLoopProxy::current().get(), |
| 169 RasterWorkerPool::GetTaskGraphRunner(), |
| 170 resource_provider_.get()); |
| 171 break; |
| 171 } | 172 } |
| 172 | 173 |
| 173 DCHECK(raster_worker_pool_); | 174 DCHECK(raster_worker_pool_); |
| 174 raster_worker_pool_->AsRasterizer()->SetClient(this); | 175 raster_worker_pool_->AsRasterizer()->SetClient(this); |
| 175 } | 176 } |
| 176 virtual ~RasterWorkerPoolTest() { | |
| 177 staging_resource_pool_.reset(); | |
| 178 resource_provider_.reset(); | |
| 179 } | |
| 180 | |
| 181 // Overridden from testing::Test: | |
| 182 virtual void TearDown() OVERRIDE { | 177 virtual void TearDown() OVERRIDE { |
| 183 raster_worker_pool_->AsRasterizer()->Shutdown(); | 178 raster_worker_pool_->AsRasterizer()->Shutdown(); |
| 184 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 179 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
| 185 } | 180 } |
| 186 | 181 |
| 187 // Overriden from RasterWorkerPoolClient: | 182 // Overriden from RasterWorkerPoolClient: |
| 188 virtual void DidFinishRunningTasks(TaskSet task_set) OVERRIDE { | 183 virtual void DidFinishRunningTasks(TaskSet task_set) OVERRIDE { |
| 189 if (task_set == ALL) { | 184 if (task_set == ALL) { |
| 190 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 185 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
| 191 base::MessageLoop::current()->Quit(); | 186 base::MessageLoop::current()->Quit(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 id), | 256 id), |
| 262 lock, | 257 lock, |
| 263 &empty)); | 258 &empty)); |
| 264 } | 259 } |
| 265 | 260 |
| 266 const std::vector<RasterTaskResult>& completed_tasks() const { | 261 const std::vector<RasterTaskResult>& completed_tasks() const { |
| 267 return completed_tasks_; | 262 return completed_tasks_; |
| 268 } | 263 } |
| 269 | 264 |
| 270 private: | 265 private: |
| 266 void Create3dOutputSurfaceAndResourceProvider() { |
| 267 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); |
| 268 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 269 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); |
| 270 context3d->set_support_sync_query(true); |
| 271 resource_provider_ = |
| 272 ResourceProvider::Create( |
| 273 output_surface_.get(), NULL, NULL, 0, false, 1, false).Pass(); |
| 274 } |
| 275 |
| 276 void CreateSoftwareOutputSurfaceAndResourceProvider() { |
| 277 output_surface_ = FakeOutputSurface::CreateSoftware( |
| 278 make_scoped_ptr(new SoftwareOutputDevice)); |
| 279 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 280 resource_provider_ = ResourceProvider::Create(output_surface_.get(), |
| 281 &shared_bitmap_manager_, |
| 282 NULL, |
| 283 0, |
| 284 false, |
| 285 1, |
| 286 false).Pass(); |
| 287 } |
| 288 |
| 271 void OnTaskCompleted(scoped_ptr<ScopedResource> resource, | 289 void OnTaskCompleted(scoped_ptr<ScopedResource> resource, |
| 272 unsigned id, | 290 unsigned id, |
| 273 const PicturePileImpl::Analysis& analysis, | 291 const PicturePileImpl::Analysis& analysis, |
| 274 bool was_canceled) { | 292 bool was_canceled) { |
| 275 RasterTaskResult result; | 293 RasterTaskResult result; |
| 276 result.id = id; | 294 result.id = id; |
| 277 result.canceled = was_canceled; | 295 result.canceled = was_canceled; |
| 278 completed_tasks_.push_back(result); | 296 completed_tasks_.push_back(result); |
| 279 } | 297 } |
| 280 | 298 |
| 281 void OnTimeout() { | 299 void OnTimeout() { |
| 282 timed_out_ = true; | 300 timed_out_ = true; |
| 283 base::MessageLoop::current()->Quit(); | 301 base::MessageLoop::current()->Quit(); |
| 284 } | 302 } |
| 285 | 303 |
| 286 protected: | 304 protected: |
| 287 scoped_refptr<TestContextProvider> context_provider_; | 305 scoped_refptr<TestContextProvider> context_provider_; |
| 288 FakeOutputSurfaceClient output_surface_client_; | 306 FakeOutputSurfaceClient output_surface_client_; |
| 289 scoped_ptr<FakeOutputSurface> output_surface_; | 307 scoped_ptr<FakeOutputSurface> output_surface_; |
| 290 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
| 291 scoped_ptr<ResourceProvider> resource_provider_; | 308 scoped_ptr<ResourceProvider> resource_provider_; |
| 292 scoped_ptr<ResourcePool> staging_resource_pool_; | 309 scoped_ptr<ResourcePool> staging_resource_pool_; |
| 293 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 310 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 311 TestSharedBitmapManager shared_bitmap_manager_; |
| 294 base::CancelableClosure timeout_; | 312 base::CancelableClosure timeout_; |
| 295 int timeout_seconds_; | 313 int timeout_seconds_; |
| 296 bool timed_out_; | 314 bool timed_out_; |
| 297 RasterTaskVector tasks_; | 315 RasterTaskVector tasks_; |
| 298 std::vector<RasterTaskResult> completed_tasks_; | 316 std::vector<RasterTaskResult> completed_tasks_; |
| 299 }; | 317 }; |
| 300 | 318 |
| 301 TEST_P(RasterWorkerPoolTest, Basic) { | 319 TEST_P(RasterWorkerPoolTest, Basic) { |
| 302 AppendTask(0u); | 320 AppendTask(0u); |
| 303 AppendTask(1u); | 321 AppendTask(1u); |
| 304 ScheduleTasks(); | 322 ScheduleTasks(); |
| 305 | 323 |
| 306 RunMessageLoopUntilAllTasksHaveCompleted(); | 324 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 307 | 325 |
| 308 ASSERT_EQ(2u, completed_tasks().size()); | 326 ASSERT_EQ(2u, completed_tasks().size()); |
| 309 EXPECT_FALSE(completed_tasks()[0].canceled); | 327 EXPECT_FALSE(completed_tasks()[0].canceled); |
| 310 EXPECT_FALSE(completed_tasks()[1].canceled); | 328 EXPECT_FALSE(completed_tasks()[1].canceled); |
| 311 } | 329 } |
| 312 | 330 |
| 313 TEST_P(RasterWorkerPoolTest, FailedMapResource) { | 331 TEST_P(RasterWorkerPoolTest, FailedMapResource) { |
| 332 if (GetParam() == RASTER_WORKER_POOL_TYPE_BITMAP) |
| 333 return; |
| 334 |
| 314 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); | 335 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); |
| 315 context3d->set_times_map_image_chromium_succeeds(0); | 336 context3d->set_times_map_image_chromium_succeeds(0); |
| 316 context3d->set_times_map_buffer_chromium_succeeds(0); | 337 context3d->set_times_map_buffer_chromium_succeeds(0); |
| 317 AppendTask(0u); | 338 AppendTask(0u); |
| 318 ScheduleTasks(); | 339 ScheduleTasks(); |
| 319 | 340 |
| 320 RunMessageLoopUntilAllTasksHaveCompleted(); | 341 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 321 | 342 |
| 322 ASSERT_EQ(1u, completed_tasks().size()); | 343 ASSERT_EQ(1u, completed_tasks().size()); |
| 323 EXPECT_FALSE(completed_tasks()[0].canceled); | 344 EXPECT_FALSE(completed_tasks()[0].canceled); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // This will time out if a resource that is larger than the throttle limit | 387 // This will time out if a resource that is larger than the throttle limit |
| 367 // never gets scheduled. | 388 // never gets scheduled. |
| 368 RunMessageLoopUntilAllTasksHaveCompleted(); | 389 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 369 } | 390 } |
| 370 | 391 |
| 371 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, | 392 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, |
| 372 RasterWorkerPoolTest, | 393 RasterWorkerPoolTest, |
| 373 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 394 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
| 374 RASTER_WORKER_POOL_TYPE_ZERO_COPY, | 395 RASTER_WORKER_POOL_TYPE_ZERO_COPY, |
| 375 RASTER_WORKER_POOL_TYPE_ONE_COPY, | 396 RASTER_WORKER_POOL_TYPE_ONE_COPY, |
| 376 RASTER_WORKER_POOL_TYPE_GPU)); | 397 RASTER_WORKER_POOL_TYPE_GPU, |
| 398 RASTER_WORKER_POOL_TYPE_BITMAP)); |
| 377 | 399 |
| 378 } // namespace | 400 } // namespace |
| 379 } // namespace cc | 401 } // namespace cc |
| OLD | NEW |