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/clip_display_item.h" | 19 #include "cc/playback/clip_display_item.h" |
20 #include "cc/playback/clip_path_display_item.h" | 20 #include "cc/playback/clip_path_display_item.h" |
21 #include "cc/playback/compositing_display_item.h" | 21 #include "cc/playback/compositing_display_item.h" |
22 #include "cc/playback/display_item_list_settings.h" | 22 #include "cc/playback/display_item_list_settings.h" |
23 #include "cc/playback/display_item_proto_factory.h" | |
24 #include "cc/playback/drawing_display_item.h" | 23 #include "cc/playback/drawing_display_item.h" |
25 #include "cc/playback/filter_display_item.h" | 24 #include "cc/playback/filter_display_item.h" |
26 #include "cc/playback/float_clip_display_item.h" | 25 #include "cc/playback/float_clip_display_item.h" |
27 #include "cc/playback/largest_display_item.h" | 26 #include "cc/playback/largest_display_item.h" |
28 #include "cc/playback/transform_display_item.h" | 27 #include "cc/playback/transform_display_item.h" |
29 #include "cc/proto/display_item.pb.h" | |
30 #include "cc/proto/gfx_conversions.h" | |
31 #include "third_party/skia/include/core/SkCanvas.h" | 28 #include "third_party/skia/include/core/SkCanvas.h" |
32 #include "third_party/skia/include/core/SkPictureRecorder.h" | 29 #include "third_party/skia/include/core/SkPictureRecorder.h" |
33 #include "third_party/skia/include/utils/SkPictureUtils.h" | 30 #include "third_party/skia/include/utils/SkPictureUtils.h" |
34 #include "ui/gfx/geometry/rect.h" | 31 #include "ui/gfx/geometry/rect.h" |
35 #include "ui/gfx/geometry/rect_conversions.h" | 32 #include "ui/gfx/geometry/rect_conversions.h" |
36 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
37 | 34 |
38 namespace cc { | 35 namespace cc { |
39 | 36 |
40 namespace { | 37 namespace { |
(...skipping 26 matching lines...) Expand all Loading... |
67 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), | 64 LargestDisplayItemSize() * kDefaultNumDisplayItemsToReserve), |
68 settings(settings) {} | 65 settings(settings) {} |
69 | 66 |
70 DisplayItemList::Inputs::~Inputs() {} | 67 DisplayItemList::Inputs::~Inputs() {} |
71 | 68 |
72 scoped_refptr<DisplayItemList> DisplayItemList::Create( | 69 scoped_refptr<DisplayItemList> DisplayItemList::Create( |
73 const DisplayItemListSettings& settings) { | 70 const DisplayItemListSettings& settings) { |
74 return make_scoped_refptr(new DisplayItemList(settings)); | 71 return make_scoped_refptr(new DisplayItemList(settings)); |
75 } | 72 } |
76 | 73 |
77 scoped_refptr<DisplayItemList> DisplayItemList::CreateFromProto( | |
78 const proto::DisplayItemList& proto, | |
79 ClientPictureCache* client_picture_cache, | |
80 std::vector<uint32_t>* used_engine_picture_ids) { | |
81 scoped_refptr<DisplayItemList> list = | |
82 DisplayItemList::Create(DisplayItemListSettings(proto.settings())); | |
83 | |
84 for (int i = 0; i < proto.items_size(); i++) { | |
85 const proto::DisplayItem& item_proto = proto.items(i); | |
86 const gfx::Rect visual_rect = ProtoToRect(proto.visual_rects(i)); | |
87 DisplayItemProtoFactory::AllocateAndConstruct( | |
88 visual_rect, list.get(), item_proto, client_picture_cache, | |
89 used_engine_picture_ids); | |
90 } | |
91 | |
92 list->Finalize(); | |
93 | |
94 return list; | |
95 } | |
96 | |
97 DisplayItemList::DisplayItemList(const DisplayItemListSettings& settings) | 74 DisplayItemList::DisplayItemList(const DisplayItemListSettings& settings) |
98 : inputs_(settings) {} | 75 : inputs_(settings) {} |
99 | 76 |
100 DisplayItemList::~DisplayItemList() { | 77 DisplayItemList::~DisplayItemList() { |
101 } | 78 } |
102 | 79 |
103 void DisplayItemList::ToProtobuf(proto::DisplayItemList* proto) { | |
104 // The flattened SkPicture approach is going away, and the proto | |
105 // doesn't currently support serializing that flattened picture. | |
106 inputs_.settings.ToProtobuf(proto->mutable_settings()); | |
107 | |
108 DCHECK_EQ(0, proto->items_size()); | |
109 DCHECK_EQ(0, proto->visual_rects_size()); | |
110 DCHECK(inputs_.items.size() == inputs_.visual_rects.size()) | |
111 << "items.size() " << inputs_.items.size() << " visual_rects.size() " | |
112 << inputs_.visual_rects.size(); | |
113 int i = 0; | |
114 for (const auto& item : inputs_.items) { | |
115 RectToProto(inputs_.visual_rects[i++], proto->add_visual_rects()); | |
116 item.ToProtobuf(proto->add_items()); | |
117 } | |
118 } | |
119 | |
120 void DisplayItemList::Raster(SkCanvas* canvas, | 80 void DisplayItemList::Raster(SkCanvas* canvas, |
121 SkPicture::AbortCallback* callback, | 81 SkPicture::AbortCallback* callback, |
122 const gfx::Rect& canvas_target_playback_rect, | 82 const gfx::Rect& canvas_target_playback_rect, |
123 float contents_scale) const { | 83 float contents_scale) const { |
124 canvas->save(); | 84 canvas->save(); |
125 if (!canvas_target_playback_rect.IsEmpty()) { | 85 if (!canvas_target_playback_rect.IsEmpty()) { |
126 // canvas_target_playback_rect is specified in device space. We can't | 86 // canvas_target_playback_rect is specified in device space. We can't |
127 // use clipRect because canvas CTM will be applied on it. Use clipRegion | 87 // use clipRect because canvas CTM will be applied on it. Use clipRegion |
128 // instead because it ignores canvas CTM. | 88 // instead because it ignores canvas CTM. |
129 SkRegion device_clip; | 89 SkRegion device_clip; |
(...skipping 25 matching lines...) Expand all Loading... |
155 } | 115 } |
156 | 116 |
157 void DisplayItemList::GrowCurrentBeginItemVisualRect( | 117 void DisplayItemList::GrowCurrentBeginItemVisualRect( |
158 const gfx::Rect& visual_rect) { | 118 const gfx::Rect& visual_rect) { |
159 if (!inputs_.begin_item_indices.empty()) | 119 if (!inputs_.begin_item_indices.empty()) |
160 inputs_.visual_rects[inputs_.begin_item_indices.back()].Union(visual_rect); | 120 inputs_.visual_rects[inputs_.begin_item_indices.back()].Union(visual_rect); |
161 } | 121 } |
162 | 122 |
163 void DisplayItemList::Finalize() { | 123 void DisplayItemList::Finalize() { |
164 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); | 124 TRACE_EVENT0("cc", "DisplayItemList::Finalize"); |
165 // TODO(dtrainor): Need to deal with serializing inputs_.visual_rects. | |
166 // http://crbug.com/568757. | |
167 DCHECK(inputs_.items.size() == inputs_.visual_rects.size()) | 125 DCHECK(inputs_.items.size() == inputs_.visual_rects.size()) |
168 << "items.size() " << inputs_.items.size() << " visual_rects.size() " | 126 << "items.size() " << inputs_.items.size() << " visual_rects.size() " |
169 << inputs_.visual_rects.size(); | 127 << inputs_.visual_rects.size(); |
170 rtree_.Build(inputs_.visual_rects); | 128 rtree_.Build(inputs_.visual_rects); |
171 | 129 |
172 // TODO(wkorman): Restore the below, potentially with a switch to allow | 130 // TODO(wkorman): Restore the below, potentially with a switch to allow |
173 // clearing visual rects except for Blimp engine. http://crbug.com/633750 | 131 // clearing visual rects except for Blimp engine. http://crbug.com/633750 |
174 // if (!retain_visual_rects_) | 132 // if (!retain_visual_rects_) |
175 // // This clears both the vector and the vector's capacity, since | 133 // // This clears both the vector and the vector's capacity, since |
176 // // visual_rects won't be used anymore. | 134 // // visual_rects won't be used anymore. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 265 } |
308 | 266 |
309 void DisplayItemList::GetDiscardableImagesInRect( | 267 void DisplayItemList::GetDiscardableImagesInRect( |
310 const gfx::Rect& rect, | 268 const gfx::Rect& rect, |
311 float contents_scale, | 269 float contents_scale, |
312 std::vector<DrawImage>* images) { | 270 std::vector<DrawImage>* images) { |
313 image_map_.GetDiscardableImagesInRect(rect, contents_scale, images); | 271 image_map_.GetDiscardableImagesInRect(rect, contents_scale, images); |
314 } | 272 } |
315 | 273 |
316 } // namespace cc | 274 } // namespace cc |
OLD | NEW |