| 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/TraceEvent.h" | 9 #include "platform/TraceEvent.h" |
| 10 #include "platform/graphics/paint/DrawingDisplayItem.h" | 10 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 void DisplayItemList::copyCachedSubsequence(DisplayItems::iterator& currentIt, D
isplayItems& updatedList) | 275 void DisplayItemList::copyCachedSubsequence(DisplayItems::iterator& currentIt, D
isplayItems& updatedList) |
| 276 { | 276 { |
| 277 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 277 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
| 278 ASSERT(currentIt->type() == DisplayItem::BeginSubsequence); | 278 ASSERT(currentIt->type() == DisplayItem::BeginSubsequence); |
| 279 ASSERT(!currentIt->scope()); | 279 ASSERT(!currentIt->scope()); |
| 280 DisplayItem::Id endSubsequenceId(currentIt->client(), DisplayItem::EndSubseq
uence, 0); | 280 DisplayItem::Id endSubsequenceId(currentIt->client(), DisplayItem::EndSubseq
uence, 0); |
| 281 do { | 281 do { |
| 282 // We should always find the EndSubsequence display item. | 282 // We should always find the EndSubsequence display item. |
| 283 ASSERT(currentIt != m_currentDisplayItems.end()); | 283 ASSERT(currentIt != m_currentDisplayItems.end()); |
| 284 updatedList.appendByMoving(*currentIt, currentIt->derivedSize()); | 284 updatedList.appendByMoving(*currentIt); |
| 285 ++currentIt; | 285 ++currentIt; |
| 286 } while (!endSubsequenceId.matches(updatedList.last())); | 286 } while (!endSubsequenceId.matches(updatedList.last())); |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Update the existing display items by removing invalidated entries, updating | 289 // Update the existing display items by removing invalidated entries, updating |
| 290 // repainted ones, and appending new items. | 290 // repainted ones, and appending new items. |
| 291 // - For CachedDisplayItem, copy the corresponding cached DrawingDisplayItem; | 291 // - For CachedDisplayItem, copy the corresponding cached DrawingDisplayItem; |
| 292 // - For SubsequenceCachedDisplayItem, copy the cached display items between the | 292 // - For SubsequenceCachedDisplayItem, copy the cached display items between the |
| 293 // corresponding BeginSubsequenceDisplayItem and EndSubsequenceDisplayItem (in
cl.); | 293 // corresponding BeginSubsequenceDisplayItem and EndSubsequenceDisplayItem (in
cl.); |
| 294 // - Otherwise, copy the new display item. | 294 // - Otherwise, copy the new display item. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // Under-invalidation checking requires a full index of m_currentDisplay
Items. | 339 // Under-invalidation checking requires a full index of m_currentDisplay
Items. |
| 340 size_t i = 0; | 340 size_t i = 0; |
| 341 for (const auto& item : m_currentDisplayItems) { | 341 for (const auto& item : m_currentDisplayItems) { |
| 342 addItemToIndexIfNeeded(item, i, outOfOrderIndexContext.displayItemIn
dicesByClient); | 342 addItemToIndexIfNeeded(item, i, outOfOrderIndexContext.displayItemIn
dicesByClient); |
| 343 ++i; | 343 ++i; |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 #endif // ENABLE(ASSERT) | 346 #endif // ENABLE(ASSERT) |
| 347 | 347 |
| 348 // TODO(jbroman): Consider revisiting this heuristic. | 348 // TODO(jbroman): Consider revisiting this heuristic. |
| 349 DisplayItems updatedList( | 349 DisplayItems updatedList(std::max(m_currentDisplayItems.usedCapacityInBytes(
), m_newDisplayItems.usedCapacityInBytes())); |
| 350 kMaximumDisplayItemSize, | |
| 351 std::max(m_currentDisplayItems.usedCapacityInBytes(), m_newDisplayItems.
usedCapacityInBytes())); | |
| 352 DisplayItems::iterator currentIt = m_currentDisplayItems.begin(); | 350 DisplayItems::iterator currentIt = m_currentDisplayItems.begin(); |
| 353 DisplayItems::iterator currentEnd = m_currentDisplayItems.end(); | 351 DisplayItems::iterator currentEnd = m_currentDisplayItems.end(); |
| 354 for (DisplayItems::iterator newIt = m_newDisplayItems.begin(); newIt != m_ne
wDisplayItems.end(); ++newIt) { | 352 for (DisplayItems::iterator newIt = m_newDisplayItems.begin(); newIt != m_ne
wDisplayItems.end(); ++newIt) { |
| 355 const DisplayItem& newDisplayItem = *newIt; | 353 const DisplayItem& newDisplayItem = *newIt; |
| 356 const DisplayItem::Id newDisplayItemId = newDisplayItem.nonCachedId(); | 354 const DisplayItem::Id newDisplayItemId = newDisplayItem.nonCachedId(); |
| 357 bool newDisplayItemHasCachedType = newDisplayItem.type() != newDisplayIt
emId.type; | 355 bool newDisplayItemHasCachedType = newDisplayItem.type() != newDisplayIt
emId.type; |
| 358 | 356 |
| 359 bool isSynchronized = currentIt != currentEnd && newDisplayItemId.matche
s(*currentIt); | 357 bool isSynchronized = currentIt != currentEnd && newDisplayItemId.matche
s(*currentIt); |
| 360 | 358 |
| 361 if (newDisplayItemHasCachedType) { | 359 if (newDisplayItemHasCachedType) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 372 #endif | 370 #endif |
| 373 ASSERT_NOT_REACHED(); | 371 ASSERT_NOT_REACHED(); |
| 374 // We did not find the cached display item. This should be i
mpossible, but may occur if there is a bug | 372 // We did not find the cached display item. This should be i
mpossible, but may occur if there is a bug |
| 375 // in the system, such as under-invalidation, incorrect cach
e checking or duplicate display ids. | 373 // in the system, such as under-invalidation, incorrect cach
e checking or duplicate display ids. |
| 376 // In this case, attempt to recover rather than crashing or
bailing on display of the rest of the display list. | 374 // In this case, attempt to recover rather than crashing or
bailing on display of the rest of the display list. |
| 377 continue; | 375 continue; |
| 378 } | 376 } |
| 379 } | 377 } |
| 380 | 378 |
| 381 if (newDisplayItem.isCachedDrawing()) { | 379 if (newDisplayItem.isCachedDrawing()) { |
| 382 updatedList.appendByMoving(*currentIt, currentIt->derivedSize())
; | 380 updatedList.appendByMoving(*currentIt); |
| 383 ++currentIt; | 381 ++currentIt; |
| 384 } else { | 382 } else { |
| 385 ASSERT(newDisplayItem.type() == DisplayItem::CachedSubsequence); | 383 ASSERT(newDisplayItem.type() == DisplayItem::CachedSubsequence); |
| 386 copyCachedSubsequence(currentIt, updatedList); | 384 copyCachedSubsequence(currentIt, updatedList); |
| 387 ASSERT(updatedList.last().type() == DisplayItem::EndSubsequence)
; | 385 ASSERT(updatedList.last().type() == DisplayItem::EndSubsequence)
; |
| 388 } | 386 } |
| 389 } else { | 387 } else { |
| 390 #if ENABLE(ASSERT) | 388 #if ENABLE(ASSERT) |
| 391 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEn
abled()) { | 389 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEn
abled()) { |
| 392 checkCachedDisplayItemIsUnchanged(newDisplayItem, outOfOrderInde
xContext.displayItemIndicesByClient); | 390 checkCachedDisplayItemIsUnchanged(newDisplayItem, outOfOrderInde
xContext.displayItemIndicesByClient); |
| 393 } else { | 391 } else { |
| 394 ASSERT(!newDisplayItem.isDrawing() | 392 ASSERT(!newDisplayItem.isDrawing() |
| 395 || newDisplayItem.skippedCache() | 393 || newDisplayItem.skippedCache() |
| 396 || !clientCacheIsValid(newDisplayItem.client()) | 394 || !clientCacheIsValid(newDisplayItem.client()) |
| 397 || (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && pain
tOffsetWasInvalidated(newDisplayItem.client()))); | 395 || (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && pain
tOffsetWasInvalidated(newDisplayItem.client()))); |
| 398 } | 396 } |
| 399 #endif | 397 #endif |
| 400 updatedList.appendByMoving(*newIt, newIt->derivedSize()); | 398 updatedList.appendByMoving(*newIt); |
| 401 | 399 |
| 402 if (isSynchronized) | 400 if (isSynchronized) |
| 403 ++currentIt; | 401 ++currentIt; |
| 404 } | 402 } |
| 405 // Items before currentIt should have been copied so we don't need to in
dex them. | 403 // Items before currentIt should have been copied so we don't need to in
dex them. |
| 406 if (currentIt - outOfOrderIndexContext.nextItemToIndex > 0) | 404 if (currentIt - outOfOrderIndexContext.nextItemToIndex > 0) |
| 407 outOfOrderIndexContext.nextItemToIndex = currentIt; | 405 outOfOrderIndexContext.nextItemToIndex = currentIt; |
| 408 } | 406 } |
| 409 | 407 |
| 410 #if ENABLE(ASSERT) | 408 #if ENABLE(ASSERT) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 #ifndef NDEBUG | 592 #ifndef NDEBUG |
| 595 | 593 |
| 596 WTF::String DisplayItemList::displayItemsAsDebugString(const DisplayItems& list)
const | 594 WTF::String DisplayItemList::displayItemsAsDebugString(const DisplayItems& list)
const |
| 597 { | 595 { |
| 598 StringBuilder stringBuilder; | 596 StringBuilder stringBuilder; |
| 599 size_t i = 0; | 597 size_t i = 0; |
| 600 for (auto it = list.begin(); it != list.end(); ++it, ++i) { | 598 for (auto it = list.begin(); it != list.end(); ++it, ++i) { |
| 601 const DisplayItem& displayItem = *it; | 599 const DisplayItem& displayItem = *it; |
| 602 if (i) | 600 if (i) |
| 603 stringBuilder.append(",\n"); | 601 stringBuilder.append(",\n"); |
| 604 if (!displayItem.isValid()) { | |
| 605 stringBuilder.append("null"); | |
| 606 continue; | |
| 607 } | |
| 608 stringBuilder.append(String::format("{index: %d, ", (int)i)); | 602 stringBuilder.append(String::format("{index: %d, ", (int)i)); |
| 609 displayItem.dumpPropertiesAsDebugString(stringBuilder); | 603 displayItem.dumpPropertiesAsDebugString(stringBuilder); |
| 610 stringBuilder.append(", cacheIsValid: "); | 604 if (displayItem.isValid()) { |
| 611 stringBuilder.append(clientCacheIsValid(displayItem.client()) ? "true" :
"false"); | 605 stringBuilder.append(", cacheIsValid: "); |
| 606 stringBuilder.append(clientCacheIsValid(displayItem.client()) ? "tru
e" : "false"); |
| 607 } |
| 612 stringBuilder.append('}'); | 608 stringBuilder.append('}'); |
| 613 } | 609 } |
| 614 return stringBuilder.toString(); | 610 return stringBuilder.toString(); |
| 615 } | 611 } |
| 616 | 612 |
| 617 void DisplayItemList::showDebugData() const | 613 void DisplayItemList::showDebugData() const |
| 618 { | 614 { |
| 619 WTFLogAlways("current display items: [%s]\n", displayItemsAsDebugString(m_cu
rrentDisplayItems).utf8().data()); | 615 WTFLogAlways("current display items: [%s]\n", displayItemsAsDebugString(m_cu
rrentDisplayItems).utf8().data()); |
| 620 WTFLogAlways("new display items: [%s]\n", displayItemsAsDebugString(m_newDis
playItems).utf8().data()); | 616 WTFLogAlways("new display items: [%s]\n", displayItemsAsDebugString(m_newDis
playItems).utf8().data()); |
| 621 } | 617 } |
| 622 | 618 |
| 623 #endif // ifndef NDEBUG | 619 #endif // ifndef NDEBUG |
| 624 | 620 |
| 625 void DisplayItemList::replay(GraphicsContext& context) | 621 void DisplayItemList::replay(GraphicsContext& context) |
| 626 { | 622 { |
| 627 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); | 623 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); |
| 628 ASSERT(m_newDisplayItems.isEmpty()); | 624 ASSERT(m_newDisplayItems.isEmpty()); |
| 629 for (DisplayItem& displayItem : m_currentDisplayItems) | 625 for (DisplayItem& displayItem : m_currentDisplayItems) |
| 630 displayItem.replay(context); | 626 displayItem.replay(context); |
| 631 } | 627 } |
| 632 | 628 |
| 633 } // namespace blink | 629 } // namespace blink |
| OLD | NEW |