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 #ifndef PaintController_h | 5 #ifndef PaintController_h |
6 #define PaintController_h | 6 #define PaintController_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
10 #include "platform/geometry/IntRect.h" | 10 #include "platform/geometry/IntRect.h" |
11 #include "platform/geometry/LayoutPoint.h" | 11 #include "platform/geometry/LayoutPoint.h" |
12 #include "platform/graphics/ContiguousContainer.h" | 12 #include "platform/graphics/ContiguousContainer.h" |
13 #include "platform/graphics/paint/DisplayItem.h" | 13 #include "platform/graphics/paint/DisplayItem.h" |
14 #include "platform/graphics/paint/DisplayItemList.h" | 14 #include "platform/graphics/paint/DisplayItemList.h" |
15 #include "platform/graphics/paint/PaintArtifact.h" | 15 #include "platform/graphics/paint/PaintArtifact.h" |
16 #include "platform/graphics/paint/PaintChunk.h" | 16 #include "platform/graphics/paint/PaintChunk.h" |
17 #include "platform/graphics/paint/PaintChunker.h" | 17 #include "platform/graphics/paint/PaintChunker.h" |
18 #include "platform/graphics/paint/Transform3DDisplayItem.h" | 18 #include "platform/graphics/paint/Transform3DDisplayItem.h" |
19 #include "wtf/Alignment.h" | 19 #include "wtf/Alignment.h" |
| 20 #include "wtf/Assertions.h" |
20 #include "wtf/HashMap.h" | 21 #include "wtf/HashMap.h" |
21 #include "wtf/HashSet.h" | 22 #include "wtf/HashSet.h" |
22 #include "wtf/PassOwnPtr.h" | 23 #include "wtf/PassOwnPtr.h" |
23 #include "wtf/Vector.h" | 24 #include "wtf/Vector.h" |
24 #include <utility> | 25 #include <utility> |
25 | 26 |
26 namespace blink { | 27 namespace blink { |
27 | 28 |
28 class GraphicsContext; | 29 class GraphicsContext; |
29 | 30 |
(...skipping 12 matching lines...) Loading... |
42 } | 43 } |
43 | 44 |
44 // These methods are called during paint invalidation (or paint if SlimmingP
aintV2 is on). | 45 // These methods are called during paint invalidation (or paint if SlimmingP
aintV2 is on). |
45 | 46 |
46 void invalidate(const DisplayItemClient&); | 47 void invalidate(const DisplayItemClient&); |
47 void invalidateUntracked(const DisplayItemClient&); | 48 void invalidateUntracked(const DisplayItemClient&); |
48 void invalidateAll(); | 49 void invalidateAll(); |
49 | 50 |
50 // Record when paint offsets change during paint. | 51 // Record when paint offsets change during paint. |
51 void invalidatePaintOffset(const DisplayItemClient&); | 52 void invalidatePaintOffset(const DisplayItemClient&); |
52 #if ENABLE(ASSERT) | 53 #if DCHECK_IS_ON() |
53 bool paintOffsetWasInvalidated(const DisplayItemClient&) const; | 54 bool paintOffsetWasInvalidated(const DisplayItemClient&) const; |
54 #endif | 55 #endif |
55 | 56 |
56 // These methods are called during painting. | 57 // These methods are called during painting. |
57 | 58 |
58 // Provide a new set of paint chunk properties to apply to recorded display | 59 // Provide a new set of paint chunk properties to apply to recorded display |
59 // items, for Slimming Paint v2. | 60 // items, for Slimming Paint v2. |
60 void updateCurrentPaintChunkProperties(const PaintChunkProperties&); | 61 void updateCurrentPaintChunkProperties(const PaintChunkProperties&); |
61 | 62 |
62 // Retrieve the current paint properties. | 63 // Retrieve the current paint properties. |
(...skipping 33 matching lines...) Loading... |
96 // multiple times and generate multiple display items with the same type. | 97 // multiple times and generate multiple display items with the same type. |
97 // We don't cache display items added in scopes. | 98 // We don't cache display items added in scopes. |
98 void beginScope(); | 99 void beginScope(); |
99 void endScope(); | 100 void endScope(); |
100 | 101 |
101 // True if the last display item is a begin that doesn't draw content. | 102 // True if the last display item is a begin that doesn't draw content. |
102 bool lastDisplayItemIsNoopBegin() const; | 103 bool lastDisplayItemIsNoopBegin() const; |
103 void removeLastDisplayItem(); | 104 void removeLastDisplayItem(); |
104 | 105 |
105 void beginSkippingCache() { ++m_skippingCacheCount; } | 106 void beginSkippingCache() { ++m_skippingCacheCount; } |
106 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach
eCount; } | 107 void endSkippingCache() { DCHECK(m_skippingCacheCount > 0); --m_skippingCach
eCount; } |
107 bool skippingCache() const { return m_skippingCacheCount; } | 108 bool skippingCache() const { return m_skippingCacheCount; } |
108 | 109 |
109 // Must be called when a painting is finished. | 110 // Must be called when a painting is finished. |
110 // offsetFromLayoutObject is the offset between the space of the GraphicsLay
er which owns this | 111 // offsetFromLayoutObject is the offset between the space of the GraphicsLay
er which owns this |
111 // PaintController and the coordinate space of the owning LayoutObject. | 112 // PaintController and the coordinate space of the owning LayoutObject. |
112 void commitNewDisplayItems(const LayoutSize& offsetFromLayoutObject = Layout
Size()); | 113 void commitNewDisplayItems(const LayoutSize& offsetFromLayoutObject = Layout
Size()); |
113 | 114 |
114 // Returns the approximate memory usage, excluding memory likely to be | 115 // Returns the approximate memory usage, excluding memory likely to be |
115 // shared with the embedder after copying to WebPaintController. | 116 // shared with the embedder after copying to WebPaintController. |
116 // Should only be called right after commitNewDisplayItems. | 117 // Should only be called right after commitNewDisplayItems. |
(...skipping 19 matching lines...) Loading... |
136 void setImagePainted() { m_imagePainted = true; } | 137 void setImagePainted() { m_imagePainted = true; } |
137 | 138 |
138 // Returns displayItemList added using createAndAppend() since beginning or | 139 // Returns displayItemList added using createAndAppend() since beginning or |
139 // the last commitNewDisplayItems(). Use with care. | 140 // the last commitNewDisplayItems(). Use with care. |
140 DisplayItemList& newDisplayItemList() { return m_newDisplayItemList; } | 141 DisplayItemList& newDisplayItemList() { return m_newDisplayItemList; } |
141 | 142 |
142 #ifndef NDEBUG | 143 #ifndef NDEBUG |
143 void showDebugData() const; | 144 void showDebugData() const; |
144 #endif | 145 #endif |
145 | 146 |
146 #if ENABLE(ASSERT) | 147 #if DCHECK_IS_ON() |
147 bool hasInvalidations() { return !m_invalidations.isEmpty(); } | 148 bool hasInvalidations() { return !m_invalidations.isEmpty(); } |
148 #endif | 149 #endif |
149 | 150 |
150 void startTrackingPaintInvalidationObjects() | 151 void startTrackingPaintInvalidationObjects() |
151 { | 152 { |
152 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 153 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
153 m_trackedPaintInvalidationObjects = adoptPtr(new Vector<String>()); | 154 m_trackedPaintInvalidationObjects = adoptPtr(new Vector<String>()); |
154 } | 155 } |
155 void stopTrackingPaintInvalidationObjects() | 156 void stopTrackingPaintInvalidationObjects() |
156 { | 157 { |
157 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 158 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
158 m_trackedPaintInvalidationObjects = nullptr; | 159 m_trackedPaintInvalidationObjects = nullptr; |
159 } | 160 } |
160 Vector<String> trackedPaintInvalidationObjects() | 161 Vector<String> trackedPaintInvalidationObjects() |
161 { | 162 { |
162 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 163 DCHECK(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
163 return m_trackedPaintInvalidationObjects ? *m_trackedPaintInvalidationOb
jects : Vector<String>(); | 164 return m_trackedPaintInvalidationObjects ? *m_trackedPaintInvalidationOb
jects : Vector<String>(); |
164 } | 165 } |
165 | 166 |
166 bool clientHasCheckedPaintInvalidation(const DisplayItemClient& client) cons
t | 167 #if DCHECK_IS_ON() |
167 { | |
168 return m_clientsCheckedPaintInvalidation.contains(&client); | |
169 } | |
170 void setClientHasCheckedPaintInvalidation(const DisplayItemClient& client) | |
171 { | |
172 m_clientsCheckedPaintInvalidation.add(&client); | |
173 } | |
174 | |
175 #if ENABLE(ASSERT) | |
176 void assertDisplayItemClientsAreLive(); | 168 void assertDisplayItemClientsAreLive(); |
177 #endif | 169 #endif |
178 | 170 |
179 protected: | 171 protected: |
180 PaintController() | 172 PaintController() |
181 : m_newDisplayItemList(kInitialDisplayItemListCapacityBytes) | 173 : m_newDisplayItemList(kInitialDisplayItemListCapacityBytes) |
182 , m_validlyCachedClientsDirty(false) | |
183 , m_constructionDisabled(false) | 174 , m_constructionDisabled(false) |
184 , m_subsequenceCachingDisabled(false) | 175 , m_subsequenceCachingDisabled(false) |
185 , m_textPainted(false) | 176 , m_textPainted(false) |
186 , m_imagePainted(false) | 177 , m_imagePainted(false) |
187 , m_skippingCacheCount(0) | 178 , m_skippingCacheCount(0) |
188 , m_numCachedNewItems(0) | 179 , m_numCachedNewItems(0) |
189 , m_nextScope(1) { } | 180 , m_nextScope(1) |
| 181 { } |
190 | 182 |
191 private: | 183 private: |
192 // Set new item state (scopes, cache skipping, etc) for a new item. | 184 // Set new item state (scopes, cache skipping, etc) for a new item. |
193 void processNewItem(DisplayItem&); | 185 void processNewItem(DisplayItem&); |
194 | 186 |
195 void updateValidlyCachedClientsIfNeeded() const; | |
196 | |
197 #ifndef NDEBUG | 187 #ifndef NDEBUG |
198 WTF::String displayItemListAsDebugString(const DisplayItemList&) const; | 188 WTF::String displayItemListAsDebugString(const DisplayItemList&) const; |
199 #endif | 189 #endif |
200 | 190 |
201 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis
playItems of each client. | 191 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis
playItems of each client. |
202 // Temporarily used during merge to find out-of-order display items. | 192 // Temporarily used during merge to find out-of-order display items. |
203 using DisplayItemIndicesByClientMap = HashMap<const DisplayItemClient*, Vect
or<size_t>>; | 193 using DisplayItemIndicesByClientMap = HashMap<const DisplayItemClient*, Vect
or<size_t>>; |
204 | 194 |
205 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa
yItemIndicesByClientMap&, const DisplayItemList&); | 195 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa
yItemIndicesByClientMap&, const DisplayItemList&); |
206 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display
ItemIndicesByClientMap&); | 196 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display
ItemIndicesByClientMap&); |
207 | 197 |
208 struct OutOfOrderIndexContext; | 198 struct OutOfOrderIndexContext; |
209 DisplayItemList::iterator findOutOfOrderCachedItem(const DisplayItem::Id&, O
utOfOrderIndexContext&); | 199 DisplayItemList::iterator findOutOfOrderCachedItem(const DisplayItem::Id&, O
utOfOrderIndexContext&); |
210 DisplayItemList::iterator findOutOfOrderCachedItemForward(const DisplayItem:
:Id&, OutOfOrderIndexContext&); | 200 DisplayItemList::iterator findOutOfOrderCachedItemForward(const DisplayItem:
:Id&, OutOfOrderIndexContext&); |
211 void copyCachedSubsequence(const DisplayItemList& currentList, DisplayItemLi
st::iterator& currentIt, DisplayItemList& updatedList, SkPictureGpuAnalyzer&); | 201 void copyCachedSubsequence(const DisplayItemList& currentList, DisplayItemLi
st::iterator& currentIt, DisplayItemList& updatedList, SkPictureGpuAnalyzer&); |
212 | 202 |
213 #if ENABLE(ASSERT) | 203 #if DCHECK_IS_ON() |
214 // The following two methods are for checking under-invalidations | 204 // The following two methods are for checking under-invalidations |
215 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). | 205 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). |
216 void checkUnderInvalidation(DisplayItemList::iterator& newIt, DisplayItemLis
t::iterator& currentIt); | 206 void checkUnderInvalidation(DisplayItemList::iterator& newIt, DisplayItemLis
t::iterator& currentIt); |
217 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp
layItem& newItem, const DisplayItem& oldItem); | 207 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp
layItem& newItem, const DisplayItem& oldItem); |
218 void checkNoRemainingCachedDisplayItems(); | 208 void checkNoRemainingCachedDisplayItems(); |
219 #endif | 209 #endif |
220 | 210 |
221 void commitNewDisplayItemsInternal(const LayoutSize& offsetFromLayoutObject)
; | 211 void commitNewDisplayItemsInternal(const LayoutSize& offsetFromLayoutObject)
; |
222 | 212 |
| 213 void updateCacheGeneration(); |
| 214 |
223 // The last complete paint artifact. | 215 // The last complete paint artifact. |
224 // In SPv2, this includes paint chunks as well as display items. | 216 // In SPv2, this includes paint chunks as well as display items. |
225 PaintArtifact m_currentPaintArtifact; | 217 PaintArtifact m_currentPaintArtifact; |
226 | 218 |
227 // Data being used to build the next paint artifact. | 219 // Data being used to build the next paint artifact. |
228 DisplayItemList m_newDisplayItemList; | 220 DisplayItemList m_newDisplayItemList; |
229 PaintChunker m_newPaintChunks; | 221 PaintChunker m_newPaintChunks; |
230 | 222 |
231 // Contains all clients having valid cached paintings if updated. | 223 #if DCHECK_IS_ON() |
232 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). | |
233 // TODO(wangxianzhu): In the future we can replace this with client-side rep
aint flags | |
234 // to avoid the cost of building and querying the hash table. | |
235 mutable HashSet<const DisplayItemClient*> m_validlyCachedClients; | |
236 mutable bool m_validlyCachedClientsDirty; | |
237 | |
238 // Used during painting. Contains clients that have checked paint invalidati
on and | |
239 // are known to be valid. | |
240 // TODO(wangxianzhu): Use client side flag to avoid const of hash table. | |
241 HashSet<const DisplayItemClient*> m_clientsCheckedPaintInvalidation; | |
242 | |
243 #if ENABLE(ASSERT) | |
244 // Set of clients which had paint offset changes since the last commit. This
is used for | 224 // Set of clients which had paint offset changes since the last commit. This
is used for |
245 // ensuring paint offsets are only updated once and are the same in all phas
es. | 225 // ensuring paint offsets are only updated once and are the same in all phas
es. |
246 HashSet<const DisplayItemClient*> m_clientsWithPaintOffsetInvalidations; | 226 HashSet<const DisplayItemClient*> m_clientsWithPaintOffsetInvalidations; |
247 #endif | 227 #endif |
248 | 228 |
249 // Allow display item construction to be disabled to isolate the costs of co
nstruction | 229 // Allow display item construction to be disabled to isolate the costs of co
nstruction |
250 // in performance metrics. | 230 // in performance metrics. |
251 bool m_constructionDisabled; | 231 bool m_constructionDisabled; |
252 | 232 |
253 // Allow subsequence caching to be disabled to test the cost of display item
caching. | 233 // Allow subsequence caching to be disabled to test the cost of display item
caching. |
254 bool m_subsequenceCachingDisabled; | 234 bool m_subsequenceCachingDisabled; |
255 | 235 |
256 // Indicates this PaintController has ever had text. It is never reset to fa
lse. | 236 // Indicates this PaintController has ever had text. It is never reset to fa
lse. |
257 bool m_textPainted; | 237 bool m_textPainted; |
258 bool m_imagePainted; | 238 bool m_imagePainted; |
259 | 239 |
260 int m_skippingCacheCount; | 240 int m_skippingCacheCount; |
261 | 241 |
262 int m_numCachedNewItems; | 242 int m_numCachedNewItems; |
263 | 243 |
264 unsigned m_nextScope; | 244 unsigned m_nextScope; |
265 Vector<unsigned> m_scopeStack; | 245 Vector<unsigned> m_scopeStack; |
266 | 246 |
267 #if ENABLE(ASSERT) | 247 #if DCHECK_IS_ON() |
268 // Record the debug names of invalidated clients for assertion and debugging
. | 248 // Record the debug names of invalidated clients for assertion and debugging
. |
269 Vector<String> m_invalidations; | 249 Vector<String> m_invalidations; |
270 | 250 |
271 // This is used to check duplicated ids during add(). We could also check | 251 // This is used to check duplicated ids during add(). We could also check |
272 // during commitNewDisplayItems(), but checking during add() helps developer | 252 // during commitNewDisplayItems(), but checking during add() helps developer |
273 // easily find where the duplicated ids are from. | 253 // easily find where the duplicated ids are from. |
274 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; | 254 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; |
275 #endif | 255 #endif |
276 | 256 |
277 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; | 257 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; |
| 258 |
| 259 DisplayItemCacheGeneration m_currentCacheGeneration; |
278 }; | 260 }; |
279 | 261 |
280 } // namespace blink | 262 } // namespace blink |
281 | 263 |
282 #endif // PaintController_h | 264 #endif // PaintController_h |
OLD | NEW |