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/resources/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/SkDrawPictureCallback.h"
14 #include "third_party/skia/include/core/SkMatrix.h"
15 #include "third_party/skia/include/core/SkPicture.h"
16 #include "third_party/skia/include/utils/SkPictureUtils.h"
20 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr
<SkPicture
> picture
,
22 : picture_(picture
), location_(location
) {
25 DrawingDisplayItem::~DrawingDisplayItem() {
28 void DrawingDisplayItem::Raster(SkCanvas
* canvas
,
29 SkDrawPictureCallback
* callback
) const {
31 canvas
->translate(location_
.x(), location_
.y());
33 picture_
->playback(canvas
, callback
);
35 canvas
->drawPicture(picture_
.get());
39 void DrawingDisplayItem::RasterForTracing(SkCanvas
* canvas
) const {
41 canvas
->translate(location_
.x(), location_
.y());
42 // The picture debugger in about:tracing doesn't drill down into |drawPicture|
43 // operations. Calling |playback()| rather than |drawPicture()| causes the
44 // skia operations in |picture_| to appear individually in the picture
45 // produced for tracing rather than being hidden inside a drawPicture
47 picture_
->playback(canvas
);
51 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const {
52 return picture_
->suitableForGpuRasterization(NULL
);
55 int DrawingDisplayItem::ApproximateOpCount() const {
56 return picture_
->approximateOpCount() + sizeof(gfx::PointF
);
59 size_t DrawingDisplayItem::PictureMemoryUsage() const {
61 return SkPictureUtils::ApproximateBytesUsed(picture_
.get());
64 void DrawingDisplayItem::AsValueInto(
65 base::trace_event::TracedValue
* array
) const {
66 array
->BeginDictionary();
67 array
->SetString("name", "DrawingDisplayItem");
68 array
->SetString("location",
69 base::StringPrintf("[%f,%f]", picture_
->cullRect().x(),
70 picture_
->cullRect().y()));
71 std::string b64_picture
;
72 PictureDebugUtil::SerializeAsBase64(picture_
.get(), &b64_picture
);
73 array
->SetString("skp64", b64_picture
);
74 array
->EndDictionary();