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 DisplayItemList_h | 5 #ifndef PaintController_h |
6 #define DisplayItemList_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/PaintInvalidationReason.h" | 13 #include "platform/graphics/PaintInvalidationReason.h" |
14 #include "platform/graphics/paint/DisplayItem.h" | 14 #include "platform/graphics/paint/DisplayItem.h" |
15 #include "platform/graphics/paint/DisplayItems.h" | 15 #include "platform/graphics/paint/DisplayItems.h" |
16 #include "platform/graphics/paint/PaintArtifact.h" | 16 #include "platform/graphics/paint/PaintArtifact.h" |
17 #include "platform/graphics/paint/PaintChunk.h" | 17 #include "platform/graphics/paint/PaintChunk.h" |
18 #include "platform/graphics/paint/PaintChunker.h" | 18 #include "platform/graphics/paint/PaintChunker.h" |
19 #include "platform/graphics/paint/Transform3DDisplayItem.h" | 19 #include "platform/graphics/paint/Transform3DDisplayItem.h" |
20 #include "wtf/Alignment.h" | 20 #include "wtf/Alignment.h" |
21 #include "wtf/HashMap.h" | 21 #include "wtf/HashMap.h" |
22 #include "wtf/PassOwnPtr.h" | 22 #include "wtf/PassOwnPtr.h" |
23 #include "wtf/Utility.h" | 23 #include "wtf/Utility.h" |
24 #include "wtf/Vector.h" | 24 #include "wtf/Vector.h" |
25 | 25 |
26 namespace blink { | 26 namespace blink { |
27 | 27 |
28 class GraphicsLayer; | 28 class GraphicsLayer; |
29 class GraphicsContext; | 29 class GraphicsContext; |
30 | 30 |
31 static const size_t kInitialDisplayItemsCapacity = 64; | 31 static const size_t kInitialDisplayItemsCapacity = 64; |
32 | 32 |
33 // Responsible for processing display items as they are produced, and producing | 33 // Responsible for processing display items as they are produced, and producing |
34 // a final paint artifact when complete. This class includes logic for caching, | 34 // a final paint artifact when complete. This class includes logic for caching, |
35 // cache invalidation, and merging. | 35 // cache invalidation, and merging. |
36 class PLATFORM_EXPORT DisplayItemList { | 36 class PLATFORM_EXPORT PaintController { |
37 WTF_MAKE_NONCOPYABLE(DisplayItemList); | 37 WTF_MAKE_NONCOPYABLE(PaintController); |
38 WTF_MAKE_FAST_ALLOCATED(DisplayItemList); | 38 WTF_MAKE_FAST_ALLOCATED(PaintController); |
39 public: | 39 public: |
40 static PassOwnPtr<DisplayItemList> create() | 40 static PassOwnPtr<PaintController> create() |
41 { | 41 { |
42 return adoptPtr(new DisplayItemList()); | 42 return adoptPtr(new PaintController()); |
43 } | 43 } |
44 | 44 |
45 // These methods are called during paint invalidation (or paint if SlimmingP
aintSynchronizedPainting is on). | 45 // These methods are called during paint invalidation (or paint if SlimmingP
aintSynchronizedPainting is on). |
46 void invalidate(const DisplayItemClientWrapper&, PaintInvalidationReason, co
nst IntRect& previousPaintInvalidationRect, const IntRect& newPaintInvalidationR
ect); | 46 void invalidate(const DisplayItemClientWrapper&, PaintInvalidationReason, co
nst IntRect& previousPaintInvalidationRect, const IntRect& newPaintInvalidationR
ect); |
47 void invalidateUntracked(DisplayItemClient); | 47 void invalidateUntracked(DisplayItemClient); |
48 void invalidateAll(); | 48 void invalidateAll(); |
49 | 49 |
50 // Record when paint offsets change during paint. | 50 // Record when paint offsets change during paint. |
51 void invalidatePaintOffset(const DisplayItemClientWrapper&); | 51 void invalidatePaintOffset(const DisplayItemClientWrapper&); |
52 #if ENABLE(ASSERT) | 52 #if ENABLE(ASSERT) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 void beginSkippingCache() { ++m_skippingCacheCount; } | 103 void beginSkippingCache() { ++m_skippingCacheCount; } |
104 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach
eCount; } | 104 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach
eCount; } |
105 bool skippingCache() const { return m_skippingCacheCount; } | 105 bool skippingCache() const { return m_skippingCacheCount; } |
106 | 106 |
107 // Must be called when a painting is finished. If passed, invalidations are
recorded on the given | 107 // Must be called when a painting is finished. If passed, invalidations are
recorded on the given |
108 // GraphicsLayer. | 108 // GraphicsLayer. |
109 void commitNewDisplayItems(GraphicsLayer* = 0); | 109 void commitNewDisplayItems(GraphicsLayer* = 0); |
110 | 110 |
111 // Returns the approximate memory usage, excluding memory likely to be | 111 // Returns the approximate memory usage, excluding memory likely to be |
112 // shared with the embedder after copying to WebDisplayItemList. | 112 // shared with the embedder after copying to WebPaintController. |
113 // Should only be called right after commitNewDisplayItems. | 113 // Should only be called right after commitNewDisplayItems. |
114 size_t approximateUnsharedMemoryUsage() const; | 114 size_t approximateUnsharedMemoryUsage() const; |
115 | 115 |
116 // Get the artifact generated after the last commit. | 116 // Get the artifact generated after the last commit. |
117 const PaintArtifact& paintArtifact() const; | 117 const PaintArtifact& paintArtifact() const; |
118 const DisplayItems& displayItems() const { return paintArtifact().displayIte
ms(); } | 118 const DisplayItems& displayItems() const { return paintArtifact().displayIte
ms(); } |
119 const Vector<PaintChunk>& paintChunks() const { return paintArtifact().paint
Chunks(); } | 119 const Vector<PaintChunk>& paintChunks() const { return paintArtifact().paint
Chunks(); } |
120 | 120 |
121 bool clientCacheIsValid(DisplayItemClient) const; | 121 bool clientCacheIsValid(DisplayItemClient) const; |
122 | 122 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); | 155 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); |
156 return m_clientsCheckedPaintInvalidation.contains(client); | 156 return m_clientsCheckedPaintInvalidation.contains(client); |
157 } | 157 } |
158 void setClientHasCheckedPaintInvalidation(DisplayItemClient client) | 158 void setClientHasCheckedPaintInvalidation(DisplayItemClient client) |
159 { | 159 { |
160 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); | 160 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); |
161 m_clientsCheckedPaintInvalidation.add(client); | 161 m_clientsCheckedPaintInvalidation.add(client); |
162 } | 162 } |
163 | 163 |
164 protected: | 164 protected: |
165 DisplayItemList() | 165 PaintController() |
166 : m_newDisplayItems(kInitialDisplayItemsCapacity * kMaximumDisplayItemSi
ze) | 166 : m_newDisplayItems(kInitialDisplayItemsCapacity * kMaximumDisplayItemSi
ze) |
167 , m_validlyCachedClientsDirty(false) | 167 , m_validlyCachedClientsDirty(false) |
168 , m_constructionDisabled(false) | 168 , m_constructionDisabled(false) |
169 , m_textPainted(false) | 169 , m_textPainted(false) |
170 , m_skippingCacheCount(0) | 170 , m_skippingCacheCount(0) |
171 , m_numCachedItems(0) | 171 , m_numCachedItems(0) |
172 , m_nextScope(1) { } | 172 , m_nextScope(1) { } |
173 | 173 |
174 private: | 174 private: |
175 // Set new item state (scopes, cache skipping, etc) for a new item. | 175 // Set new item state (scopes, cache skipping, etc) for a new item. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 #if ENABLE(ASSERT) | 226 #if ENABLE(ASSERT) |
227 // Set of clients which had paint offset changes since the last commit. This
is used for | 227 // Set of clients which had paint offset changes since the last commit. This
is used for |
228 // ensuring paint offsets are only updated once and are the same in all phas
es. | 228 // ensuring paint offsets are only updated once and are the same in all phas
es. |
229 HashSet<DisplayItemClient> m_clientsWithPaintOffsetInvalidations; | 229 HashSet<DisplayItemClient> m_clientsWithPaintOffsetInvalidations; |
230 #endif | 230 #endif |
231 | 231 |
232 // Allow display item construction to be disabled to isolate the costs of co
nstruction | 232 // Allow display item construction to be disabled to isolate the costs of co
nstruction |
233 // in performance metrics. | 233 // in performance metrics. |
234 bool m_constructionDisabled; | 234 bool m_constructionDisabled; |
235 | 235 |
236 // Indicates this DisplayItemList 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. |
237 bool m_textPainted; | 237 bool m_textPainted; |
238 | 238 |
239 int m_skippingCacheCount; | 239 int m_skippingCacheCount; |
240 | 240 |
241 int m_numCachedItems; | 241 int m_numCachedItems; |
242 | 242 |
243 unsigned m_nextScope; | 243 unsigned m_nextScope; |
244 Vector<unsigned> m_scopeStack; | 244 Vector<unsigned> m_scopeStack; |
245 | 245 |
246 struct Invalidation { | 246 struct Invalidation { |
247 IntRect rect; | 247 IntRect rect; |
248 PaintInvalidationReason invalidationReason; | 248 PaintInvalidationReason invalidationReason; |
249 }; | 249 }; |
250 | 250 |
251 Vector<Invalidation> m_invalidations; | 251 Vector<Invalidation> m_invalidations; |
252 | 252 |
253 #if ENABLE(ASSERT) | 253 #if ENABLE(ASSERT) |
254 // This is used to check duplicated ids during add(). We could also check du
ring | 254 // This is used to check duplicated ids during add(). We could also check du
ring |
255 // updatePaintList(), but checking during add() helps developer easily find
where | 255 // updatePaintList(), but checking during add() helps developer easily find
where |
256 // the duplicated ids are from. | 256 // the duplicated ids are from. |
257 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; | 257 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; |
258 #endif | 258 #endif |
259 | 259 |
260 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; | 260 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; |
261 }; | 261 }; |
262 | 262 |
263 } // namespace blink | 263 } // namespace blink |
264 | 264 |
265 #endif // DisplayItemList_h | 265 #endif // PaintController_h |
OLD | NEW |