| 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/raster/tile_task_worker_pool.h" | 5 #include "cc/raster/tile_task_worker_pool.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 19 #include "cc/base/unique_notifier.h" | 20 #include "cc/base/unique_notifier.h" |
| 20 #include "cc/raster/bitmap_tile_task_worker_pool.h" | 21 #include "cc/raster/bitmap_tile_task_worker_pool.h" |
| 21 #include "cc/raster/gpu_rasterizer.h" | 22 #include "cc/raster/gpu_rasterizer.h" |
| 22 #include "cc/raster/gpu_tile_task_worker_pool.h" | 23 #include "cc/raster/gpu_tile_task_worker_pool.h" |
| 23 #include "cc/raster/one_copy_tile_task_worker_pool.h" | 24 #include "cc/raster/one_copy_tile_task_worker_pool.h" |
| 24 #include "cc/raster/raster_buffer.h" | 25 #include "cc/raster/raster_buffer.h" |
| 25 #include "cc/raster/synchronous_task_graph_runner.h" | 26 #include "cc/raster/synchronous_task_graph_runner.h" |
| 26 #include "cc/raster/tile_task_runner.h" | 27 #include "cc/raster/tile_task_runner.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 client->ReleaseBufferForRaster(std::move(raster_buffer_)); | 82 client->ReleaseBufferForRaster(std::move(raster_buffer_)); |
| 82 reply_.Run(!HasFinishedRunning()); | 83 reply_.Run(!HasFinishedRunning()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 protected: | 86 protected: |
| 86 ~TestRasterTaskImpl() override {} | 87 ~TestRasterTaskImpl() override {} |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 const Resource* resource_; | 90 const Resource* resource_; |
| 90 const Reply reply_; | 91 const Reply reply_; |
| 91 scoped_ptr<RasterBuffer> raster_buffer_; | 92 std::unique_ptr<RasterBuffer> raster_buffer_; |
| 92 scoped_refptr<RasterSource> raster_source_; | 93 scoped_refptr<RasterSource> raster_source_; |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); | 95 DISALLOW_COPY_AND_ASSIGN(TestRasterTaskImpl); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { | 98 class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
| 98 public: | 99 public: |
| 99 BlockingTestRasterTaskImpl(const Resource* resource, | 100 BlockingTestRasterTaskImpl(const Resource* resource, |
| 100 const Reply& reply, | 101 const Reply& reply, |
| 101 base::Lock* lock, | 102 base::Lock* lock, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 for (RasterTaskVector::const_iterator it = tasks_.begin(); | 198 for (RasterTaskVector::const_iterator it = tasks_.begin(); |
| 198 it != tasks_.end(); ++it) { | 199 it != tasks_.end(); ++it) { |
| 199 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, | 200 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, |
| 200 0 /* dependencies */); | 201 0 /* dependencies */); |
| 201 } | 202 } |
| 202 | 203 |
| 203 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph_); | 204 tile_task_worker_pool_->AsTileTaskRunner()->ScheduleTasks(&graph_); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void AppendTask(unsigned id, const gfx::Size& size) { | 207 void AppendTask(unsigned id, const gfx::Size& size) { |
| 207 scoped_ptr<ScopedResource> resource( | 208 std::unique_ptr<ScopedResource> resource( |
| 208 ScopedResource::Create(resource_provider_.get())); | 209 ScopedResource::Create(resource_provider_.get())); |
| 209 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 210 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 210 RGBA_8888); | 211 RGBA_8888); |
| 211 const Resource* const_resource = resource.get(); | 212 const Resource* const_resource = resource.get(); |
| 212 | 213 |
| 213 ImageDecodeTask::Vector empty; | 214 ImageDecodeTask::Vector empty; |
| 214 tasks_.push_back(new TestRasterTaskImpl( | 215 tasks_.push_back(new TestRasterTaskImpl( |
| 215 const_resource, | 216 const_resource, |
| 216 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, | 217 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, |
| 217 base::Unretained(this), base::Passed(&resource), id), | 218 base::Unretained(this), base::Passed(&resource), id), |
| 218 &empty)); | 219 &empty)); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } | 222 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
| 222 | 223 |
| 223 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 224 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
| 224 const gfx::Size size(1, 1); | 225 const gfx::Size size(1, 1); |
| 225 | 226 |
| 226 scoped_ptr<ScopedResource> resource( | 227 std::unique_ptr<ScopedResource> resource( |
| 227 ScopedResource::Create(resource_provider_.get())); | 228 ScopedResource::Create(resource_provider_.get())); |
| 228 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 229 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 229 RGBA_8888); | 230 RGBA_8888); |
| 230 const Resource* const_resource = resource.get(); | 231 const Resource* const_resource = resource.get(); |
| 231 | 232 |
| 232 ImageDecodeTask::Vector empty; | 233 ImageDecodeTask::Vector empty; |
| 233 tasks_.push_back(new BlockingTestRasterTaskImpl( | 234 tasks_.push_back(new BlockingTestRasterTaskImpl( |
| 234 const_resource, | 235 const_resource, |
| 235 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, | 236 base::Bind(&TileTaskWorkerPoolTest::OnTaskCompleted, |
| 236 base::Unretained(this), base::Passed(&resource), id), | 237 base::Unretained(this), base::Passed(&resource), id), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 255 worker_context_provider_); | 256 worker_context_provider_); |
| 256 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 257 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 257 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); | 258 TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d(); |
| 258 context3d->set_support_sync_query(true); | 259 context3d->set_support_sync_query(true); |
| 259 resource_provider_ = FakeResourceProvider::Create( | 260 resource_provider_ = FakeResourceProvider::Create( |
| 260 output_surface_.get(), nullptr, &gpu_memory_buffer_manager_); | 261 output_surface_.get(), nullptr, &gpu_memory_buffer_manager_); |
| 261 } | 262 } |
| 262 | 263 |
| 263 void CreateSoftwareOutputSurfaceAndResourceProvider() { | 264 void CreateSoftwareOutputSurfaceAndResourceProvider() { |
| 264 output_surface_ = FakeOutputSurface::CreateSoftware( | 265 output_surface_ = FakeOutputSurface::CreateSoftware( |
| 265 make_scoped_ptr(new SoftwareOutputDevice)); | 266 base::WrapUnique(new SoftwareOutputDevice)); |
| 266 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 267 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 267 resource_provider_ = FakeResourceProvider::Create( | 268 resource_provider_ = FakeResourceProvider::Create( |
| 268 output_surface_.get(), &shared_bitmap_manager_, nullptr); | 269 output_surface_.get(), &shared_bitmap_manager_, nullptr); |
| 269 } | 270 } |
| 270 | 271 |
| 271 void OnTaskCompleted( | 272 void OnTaskCompleted(std::unique_ptr<ScopedResource> resource, |
| 272 scoped_ptr<ScopedResource> resource, | 273 unsigned id, |
| 273 unsigned id, | 274 bool was_canceled) { |
| 274 bool was_canceled) { | |
| 275 RasterTaskResult result; | 275 RasterTaskResult result; |
| 276 result.id = id; | 276 result.id = id; |
| 277 result.canceled = was_canceled; | 277 result.canceled = was_canceled; |
| 278 completed_tasks_.push_back(result); | 278 completed_tasks_.push_back(result); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void OnTimeout() { | 281 void OnTimeout() { |
| 282 timed_out_ = true; | 282 timed_out_ = true; |
| 283 base::MessageLoop::current()->QuitWhenIdle(); | 283 base::MessageLoop::current()->QuitWhenIdle(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 protected: | 286 protected: |
| 287 scoped_refptr<TestContextProvider> context_provider_; | 287 scoped_refptr<TestContextProvider> context_provider_; |
| 288 scoped_refptr<TestContextProvider> worker_context_provider_; | 288 scoped_refptr<TestContextProvider> worker_context_provider_; |
| 289 FakeOutputSurfaceClient output_surface_client_; | 289 FakeOutputSurfaceClient output_surface_client_; |
| 290 scoped_ptr<FakeOutputSurface> output_surface_; | 290 std::unique_ptr<FakeOutputSurface> output_surface_; |
| 291 scoped_ptr<ResourceProvider> resource_provider_; | 291 std::unique_ptr<ResourceProvider> resource_provider_; |
| 292 scoped_ptr<TileTaskWorkerPool> tile_task_worker_pool_; | 292 std::unique_ptr<TileTaskWorkerPool> tile_task_worker_pool_; |
| 293 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; | 293 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
| 294 TestSharedBitmapManager shared_bitmap_manager_; | 294 TestSharedBitmapManager shared_bitmap_manager_; |
| 295 SynchronousTaskGraphRunner task_graph_runner_; | 295 SynchronousTaskGraphRunner task_graph_runner_; |
| 296 base::CancelableClosure timeout_; | 296 base::CancelableClosure timeout_; |
| 297 UniqueNotifier all_tile_tasks_finished_; | 297 UniqueNotifier all_tile_tasks_finished_; |
| 298 int timeout_seconds_; | 298 int timeout_seconds_; |
| 299 bool timed_out_; | 299 bool timed_out_; |
| 300 RasterTaskVector tasks_; | 300 RasterTaskVector tasks_; |
| 301 std::vector<RasterTaskResult> completed_tasks_; | 301 std::vector<RasterTaskResult> completed_tasks_; |
| 302 TaskGraph graph_; | 302 TaskGraph graph_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 370 |
| 371 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, | 371 INSTANTIATE_TEST_CASE_P(TileTaskWorkerPoolTests, |
| 372 TileTaskWorkerPoolTest, | 372 TileTaskWorkerPoolTest, |
| 373 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, | 373 ::testing::Values(TILE_TASK_WORKER_POOL_TYPE_ZERO_COPY, |
| 374 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, | 374 TILE_TASK_WORKER_POOL_TYPE_ONE_COPY, |
| 375 TILE_TASK_WORKER_POOL_TYPE_GPU, | 375 TILE_TASK_WORKER_POOL_TYPE_GPU, |
| 376 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); | 376 TILE_TASK_WORKER_POOL_TYPE_BITMAP)); |
| 377 | 377 |
| 378 } // namespace | 378 } // namespace |
| 379 } // namespace cc | 379 } // namespace cc |
| OLD | NEW |