| 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/picture_pile_impl.h" |
| 11 #include "cc/resources/raster_buffer.h" | 12 #include "cc/resources/raster_buffer.h" |
| 12 #include "cc/resources/resource.h" | 13 #include "cc/resources/resource.h" |
| 13 #include "cc/resources/resource_provider.h" | 14 #include "cc/resources/resource_provider.h" |
| 14 #include "cc/resources/scoped_gpu_raster.h" | 15 #include "cc/resources/scoped_gpu_raster.h" |
| 15 #include "gpu/command_buffer/client/gles2_interface.h" | 16 #include "gpu/command_buffer/client/gles2_interface.h" |
| 16 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 17 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 17 #include "third_party/skia/include/core/SkPictureRecorder.h" | 18 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 18 #include "third_party/skia/include/core/SkSurface.h" | 19 #include "third_party/skia/include/core/SkSurface.h" |
| 19 #include "third_party/skia/include/gpu/GrContext.h" | 20 #include "third_party/skia/include/gpu/GrContext.h" |
| 20 #include "third_party/skia/include/utils/SkNullCanvas.h" | |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class RasterBufferImpl : public RasterBuffer { | 25 class RasterBufferImpl : public RasterBuffer { |
| 26 public: | 26 public: |
| 27 RasterBufferImpl(ResourceProvider* resource_provider, | 27 RasterBufferImpl(ResourceProvider* resource_provider, |
| 28 const Resource* resource, | 28 const Resource* resource, |
| 29 SkMultiPictureDraw* multi_picture_draw) | 29 SkMultiPictureDraw* multi_picture_draw) |
| 30 : lock_(resource_provider, resource->id()), | 30 : lock_(resource_provider, resource->id()), |
| 31 resource_(resource), | 31 resource_(resource), |
| 32 multi_picture_draw_(multi_picture_draw) {} | 32 multi_picture_draw_(multi_picture_draw) {} |
| 33 | 33 |
| 34 // Overridden from RasterBuffer: | 34 // Overridden from RasterBuffer: |
| 35 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() override { | 35 virtual void Playback(const PicturePileImpl* picture_pile, |
| 36 if (!lock_.sk_surface()) | 36 const gfx::Rect& rect, |
| 37 return skia::AdoptRef(SkCreateNullCanvas()); | 37 float scale, |
| 38 | 38 RenderingStatsInstrumentation* stats) override { |
| 39 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(recorder_.beginRecording( | |
| 40 resource_->size().width(), resource_->size().height())); | |
| 41 | |
| 42 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls | |
| 43 // are needed to ensure that canvas returns to its previous state after use. | |
| 44 canvas->save(); | |
| 45 return canvas; | |
| 46 } | |
| 47 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) override { | |
| 48 if (!lock_.sk_surface()) | 39 if (!lock_.sk_surface()) |
| 49 return; | 40 return; |
| 50 | 41 |
| 51 // Balanced with save() call in AcquireSkCanvas. | 42 SkPictureRecorder recorder; |
| 43 gfx::Size size = resource_->size(); |
| 44 skia::RefPtr<SkCanvas> canvas = |
| 45 skia::SharePtr(recorder.beginRecording(size.width(), size.height())); |
| 46 |
| 47 canvas->save(); |
| 48 picture_pile->RasterToBitmap(canvas.get(), rect, scale, stats); |
| 52 canvas->restore(); | 49 canvas->restore(); |
| 53 | 50 |
| 54 // Add the canvas and recorded picture to |multi_picture_draw_|. | 51 // Add the canvas and recorded picture to |multi_picture_draw_|. |
| 55 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder_.endRecording()); | 52 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 56 multi_picture_draw_->add(lock_.sk_surface()->getCanvas(), picture.get()); | 53 multi_picture_draw_->add(lock_.sk_surface()->getCanvas(), picture.get()); |
| 57 } | 54 } |
| 58 | 55 |
| 59 private: | 56 private: |
| 60 ResourceProvider::ScopedWriteLockGr lock_; | 57 ResourceProvider::ScopedWriteLockGr lock_; |
| 61 const Resource* resource_; | 58 const Resource* resource_; |
| 62 SkMultiPictureDraw* multi_picture_draw_; | 59 SkMultiPictureDraw* multi_picture_draw_; |
| 63 SkPictureRecorder recorder_; | |
| 64 | 60 |
| 65 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 61 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 66 }; | 62 }; |
| 67 | 63 |
| 68 } // namespace | 64 } // namespace |
| 69 | 65 |
| 70 // static | 66 // static |
| 71 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( | 67 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( |
| 72 base::SequencedTaskRunner* task_runner, | 68 base::SequencedTaskRunner* task_runner, |
| 73 ContextProvider* context_provider, | 69 ContextProvider* context_provider, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 226 |
| 231 ScopedGpuRaster gpu_raster(context_provider_); | 227 ScopedGpuRaster gpu_raster(context_provider_); |
| 232 task_graph_runner_->RunUntilIdle(); | 228 task_graph_runner_->RunUntilIdle(); |
| 233 | 229 |
| 234 // Draw each all of the pictures that were collected. This will also clear | 230 // Draw each all of the pictures that were collected. This will also clear |
| 235 // the pictures and canvases added to |multi_picture_draw_| | 231 // the pictures and canvases added to |multi_picture_draw_| |
| 236 multi_picture_draw_.draw(); | 232 multi_picture_draw_.draw(); |
| 237 } | 233 } |
| 238 | 234 |
| 239 } // namespace cc | 235 } // namespace cc |
| OLD | NEW |