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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintController.h

Issue 2107103002: Find cached display items directly during painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 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
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 PaintController_h 5 #ifndef PaintController_h
6 #define PaintController_h 6 #define PaintController_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/RuntimeEnabledFeatures.h" 9 #include "platform/RuntimeEnabledFeatures.h"
10 #include "platform/geometry/IntRect.h" 10 #include "platform/geometry/IntRect.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 template <typename DisplayItemClass, typename... Args> 68 template <typename DisplayItemClass, typename... Args>
69 void createAndAppend(Args&&... args) 69 void createAndAppend(Args&&... args)
70 { 70 {
71 static_assert(WTF::IsSubclass<DisplayItemClass, DisplayItem>::value, 71 static_assert(WTF::IsSubclass<DisplayItemClass, DisplayItem>::value,
72 "Can only createAndAppend subclasses of DisplayItem."); 72 "Can only createAndAppend subclasses of DisplayItem.");
73 static_assert(sizeof(DisplayItemClass) <= kMaximumDisplayItemSize, 73 static_assert(sizeof(DisplayItemClass) <= kMaximumDisplayItemSize,
74 "DisplayItem subclass is larger than kMaximumDisplayItemSize."); 74 "DisplayItem subclass is larger than kMaximumDisplayItemSize.");
75 75
76 if (displayItemConstructionIsDisabled()) 76 if (displayItemConstructionIsDisabled())
77 return; 77 return;
78
79 ensureNewDisplayItemListInitialCapacity();
78 DisplayItemClass& displayItem = m_newDisplayItemList.allocateAndConstruc t<DisplayItemClass>(std::forward<Args>(args)...); 80 DisplayItemClass& displayItem = m_newDisplayItemList.allocateAndConstruc t<DisplayItemClass>(std::forward<Args>(args)...);
79 processNewItem(displayItem); 81 processNewItem(displayItem);
80 } 82 }
81 83
82 // Creates and appends an ending display item to pair with a preceding 84 // Creates and appends an ending display item to pair with a preceding
83 // beginning item iff the display item actually draws content. For no-op 85 // beginning item iff the display item actually draws content. For no-op
84 // items, rather than creating an ending item, the begin item will 86 // items, rather than creating an ending item, the begin item will
85 // instead be removed, thereby maintaining brevity of the list. If display 87 // instead be removed, thereby maintaining brevity of the list. If display
86 // item construction is disabled, no list mutations will be performed. 88 // item construction is disabled, no list mutations will be performed.
87 template <typename DisplayItemClass, typename... Args> 89 template <typename DisplayItemClass, typename... Args>
88 void endItem(Args&&... args) 90 void endItem(Args&&... args)
89 { 91 {
90 if (displayItemConstructionIsDisabled()) 92 if (displayItemConstructionIsDisabled())
91 return; 93 return;
92 if (lastDisplayItemIsNoopBegin()) 94 if (lastDisplayItemIsNoopBegin())
93 removeLastDisplayItem(); 95 removeLastDisplayItem();
94 else 96 else
95 createAndAppend<DisplayItemClass>(std::forward<Args>(args)...); 97 createAndAppend<DisplayItemClass>(std::forward<Args>(args)...);
96 } 98 }
97 99
100 // Try to find the cached drawing display item corresponding to the given pa rameters. If found,
101 // append the cached display item to the new display list and return true. O therwise return false.
102 bool useCachedDrawingIfPossible(const DisplayItemClient&, DisplayItem::Type) ;
103
104 // Try to find the cached subsequence corresponding to the given parameters. If found, copy the
105 // cache subsequence to the new display list and return true. Otherwise retu rn false.
106 bool useCachedSubsequenceIfPossible(const DisplayItemClient&);
107
98 // True if the last display item is a begin that doesn't draw content. 108 // True if the last display item is a begin that doesn't draw content.
99 bool lastDisplayItemIsNoopBegin() const; 109 bool lastDisplayItemIsNoopBegin() const;
100 void removeLastDisplayItem(); 110 void removeLastDisplayItem();
101 111
102 void beginSkippingCache() { ++m_skippingCacheCount; } 112 void beginSkippingCache() { ++m_skippingCacheCount; }
103 void endSkippingCache() { DCHECK(m_skippingCacheCount > 0); --m_skippingCach eCount; } 113 void endSkippingCache() { DCHECK(m_skippingCacheCount > 0); --m_skippingCach eCount; }
104 bool skippingCache() const { return m_skippingCacheCount; } 114 bool skippingCache() const { return m_skippingCacheCount; }
105 115
106 // Must be called when a painting is finished. 116 // Must be called when a painting is finished.
107 // offsetFromLayoutObject is the offset between the space of the GraphicsLay er which owns this 117 // offsetFromLayoutObject is the offset between the space of the GraphicsLay er which owns this
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 #ifndef NDEBUG 151 #ifndef NDEBUG
142 void showDebugData() const; 152 void showDebugData() const;
143 #endif 153 #endif
144 154
145 #if DCHECK_IS_ON() 155 #if DCHECK_IS_ON()
146 void assertDisplayItemClientsAreLive(); 156 void assertDisplayItemClientsAreLive();
147 #endif 157 #endif
148 158
149 protected: 159 protected:
150 PaintController() 160 PaintController()
151 : m_newDisplayItemList(kInitialDisplayItemListCapacityBytes) 161 : m_newDisplayItemList(0)
152 , m_constructionDisabled(false) 162 , m_constructionDisabled(false)
153 , m_subsequenceCachingDisabled(false) 163 , m_subsequenceCachingDisabled(false)
154 , m_textPainted(false) 164 , m_textPainted(false)
155 , m_imagePainted(false) 165 , m_imagePainted(false)
156 , m_skippingCacheCount(0) 166 , m_skippingCacheCount(0)
157 , m_numCachedNewItems(0) 167 , m_numCachedNewItems(0)
158 { } 168 #if DCHECK_IS_ON()
169 , m_numSequentialMatches(0)
170 , m_numOutOfOrderMatches(0)
171 , m_numIndexedItems(0)
172 #endif
173 {
174 resetCurrentListIterators();
175 }
159 176
160 private: 177 private:
178 friend class PaintControllerTest;
179 friend class PaintControllerPaintTestBase;
180
181 void ensureNewDisplayItemListInitialCapacity()
182 {
183 if (m_newDisplayItemList.isEmpty()) {
184 // TODO(wangxianzhu): Consider revisiting this heuristic.
185 m_newDisplayItemList = DisplayItemList(m_currentPaintArtifact.getDis playItemList().isEmpty() ? kInitialDisplayItemListCapacityBytes : m_currentPaint Artifact.getDisplayItemList().usedCapacityInBytes());
186 }
187 }
188
161 // Set new item state (cache skipping, etc) for a new item. 189 // Set new item state (cache skipping, etc) for a new item.
162 void processNewItem(DisplayItem&); 190 void processNewItem(DisplayItem&);
163 191
164 #ifndef NDEBUG 192 #ifndef NDEBUG
165 WTF::String displayItemListAsDebugString(const DisplayItemList&) const; 193 WTF::String displayItemListAsDebugString(const DisplayItemList&) const;
166 #endif 194 #endif
167 195
168 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis playItems of each client. 196 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis playItems of each client.
169 // Temporarily used during merge to find out-of-order display items. 197 // Temporarily used during merge to find out-of-order display items.
170 using DisplayItemIndicesByClientMap = HashMap<const DisplayItemClient*, Vect or<size_t>>; 198 using DisplayItemIndicesByClientMap = HashMap<const DisplayItemClient*, Vect or<size_t>>;
171 199
172 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa yItemIndicesByClientMap&, const DisplayItemList&); 200 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa yItemIndicesByClientMap&, const DisplayItemList&);
173 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display ItemIndicesByClientMap&); 201 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display ItemIndicesByClientMap&);
174 202
175 struct OutOfOrderIndexContext; 203 DisplayItemList::iterator findCachedItem(const DisplayItem::Id&);
176 DisplayItemList::iterator findOutOfOrderCachedItem(const DisplayItem::Id&, O utOfOrderIndexContext&); 204 DisplayItemList::iterator findOutOfOrderCachedItemForward(const DisplayItem: :Id&);
177 DisplayItemList::iterator findOutOfOrderCachedItemForward(const DisplayItem: :Id&, OutOfOrderIndexContext&); 205 void copyCachedSubsequence(DisplayItemList::iterator&);
178 void copyCachedSubsequence(const DisplayItemList& currentList, DisplayItemLi st::iterator& currentIt, DisplayItemList& updatedList, SkPictureGpuAnalyzer&); 206
207 void resetCurrentListIterators();
jbroman 2016/07/06 19:09:38 Comment? It's not obvious to me what the "current
Xianzhu 2016/07/06 19:29:34 Done.
179 208
180 #if DCHECK_IS_ON() 209 #if DCHECK_IS_ON()
181 // The following two methods are for checking under-invalidations 210 // The following two methods are for checking under-invalidations
182 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl ed). 211 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl ed).
183 void checkUnderInvalidation(DisplayItemList::iterator& newIt, DisplayItemLis t::iterator& currentIt); 212 void checkUnderInvalidation(DisplayItemList::iterator& newIt, DisplayItemLis t::iterator& currentIt);
184 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp layItem& newItem, const DisplayItem& oldItem); 213 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp layItem& newItem, const DisplayItem& oldItem);
185 #endif 214 #endif
186 215
187 void updateCacheGeneration();
188
189 // The last complete paint artifact. 216 // The last complete paint artifact.
190 // In SPv2, this includes paint chunks as well as display items. 217 // In SPv2, this includes paint chunks as well as display items.
191 PaintArtifact m_currentPaintArtifact; 218 PaintArtifact m_currentPaintArtifact;
192 219
193 // Data being used to build the next paint artifact. 220 // Data being used to build the next paint artifact.
194 DisplayItemList m_newDisplayItemList; 221 DisplayItemList m_newDisplayItemList;
195 PaintChunker m_newPaintChunks; 222 PaintChunker m_newPaintChunks;
196 223
197 // Allow display item construction to be disabled to isolate the costs of co nstruction 224 // Allow display item construction to be disabled to isolate the costs of co nstruction
198 // in performance metrics. 225 // in performance metrics.
199 bool m_constructionDisabled; 226 bool m_constructionDisabled;
200 227
201 // Allow subsequence caching to be disabled to test the cost of display item caching. 228 // Allow subsequence caching to be disabled to test the cost of display item caching.
202 bool m_subsequenceCachingDisabled; 229 bool m_subsequenceCachingDisabled;
203 230
204 // Indicates this PaintController has ever had text. It is never reset to fa lse. 231 // Indicates this PaintController has ever had text. It is never reset to fa lse.
205 bool m_textPainted; 232 bool m_textPainted;
206 bool m_imagePainted; 233 bool m_imagePainted;
207 234
208 int m_skippingCacheCount; 235 int m_skippingCacheCount;
209 236
210 int m_numCachedNewItems; 237 int m_numCachedNewItems;
211 238
239 // Stores indices to valid DrawingDisplayItems in current display list that have not been
240 // matched by CachedDisplayItems during sequential matching. The indexed ite ms will be
241 // matched by later out-of-order requests of cached display items. This ensu res that when
242 // out-of-order cached display items are requested, we only traverse at most once over
243 // the current display list looking for potential matches. Thus we can ensur e that the
244 // algorithm runs in linear time.
245 DisplayItemIndicesByClientMap m_outOfOrderItemIndices;
246
247 // The next item in the current list for sequential match.
248 DisplayItemList::iterator m_nextItemToMatch;
249
250 // The next item in the current list to be indexed for out-of-order cache re quests.
251 DisplayItemList::iterator m_nextItemToIndex;
252
253 DisplayItemClient::CacheGenerationOrInvalidationReason m_currentCacheGenerat ion;
254
212 #if DCHECK_IS_ON() 255 #if DCHECK_IS_ON()
213 // This is used to check duplicated ids during add(). We could also check 256 int m_numSequentialMatches;
214 // during commitNewDisplayItems(), but checking during add() helps developer 257 int m_numOutOfOrderMatches;
215 // easily find where the duplicated ids are from. 258 int m_numIndexedItems;
259
260 // This is used to check duplicated ids during createAndAppend().
216 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; 261 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient;
217 #endif 262 #endif
218 263
219 DisplayItemClient::CacheGenerationOrInvalidationReason m_currentCacheGenerat ion;
220
221 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS 264 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS
222 // A stack recording subsequence clients that are currently painting. 265 // A stack recording subsequence clients that are currently painting.
223 Vector<const DisplayItemClient*> m_currentSubsequenceClients; 266 Vector<const DisplayItemClient*> m_currentSubsequenceClients;
224 #endif 267 #endif
225 }; 268 };
226 269
227 } // namespace blink 270 } // namespace blink
228 271
229 #endif // PaintController_h 272 #endif // PaintController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698