Chromium Code Reviews| Index: cc/resources/gpu_raster_worker_pool.cc |
| diff --git a/cc/resources/gpu_raster_worker_pool.cc b/cc/resources/gpu_raster_worker_pool.cc |
| index 8dc5adcfe04c7d48f29cb72e8461f34b9ad9237e..3003d03bc7d951ff20ec6666344501c645b53f98 100644 |
| --- a/cc/resources/gpu_raster_worker_pool.cc |
| +++ b/cc/resources/gpu_raster_worker_pool.cc |
| @@ -6,13 +6,54 @@ |
| #include "base/debug/trace_event.h" |
| #include "cc/output/context_provider.h" |
| +#include "cc/resources/raster_buffer.h" |
| #include "cc/resources/resource.h" |
| #include "cc/resources/resource_provider.h" |
| #include "cc/resources/scoped_gpu_raster.h" |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| +#include "third_party/skia/include/core/SkSurface.h" |
| #include "third_party/skia/include/gpu/GrContext.h" |
| +#include "third_party/skia/include/utils/SkNullCanvas.h" |
| namespace cc { |
| +namespace { |
| + |
| +class RasterBufferImpl : public RasterBuffer { |
|
vmpstr
2014/09/16 22:15:55
<nit>
Can we come up with a name that isn't using
reveman
2014/09/17 14:40:56
RasterBufferImpl is a more compact way of writing
|
| + public: |
| + RasterBufferImpl(ResourceProvider* resource_provider, |
| + const Resource* resource) |
| + : resource_provider_(resource_provider), |
| + resource_(resource), |
| + surface_(resource_provider->LockForWriteToSkSurface(resource->id())) {} |
| + virtual ~RasterBufferImpl() { |
| + resource_provider_->UnlockForWriteToSkSurface(resource_->id()); |
| + } |
| + |
| + // Overridden from RasterBuffer: |
| + virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE { |
| + skia::RefPtr<SkCanvas> canvas = surface_ |
| + ? skia::SharePtr(surface_->getCanvas()) |
| + : skia::AdoptRef(SkCreateNullCanvas()); |
|
vmpstr
2014/09/16 22:15:55
The previous code did "return skia::RefPtr<SkCanva
reveman
2014/09/17 14:40:56
The return value couldn't be used in DCHECKs as we
|
| + |
| + // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls |
| + // are needed to ensure that canvas returns to its previous state after use. |
| + canvas->save(); |
| + return canvas; |
| + } |
| + virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { |
| + // Balanced with save() call in AcquireSkCanvas. |
| + canvas->restore(); |
| + } |
| + |
| + private: |
| + ResourceProvider* resource_provider_; |
| + const Resource* resource_; |
| + SkSurface* surface_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| +}; |
| + |
| +} // namespace |
| // static |
| scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( |
| @@ -143,12 +184,15 @@ void GpuRasterWorkerPool::CheckForCompletedTasks() { |
| completed_tasks_.clear(); |
| } |
| -RasterBuffer* GpuRasterWorkerPool::AcquireBufferForRaster(RasterTask* task) { |
| - return resource_provider_->AcquireGpuRasterBuffer(task->resource()->id()); |
| +scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( |
| + const Resource* resource) { |
| + return make_scoped_ptr<RasterBuffer>( |
| + new RasterBufferImpl(resource_provider_, resource)); |
| } |
| -void GpuRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) { |
| - resource_provider_->ReleaseGpuRasterBuffer(task->resource()->id()); |
| +void GpuRasterWorkerPool::ReleaseBufferForRaster( |
| + scoped_ptr<RasterBuffer> buffer) { |
| + // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| } |
| void GpuRasterWorkerPool::OnRasterFinished() { |