Index: cc/raster/raster_buffer_provider_unittest.cc |
diff --git a/cc/raster/raster_buffer_provider_unittest.cc b/cc/raster/raster_buffer_provider_unittest.cc |
index ffdb710b0e43df2048a2b7f86ab6af2d8edff3d6..a3f07c72aa1afeb91b7e38d72092cfc0c315bcf5 100644 |
--- a/cc/raster/raster_buffer_provider_unittest.cc |
+++ b/cc/raster/raster_buffer_provider_unittest.cc |
@@ -51,16 +51,26 @@ enum RasterBufferProviderType { |
RASTER_BUFFER_PROVIDER_TYPE_BITMAP |
}; |
-class TestRasterTaskImpl : public TileTask { |
+class TestRasterTaskCompletionHandler { |
public: |
- typedef base::Callback<void(bool was_canceled)> Reply; |
+ virtual void OnRasterTaskCompleted( |
+ std::unique_ptr<RasterBuffer> raster_buffer, |
+ unsigned id, |
+ bool was_canceled) = 0; |
+}; |
- TestRasterTaskImpl(const Resource* resource, |
- const Reply& reply, |
+class TestRasterTaskImpl : public TileTask { |
+ public: |
+ TestRasterTaskImpl(TestRasterTaskCompletionHandler* completion_handler, |
+ std::unique_ptr<ScopedResource> resource, |
+ unsigned id, |
+ std::unique_ptr<RasterBuffer> raster_buffer, |
TileTask::Vector* dependencies) |
: TileTask(true, dependencies), |
- resource_(resource), |
- reply_(reply), |
+ completion_handler_(completion_handler), |
+ resource_(std::move(resource)), |
+ id_(id), |
+ raster_buffer_(std::move(raster_buffer)), |
raster_source_(FakeRasterSource::CreateFilled(gfx::Size(1, 1))) {} |
// Overridden from Task: |
@@ -72,22 +82,18 @@ class TestRasterTaskImpl : public TileTask { |
} |
// Overridden from TileTask: |
- void ScheduleOnOriginThread(RasterBufferProvider* provider) override { |
- // The raster buffer has no tile ids associated with it for partial update, |
- // so doesn't need to provide a valid dirty rect. |
- raster_buffer_ = provider->AcquireBufferForRaster(resource_, 0, 0); |
- } |
- void CompleteOnOriginThread(RasterBufferProvider* provider) override { |
- provider->ReleaseBufferForRaster(std::move(raster_buffer_)); |
- reply_.Run(!state().IsFinished()); |
+ void OnTaskCompleted() override { |
+ completion_handler_->OnRasterTaskCompleted(std::move(raster_buffer_), id_, |
+ state().IsCanceled()); |
} |
protected: |
~TestRasterTaskImpl() override {} |
private: |
- const Resource* resource_; |
- const Reply reply_; |
+ TestRasterTaskCompletionHandler* completion_handler_; |
+ std::unique_ptr<ScopedResource> resource_; |
+ unsigned id_; |
std::unique_ptr<RasterBuffer> raster_buffer_; |
scoped_refptr<RasterSource> raster_source_; |
@@ -96,11 +102,19 @@ class TestRasterTaskImpl : public TileTask { |
class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
public: |
- BlockingTestRasterTaskImpl(const Resource* resource, |
- const Reply& reply, |
- base::Lock* lock, |
- TileTask::Vector* dependencies) |
- : TestRasterTaskImpl(resource, reply, dependencies), lock_(lock) {} |
+ BlockingTestRasterTaskImpl( |
+ TestRasterTaskCompletionHandler* completion_handler, |
+ std::unique_ptr<ScopedResource> resource, |
+ unsigned id, |
+ std::unique_ptr<RasterBuffer> raster_buffer, |
+ base::Lock* lock, |
+ TileTask::Vector* dependencies) |
+ : TestRasterTaskImpl(completion_handler, |
+ std::move(resource), |
+ id, |
+ std::move(raster_buffer), |
+ dependencies), |
+ lock_(lock) {} |
// Overridden from Task: |
void RunOnWorkerThread() override { |
@@ -118,7 +132,8 @@ class BlockingTestRasterTaskImpl : public TestRasterTaskImpl { |
}; |
class RasterBufferProviderTest |
- : public testing::TestWithParam<RasterBufferProviderType> { |
+ : public TestRasterTaskCompletionHandler, |
+ public testing::TestWithParam<RasterBufferProviderType> { |
public: |
struct RasterTaskResult { |
unsigned id; |
@@ -207,14 +222,15 @@ class RasterBufferProviderTest |
ScopedResource::Create(resource_provider_.get())); |
resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
RGBA_8888); |
- const Resource* const_resource = resource.get(); |
+ // The raster buffer has no tile ids associated with it for partial update, |
+ // so doesn't need to provide a valid dirty rect. |
+ std::unique_ptr<RasterBuffer> raster_buffer = |
+ tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
+ resource.get(), 0, 0); |
TileTask::Vector empty; |
- tasks_.push_back(new TestRasterTaskImpl( |
- const_resource, |
- base::Bind(&RasterBufferProviderTest::OnTaskCompleted, |
- base::Unretained(this), base::Passed(&resource), id), |
- &empty)); |
+ tasks_.push_back(new TestRasterTaskImpl(this, std::move(resource), id, |
+ std::move(raster_buffer), &empty)); |
} |
void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
@@ -226,14 +242,13 @@ class RasterBufferProviderTest |
ScopedResource::Create(resource_provider_.get())); |
resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
RGBA_8888); |
- const Resource* const_resource = resource.get(); |
+ std::unique_ptr<RasterBuffer> raster_buffer = |
+ tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
+ resource.get(), 0, 0); |
TileTask::Vector empty; |
tasks_.push_back(new BlockingTestRasterTaskImpl( |
- const_resource, |
- base::Bind(&RasterBufferProviderTest::OnTaskCompleted, |
- base::Unretained(this), base::Passed(&resource), id), |
- lock, &empty)); |
+ this, std::move(resource), id, std::move(raster_buffer), lock, &empty)); |
} |
const std::vector<RasterTaskResult>& completed_tasks() const { |
@@ -248,6 +263,17 @@ class RasterBufferProviderTest |
context_provider->ContextGL()->Flush(); |
} |
+ void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, |
+ unsigned id, |
+ bool was_canceled) override { |
+ tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( |
+ std::move(raster_buffer)); |
+ RasterTaskResult result; |
+ result.id = id; |
+ result.canceled = was_canceled; |
+ completed_tasks_.push_back(result); |
+ } |
+ |
private: |
void Create3dOutputSurfaceAndResourceProvider() { |
output_surface_ = FakeOutputSurface::Create3d(context_provider_, |
@@ -267,15 +293,6 @@ class RasterBufferProviderTest |
output_surface_.get(), &shared_bitmap_manager_, nullptr); |
} |
- void OnTaskCompleted(std::unique_ptr<ScopedResource> resource, |
- unsigned id, |
- bool was_canceled) { |
- RasterTaskResult result; |
- result.id = id; |
- result.canceled = was_canceled; |
- completed_tasks_.push_back(result); |
- } |
- |
void OnTimeout() { |
timed_out_ = true; |
base::MessageLoop::current()->QuitWhenIdle(); |