| 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/direct_raster_worker_pool.h" | 11 #include "cc/resources/direct_raster_worker_pool.h" |
| 12 #include "cc/resources/image_copy_raster_worker_pool.h" |
| 12 #include "cc/resources/image_raster_worker_pool.h" | 13 #include "cc/resources/image_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/rasterizer.h" | 17 #include "cc/resources/rasterizer.h" |
| 18 #include "cc/resources/resource_pool.h" |
| 17 #include "cc/resources/resource_provider.h" | 19 #include "cc/resources/resource_provider.h" |
| 18 #include "cc/resources/scoped_resource.h" | 20 #include "cc/resources/scoped_resource.h" |
| 19 #include "cc/test/fake_output_surface.h" | 21 #include "cc/test/fake_output_surface.h" |
| 20 #include "cc/test/fake_output_surface_client.h" | 22 #include "cc/test/fake_output_surface_client.h" |
| 21 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
| 22 #include "cc/test/test_web_graphics_context_3d.h" | 24 #include "cc/test/test_web_graphics_context_3d.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| 25 namespace cc { | 27 namespace cc { |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 enum RasterThread { | 30 enum RasterThread { |
| 29 RASTER_THREAD_NONE, | 31 RASTER_THREAD_NONE, |
| 30 RASTER_THREAD_ORIGIN, | 32 RASTER_THREAD_ORIGIN, |
| 31 RASTER_THREAD_WORKER | 33 RASTER_THREAD_WORKER |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 enum RasterWorkerPoolType { | 36 enum RasterWorkerPoolType { |
| 35 RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 37 RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
| 36 RASTER_WORKER_POOL_TYPE_IMAGE, | 38 RASTER_WORKER_POOL_TYPE_IMAGE, |
| 39 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, |
| 37 RASTER_WORKER_POOL_TYPE_DIRECT | 40 RASTER_WORKER_POOL_TYPE_DIRECT |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 class TestRasterTaskImpl : public RasterTask { | 43 class TestRasterTaskImpl : public RasterTask { |
| 41 public: | 44 public: |
| 42 typedef base::Callback<void(const PicturePileImpl::Analysis& analysis, | 45 typedef base::Callback<void(const PicturePileImpl::Analysis& analysis, |
| 43 bool was_canceled, | 46 bool was_canceled, |
| 44 RasterThread raster_thread)> Reply; | 47 RasterThread raster_thread)> Reply; |
| 45 | 48 |
| 46 TestRasterTaskImpl(const Resource* resource, | 49 TestRasterTaskImpl(const Resource* resource, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 timeout_seconds_(5), | 126 timeout_seconds_(5), |
| 124 timed_out_(false) { | 127 timed_out_(false) { |
| 125 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); | 128 output_surface_ = FakeOutputSurface::Create3d(context_provider_).Pass(); |
| 126 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 129 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 127 | 130 |
| 128 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 131 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
| 129 resource_provider_ = | 132 resource_provider_ = |
| 130 ResourceProvider::Create( | 133 ResourceProvider::Create( |
| 131 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1) | 134 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1) |
| 132 .Pass(); | 135 .Pass(); |
| 136 staging_resource_pool_ = ResourcePool::Create( |
| 137 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); |
| 133 | 138 |
| 134 switch (GetParam()) { | 139 switch (GetParam()) { |
| 135 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: | 140 case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: |
| 136 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( | 141 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( |
| 137 base::MessageLoopProxy::current().get(), | 142 base::MessageLoopProxy::current().get(), |
| 138 RasterWorkerPool::GetTaskGraphRunner(), | 143 RasterWorkerPool::GetTaskGraphRunner(), |
| 139 resource_provider_.get(), | 144 resource_provider_.get(), |
| 140 std::numeric_limits<size_t>::max()); | 145 std::numeric_limits<size_t>::max()); |
| 141 break; | 146 break; |
| 142 case RASTER_WORKER_POOL_TYPE_IMAGE: | 147 case RASTER_WORKER_POOL_TYPE_IMAGE: |
| 143 raster_worker_pool_ = ImageRasterWorkerPool::Create( | 148 raster_worker_pool_ = ImageRasterWorkerPool::Create( |
| 144 base::MessageLoopProxy::current().get(), | 149 base::MessageLoopProxy::current().get(), |
| 145 RasterWorkerPool::GetTaskGraphRunner(), | 150 RasterWorkerPool::GetTaskGraphRunner(), |
| 146 resource_provider_.get()); | 151 resource_provider_.get()); |
| 147 break; | 152 break; |
| 153 case RASTER_WORKER_POOL_TYPE_IMAGE_COPY: |
| 154 raster_worker_pool_ = ImageCopyRasterWorkerPool::Create( |
| 155 base::MessageLoopProxy::current().get(), |
| 156 RasterWorkerPool::GetTaskGraphRunner(), |
| 157 resource_provider_.get(), |
| 158 staging_resource_pool_.get()); |
| 159 break; |
| 148 case RASTER_WORKER_POOL_TYPE_DIRECT: | 160 case RASTER_WORKER_POOL_TYPE_DIRECT: |
| 149 raster_worker_pool_ = DirectRasterWorkerPool::Create( | 161 raster_worker_pool_ = DirectRasterWorkerPool::Create( |
| 150 base::MessageLoopProxy::current().get(), | 162 base::MessageLoopProxy::current().get(), |
| 151 resource_provider_.get(), | 163 resource_provider_.get(), |
| 152 context_provider_.get()); | 164 context_provider_.get()); |
| 153 break; | 165 break; |
| 154 } | 166 } |
| 155 | 167 |
| 156 DCHECK(raster_worker_pool_); | 168 DCHECK(raster_worker_pool_); |
| 157 raster_worker_pool_->AsRasterizer()->SetClient(this); | 169 raster_worker_pool_->AsRasterizer()->SetClient(this); |
| 158 } | 170 } |
| 159 virtual ~RasterWorkerPoolTest() { resource_provider_.reset(); } | 171 virtual ~RasterWorkerPoolTest() { |
| 172 staging_resource_pool_.reset(); |
| 173 resource_provider_.reset(); |
| 174 } |
| 160 | 175 |
| 161 // Overridden from testing::Test: | 176 // Overridden from testing::Test: |
| 162 virtual void TearDown() OVERRIDE { | 177 virtual void TearDown() OVERRIDE { |
| 163 raster_worker_pool_->AsRasterizer()->Shutdown(); | 178 raster_worker_pool_->AsRasterizer()->Shutdown(); |
| 164 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); | 179 raster_worker_pool_->AsRasterizer()->CheckForCompletedTasks(); |
| 165 } | 180 } |
| 166 | 181 |
| 167 // Overriden from RasterWorkerPoolClient: | 182 // Overriden from RasterWorkerPoolClient: |
| 168 virtual bool ShouldForceTasksRequiredForActivationToComplete() const | 183 virtual bool ShouldForceTasksRequiredForActivationToComplete() const |
| 169 OVERRIDE { | 184 OVERRIDE { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 timed_out_ = true; | 276 timed_out_ = true; |
| 262 base::MessageLoop::current()->Quit(); | 277 base::MessageLoop::current()->Quit(); |
| 263 } | 278 } |
| 264 | 279 |
| 265 protected: | 280 protected: |
| 266 scoped_refptr<TestContextProvider> context_provider_; | 281 scoped_refptr<TestContextProvider> context_provider_; |
| 267 FakeOutputSurfaceClient output_surface_client_; | 282 FakeOutputSurfaceClient output_surface_client_; |
| 268 scoped_ptr<FakeOutputSurface> output_surface_; | 283 scoped_ptr<FakeOutputSurface> output_surface_; |
| 269 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 284 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 270 scoped_ptr<ResourceProvider> resource_provider_; | 285 scoped_ptr<ResourceProvider> resource_provider_; |
| 286 scoped_ptr<ResourcePool> staging_resource_pool_; |
| 271 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 287 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 272 base::CancelableClosure timeout_; | 288 base::CancelableClosure timeout_; |
| 273 int timeout_seconds_; | 289 int timeout_seconds_; |
| 274 bool timed_out_; | 290 bool timed_out_; |
| 275 RasterTaskVector tasks_; | 291 RasterTaskVector tasks_; |
| 276 std::vector<RasterTaskResult> completed_tasks_; | 292 std::vector<RasterTaskResult> completed_tasks_; |
| 277 }; | 293 }; |
| 278 | 294 |
| 279 TEST_P(RasterWorkerPoolTest, Basic) { | 295 TEST_P(RasterWorkerPoolTest, Basic) { |
| 280 AppendTask(0u); | 296 AppendTask(0u); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // Unblock the first task to allow the second task to complete. | 341 // Unblock the first task to allow the second task to complete. |
| 326 lock.Release(); | 342 lock.Release(); |
| 327 | 343 |
| 328 RunMessageLoopUntilAllTasksHaveCompleted(); | 344 RunMessageLoopUntilAllTasksHaveCompleted(); |
| 329 } | 345 } |
| 330 | 346 |
| 331 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, | 347 INSTANTIATE_TEST_CASE_P(RasterWorkerPoolTests, |
| 332 RasterWorkerPoolTest, | 348 RasterWorkerPoolTest, |
| 333 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, | 349 ::testing::Values(RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER, |
| 334 RASTER_WORKER_POOL_TYPE_IMAGE, | 350 RASTER_WORKER_POOL_TYPE_IMAGE, |
| 351 RASTER_WORKER_POOL_TYPE_IMAGE_COPY, |
| 335 RASTER_WORKER_POOL_TYPE_DIRECT)); | 352 RASTER_WORKER_POOL_TYPE_DIRECT)); |
| 336 | 353 |
| 337 } // namespace | 354 } // namespace |
| 338 } // namespace cc | 355 } // namespace cc |
| OLD | NEW |