Chromium Code Reviews| 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 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | |
|
vmpstr
2014/09/24 16:31:51
here as well
reveman
2014/09/24 17:25:27
Done.
| |
| 133 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 134 resource_provider_ = | |
| 135 ResourceProvider::Create( | |
| 136 output_surface_.get(), NULL, NULL, 0, false, 1, false).Pass(); | |
| 144 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( | 137 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( |
| 145 base::MessageLoopProxy::current().get(), | 138 base::MessageLoopProxy::current().get(), |
| 146 RasterWorkerPool::GetTaskGraphRunner(), | 139 RasterWorkerPool::GetTaskGraphRunner(), |
| 147 context_provider_.get(), | 140 context_provider_.get(), |
| 148 resource_provider_.get(), | 141 resource_provider_.get(), |
| 149 kMaxTransferBufferUsageBytes); | 142 kMaxTransferBufferUsageBytes); |
| 150 break; | 143 break; |
| 151 case RASTER_WORKER_POOL_TYPE_ZERO_COPY: | 144 case RASTER_WORKER_POOL_TYPE_ZERO_COPY: |
| 145 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | |
| 146 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 147 resource_provider_ = | |
| 148 ResourceProvider::Create( | |
| 149 output_surface_.get(), NULL, NULL, 0, false, 1, false).Pass(); | |
| 152 raster_worker_pool_ = ZeroCopyRasterWorkerPool::Create( | 150 raster_worker_pool_ = ZeroCopyRasterWorkerPool::Create( |
| 153 base::MessageLoopProxy::current().get(), | 151 base::MessageLoopProxy::current().get(), |
| 154 RasterWorkerPool::GetTaskGraphRunner(), | 152 RasterWorkerPool::GetTaskGraphRunner(), |
| 155 resource_provider_.get()); | 153 resource_provider_.get()); |
| 156 break; | 154 break; |
| 157 case RASTER_WORKER_POOL_TYPE_ONE_COPY: | 155 case RASTER_WORKER_POOL_TYPE_ONE_COPY: |
| 156 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | |
| 157 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 158 context_provider_->TestContext3d()->set_support_sync_query(true); | |
| 159 resource_provider_ = | |
| 160 ResourceProvider::Create( | |
| 161 output_surface_.get(), NULL, NULL, 0, false, 1, false).Pass(); | |
| 162 staging_resource_pool_ = ResourcePool::Create( | |
| 163 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
| 158 raster_worker_pool_ = OneCopyRasterWorkerPool::Create( | 164 raster_worker_pool_ = OneCopyRasterWorkerPool::Create( |
| 159 base::MessageLoopProxy::current().get(), | 165 base::MessageLoopProxy::current().get(), |
| 160 RasterWorkerPool::GetTaskGraphRunner(), | 166 RasterWorkerPool::GetTaskGraphRunner(), |
| 161 context_provider_.get(), | 167 context_provider_.get(), |
| 162 resource_provider_.get(), | 168 resource_provider_.get(), |
| 163 staging_resource_pool_.get()); | 169 staging_resource_pool_.get()); |
| 164 break; | 170 break; |
| 165 case RASTER_WORKER_POOL_TYPE_GPU: | 171 case RASTER_WORKER_POOL_TYPE_GPU: |
| 172 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | |
| 173 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 174 resource_provider_ = | |
| 175 ResourceProvider::Create( | |
| 176 output_surface_.get(), NULL, NULL, 0, false, 1, false).Pass(); | |
| 166 raster_worker_pool_ = | 177 raster_worker_pool_ = |
| 167 GpuRasterWorkerPool::Create(base::MessageLoopProxy::current().get(), | 178 GpuRasterWorkerPool::Create(base::MessageLoopProxy::current().get(), |
| 168 context_provider_.get(), | 179 context_provider_.get(), |
| 169 resource_provider_.get()); | 180 resource_provider_.get()); |
| 170 break; | 181 break; |
| 182 case RASTER_WORKER_POOL_TYPE_BITMAP: | |
| 183 output_surface_ = FakeOutputSurface::CreateSoftware( | |
| 184 make_scoped_ptr(new SoftwareOutputDevice)); | |
| 185 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 186 resource_provider_ = ResourceProvider::Create(output_surface_.get(), | |
| 187 &shared_bitmap_manager_, | |
| 188 NULL, | |
| 189 0, | |
| 190 false, | |
| 191 1, | |
| 192 false).Pass(); | |
| 193 raster_worker_pool_ = BitmapRasterWorkerPool::Create( | |
| 194 base::MessageLoopProxy::current().get(), | |
| 195 RasterWorkerPool::GetTaskGraphRunner(), | |
| 196 resource_provider_.get()); | |
| 197 break; | |
| 171 } | 198 } |
| 172 | 199 |
| 173 DCHECK(raster_worker_pool_); | 200 DCHECK(raster_worker_pool_); |
| 174 raster_worker_pool_->AsRasterizer()->SetClient(this); | 201 raster_worker_pool_->AsRasterizer()->SetClient(this); |
| 175 } | 202 } |
| 176 virtual ~RasterWorkerPoolTest() { | |
| 177 staging_resource_pool_.reset(); | |
| 178 resource_provider_.reset(); | |
| 179 } | |
| 180 | |
| 181 // Overridden from testing::Test: | |
| 182 virtual void TearDown() OVERRIDE { | 203 virtual void TearDown() OVERRIDE { |
| 183 raster_worker_pool_->AsRasterizer()->Shutdown(); | 204 raster_worker_pool_->AsRasterizer()->Shutdown(); |
| 184 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 205 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
| 185 } | 206 } |
| 186 | 207 |
| 187 // Overriden from RasterWorkerPoolClient: | 208 // Overriden from RasterWorkerPoolClient: |
| 188 virtual void DidFinishRunningTasks(TaskSet task_set) OVERRIDE { | 209 virtual void DidFinishRunningTasks(TaskSet task_set) OVERRIDE { |
| 189 if (task_set == ALL) { | 210 if (task_set == ALL) { |
| 190 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 211 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
| 191 base::MessageLoop::current()->Quit(); | 212 base::MessageLoop::current()->Quit(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 | 301 |
| 281 void OnTimeout() { | 302 void OnTimeout() { |
| 282 timed_out_ = true; | 303 timed_out_ = true; |
| 283 base::MessageLoop::current()->Quit(); | 304 base::MessageLoop::current()->Quit(); |
| 284 } | 305 } |
| 285 | 306 |
| 286 protected: | 307 protected: |
| 287 scoped_refptr<TestContextProvider> context_provider_; | 308 scoped_refptr<TestContextProvider> context_provider_; |
| 288 FakeOutputSurfaceClient output_surface_client_; | 309 FakeOutputSurfaceClient output_surface_client_; |
| 289 scoped_ptr<FakeOutputSurface> output_surface_; | 310 scoped_ptr<FakeOutputSurface> output_surface_; |
| 290 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
| 291 scoped_ptr<ResourceProvider> resource_provider_; | 311 scoped_ptr<ResourceProvider> resource_provider_; |
| 292 scoped_ptr<ResourcePool> staging_resource_pool_; | 312 scoped_ptr<ResourcePool> staging_resource_pool_; |
| 293 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 313 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 314 TestSharedBitmapManager shared_bitmap_manager_; | |
| 294 base::CancelableClosure timeout_; | 315 base::CancelableClosure timeout_; |
| 295 int timeout_seconds_; | 316 int timeout_seconds_; |
| 296 bool timed_out_; | 317 bool timed_out_; |
| 297 RasterTaskVector tasks_; | 318 RasterTaskVector tasks_; |
| 298 std::vector<RasterTaskResult> completed_tasks_; | 319 std::vector<RasterTaskResult> completed_tasks_; |
| 299 }; | 320 }; |
| 300 | 321 |
| 301 TEST_P(RasterWorkerPoolTest, Basic) { | 322 TEST_P(RasterWorkerPoolTest, Basic) { |
| 302 AppendTask(0u); | 323 AppendTask(0u); |
| 303 AppendTask(1u); | 324 AppendTask(1u); |
| 304 ScheduleTasks(); | 325 ScheduleTasks(); |
| 305 | 326 |
| 306 RunMessageLoopUntilAllTasksHaveCompleted(); | 327 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 307 | 328 |
| 308 ASSERT_EQ(2u, completed_tasks().size()); | 329 ASSERT_EQ(2u, completed_tasks().size()); |
| 309 EXPECT_FALSE(completed_tasks()[0].canceled); | 330 EXPECT_FALSE(completed_tasks()[0].canceled); |
| 310 EXPECT_FALSE(completed_tasks()[1].canceled); | 331 EXPECT_FALSE(completed_tasks()[1].canceled); |
| 311 } | 332 } |
| 312 | 333 |
| 313 TEST_P(RasterWorkerPoolTest, FailedMapResource) { | 334 TEST_P(RasterWorkerPoolTest, FailedMapResource) { |
| 335 if (GetParam() == RASTER_WORKER_POOL_TYPE_BITMAP) | |
| 336 return; | |
| 337 | |
| 314 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); | 338 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); |
| 315 context3d->set_times_map_image_chromium_succeeds(0); | 339 context3d->set_times_map_image_chromium_succeeds(0); |
| 316 context3d->set_times_map_buffer_chromium_succeeds(0); | 340 context3d->set_times_map_buffer_chromium_succeeds(0); |
| 317 AppendTask(0u); | 341 AppendTask(0u); |
| 318 ScheduleTasks(); | 342 ScheduleTasks(); |
| 319 | 343 |
| 320 RunMessageLoopUntilAllTasksHaveCompleted(); | 344 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 321 | 345 |
| 322 ASSERT_EQ(1u, completed_tasks().size()); | 346 ASSERT_EQ(1u, completed_tasks().size()); |
| 323 EXPECT_FALSE(completed_tasks()[0].canceled); | 347 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 | 390 // This will time out if a resource that is larger than the throttle limit |
| 367 // never gets scheduled. | 391 // never gets scheduled. |
| 368 RunMessageLoopUntilAllTasksHaveCompleted(); | 392 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 369 } | 393 } |
| 370 | 394 |
| 371 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, | 395 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, |
| 372 RasterWorkerPoolTest, | 396 RasterWorkerPoolTest, |
| 373 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 397 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
| 374 RASTER_WORKER_POOL_TYPE_ZERO_COPY, | 398 RASTER_WORKER_POOL_TYPE_ZERO_COPY, |
| 375 RASTER_WORKER_POOL_TYPE_ONE_COPY, | 399 RASTER_WORKER_POOL_TYPE_ONE_COPY, |
| 376 RASTER_WORKER_POOL_TYPE_GPU)); | 400 RASTER_WORKER_POOL_TYPE_GPU, |
| 401 RASTER_WORKER_POOL_TYPE_BITMAP)); | |
| 377 | 402 |
| 378 } // namespace | 403 } // namespace |
| 379 } // namespace cc | 404 } // namespace cc |
| OLD | NEW |