OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/resources/drawing_display_item.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/strings/stringprintf.h" | |
11 #include "base/trace_event/trace_event_argument.h" | |
12 #include "cc/debug/picture_debug_util.h" | |
13 #include "third_party/skia/include/core/SkCanvas.h" | |
14 #include "third_party/skia/include/core/SkDrawPictureCallback.h" | |
15 #include "third_party/skia/include/core/SkMatrix.h" | |
16 #include "third_party/skia/include/core/SkPicture.h" | |
17 #include "third_party/skia/include/utils/SkPictureUtils.h" | |
18 | |
19 namespace cc { | |
20 | |
21 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture) | |
22 : picture_(picture) { | |
23 } | |
24 | |
25 DrawingDisplayItem::~DrawingDisplayItem() { | |
26 } | |
27 | |
28 void DrawingDisplayItem::Raster(SkCanvas* canvas, | |
29 SkDrawPictureCallback* callback) const { | |
30 canvas->save(); | |
31 if (callback) | |
32 picture_->playback(canvas, callback); | |
33 else | |
34 canvas->drawPicture(picture_.get()); | |
35 canvas->restore(); | |
36 } | |
37 | |
38 void DrawingDisplayItem::RasterForTracing(SkCanvas* canvas) const { | |
39 canvas->save(); | |
40 // The picture debugger in about:tracing doesn't drill down into |drawPicture| | |
41 // operations. Calling |playback()| rather than |drawPicture()| causes the | |
42 // skia operations in |picture_| to appear individually in the picture | |
43 // produced for tracing rather than being hidden inside a drawPicture | |
44 // operation. | |
45 picture_->playback(canvas); | |
46 canvas->restore(); | |
47 } | |
48 | |
49 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { | |
50 return picture_->suitableForGpuRasterization(NULL); | |
51 } | |
52 | |
53 int DrawingDisplayItem::ApproximateOpCount() const { | |
54 return picture_->approximateOpCount(); | |
55 } | |
56 | |
57 size_t DrawingDisplayItem::PictureMemoryUsage() const { | |
58 DCHECK(picture_); | |
59 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | |
60 } | |
61 | |
62 void DrawingDisplayItem::AsValueInto( | |
63 base::trace_event::TracedValue* array) const { | |
64 array->BeginDictionary(); | |
65 array->SetString("name", "DrawingDisplayItem"); | |
66 array->SetString( | |
67 "cullRect", | |
68 base::StringPrintf("[%f,%f,%f,%f]", picture_->cullRect().x(), | |
69 picture_->cullRect().y(), picture_->cullRect().width(), | |
70 picture_->cullRect().height())); | |
71 std::string b64_picture; | |
72 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | |
73 array->SetString("skp64", b64_picture); | |
74 array->EndDictionary(); | |
75 } | |
76 | |
77 } // namespace cc | |
OLD | NEW |