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

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

Issue 2750683002: cc: Remove the Inputs struct from DisplayItemList (Closed)
Patch Set: displaylist-inputs: rebaserebase Created 3 years, 9 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 | « no previous file | 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>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return CreateAndAppendPairedBeginItemWithVisualRect<DisplayItemType>( 61 return CreateAndAppendPairedBeginItemWithVisualRect<DisplayItemType>(
62 gfx::Rect(), std::forward<Args>(args)...); 62 gfx::Rect(), std::forward<Args>(args)...);
63 } 63 }
64 64
65 // This method variant is exposed to allow filters to specify their visual 65 // This method variant is exposed to allow filters to specify their visual
66 // rect since they may draw content despite containing no drawing items. 66 // rect since they may draw content despite containing no drawing items.
67 template <typename DisplayItemType, typename... Args> 67 template <typename DisplayItemType, typename... Args>
68 const DisplayItemType& CreateAndAppendPairedBeginItemWithVisualRect( 68 const DisplayItemType& CreateAndAppendPairedBeginItemWithVisualRect(
69 const gfx::Rect& visual_rect, 69 const gfx::Rect& visual_rect,
70 Args&&... args) { 70 Args&&... args) {
71 size_t item_index = inputs_.visual_rects.size(); 71 size_t item_index = visual_rects_.size();
72 inputs_.visual_rects.push_back(visual_rect); 72 visual_rects_.push_back(visual_rect);
73 inputs_.begin_item_indices.push_back(item_index); 73 begin_item_indices_.push_back(item_index);
74 74
75 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); 75 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...);
76 } 76 }
77 77
78 template <typename DisplayItemType, typename... Args> 78 template <typename DisplayItemType, typename... Args>
79 const DisplayItemType& CreateAndAppendPairedEndItem(Args&&... args) { 79 const DisplayItemType& CreateAndAppendPairedEndItem(Args&&... args) {
80 DCHECK(!inputs_.begin_item_indices.empty()); 80 DCHECK(!begin_item_indices_.empty());
81 size_t last_begin_index = inputs_.begin_item_indices.back(); 81 size_t last_begin_index = begin_item_indices_.back();
82 inputs_.begin_item_indices.pop_back(); 82 begin_item_indices_.pop_back();
83 83
84 // Note that we are doing two separate things below: 84 // Note that we are doing two separate things below:
85 // 85 //
86 // 1. Appending a new rect to the |visual_rects| list associated with 86 // 1. Appending a new rect to the |visual_rects| list associated with
87 // the newly-being-added paired end item, with that visual rect 87 // the newly-being-added paired end item, with that visual rect
88 // having same bounds as its paired begin item, referenced via 88 // having same bounds as its paired begin item, referenced via
89 // |last_begin_index|. The paired begin item may or may not be the 89 // |last_begin_index|. The paired begin item may or may not be the
90 // current last visual rect in |visual_rects|, and its bounds has 90 // current last visual rect in |visual_rects|, and its bounds has
91 // potentially been grown via calls to CreateAndAppendDrawingItem(). 91 // potentially been grown via calls to CreateAndAppendDrawingItem().
92 // 92 //
93 // 2. If there is still a containing paired begin item after closing the 93 // 2. If there is still a containing paired begin item after closing the
94 // pair ended in this method call, growing that item's visual rect to 94 // pair ended in this method call, growing that item's visual rect to
95 // incorporate the bounds of the now-finished pair. 95 // incorporate the bounds of the now-finished pair.
96 // 96 //
97 // Thus we're carefully pushing and growing by the visual rect of the 97 // Thus we're carefully pushing and growing by the visual rect of the
98 // paired begin item we're closing in this method call, which is not 98 // paired begin item we're closing in this method call, which is not
99 // necessarily the same as |visual_rects.back()|, and given that the 99 // necessarily the same as |visual_rects.back()|, and given that the
100 // |visual_rects| list is mutated in step 1 before step 2, we also can't 100 // |visual_rects| list is mutated in step 1 before step 2, we also can't
101 // shorten the reference via a |const auto| reference. We could make a 101 // shorten the reference via a |const auto| reference. We could make a
102 // copy of the rect before list mutation, but that would incur copy 102 // copy of the rect before list mutation, but that would incur copy
103 // overhead. 103 // overhead.
104 104
105 // Ending bounds match the starting bounds. 105 // Ending bounds match the starting bounds.
106 inputs_.visual_rects.push_back(inputs_.visual_rects[last_begin_index]); 106 visual_rects_.push_back(visual_rects_[last_begin_index]);
107 107
108 // The block that ended needs to be included in the bounds of the enclosing 108 // The block that ended needs to be included in the bounds of the enclosing
109 // block. 109 // block.
110 GrowCurrentBeginItemVisualRect(inputs_.visual_rects[last_begin_index]); 110 GrowCurrentBeginItemVisualRect(visual_rects_[last_begin_index]);
111 111
112 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); 112 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...);
113 } 113 }
114 114
115 template <typename DisplayItemType, typename... Args> 115 template <typename DisplayItemType, typename... Args>
116 const DisplayItemType& CreateAndAppendDrawingItem( 116 const DisplayItemType& CreateAndAppendDrawingItem(
117 const gfx::Rect& visual_rect, 117 const gfx::Rect& visual_rect,
118 Args&&... args) { 118 Args&&... args) {
119 inputs_.visual_rects.push_back(visual_rect); 119 visual_rects_.push_back(visual_rect);
120 GrowCurrentBeginItemVisualRect(visual_rect); 120 GrowCurrentBeginItemVisualRect(visual_rect);
121 121
122 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); 122 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...);
123 } 123 }
124 124
125 // Called after all items are appended, to process the items and, if 125 // Called after all items are appended, to process the items and, if
126 // applicable, create an internally cached SkPicture. 126 // applicable, create an internally cached SkPicture.
127 void Finalize(); 127 void Finalize();
128 128
129 void SetIsSuitableForGpuRasterization(bool is_suitable) { 129 void SetIsSuitableForGpuRasterization(bool is_suitable) {
130 inputs_.all_items_are_suitable_for_gpu_rasterization = is_suitable; 130 all_items_are_suitable_for_gpu_rasterization_ = is_suitable;
131 } 131 }
132 bool IsSuitableForGpuRasterization() const; 132 bool IsSuitableForGpuRasterization() const;
133 133
134 int ApproximateOpCount() const; 134 int ApproximateOpCount() const;
135 size_t ApproximateMemoryUsage() const; 135 size_t ApproximateMemoryUsage() const;
136 bool ShouldBeAnalyzedForSolidColor() const; 136 bool ShouldBeAnalyzedForSolidColor() const;
137 137
138 void EmitTraceSnapshot() const; 138 void EmitTraceSnapshot() const;
139 139
140 void GenerateDiscardableImagesMetadata(); 140 void GenerateDiscardableImagesMetadata();
141 void GetDiscardableImagesInRect(const gfx::Rect& rect, 141 void GetDiscardableImagesInRect(const gfx::Rect& rect,
142 float contents_scale, 142 float contents_scale,
143 std::vector<DrawImage>* images); 143 std::vector<DrawImage>* images);
144 gfx::Rect GetRectForImage(ImageId image_id) const; 144 gfx::Rect GetRectForImage(ImageId image_id) const;
145 145
146 void SetRetainVisualRectsForTesting(bool retain) { 146 void SetRetainVisualRectsForTesting(bool retain) {
147 retain_visual_rects_ = retain; 147 retain_visual_rects_ = retain;
148 } 148 }
149 149
150 size_t size() const { return inputs_.items.size(); } 150 size_t size() const { return items_.size(); }
151 151
152 gfx::Rect VisualRectForTesting(int index) { 152 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; }
153 return inputs_.visual_rects[index];
154 }
155 153
156 ContiguousContainer<DisplayItem>::const_iterator begin() const { 154 ContiguousContainer<DisplayItem>::const_iterator begin() const {
157 return inputs_.items.begin(); 155 return items_.begin();
158 } 156 }
159 157
160 ContiguousContainer<DisplayItem>::const_iterator end() const { 158 ContiguousContainer<DisplayItem>::const_iterator end() const {
161 return inputs_.items.end(); 159 return items_.end();
162 } 160 }
163 161
164 private: 162 private:
165 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithNoItems); 163 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithNoItems);
166 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithItems); 164 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithItems);
167 165
168 ~DisplayItemList(); 166 ~DisplayItemList();
169 167
170 std::unique_ptr<base::trace_event::TracedValue> CreateTracedValue( 168 std::unique_ptr<base::trace_event::TracedValue> CreateTracedValue(
171 bool include_items) const; 169 bool include_items) const;
172 170
173 RTree rtree_;
174 // For testing purposes only. Whether to keep visual rects across calls to
175 // Finalize().
176 bool retain_visual_rects_ = false;
177
178 // If we're currently within a paired display item block, unions the 171 // If we're currently within a paired display item block, unions the
179 // given visual rect with the begin display item's visual rect. 172 // given visual rect with the begin display item's visual rect.
180 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect); 173 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect);
181 174
182 template <typename DisplayItemType, typename... Args> 175 template <typename DisplayItemType, typename... Args>
183 const DisplayItemType& AllocateAndConstruct(Args&&... args) { 176 const DisplayItemType& AllocateAndConstruct(Args&&... args) {
184 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( 177 auto* item = &items_.AllocateAndConstruct<DisplayItemType>(
185 std::forward<Args>(args)...); 178 std::forward<Args>(args)...);
186 approximate_op_count_ += item->ApproximateOpCount(); 179 approximate_op_count_ += item->ApproximateOpCount();
187 return *item; 180 return *item;
188 } 181 }
189 182
183 RTree rtree_;
184 DiscardableImageMap image_map_;
185 ContiguousContainer<DisplayItem> items_;
186
187 // The visual rects associated with each of the display items in the
188 // display item list. There is one rect per display item, and the
189 // position in |visual_rects| matches the position of the item in
190 // |items| . These rects are intentionally kept separate
191 // because they are not needed while walking the |items| for raster.
192 std::vector<gfx::Rect> visual_rects_;
193 std::vector<size_t> begin_item_indices_;
194
190 int approximate_op_count_ = 0; 195 int approximate_op_count_ = 0;
191 196 bool all_items_are_suitable_for_gpu_rasterization_ = true;
192 DiscardableImageMap image_map_; 197 // For testing purposes only. Whether to keep visual rects across calls to
193 198 // Finalize().
194 struct Inputs { 199 bool retain_visual_rects_ = false;
195 Inputs();
196 ~Inputs();
197
198 ContiguousContainer<DisplayItem> items;
199 // The visual rects associated with each of the display items in the
200 // display item list. There is one rect per display item, and the
201 // position in |visual_rects| matches the position of the item in
202 // |items| . These rects are intentionally kept separate
203 // because they are not needed while walking the |items| for raster.
204 std::vector<gfx::Rect> visual_rects;
205 std::vector<size_t> begin_item_indices;
206 bool all_items_are_suitable_for_gpu_rasterization = true;
207 };
208
209 Inputs inputs_;
210 200
211 friend class base::RefCountedThreadSafe<DisplayItemList>; 201 friend class base::RefCountedThreadSafe<DisplayItemList>;
212 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); 202 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage);
213 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); 203 DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
214 }; 204 };
215 205
216 } // namespace cc 206 } // namespace cc
217 207
218 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ 208 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | cc/playback/display_item_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698