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

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

Issue 236633008: Switching Chromium to use new Skia SkPictureRecorder API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address code review issue Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/picture.h" 5 #include "cc/resources/picture.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 RecordingMode recording_mode) { 242 RecordingMode recording_mode) {
243 TRACE_EVENT2("cc", 243 TRACE_EVENT2("cc",
244 "Picture::Record", 244 "Picture::Record",
245 "data", 245 "data",
246 AsTraceableRecordData(), 246 AsTraceableRecordData(),
247 "recording_mode", 247 "recording_mode",
248 recording_mode); 248 recording_mode);
249 249
250 DCHECK(!picture_); 250 DCHECK(!picture_);
251 DCHECK(!tile_grid_info.fTileInterval.isEmpty()); 251 DCHECK(!tile_grid_info.fTileInterval.isEmpty());
252 picture_ = skia::AdoptRef(new SkTileGridPicture( 252
253 layer_rect_.width(), layer_rect_.height(), tile_grid_info)); 253 skia::RefPtr<SkPictureFactory> factory =
254 skia::AdoptRef(new SkTileGridPictureFactory(tile_grid_info));
255 SkPictureRecorder recorder(factory.get());
254 256
255 skia::RefPtr<SkCanvas> canvas; 257 skia::RefPtr<SkCanvas> canvas;
258 canvas = skia::SharePtr(recorder.beginRecording(
enne (OOO) 2014/04/15 01:10:39 Should all the beginRecording calls be wrapped in
robertphillips 2014/04/15 15:37:04 As is, I think the behavior is correct here but ma
enne (OOO) 2014/04/15 16:45:16 Gotcha. The ref here is just RAII. Makes sense.
259 layer_rect_.width(),
260 layer_rect_.height(),
261 SkPicture::kUsePathBoundsForClip_RecordingFlag |
262 SkPicture::kOptimizeForClippedPlayback_RecordingFlag));
263
256 switch (recording_mode) { 264 switch (recording_mode) {
257 case RECORD_NORMALLY: 265 case RECORD_NORMALLY:
258 canvas = skia::SharePtr(picture_->beginRecording( 266 // Already setup for normal recording
enne (OOO) 2014/04/15 01:10:39 Why did the code move out of this switch?
robertphillips 2014/04/15 15:37:04 The old code always generated an SkPicture (albeit
enne (OOO) 2014/04/15 16:45:16 I guess I'm asking because in all other cases, the
robertphillips 2014/04/15 19:17:32 The RECORD_WITH_PAINTING_DISABLED and RECORD_WITH_
enne (OOO) 2014/04/15 19:43:27 I see. So even though you delete the canvas that
259 layer_rect_.width(),
260 layer_rect_.height(),
261 SkPicture::kUsePathBoundsForClip_RecordingFlag |
262 SkPicture::kOptimizeForClippedPlayback_RecordingFlag));
263 break; 267 break;
264 case RECORD_WITH_SK_NULL_CANVAS: 268 case RECORD_WITH_SK_NULL_CANVAS:
265 canvas = skia::AdoptRef(SkCreateNullCanvas()); 269 canvas = skia::AdoptRef(SkCreateNullCanvas());
266 break; 270 break;
267 case RECORD_WITH_PAINTING_DISABLED: 271 case RECORD_WITH_PAINTING_DISABLED:
268 // Blink's GraphicsContext will disable painting when given a NULL 272 // Blink's GraphicsContext will disable painting when given a NULL
269 // canvas. 273 // canvas.
274 canvas.clear();
270 break; 275 break;
271 default: 276 default:
272 NOTREACHED(); 277 NOTREACHED();
273 } 278 }
274 279
275 if (canvas) { 280 if (canvas) {
276 canvas->save(); 281 canvas->save();
277 canvas->translate(SkFloatToScalar(-layer_rect_.x()), 282 canvas->translate(SkFloatToScalar(-layer_rect_.x()),
278 SkFloatToScalar(-layer_rect_.y())); 283 SkFloatToScalar(-layer_rect_.y()));
279 284
280 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(), 285 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(),
281 layer_rect_.y(), 286 layer_rect_.y(),
282 layer_rect_.width(), 287 layer_rect_.width(),
283 layer_rect_.height()); 288 layer_rect_.height());
284 canvas->clipRect(layer_skrect); 289 canvas->clipRect(layer_skrect);
285 } 290 }
286 291
287 gfx::RectF opaque_layer_rect; 292 gfx::RectF opaque_layer_rect;
288 painter->PaintContents(canvas.get(), layer_rect_, &opaque_layer_rect); 293 painter->PaintContents(canvas.get(), layer_rect_, &opaque_layer_rect);
289 294
290 if (canvas) 295 if (canvas)
291 canvas->restore(); 296 canvas->restore();
292 if (picture_->getRecordingCanvas()) 297 picture_ = skia::AdoptRef(recorder.endRecording());
enne (OOO) 2014/04/15 01:10:39 Previously, picture_ was always non-null if the cc
robertphillips 2014/04/15 15:37:04 picture_ should still always be non-null after a c
enne (OOO) 2014/04/15 16:45:16 Oh, ok! I misunderstood the change description her
robertphillips 2014/04/15 19:17:32 I have added a DCHECK.
293 picture_->endRecording();
294 298
295 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect); 299 opaque_rect_ = gfx::ToEnclosedRect(opaque_layer_rect);
296 300
297 EmitTraceSnapshot(); 301 EmitTraceSnapshot();
298 } 302 }
299 303
300 void Picture::GatherPixelRefs( 304 void Picture::GatherPixelRefs(
301 const SkTileGridPicture::TileGridInfo& tile_grid_info) { 305 const SkTileGridPicture::TileGridInfo& tile_grid_info) {
302 TRACE_EVENT2("cc", "Picture::GatherPixelRefs", 306 TRACE_EVENT2("cc", "Picture::GatherPixelRefs",
303 "width", layer_rect_.width(), 307 "width", layer_rect_.width(),
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 544
541 scoped_refptr<base::debug::ConvertableToTraceFormat> 545 scoped_refptr<base::debug::ConvertableToTraceFormat>
542 Picture::AsTraceableRecordData() const { 546 Picture::AsTraceableRecordData() const {
543 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); 547 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue());
544 record_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); 548 record_data->Set("picture_id", TracedValue::CreateIDRef(this).release());
545 record_data->Set("layer_rect", MathUtil::AsValue(layer_rect_).release()); 549 record_data->Set("layer_rect", MathUtil::AsValue(layer_rect_).release());
546 return TracedValue::FromValue(record_data.release()); 550 return TracedValue::FromValue(record_data.release());
547 } 551 }
548 552
549 } // namespace cc 553 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698