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 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(recorder_.beginRecording( |
37 ? skia::SharePtr(surface_->getCanvas()) | 41 resource_->size().width(), resource_->size().height())); |
38 : skia::AdoptRef(SkCreateNullCanvas()); | |
39 | 42 |
40 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls | 43 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls |
41 // are needed to ensure that canvas returns to its previous state after use. | 44 // are needed to ensure that canvas returns to its previous state after use. |
42 canvas->save(); | 45 canvas->save(); |
reveman
2014/09/22 21:29:05
do we still need this save/restore pair?
hendrikw
2014/09/22 21:48:39
It is probably still required, but should be moved
reveman
2014/09/22 22:41:08
Acknowledged.
| |
43 return canvas; | 46 return canvas; |
44 } | 47 } |
45 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { | 48 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { |
46 // Balanced with save() call in AcquireSkCanvas. | 49 // Balanced with save() call in AcquireSkCanvas. |
47 canvas->restore(); | 50 canvas->restore(); |
51 | |
52 // Add the canvas and recorded picture to |multi_picture_draw_|. | |
53 skia::RefPtr<SkCanvas> real_canvas = | |
54 surface_ ? skia::SharePtr(surface_->getCanvas()) | |
55 : skia::AdoptRef(SkCreateNullCanvas()); | |
reveman
2014/09/22 21:29:05
it seems a bit silly to add a null canvas. would i
hendrikw
2014/09/22 21:48:39
If we want status quo, I should probably allocate
| |
56 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder_.endRecording()); | |
57 multi_picture_draw_->add(real_canvas.get(), picture.get()); | |
48 } | 58 } |
49 | 59 |
50 private: | 60 private: |
51 ResourceProvider* resource_provider_; | 61 ResourceProvider* resource_provider_; |
52 const Resource* resource_; | 62 const Resource* resource_; |
53 SkSurface* surface_; | 63 SkSurface* surface_; |
64 SkMultiPictureDraw* multi_picture_draw_; | |
65 SkPictureRecorder recorder_; | |
54 | 66 |
55 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 67 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
56 }; | 68 }; |
57 | 69 |
58 } // namespace | 70 } // namespace |
59 | 71 |
60 // static | 72 // static |
61 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( | 73 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( |
62 base::SequencedTaskRunner* task_runner, | 74 base::SequencedTaskRunner* task_runner, |
63 ContextProvider* context_provider, | 75 ContextProvider* context_provider, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 completed_tasks_.clear(); | 193 completed_tasks_.clear(); |
182 } | 194 } |
183 | 195 |
184 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( | 196 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( |
185 const Resource* resource) { | 197 const Resource* resource) { |
186 // RasterBuffer implementation depends on a SkSurface having been acquired for | 198 // RasterBuffer implementation depends on a SkSurface having been acquired for |
187 // the resource. | 199 // the resource. |
188 resource_provider_->AcquireSkSurface(resource->id()); | 200 resource_provider_->AcquireSkSurface(resource->id()); |
189 | 201 |
190 return make_scoped_ptr<RasterBuffer>( | 202 return make_scoped_ptr<RasterBuffer>( |
191 new RasterBufferImpl(resource_provider_, resource)); | 203 new RasterBufferImpl(resource_provider_, resource, &multi_picture_draw_)); |
192 } | 204 } |
193 | 205 |
194 void GpuRasterWorkerPool::ReleaseBufferForRaster( | 206 void GpuRasterWorkerPool::ReleaseBufferForRaster( |
195 scoped_ptr<RasterBuffer> buffer) { | 207 scoped_ptr<RasterBuffer> buffer) { |
196 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 208 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
197 } | 209 } |
198 | 210 |
199 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { | 211 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { |
200 TRACE_EVENT1( | 212 TRACE_EVENT1( |
201 "cc", "GpuRasterWorkerPool::OnRasterFinished", "task_set", task_set); | 213 "cc", "GpuRasterWorkerPool::OnRasterFinished", "task_set", task_set); |
(...skipping 15 matching lines...) Expand all Loading... | |
217 } | 229 } |
218 | 230 |
219 void GpuRasterWorkerPool::RunTasksOnOriginThread() { | 231 void GpuRasterWorkerPool::RunTasksOnOriginThread() { |
220 TRACE_EVENT0("cc", "GpuRasterWorkerPool::RunTasksOnOriginThread"); | 232 TRACE_EVENT0("cc", "GpuRasterWorkerPool::RunTasksOnOriginThread"); |
221 | 233 |
222 DCHECK(run_tasks_on_origin_thread_pending_); | 234 DCHECK(run_tasks_on_origin_thread_pending_); |
223 run_tasks_on_origin_thread_pending_ = false; | 235 run_tasks_on_origin_thread_pending_ = false; |
224 | 236 |
225 ScopedGpuRaster gpu_raster(context_provider_); | 237 ScopedGpuRaster gpu_raster(context_provider_); |
226 task_graph_runner_->RunUntilIdle(); | 238 task_graph_runner_->RunUntilIdle(); |
239 multi_picture_draw_.draw(); | |
reveman
2014/09/22 21:29:05
Does calling draw() also clear the SkMultiPictureD
hendrikw
2014/09/22 21:48:39
Yes, it clears. I'll add a comment.
| |
227 } | 240 } |
228 | 241 |
229 } // namespace cc | 242 } // namespace cc |
OLD | NEW |