| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 bool DisplayItemList::clientCacheIsValid(DisplayItemClient client) const | 130 bool DisplayItemList::clientCacheIsValid(DisplayItemClient client) const |
| 131 { | 131 { |
| 132 if (skippingCache()) | 132 if (skippingCache()) |
| 133 return false; | 133 return false; |
| 134 updateValidlyCachedClientsIfNeeded(); | 134 updateValidlyCachedClientsIfNeeded(); |
| 135 return m_validlyCachedClients.contains(client); | 135 return m_validlyCachedClients.contains(client); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void DisplayItemList::invalidatePaintOffset(const DisplayItemClientWrapper& clie
nt) | 138 void DisplayItemList::invalidatePaintOffset(const DisplayItemClientWrapper& clie
nt) |
| 139 { | 139 { |
| 140 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 140 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); |
| 141 | 141 |
| 142 updateValidlyCachedClientsIfNeeded(); | 142 updateValidlyCachedClientsIfNeeded(); |
| 143 m_validlyCachedClients.remove(client.displayItemClient()); | 143 m_validlyCachedClients.remove(client.displayItemClient()); |
| 144 | 144 |
| 145 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && m_trackedPaintInvali
dationObjects) | 145 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && m_trackedPaintInvali
dationObjects) |
| 146 m_trackedPaintInvalidationObjects->append(client.debugName()); | 146 m_trackedPaintInvalidationObjects->append(client.debugName()); |
| 147 | 147 |
| 148 #if ENABLE(ASSERT) | 148 #if ENABLE(ASSERT) |
| 149 m_clientsWithPaintOffsetInvalidations.add(client.displayItemClient()); | 149 m_clientsWithPaintOffsetInvalidations.add(client.displayItemClient()); |
| 150 | 150 |
| 151 // Ensure no phases slipped in using the old paint offset which would indica
te | 151 // Ensure no phases slipped in using the old paint offset which would indica
te |
| 152 // different phases used different paint offsets, which should not happen. | 152 // different phases used different paint offsets, which should not happen. |
| 153 for (const auto& item : m_newDisplayItems) | 153 for (const auto& item : m_newDisplayItems) |
| 154 ASSERT(!item.isCached() || item.client() != client.displayItemClient()); | 154 ASSERT(!item.isCached() || item.client() != client.displayItemClient()); |
| 155 #endif | 155 #endif |
| 156 } | 156 } |
| 157 | 157 |
| 158 #if ENABLE(ASSERT) | 158 #if ENABLE(ASSERT) |
| 159 bool DisplayItemList::paintOffsetWasInvalidated(DisplayItemClient client) const | 159 bool DisplayItemList::paintOffsetWasInvalidated(DisplayItemClient client) const |
| 160 { | 160 { |
| 161 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 161 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); |
| 162 return m_clientsWithPaintOffsetInvalidations.contains(client); | 162 return m_clientsWithPaintOffsetInvalidations.contains(client); |
| 163 } | 163 } |
| 164 #endif | 164 #endif |
| 165 | 165 |
| 166 void DisplayItemList::recordPaintOffset(DisplayItemClient client, const LayoutPo
int& paintOffset) | 166 void DisplayItemList::recordPaintOffset(DisplayItemClient client, const LayoutPo
int& paintOffset) |
| 167 { | 167 { |
| 168 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 168 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); |
| 169 m_previousPaintOffsets.set(client, paintOffset); | 169 m_previousPaintOffsets.set(client, paintOffset); |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool DisplayItemList::paintOffsetIsUnchanged(DisplayItemClient client, const Lay
outPoint& paintOffset) const | 172 bool DisplayItemList::paintOffsetIsUnchanged(DisplayItemClient client, const Lay
outPoint& paintOffset) const |
| 173 { | 173 { |
| 174 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 174 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); |
| 175 PreviousPaintOffsets::const_iterator it = m_previousPaintOffsets.find(client
); | 175 PreviousPaintOffsets::const_iterator it = m_previousPaintOffsets.find(client
); |
| 176 if (it == m_previousPaintOffsets.end()) | 176 if (it == m_previousPaintOffsets.end()) |
| 177 return false; | 177 return false; |
| 178 return paintOffset == it->value; | 178 return paintOffset == it->value; |
| 179 } | 179 } |
| 180 | 180 |
| 181 void DisplayItemList::removeUnneededPaintOffsetEntries() | 181 void DisplayItemList::removeUnneededPaintOffsetEntries() |
| 182 { | 182 { |
| 183 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 183 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); |
| 184 | 184 |
| 185 // This function is only needed temporarily while paint offsets are stored | 185 // This function is only needed temporarily while paint offsets are stored |
| 186 // in a map on the list itself. Because we don't always get notified when | 186 // in a map on the list itself. Because we don't always get notified when |
| 187 // a display item client is removed, we need to infer it to prevent the | 187 // a display item client is removed, we need to infer it to prevent the |
| 188 // paint offset map from growing indefinitely. This is achieved by just | 188 // paint offset map from growing indefinitely. This is achieved by just |
| 189 // removing any paint offset clients that are no longer in the full list. | 189 // removing any paint offset clients that are no longer in the full list. |
| 190 | 190 |
| 191 HashSet<DisplayItemClient> paintOffsetClientsToRemove; | 191 HashSet<DisplayItemClient> paintOffsetClientsToRemove; |
| 192 for (auto& client : m_previousPaintOffsets.keys()) | 192 for (auto& client : m_previousPaintOffsets.keys()) |
| 193 paintOffsetClientsToRemove.add(client); | 193 paintOffsetClientsToRemove.add(client); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 #endif | 302 #endif |
| 303 | 303 |
| 304 if (m_currentDisplayItems.isEmpty()) { | 304 if (m_currentDisplayItems.isEmpty()) { |
| 305 #if ENABLE(ASSERT) | 305 #if ENABLE(ASSERT) |
| 306 for (const auto& item : m_newDisplayItems) | 306 for (const auto& item : m_newDisplayItems) |
| 307 ASSERT(!item.isCached()); | 307 ASSERT(!item.isCached()); |
| 308 #endif | 308 #endif |
| 309 m_currentDisplayItems.swap(m_newDisplayItems); | 309 m_currentDisplayItems.swap(m_newDisplayItems); |
| 310 m_validlyCachedClientsDirty = true; | 310 m_validlyCachedClientsDirty = true; |
| 311 m_numCachedItems = 0; | 311 m_numCachedItems = 0; |
| 312 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 312 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()) |
| 313 removeUnneededPaintOffsetEntries(); | 313 removeUnneededPaintOffsetEntries(); |
| 314 return; | 314 return; |
| 315 } | 315 } |
| 316 | 316 |
| 317 updateValidlyCachedClientsIfNeeded(); | 317 updateValidlyCachedClientsIfNeeded(); |
| 318 | 318 |
| 319 // Stores indices to valid DrawingDisplayItems in m_currentDisplayItems that
have not been matched | 319 // Stores indices to valid DrawingDisplayItems in m_currentDisplayItems that
have not been matched |
| 320 // by CachedDisplayItems during synchronized matching. The indexed items wil
l be matched | 320 // by CachedDisplayItems during synchronized matching. The indexed items wil
l be matched |
| 321 // by later out-of-order CachedDisplayItems in m_newDisplayItems. This ensur
es that when | 321 // by later out-of-order CachedDisplayItems in m_newDisplayItems. This ensur
es that when |
| 322 // out-of-order CachedDisplayItems occur, we only traverse at most once over
m_currentDisplayItems | 322 // out-of-order CachedDisplayItems occur, we only traverse at most once over
m_currentDisplayItems |
| 323 // looking for potential matches. Thus we can ensure that the algorithm runs
in linear time. | 323 // looking for potential matches. Thus we can ensure that the algorithm runs
in linear time. |
| 324 OutOfOrderIndexContext outOfOrderIndexContext(m_currentDisplayItems.begin())
; | 324 OutOfOrderIndexContext outOfOrderIndexContext(m_currentDisplayItems.begin())
; |
| 325 | 325 |
| 326 // TODO(jbroman): Consider revisiting this heuristic. | 326 // TODO(jbroman): Consider revisiting this heuristic. |
| 327 DisplayItems updatedList(std::max(m_currentDisplayItems.usedCapacityInBytes(
), m_newDisplayItems.usedCapacityInBytes())); | 327 DisplayItems updatedList(std::max(m_currentDisplayItems.usedCapacityInBytes(
), m_newDisplayItems.usedCapacityInBytes())); |
| 328 DisplayItems::iterator currentIt = m_currentDisplayItems.begin(); | 328 DisplayItems::iterator currentIt = m_currentDisplayItems.begin(); |
| 329 DisplayItems::iterator currentEnd = m_currentDisplayItems.end(); | 329 DisplayItems::iterator currentEnd = m_currentDisplayItems.end(); |
| 330 for (DisplayItems::iterator newIt = m_newDisplayItems.begin(); newIt != m_ne
wDisplayItems.end(); ++newIt) { | 330 for (DisplayItems::iterator newIt = m_newDisplayItems.begin(); newIt != m_ne
wDisplayItems.end(); ++newIt) { |
| 331 const DisplayItem& newDisplayItem = *newIt; | 331 const DisplayItem& newDisplayItem = *newIt; |
| 332 const DisplayItem::Id newDisplayItemId = newDisplayItem.nonCachedId(); | 332 const DisplayItem::Id newDisplayItemId = newDisplayItem.nonCachedId(); |
| 333 bool newDisplayItemHasCachedType = newDisplayItem.type() != newDisplayIt
emId.type; | 333 bool newDisplayItemHasCachedType = newDisplayItem.type() != newDisplayIt
emId.type; |
| 334 | 334 |
| 335 bool isSynchronized = currentIt != currentEnd && newDisplayItemId.matche
s(*currentIt); | 335 bool isSynchronized = currentIt != currentEnd && newDisplayItemId.matche
s(*currentIt); |
| 336 | 336 |
| 337 if (newDisplayItemHasCachedType) { | 337 if (newDisplayItemHasCachedType) { |
| 338 ASSERT(newDisplayItem.isCached()); | 338 ASSERT(newDisplayItem.isCached()); |
| 339 ASSERT(clientCacheIsValid(newDisplayItem.client()) || (RuntimeEnable
dFeatures::slimmingPaintV2Enabled() && !paintOffsetWasInvalidated(newDisplayItem
.client()))); | 339 ASSERT(clientCacheIsValid(newDisplayItem.client()) || (RuntimeEnable
dFeatures::slimmingPaintOffsetCachingEnabled() && !paintOffsetWasInvalidated(new
DisplayItem.client()))); |
| 340 if (!isSynchronized) { | 340 if (!isSynchronized) { |
| 341 currentIt = findOutOfOrderCachedItem(newDisplayItemId, outOfOrde
rIndexContext); | 341 currentIt = findOutOfOrderCachedItem(newDisplayItemId, outOfOrde
rIndexContext); |
| 342 | 342 |
| 343 if (currentIt == currentEnd) { | 343 if (currentIt == currentEnd) { |
| 344 #ifndef NDEBUG | 344 #ifndef NDEBUG |
| 345 showDebugData(); | 345 showDebugData(); |
| 346 WTFLogAlways("%s not found in m_currentDisplayItems\n", newD
isplayItem.asDebugString().utf8().data()); | 346 WTFLogAlways("%s not found in m_currentDisplayItems\n", newD
isplayItem.asDebugString().utf8().data()); |
| 347 #endif | 347 #endif |
| 348 ASSERT_NOT_REACHED(); | 348 ASSERT_NOT_REACHED(); |
| 349 // We did not find the cached display item. This should be i
mpossible, but may occur if there is a bug | 349 // We did not find the cached display item. This should be i
mpossible, but may occur if there is a bug |
| (...skipping 13 matching lines...) Expand all Loading... |
| 363 ++currentIt; | 363 ++currentIt; |
| 364 } else { | 364 } else { |
| 365 ASSERT(newDisplayItem.type() == DisplayItem::CachedSubsequence); | 365 ASSERT(newDisplayItem.type() == DisplayItem::CachedSubsequence); |
| 366 copyCachedSubsequence(currentIt, updatedList); | 366 copyCachedSubsequence(currentIt, updatedList); |
| 367 ASSERT(updatedList.last().type() == DisplayItem::EndSubsequence)
; | 367 ASSERT(updatedList.last().type() == DisplayItem::EndSubsequence)
; |
| 368 } | 368 } |
| 369 } else { | 369 } else { |
| 370 ASSERT(!newDisplayItem.isDrawing() | 370 ASSERT(!newDisplayItem.isDrawing() |
| 371 || newDisplayItem.skippedCache() | 371 || newDisplayItem.skippedCache() |
| 372 || !clientCacheIsValid(newDisplayItem.client()) | 372 || !clientCacheIsValid(newDisplayItem.client()) |
| 373 || (RuntimeEnabledFeatures::slimmingPaintV2Enabled() && paintOff
setWasInvalidated(newDisplayItem.client()))); | 373 || (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()
&& paintOffsetWasInvalidated(newDisplayItem.client()))); |
| 374 | 374 |
| 375 updatedList.appendByMoving(*newIt); | 375 updatedList.appendByMoving(*newIt); |
| 376 | 376 |
| 377 if (isSynchronized) | 377 if (isSynchronized) |
| 378 ++currentIt; | 378 ++currentIt; |
| 379 } | 379 } |
| 380 // Items before currentIt should have been copied so we don't need to in
dex them. | 380 // Items before currentIt should have been copied so we don't need to in
dex them. |
| 381 if (currentIt - outOfOrderIndexContext.nextItemToIndex > 0) | 381 if (currentIt - outOfOrderIndexContext.nextItemToIndex > 0) |
| 382 outOfOrderIndexContext.nextItemToIndex = currentIt; | 382 outOfOrderIndexContext.nextItemToIndex = currentIt; |
| 383 } | 383 } |
| 384 | 384 |
| 385 #if ENABLE(ASSERT) | 385 #if ENABLE(ASSERT) |
| 386 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) | 386 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) |
| 387 checkNoRemainingCachedDisplayItems(); | 387 checkNoRemainingCachedDisplayItems(); |
| 388 #endif // ENABLE(ASSERT) | 388 #endif // ENABLE(ASSERT) |
| 389 | 389 |
| 390 m_newDisplayItems.clear(); | 390 m_newDisplayItems.clear(); |
| 391 m_validlyCachedClientsDirty = true; | 391 m_validlyCachedClientsDirty = true; |
| 392 m_currentDisplayItems.swap(updatedList); | 392 m_currentDisplayItems.swap(updatedList); |
| 393 m_numCachedItems = 0; | 393 m_numCachedItems = 0; |
| 394 | 394 |
| 395 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 395 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()) |
| 396 removeUnneededPaintOffsetEntries(); | 396 removeUnneededPaintOffsetEntries(); |
| 397 | 397 |
| 398 #if ENABLE(ASSERT) | 398 #if ENABLE(ASSERT) |
| 399 m_clientsWithPaintOffsetInvalidations.clear(); | 399 m_clientsWithPaintOffsetInvalidations.clear(); |
| 400 #endif | 400 #endif |
| 401 } | 401 } |
| 402 | 402 |
| 403 size_t DisplayItemList::approximateUnsharedMemoryUsage() const | 403 size_t DisplayItemList::approximateUnsharedMemoryUsage() const |
| 404 { | 404 { |
| 405 size_t memoryUsage = sizeof(*this); | 405 size_t memoryUsage = sizeof(*this); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 587 |
| 588 void DisplayItemList::replay(GraphicsContext& context) | 588 void DisplayItemList::replay(GraphicsContext& context) |
| 589 { | 589 { |
| 590 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); | 590 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); |
| 591 ASSERT(m_newDisplayItems.isEmpty()); | 591 ASSERT(m_newDisplayItems.isEmpty()); |
| 592 for (DisplayItem& displayItem : m_currentDisplayItems) | 592 for (DisplayItem& displayItem : m_currentDisplayItems) |
| 593 displayItem.replay(context); | 593 displayItem.replay(context); |
| 594 } | 594 } |
| 595 | 595 |
| 596 } // namespace blink | 596 } // namespace blink |
| OLD | NEW |