Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: cc/resources/gpu_raster_worker_pool.cc

Issue 635733004: cc: Add ScopedWriteLock classes for raster to GpuMemoryBuffer or using Ganesh. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/resources/one_copy_raster_worker_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 16 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
17 #include "third_party/skia/include/core/SkPictureRecorder.h" 17 #include "third_party/skia/include/core/SkPictureRecorder.h"
18 #include "third_party/skia/include/core/SkSurface.h" 18 #include "third_party/skia/include/core/SkSurface.h"
19 #include "third_party/skia/include/gpu/GrContext.h" 19 #include "third_party/skia/include/gpu/GrContext.h"
20 #include "third_party/skia/include/utils/SkNullCanvas.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 : resource_provider_(resource_provider), 30 : lock_(resource_provider, resource->id()),
31 resource_(resource), 31 resource_(resource),
32 surface_(resource_provider->LockForWriteToSkSurface(resource->id())),
33 multi_picture_draw_(multi_picture_draw) {} 32 multi_picture_draw_(multi_picture_draw) {}
34 virtual ~RasterBufferImpl() {
35 resource_provider_->UnlockForWriteToSkSurface(resource_->id());
36 }
37 33
38 // Overridden from RasterBuffer: 34 // Overridden from RasterBuffer:
39 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() override { 35 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() override {
40 if (!surface_) 36 if (!lock_.sk_surface())
41 return skia::AdoptRef(SkCreateNullCanvas()); 37 return skia::AdoptRef(SkCreateNullCanvas());
42 38
43 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(recorder_.beginRecording( 39 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(recorder_.beginRecording(
44 resource_->size().width(), resource_->size().height())); 40 resource_->size().width(), resource_->size().height()));
45 41
46 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls 42 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls
47 // are needed to ensure that canvas returns to its previous state after use. 43 // are needed to ensure that canvas returns to its previous state after use.
48 canvas->save(); 44 canvas->save();
49 return canvas; 45 return canvas;
50 } 46 }
51 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) override { 47 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) override {
52 if (!surface_) 48 if (!lock_.sk_surface())
53 return; 49 return;
54 50
55 // Balanced with save() call in AcquireSkCanvas. 51 // Balanced with save() call in AcquireSkCanvas.
56 canvas->restore(); 52 canvas->restore();
57 53
58 // Add the canvas and recorded picture to |multi_picture_draw_|. 54 // Add the canvas and recorded picture to |multi_picture_draw_|.
59 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder_.endRecording()); 55 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder_.endRecording());
60 multi_picture_draw_->add(surface_->getCanvas(), picture.get()); 56 multi_picture_draw_->add(lock_.sk_surface()->getCanvas(), picture.get());
61 } 57 }
62 58
63 private: 59 private:
64 ResourceProvider* resource_provider_; 60 ResourceProvider::ScopedWriteLockGr lock_;
65 const Resource* resource_; 61 const Resource* resource_;
66 SkSurface* surface_;
67 SkMultiPictureDraw* multi_picture_draw_; 62 SkMultiPictureDraw* multi_picture_draw_;
68 SkPictureRecorder recorder_; 63 SkPictureRecorder recorder_;
69 64
70 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); 65 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
71 }; 66 };
72 67
73 } // namespace 68 } // namespace
74 69
75 // static 70 // static
76 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( 71 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 task->CompleteOnOriginThread(this); 186 task->CompleteOnOriginThread(this);
192 task->DidComplete(); 187 task->DidComplete();
193 188
194 task->RunReplyOnOriginThread(); 189 task->RunReplyOnOriginThread();
195 } 190 }
196 completed_tasks_.clear(); 191 completed_tasks_.clear();
197 } 192 }
198 193
199 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( 194 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster(
200 const Resource* resource) { 195 const Resource* resource) {
201 // RasterBuffer implementation depends on a SkSurface having been acquired for
202 // the resource.
203 resource_provider_->AcquireSkSurface(resource->id());
204
205 return make_scoped_ptr<RasterBuffer>( 196 return make_scoped_ptr<RasterBuffer>(
206 new RasterBufferImpl(resource_provider_, resource, &multi_picture_draw_)); 197 new RasterBufferImpl(resource_provider_, resource, &multi_picture_draw_));
207 } 198 }
208 199
209 void GpuRasterWorkerPool::ReleaseBufferForRaster( 200 void GpuRasterWorkerPool::ReleaseBufferForRaster(
210 scoped_ptr<RasterBuffer> buffer) { 201 scoped_ptr<RasterBuffer> buffer) {
211 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. 202 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
212 } 203 }
213 204
214 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) { 205 void GpuRasterWorkerPool::OnRasterFinished(TaskSet task_set) {
(...skipping 24 matching lines...) Expand all
239 230
240 ScopedGpuRaster gpu_raster(context_provider_); 231 ScopedGpuRaster gpu_raster(context_provider_);
241 task_graph_runner_->RunUntilIdle(); 232 task_graph_runner_->RunUntilIdle();
242 233
243 // Draw each all of the pictures that were collected. This will also clear 234 // Draw each all of the pictures that were collected. This will also clear
244 // the pictures and canvases added to |multi_picture_draw_| 235 // the pictures and canvases added to |multi_picture_draw_|
245 multi_picture_draw_.draw(); 236 multi_picture_draw_.draw();
246 } 237 }
247 238
248 } // namespace cc 239 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/resources/one_copy_raster_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698