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 #include "platform/graphics/paint/PaintController.h" | 5 #include "platform/graphics/paint/PaintController.h" |
6 | 6 |
7 #include "platform/TraceEvent.h" | 7 #include "platform/TraceEvent.h" |
8 #include "platform/graphics/GraphicsLayer.h" | 8 #include "platform/graphics/GraphicsLayer.h" |
9 #include "platform/graphics/paint/DrawingDisplayItem.h" | 9 #include "platform/graphics/paint/DrawingDisplayItem.h" |
10 #include "third_party/skia/include/core/SkPictureAnalyzer.h" | 10 #include "third_party/skia/include/core/SkPictureAnalyzer.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 bool PaintController::useCachedDrawingIfPossible(const DisplayItemClient& client
, DisplayItem::Type type) | 27 bool PaintController::useCachedDrawingIfPossible(const DisplayItemClient& client
, DisplayItem::Type type) |
28 { | 28 { |
29 DCHECK(DisplayItem::isDrawingType(type)); | 29 DCHECK(DisplayItem::isDrawingType(type)); |
30 | 30 |
31 if (displayItemConstructionIsDisabled()) | 31 if (displayItemConstructionIsDisabled()) |
32 return false; | 32 return false; |
33 | 33 |
34 if (!clientCacheIsValid(client)) | 34 if (!clientCacheIsValid(client)) |
35 return false; | 35 return false; |
36 | 36 |
37 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled() && isChe
ckingUnderInvalidation()) { | 37 #if DCHECK_IS_ON() |
| 38 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()
&& isCheckingUnderInvalidation()) { |
38 // We are checking under-invalidation of a subsequence enclosing this di
splay item. | 39 // We are checking under-invalidation of a subsequence enclosing this di
splay item. |
39 // Let the client continue to actually paint the display item. | 40 // Let the client continue to actually paint the display item. |
40 return false; | 41 return false; |
41 } | 42 } |
| 43 #endif |
42 | 44 |
43 size_t cachedItem = findCachedItem(DisplayItem::Id(client, type)); | 45 size_t cachedItem = findCachedItem(DisplayItem::Id(client, type)); |
44 if (cachedItem == kNotFound) { | 46 if (cachedItem == kNotFound) { |
45 NOTREACHED(); | 47 NOTREACHED(); |
46 return false; | 48 return false; |
47 } | 49 } |
48 | 50 |
49 ++m_numCachedNewItems; | 51 ++m_numCachedNewItems; |
50 ensureNewDisplayItemListInitialCapacity(); | 52 ensureNewDisplayItemListInitialCapacity(); |
51 if (!RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) | 53 if (!DCHECK_IS_ON() || !RuntimeEnabledFeatures::slimmingPaintUnderInvalidati
onCheckingEnabled()) |
52 processNewItem(m_newDisplayItemList.appendByMoving(m_currentPaintArtifac
t.getDisplayItemList()[cachedItem]), FromCachedItem); | 54 processNewItem(m_newDisplayItemList.appendByMoving(m_currentPaintArtifac
t.getDisplayItemList()[cachedItem]), FromCachedItem); |
53 | 55 |
54 m_nextItemToMatch = cachedItem + 1; | 56 m_nextItemToMatch = cachedItem + 1; |
55 // Items before m_nextItemToMatch have been copied so we don't need to index
them. | 57 // Items before m_nextItemToMatch have been copied so we don't need to index
them. |
56 if (m_nextItemToMatch > m_nextItemToIndex) | 58 if (m_nextItemToMatch > m_nextItemToIndex) |
57 m_nextItemToIndex = m_nextItemToMatch; | 59 m_nextItemToIndex = m_nextItemToMatch; |
58 | 60 |
59 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 61 #if DCHECK_IS_ON() |
| 62 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled())
{ |
60 if (!isCheckingUnderInvalidation()) { | 63 if (!isCheckingUnderInvalidation()) { |
61 m_underInvalidationCheckingBegin = cachedItem; | 64 m_underInvalidationCheckingBegin = cachedItem; |
62 m_underInvalidationCheckingEnd = cachedItem + 1; | 65 m_underInvalidationCheckingEnd = cachedItem + 1; |
63 m_underInvalidationMessagePrefix = ""; | 66 m_underInvalidationMessagePrefix = ""; |
64 } | 67 } |
65 // Return false to let the painter actually paint, and we will check if
the new painting | 68 // Return false to let the painter actually paint, and we will check if
the new painting |
66 // is the same as the cached. | 69 // is the same as the cached. |
67 return false; | 70 return false; |
68 } | 71 } |
| 72 #endif |
69 | 73 |
70 return true; | 74 return true; |
71 } | 75 } |
72 | 76 |
73 bool PaintController::useCachedSubsequenceIfPossible(const DisplayItemClient& cl
ient) | 77 bool PaintController::useCachedSubsequenceIfPossible(const DisplayItemClient& cl
ient) |
74 { | 78 { |
75 if (displayItemConstructionIsDisabled() || subsequenceCachingIsDisabled()) | 79 if (displayItemConstructionIsDisabled() || subsequenceCachingIsDisabled()) |
76 return false; | 80 return false; |
77 | 81 |
78 if (!clientCacheIsValid(client)) | 82 if (!clientCacheIsValid(client)) |
79 return false; | 83 return false; |
80 | 84 |
81 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled() && isChe
ckingUnderInvalidation()) { | 85 #if DCHECK_IS_ON() |
| 86 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()
&& isCheckingUnderInvalidation()) { |
82 // We are checking under-invalidation of an ancestor subsequence enclosi
ng this one. | 87 // We are checking under-invalidation of an ancestor subsequence enclosi
ng this one. |
83 // The ancestor subsequence is supposed to have already "copied", so we
should let the | 88 // The ancestor subsequence is supposed to have already "copied", so we
should let the |
84 // client continue to actually paint the descendant subsequences without
"copying". | 89 // client continue to actually paint the descendant subsequences without
"copying". |
85 return false; | 90 return false; |
86 } | 91 } |
| 92 #endif |
87 | 93 |
88 size_t cachedItem = findCachedItem(DisplayItem::Id(client, DisplayItem::kSub
sequence)); | 94 size_t cachedItem = findCachedItem(DisplayItem::Id(client, DisplayItem::kSub
sequence)); |
89 if (cachedItem == kNotFound) { | 95 if (cachedItem == kNotFound) { |
90 NOTREACHED(); | 96 NOTREACHED(); |
91 return false; | 97 return false; |
92 } | 98 } |
93 | 99 |
94 // |cachedItem| will point to the first item after the subsequence or end of
the current list. | 100 // |cachedItem| will point to the first item after the subsequence or end of
the current list. |
95 ensureNewDisplayItemListInitialCapacity(); | 101 ensureNewDisplayItemListInitialCapacity(); |
96 copyCachedSubsequence(cachedItem); | 102 copyCachedSubsequence(cachedItem); |
97 | 103 |
98 m_nextItemToMatch = cachedItem; | 104 m_nextItemToMatch = cachedItem; |
99 // Items before |cachedItem| have been copied so we don't need to index them
. | 105 // Items before |cachedItem| have been copied so we don't need to index them
. |
100 if (cachedItem > m_nextItemToIndex) | 106 if (cachedItem > m_nextItemToIndex) |
101 m_nextItemToIndex = cachedItem; | 107 m_nextItemToIndex = cachedItem; |
102 | 108 |
103 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 109 #if DCHECK_IS_ON() |
| 110 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled())
{ |
104 // Return false to let the painter actually paint, and we will check if
the new painting | 111 // Return false to let the painter actually paint, and we will check if
the new painting |
105 // is the same as the cached. | 112 // is the same as the cached. |
106 return false; | 113 return false; |
107 } | 114 } |
| 115 #endif |
108 | 116 |
109 return true; | 117 return true; |
110 } | 118 } |
111 | 119 |
112 bool PaintController::lastDisplayItemIsNoopBegin() const | 120 bool PaintController::lastDisplayItemIsNoopBegin() const |
113 { | 121 { |
114 if (m_newDisplayItemList.isEmpty()) | 122 if (m_newDisplayItemList.isEmpty()) |
115 return false; | 123 return false; |
116 | 124 |
117 const auto& lastDisplayItem = m_newDisplayItemList.last(); | 125 const auto& lastDisplayItem = m_newDisplayItemList.last(); |
118 return lastDisplayItem.isBegin() && !lastDisplayItem.drawsContent(); | 126 return lastDisplayItem.isBegin() && !lastDisplayItem.drawsContent(); |
119 } | 127 } |
120 | 128 |
121 void PaintController::removeLastDisplayItem() | 129 void PaintController::removeLastDisplayItem() |
122 { | 130 { |
123 if (m_newDisplayItemList.isEmpty()) | 131 if (m_newDisplayItemList.isEmpty()) |
124 return; | 132 return; |
125 | 133 |
126 #if DCHECK_IS_ON() | 134 #if DCHECK_IS_ON() |
127 // Also remove the index pointing to the removed display item. | 135 // Also remove the index pointing to the removed display item. |
128 IndicesByClientMap::iterator it = m_newDisplayItemIndicesByClient.find(&m_ne
wDisplayItemList.last().client()); | 136 IndicesByClientMap::iterator it = m_newDisplayItemIndicesByClient.find(&m_ne
wDisplayItemList.last().client()); |
129 if (it != m_newDisplayItemIndicesByClient.end()) { | 137 if (it != m_newDisplayItemIndicesByClient.end()) { |
130 Vector<size_t>& indices = it->value; | 138 Vector<size_t>& indices = it->value; |
131 if (!indices.isEmpty() && indices.last() == (m_newDisplayItemList.size()
- 1)) | 139 if (!indices.isEmpty() && indices.last() == (m_newDisplayItemList.size()
- 1)) |
132 indices.removeLast(); | 140 indices.removeLast(); |
133 } | 141 } |
134 #endif | |
135 | 142 |
136 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled() && isChe
ckingUnderInvalidation()) { | 143 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()
&& isCheckingUnderInvalidation()) { |
137 if (m_skippedProbableUnderInvalidationCount) { | 144 if (m_skippedProbableUnderInvalidationCount) { |
138 --m_skippedProbableUnderInvalidationCount; | 145 --m_skippedProbableUnderInvalidationCount; |
139 } else { | 146 } else { |
140 DCHECK(m_underInvalidationCheckingBegin); | 147 DCHECK(m_underInvalidationCheckingBegin); |
141 --m_underInvalidationCheckingBegin; | 148 --m_underInvalidationCheckingBegin; |
142 } | 149 } |
143 } | 150 } |
| 151 #endif |
144 m_newDisplayItemList.removeLast(); | 152 m_newDisplayItemList.removeLast(); |
145 | 153 |
146 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 154 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
147 m_newPaintChunks.decrementDisplayItemIndex(); | 155 m_newPaintChunks.decrementDisplayItemIndex(); |
148 } | 156 } |
149 | 157 |
150 const DisplayItem* PaintController::lastDisplayItem(unsigned offset) | 158 const DisplayItem* PaintController::lastDisplayItem(unsigned offset) |
151 { | 159 { |
152 if (offset < m_newDisplayItemList.size()) | 160 if (offset < m_newDisplayItemList.size()) |
153 return &m_newDisplayItemList[m_newDisplayItemList.size() - offset - 1]; | 161 return &m_newDisplayItemList[m_newDisplayItemList.size() - offset - 1]; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 size_t index = findMatchingItemFromIndex(displayItem.getId(), m_newDisplayIt
emIndicesByClient, m_newDisplayItemList); | 218 size_t index = findMatchingItemFromIndex(displayItem.getId(), m_newDisplayIt
emIndicesByClient, m_newDisplayItemList); |
211 if (index != kNotFound) { | 219 if (index != kNotFound) { |
212 #ifndef NDEBUG | 220 #ifndef NDEBUG |
213 showDebugData(); | 221 showDebugData(); |
214 WTFLogAlways("DisplayItem %s has duplicated id with previous %s (index=%
d)\n", | 222 WTFLogAlways("DisplayItem %s has duplicated id with previous %s (index=%
d)\n", |
215 displayItem.asDebugString().utf8().data(), m_newDisplayItemList[inde
x].asDebugString().utf8().data(), static_cast<int>(index)); | 223 displayItem.asDebugString().utf8().data(), m_newDisplayItemList[inde
x].asDebugString().utf8().data(), static_cast<int>(index)); |
216 #endif | 224 #endif |
217 NOTREACHED(); | 225 NOTREACHED(); |
218 } | 226 } |
219 addItemToIndexIfNeeded(displayItem, m_newDisplayItemList.size() - 1, m_newDi
splayItemIndicesByClient); | 227 addItemToIndexIfNeeded(displayItem, m_newDisplayItemList.size() - 1, m_newDi
splayItemIndicesByClient); |
| 228 |
| 229 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) |
| 230 checkUnderInvalidation(); |
220 #endif // DCHECK_IS_ON() | 231 #endif // DCHECK_IS_ON() |
221 | |
222 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) | |
223 checkUnderInvalidation(); | |
224 } | 232 } |
225 | 233 |
226 void PaintController::updateCurrentPaintChunkProperties(const PaintChunk::Id* id
, const PaintChunkProperties& newProperties) | 234 void PaintController::updateCurrentPaintChunkProperties(const PaintChunk::Id* id
, const PaintChunkProperties& newProperties) |
227 { | 235 { |
228 m_newPaintChunks.updateCurrentPaintChunkProperties(id, newProperties); | 236 m_newPaintChunks.updateCurrentPaintChunkProperties(id, newProperties); |
229 } | 237 } |
230 | 238 |
231 const PaintChunkProperties& PaintController::currentPaintChunkProperties() const | 239 const PaintChunkProperties& PaintController::currentPaintChunkProperties() const |
232 { | 240 { |
233 return m_newPaintChunks.currentPaintChunkProperties(); | 241 return m_newPaintChunks.currentPaintChunkProperties(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 DCHECK(clientCacheIsValid(id.client)); | 292 DCHECK(clientCacheIsValid(id.client)); |
285 | 293 |
286 // Try to find the item sequentially first. This is fast if the current list
and the new list are in | 294 // Try to find the item sequentially first. This is fast if the current list
and the new list are in |
287 // the same order around the new item. If found, we don't need to update and
lookup the index. | 295 // the same order around the new item. If found, we don't need to update and
lookup the index. |
288 for (size_t i = m_nextItemToMatch; i < m_currentPaintArtifact.getDisplayItem
List().size(); ++i) { | 296 for (size_t i = m_nextItemToMatch; i < m_currentPaintArtifact.getDisplayItem
List().size(); ++i) { |
289 // We encounter an item that has already been copied which indicates we
can't do sequential matching. | 297 // We encounter an item that has already been copied which indicates we
can't do sequential matching. |
290 const DisplayItem& item = m_currentPaintArtifact.getDisplayItemList()[i]
; | 298 const DisplayItem& item = m_currentPaintArtifact.getDisplayItemList()[i]
; |
291 if (!item.hasValidClient()) | 299 if (!item.hasValidClient()) |
292 break; | 300 break; |
293 if (id == item.getId()) { | 301 if (id == item.getId()) { |
294 #ifndef NDEBUG | 302 #if DCHECK_IS_ON() |
295 ++m_numSequentialMatches; | 303 ++m_numSequentialMatches; |
296 #endif | 304 #endif |
297 return i; | 305 return i; |
298 } | 306 } |
299 // We encounter a different cacheable item which also indicates we can't
do sequential matching. | 307 // We encounter a different cacheable item which also indicates we can't
do sequential matching. |
300 if (item.isCacheable()) | 308 if (item.isCacheable()) |
301 break; | 309 break; |
302 } | 310 } |
303 | 311 |
304 size_t foundIndex = findMatchingItemFromIndex(id, m_outOfOrderItemIndices, m
_currentPaintArtifact.getDisplayItemList()); | 312 size_t foundIndex = findMatchingItemFromIndex(id, m_outOfOrderItemIndices, m
_currentPaintArtifact.getDisplayItemList()); |
305 if (foundIndex != kNotFound) { | 313 if (foundIndex != kNotFound) { |
306 #ifndef NDEBUG | 314 #if DCHECK_IS_ON() |
307 ++m_numOutOfOrderMatches; | 315 ++m_numOutOfOrderMatches; |
308 #endif | 316 #endif |
309 return foundIndex; | 317 return foundIndex; |
310 } | 318 } |
311 | 319 |
312 return findOutOfOrderCachedItemForward(id); | 320 return findOutOfOrderCachedItemForward(id); |
313 } | 321 } |
314 | 322 |
315 // Find forward for the item and index all skipped indexable items. | 323 // Find forward for the item and index all skipped indexable items. |
316 size_t PaintController::findOutOfOrderCachedItemForward(const DisplayItem::Id& i
d) | 324 size_t PaintController::findOutOfOrderCachedItemForward(const DisplayItem::Id& i
d) |
317 { | 325 { |
318 for (size_t i = m_nextItemToIndex; i < m_currentPaintArtifact.getDisplayItem
List().size(); ++i) { | 326 for (size_t i = m_nextItemToIndex; i < m_currentPaintArtifact.getDisplayItem
List().size(); ++i) { |
319 const DisplayItem& item = m_currentPaintArtifact.getDisplayItemList()[i]
; | 327 const DisplayItem& item = m_currentPaintArtifact.getDisplayItemList()[i]
; |
320 DCHECK(item.hasValidClient()); | 328 DCHECK(item.hasValidClient()); |
321 if (id == item.getId()) { | 329 if (id == item.getId()) { |
322 #ifndef NDEBUG | 330 #if DCHECK_IS_ON() |
323 ++m_numSequentialMatches; | 331 ++m_numSequentialMatches; |
324 #endif | 332 #endif |
325 return i; | 333 return i; |
326 } | 334 } |
327 if (item.isCacheable()) { | 335 if (item.isCacheable()) { |
328 #ifndef NDEBUG | 336 #if DCHECK_IS_ON() |
329 ++m_numIndexedItems; | 337 ++m_numIndexedItems; |
330 #endif | 338 #endif |
331 addItemToIndexIfNeeded(item, i, m_outOfOrderItemIndices); | 339 addItemToIndexIfNeeded(item, i, m_outOfOrderItemIndices); |
332 } | 340 } |
333 } | 341 } |
334 | 342 |
335 #ifndef NDEBUG | 343 #ifndef NDEBUG |
336 showDebugData(); | 344 showDebugData(); |
337 LOG(ERROR) << id.client.debugName() << ":" << DisplayItem::typeAsDebugString
(id.type); | 345 LOG(ERROR) << id.client.debugName() << ":" << DisplayItem::typeAsDebugString
(id.type); |
338 #endif | 346 #endif |
339 | 347 NOTREACHED() << "Can't find cached display item"; |
340 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) | |
341 CHECK(false) << "Can't find cached display item"; | |
342 | |
343 // We did not find the cached display item. This should be impossible, but m
ay occur if there is a bug | 348 // We did not find the cached display item. This should be impossible, but m
ay occur if there is a bug |
344 // in the system, such as under-invalidation, incorrect cache checking or du
plicate display ids. | 349 // in the system, such as under-invalidation, incorrect cache checking or du
plicate display ids. |
345 // In this case, the caller should fall back to repaint the display item. | 350 // In this case, the caller should fall back to repaint the display item. |
346 return kNotFound; | 351 return kNotFound; |
347 } | 352 } |
348 | 353 |
349 // Copies a cached subsequence from current list to the new list. On return, | 354 // Copies a cached subsequence from current list to the new list. On return, |
350 // |cachedItemIndex| points to the item after the EndSubsequence item of the sub
sequence. | 355 // |cachedItemIndex| points to the item after the EndSubsequence item of the sub
sequence. |
351 // When paintUnderInvaldiationCheckingEnabled() we'll not actually copy the subs
equence, | 356 // When paintUnderInvaldiationCheckingEnabled() we'll not actually copy the subs
equence, |
352 // but mark the begin and end of the subsequence for under-invalidation checking
. | 357 // but mark the begin and end of the subsequence for under-invalidation checking
. |
353 void PaintController::copyCachedSubsequence(size_t& cachedItemIndex) | 358 void PaintController::copyCachedSubsequence(size_t& cachedItemIndex) |
354 { | 359 { |
355 DisplayItem* cachedItem = &m_currentPaintArtifact.getDisplayItemList()[cache
dItemIndex]; | 360 DisplayItem* cachedItem = &m_currentPaintArtifact.getDisplayItemList()[cache
dItemIndex]; |
| 361 #if DCHECK_IS_ON() |
356 DCHECK(cachedItem->getType() == DisplayItem::kSubsequence); | 362 DCHECK(cachedItem->getType() == DisplayItem::kSubsequence); |
357 | 363 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled())
{ |
358 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | |
359 DCHECK(!isCheckingUnderInvalidation()); | 364 DCHECK(!isCheckingUnderInvalidation()); |
360 m_underInvalidationCheckingBegin = cachedItemIndex; | 365 m_underInvalidationCheckingBegin = cachedItemIndex; |
361 m_underInvalidationMessagePrefix = "(In cached subsequence of " + cached
Item->client().debugName() + ")"; | 366 m_underInvalidationMessagePrefix = "(In cached subsequence of " + cached
Item->client().debugName() + ")"; |
362 } | 367 } |
| 368 #endif |
363 | 369 |
364 DisplayItem::Id endSubsequenceId(cachedItem->client(), DisplayItem::kEndSubs
equence); | 370 DisplayItem::Id endSubsequenceId(cachedItem->client(), DisplayItem::kEndSubs
equence); |
365 Vector<PaintChunk>::const_iterator cachedChunk; | 371 Vector<PaintChunk>::const_iterator cachedChunk; |
366 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | 372 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
367 cachedChunk = m_currentPaintArtifact.findChunkByDisplayItemIndex(cachedI
temIndex); | 373 cachedChunk = m_currentPaintArtifact.findChunkByDisplayItemIndex(cachedI
temIndex); |
368 updateCurrentPaintChunkProperties(cachedChunk->id ? &*cachedChunk->id :
nullptr, cachedChunk->properties); | 374 updateCurrentPaintChunkProperties(cachedChunk->id ? &*cachedChunk->id :
nullptr, cachedChunk->properties); |
369 } else { | 375 } else { |
370 // This is to avoid compilation error about uninitialized variable on Wi
ndows. | 376 // This is to avoid compilation error about uninitialized variable on Wi
ndows. |
371 cachedChunk = m_currentPaintArtifact.paintChunks().begin(); | 377 cachedChunk = m_currentPaintArtifact.paintChunks().begin(); |
372 } | 378 } |
373 | 379 |
374 while (true) { | 380 while (true) { |
375 DCHECK(cachedItem->hasValidClient()); | 381 DCHECK(cachedItem->hasValidClient()); |
376 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 382 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
377 CHECK(cachedItem->client().isAlive()); | 383 CHECK(cachedItem->client().isAlive()); |
378 #endif | 384 #endif |
379 ++m_numCachedNewItems; | 385 ++m_numCachedNewItems; |
380 bool metEndSubsequence = cachedItem->getId() == endSubsequenceId; | 386 bool metEndSubsequence = cachedItem->getId() == endSubsequenceId; |
381 if (!RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 387 if (!DCHECK_IS_ON() || !RuntimeEnabledFeatures::slimmingPaintUnderInvali
dationCheckingEnabled()) { |
382 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && cachedItemIn
dex == cachedChunk->endIndex) { | 388 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && cachedItemIn
dex == cachedChunk->endIndex) { |
383 ++cachedChunk; | 389 ++cachedChunk; |
384 updateCurrentPaintChunkProperties(cachedChunk->id ? &*cachedChun
k->id : nullptr, cachedChunk->properties); | 390 updateCurrentPaintChunkProperties(cachedChunk->id ? &*cachedChun
k->id : nullptr, cachedChunk->properties); |
385 } | 391 } |
386 processNewItem(m_newDisplayItemList.appendByMoving(*cachedItem), Fro
mCachedSubsequence); | 392 processNewItem(m_newDisplayItemList.appendByMoving(*cachedItem), Fro
mCachedSubsequence); |
387 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 393 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
388 DCHECK((!m_newPaintChunks.lastChunk().id && !cachedChunk->id) ||
m_newPaintChunks.lastChunk().matches(*cachedChunk)); | 394 DCHECK((!m_newPaintChunks.lastChunk().id && !cachedChunk->id) ||
m_newPaintChunks.lastChunk().matches(*cachedChunk)); |
389 } | 395 } |
390 | 396 |
391 ++cachedItemIndex; | 397 ++cachedItemIndex; |
392 if (metEndSubsequence) | 398 if (metEndSubsequence) |
393 break; | 399 break; |
394 | 400 |
395 // We should always be able to find the EndSubsequence display item. | 401 // We should always be able to find the EndSubsequence display item. |
396 DCHECK(cachedItemIndex < m_currentPaintArtifact.getDisplayItemList().siz
e()); | 402 DCHECK(cachedItemIndex < m_currentPaintArtifact.getDisplayItemList().siz
e()); |
397 cachedItem = &m_currentPaintArtifact.getDisplayItemList()[cachedItemInde
x]; | 403 cachedItem = &m_currentPaintArtifact.getDisplayItemList()[cachedItemInde
x]; |
398 } | 404 } |
399 | 405 |
400 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 406 #if DCHECK_IS_ON() |
| 407 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled())
{ |
401 m_underInvalidationCheckingEnd = cachedItemIndex; | 408 m_underInvalidationCheckingEnd = cachedItemIndex; |
402 DCHECK(isCheckingUnderInvalidation()); | 409 DCHECK(isCheckingUnderInvalidation()); |
403 } | 410 } |
| 411 #endif |
404 } | 412 } |
405 | 413 |
406 static IntRect visualRectForDisplayItem(const DisplayItem& displayItem, const La
youtSize& offsetFromLayoutObject) | 414 static IntRect visualRectForDisplayItem(const DisplayItem& displayItem, const La
youtSize& offsetFromLayoutObject) |
407 { | 415 { |
408 LayoutRect visualRect = displayItem.client().visualRect(); | 416 LayoutRect visualRect = displayItem.client().visualRect(); |
409 visualRect.move(-offsetFromLayoutObject); | 417 visualRect.move(-offsetFromLayoutObject); |
410 return enclosingIntRect(visualRect); | 418 return enclosingIntRect(visualRect); |
411 } | 419 } |
412 | 420 |
413 void PaintController::resetCurrentListIndices() | 421 void PaintController::resetCurrentListIndices() |
414 { | 422 { |
415 m_nextItemToMatch = 0; | 423 m_nextItemToMatch = 0; |
416 m_nextItemToIndex = 0; | 424 m_nextItemToIndex = 0; |
417 m_nextChunkToMatch = 0; | 425 m_nextChunkToMatch = 0; |
| 426 #if DCHECK_IS_ON() |
418 m_underInvalidationCheckingBegin = 0; | 427 m_underInvalidationCheckingBegin = 0; |
419 m_underInvalidationCheckingEnd = 0; | 428 m_underInvalidationCheckingEnd = 0; |
420 m_skippedProbableUnderInvalidationCount = 0; | 429 m_skippedProbableUnderInvalidationCount = 0; |
| 430 #endif |
421 } | 431 } |
422 | 432 |
423 void PaintController::commitNewDisplayItems(const LayoutSize& offsetFromLayoutOb
ject) | 433 void PaintController::commitNewDisplayItems(const LayoutSize& offsetFromLayoutOb
ject) |
424 { | 434 { |
425 TRACE_EVENT2("blink,benchmark", "PaintController::commitNewDisplayItems", | 435 TRACE_EVENT2("blink,benchmark", "PaintController::commitNewDisplayItems", |
426 "current_display_list_size", (int)m_currentPaintArtifact.getDisplayItemL
ist().size(), | 436 "current_display_list_size", (int)m_currentPaintArtifact.getDisplayItemL
ist().size(), |
427 "num_non_cached_new_items", (int)m_newDisplayItemList.size() - m_numCach
edNewItems); | 437 "num_non_cached_new_items", (int)m_newDisplayItemList.size() - m_numCach
edNewItems); |
428 m_numCachedNewItems = 0; | 438 m_numCachedNewItems = 0; |
429 | 439 |
430 // These data structures are used during painting only. | 440 // These data structures are used during painting only. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } | 486 } |
477 | 487 |
478 // We'll allocate the initial buffer when we start the next paint. | 488 // We'll allocate the initial buffer when we start the next paint. |
479 m_newDisplayItemList = DisplayItemList(0); | 489 m_newDisplayItemList = DisplayItemList(0); |
480 | 490 |
481 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 491 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
482 CHECK(m_currentSubsequenceClients.isEmpty()); | 492 CHECK(m_currentSubsequenceClients.isEmpty()); |
483 DisplayItemClient::endShouldKeepAliveAllClients(this); | 493 DisplayItemClient::endShouldKeepAliveAllClients(this); |
484 #endif | 494 #endif |
485 | 495 |
486 #ifndef NDEBUG | 496 #if DCHECK_IS_ON() |
487 m_numSequentialMatches = 0; | 497 m_numSequentialMatches = 0; |
488 m_numOutOfOrderMatches = 0; | 498 m_numOutOfOrderMatches = 0; |
489 m_numIndexedItems = 0; | 499 m_numIndexedItems = 0; |
490 #endif | 500 #endif |
491 } | 501 } |
492 | 502 |
493 size_t PaintController::approximateUnsharedMemoryUsage() const | 503 size_t PaintController::approximateUnsharedMemoryUsage() const |
494 { | 504 { |
495 size_t memoryUsage = sizeof(*this); | 505 size_t memoryUsage = sizeof(*this); |
496 | 506 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 if (newChunkClients.add(&newItem.client()).isNewEntry) | 607 if (newChunkClients.add(&newItem.client()).isNewEntry) |
598 newChunk.rasterInvalidationRects.append(newItem.client().vis
ualRect()); | 608 newChunk.rasterInvalidationRects.append(newItem.client().vis
ualRect()); |
599 } else { | 609 } else { |
600 // The cached item was moved from the old chunk which should not
contain any item of the client now. | 610 // The cached item was moved from the old chunk which should not
contain any item of the client now. |
601 DCHECK(!oldChunkClients.contains(&newItem.client())); | 611 DCHECK(!oldChunkClients.contains(&newItem.client())); |
602 } | 612 } |
603 } | 613 } |
604 } | 614 } |
605 } | 615 } |
606 | 616 |
| 617 #if DCHECK_IS_ON() |
| 618 |
607 void PaintController::showUnderInvalidationError(const char* reason, const Displ
ayItem& newItem, const DisplayItem* oldItem) const | 619 void PaintController::showUnderInvalidationError(const char* reason, const Displ
ayItem& newItem, const DisplayItem* oldItem) const |
608 { | 620 { |
609 LOG(ERROR) << m_underInvalidationMessagePrefix << " " << reason; | 621 LOG(ERROR) << m_underInvalidationMessagePrefix << " " << reason; |
610 #ifndef NDEBUG | 622 #ifndef NDEBUG |
611 LOG(ERROR) << "New display item: " << newItem.asDebugString(); | 623 LOG(ERROR) << "New display item: " << newItem.asDebugString(); |
612 LOG(ERROR) << "Old display item: " << (oldItem ? oldItem->asDebugString() :
"None"); | 624 LOG(ERROR) << "Old display item: " << (oldItem ? oldItem->asDebugString() :
"None"); |
613 #else | 625 #else |
614 LOG(ERROR) << "Run debug build to get more details."; | 626 LOG(ERROR) << "Run debug build to get more details."; |
615 #endif | 627 #endif |
616 LOG(ERROR) << "See http://crbug.com/619103."; | 628 LOG(ERROR) << "See http://crbug.com/619103."; |
617 | 629 |
618 #ifndef NDEBUG | 630 #ifndef NDEBUG |
619 const SkPicture* newPicture = newItem.isDrawing() ? static_cast<const Drawin
gDisplayItem&>(newItem).picture() : nullptr; | 631 const SkPicture* newPicture = newItem.isDrawing() ? static_cast<const Drawin
gDisplayItem&>(newItem).picture() : nullptr; |
620 const SkPicture* oldPicture = oldItem && oldItem->isDrawing() ? static_cast<
const DrawingDisplayItem*>(oldItem)->picture() : nullptr; | 632 const SkPicture* oldPicture = oldItem && oldItem->isDrawing() ? static_cast<
const DrawingDisplayItem*>(oldItem)->picture() : nullptr; |
621 LOG(INFO) << "new picture:\n" << (newPicture ? pictureAsDebugString(newPictu
re) : "None"); | 633 LOG(INFO) << "new picture:\n" << (newPicture ? pictureAsDebugString(newPictu
re) : "None"); |
622 LOG(INFO) << "old picture:\n" << (oldPicture ? pictureAsDebugString(oldPictu
re) : "None"); | 634 LOG(INFO) << "old picture:\n" << (oldPicture ? pictureAsDebugString(oldPictu
re) : "None"); |
623 | 635 |
624 showDebugData(); | 636 showDebugData(); |
625 #endif // NDEBUG | 637 #endif // NDEBUG |
626 } | 638 } |
627 | 639 |
628 void PaintController::checkUnderInvalidation() | 640 void PaintController::checkUnderInvalidation() |
629 { | 641 { |
630 DCHECK(RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()); | 642 DCHECK(RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled
()); |
631 | 643 |
632 if (!isCheckingUnderInvalidation()) | 644 if (!isCheckingUnderInvalidation()) |
633 return; | 645 return; |
634 | 646 |
635 const DisplayItem& newItem = m_newDisplayItemList.last(); | 647 const DisplayItem& newItem = m_newDisplayItemList.last(); |
636 size_t oldItemIndex = m_underInvalidationCheckingBegin + m_skippedProbableUn
derInvalidationCount; | 648 size_t oldItemIndex = m_underInvalidationCheckingBegin + m_skippedProbableUn
derInvalidationCount; |
637 DisplayItem* oldItem = oldItemIndex < m_currentPaintArtifact.getDisplayItemL
ist().size() ? &m_currentPaintArtifact.getDisplayItemList()[oldItemIndex] : null
ptr; | 649 DisplayItem* oldItem = oldItemIndex < m_currentPaintArtifact.getDisplayItemL
ist().size() ? &m_currentPaintArtifact.getDisplayItemList()[oldItemIndex] : null
ptr; |
638 | 650 |
639 bool oldAndNewEqual = oldItem && newItem.equals(*oldItem); | 651 bool oldAndNewEqual = oldItem && newItem.equals(*oldItem); |
640 if (!oldAndNewEqual) { | 652 if (!oldAndNewEqual) { |
(...skipping 11 matching lines...) Expand all Loading... |
652 return; | 664 return; |
653 } | 665 } |
654 } | 666 } |
655 } | 667 } |
656 | 668 |
657 if (m_skippedProbableUnderInvalidationCount || !oldAndNewEqual) { | 669 if (m_skippedProbableUnderInvalidationCount || !oldAndNewEqual) { |
658 // If we ever skipped reporting any under-invalidations, report the earl
iest one. | 670 // If we ever skipped reporting any under-invalidations, report the earl
iest one. |
659 showUnderInvalidationError("under-invalidation: display item changed", | 671 showUnderInvalidationError("under-invalidation: display item changed", |
660 m_newDisplayItemList[m_newDisplayItemList.size() - m_skippedProbable
UnderInvalidationCount - 1], | 672 m_newDisplayItemList[m_newDisplayItemList.size() - m_skippedProbable
UnderInvalidationCount - 1], |
661 &m_currentPaintArtifact.getDisplayItemList()[m_underInvalidationChec
kingBegin]); | 673 &m_currentPaintArtifact.getDisplayItemList()[m_underInvalidationChec
kingBegin]); |
662 CHECK(false); | 674 NOTREACHED(); |
663 } | 675 } |
664 | 676 |
665 // Discard the forced repainted display item and move the cached item into m
_newDisplayItemList. | 677 // Discard the forced repainted display item and move the cached item into m
_newDisplayItemList. |
666 // This is to align with the non-under-invalidation-checking path to empty t
he original cached slot, | 678 // This is to align with the non-under-invalidation-checking path to empty t
he original cached slot, |
667 // leaving only disappeared or invalidated display items in the old list aft
er painting. | 679 // leaving only disappeared or invalidated display items in the old list aft
er painting. |
668 m_newDisplayItemList.removeLast(); | 680 m_newDisplayItemList.removeLast(); |
669 m_newDisplayItemList.appendByMoving(*oldItem); | 681 m_newDisplayItemList.appendByMoving(*oldItem); |
670 | 682 |
671 ++m_underInvalidationCheckingBegin; | 683 ++m_underInvalidationCheckingBegin; |
672 } | 684 } |
673 | 685 |
| 686 #endif // DCHECK_IS_ON() |
| 687 |
674 String PaintController::displayItemListAsDebugString(const DisplayItemList& list
) const | 688 String PaintController::displayItemListAsDebugString(const DisplayItemList& list
) const |
675 { | 689 { |
676 StringBuilder stringBuilder; | 690 StringBuilder stringBuilder; |
677 size_t i = 0; | 691 size_t i = 0; |
678 for (auto it = list.begin(); it != list.end(); ++it, ++i) { | 692 for (auto it = list.begin(); it != list.end(); ++it, ++i) { |
679 const DisplayItem& displayItem = *it; | 693 const DisplayItem& displayItem = *it; |
680 if (i) | 694 if (i) |
681 stringBuilder.append(",\n"); | 695 stringBuilder.append(",\n"); |
682 stringBuilder.append(String::format("{index: %d, ", (int)i)); | 696 stringBuilder.append(String::format("{index: %d, ", (int)i)); |
683 #ifndef NDEBUG | 697 #ifndef NDEBUG |
(...skipping 24 matching lines...) Expand all Loading... |
708 return stringBuilder.toString(); | 722 return stringBuilder.toString(); |
709 } | 723 } |
710 | 724 |
711 void PaintController::showDebugData() const | 725 void PaintController::showDebugData() const |
712 { | 726 { |
713 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri
ng(m_currentPaintArtifact.getDisplayItemList()).utf8().data()); | 727 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri
ng(m_currentPaintArtifact.getDisplayItemList()).utf8().data()); |
714 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m
_newDisplayItemList).utf8().data()); | 728 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m
_newDisplayItemList).utf8().data()); |
715 } | 729 } |
716 | 730 |
717 } // namespace blink | 731 } // namespace blink |
OLD | NEW |