| 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 | |
| 27 const PaintArtifact& PaintController::paintArtifact() const | 20 const PaintArtifact& PaintController::paintArtifact() const |
| 28 { | 21 { |
| 29 DCHECK(m_newDisplayItemList.isEmpty()); | 22 DCHECK(m_newDisplayItemList.isEmpty()); |
| 30 DCHECK(m_newPaintChunks.isInInitialState()); | 23 DCHECK(m_newPaintChunks.isInInitialState()); |
| 31 return m_currentPaintArtifact; | 24 return m_currentPaintArtifact; |
| 32 } | 25 } |
| 33 | 26 |
| 34 bool PaintController::useCachedDrawingIfPossible(const DisplayItemClient& client
, DisplayItem::Type type) | 27 bool PaintController::useCachedDrawingIfPossible(const DisplayItemClient& client
, DisplayItem::Type type) |
| 35 { | 28 { |
| 36 DCHECK(DisplayItem::isDrawingType(type)); | 29 DCHECK(DisplayItem::isDrawingType(type)); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 126 |
| 134 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 127 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 135 m_newPaintChunks.decrementDisplayItemIndex(); | 128 m_newPaintChunks.decrementDisplayItemIndex(); |
| 136 } | 129 } |
| 137 | 130 |
| 138 void PaintController::processNewItem(DisplayItem& displayItem) | 131 void PaintController::processNewItem(DisplayItem& displayItem) |
| 139 { | 132 { |
| 140 DCHECK(!m_constructionDisabled); | 133 DCHECK(!m_constructionDisabled); |
| 141 | 134 |
| 142 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 135 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 143 if (!skippingCache()) { | 136 if (!isSkippingCache()) { |
| 144 if (displayItem.isCacheable()) { | 137 if (displayItem.isCacheable()) { |
| 145 // Mark the client shouldKeepAlive under this PaintController. | 138 // Mark the client shouldKeepAlive under this PaintController. |
| 146 // The status will end after the new display items are committed. | 139 // The status will end after the new display items are committed. |
| 147 displayItem.client().beginShouldKeepAlive(this); | 140 displayItem.client().beginShouldKeepAlive(this); |
| 148 | 141 |
| 149 if (!m_currentSubsequenceClients.isEmpty()) { | 142 if (!m_currentSubsequenceClients.isEmpty()) { |
| 150 // Mark the client shouldKeepAlive under the current subsequence
. | 143 // Mark the client shouldKeepAlive under the current subsequence
. |
| 151 // The status will end when the subsequence owner is invalidated
or deleted. | 144 // The status will end when the subsequence owner is invalidated
or deleted. |
| 152 displayItem.client().beginShouldKeepAlive(m_currentSubsequenceCl
ients.last()); | 145 displayItem.client().beginShouldKeepAlive(m_currentSubsequenceCl
ients.last()); |
| 153 } | 146 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 164 | 157 |
| 165 #if DCHECK_IS_ON() | 158 #if DCHECK_IS_ON() |
| 166 // Verify noop begin/end pairs have been removed. | 159 // Verify noop begin/end pairs have been removed. |
| 167 if (m_newDisplayItemList.size() >= 2 && displayItem.isEnd()) { | 160 if (m_newDisplayItemList.size() >= 2 && displayItem.isEnd()) { |
| 168 const auto& beginDisplayItem = m_newDisplayItemList[m_newDisplayItemList
.size() - 2]; | 161 const auto& beginDisplayItem = m_newDisplayItemList[m_newDisplayItemList
.size() - 2]; |
| 169 if (beginDisplayItem.isBegin() && beginDisplayItem.getType() != DisplayI
tem::Subsequence && !beginDisplayItem.drawsContent()) | 162 if (beginDisplayItem.isBegin() && beginDisplayItem.getType() != DisplayI
tem::Subsequence && !beginDisplayItem.drawsContent()) |
| 170 DCHECK(!displayItem.isEndAndPairedWith(beginDisplayItem.getType())); | 163 DCHECK(!displayItem.isEndAndPairedWith(beginDisplayItem.getType())); |
| 171 } | 164 } |
| 172 #endif | 165 #endif |
| 173 | 166 |
| 174 if (skippingCache()) | 167 if (isSkippingCache()) |
| 175 displayItem.setSkippedCache(); | 168 displayItem.setSkippedCache(); |
| 176 | 169 |
| 177 #if DCHECK_IS_ON() | 170 #if DCHECK_IS_ON() |
| 178 size_t index = findMatchingItemFromIndex(displayItem.getId(), m_newDisplayIt
emIndicesByClient, m_newDisplayItemList); | 171 size_t index = findMatchingItemFromIndex(displayItem.getId(), m_newDisplayIt
emIndicesByClient, m_newDisplayItemList); |
| 179 if (index != kNotFound) { | 172 if (index != kNotFound) { |
| 180 #ifndef NDEBUG | 173 #ifndef NDEBUG |
| 181 showDebugData(); | 174 showDebugData(); |
| 182 WTFLogAlways("DisplayItem %s has duplicated id with previous %s (index=%
d)\n", | 175 WTFLogAlways("DisplayItem %s has duplicated id with previous %s (index=%
d)\n", |
| 183 displayItem.asDebugString().utf8().data(), m_newDisplayItemList[inde
x].asDebugString().utf8().data(), static_cast<int>(index)); | 176 displayItem.asDebugString().utf8().data(), m_newDisplayItemList[inde
x].asDebugString().utf8().data(), static_cast<int>(index)); |
| 184 #endif | 177 #endif |
| 185 NOTREACHED(); | 178 NOTREACHED(); |
| 186 } | 179 } |
| 187 addItemToIndexIfNeeded(displayItem, m_newDisplayItemList.size() - 1, m_newDi
splayItemIndicesByClient); | 180 addItemToIndexIfNeeded(displayItem, m_newDisplayItemList.size() - 1, m_newDi
splayItemIndicesByClient); |
| 188 #endif // DCHECK_IS_ON() | 181 #endif // DCHECK_IS_ON() |
| 189 | 182 |
| 190 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 183 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 191 m_newPaintChunks.incrementDisplayItemIndex(behaviorOfItemType(displayIte
m.getType())); | 184 m_newPaintChunks.incrementDisplayItemIndex(displayItem); |
| 192 } | 185 } |
| 193 | 186 |
| 194 void PaintController::updateCurrentPaintChunkProperties(const PaintChunkProperti
es& newProperties) | 187 void PaintController::updateCurrentPaintChunkProperties(const DisplayItem::Id* i
d, const PaintChunkProperties& newProperties) |
| 195 { | 188 { |
| 196 m_newPaintChunks.updateCurrentPaintChunkProperties(newProperties); | 189 m_newPaintChunks.updateCurrentPaintChunkProperties(id, newProperties); |
| 197 } | 190 } |
| 198 | 191 |
| 199 const PaintChunkProperties& PaintController::currentPaintChunkProperties() const | 192 const PaintChunkProperties& PaintController::currentPaintChunkProperties() const |
| 200 { | 193 { |
| 201 return m_newPaintChunks.currentPaintChunkProperties(); | 194 return m_newPaintChunks.currentPaintChunkProperties(); |
| 202 } | 195 } |
| 203 | 196 |
| 204 void PaintController::invalidateAll() | 197 void PaintController::invalidateAll() |
| 205 { | 198 { |
| 206 // Can only be called during layout/paintInvalidation, not during painting. | 199 // Can only be called during layout/paintInvalidation, not during painting. |
| 207 DCHECK(m_newDisplayItemList.isEmpty()); | 200 DCHECK(m_newDisplayItemList.isEmpty()); |
| 208 m_currentPaintArtifact.reset(); | 201 m_currentPaintArtifact.reset(); |
| 209 m_currentCacheGeneration.invalidate(); | 202 m_currentCacheGeneration.invalidate(); |
| 210 } | 203 } |
| 211 | 204 |
| 212 bool PaintController::clientCacheIsValid(const DisplayItemClient& client) const | 205 bool PaintController::clientCacheIsValid(const DisplayItemClient& client) const |
| 213 { | 206 { |
| 214 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 207 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
| 215 CHECK(client.isAlive()); | 208 CHECK(client.isAlive()); |
| 216 #endif | 209 #endif |
| 217 if (skippingCache()) | 210 if (isSkippingCache()) |
| 218 return false; | 211 return false; |
| 219 return client.displayItemsAreCached(m_currentCacheGeneration); | 212 return client.displayItemsAreCached(m_currentCacheGeneration); |
| 220 } | 213 } |
| 221 | 214 |
| 222 size_t PaintController::findMatchingItemFromIndex(const DisplayItem::Id& id, con
st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItemL
ist& list) | 215 size_t PaintController::findMatchingItemFromIndex(const DisplayItem::Id& id, con
st DisplayItemIndicesByClientMap& displayItemIndicesByClient, const DisplayItemL
ist& list) |
| 223 { | 216 { |
| 224 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien
t.find(&id.client); | 217 DisplayItemIndicesByClientMap::const_iterator it = displayItemIndicesByClien
t.find(&id.client); |
| 225 if (it == displayItemIndicesByClient.end()) | 218 if (it == displayItemIndicesByClient.end()) |
| 226 return kNotFound; | 219 return kNotFound; |
| 227 | 220 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 338 } |
| 346 | 339 |
| 347 void PaintController::commitNewDisplayItems(const LayoutSize& offsetFromLayoutOb
ject) | 340 void PaintController::commitNewDisplayItems(const LayoutSize& offsetFromLayoutOb
ject) |
| 348 { | 341 { |
| 349 TRACE_EVENT2("blink,benchmark", "PaintController::commitNewDisplayItems", | 342 TRACE_EVENT2("blink,benchmark", "PaintController::commitNewDisplayItems", |
| 350 "current_display_list_size", (int)m_currentPaintArtifact.getDisplayItemL
ist().size(), | 343 "current_display_list_size", (int)m_currentPaintArtifact.getDisplayItemL
ist().size(), |
| 351 "num_non_cached_new_items", (int)m_newDisplayItemList.size() - m_numCach
edNewItems); | 344 "num_non_cached_new_items", (int)m_newDisplayItemList.size() - m_numCach
edNewItems); |
| 352 m_numCachedNewItems = 0; | 345 m_numCachedNewItems = 0; |
| 353 | 346 |
| 354 // These data structures are used during painting only. | 347 // These data structures are used during painting only. |
| 355 DCHECK(!skippingCache()); | 348 DCHECK(!isSkippingCache()); |
| 356 #if DCHECK_IS_ON() | 349 #if DCHECK_IS_ON() |
| 357 m_newDisplayItemIndicesByClient.clear(); | 350 m_newDisplayItemIndicesByClient.clear(); |
| 358 #endif | 351 #endif |
| 359 | 352 |
| 360 SkPictureGpuAnalyzer gpuAnalyzer; | 353 SkPictureGpuAnalyzer gpuAnalyzer; |
| 361 | 354 |
| 362 m_currentCacheGeneration = DisplayItemClient::CacheGenerationOrInvalidationR
eason::next(); | 355 m_currentCacheGeneration = DisplayItemClient::CacheGenerationOrInvalidationR
eason::next(); |
| 363 for (const auto& item : m_newDisplayItemList) { | 356 for (const auto& item : m_newDisplayItemList) { |
| 364 // No reason to continue the analysis once we have a veto. | 357 // No reason to continue the analysis once we have a veto. |
| 365 if (gpuAnalyzer.suitableForGpuRasterization()) | 358 if (gpuAnalyzer.suitableForGpuRasterization()) |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 537 |
| 545 void PaintController::showDebugData() const | 538 void PaintController::showDebugData() const |
| 546 { | 539 { |
| 547 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri
ng(m_currentPaintArtifact.getDisplayItemList()).utf8().data()); | 540 WTFLogAlways("current display item list: [%s]\n", displayItemListAsDebugStri
ng(m_currentPaintArtifact.getDisplayItemList()).utf8().data()); |
| 548 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m
_newDisplayItemList).utf8().data()); | 541 WTFLogAlways("new display item list: [%s]\n", displayItemListAsDebugString(m
_newDisplayItemList).utf8().data()); |
| 549 } | 542 } |
| 550 | 543 |
| 551 #endif // ifndef NDEBUG | 544 #endif // ifndef NDEBUG |
| 552 | 545 |
| 553 } // namespace blink | 546 } // namespace blink |
| OLD | NEW |