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

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

Issue 664583002: Remove obsolete SkRecord preview code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update r&r micro, and format 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 | « cc/resources/picture.h ('k') | cc/resources/picture_unittest.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 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 AsTraceableRecordData(), 207 AsTraceableRecordData(),
208 "recording_mode", 208 "recording_mode",
209 recording_mode); 209 recording_mode);
210 210
211 DCHECK(!picture_); 211 DCHECK(!picture_);
212 DCHECK(!tile_grid_info.fTileInterval.isEmpty()); 212 DCHECK(!tile_grid_info.fTileInterval.isEmpty());
213 213
214 SkTileGridFactory factory(tile_grid_info); 214 SkTileGridFactory factory(tile_grid_info);
215 SkPictureRecorder recorder; 215 SkPictureRecorder recorder;
216 216
217 scoped_ptr<EXPERIMENTAL::SkRecording> recording;
218
219 skia::RefPtr<SkCanvas> canvas; 217 skia::RefPtr<SkCanvas> canvas;
220 canvas = skia::SharePtr(recorder.beginRecording( 218 canvas = skia::SharePtr(recorder.beginRecording(
221 layer_rect_.width(), layer_rect_.height(), &factory)); 219 layer_rect_.width(), layer_rect_.height(), &factory));
222 220
223 ContentLayerClient::GraphicsContextStatus graphics_context_status = 221 ContentLayerClient::GraphicsContextStatus graphics_context_status =
224 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED; 222 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED;
225 223
226 switch (recording_mode) { 224 switch (recording_mode) {
227 case RECORD_NORMALLY: 225 case RECORD_NORMALLY:
228 // Already setup for normal recording. 226 // Already setup for normal recording.
229 break; 227 break;
230 case RECORD_WITH_SK_NULL_CANVAS: 228 case RECORD_WITH_SK_NULL_CANVAS:
231 canvas = skia::AdoptRef(SkCreateNullCanvas()); 229 canvas = skia::AdoptRef(SkCreateNullCanvas());
232 break; 230 break;
233 case RECORD_WITH_PAINTING_DISABLED: 231 case RECORD_WITH_PAINTING_DISABLED:
234 // We pass a disable flag through the paint calls when perfromance 232 // We pass a disable flag through the paint calls when perfromance
235 // testing (the only time this case should ever arise) when we want to 233 // testing (the only time this case should ever arise) when we want to
236 // prevent the Blink GraphicsContext object from consuming any compute 234 // prevent the Blink GraphicsContext object from consuming any compute
237 // time. 235 // time.
238 canvas = skia::AdoptRef(SkCreateNullCanvas()); 236 canvas = skia::AdoptRef(SkCreateNullCanvas());
239 graphics_context_status = ContentLayerClient::GRAPHICS_CONTEXT_DISABLED; 237 graphics_context_status = ContentLayerClient::GRAPHICS_CONTEXT_DISABLED;
240 break; 238 break;
241 case RECORD_WITH_SKRECORD:
242 recording.reset(new EXPERIMENTAL::SkRecording(layer_rect_.width(),
243 layer_rect_.height()));
244 canvas = skia::SharePtr(recording->canvas());
245 break;
246 default: 239 default:
247 NOTREACHED(); 240 NOTREACHED();
248 } 241 }
249 242
250 canvas->save(); 243 canvas->save();
251 canvas->translate(SkFloatToScalar(-layer_rect_.x()), 244 canvas->translate(SkFloatToScalar(-layer_rect_.x()),
252 SkFloatToScalar(-layer_rect_.y())); 245 SkFloatToScalar(-layer_rect_.y()));
253 246
254 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(), 247 SkRect layer_skrect = SkRect::MakeXYWH(layer_rect_.x(),
255 layer_rect_.y(), 248 layer_rect_.y(),
256 layer_rect_.width(), 249 layer_rect_.width(),
257 layer_rect_.height()); 250 layer_rect_.height());
258 canvas->clipRect(layer_skrect); 251 canvas->clipRect(layer_skrect);
259 252
260 painter->PaintContents(canvas.get(), layer_rect_, graphics_context_status); 253 painter->PaintContents(canvas.get(), layer_rect_, graphics_context_status);
261 254
262 canvas->restore(); 255 canvas->restore();
263 picture_ = skia::AdoptRef(recorder.endRecording()); 256 picture_ = skia::AdoptRef(recorder.endRecording());
264 DCHECK(picture_); 257 DCHECK(picture_);
265 258
266 if (recording) {
267 // SkRecording requires it's the only one holding onto canvas before we
268 // may call releasePlayback(). (This helps enforce thread-safety.)
269 canvas.clear();
270 playback_.reset(recording->releasePlayback());
271 }
272
273 EmitTraceSnapshot(); 259 EmitTraceSnapshot();
274 } 260 }
275 261
276 void Picture::GatherPixelRefs( 262 void Picture::GatherPixelRefs(
277 const SkTileGridFactory::TileGridInfo& tile_grid_info) { 263 const SkTileGridFactory::TileGridInfo& tile_grid_info) {
278 TRACE_EVENT2("cc", "Picture::GatherPixelRefs", 264 TRACE_EVENT2("cc", "Picture::GatherPixelRefs",
279 "width", layer_rect_.width(), 265 "width", layer_rect_.width(),
280 "height", layer_rect_.height()); 266 "height", layer_rect_.height());
281 267
282 DCHECK(picture_); 268 DCHECK(picture_);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 327
342 DCHECK(picture_); 328 DCHECK(picture_);
343 329
344 canvas->save(); 330 canvas->save();
345 331
346 for (Region::Iterator it(negated_content_region); it.has_rect(); it.next()) 332 for (Region::Iterator it(negated_content_region); it.has_rect(); it.next())
347 canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op); 333 canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op);
348 334
349 canvas->scale(contents_scale, contents_scale); 335 canvas->scale(contents_scale, contents_scale);
350 canvas->translate(layer_rect_.x(), layer_rect_.y()); 336 canvas->translate(layer_rect_.x(), layer_rect_.y());
351 if (playback_) { 337 if (callback) {
352 playback_->draw(canvas);
353 } else if (callback) {
354 // If we have a callback, we need to call |draw()|, |drawPicture()| doesn't 338 // If we have a callback, we need to call |draw()|, |drawPicture()| doesn't
355 // take a callback. This is used by |AnalysisCanvas| to early out. 339 // take a callback. This is used by |AnalysisCanvas| to early out.
356 picture_->draw(canvas, callback); 340 picture_->draw(canvas, callback);
357 } else { 341 } else {
358 // Prefer to call |drawPicture()| on the canvas since it could place the 342 // Prefer to call |drawPicture()| on the canvas since it could place the
359 // entire picture on the canvas instead of parsing the skia operations. 343 // entire picture on the canvas instead of parsing the skia operations.
360 canvas->drawPicture(picture_.get()); 344 canvas->drawPicture(picture_.get());
361 } 345 }
362 SkIRect bounds; 346 SkIRect bounds;
363 canvas->getClipDeviceBounds(&bounds); 347 canvas->getClipDeviceBounds(&bounds);
364 canvas->restore(); 348 canvas->restore();
365 TRACE_EVENT_END1( 349 TRACE_EVENT_END1(
366 "cc", "Picture::Raster", 350 "cc", "Picture::Raster",
367 "num_pixels_rasterized", bounds.width() * bounds.height()); 351 "num_pixels_rasterized", bounds.width() * bounds.height());
368 return bounds.width() * bounds.height(); 352 return bounds.width() * bounds.height();
369 } 353 }
370 354
371 void Picture::Replay(SkCanvas* canvas) { 355 void Picture::Replay(SkCanvas* canvas) {
372 TRACE_EVENT_BEGIN0("cc", "Picture::Replay"); 356 TRACE_EVENT_BEGIN0("cc", "Picture::Replay");
373 DCHECK(picture_); 357 DCHECK(picture_);
374 358 picture_->draw(canvas);
375 if (playback_) {
376 playback_->draw(canvas);
377 } else {
378 picture_->draw(canvas);
379 }
380 SkIRect bounds; 359 SkIRect bounds;
381 canvas->getClipDeviceBounds(&bounds); 360 canvas->getClipDeviceBounds(&bounds);
382 TRACE_EVENT_END1("cc", "Picture::Replay", 361 TRACE_EVENT_END1("cc", "Picture::Replay",
383 "num_pixels_replayed", bounds.width() * bounds.height()); 362 "num_pixels_replayed", bounds.width() * bounds.height());
384 } 363 }
385 364
386 scoped_ptr<base::Value> Picture::AsValue() const { 365 scoped_ptr<base::Value> Picture::AsValue() const {
387 SkDynamicMemoryWStream stream; 366 SkDynamicMemoryWStream stream;
388 367 picture_->serialize(&stream, &EncodeBitmap);
389 if (playback_) {
390 // SkPlayback can't serialize itself, so re-record into an SkPicture.
391 SkPictureRecorder recorder;
392 skia::RefPtr<SkCanvas> canvas(skia::SharePtr(recorder.beginRecording(
393 layer_rect_.width(),
394 layer_rect_.height(),
395 NULL))); // Default (no) bounding-box hierarchy is fastest.
396 playback_->draw(canvas.get());
397 skia::RefPtr<SkPicture> picture(skia::AdoptRef(recorder.endRecording()));
398 picture->serialize(&stream, &EncodeBitmap);
399 } else {
400 // Serialize the picture.
401 picture_->serialize(&stream, &EncodeBitmap);
402 }
403 368
404 // Encode the picture as base64. 369 // Encode the picture as base64.
405 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 370 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
406 res->Set("params.layer_rect", MathUtil::AsValue(layer_rect_).release()); 371 res->Set("params.layer_rect", MathUtil::AsValue(layer_rect_).release());
407 372
408 size_t serialized_size = stream.bytesWritten(); 373 size_t serialized_size = stream.bytesWritten();
409 scoped_ptr<char[]> serialized_picture(new char[serialized_size]); 374 scoped_ptr<char[]> serialized_picture(new char[serialized_size]);
410 stream.copyTo(serialized_picture.get()); 375 stream.copyTo(serialized_picture.get());
411 std::string b64_picture; 376 std::string b64_picture;
412 base::Base64Encode(std::string(serialized_picture.get(), serialized_size), 377 base::Base64Encode(std::string(serialized_picture.get(), serialized_size),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 scoped_refptr<base::debug::TracedValue> record_data = 512 scoped_refptr<base::debug::TracedValue> record_data =
548 new base::debug::TracedValue(); 513 new base::debug::TracedValue();
549 TracedValue::SetIDRef(this, record_data.get(), "picture_id"); 514 TracedValue::SetIDRef(this, record_data.get(), "picture_id");
550 record_data->BeginArray("layer_rect"); 515 record_data->BeginArray("layer_rect");
551 MathUtil::AddToTracedValue(layer_rect_, record_data.get()); 516 MathUtil::AddToTracedValue(layer_rect_, record_data.get());
552 record_data->EndArray(); 517 record_data->EndArray();
553 return record_data; 518 return record_data;
554 } 519 }
555 520
556 } // namespace cc 521 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture.h ('k') | cc/resources/picture_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698