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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "cc/output/context_provider.h" | 8 #include "cc/output/context_provider.h" |
| 9 #include "cc/resources/raster_buffer.h" |
9 #include "cc/resources/resource.h" | 10 #include "cc/resources/resource.h" |
10 #include "cc/resources/resource_provider.h" | 11 #include "cc/resources/resource_provider.h" |
11 #include "cc/resources/scoped_gpu_raster.h" | 12 #include "cc/resources/scoped_gpu_raster.h" |
12 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 14 #include "third_party/skia/include/core/SkSurface.h" |
13 #include "third_party/skia/include/gpu/GrContext.h" | 15 #include "third_party/skia/include/gpu/GrContext.h" |
| 16 #include "third_party/skia/include/utils/SkNullCanvas.h" |
14 | 17 |
15 namespace cc { | 18 namespace cc { |
| 19 namespace { |
| 20 |
| 21 class RasterBufferImpl : public RasterBuffer { |
| 22 public: |
| 23 RasterBufferImpl(ResourceProvider* resource_provider, |
| 24 const Resource* resource) |
| 25 : resource_provider_(resource_provider), |
| 26 resource_(resource), |
| 27 surface_(resource_provider->LockForWriteToSkSurface(resource->id())) {} |
| 28 virtual ~RasterBufferImpl() { |
| 29 resource_provider_->UnlockForWriteToSkSurface(resource_->id()); |
| 30 } |
| 31 |
| 32 // Overridden from RasterBuffer: |
| 33 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE { |
| 34 skia::RefPtr<SkCanvas> canvas = surface_ |
| 35 ? skia::SharePtr(surface_->getCanvas()) |
| 36 : skia::AdoptRef(SkCreateNullCanvas()); |
| 37 |
| 38 // Balanced with restore() call in ReleaseSkCanvas. save()/restore() calls |
| 39 // are needed to ensure that canvas returns to its previous state after use. |
| 40 canvas->save(); |
| 41 return canvas; |
| 42 } |
| 43 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE { |
| 44 // Balanced with save() call in AcquireSkCanvas. |
| 45 canvas->restore(); |
| 46 } |
| 47 |
| 48 private: |
| 49 ResourceProvider* resource_provider_; |
| 50 const Resource* resource_; |
| 51 SkSurface* surface_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 54 }; |
| 55 |
| 56 } // namespace |
16 | 57 |
17 // static | 58 // static |
18 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( | 59 scoped_ptr<RasterWorkerPool> GpuRasterWorkerPool::Create( |
19 base::SequencedTaskRunner* task_runner, | 60 base::SequencedTaskRunner* task_runner, |
20 ContextProvider* context_provider, | 61 ContextProvider* context_provider, |
21 ResourceProvider* resource_provider) { | 62 ResourceProvider* resource_provider) { |
22 return make_scoped_ptr<RasterWorkerPool>(new GpuRasterWorkerPool( | 63 return make_scoped_ptr<RasterWorkerPool>(new GpuRasterWorkerPool( |
23 task_runner, context_provider, resource_provider)); | 64 task_runner, context_provider, resource_provider)); |
24 } | 65 } |
25 | 66 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 177 |
137 task->WillComplete(); | 178 task->WillComplete(); |
138 task->CompleteOnOriginThread(this); | 179 task->CompleteOnOriginThread(this); |
139 task->DidComplete(); | 180 task->DidComplete(); |
140 | 181 |
141 task->RunReplyOnOriginThread(); | 182 task->RunReplyOnOriginThread(); |
142 } | 183 } |
143 completed_tasks_.clear(); | 184 completed_tasks_.clear(); |
144 } | 185 } |
145 | 186 |
146 RasterBuffer* GpuRasterWorkerPool::AcquireBufferForRaster(RasterTask* task) { | 187 scoped_ptr<RasterBuffer> GpuRasterWorkerPool::AcquireBufferForRaster( |
147 return resource_provider_->AcquireGpuRasterBuffer(task->resource()->id()); | 188 const Resource* resource) { |
| 189 return make_scoped_ptr<RasterBuffer>( |
| 190 new RasterBufferImpl(resource_provider_, resource)); |
148 } | 191 } |
149 | 192 |
150 void GpuRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) { | 193 void GpuRasterWorkerPool::ReleaseBufferForRaster( |
151 resource_provider_->ReleaseGpuRasterBuffer(task->resource()->id()); | 194 scoped_ptr<RasterBuffer> buffer) { |
| 195 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
152 } | 196 } |
153 | 197 |
154 void GpuRasterWorkerPool::OnRasterFinished() { | 198 void GpuRasterWorkerPool::OnRasterFinished() { |
155 TRACE_EVENT0("cc", "GpuRasterWorkerPool::OnRasterFinished"); | 199 TRACE_EVENT0("cc", "GpuRasterWorkerPool::OnRasterFinished"); |
156 | 200 |
157 DCHECK(raster_tasks_pending_); | 201 DCHECK(raster_tasks_pending_); |
158 raster_tasks_pending_ = false; | 202 raster_tasks_pending_ = false; |
159 client_->DidFinishRunningTasks(); | 203 client_->DidFinishRunningTasks(); |
160 } | 204 } |
161 | 205 |
(...skipping 21 matching lines...) Expand all Loading... |
183 TRACE_EVENT0("cc", "GpuRasterWorkerPool::RunTasksOnOriginThread"); | 227 TRACE_EVENT0("cc", "GpuRasterWorkerPool::RunTasksOnOriginThread"); |
184 | 228 |
185 DCHECK(run_tasks_on_origin_thread_pending_); | 229 DCHECK(run_tasks_on_origin_thread_pending_); |
186 run_tasks_on_origin_thread_pending_ = false; | 230 run_tasks_on_origin_thread_pending_ = false; |
187 | 231 |
188 ScopedGpuRaster gpu_raster(context_provider_); | 232 ScopedGpuRaster gpu_raster(context_provider_); |
189 task_graph_runner_->RunUntilIdle(); | 233 task_graph_runner_->RunUntilIdle(); |
190 } | 234 } |
191 | 235 |
192 } // namespace cc | 236 } // namespace cc |
OLD | NEW |