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 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 78 |
79 ensureNewDisplayItemListInitialCapacity(); | 79 ensureNewDisplayItemListInitialCapacity(); |
80 DisplayItemClass& displayItem = m_newDisplayItemList.allocateAndConstruc
t<DisplayItemClass>(std::forward<Args>(args)...); | 80 DisplayItemClass& displayItem = m_newDisplayItemList.allocateAndConstruc
t<DisplayItemClass>(std::forward<Args>(args)...); |
81 processNewItem(displayItem); | 81 processNewItem(displayItem, NewPainting); |
82 } | 82 } |
83 | 83 |
84 // 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 |
85 // 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 |
86 // items, rather than creating an ending item, the begin item will | 86 // items, rather than creating an ending item, the begin item will |
87 // instead be removed, thereby maintaining brevity of the list. If display | 87 // instead be removed, thereby maintaining brevity of the list. If display |
88 // item construction is disabled, no list mutations will be performed. | 88 // item construction is disabled, no list mutations will be performed. |
89 template <typename DisplayItemClass, typename... Args> | 89 template <typename DisplayItemClass, typename... Args> |
90 void endItem(Args&&... args) | 90 void endItem(Args&&... args) |
91 { | 91 { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 protected: | 158 protected: |
159 PaintController() | 159 PaintController() |
160 : m_newDisplayItemList(0) | 160 : m_newDisplayItemList(0) |
161 , m_constructionDisabled(false) | 161 , m_constructionDisabled(false) |
162 , m_subsequenceCachingDisabled(false) | 162 , m_subsequenceCachingDisabled(false) |
163 , m_textPainted(false) | 163 , m_textPainted(false) |
164 , m_imagePainted(false) | 164 , m_imagePainted(false) |
165 , m_skippingCacheCount(0) | 165 , m_skippingCacheCount(0) |
166 , m_numCachedNewItems(0) | 166 , m_numCachedNewItems(0) |
| 167 , m_currentChunkIsFromCachedSubsequence(true) |
167 #if DCHECK_IS_ON() | 168 #if DCHECK_IS_ON() |
168 , m_numSequentialMatches(0) | 169 , m_numSequentialMatches(0) |
169 , m_numOutOfOrderMatches(0) | 170 , m_numOutOfOrderMatches(0) |
170 , m_numIndexedItems(0) | 171 , m_numIndexedItems(0) |
171 #endif | 172 #endif |
172 { | 173 { |
173 resetCurrentListIndices(); | 174 resetCurrentListIndices(); |
174 } | 175 } |
175 | 176 |
176 private: | 177 private: |
177 friend class PaintControllerTestBase; | 178 friend class PaintControllerTestBase; |
178 friend class PaintControllerPaintTestBase; | 179 friend class PaintControllerPaintTestBase; |
179 | 180 |
180 void ensureNewDisplayItemListInitialCapacity() | 181 void ensureNewDisplayItemListInitialCapacity() |
181 { | 182 { |
182 if (m_newDisplayItemList.isEmpty()) { | 183 if (m_newDisplayItemList.isEmpty()) { |
183 // TODO(wangxianzhu): Consider revisiting this heuristic. | 184 // TODO(wangxianzhu): Consider revisiting this heuristic. |
184 m_newDisplayItemList = DisplayItemList(m_currentPaintArtifact.getDis
playItemList().isEmpty() ? kInitialDisplayItemListCapacityBytes : m_currentPaint
Artifact.getDisplayItemList().usedCapacityInBytes()); | 185 m_newDisplayItemList = DisplayItemList(m_currentPaintArtifact.getDis
playItemList().isEmpty() ? kInitialDisplayItemListCapacityBytes : m_currentPaint
Artifact.getDisplayItemList().usedCapacityInBytes()); |
185 } | 186 } |
186 } | 187 } |
187 | 188 |
188 // Set new item state (cache skipping, etc) for a new item. | 189 // Set new item state (cache skipping, etc) for a new item. |
189 void processNewItem(DisplayItem&); | 190 enum NewItemSource { FromCachedItem, FromCachedSubsequence, NewPainting }; |
| 191 void processNewItem(DisplayItem&, NewItemSource); |
190 | 192 |
191 String displayItemListAsDebugString(const DisplayItemList&) const; | 193 String displayItemListAsDebugString(const DisplayItemList&) const; |
192 | 194 |
193 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis
playItems of each client. | 195 // Maps clients to indices of display items or chunks of each client. |
194 // Temporarily used during merge to find out-of-order display items. | 196 using IndicesByClientMap = HashMap<const DisplayItemClient*, Vector<size_t>>
; |
195 using DisplayItemIndicesByClientMap = HashMap<const DisplayItemClient*, Vect
or<size_t>>; | |
196 | 197 |
197 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa
yItemIndicesByClientMap&, const DisplayItemList&); | 198 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Indice
sByClientMap&, const DisplayItemList&); |
198 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display
ItemIndicesByClientMap&); | 199 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Indices
ByClientMap&); |
199 | 200 |
200 size_t findCachedItem(const DisplayItem::Id&); | 201 size_t findCachedItem(const DisplayItem::Id&); |
201 size_t findOutOfOrderCachedItemForward(const DisplayItem::Id&); | 202 size_t findOutOfOrderCachedItemForward(const DisplayItem::Id&); |
202 void copyCachedSubsequence(size_t&); | 203 void copyCachedSubsequence(size_t&); |
203 | 204 |
204 // Resets the indices (e.g. m_nextItemToMatch) of m_currentPaintArtifact.get
DisplayItemList() | 205 // Resets the indices (e.g. m_nextItemToMatch) of m_currentPaintArtifact.get
DisplayItemList() |
205 // to their initial values. This should be called when the DisplayItemList i
n m_currentPaintArtifact | 206 // to their initial values. This should be called when the DisplayItemList i
n m_currentPaintArtifact |
206 // is newly created, or is changed causing the previous indices to be invali
d. | 207 // is newly created, or is changed causing the previous indices to be invali
d. |
207 void resetCurrentListIndices(); | 208 void resetCurrentListIndices(); |
208 | 209 |
| 210 void generateChunkRasterInvalidationRects(PaintChunk& newChunk); |
| 211 void generateChunkRasterInvalidationRectsComparingOldChunk(PaintChunk& newCh
unk, const PaintChunk& oldChunk); |
| 212 |
209 #if DCHECK_IS_ON() | 213 #if DCHECK_IS_ON() |
210 // The following two methods are for checking under-invalidations | 214 // The following two methods are for checking under-invalidations |
211 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). | 215 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). |
212 void showUnderInvalidationError(const char* reason, const DisplayItem& newIt
em, const DisplayItem* oldItem) const; | 216 void showUnderInvalidationError(const char* reason, const DisplayItem& newIt
em, const DisplayItem* oldItem) const; |
213 void checkUnderInvalidation(); | 217 void checkUnderInvalidation(); |
214 bool isCheckingUnderInvalidation() const { return m_underInvalidationCheckin
gEnd - m_underInvalidationCheckingBegin > 0; } | 218 bool isCheckingUnderInvalidation() const { return m_underInvalidationCheckin
gEnd - m_underInvalidationCheckingBegin > 0; } |
215 #endif | 219 #endif |
216 | 220 |
217 // The last complete paint artifact. | 221 // The last complete paint artifact. |
218 // In SPv2, this includes paint chunks as well as display items. | 222 // In SPv2, this includes paint chunks as well as display items. |
(...skipping 11 matching lines...) Expand all Loading... |
230 bool m_subsequenceCachingDisabled; | 234 bool m_subsequenceCachingDisabled; |
231 | 235 |
232 // Indicates this PaintController has ever had text. It is never reset to fa
lse. | 236 // Indicates this PaintController has ever had text. It is never reset to fa
lse. |
233 bool m_textPainted; | 237 bool m_textPainted; |
234 bool m_imagePainted; | 238 bool m_imagePainted; |
235 | 239 |
236 int m_skippingCacheCount; | 240 int m_skippingCacheCount; |
237 | 241 |
238 int m_numCachedNewItems; | 242 int m_numCachedNewItems; |
239 | 243 |
240 // Stores indices to valid DrawingDisplayItems in current display list that
have not been | 244 // Stores indices to valid cacheable display items in m_currentPaintArtifact
.displayItemList() |
241 // matched by CachedDisplayItems during sequential matching. The indexed ite
ms will be | 245 // that have not been matched by requests of cached display items (using use
CachedDrawingIfPossible() |
| 246 // and useCachedSubsequenceIfPossible()) during sequential matching . The in
dexed items will be |
242 // matched by later out-of-order requests of cached display items. This ensu
res that when | 247 // matched by later out-of-order requests of cached display items. This ensu
res that when |
243 // out-of-order cached display items are requested, we only traverse at most
once over | 248 // out-of-order cached display items are requested, we only traverse at most
once over |
244 // the current display list looking for potential matches. Thus we can ensur
e that the | 249 // the current display list looking for potential matches. Thus we can ensur
e that the |
245 // algorithm runs in linear time. | 250 // algorithm runs in linear time. |
246 DisplayItemIndicesByClientMap m_outOfOrderItemIndices; | 251 IndicesByClientMap m_outOfOrderItemIndices; |
247 | 252 |
248 // The next item in the current list for sequential match. | 253 // The next item in the current list for sequential match. |
249 size_t m_nextItemToMatch; | 254 size_t m_nextItemToMatch; |
250 | 255 |
251 // The next item in the current list to be indexed for out-of-order cache re
quests. | 256 // The next item in the current list to be indexed for out-of-order cache re
quests. |
252 size_t m_nextItemToIndex; | 257 size_t m_nextItemToIndex; |
253 | 258 |
| 259 // Similar to m_outOfOrderItemIndices but |
| 260 // - the indices are chunk indices in m_currentPaintArtifacts.paintChunks(); |
| 261 // - chunks are matched not only for requests of cached display items, but a
lso non-cached display items. |
| 262 IndicesByClientMap m_outOfOrderChunkIndices; |
| 263 |
| 264 bool m_currentChunkIsFromCachedSubsequence; |
| 265 size_t m_nextChunkToMatch; |
| 266 |
254 DisplayItemClient::CacheGenerationOrInvalidationReason m_currentCacheGenerat
ion; | 267 DisplayItemClient::CacheGenerationOrInvalidationReason m_currentCacheGenerat
ion; |
255 | 268 |
256 #if DCHECK_IS_ON() | 269 #if DCHECK_IS_ON() |
257 int m_numSequentialMatches; | 270 int m_numSequentialMatches; |
258 int m_numOutOfOrderMatches; | 271 int m_numOutOfOrderMatches; |
259 int m_numIndexedItems; | 272 int m_numIndexedItems; |
260 | 273 |
261 // This is used to check duplicated ids during createAndAppend(). | 274 // This is used to check duplicated ids during createAndAppend(). |
262 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; | 275 IndicesByClientMap m_newDisplayItemIndicesByClient; |
263 | 276 |
264 // These are set in useCachedDrawingIfPossible() and useCachedSubsequenceIfP
ossible() | 277 // These are set in useCachedDrawingIfPossible() and useCachedSubsequenceIfP
ossible() |
265 // when we could use cached drawing or subsequence and under-invalidation ch
ecking is on, | 278 // when we could use cached drawing or subsequence and under-invalidation ch
ecking is on, |
266 // indicating the begin and end of the cached drawing or subsequence in the
current list. | 279 // indicating the begin and end of the cached drawing or subsequence in the
current list. |
267 // The functions return false to let the client do actual painting, and Pain
tController | 280 // The functions return false to let the client do actual painting, and Pain
tController |
268 // will check if the actual painting results are the same as the cached. | 281 // will check if the actual painting results are the same as the cached. |
269 size_t m_underInvalidationCheckingBegin; | 282 size_t m_underInvalidationCheckingBegin; |
270 size_t m_underInvalidationCheckingEnd; | 283 size_t m_underInvalidationCheckingEnd; |
271 // Number of probable under-invalidations that have been skipped temporarily
because the | 284 // Number of probable under-invalidations that have been skipped temporarily
because the |
272 // mismatching display items may be removed in the future because of no-op p
airs or | 285 // mismatching display items may be removed in the future because of no-op p
airs or |
273 // compositing folding. | 286 // compositing folding. |
274 int m_skippedProbableUnderInvalidationCount; | 287 int m_skippedProbableUnderInvalidationCount; |
275 String m_underInvalidationMessagePrefix; | 288 String m_underInvalidationMessagePrefix; |
276 #endif | 289 #endif |
277 | 290 |
278 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 291 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
279 // A stack recording subsequence clients that are currently painting. | 292 // A stack recording subsequence clients that are currently painting. |
280 Vector<const DisplayItemClient*> m_currentSubsequenceClients; | 293 Vector<const DisplayItemClient*> m_currentSubsequenceClients; |
281 #endif | 294 #endif |
282 }; | 295 }; |
283 | 296 |
284 } // namespace blink | 297 } // namespace blink |
285 | 298 |
286 #endif // PaintController_h | 299 #endif // PaintController_h |
OLD | NEW |