OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/playback/drawing_display_item.h" | 5 #include "cc/playback/drawing_display_item.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "cc/debug/picture_debug_util.h" | 12 #include "cc/debug/picture_debug_util.h" |
13 #include "cc/proto/display_item.pb.h" | 13 #include "cc/proto/display_item.pb.h" |
14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
15 #include "third_party/skia/include/core/SkData.h" | 15 #include "third_party/skia/include/core/SkData.h" |
16 #include "third_party/skia/include/core/SkMatrix.h" | 16 #include "third_party/skia/include/core/SkMatrix.h" |
17 #include "third_party/skia/include/core/SkPicture.h" | 17 #include "third_party/skia/include/core/SkPicture.h" |
18 #include "third_party/skia/include/core/SkStream.h" | 18 #include "third_party/skia/include/core/SkStream.h" |
19 #include "third_party/skia/include/utils/SkPictureUtils.h" | 19 #include "third_party/skia/include/utils/SkPictureUtils.h" |
20 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 | 23 |
24 DrawingDisplayItem::DrawingDisplayItem() { | 24 DrawingDisplayItem::DrawingDisplayItem() {} |
25 | |
26 DrawingDisplayItem::DrawingDisplayItem(skia::RefPtr<SkPicture> picture) { | |
27 SetNew(picture); | |
danakj
2015/12/08 19:18:16
prefer to move() the reference when it makes sense
| |
28 } | |
29 | |
30 DrawingDisplayItem::DrawingDisplayItem(const proto::DisplayItem& proto) { | |
31 FromProtobuf(proto); | |
32 } | |
33 | |
34 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) { | |
35 item.CloneTo(this); | |
25 } | 36 } |
26 | 37 |
27 DrawingDisplayItem::~DrawingDisplayItem() { | 38 DrawingDisplayItem::~DrawingDisplayItem() { |
28 } | 39 } |
29 | 40 |
30 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { | 41 void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) { |
31 picture_ = std::move(picture); | 42 picture_ = picture; |
vmpstr
2015/12/08 19:07:02
Still move to save on refcounts?
danakj
2015/12/08 19:18:16
ditto
| |
32 DisplayItem::SetNew(picture_->suitableForGpuRasterization(NULL), | |
33 picture_->approximateOpCount(), | |
34 SkPictureUtils::ApproximateBytesUsed(picture_.get())); | |
35 } | 43 } |
36 | 44 |
37 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { | 45 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
38 proto->set_type(proto::DisplayItem::Type_Drawing); | 46 proto->set_type(proto::DisplayItem::Type_Drawing); |
39 | 47 |
40 proto::DrawingDisplayItem* details = proto->mutable_drawing_item(); | 48 proto::DrawingDisplayItem* details = proto->mutable_drawing_item(); |
41 | 49 |
42 // Just use skia's serialize() method for now. | 50 // Just use skia's serialize() method for now. |
43 if (picture_) { | 51 if (picture_) { |
44 SkDynamicMemoryWStream stream; | 52 SkDynamicMemoryWStream stream; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 std::string b64_picture; | 120 std::string b64_picture; |
113 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); | 121 PictureDebugUtil::SerializeAsBase64(picture_.get(), &b64_picture); |
114 array->SetString("skp64", b64_picture); | 122 array->SetString("skp64", b64_picture); |
115 array->EndDictionary(); | 123 array->EndDictionary(); |
116 } | 124 } |
117 | 125 |
118 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { | 126 void DrawingDisplayItem::CloneTo(DrawingDisplayItem* item) const { |
119 item->SetNew(picture_); | 127 item->SetNew(picture_); |
120 } | 128 } |
121 | 129 |
130 size_t DrawingDisplayItem::ExternalMemoryUsage() const { | |
131 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | |
132 } | |
133 | |
134 int DrawingDisplayItem::ApproximateOpCount() const { | |
135 return picture_->approximateOpCount(); | |
136 } | |
137 | |
138 bool DrawingDisplayItem::IsSuitableForGpuRasterization() const { | |
139 return picture_->suitableForGpuRasterization(NULL); | |
140 } | |
141 | |
122 } // namespace cc | 142 } // namespace cc |
OLD | NEW |