Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: cc/playback/display_item_list.h

Issue 2225563002: Reland "Raster display item lists via a visual rect RTree." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to head. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/discardable_image_map_unittest.cc ('k') | cc/playback/display_item_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
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/cc_export.h" 17 #include "cc/base/cc_export.h"
18 #include "cc/base/contiguous_container.h" 18 #include "cc/base/contiguous_container.h"
19 #include "cc/base/rtree.h"
19 #include "cc/playback/discardable_image_map.h" 20 #include "cc/playback/discardable_image_map.h"
20 #include "cc/playback/display_item.h" 21 #include "cc/playback/display_item.h"
21 #include "cc/playback/display_item_list_settings.h" 22 #include "cc/playback/display_item_list_settings.h"
22 #include "third_party/skia/include/core/SkPicture.h" 23 #include "third_party/skia/include/core/SkPicture.h"
23 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/geometry/rect_conversions.h"
24 26
25 class SkCanvas; 27 class SkCanvas;
26 class SkPictureRecorder; 28 class SkPictureRecorder;
27 29
28 namespace cc { 30 namespace cc {
29 class ClientPictureCache; 31 class ClientPictureCache;
30 class DisplayItem; 32 class DisplayItem;
31 class DrawingDisplayItem; 33 class DrawingDisplayItem;
32 34
33 namespace proto { 35 namespace proto {
34 class DisplayItemList; 36 class DisplayItemList;
35 } 37 }
36 38
37 class CC_EXPORT DisplayItemList 39 class CC_EXPORT DisplayItemList
38 : public base::RefCountedThreadSafe<DisplayItemList> { 40 : public base::RefCountedThreadSafe<DisplayItemList> {
39 public: 41 public:
40 // Creates a display item list. If picture caching is used, then layer_rect 42 // Creates a display item list.
41 // specifies the cull rect of the display item list (the picture will not
42 // exceed this rect). If picture caching is not used, then the given rect can
43 // be empty.
44 // TODO(vmpstr): Maybe this cull rect can be part of the settings instead.
45 static scoped_refptr<DisplayItemList> Create( 43 static scoped_refptr<DisplayItemList> Create(
46 const gfx::Rect& layer_rect,
47 const DisplayItemListSettings& settings); 44 const DisplayItemListSettings& settings);
48 45
49 // Creates a DisplayItemList from a Protobuf. 46 // Creates a DisplayItemList from a Protobuf.
50 // TODO(dtrainor): Pass in a list of possible DisplayItems to reuse 47 // TODO(dtrainor): Pass in a list of possible DisplayItems to reuse
51 // (crbug.com/548434). 48 // (crbug.com/548434).
52 static scoped_refptr<DisplayItemList> CreateFromProto( 49 static scoped_refptr<DisplayItemList> CreateFromProto(
53 const proto::DisplayItemList& proto, 50 const proto::DisplayItemList& proto,
54 ClientPictureCache* client_picture_cache, 51 ClientPictureCache* client_picture_cache,
55 std::vector<uint32_t>* used_engine_picture_ids); 52 std::vector<uint32_t>* used_engine_picture_ids);
56 53
57 // Creates a Protobuf representing the state of this DisplayItemList. 54 // Creates a Protobuf representing the state of this DisplayItemList.
58 void ToProtobuf(proto::DisplayItemList* proto); 55 void ToProtobuf(proto::DisplayItemList* proto);
59 56
60 // TODO(trchen): Deprecated. Apply clip and scale on the canvas instead. 57 // TODO(trchen): Deprecated. Apply clip and scale on the canvas instead.
61 void Raster(SkCanvas* canvas, 58 void Raster(SkCanvas* canvas,
62 SkPicture::AbortCallback* callback, 59 SkPicture::AbortCallback* callback,
63 const gfx::Rect& canvas_target_playback_rect, 60 const gfx::Rect& canvas_target_playback_rect,
64 float contents_scale) const; 61 float contents_scale) const;
65 62
66 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; 63 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const;
67 64
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
70 // approximate_op_count_.
71 void RasterIntoCanvas(const DisplayItem& display_item);
72 65
73 // Because processing happens in these CreateAndAppend functions, all the set 66 // Because processing happens in these CreateAndAppend functions, all the set
74 // up for the item should be done via the args, which is why the return type 67 // up for the item should be done via the args, which is why the return type
75 // needs to be const, to prevent set-after-processing mistakes. 68 // needs to be const, to prevent set-after-processing mistakes.
76 69
77 // Most paired begin item types default to an empty visual rect, which will 70 // Most paired begin item types default to an empty visual rect, which will
78 // subsequently be grown as needed to encompass any contained items that draw 71 // subsequently be grown as needed to encompass any contained items that draw
79 // content, such as drawing or filter items. 72 // content, such as drawing or filter items.
80 template <typename DisplayItemType, typename... Args> 73 template <typename DisplayItemType, typename... Args>
81 const DisplayItemType& CreateAndAppendPairedBeginItem(Args&&... args) { 74 const DisplayItemType& CreateAndAppendPairedBeginItem(Args&&... args) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 GrowCurrentBeginItemVisualRect(visual_rect); 134 GrowCurrentBeginItemVisualRect(visual_rect);
142 135
143 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); 136 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...);
144 } 137 }
145 138
146 // Called after all items are appended, to process the items and, if 139 // Called after all items are appended, to process the items and, if
147 // applicable, create an internally cached SkPicture. 140 // applicable, create an internally cached SkPicture.
148 void Finalize(); 141 void Finalize();
149 142
150 void SetIsSuitableForGpuRasterization(bool is_suitable) { 143 void SetIsSuitableForGpuRasterization(bool is_suitable) {
151 inputs_.is_suitable_for_gpu_rasterization = is_suitable; 144 inputs_.all_items_are_suitable_for_gpu_rasterization = is_suitable;
152 } 145 }
153 bool IsSuitableForGpuRasterization() const; 146 bool IsSuitableForGpuRasterization() const;
154 int ApproximateOpCount() const; 147 int ApproximateOpCount() const;
155 size_t ApproximateMemoryUsage() const; 148 size_t ApproximateMemoryUsage() const;
156 bool ShouldBeAnalyzedForSolidColor() const; 149 bool ShouldBeAnalyzedForSolidColor() const;
157 150
158 bool RetainsIndividualDisplayItems() const;
159
160 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( 151 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue(
161 bool include_items) const; 152 bool include_items) const;
162 153
163 void EmitTraceSnapshot() const; 154 void EmitTraceSnapshot() const;
164 155
165 void GenerateDiscardableImagesMetadata(); 156 void GenerateDiscardableImagesMetadata();
166 void GetDiscardableImagesInRect(const gfx::Rect& rect, 157 void GetDiscardableImagesInRect(const gfx::Rect& rect,
167 float raster_scale, 158 float raster_scale,
168 std::vector<DrawImage>* images); 159 std::vector<DrawImage>* images);
169 160
161 void SetRetainVisualRectsForTesting(bool retain) {
162 retain_visual_rects_ = retain;
163 }
164
170 size_t size() const { return inputs_.items.size(); } 165 size_t size() const { return inputs_.items.size(); }
171 166
172 gfx::Rect VisualRectForTesting(int index) { 167 gfx::Rect VisualRectForTesting(int index) {
173 return inputs_.visual_rects[index]; 168 return inputs_.visual_rects[index];
174 } 169 }
175 170
176 ContiguousContainer<DisplayItem>::const_iterator begin() const { 171 ContiguousContainer<DisplayItem>::const_iterator begin() const {
177 return inputs_.items.begin(); 172 return inputs_.items.begin();
178 } 173 }
179 174
180 ContiguousContainer<DisplayItem>::const_iterator end() const { 175 ContiguousContainer<DisplayItem>::const_iterator end() const {
181 return inputs_.items.end(); 176 return inputs_.items.end();
182 } 177 }
183 178
184 private: 179 private:
185 DisplayItemList(gfx::Rect layer_rect, 180 explicit DisplayItemList(
186 const DisplayItemListSettings& display_list_settings, 181 const DisplayItemListSettings& display_list_settings);
187 bool retain_individual_display_items);
188 ~DisplayItemList(); 182 ~DisplayItemList();
189 183
184 RTree rtree_;
185 // For testing purposes only. Whether to keep visual rects across calls to
186 // Finalize().
187 bool retain_visual_rects_ = false;
188
190 // If we're currently within a paired display item block, unions the 189 // If we're currently within a paired display item block, unions the
191 // given visual rect with the begin display item's visual rect. 190 // given visual rect with the begin display item's visual rect.
192 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect); 191 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect);
193 void ProcessAppendedItem(const DisplayItem* item);
194 192
195 template <typename DisplayItemType, typename... Args> 193 template <typename DisplayItemType, typename... Args>
196 const DisplayItemType& AllocateAndConstruct(Args&&... args) { 194 const DisplayItemType& AllocateAndConstruct(Args&&... args) {
197 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( 195 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>(
198 std::forward<Args>(args)...); 196 std::forward<Args>(args)...);
199 approximate_op_count_ += item->ApproximateOpCount(); 197 approximate_op_count_ += item->ApproximateOpCount();
200 ProcessAppendedItem(item);
201 return *item; 198 return *item;
202 } 199 }
203 200
204 sk_sp<SkPicture> picture_; 201 int approximate_op_count_ = 0;
205
206 std::unique_ptr<SkPictureRecorder> recorder_;
207
208 bool retain_individual_display_items_;
209 int approximate_op_count_;
210
211 // Memory usage due to the cached SkPicture.
212 size_t picture_memory_usage_;
213 202
214 DiscardableImageMap image_map_; 203 DiscardableImageMap image_map_;
215 204
216 struct Inputs { 205 struct Inputs {
217 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); 206 explicit Inputs(const DisplayItemListSettings& settings);
218 ~Inputs(); 207 ~Inputs();
219 208
220 ContiguousContainer<DisplayItem> items; 209 ContiguousContainer<DisplayItem> items;
221 // The visual rects associated with each of the display items in the 210 // The visual rects associated with each of the display items in the
222 // display item list. There is one rect per display item, and the 211 // display item list. There is one rect per display item, and the
223 // position in |visual_rects| matches the position of the item in 212 // position in |visual_rects| matches the position of the item in
224 // |items| . These rects are intentionally kept separate 213 // |items| . These rects are intentionally kept separate
225 // because they are not needed while walking the |items| for raster. 214 // because they are not needed while walking the |items| for raster.
226 std::vector<gfx::Rect> visual_rects; 215 std::vector<gfx::Rect> visual_rects;
227 std::vector<size_t> begin_item_indices; 216 std::vector<size_t> begin_item_indices;
228 const DisplayItemListSettings settings; 217 const DisplayItemListSettings settings;
229 gfx::Rect layer_rect; 218 bool all_items_are_suitable_for_gpu_rasterization = true;
230 bool is_suitable_for_gpu_rasterization;
231 }; 219 };
232 220
233 Inputs inputs_; 221 Inputs inputs_;
234 222
235 friend class base::RefCountedThreadSafe<DisplayItemList>; 223 friend class base::RefCountedThreadSafe<DisplayItemList>;
236 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); 224 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage);
237 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); 225 DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
238 }; 226 };
239 227
240 } // namespace cc 228 } // namespace cc
241 229
242 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ 230 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
OLDNEW
« no previous file with comments | « cc/playback/discardable_image_map_unittest.cc ('k') | cc/playback/display_item_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698