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_PAINT_DISPLAY_ITEM_LIST_H_ | 5 #ifndef CC_PAINT_DISPLAY_ITEM_LIST_H_ |
6 #define CC_PAINT_DISPLAY_ITEM_LIST_H_ | 6 #define CC_PAINT_DISPLAY_ITEM_LIST_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "cc/base/contiguous_container.h" | 17 #include "cc/base/contiguous_container.h" |
18 #include "cc/base/rtree.h" | 18 #include "cc/base/rtree.h" |
19 #include "cc/paint/discardable_image_map.h" | 19 #include "cc/paint/discardable_image_map.h" |
20 #include "cc/paint/display_item.h" | 20 #include "cc/paint/display_item.h" |
| 21 #include "cc/paint/drawing_display_item.h" |
21 #include "cc/paint/image_id.h" | 22 #include "cc/paint/image_id.h" |
22 #include "cc/paint/paint_export.h" | 23 #include "cc/paint/paint_export.h" |
23 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
24 #include "ui/gfx/color_space.h" | 25 #include "ui/gfx/color_space.h" |
25 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
26 #include "ui/gfx/geometry/rect_conversions.h" | 27 #include "ui/gfx/geometry/rect_conversions.h" |
27 | 28 |
28 class SkCanvas; | 29 class SkCanvas; |
29 | 30 |
30 namespace base { | 31 namespace base { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); | 113 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); |
113 } | 114 } |
114 | 115 |
115 template <typename DisplayItemType, typename... Args> | 116 template <typename DisplayItemType, typename... Args> |
116 const DisplayItemType& CreateAndAppendDrawingItem( | 117 const DisplayItemType& CreateAndAppendDrawingItem( |
117 const gfx::Rect& visual_rect, | 118 const gfx::Rect& visual_rect, |
118 Args&&... args) { | 119 Args&&... args) { |
119 visual_rects_.push_back(visual_rect); | 120 visual_rects_.push_back(visual_rect); |
120 GrowCurrentBeginItemVisualRect(visual_rect); | 121 GrowCurrentBeginItemVisualRect(visual_rect); |
121 | 122 |
122 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); | 123 const auto& item = |
| 124 AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); |
| 125 has_discardable_images_ |= item.picture->HasDiscardableImages(); |
| 126 return item; |
123 } | 127 } |
124 | 128 |
125 // Called after all items are appended, to process the items and, if | 129 // Called after all items are appended, to process the items and, if |
126 // applicable, create an internally cached SkPicture. | 130 // applicable, create an internally cached SkPicture. |
127 void Finalize(); | 131 void Finalize(); |
128 | 132 |
129 void SetIsSuitableForGpuRasterization(bool is_suitable) { | 133 void SetIsSuitableForGpuRasterization(bool is_suitable) { |
130 all_items_are_suitable_for_gpu_rasterization_ = is_suitable; | 134 all_items_are_suitable_for_gpu_rasterization_ = is_suitable; |
131 } | 135 } |
132 bool IsSuitableForGpuRasterization() const; | 136 bool IsSuitableForGpuRasterization() const; |
133 | 137 |
134 int ApproximateOpCount() const; | 138 int ApproximateOpCount() const; |
135 size_t ApproximateMemoryUsage() const; | 139 size_t ApproximateMemoryUsage() const; |
136 bool ShouldBeAnalyzedForSolidColor() const; | 140 bool ShouldBeAnalyzedForSolidColor() const; |
137 | 141 |
138 void EmitTraceSnapshot() const; | 142 void EmitTraceSnapshot() const; |
139 | 143 |
140 void GenerateDiscardableImagesMetadata(); | |
141 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 144 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
142 float contents_scale, | 145 float contents_scale, |
143 const gfx::ColorSpace& target_color_space, | 146 const gfx::ColorSpace& target_color_space, |
144 std::vector<DrawImage>* images); | 147 std::vector<DrawImage>* images); |
145 gfx::Rect GetRectForImage(ImageId image_id) const; | 148 gfx::Rect GetRectForImage(ImageId image_id) const; |
146 | 149 |
147 void SetRetainVisualRectsForTesting(bool retain) { | 150 void SetRetainVisualRectsForTesting(bool retain) { |
148 retain_visual_rects_ = retain; | 151 retain_visual_rects_ = retain; |
149 } | 152 } |
150 | 153 |
151 size_t size() const { return items_.size(); } | 154 size_t size() const { return items_.size(); } |
152 | 155 |
153 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } | 156 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } |
154 | 157 |
155 ContiguousContainer<DisplayItem>::const_iterator begin() const { | 158 ContiguousContainer<DisplayItem>::const_iterator begin() const { |
156 return items_.begin(); | 159 return items_.begin(); |
157 } | 160 } |
158 | 161 |
159 ContiguousContainer<DisplayItem>::const_iterator end() const { | 162 ContiguousContainer<DisplayItem>::const_iterator end() const { |
160 return items_.end(); | 163 return items_.end(); |
161 } | 164 } |
162 | 165 |
| 166 bool has_discardable_images() const { return has_discardable_images_; } |
| 167 |
163 private: | 168 private: |
164 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithNoItems); | 169 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithNoItems); |
165 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithItems); | 170 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithItems); |
166 | 171 |
167 ~DisplayItemList(); | 172 ~DisplayItemList(); |
168 | 173 |
169 std::unique_ptr<base::trace_event::TracedValue> CreateTracedValue( | 174 std::unique_ptr<base::trace_event::TracedValue> CreateTracedValue( |
170 bool include_items) const; | 175 bool include_items) const; |
171 | 176 |
172 // If we're currently within a paired display item block, unions the | 177 // If we're currently within a paired display item block, unions the |
173 // given visual rect with the begin display item's visual rect. | 178 // given visual rect with the begin display item's visual rect. |
174 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect); | 179 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect); |
175 | 180 |
176 template <typename DisplayItemType, typename... Args> | 181 template <typename DisplayItemType, typename... Args> |
177 const DisplayItemType& AllocateAndConstruct(Args&&... args) { | 182 const DisplayItemType& AllocateAndConstruct(Args&&... args) { |
178 auto* item = &items_.AllocateAndConstruct<DisplayItemType>( | 183 auto* item = &items_.AllocateAndConstruct<DisplayItemType>( |
179 std::forward<Args>(args)...); | 184 std::forward<Args>(args)...); |
180 approximate_op_count_ += item->ApproximateOpCount(); | 185 approximate_op_count_ += item->ApproximateOpCount(); |
181 return *item; | 186 return *item; |
182 } | 187 } |
183 | 188 |
| 189 void GenerateDiscardableImagesMetadata(); |
| 190 |
184 RTree rtree_; | 191 RTree rtree_; |
185 DiscardableImageMap image_map_; | 192 DiscardableImageMap image_map_; |
186 ContiguousContainer<DisplayItem> items_; | 193 ContiguousContainer<DisplayItem> items_; |
187 | 194 |
188 // The visual rects associated with each of the display items in the | 195 // The visual rects associated with each of the display items in the |
189 // display item list. There is one rect per display item, and the | 196 // display item list. There is one rect per display item, and the |
190 // position in |visual_rects| matches the position of the item in | 197 // position in |visual_rects| matches the position of the item in |
191 // |items| . These rects are intentionally kept separate | 198 // |items| . These rects are intentionally kept separate |
192 // because they are not needed while walking the |items| for raster. | 199 // because they are not needed while walking the |items| for raster. |
193 std::vector<gfx::Rect> visual_rects_; | 200 std::vector<gfx::Rect> visual_rects_; |
194 std::vector<size_t> begin_item_indices_; | 201 std::vector<size_t> begin_item_indices_; |
195 | 202 |
196 int approximate_op_count_ = 0; | 203 int approximate_op_count_ = 0; |
197 bool all_items_are_suitable_for_gpu_rasterization_ = true; | 204 bool all_items_are_suitable_for_gpu_rasterization_ = true; |
198 // For testing purposes only. Whether to keep visual rects across calls to | 205 // For testing purposes only. Whether to keep visual rects across calls to |
199 // Finalize(). | 206 // Finalize(). |
200 bool retain_visual_rects_ = false; | 207 bool retain_visual_rects_ = false; |
| 208 bool has_discardable_images_ = false; |
201 | 209 |
202 friend class base::RefCountedThreadSafe<DisplayItemList>; | 210 friend class base::RefCountedThreadSafe<DisplayItemList>; |
203 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 211 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
204 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 212 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
205 }; | 213 }; |
206 | 214 |
207 } // namespace cc | 215 } // namespace cc |
208 | 216 |
209 #endif // CC_PAINT_DISPLAY_ITEM_LIST_H_ | 217 #endif // CC_PAINT_DISPLAY_ITEM_LIST_H_ |
OLD | NEW |