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

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

Issue 562833004: cc: Move RasterBuffer implementations from ResourceProvider to RasterWorkerPool implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move NullCanvas change to separate patch Created 6 years, 3 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
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/image_copy_raster_worker_pool.h" 5 #include "cc/resources/image_copy_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 "base/debug/trace_event_argument.h" 10 #include "base/debug/trace_event_argument.h"
11 #include "cc/debug/traced_value.h" 11 #include "cc/debug/traced_value.h"
12 #include "cc/resources/raster_buffer.h"
12 #include "cc/resources/resource_pool.h" 13 #include "cc/resources/resource_pool.h"
13 #include "cc/resources/scoped_resource.h" 14 #include "cc/resources/scoped_resource.h"
14 #include "gpu/command_buffer/client/gles2_interface.h" 15 #include "gpu/command_buffer/client/gles2_interface.h"
16 #include "third_party/skia/include/utils/SkNullCanvas.h"
15 17
16 namespace cc { 18 namespace cc {
19 namespace {
20
21 class RasterBufferImpl : public RasterBuffer {
22 public:
23 RasterBufferImpl(ResourceProvider* resource_provider,
24 ResourcePool* resource_pool,
25 const Resource* resource)
26 : resource_provider_(resource_provider),
27 resource_pool_(resource_pool),
28 resource_(resource),
29 raster_resource_(resource_pool->AcquireResource(resource->size())),
30 buffer_(NULL),
31 stride_(0) {
32 // This RasterBuffer implementation provides direct access to the memory
33 // used by the GPU. Read lock fences are required to ensure that we're not
34 // trying to map a resource that is currently in-use by the GPU.
35 resource_provider_->EnableReadLockFences(raster_resource_->id());
36
37 // Acquire and map image for raster resource.
38 resource_provider_->AcquireImage(raster_resource_->id());
39 buffer_ = resource_provider_->MapImage(raster_resource_->id(), &stride_);
40 }
41
42 virtual ~RasterBufferImpl() {
43 // First unmap image for raster resource.
44 resource_provider_->UnmapImage(raster_resource_->id());
45
46 // Copy contents of raster resource to |resource_|.
47 resource_provider_->CopyResource(raster_resource_->id(), resource_->id());
48
49 // Return raster resource to pool so it can be used by another RasterBuffer
50 // instance.
51 resource_pool_->ReleaseResource(raster_resource_.Pass());
52 }
53
54 // Overridden from RasterBuffer:
55 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE {
56 if (!buffer_)
57 return skia::AdoptRef(SkCreateNullCanvas());
58
59 RasterWorkerPool::AcquireBitmapForBuffer(
60 &bitmap_, buffer_, resource_->format(), resource_->size(), stride_);
61 return skia::AdoptRef(new SkCanvas(bitmap_));
62 }
63 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE {
64 if (!buffer_)
65 return;
66
67 RasterWorkerPool::ReleaseBitmapForBuffer(
68 &bitmap_, buffer_, resource_->format());
69 }
70
71 private:
72 ResourceProvider* resource_provider_;
73 ResourcePool* resource_pool_;
74 const Resource* resource_;
75 scoped_ptr<ScopedResource> raster_resource_;
76 uint8_t* buffer_;
77 int stride_;
78 SkBitmap bitmap_;
79
80 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
81 };
82
83 } // namespace
17 84
18 // static 85 // static
19 scoped_ptr<RasterWorkerPool> ImageCopyRasterWorkerPool::Create( 86 scoped_ptr<RasterWorkerPool> ImageCopyRasterWorkerPool::Create(
20 base::SequencedTaskRunner* task_runner, 87 base::SequencedTaskRunner* task_runner,
21 TaskGraphRunner* task_graph_runner, 88 TaskGraphRunner* task_graph_runner,
22 ContextProvider* context_provider, 89 ContextProvider* context_provider,
23 ResourceProvider* resource_provider, 90 ResourceProvider* resource_provider,
24 ResourcePool* resource_pool) { 91 ResourcePool* resource_pool) {
25 return make_scoped_ptr<RasterWorkerPool>( 92 return make_scoped_ptr<RasterWorkerPool>(
26 new ImageCopyRasterWorkerPool(task_runner, 93 new ImageCopyRasterWorkerPool(task_runner,
27 task_graph_runner, 94 task_graph_runner,
28 context_provider, 95 context_provider,
29 resource_provider, 96 resource_provider,
30 resource_pool)); 97 resource_pool));
31 } 98 }
32 99
33 ImageCopyRasterWorkerPool::ImageCopyRasterWorkerPool( 100 ImageCopyRasterWorkerPool::ImageCopyRasterWorkerPool(
34 base::SequencedTaskRunner* task_runner, 101 base::SequencedTaskRunner* task_runner,
35 TaskGraphRunner* task_graph_runner, 102 TaskGraphRunner* task_graph_runner,
36 ContextProvider* context_provider, 103 ContextProvider* context_provider,
37 ResourceProvider* resource_provider, 104 ResourceProvider* resource_provider,
38 ResourcePool* resource_pool) 105 ResourcePool* resource_pool)
39 : task_runner_(task_runner), 106 : task_runner_(task_runner),
40 task_graph_runner_(task_graph_runner), 107 task_graph_runner_(task_graph_runner),
41 namespace_token_(task_graph_runner->GetNamespaceToken()), 108 namespace_token_(task_graph_runner->GetNamespaceToken()),
42 context_provider_(context_provider), 109 context_provider_(context_provider),
43 resource_provider_(resource_provider), 110 resource_provider_(resource_provider),
44 resource_pool_(resource_pool), 111 resource_pool_(resource_pool),
45 has_performed_copy_since_last_flush_(false),
46 raster_tasks_pending_(false), 112 raster_tasks_pending_(false),
47 raster_tasks_required_for_activation_pending_(false), 113 raster_tasks_required_for_activation_pending_(false),
48 raster_finished_weak_ptr_factory_(this) { 114 raster_finished_weak_ptr_factory_(this) {
49 DCHECK(context_provider_); 115 DCHECK(context_provider_);
50 } 116 }
51 117
52 ImageCopyRasterWorkerPool::~ImageCopyRasterWorkerPool() { 118 ImageCopyRasterWorkerPool::~ImageCopyRasterWorkerPool() {
53 DCHECK_EQ(0u, raster_task_states_.size());
54 } 119 }
55 120
56 Rasterizer* ImageCopyRasterWorkerPool::AsRasterizer() { return this; } 121 Rasterizer* ImageCopyRasterWorkerPool::AsRasterizer() { return this; }
57 122
58 void ImageCopyRasterWorkerPool::SetClient(RasterizerClient* client) { 123 void ImageCopyRasterWorkerPool::SetClient(RasterizerClient* client) {
59 client_ = client; 124 client_ = client;
60 } 125 }
61 126
62 void ImageCopyRasterWorkerPool::Shutdown() { 127 void ImageCopyRasterWorkerPool::Shutdown() {
63 TRACE_EVENT0("cc", "ImageCopyRasterWorkerPool::Shutdown"); 128 TRACE_EVENT0("cc", "ImageCopyRasterWorkerPool::Shutdown");
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 RasterizerTask* task = static_cast<RasterizerTask*>(it->get()); 216 RasterizerTask* task = static_cast<RasterizerTask*>(it->get());
152 217
153 task->WillComplete(); 218 task->WillComplete();
154 task->CompleteOnOriginThread(this); 219 task->CompleteOnOriginThread(this);
155 task->DidComplete(); 220 task->DidComplete();
156 221
157 task->RunReplyOnOriginThread(); 222 task->RunReplyOnOriginThread();
158 } 223 }
159 completed_tasks_.clear(); 224 completed_tasks_.clear();
160 225
161 FlushCopies(); 226 context_provider_->ContextGL()->ShallowFlushCHROMIUM();
162 } 227 }
163 228
164 RasterBuffer* ImageCopyRasterWorkerPool::AcquireBufferForRaster( 229 scoped_ptr<RasterBuffer> ImageCopyRasterWorkerPool::AcquireBufferForRaster(
165 RasterTask* task) { 230 const Resource* resource) {
166 DCHECK_EQ(task->resource()->format(), resource_pool_->resource_format()); 231 DCHECK_EQ(resource->format(), resource_pool_->resource_format());
167 scoped_ptr<ScopedResource> resource( 232 return make_scoped_ptr<RasterBuffer>(
168 resource_pool_->AcquireResource(task->resource()->size())); 233 new RasterBufferImpl(resource_provider_, resource_pool_, resource));
169 RasterBuffer* raster_buffer =
170 resource_provider_->AcquireImageRasterBuffer(resource->id());
171 DCHECK(std::find_if(raster_task_states_.begin(),
172 raster_task_states_.end(),
173 RasterTaskState::TaskComparator(task)) ==
174 raster_task_states_.end());
175 raster_task_states_.push_back(RasterTaskState(task, resource.release()));
176 return raster_buffer;
177 } 234 }
178 235
179 void ImageCopyRasterWorkerPool::ReleaseBufferForRaster(RasterTask* task) { 236 void ImageCopyRasterWorkerPool::ReleaseBufferForRaster(
180 RasterTaskState::Vector::iterator it = 237 scoped_ptr<RasterBuffer> buffer) {
181 std::find_if(raster_task_states_.begin(), 238 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
182 raster_task_states_.end(),
183 RasterTaskState::TaskComparator(task));
184 DCHECK(it != raster_task_states_.end());
185 scoped_ptr<ScopedResource> resource(it->resource);
186 std::swap(*it, raster_task_states_.back());
187 raster_task_states_.pop_back();
188
189 bool content_has_changed =
190 resource_provider_->ReleaseImageRasterBuffer(resource->id());
191
192 // |content_has_changed| can be false as result of task being canceled or
193 // task implementation deciding not to modify bitmap (ie. analysis of raster
194 // commands detected content as a solid color).
195 if (content_has_changed) {
196 resource_provider_->CopyResource(resource->id(), task->resource()->id());
197 has_performed_copy_since_last_flush_ = true;
198 }
199
200 resource_pool_->ReleaseResource(resource.Pass());
201 } 239 }
202 240
203 void ImageCopyRasterWorkerPool::OnRasterFinished() { 241 void ImageCopyRasterWorkerPool::OnRasterFinished() {
204 TRACE_EVENT0("cc", "ImageCopyRasterWorkerPool::OnRasterFinished"); 242 TRACE_EVENT0("cc", "ImageCopyRasterWorkerPool::OnRasterFinished");
205 243
206 DCHECK(raster_tasks_pending_); 244 DCHECK(raster_tasks_pending_);
207 raster_tasks_pending_ = false; 245 raster_tasks_pending_ = false;
208 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); 246 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
209 client_->DidFinishRunningTasks(); 247 client_->DidFinishRunningTasks();
210 } 248 }
211 249
212 void ImageCopyRasterWorkerPool::OnRasterRequiredForActivationFinished() { 250 void ImageCopyRasterWorkerPool::OnRasterRequiredForActivationFinished() {
213 TRACE_EVENT0( 251 TRACE_EVENT0(
214 "cc", "ImageCopyRasterWorkerPool::OnRasterRequiredForActivationFinished"); 252 "cc", "ImageCopyRasterWorkerPool::OnRasterRequiredForActivationFinished");
215 253
216 DCHECK(raster_tasks_required_for_activation_pending_); 254 DCHECK(raster_tasks_required_for_activation_pending_);
217 raster_tasks_required_for_activation_pending_ = false; 255 raster_tasks_required_for_activation_pending_ = false;
218 TRACE_EVENT_ASYNC_STEP_INTO1( 256 TRACE_EVENT_ASYNC_STEP_INTO1(
219 "cc", "ScheduledTasks", this, "rasterizing", "state", StateAsValue()); 257 "cc", "ScheduledTasks", this, "rasterizing", "state", StateAsValue());
220 client_->DidFinishRunningTasksRequiredForActivation(); 258 client_->DidFinishRunningTasksRequiredForActivation();
221 } 259 }
222 260
223 void ImageCopyRasterWorkerPool::FlushCopies() {
224 if (!has_performed_copy_since_last_flush_)
225 return;
226
227 context_provider_->ContextGL()->ShallowFlushCHROMIUM();
228 has_performed_copy_since_last_flush_ = false;
229 }
230
231 scoped_refptr<base::debug::ConvertableToTraceFormat> 261 scoped_refptr<base::debug::ConvertableToTraceFormat>
232 ImageCopyRasterWorkerPool::StateAsValue() const { 262 ImageCopyRasterWorkerPool::StateAsValue() const {
233 scoped_refptr<base::debug::TracedValue> state = 263 scoped_refptr<base::debug::TracedValue> state =
234 new base::debug::TracedValue(); 264 new base::debug::TracedValue();
235 265
236 state->SetInteger("pending_count", raster_task_states_.size());
vmpstr 2014/09/17 15:53:02 We still have a boolean that indicates that we hav
reveman 2014/09/17 16:22:54 Done.
237 state->SetBoolean("tasks_required_for_activation_pending", 266 state->SetBoolean("tasks_required_for_activation_pending",
238 raster_tasks_required_for_activation_pending_); 267 raster_tasks_required_for_activation_pending_);
239 state->BeginDictionary("staging_state"); 268 state->BeginDictionary("staging_state");
240 StagingStateAsValueInto(state.get()); 269 StagingStateAsValueInto(state.get());
241 state->EndDictionary(); 270 state->EndDictionary();
242 271
243 return state; 272 return state;
244 } 273 }
245 void ImageCopyRasterWorkerPool::StagingStateAsValueInto( 274 void ImageCopyRasterWorkerPool::StagingStateAsValueInto(
246 base::debug::TracedValue* staging_state) const { 275 base::debug::TracedValue* staging_state) const {
247 staging_state->SetInteger("staging_resource_count", 276 staging_state->SetInteger("staging_resource_count",
248 resource_pool_->total_resource_count()); 277 resource_pool_->total_resource_count());
249 staging_state->SetInteger("bytes_used_for_staging_resources", 278 staging_state->SetInteger("bytes_used_for_staging_resources",
250 resource_pool_->total_memory_usage_bytes()); 279 resource_pool_->total_memory_usage_bytes());
251 staging_state->SetInteger("pending_copy_count", 280 staging_state->SetInteger("pending_copy_count",
252 resource_pool_->total_resource_count() - 281 resource_pool_->total_resource_count() -
253 resource_pool_->acquired_resource_count()); 282 resource_pool_->acquired_resource_count());
254 staging_state->SetInteger("bytes_pending_copy", 283 staging_state->SetInteger("bytes_pending_copy",
255 resource_pool_->total_memory_usage_bytes() - 284 resource_pool_->total_memory_usage_bytes() -
256 resource_pool_->acquired_memory_usage_bytes()); 285 resource_pool_->acquired_memory_usage_bytes());
257 } 286 }
258 287
259 } // namespace cc 288 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698