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