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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "cc/blimp/client_picture_cache.h" |
| 16 #include "cc/blimp/image_serialization_processor.h" |
15 #include "cc/debug/picture_debug_util.h" | 17 #include "cc/debug/picture_debug_util.h" |
16 #include "cc/proto/display_item.pb.h" | 18 #include "cc/proto/display_item.pb.h" |
17 #include "cc/proto/image_serialization_processor.h" | |
18 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
19 #include "third_party/skia/include/core/SkData.h" | 20 #include "third_party/skia/include/core/SkData.h" |
20 #include "third_party/skia/include/core/SkMatrix.h" | 21 #include "third_party/skia/include/core/SkMatrix.h" |
21 #include "third_party/skia/include/core/SkPicture.h" | 22 #include "third_party/skia/include/core/SkPicture.h" |
22 #include "third_party/skia/include/core/SkStream.h" | 23 #include "third_party/skia/include/core/SkStream.h" |
23 #include "third_party/skia/include/utils/SkPictureUtils.h" | 24 #include "third_party/skia/include/utils/SkPictureUtils.h" |
24 #include "ui/gfx/skia_util.h" | 25 #include "ui/gfx/skia_util.h" |
25 | 26 |
26 namespace cc { | 27 namespace cc { |
27 | 28 |
28 DrawingDisplayItem::DrawingDisplayItem() {} | 29 DrawingDisplayItem::DrawingDisplayItem() {} |
29 | 30 |
30 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) { | 31 DrawingDisplayItem::DrawingDisplayItem(sk_sp<const SkPicture> picture) { |
31 SetNew(std::move(picture)); | 32 SetNew(std::move(picture)); |
32 } | 33 } |
33 | 34 |
34 DrawingDisplayItem::DrawingDisplayItem( | 35 DrawingDisplayItem::DrawingDisplayItem( |
35 const proto::DisplayItem& proto, | 36 const proto::DisplayItem& proto, |
36 ImageSerializationProcessor* image_serialization_processor) { | 37 ClientPictureCache* client_picture_cache, |
| 38 std::vector<uint32_t>* used_engine_picture_ids) { |
37 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type()); | 39 DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type()); |
| 40 DCHECK(client_picture_cache); |
38 | 41 |
39 sk_sp<SkPicture> picture; | |
40 const proto::DrawingDisplayItem& details = proto.drawing_item(); | 42 const proto::DrawingDisplayItem& details = proto.drawing_item(); |
41 if (details.has_picture()) { | 43 DCHECK(details.has_id()); |
42 SkMemoryStream stream(details.picture().data(), details.picture().size()); | 44 const proto::SkPictureID& sk_picture_id = details.id(); |
| 45 DCHECK(sk_picture_id.has_unique_id()); |
43 | 46 |
44 picture = SkPicture::MakeFromStream( | 47 uint32_t unique_id = sk_picture_id.unique_id(); |
45 &stream, image_serialization_processor->GetPixelDeserializer()); | 48 sk_sp<const SkPicture> picture = client_picture_cache->GetPicture(unique_id); |
46 } | 49 DCHECK(picture); |
47 | 50 |
| 51 used_engine_picture_ids->push_back(unique_id); |
48 SetNew(std::move(picture)); | 52 SetNew(std::move(picture)); |
49 } | 53 } |
50 | 54 |
51 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) { | 55 DrawingDisplayItem::DrawingDisplayItem(const DrawingDisplayItem& item) { |
52 item.CloneTo(this); | 56 item.CloneTo(this); |
53 } | 57 } |
54 | 58 |
55 DrawingDisplayItem::~DrawingDisplayItem() { | 59 DrawingDisplayItem::~DrawingDisplayItem() { |
56 } | 60 } |
57 | 61 |
58 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { | 62 void DrawingDisplayItem::SetNew(sk_sp<const SkPicture> picture) { |
59 picture_ = std::move(picture); | 63 picture_ = std::move(picture); |
60 } | 64 } |
61 | 65 |
62 void DrawingDisplayItem::ToProtobuf( | 66 void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) const { |
63 proto::DisplayItem* proto, | |
64 ImageSerializationProcessor* image_serialization_processor) const { | |
65 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf"); | 67 TRACE_EVENT0("cc.remote", "DrawingDisplayItem::ToProtobuf"); |
66 proto->set_type(proto::DisplayItem::Type_Drawing); | 68 proto->set_type(proto::DisplayItem::Type_Drawing); |
67 | 69 |
68 proto::DrawingDisplayItem* details = proto->mutable_drawing_item(); | 70 if (!picture_) |
| 71 return; |
69 | 72 |
70 // Just use skia's serialize() method for now. | 73 proto->mutable_drawing_item()->mutable_id()->set_unique_id( |
71 if (picture_) { | 74 picture_->uniqueID()); |
72 TRACE_EVENT0("cc.remote", | 75 } |
73 "DrawingDisplayItem::ToProtobuf SkPicture::Serialize"); | 76 |
74 SkDynamicMemoryWStream stream; | 77 sk_sp<const SkPicture> DrawingDisplayItem::GetPicture() const { |
75 picture_->serialize(&stream, | 78 return picture_; |
76 image_serialization_processor->GetPixelSerializer()); | |
77 if (stream.bytesWritten() > 0) { | |
78 SkAutoDataUnref data(stream.copyToData()); | |
79 details->set_picture(data->data(), data->size()); | |
80 } | |
81 } | |
82 } | 79 } |
83 | 80 |
84 void DrawingDisplayItem::Raster(SkCanvas* canvas, | 81 void DrawingDisplayItem::Raster(SkCanvas* canvas, |
85 SkPicture::AbortCallback* callback) const { | 82 SkPicture::AbortCallback* callback) const { |
86 if (canvas->quickReject(picture_->cullRect())) | 83 if (canvas->quickReject(picture_->cullRect())) |
87 return; | 84 return; |
88 | 85 |
89 // SkPicture always does a wrapping save/restore on the canvas, so it is not | 86 // SkPicture always does a wrapping save/restore on the canvas, so it is not |
90 // necessary here. | 87 // necessary here. |
91 if (callback) | 88 if (callback) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 123 |
127 size_t DrawingDisplayItem::ExternalMemoryUsage() const { | 124 size_t DrawingDisplayItem::ExternalMemoryUsage() const { |
128 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 125 return SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
129 } | 126 } |
130 | 127 |
131 int DrawingDisplayItem::ApproximateOpCount() const { | 128 int DrawingDisplayItem::ApproximateOpCount() const { |
132 return picture_->approximateOpCount(); | 129 return picture_->approximateOpCount(); |
133 } | 130 } |
134 | 131 |
135 } // namespace cc | 132 } // namespace cc |
OLD | NEW |