Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintChunker.cpp

Issue 2698673007: Only create PaintChunks at drawing and foreignLayer boundaries (Closed)
Patch Set: Great expectations Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/PaintChunker.h" 5 #include "platform/graphics/paint/PaintChunker.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 PaintChunker::PaintChunker() {} 11 PaintChunker::PaintChunker() : m_skippedItemsSinceLastChunk(0) {}
12 12
13 PaintChunker::~PaintChunker() {} 13 PaintChunker::~PaintChunker() {}
14 14
15 void PaintChunker::updateCurrentPaintChunkProperties( 15 void PaintChunker::updateCurrentPaintChunkProperties(
16 const PaintChunk::Id* chunkId, 16 const PaintChunk::Id* chunkId,
17 const PaintChunkProperties& properties) { 17 const PaintChunkProperties& properties) {
18 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 18 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
19 19
20 m_currentChunkId = WTF::nullopt; 20 m_currentChunkId = WTF::nullopt;
21 if (chunkId) 21 if (chunkId)
22 m_currentChunkId.emplace(*chunkId); 22 m_currentChunkId.emplace(*chunkId);
23 m_currentProperties = properties; 23 m_currentProperties = properties;
24 } 24 }
25 25
26 bool PaintChunker::incrementDisplayItemIndex(const DisplayItem& item) { 26 bool PaintChunker::incrementDisplayItemIndex(const DisplayItem& item) {
27 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 27 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
28 if (!PaintChunker::canBeginOrEndChunk(item)) {
29 m_skippedItemsSinceLastChunk++;
30 return false;
31 }
28 32
29 #if DCHECK_IS_ON() 33 #if DCHECK_IS_ON()
30 // Property nodes should never be null because they should either be set to 34 // Property nodes should never be null because they should either be set to
31 // properties created by a LayoutObject/FrameView, or be set to a non-null 35 // properties created by a LayoutObject/FrameView, or be set to a non-null
32 // root node. If these DCHECKs are hit we are missing a call to update the 36 // root node. If these DCHECKs are hit we are missing a call to update the
33 // properties. See: ScopedPaintChunkProperties. 37 // properties. See: ScopedPaintChunkProperties.
34 DCHECK(m_currentProperties.propertyTreeState.transform()); 38 DCHECK(m_currentProperties.propertyTreeState.transform());
35 DCHECK(m_currentProperties.propertyTreeState.clip()); 39 DCHECK(m_currentProperties.propertyTreeState.clip());
36 DCHECK(m_currentProperties.propertyTreeState.effect()); 40 DCHECK(m_currentProperties.propertyTreeState.effect());
37 #endif 41 #endif
38 42
39 ItemBehavior behavior; 43 ItemBehavior behavior;
40 Optional<PaintChunk::Id> newChunkId; 44 Optional<PaintChunk::Id> newChunkId;
41 if (DisplayItem::isForeignLayerType(item.getType())) { 45 if (DisplayItem::isForeignLayerType(item.getType())) {
42 behavior = RequiresSeparateChunk; 46 behavior = RequiresSeparateChunk;
43 // Use null chunkId if we are skipping cache, so that the chunk will not 47 // Use null chunkId if we are skipping cache, so that the chunk will not
44 // match any old chunk and will be treated as brand new. 48 // match any old chunk and will be treated as brand new.
45 if (!item.skippedCache()) 49 if (!item.skippedCache())
46 newChunkId.emplace(item.getId()); 50 newChunkId.emplace(item.getId());
47 51
48 // Clear m_currentChunkId so that any display items after the foreign layer 52 // Clear m_currentChunkId so that any display items after the foreign layer
49 // without a new chunk id will be treated as having no id to avoid the chunk 53 // without a new chunk id will be treated as having no id to avoid the chunk
50 // from using the same id as the chunk before the foreign layer chunk. 54 // from using the same id as the chunk before the foreign layer chunk.
51 m_currentChunkId = WTF::nullopt; 55 m_currentChunkId = WTF::nullopt;
52 } else { 56 } else {
57 DCHECK(DisplayItem::isDrawingType(item.getType()));
53 behavior = DefaultBehavior; 58 behavior = DefaultBehavior;
54 if (!item.skippedCache() && m_currentChunkId) 59 if (!item.skippedCache() && m_currentChunkId)
55 newChunkId.emplace(*m_currentChunkId); 60 newChunkId.emplace(*m_currentChunkId);
56 } 61 }
57 62
58 if (m_chunks.isEmpty()) { 63 if (m_chunks.isEmpty()) {
59 PaintChunk newChunk(0, 1, newChunkId ? &*newChunkId : nullptr, 64 PaintChunk newChunk(
60 m_currentProperties); 65 m_skippedItemsSinceLastChunk, m_skippedItemsSinceLastChunk + 1,
66 newChunkId ? &*newChunkId : nullptr, m_currentProperties);
67 m_skippedItemsSinceLastChunk = 0;
61 m_chunks.push_back(newChunk); 68 m_chunks.push_back(newChunk);
62 m_chunkBehavior.push_back(behavior); 69 m_chunkBehavior.push_back(behavior);
63 return true; 70 return true;
64 } 71 }
65 72
66 auto& lastChunk = m_chunks.back(); 73 auto& lastChunk = m_chunks.back();
67 bool canContinueChunk = m_currentProperties == lastChunk.properties && 74 bool canContinueChunk = m_currentProperties == lastChunk.properties &&
68 behavior != RequiresSeparateChunk && 75 behavior != RequiresSeparateChunk &&
69 m_chunkBehavior.back() != RequiresSeparateChunk; 76 m_chunkBehavior.back() != RequiresSeparateChunk;
70 if (canContinueChunk) { 77 if (canContinueChunk) {
78 if (m_skippedItemsSinceLastChunk) {
79 lastChunk.endIndex += m_skippedItemsSinceLastChunk;
80 m_skippedItemsSinceLastChunk = 0;
81 }
71 lastChunk.endIndex++; 82 lastChunk.endIndex++;
72 return false; 83 return false;
73 } 84 }
74 85
75 PaintChunk newChunk(lastChunk.endIndex, lastChunk.endIndex + 1, 86 PaintChunk newChunk(lastChunk.endIndex + m_skippedItemsSinceLastChunk,
87 lastChunk.endIndex + m_skippedItemsSinceLastChunk + 1,
76 newChunkId ? &*newChunkId : nullptr, m_currentProperties); 88 newChunkId ? &*newChunkId : nullptr, m_currentProperties);
89 m_skippedItemsSinceLastChunk = 0;
77 m_chunks.push_back(newChunk); 90 m_chunks.push_back(newChunk);
78 m_chunkBehavior.push_back(behavior); 91 m_chunkBehavior.push_back(behavior);
79 return true; 92 return true;
80 } 93 }
81 94
82 bool PaintChunker::decrementDisplayItemIndex() { 95 bool PaintChunker::decrementDisplayItemIndex() {
83 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 96 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled());
84 DCHECK(!m_chunks.isEmpty()); 97 DCHECK(!m_chunks.isEmpty());
85 98
99 if (m_skippedItemsSinceLastChunk) {
100 m_skippedItemsSinceLastChunk--;
101 return false;
102 }
103
86 auto& lastChunk = m_chunks.back(); 104 auto& lastChunk = m_chunks.back();
87 if ((lastChunk.endIndex - lastChunk.beginIndex) > 1) { 105 if ((lastChunk.endIndex - lastChunk.beginIndex) > 1) {
88 lastChunk.endIndex--; 106 lastChunk.endIndex--;
89 return false; 107 return false;
90 } 108 }
91 109
92 m_chunks.pop_back(); 110 m_chunks.pop_back();
93 m_chunkBehavior.pop_back(); 111 m_chunkBehavior.pop_back();
94 return true; 112 return true;
95 } 113 }
96 114
97 void PaintChunker::clear() { 115 void PaintChunker::clear() {
98 m_chunks.clear(); 116 m_chunks.clear();
99 m_chunkBehavior.clear(); 117 m_chunkBehavior.clear();
100 m_currentChunkId = WTF::nullopt; 118 m_currentChunkId = WTF::nullopt;
101 m_currentProperties = PaintChunkProperties(); 119 m_currentProperties = PaintChunkProperties();
120 m_skippedItemsSinceLastChunk = 0;
102 } 121 }
103 122
104 Vector<PaintChunk> PaintChunker::releasePaintChunks() { 123 Vector<PaintChunk> PaintChunker::releasePaintChunks() {
105 Vector<PaintChunk> chunks; 124 Vector<PaintChunk> chunks;
106 chunks.swap(m_chunks); 125 chunks.swap(m_chunks);
107 m_chunkBehavior.clear(); 126 m_chunkBehavior.clear();
108 m_currentChunkId = WTF::nullopt; 127 m_currentChunkId = WTF::nullopt;
109 m_currentProperties = PaintChunkProperties(); 128 m_currentProperties = PaintChunkProperties();
129 m_skippedItemsSinceLastChunk = 0;
110 return chunks; 130 return chunks;
111 } 131 }
112 132
113 } // namespace blink 133 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698