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/display_item_list.h" | 5 #include "cc/playback/display_item_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" |
15 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
16 #include "cc/debug/picture_debug_util.h" | 16 #include "cc/debug/picture_debug_util.h" |
17 #include "cc/debug/traced_display_item_list.h" | 17 #include "cc/debug/traced_display_item_list.h" |
18 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
19 #include "cc/playback/display_item_list_settings.h" | 19 #include "cc/playback/display_item_list_settings.h" |
20 #include "cc/playback/display_item_proto_factory.h" | 20 #include "cc/playback/display_item_proto_factory.h" |
21 #include "cc/playback/drawing_display_item.h" | 21 #include "cc/playback/drawing_display_item.h" |
22 #include "cc/playback/largest_display_item.h" | 22 #include "cc/playback/largest_display_item.h" |
23 #include "cc/proto/display_item.pb.h" | 23 #include "cc/proto/display_item.pb.h" |
24 #include "cc/proto/gfx_conversions.h" | 24 #include "cc/proto/gfx_conversions.h" |
25 #include "cc/proto/picture_cache.h" | |
25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "third_party/skia/include/core/SkPictureRecorder.h" | 27 #include "third_party/skia/include/core/SkPictureRecorder.h" |
27 #include "third_party/skia/include/utils/SkPictureUtils.h" | 28 #include "third_party/skia/include/utils/SkPictureUtils.h" |
28 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
29 #include "ui/gfx/skia_util.h" | 30 #include "ui/gfx/skia_util.h" |
30 | 31 |
31 namespace cc { | 32 namespace cc { |
32 class ImageSerializationProcessor; | 33 class EnginePictureCache; |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 // We don't perform per-layer solid color analysis when there are too many skia | 37 // We don't perform per-layer solid color analysis when there are too many skia |
37 // operations. | 38 // operations. |
38 const int kOpCountThatIsOkToAnalyze = 10; | 39 const int kOpCountThatIsOkToAnalyze = 10; |
39 | 40 |
40 bool DisplayItemsTracingEnabled() { | 41 bool DisplayItemsTracingEnabled() { |
41 bool tracing_enabled; | 42 bool tracing_enabled; |
42 TRACE_EVENT_CATEGORY_GROUP_ENABLED( | 43 TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
43 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items"), &tracing_enabled); | 44 TRACE_DISABLED_BY_DEFAULT("cc.debug.display_items"), &tracing_enabled); |
44 return tracing_enabled; | 45 return tracing_enabled; |
45 } | 46 } |
46 | 47 |
47 const int kDefaultNumDisplayItemsToReserve = 100; | 48 const int kDefaultNumDisplayItemsToReserve = 100; |
48 | 49 |
50 // SkPicture::uniqueID() starts at 1. | |
51 const uint32_t kInvalidEnginePictureID = 0; | |
52 | |
53 uint32_t GetUniqueSkPictureIDOrNothing(const proto::DisplayItem& item_proto) { | |
vmpstr
2016/06/16 22:09:59
OrNothing is wrong here. It doesn't return nothing
nyquist
2016/06/24 11:11:14
Done.
| |
54 if (item_proto.type() == proto::DisplayItem::Type_Drawing) { | |
55 DCHECK(item_proto.has_drawing_item()); | |
56 const proto::DrawingDisplayItem& details = item_proto.drawing_item(); | |
57 DCHECK(details.has_id()); | |
58 const proto::SkPictureID& sk_picture_id = details.id(); | |
59 DCHECK(sk_picture_id.has_unique_id()); | |
60 return sk_picture_id.unique_id(); | |
61 } | |
62 return kInvalidEnginePictureID; | |
63 } | |
64 | |
49 } // namespace | 65 } // namespace |
50 | 66 |
51 scoped_refptr<DisplayItemList> DisplayItemList::Create( | 67 scoped_refptr<DisplayItemList> DisplayItemList::Create( |
52 const gfx::Rect& layer_rect, | 68 const gfx::Rect& layer_rect, |
53 const DisplayItemListSettings& settings) { | 69 const DisplayItemListSettings& settings) { |
54 return make_scoped_refptr(new DisplayItemList( | 70 return make_scoped_refptr(new DisplayItemList( |
55 layer_rect, settings, | 71 layer_rect, settings, |
56 !settings.use_cached_picture || DisplayItemsTracingEnabled())); | 72 !settings.use_cached_picture || DisplayItemsTracingEnabled())); |
57 } | 73 } |
58 | 74 |
59 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( | 75 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( |
60 const proto::DisplayItemList& proto, | 76 const proto::DisplayItemList& proto, |
61 ImageSerializationProcessor* image_serialization_processor) { | 77 ClientPictureCache* client_picture_cache) { |
62 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); | 78 gfx::Rect layer_rect = ProtoToRect(proto.layer_rect()); |
63 scoped_refptr<DisplayItemList> list = | 79 scoped_refptr<DisplayItemList> list = |
64 DisplayItemList::Create(ProtoToRect(proto.layer_rect()), | 80 DisplayItemList::Create(ProtoToRect(proto.layer_rect()), |
65 DisplayItemListSettings(proto.settings())); | 81 DisplayItemListSettings(proto.settings())); |
66 | 82 |
83 std::vector<uint32_t> engine_picture_ids; | |
67 for (int i = 0; i < proto.items_size(); i++) { | 84 for (int i = 0; i < proto.items_size(); i++) { |
68 const proto::DisplayItem& item_proto = proto.items(i); | 85 const proto::DisplayItem& item_proto = proto.items(i); |
69 DisplayItemProtoFactory::AllocateAndConstruct( | 86 DisplayItemProtoFactory::AllocateAndConstruct( |
70 layer_rect, list.get(), item_proto, image_serialization_processor); | 87 layer_rect, list.get(), item_proto, client_picture_cache); |
88 engine_picture_ids.push_back(GetUniqueSkPictureIDOrNothing(item_proto)); | |
vmpstr
2016/06/16 22:09:59
So this is meant to have a bunch of 0s in there?
nyquist
2016/06/24 11:11:14
Done.
| |
71 } | 89 } |
72 | 90 |
73 list->Finalize(); | 91 list->Finalize(); |
74 | 92 |
93 // Now that the list has been constructed, ensure that the | |
94 // |engine_picture_ids_| map in order to the same DisplayItems. | |
95 list->engine_picture_ids_.swap(engine_picture_ids); | |
vmpstr
2016/06/16 22:09:59
Sorry if I missed this, but why are storing engine
nyquist
2016/06/24 11:11:14
From the header where the list of IDs is declared:
| |
75 return list; | 96 return list; |
76 } | 97 } |
77 | 98 |
78 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, | 99 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, |
79 const DisplayItemListSettings& settings, | 100 const DisplayItemListSettings& settings, |
80 bool retain_individual_display_items) | 101 bool retain_individual_display_items) |
81 : items_(LargestDisplayItemSize(), | 102 : items_(LargestDisplayItemSize(), |
82 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), | 103 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), |
83 settings_(settings), | 104 settings_(settings), |
84 retain_individual_display_items_(retain_individual_display_items), | 105 retain_individual_display_items_(retain_individual_display_items), |
85 layer_rect_(layer_rect), | 106 layer_rect_(layer_rect), |
86 is_suitable_for_gpu_rasterization_(true), | 107 is_suitable_for_gpu_rasterization_(true), |
87 approximate_op_count_(0), | 108 approximate_op_count_(0), |
88 picture_memory_usage_(0) { | 109 picture_memory_usage_(0) { |
89 if (settings_.use_cached_picture) { | 110 if (settings_.use_cached_picture) { |
90 SkRTreeFactory factory; | 111 SkRTreeFactory factory; |
91 recorder_.reset(new SkPictureRecorder()); | 112 recorder_.reset(new SkPictureRecorder()); |
92 | 113 |
93 SkCanvas* canvas = recorder_->beginRecording( | 114 SkCanvas* canvas = recorder_->beginRecording( |
94 layer_rect_.width(), layer_rect_.height(), &factory); | 115 layer_rect_.width(), layer_rect_.height(), &factory); |
95 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); | 116 canvas->translate(-layer_rect_.x(), -layer_rect_.y()); |
96 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); | 117 canvas->clipRect(gfx::RectToSkRect(layer_rect_)); |
97 } | 118 } |
98 } | 119 } |
99 | 120 |
100 DisplayItemList::~DisplayItemList() { | 121 DisplayItemList::~DisplayItemList() { |
101 } | 122 } |
102 | 123 |
103 void DisplayItemList::ToProtobuf( | 124 void DisplayItemList::ToProtobuf(proto::DisplayItemList* proto) { |
104 proto::DisplayItemList* proto, | |
105 ImageSerializationProcessor* image_serialization_processor) { | |
106 // The flattened SkPicture approach is going away, and the proto | 125 // The flattened SkPicture approach is going away, and the proto |
107 // doesn't currently support serializing that flattened picture. | 126 // doesn't currently support serializing that flattened picture. |
108 DCHECK(retain_individual_display_items_); | 127 DCHECK(retain_individual_display_items_); |
109 | 128 |
110 RectToProto(layer_rect_, proto->mutable_layer_rect()); | 129 RectToProto(layer_rect_, proto->mutable_layer_rect()); |
111 settings_.ToProtobuf(proto->mutable_settings()); | 130 settings_.ToProtobuf(proto->mutable_settings()); |
112 | 131 |
113 DCHECK_EQ(0, proto->items_size()); | 132 DCHECK_EQ(0, proto->items_size()); |
114 for (const auto& item : items_) | 133 for (const auto& item : items_) |
115 item.ToProtobuf(proto->add_items(), image_serialization_processor); | 134 item.ToProtobuf(proto->add_items()); |
135 } | |
136 | |
137 void DisplayItemList::MarkForRegistrationEngine( | |
138 EnginePictureCache* engine_picture_cache) { | |
139 DCHECK(!marked_); | |
140 marked_ = true; | |
141 for (const auto& item : items_) | |
vmpstr
2016/06/16 22:09:59
What I proposed earlier is to maybe provide this t
nyquist
2016/06/24 11:11:14
Done.
| |
142 item.MarkForRegistrationEngine(engine_picture_cache); | |
143 } | |
144 | |
145 void DisplayItemList::MarkForUnregistrationEngine( | |
146 EnginePictureCache* engine_picture_cache) { | |
147 DCHECK(marked_); | |
148 marked_ = false; | |
149 for (const auto& item : items_) | |
150 item.MarkForUnregistrationEngine(engine_picture_cache); | |
151 } | |
152 | |
153 void DisplayItemList::MarkForRegistrationClient( | |
154 ClientPictureCache* client_picture_cache) { | |
155 DCHECK(!marked_); | |
156 marked_ = true; | |
157 for (const uint32_t id : engine_picture_ids_) { | |
158 if (id == kInvalidEnginePictureID) | |
159 continue; | |
160 client_picture_cache->MarkPictureForRegistration(id); | |
161 } | |
162 } | |
163 | |
164 void DisplayItemList::MarkForUnregistrationClient( | |
165 ClientPictureCache* client_picture_cache) { | |
166 DCHECK(marked_); | |
167 marked_ = false; | |
168 for (const uint32_t id : engine_picture_ids_) { | |
169 if (id == kInvalidEnginePictureID) | |
170 continue; | |
171 client_picture_cache->MarkPictureForUnregistration(id); | |
172 } | |
116 } | 173 } |
117 | 174 |
118 void DisplayItemList::Raster(SkCanvas* canvas, | 175 void DisplayItemList::Raster(SkCanvas* canvas, |
119 SkPicture::AbortCallback* callback, | 176 SkPicture::AbortCallback* callback, |
120 const gfx::Rect& canvas_target_playback_rect, | 177 const gfx::Rect& canvas_target_playback_rect, |
121 float contents_scale) const { | 178 float contents_scale) const { |
122 if (!settings_.use_cached_picture) { | 179 if (!settings_.use_cached_picture) { |
123 canvas->save(); | 180 canvas->save(); |
124 canvas->scale(contents_scale, contents_scale); | 181 canvas->scale(contents_scale, contents_scale); |
125 for (const auto& item : items_) | 182 for (const auto& item : items_) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 } | 360 } |
304 | 361 |
305 void DisplayItemList::GetDiscardableImagesInRect( | 362 void DisplayItemList::GetDiscardableImagesInRect( |
306 const gfx::Rect& rect, | 363 const gfx::Rect& rect, |
307 float raster_scale, | 364 float raster_scale, |
308 std::vector<DrawImage>* images) { | 365 std::vector<DrawImage>* images) { |
309 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); | 366 image_map_.GetDiscardableImagesInRect(rect, raster_scale, images); |
310 } | 367 } |
311 | 368 |
312 } // namespace cc | 369 } // namespace cc |
OLD | NEW |