| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gpu_raster_worker_pool.h" | 5 #include "cc/resources/gpu_raster_worker_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
| 11 #include "cc/resources/raster_buffer.h" | 11 #include "cc/resources/raster_buffer.h" |
| 12 #include "cc/resources/resource.h" | 12 #include "cc/resources/resource.h" |
| 13 #include "cc/resources/resource_provider.h" | 13 #include "cc/resources/resource_provider.h" |
| 14 #include "cc/resources/scoped_gpu_raster.h" | 14 #include "cc/resources/scoped_gpu_raster.h" |
| 15 #include "gpu/command_buffer/client/gles2_interface.h" | 15 #include "gpu/command_buffer/client/gles2_interface.h" |
| 16 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 17 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 16 #include "third_party/skia/include/core/SkSurface.h" | 18 #include "third_party/skia/include/core/SkSurface.h" |
| 17 #include "third_party/skia/include/gpu/GrContext.h" | 19 #include "third_party/skia/include/gpu/GrContext.h" |
| 18 #include "third_party/skia/include/utils/SkNullCanvas.h" | 20 #include "third_party/skia/include/utils/SkNullCanvas.h" |
| 19 | 21 |
| 20 namespace cc { | 22 namespace cc { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 class RasterBufferImpl : public RasterBuffer { | 25 class RasterBufferImpl : public RasterBuffer { |
| 24 public: | 26 public: |
| 25 RasterBufferImpl(ResourceProvider* resource_provider, | 27 RasterBufferImpl(ResourceProvider* resource_provider, |
| 26 const Resource* resource) | 28 const Resource* resource, |
| 29 SkMultiPictureDraw* multi_picture_draw) |
| 27 : resource_provider_(resource_provider), | 30 : resource_provider_(resource_provider), |
| 28 resource_(resource), | 31 resource_(resource), |
| 29 surface_(resource_provider->LockForWriteToSkSurface(resource->id())) {} | 32 surface_(resource_provider->LockForWriteToSkSurface(resource->id())), |
| 33 multi_picture_draw_(multi_picture_draw) {} |
| 30 virtual ~RasterBufferImpl() { | 34 virtual ~RasterBufferImpl() { |
| 31 resource_provider_->UnlockForWriteToSkSurface(resource_->id()); | 35 resource_provider_->UnlockForWriteToSkSurface(resource_->id()); |
| 32 } | 36 } |
| 33 | 37 |
| 34 // Overridden from RasterBuffer: | 38 // Overridden from RasterBuffer: |
| 35 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE { | 39 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE { |
| 36 skia::RefPtr<SkCanvas> canvas = surface_ | 40 if (!surface_) |
| 37 ? skia::SharePtr(surface_->getCanvas()) | 41 return skia::AdoptRef(SkCreateNullCanvas()); |
| 38 : skia::AdoptRef(SkCreateNullCanvas()); | 42 |
| 43 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(recorder_.beginRecording( |
| 44 resource_->size().width(), resource_->size().height())); |
| 39 | 45 |
| 40 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls | 46 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls |
| 41 // are needed to ensure that canvas returns to its previous state after use. | 47 // are needed to ensure that canvas returns to its previous state after use. |
| 42 canvas->save(); | 48 canvas->save(); |
| 43 return canvas; | 49 return canvas; |
| 44 } | 50 } |
| 45 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { | 51 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { |
| 52 if (!surface_) |
| 53 return; |
| 54 |
| 46 // Balanced with save() call in AcquireSkCanvas. | 55 // Balanced with save() call in AcquireSkCanvas. |
| 47 canvas->restore(); | 56 canvas->restore(); |
| 57 |
| 58 // Add the canvas and recorded picture to |multi_picture_draw_|. |
| 59 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder_.endRecording()); |
| 60 multi_picture_draw_->add(surface_->getCanvas(), picture.get()); |
| 48 } | 61 } |
| 49 | 62 |
| 50 private: | 63 private: |
| 51 ResourceProvider* resource_provider_; | 64 ResourceProvider* resource_provider_; |
| 52 const Resource* resource_; | 65 const Resource* resource_; |
| 53 SkSurface* surface_; | 66 SkSurface* surface_; |
| 67 SkMultiPictureDraw* multi_picture_draw_; |
| 68 SkPictureRecorder recorder_; |
| 54 | 69 |
| 55 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 70 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 56 }; | 71 }; |
| 57 | 72 |
| 58 } // namespace | 73 } // namespace |
| 59 | 74 |
| 60 // static | 75 // static |
| 61 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( | 76 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( |
| 62 base::SequencedTaskRunner* task_runner, | 77 base::SequencedTaskRunner* task_runner, |
| 63 ContextProvider* context_provider, | 78 ContextProvider* context_provider, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 completed_tasks_.clear(); | 196 completed_tasks_.clear(); |
| 182 } | 197 } |
| 183 | 198 |
| 184 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( | 199 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( |
| 185 const Resource* resource) { | 200 const Resource* resource) { |
| 186 // RasterBuffer implementation depends on a SkSurface having been acquired for | 201 // RasterBuffer implementation depends on a SkSurface having been acquired for |
| 187 // the resource. | 202 // the resource. |
| 188 resource_provider_->AcquireSkSurface(resource->id()); | 203 resource_provider_->AcquireSkSurface(resource->id()); |
| 189 | 204 |
| 190 return make_scoped_ptr<RasterBuffer>( | 205 return make_scoped_ptr<RasterBuffer>( |
| 191 new RasterBufferImpl(resource_provider_, resource)); | 206 new RasterBufferImpl(resource_provider_, resource, &multi_picture_draw_)); |
| 192 } | 207 } |
| 193 | 208 |
| 194 void GpuRasterWorkerPool::ReleaseBufferForRaster( | 209 void GpuRasterWorkerPool::ReleaseBufferForRaster( |
| 195 scoped_ptr<RasterBuffer> buffer) { | 210 scoped_ptr<RasterBuffer> buffer) { |
| 196 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 211 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 197 } | 212 } |
| 198 | 213 |
| 199 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { | 214 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { |
| 200 TRACE_EVENT1( | 215 TRACE_EVENT1( |
| 201 "cc", "GpuRasterWorkerPool::OnRasterFinished", "task_set", task_set); | 216 "cc", "GpuRasterWorkerPool::OnRasterFinished", "task_set", task_set); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 217 } | 232 } |
| 218 | 233 |
| 219 void GpuRasterWorkerPool::RunTasksOnOriginThread() { | 234 void GpuRasterWorkerPool::RunTasksOnOriginThread() { |
| 220 TRACE_EVENT0("cc", "GpuRasterWorkerPool::RunTasksOnOriginThread"); | 235 TRACE_EVENT0("cc", "GpuRasterWorkerPool::RunTasksOnOriginThread"); |
| 221 | 236 |
| 222 DCHECK(run_tasks_on_origin_thread_pending_); | 237 DCHECK(run_tasks_on_origin_thread_pending_); |
| 223 run_tasks_on_origin_thread_pending_ = false; | 238 run_tasks_on_origin_thread_pending_ = false; |
| 224 | 239 |
| 225 ScopedGpuRaster gpu_raster(context_provider_); | 240 ScopedGpuRaster gpu_raster(context_provider_); |
| 226 task_graph_runner_->RunUntilIdle(); | 241 task_graph_runner_->RunUntilIdle(); |
| 242 |
| 243 // Draw each all of the pictures that were collected. This will also clear |
| 244 // the pictures and canvases added to |multi_picture_draw_| |
| 245 multi_picture_draw_.draw(); |
| 227 } | 246 } |
| 228 | 247 |
| 229 } // namespace cc | 248 } // namespace cc |
| OLD | NEW |