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 "config.h" | 5 #include "config.h" |
6 #include "platform/graphics/paint/DisplayItemList.h" | 6 #include "platform/graphics/paint/DisplayItemList.h" |
7 | 7 |
8 #include "platform/NotImplemented.h" | 8 #include "platform/NotImplemented.h" |
9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
10 #include "platform/TraceEvent.h" | 10 #include "platform/TraceEvent.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 OutOfOrderIndexContext(DisplayItems::iterator begin) : nextItemToIndex(begin
) { } | 171 OutOfOrderIndexContext(DisplayItems::iterator begin) : nextItemToIndex(begin
) { } |
172 | 172 |
173 DisplayItems::iterator nextItemToIndex; | 173 DisplayItems::iterator nextItemToIndex; |
174 DisplayItemIndicesByClientMap displayItemIndicesByClient; | 174 DisplayItemIndicesByClientMap displayItemIndicesByClient; |
175 }; | 175 }; |
176 | 176 |
177 DisplayItems::iterator DisplayItemList::findOutOfOrderCachedItem(DisplayItems::i
terator currentIt, const DisplayItem::Id& id, OutOfOrderIndexContext& context) | 177 DisplayItems::iterator DisplayItemList::findOutOfOrderCachedItem(DisplayItems::i
terator currentIt, const DisplayItem::Id& id, OutOfOrderIndexContext& context) |
178 { | 178 { |
179 ASSERT(clientCacheIsValid(id.client)); | 179 ASSERT(clientCacheIsValid(id.client)); |
180 | 180 |
181 // Skip indexing of copied items. | |
182 if (currentIt - context.nextItemToIndex > 0) | |
183 context.nextItemToIndex = currentIt; | |
184 | |
185 size_t foundIndex = findMatchingItemFromIndex(id, context.displayItemIndices
ByClient, m_currentDisplayItems); | 181 size_t foundIndex = findMatchingItemFromIndex(id, context.displayItemIndices
ByClient, m_currentDisplayItems); |
186 if (foundIndex != kNotFound) | 182 if (foundIndex != kNotFound) |
187 return m_currentDisplayItems.begin() + foundIndex; | 183 return m_currentDisplayItems.begin() + foundIndex; |
188 | 184 |
189 return findOutOfOrderCachedItemForward(id, context); | 185 return findOutOfOrderCachedItemForward(currentIt, id, context); |
190 } | 186 } |
191 | 187 |
192 // Find forward for the item and index all skipped indexable items. | 188 // Find forward for the item and index all skipped indexable items. |
193 DisplayItems::iterator DisplayItemList::findOutOfOrderCachedItemForward(const Di
splayItem::Id& id, OutOfOrderIndexContext& context) | 189 DisplayItems::iterator DisplayItemList::findOutOfOrderCachedItemForward(DisplayI
tems::iterator currentIt, const DisplayItem::Id& id, OutOfOrderIndexContext& con
text) |
194 { | 190 { |
| 191 // Items before currentIt should have been copied. Skip indexing of them. |
| 192 if (currentIt - context.nextItemToIndex > 0) |
| 193 context.nextItemToIndex = currentIt; |
| 194 |
195 DisplayItems::iterator currentEnd = m_currentDisplayItems.end(); | 195 DisplayItems::iterator currentEnd = m_currentDisplayItems.end(); |
196 for (; context.nextItemToIndex != currentEnd; ++context.nextItemToIndex) { | 196 for (; context.nextItemToIndex != currentEnd; ++context.nextItemToIndex) { |
197 const DisplayItem& item = *context.nextItemToIndex; | 197 const DisplayItem& item = *context.nextItemToIndex; |
198 ASSERT(item.isValid()); | 198 ASSERT(item.isValid()); |
199 if (item.isCacheable() && clientCacheIsValid(item.client())) { | 199 if (item.isCacheable() && clientCacheIsValid(item.client())) { |
200 if (id.matches(item)) | 200 if (id.matches(item)) |
201 return context.nextItemToIndex++; | 201 return context.nextItemToIndex++; |
202 | 202 |
203 addItemToIndexIfNeeded(item, context.nextItemToIndex - m_currentDisp
layItems.begin(), context.displayItemIndicesByClient); | 203 addItemToIndexIfNeeded(item, context.nextItemToIndex - m_currentDisp
layItems.begin(), context.displayItemIndicesByClient); |
204 } | 204 } |
205 } | 205 } |
206 return currentEnd; | 206 return currentEnd; |
207 } | 207 } |
208 | 208 |
209 void DisplayItemList::copyCachedSubtree(DisplayItems::iterator& currentIt, Displ
ayItems& updatedList) | 209 void DisplayItemList::copyCachedSubtree(DisplayItems::iterator& currentIt, Displ
ayItems& updatedList) |
210 { | 210 { |
211 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 211 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
212 ASSERT(currentIt->isBeginSubtree()); | 212 ASSERT(currentIt->type() == DisplayItem::BeginSubtree); |
213 ASSERT(!currentIt->scope()); | 213 ASSERT(!currentIt->scope()); |
214 DisplayItem::Id endSubtreeId(currentIt->client(), DisplayItem::beginSubtreeT
ypeToEndSubtreeType(currentIt->type()), 0); | 214 DisplayItem::Id endSubtreeId(currentIt->client(), DisplayItem::EndSubtree, 0
); |
215 do { | 215 do { |
216 // We should always find the EndSubtree display item. | 216 // We should always find the EndSubtree display item. |
217 ASSERT(currentIt != m_currentDisplayItems.end()); | 217 ASSERT(currentIt != m_currentDisplayItems.end()); |
218 updatedList.appendByMoving(*currentIt, currentIt->derivedSize()); | 218 updatedList.appendByMoving(*currentIt, currentIt->derivedSize()); |
219 ++currentIt; | 219 ++currentIt; |
220 } while (!endSubtreeId.matches(updatedList.last())); | 220 } while (!endSubtreeId.matches(updatedList.last())); |
221 } | 221 } |
222 | 222 |
223 // Update the existing display items by removing invalidated entries, updating | 223 // Update the existing display items by removing invalidated entries, updating |
224 // repainted ones, and appending new items. | 224 // repainted ones, and appending new items. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 const DisplayItem::Id newDisplayItemId = newDisplayItem.nonCachedId(); | 288 const DisplayItem::Id newDisplayItemId = newDisplayItem.nonCachedId(); |
289 bool newDisplayItemHasCachedType = newDisplayItem.type() != newDisplayIt
emId.type; | 289 bool newDisplayItemHasCachedType = newDisplayItem.type() != newDisplayIt
emId.type; |
290 | 290 |
291 bool isSynchronized = currentIt != currentEnd && newDisplayItemId.matche
s(*currentIt); | 291 bool isSynchronized = currentIt != currentEnd && newDisplayItemId.matche
s(*currentIt); |
292 | 292 |
293 if (newDisplayItemHasCachedType) { | 293 if (newDisplayItemHasCachedType) { |
294 ASSERT(!RuntimeEnabledFeatures::slimmingPaintUnderInvalidationChecki
ngEnabled()); | 294 ASSERT(!RuntimeEnabledFeatures::slimmingPaintUnderInvalidationChecki
ngEnabled()); |
295 ASSERT(newDisplayItem.isCached()); | 295 ASSERT(newDisplayItem.isCached()); |
296 ASSERT(clientCacheIsValid(newDisplayItem.client())); | 296 ASSERT(clientCacheIsValid(newDisplayItem.client())); |
297 if (!isSynchronized) { | 297 if (!isSynchronized) { |
298 DisplayItems::iterator foundIt = findOutOfOrderCachedItem(curren
tIt, newDisplayItemId, outOfOrderIndexContext); | 298 currentIt = findOutOfOrderCachedItem(currentIt, newDisplayItemId
, outOfOrderIndexContext); |
299 | 299 |
300 if (foundIt == currentEnd) { | 300 if (currentIt == currentEnd) { |
301 #ifndef NDEBUG | 301 #ifndef NDEBUG |
302 showDebugData(); | 302 showDebugData(); |
303 WTFLogAlways("%s not found in m_currentDisplayItems\n", newD
isplayItem.asDebugString().utf8().data()); | 303 WTFLogAlways("%s not found in m_currentDisplayItems\n", newD
isplayItem.asDebugString().utf8().data()); |
304 #endif | 304 #endif |
305 ASSERT_NOT_REACHED(); | 305 ASSERT_NOT_REACHED(); |
306 | 306 // We did not find the cached display item. This should be i
mpossible, but may occur if there is a bug |
307 // If foundIt == currentEnd, it means that we did not find t
he cached display item. This should be impossible, but may occur | 307 // in the system, such as under-invalidation, incorrect cach
e checking or duplicate display ids. |
308 // if there is a bug in the system, such as under-invalidati
on, incorrect cache checking or duplicate display ids. In this case, | 308 // In this case, attempt to recover rather than crashing or
bailing on display of the rest of the display list. |
309 // attempt to recover rather than crashing or bailing on dis
play of the rest of the display list. | |
310 continue; | 309 continue; |
311 } | 310 } |
312 | |
313 ASSERT(foundIt != currentIt); // because we are in 'if (!isSynch
ronized)' | |
314 currentIt = foundIt; | |
315 } | 311 } |
316 | 312 |
317 if (newDisplayItem.isCachedDrawing()) { | 313 if (newDisplayItem.isCachedDrawing()) { |
318 updatedList.appendByMoving(*currentIt, currentIt->derivedSize())
; | 314 updatedList.appendByMoving(*currentIt, currentIt->derivedSize())
; |
319 ++currentIt; | 315 ++currentIt; |
320 } else { | 316 } else { |
321 ASSERT(newDisplayItem.isCachedSubtree()); | 317 ASSERT(newDisplayItem.type() == DisplayItem::CachedSubtree); |
322 copyCachedSubtree(currentIt, updatedList); | 318 copyCachedSubtree(currentIt, updatedList); |
323 ASSERT(updatedList.last().isEndSubtree()); | 319 ASSERT(updatedList.last().type() == DisplayItem::EndSubtree); |
324 } | 320 } |
325 } else { | 321 } else { |
326 #if ENABLE(ASSERT) | 322 #if ENABLE(ASSERT) |
327 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEn
abled()) | 323 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEn
abled()) |
328 checkCachedDisplayItemIsUnchanged(newDisplayItem, outOfOrderInde
xContext.displayItemIndicesByClient); | 324 checkCachedDisplayItemIsUnchanged(newDisplayItem, outOfOrderInde
xContext.displayItemIndicesByClient); |
329 else | 325 else |
330 ASSERT(!newDisplayItem.isDrawing() || newDisplayItem.skippedCach
e() || !clientCacheIsValid(newDisplayItem.client())); | 326 ASSERT(!newDisplayItem.isDrawing() || newDisplayItem.skippedCach
e() || !clientCacheIsValid(newDisplayItem.client())); |
331 #endif // ENABLE(ASSERT) | 327 #endif // ENABLE(ASSERT) |
332 updatedList.appendByMoving(*newIt, newIt->derivedSize()); | 328 updatedList.appendByMoving(*newIt, newIt->derivedSize()); |
333 | 329 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 541 |
546 void DisplayItemList::replay(GraphicsContext& context) | 542 void DisplayItemList::replay(GraphicsContext& context) |
547 { | 543 { |
548 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); | 544 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); |
549 ASSERT(m_newDisplayItems.isEmpty()); | 545 ASSERT(m_newDisplayItems.isEmpty()); |
550 for (DisplayItem& displayItem : m_currentDisplayItems) | 546 for (DisplayItem& displayItem : m_currentDisplayItems) |
551 displayItem.replay(context); | 547 displayItem.replay(context); |
552 } | 548 } |
553 | 549 |
554 } // namespace blink | 550 } // namespace blink |
OLD | NEW |