| 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" |
| 11 | 11 |
| 12 #ifndef NDEBUG | 12 #ifndef NDEBUG |
| 13 #include "platform/graphics/LoggingCanvas.h" | 13 #include "platform/graphics/LoggingCanvas.h" |
| 14 #include "wtf/text/StringBuilder.h" | 14 #include "wtf/text/StringBuilder.h" |
| 15 #include <stdio.h> | 15 #include <stdio.h> |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 static PaintChunker::ItemBehavior behaviorOfItemType(DisplayItem::Type type) |
| 21 { |
| 22 if (DisplayItem::isForeignLayerType(type)) |
| 23 return PaintChunker::RequiresSeparateChunk; |
| 24 return PaintChunker::DefaultBehavior; |
| 25 } |
| 26 |
| 20 const PaintArtifact& PaintController::paintArtifact() const | 27 const PaintArtifact& PaintController::paintArtifact() const |
| 21 { | 28 { |
| 22 DCHECK(m_newDisplayItemList.isEmpty()); | 29 DCHECK(m_newDisplayItemList.isEmpty()); |
| 23 DCHECK(m_newPaintChunks.isInInitialState()); | 30 DCHECK(m_newPaintChunks.isInInitialState()); |
| 24 return m_currentPaintArtifact; | 31 return m_currentPaintArtifact; |
| 25 } | 32 } |
| 26 | 33 |
| 27 bool PaintController::useCachedDrawingIfPossible(const DisplayItemClient& client
, DisplayItem::Type type) | 34 bool PaintController::useCachedDrawingIfPossible(const DisplayItemClient& client
, DisplayItem::Type type) |
| 28 { | 35 { |
| 29 DCHECK(DisplayItem::isDrawingType(type)); | 36 DCHECK(DisplayItem::isDrawingType(type)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 158 |
| 152 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 159 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 153 m_newPaintChunks.decrementDisplayItemIndex(); | 160 m_newPaintChunks.decrementDisplayItemIndex(); |
| 154 } | 161 } |
| 155 | 162 |
| 156 void PaintController::processNewItem(DisplayItem& displayItem) | 163 void PaintController::processNewItem(DisplayItem& displayItem) |
| 157 { | 164 { |
| 158 DCHECK(!m_constructionDisabled); | 165 DCHECK(!m_constructionDisabled); |
| 159 | 166 |
| 160 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 167 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 161 if (!isSkippingCache()) { | 168 if (!skippingCache()) { |
| 162 if (displayItem.isCacheable()) { | 169 if (displayItem.isCacheable()) { |
| 163 // Mark the client shouldKeepAlive under this PaintController. | 170 // Mark the client shouldKeepAlive under this PaintController. |
| 164 // The status will end after the new display items are committed. | 171 // The status will end after the new display items are committed. |
| 165 displayItem.client().beginShouldKeepAlive(this); | 172 displayItem.client().beginShouldKeepAlive(this); |
| 166 | 173 |
| 167 if (!m_currentSubsequenceClients.isEmpty()) { | 174 if (!m_currentSubsequenceClients.isEmpty()) { |
| 168 // Mark the client shouldKeepAlive under the current subsequence
. | 175 // Mark the client shouldKeepAlive under the current subsequence
. |
| 169 // The status will end when the subsequence owner is invalidated
or deleted. | 176 // The status will end when the subsequence owner is invalidated
or deleted. |
| 170 displayItem.client().beginShouldKeepAlive(m_currentSubsequenceCl
ients.last()); | 177 displayItem.client().beginShouldKeepAlive(m_currentSubsequenceCl
ients.last()); |
| 171 } | 178 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 182 | 189 |
| 183 #if DCHECK_IS_ON() | 190 #if DCHECK_IS_ON() |
| 184 // Verify noop begin/end pairs have been removed. | 191 // Verify noop begin/end pairs have been removed. |
| 185 if (m_newDisplayItemList.size() >= 2 && displayItem.isEnd()) { | 192 if (m_newDisplayItemList.size() >= 2 && displayItem.isEnd()) { |
| 186 const auto& beginDisplayItem = m_newDisplayItemList[m_newDisplayItemList
.size() - 2]; | 193 const auto& beginDisplayItem = m_newDisplayItemList[m_newDisplayItemList
.size() - 2]; |
| 187 if (beginDisplayItem.isBegin() && beginDisplayItem.getType() != DisplayI
tem::Subsequence && !beginDisplayItem.drawsContent()) | 194 if (beginDisplayItem.isBegin() && beginDisplayItem.getType() != DisplayI
tem::Subsequence && !beginDisplayItem.drawsContent()) |
| 188 DCHECK(!displayItem.isEndAndPairedWith(beginDisplayItem.getType())); | 195 DCHECK(!displayItem.isEndAndPairedWith(beginDisplayItem.getType())); |
| 189 } | 196 } |
| 190 #endif | 197 #endif |
| 191 | 198 |
| 192 if (isSkippingCache()) | 199 if (skippingCache()) |
| 193 displayItem.setSkippedCache(); | 200 displayItem.setSkippedCache(); |
| 194 | 201 |
| 195 #if DCHECK_IS_ON() | 202 #if DCHECK_IS_ON() |
| 196 size_t index = findMatchingItemFromIndex(displayItem.getId(), m_newDisplayIt
emIndicesByClient, m_newDisplayItemList); | 203 size_t index = findMatchingItemFromIndex(displayItem.getId(), m_newDisplayIt
emIndicesByClient, m_newDisplayItemList); |
| 197 if (index != kNotFound) { | 204 if (index != kNotFound) { |
| 198 #ifndef NDEBUG | 205 #ifndef NDEBUG |
| 199 showDebugData(); | 206 showDebugData(); |
| 200 WTFLogAlways("DisplayItem %s has duplicated id with previous %s (index=%
d)\n", | 207 WTFLogAlways("DisplayItem %s has duplicated id with previous %s (index=%
d)\n", |
| 201 displayItem.asDebugString().utf8().data(), m_newDisplayItemList[inde
x].asDebugString().utf8().data(), static_cast<int>(index)); | 208 displayItem.asDebugString().utf8().data(), m_newDisplayItemList[inde
x].asDebugString().utf8().data(), static_cast<int>(index)); |
| 202 #endif | 209 #endif |
| 203 NOTREACHED(); | 210 NOTREACHED(); |
| 204 } | 211 } |
| 205 addItemToIndexIfNeeded(displayItem, m_newDisplayItemList.size() - 1, m_newDi
splayItemIndicesByClient); | 212 addItemToIndexIfNeeded(displayItem, m_newDisplayItemList.size() - 1, m_newDi
splayItemIndicesByClient); |
| 206 | 213 |
| 207 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) | 214 if (RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled()) |
| 208 checkUnderInvalidation(); | 215 checkUnderInvalidation(); |
| 209 #endif // DCHECK_IS_ON() | 216 #endif // DCHECK_IS_ON() |
| 210 | 217 |
| 211 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 218 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 212 m_newPaintChunks.incrementDisplayItemIndex(displayItem); | 219 m_newPaintChunks.incrementDisplayItemIndex(behaviorOfItemType(displayIte
m.getType())); |
| 213 } | 220 } |
| 214 | 221 |
| 215 void PaintController::updateCurrentPaintChunkProperties(const PaintChunk::Id* id
, const PaintChunkProperties& newProperties) | 222 void PaintController::updateCurrentPaintChunkProperties(const PaintChunkProperti
es& newProperties) |
| 216 { | 223 { |
| 217 m_newPaintChunks.updateCurrentPaintChunkProperties(id, newProperties); | 224 m_newPaintChunks.updateCurrentPaintChunkProperties(newProperties); |
| 218 } | 225 } |
| 219 | 226 |
| 220 const PaintChunkProperties& PaintController::currentPaintChunkProperties() const | 227 const PaintChunkProperties& PaintController::currentPaintChunkProperties() const |
| 221 { | 228 { |
| 222 return m_newPaintChunks.currentPaintChunkProperties(); | 229 return m_newPaintChunks.currentPaintChunkProperties(); |
| 223 } | 230 } |
| 224 | 231 |
| 225 void PaintController::invalidateAll() | 232 void PaintController::invalidateAll() |
| 226 { | 233 { |
| 227 // Can only be called during layout/paintInvalidation, not during painting. | 234 // Can only be called during layout/paintInvalidation, not during painting. |
| 228 DCHECK(m_newDisplayItemList.isEmpty()); | 235 DCHECK(m_newDisplayItemList.isEmpty()); |
| 229 m_currentPaintArtifact.reset(); | 236 m_currentPaintArtifact.reset(); |
| 230 m_currentCacheGeneration.invalidate(); | 237 m_currentCacheGeneration.invalidate(); |
| 231 } | 238 } |
| 232 | 239 |
| 233 bool PaintController::clientCacheIsValid(const DisplayItemClient& client) const | 240 bool PaintController::clientCacheIsValid(const DisplayItemClient& client) const |
| 234 { | 241 { |
| 235 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 242 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 236 CHECK(client.isAlive()); | 243 CHECK(client.isAlive()); |
| 237 #endif | 244 #endif |
| 238 if (isSkippingCache()) | 245 if (skippingCache()) |
| 239 return false; | 246 return false; |
| 240 return client.displayItemsAreCached(m_currentCacheGeneration); | 247 return client.displayItemsAreCached(m_currentCacheGeneration); |
| 241 } | 248 } |
| 242 | 249 |
| 243 size_t PaintController::findMatchingItemFromIndex(const DisplayItem::Id& id, con
st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItemL
ist& list) | 250 size_t PaintController::findMatchingItemFromIndex(const DisplayItem::Id& id, con
st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItemL
ist& list) |
| 244 { | 251 { |
| 245 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien
t.find(&id.client); | 252 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien
t.find(&id.client); |
| 246 if (it == displayItemIndicesByClient.end()) | 253 if (it == displayItemIndicesByClient.end()) |
| 247 return kNotFound; | 254 return kNotFound; |
| 248 | 255 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 403 } |
| 397 | 404 |
| 398 void PaintController::commitNewDisplayItems(const LayoutSize& offsetFromLayoutOb
ject) | 405 void PaintController::commitNewDisplayItems(const LayoutSize& offsetFromLayoutOb
ject) |
| 399 { | 406 { |
| 400 TRACE_EVENT2("blink,benchmark", "PaintController::commitNewDisplayItems", | 407 TRACE_EVENT2("blink,benchmark", "PaintController::commitNewDisplayItems", |
| 401 "current_display_list_size", (int)m_currentPaintArtifact.getDisplayItemL
ist().size(), | 408 "current_display_list_size", (int)m_currentPaintArtifact.getDisplayItemL
ist().size(), |
| 402 "num_non_cached_new_items", (int)m_newDisplayItemList.size() - m_numCach
edNewItems); | 409 "num_non_cached_new_items", (int)m_newDisplayItemList.size() - m_numCach
edNewItems); |
| 403 m_numCachedNewItems = 0; | 410 m_numCachedNewItems = 0; |
| 404 | 411 |
| 405 // These data structures are used during painting only. | 412 // These data structures are used during painting only. |
| 406 DCHECK(!isSkippingCache()); | 413 DCHECK(!skippingCache()); |
| 407 #if DCHECK_IS_ON() | 414 #if DCHECK_IS_ON() |
| 408 m_newDisplayItemIndicesByClient.clear(); | 415 m_newDisplayItemIndicesByClient.clear(); |
| 409 #endif | 416 #endif |
| 410 | 417 |
| 411 SkPictureGpuAnalyzer gpuAnalyzer; | 418 SkPictureGpuAnalyzer gpuAnalyzer; |
| 412 | 419 |
| 413 m_currentCacheGeneration = DisplayItemClient::CacheGenerationOrInvalidationR
eason::next(); | 420 m_currentCacheGeneration = DisplayItemClient::CacheGenerationOrInvalidationR
eason::next(); |
| 414 for (const auto& item : m_newDisplayItemList) { | 421 for (const auto& item : m_newDisplayItemList) { |
| 415 // No reason to continue the analysis once we have a veto. | 422 // No reason to continue the analysis once we have a veto. |
| 416 if (gpuAnalyzer.suitableForGpuRasterization()) | 423 if (gpuAnalyzer.suitableForGpuRasterization()) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 560 |
| 554 void PaintController::showDebugData() const | 561 void PaintController::showDebugData() const |
| 555 { | 562 { |
| 556 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri
ng(m_currentPaintArtifact.getDisplayItemList()).utf8().data()); | 563 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri
ng(m_currentPaintArtifact.getDisplayItemList()).utf8().data()); |
| 557 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m
_newDisplayItemList).utf8().data()); | 564 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m
_newDisplayItemList).utf8().data()); |
| 558 } | 565 } |
| 559 | 566 |
| 560 #endif // ifndef NDEBUG | 567 #endif // ifndef NDEBUG |
| 561 | 568 |
| 562 } // namespace blink | 569 } // namespace blink |
| OLD | NEW |