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
3 // found in the LICENSE file.
5 #include "cc/playback/drawing_display_item.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "cc/debug/picture_debug_util.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkMatrix.h"
14 #include "third_party/skia/include/core/SkPicture.h"
15 #include "third_party/skia/include/utils/SkPictureUtils.h"
19 DrawingDisplayItem::DrawingDisplayItem() {
22 DrawingDisplayItem::~DrawingDisplayItem() {
25 void DrawingDisplayItem::SetNew(skia::RefPtr
<SkPicture
> picture
) {
26 picture_
= picture
.Pass();
27 DisplayItem::SetNew(picture_
->suitableForGpuRasterization(NULL
),
28 picture_
->approximateOpCount(),
29 SkPictureUtils::ApproximateBytesUsed(picture_
.get()));
32 void DrawingDisplayItem::Raster(SkCanvas
* canvas
,
33 SkPicture::AbortCallback
* callback
) const {
34 // SkPicture always does a wrapping save/restore on the canvas, so it is not
37 picture_
->playback(canvas
, callback
);
39 canvas
->drawPicture(picture_
.get());
42 void DrawingDisplayItem::AsValueInto(
43 base::trace_event::TracedValue
* array
) const {
44 array
->BeginDictionary();
45 array
->SetString("name", "DrawingDisplayItem");
48 base::StringPrintf("[%f,%f,%f,%f]", picture_
->cullRect().x(),
49 picture_
->cullRect().y(), picture_
->cullRect().width(),
50 picture_
->cullRect().height()));
51 std::string b64_picture
;
52 PictureDebugUtil::SerializeAsBase64(picture_
.get(), &b64_picture
);
53 array
->SetString("skp64", b64_picture
);
54 array
->EndDictionary();
57 void DrawingDisplayItem::CloneTo(DrawingDisplayItem
* item
) const {
58 item
->SetNew(picture_
);