Re-land: C++ readability review
[chromium-blink-merge.git] / cc / resources / drawing_display_item.cc
blob648f9de60a2938eb3b7d77a21a9c2c34d8ae6232
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"
7 #include <string>
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"
18 namespace cc {
20 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture)
21 : picture_(picture) {
24 DrawingDisplayItem::~DrawingDisplayItem() {
27 void DrawingDisplayItem::Raster(SkCanvas* canvas,
28 SkDrawPictureCallback* callback) const {
29 canvas->save();
30 if (callback)
31 picture_->playback(canvas, callback);
32 else
33 canvas->drawPicture(picture_.get());
34 canvas->restore();
37 void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const {
38 canvas->save();
39 // The picture debugger in about:tracing doesn't drill down into |drawPicture|
40 // operations. Calling |playback()| rather than |drawPicture()| causes the
41 // skia operations in |picture_| to appear individually in the picture
42 // produced for tracing rather than being hidden inside a drawPicture
43 // operation.
44 picture_->playback(canvas);
45 canvas->restore();
48 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const {
49 return picture_->suitableForGpuRasterization(NULL);
52 int DrawingDisplayItem::ApproximateOpCount() const {
53 return picture_->approximateOpCount();
56 size_t DrawingDisplayItem::PictureMemoryUsage() const {
57 DCHECK(picture_);
58 return SkPictureUtils::ApproximateBytesUsed(picture_.get());
61 void DrawingDisplayItem::AsValueInto(
62 base::trace_event::TracedValue* array) const {
63 array->BeginDictionary();
64 array->SetString("name", "DrawingDisplayItem");
65 array->SetString(
66 "cullRect",
67 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(),
68 picture_->cullRect().y(), picture_->cullRect().width(),
69 picture_->cullRect().height()));
70 std::string b64_picture;
71 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture);
72 array->SetString("skp64", b64_picture);
73 array->EndDictionary();
76 } // namespace cc