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 #ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 5 #ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
6 #define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 6 #define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 const gfx::Rect& canvas_target_playback_rect, | 63 const gfx::Rect& canvas_target_playback_rect, |
64 float contents_scale) const; | 64 float contents_scale) const; |
65 | 65 |
66 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; | 66 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; |
67 | 67 |
68 // This is a fast path for use only if canvas_ is set and | 68 // This is a fast path for use only if canvas_ is set and |
69 // retain_individual_display_items_ is false. This method also updates | 69 // retain_individual_display_items_ is false. This method also updates |
70 // approximate_op_count_. | 70 // approximate_op_count_. |
71 void RasterIntoCanvas(const DisplayItem& display_item); | 71 void RasterIntoCanvas(const DisplayItem& display_item); |
72 | 72 |
73 // Because processing happens in this function, all the set up for | 73 // Because processing happens in these CreateAndAppend functions, all the set |
74 // this item should be done via the args, which is why the return | 74 // up for the item should be done via the args, which is why the return type |
75 // type needs to be const, to prevent set-after-processing mistakes. | 75 // needs to be const, to prevent set-after-processing mistakes. |
76 template <typename DisplayItemType, typename... Args> | 76 template <typename DisplayItemType, typename... Args> |
77 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, | 77 const DisplayItemType& CreateAndAppendPairedBeginItem(Args&&... args) { |
78 Args&&... args) { | 78 size_t item_index = inputs_.visual_rects.size(); |
| 79 inputs_.visual_rects.push_back(gfx::Rect()); |
| 80 inputs_.begin_item_indices.push_back(item_index); |
| 81 |
| 82 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); |
| 83 } |
| 84 |
| 85 template <typename DisplayItemType, typename... Args> |
| 86 const DisplayItemType& CreateAndAppendPairedEndItem(Args&&... args) { |
| 87 DCHECK(!inputs_.begin_item_indices.empty()); |
| 88 size_t last_begin_index = inputs_.begin_item_indices.back(); |
| 89 inputs_.begin_item_indices.pop_back(); |
| 90 |
| 91 // Note that we are doing two separate things below: |
| 92 // |
| 93 // 1. Appending a new rect to the |visual_rects| list associated with |
| 94 // the newly-being-added paired end item, with that visual rect |
| 95 // having same bounds as its paired begin item, referenced via |
| 96 // |last_begin_index|. The paired begin item may or may not be the |
| 97 // current last visual rect in |visual_rects|, and its bounds has |
| 98 // potentially been grown via calls to CreateAndAppendDrawingItem(). |
| 99 // |
| 100 // 2. If there is still a containing paired begin item after closing the |
| 101 // pair ended in this method call, growing that item's visual rect to |
| 102 // incorporate the bounds of the now-finished pair. |
| 103 // |
| 104 // Thus we're carefully pushing and growing by the visual rect of the |
| 105 // paired begin item we're closing in this method call, which is not |
| 106 // necessarily the same as |visual_rects.back()|, and given that the |
| 107 // |visual_rects| list is mutated in step 1 before step 2, we also can't |
| 108 // shorten the reference via a |const auto| reference. We could make a |
| 109 // copy of the rect before list mutation, but that would incur copy |
| 110 // overhead. |
| 111 |
| 112 // Ending bounds match the starting bounds. |
| 113 inputs_.visual_rects.push_back(inputs_.visual_rects[last_begin_index]); |
| 114 |
| 115 // The block that ended needs to be included in the bounds of the enclosing |
| 116 // block. |
| 117 GrowCurrentBeginItemVisualRect(inputs_.visual_rects[last_begin_index]); |
| 118 |
| 119 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); |
| 120 } |
| 121 |
| 122 template <typename DisplayItemType, typename... Args> |
| 123 const DisplayItemType& CreateAndAppendDrawingItem( |
| 124 const gfx::Rect& visual_rect, |
| 125 Args&&... args) { |
79 inputs_.visual_rects.push_back(visual_rect); | 126 inputs_.visual_rects.push_back(visual_rect); |
80 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( | 127 GrowCurrentBeginItemVisualRect(visual_rect); |
81 std::forward<Args>(args)...); | 128 |
82 approximate_op_count_ += item->ApproximateOpCount(); | 129 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); |
83 ProcessAppendedItem(item); | |
84 return *item; | |
85 } | 130 } |
86 | 131 |
87 // Called after all items are appended, to process the items and, if | 132 // Called after all items are appended, to process the items and, if |
88 // applicable, create an internally cached SkPicture. | 133 // applicable, create an internally cached SkPicture. |
89 void Finalize(); | 134 void Finalize(); |
90 | 135 |
91 void SetIsSuitableForGpuRasterization(bool is_suitable) { | 136 void SetIsSuitableForGpuRasterization(bool is_suitable) { |
92 inputs_.is_suitable_for_gpu_rasterization = is_suitable; | 137 inputs_.is_suitable_for_gpu_rasterization = is_suitable; |
93 } | 138 } |
94 bool IsSuitableForGpuRasterization() const; | 139 bool IsSuitableForGpuRasterization() const; |
95 int ApproximateOpCount() const; | 140 int ApproximateOpCount() const; |
96 size_t ApproximateMemoryUsage() const; | 141 size_t ApproximateMemoryUsage() const; |
97 bool ShouldBeAnalyzedForSolidColor() const; | 142 bool ShouldBeAnalyzedForSolidColor() const; |
98 | 143 |
99 bool RetainsIndividualDisplayItems() const; | 144 bool RetainsIndividualDisplayItems() const; |
100 | 145 |
101 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 146 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
102 bool include_items) const; | 147 bool include_items) const; |
103 | 148 |
104 void EmitTraceSnapshot() const; | 149 void EmitTraceSnapshot() const; |
105 | 150 |
106 void GenerateDiscardableImagesMetadata(); | 151 void GenerateDiscardableImagesMetadata(); |
107 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 152 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
108 float raster_scale, | 153 float raster_scale, |
109 std::vector<DrawImage>* images); | 154 std::vector<DrawImage>* images); |
110 | 155 |
| 156 size_t size() const { return inputs_.items.size(); } |
| 157 |
111 gfx::Rect VisualRectForTesting(int index) { | 158 gfx::Rect VisualRectForTesting(int index) { |
112 return inputs_.visual_rects[index]; | 159 return inputs_.visual_rects[index]; |
113 } | 160 } |
114 | 161 |
115 ContiguousContainer<DisplayItem>::const_iterator begin() const { | 162 ContiguousContainer<DisplayItem>::const_iterator begin() const { |
116 return inputs_.items.begin(); | 163 return inputs_.items.begin(); |
117 } | 164 } |
118 | 165 |
119 ContiguousContainer<DisplayItem>::const_iterator end() const { | 166 ContiguousContainer<DisplayItem>::const_iterator end() const { |
120 return inputs_.items.end(); | 167 return inputs_.items.end(); |
121 } | 168 } |
122 | 169 |
123 private: | 170 private: |
124 DisplayItemList(gfx::Rect layer_rect, | 171 DisplayItemList(gfx::Rect layer_rect, |
125 const DisplayItemListSettings& display_list_settings, | 172 const DisplayItemListSettings& display_list_settings, |
126 bool retain_individual_display_items); | 173 bool retain_individual_display_items); |
127 ~DisplayItemList(); | 174 ~DisplayItemList(); |
128 | 175 |
| 176 // If we're currently within a paired display item block, unions the |
| 177 // given visual rect with the begin display item's visual rect. |
| 178 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect); |
129 void ProcessAppendedItem(const DisplayItem* item); | 179 void ProcessAppendedItem(const DisplayItem* item); |
130 | 180 |
| 181 template <typename DisplayItemType, typename... Args> |
| 182 const DisplayItemType& AllocateAndConstruct(Args&&... args) { |
| 183 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( |
| 184 std::forward<Args>(args)...); |
| 185 approximate_op_count_ += item->ApproximateOpCount(); |
| 186 ProcessAppendedItem(item); |
| 187 return *item; |
| 188 } |
| 189 |
131 sk_sp<SkPicture> picture_; | 190 sk_sp<SkPicture> picture_; |
132 | 191 |
133 std::unique_ptr<SkPictureRecorder> recorder_; | 192 std::unique_ptr<SkPictureRecorder> recorder_; |
134 | 193 |
135 bool retain_individual_display_items_; | 194 bool retain_individual_display_items_; |
136 int approximate_op_count_; | 195 int approximate_op_count_; |
137 | 196 |
138 // Memory usage due to the cached SkPicture. | 197 // Memory usage due to the cached SkPicture. |
139 size_t picture_memory_usage_; | 198 size_t picture_memory_usage_; |
140 | 199 |
141 DiscardableImageMap image_map_; | 200 DiscardableImageMap image_map_; |
142 | 201 |
143 struct Inputs { | 202 struct Inputs { |
144 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); | 203 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); |
145 ~Inputs(); | 204 ~Inputs(); |
146 | 205 |
147 ContiguousContainer<DisplayItem> items; | 206 ContiguousContainer<DisplayItem> items; |
148 // The visual rects associated with each of the display items in the | 207 // The visual rects associated with each of the display items in the |
149 // display item list. There is one rect per display item, and the | 208 // display item list. There is one rect per display item, and the |
150 // position in |visual_rects| matches the position of the item in | 209 // position in |visual_rects| matches the position of the item in |
151 // |items| . These rects are intentionally kept separate | 210 // |items| . These rects are intentionally kept separate |
152 // because they are not needed while walking the |items| for raster. | 211 // because they are not needed while walking the |items| for raster. |
153 std::vector<gfx::Rect> visual_rects; | 212 std::vector<gfx::Rect> visual_rects; |
154 | 213 std::vector<size_t> begin_item_indices; |
155 const DisplayItemListSettings settings; | 214 const DisplayItemListSettings settings; |
156 gfx::Rect layer_rect; | 215 gfx::Rect layer_rect; |
157 bool is_suitable_for_gpu_rasterization; | 216 bool is_suitable_for_gpu_rasterization; |
158 }; | 217 }; |
159 | 218 |
160 Inputs inputs_; | 219 Inputs inputs_; |
161 | 220 |
162 friend class base::RefCountedThreadSafe<DisplayItemList>; | 221 friend class base::RefCountedThreadSafe<DisplayItemList>; |
163 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 222 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
164 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 223 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
165 }; | 224 }; |
166 | 225 |
167 } // namespace cc | 226 } // namespace cc |
168 | 227 |
169 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 228 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
OLD | NEW |