| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::slimmingPaintOffsetCachingEnabled()); | 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) | |
| 167 { | |
| 168 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); | |
| 169 m_previousPaintOffsets.set(client, paintOffset); | |
| 170 } | |
| 171 | |
| 172 bool DisplayItemList::paintOffsetIsUnchanged(DisplayItemClient client, const Lay
outPoint& paintOffset) const | |
| 173 { | |
| 174 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); | |
| 175 PreviousPaintOffsets::const_iterator it = m_previousPaintOffsets.find(client
); | |
| 176 if (it == m_previousPaintOffsets.end()) | |
| 177 return false; | |
| 178 return paintOffset == it->value; | |
| 179 } | |
| 180 | |
| 181 void DisplayItemList::removeUnneededPaintOffsetEntries() | |
| 182 { | |
| 183 ASSERT(RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()); | |
| 184 | |
| 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 | |
| 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 | |
| 189 // removing any paint offset clients that are no longer in the full list. | |
| 190 | |
| 191 HashSet<DisplayItemClient> paintOffsetClientsToRemove; | |
| 192 for (auto& client : m_previousPaintOffsets.keys()) | |
| 193 paintOffsetClientsToRemove.add(client); | |
| 194 for (auto& item : m_currentDisplayItems) | |
| 195 paintOffsetClientsToRemove.remove(item.client()); | |
| 196 | |
| 197 for (auto& client : paintOffsetClientsToRemove) | |
| 198 m_previousPaintOffsets.remove(client); | |
| 199 } | |
| 200 | |
| 201 size_t DisplayItemList::findMatchingItemFromIndex(const DisplayItem::Id& id, con
st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItems
& list) | 166 size_t DisplayItemList::findMatchingItemFromIndex(const DisplayItem::Id& id, con
st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItems
& list) |
| 202 { | 167 { |
| 203 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien
t.find(id.client); | 168 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien
t.find(id.client); |
| 204 if (it == displayItemIndicesByClient.end()) | 169 if (it == displayItemIndicesByClient.end()) |
| 205 return kNotFound; | 170 return kNotFound; |
| 206 | 171 |
| 207 const Vector<size_t>& indices = it->value; | 172 const Vector<size_t>& indices = it->value; |
| 208 for (size_t index : indices) { | 173 for (size_t index : indices) { |
| 209 const DisplayItem& existingItem = list[index]; | 174 const DisplayItem& existingItem = list[index]; |
| 210 ASSERT(!existingItem.isValid() || existingItem.client() == id.client); | 175 ASSERT(!existingItem.isValid() || existingItem.client() == id.client); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 #endif | 267 #endif |
| 303 | 268 |
| 304 if (m_currentDisplayItems.isEmpty()) { | 269 if (m_currentDisplayItems.isEmpty()) { |
| 305 #if ENABLE(ASSERT) | 270 #if ENABLE(ASSERT) |
| 306 for (const auto& item : m_newDisplayItems) | 271 for (const auto& item : m_newDisplayItems) |
| 307 ASSERT(!item.isCached()); | 272 ASSERT(!item.isCached()); |
| 308 #endif | 273 #endif |
| 309 m_currentDisplayItems.swap(m_newDisplayItems); | 274 m_currentDisplayItems.swap(m_newDisplayItems); |
| 310 m_validlyCachedClientsDirty = true; | 275 m_validlyCachedClientsDirty = true; |
| 311 m_numCachedItems = 0; | 276 m_numCachedItems = 0; |
| 312 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()) | |
| 313 removeUnneededPaintOffsetEntries(); | |
| 314 return; | 277 return; |
| 315 } | 278 } |
| 316 | 279 |
| 317 updateValidlyCachedClientsIfNeeded(); | 280 updateValidlyCachedClientsIfNeeded(); |
| 318 | 281 |
| 319 // Stores indices to valid DrawingDisplayItems in m_currentDisplayItems that
have not been matched | 282 // 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 | 283 // 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 | 284 // 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 | 285 // 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. | 286 // looking for potential matches. Thus we can ensure that the algorithm runs
in linear time. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 #if ENABLE(ASSERT) | 348 #if ENABLE(ASSERT) |
| 386 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) | 349 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) |
| 387 checkNoRemainingCachedDisplayItems(); | 350 checkNoRemainingCachedDisplayItems(); |
| 388 #endif // ENABLE(ASSERT) | 351 #endif // ENABLE(ASSERT) |
| 389 | 352 |
| 390 m_newDisplayItems.clear(); | 353 m_newDisplayItems.clear(); |
| 391 m_validlyCachedClientsDirty = true; | 354 m_validlyCachedClientsDirty = true; |
| 392 m_currentDisplayItems.swap(updatedList); | 355 m_currentDisplayItems.swap(updatedList); |
| 393 m_numCachedItems = 0; | 356 m_numCachedItems = 0; |
| 394 | 357 |
| 395 if (RuntimeEnabledFeatures::slimmingPaintOffsetCachingEnabled()) | |
| 396 removeUnneededPaintOffsetEntries(); | |
| 397 | |
| 398 #if ENABLE(ASSERT) | 358 #if ENABLE(ASSERT) |
| 399 m_clientsWithPaintOffsetInvalidations.clear(); | 359 m_clientsWithPaintOffsetInvalidations.clear(); |
| 400 #endif | 360 #endif |
| 401 } | 361 } |
| 402 | 362 |
| 403 size_t DisplayItemList::approximateUnsharedMemoryUsage() const | 363 size_t DisplayItemList::approximateUnsharedMemoryUsage() const |
| 404 { | 364 { |
| 405 size_t memoryUsage = sizeof(*this); | 365 size_t memoryUsage = sizeof(*this); |
| 406 | 366 |
| 407 // Memory outside this class due to m_currentDisplayItems. | 367 // Memory outside this class due to m_currentDisplayItems. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 547 |
| 588 void DisplayItemList::replay(GraphicsContext& context) | 548 void DisplayItemList::replay(GraphicsContext& context) |
| 589 { | 549 { |
| 590 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); | 550 TRACE_EVENT0("blink,benchmark", "DisplayItemList::replay"); |
| 591 ASSERT(m_newDisplayItems.isEmpty()); | 551 ASSERT(m_newDisplayItems.isEmpty()); |
| 592 for (DisplayItem& displayItem : m_currentDisplayItems) | 552 for (DisplayItem& displayItem : m_currentDisplayItems) |
| 593 displayItem.replay(context); | 553 displayItem.replay(context); |
| 594 } | 554 } |
| 595 | 555 |
| 596 } // namespace blink | 556 } // namespace blink |
| OLD | NEW |