| 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/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/DisplayItemList.h" | 15 #include "platform/graphics/paint/DisplayItemList.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/HashSet.h" |
| 22 #include "wtf/PassOwnPtr.h" | 23 #include "wtf/PassOwnPtr.h" |
| 23 #include "wtf/Utility.h" | 24 #include "wtf/Utility.h" |
| 24 #include "wtf/Vector.h" | 25 #include "wtf/Vector.h" |
| 25 | 26 |
| 26 namespace blink { | 27 namespace blink { |
| 27 | 28 |
| 28 class GraphicsContext; | 29 class GraphicsContext; |
| 29 | 30 |
| 30 static const size_t kInitialDisplayItemListCapacityBytes = 512; | 31 static const size_t kInitialDisplayItemListCapacityBytes = 512; |
| 31 | 32 |
| 32 // Responsible for processing display items as they are produced, and producing | 33 // Responsible for processing display items as they are produced, and producing |
| 33 // 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, |
| 34 // cache invalidation, and merging. | 35 // cache invalidation, and merging. |
| 35 class PLATFORM_EXPORT PaintController { | 36 class PLATFORM_EXPORT PaintController { |
| 36 WTF_MAKE_NONCOPYABLE(PaintController); | 37 WTF_MAKE_NONCOPYABLE(PaintController); |
| 37 USING_FAST_MALLOC(PaintController); | 38 USING_FAST_MALLOC(PaintController); |
| 38 public: | 39 public: |
| 39 static PassOwnPtr<PaintController> create() | 40 static PassOwnPtr<PaintController> create() |
| 40 { | 41 { |
| 41 return adoptPtr(new PaintController()); | 42 return adoptPtr(new PaintController()); |
| 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 // If |visualRect| is not nullptr, for slimming paint v1, it contains all pi
xels within the GraphicsLayer | 47 // If |visualRect| is not nullptr, for slimming paint v1, it contains all pi
xels within the GraphicsLayer |
| 47 // which might be painted into by the display item client, in coordinate spa
ce of the GraphicsLayer. | 48 // which might be painted into by the display item client, in coordinate spa
ce of the GraphicsLayer. |
| 48 // TODO(pdr): define it for spv2. | 49 // TODO(pdr): define it for spv2. |
| 49 // |visualRect| can be nullptr if we know it's unchanged and PaintController
has cached the previous value. | 50 // |visualRect| can be nullptr if we know it's unchanged and PaintController
has cached the previous value. |
| 50 void invalidate(const DisplayItemClientWrapper&, PaintInvalidationReason, co
nst IntRect* visualRect); | 51 void invalidate(const DisplayItemClient&, PaintInvalidationReason, const Int
Rect* visualRect); |
| 51 void invalidateUntracked(DisplayItemClient); | 52 void invalidateUntracked(const DisplayItemClient&); |
| 52 void invalidateAll(); | 53 void invalidateAll(); |
| 53 | 54 |
| 54 // Record when paint offsets change during paint. | 55 // Record when paint offsets change during paint. |
| 55 void invalidatePaintOffset(const DisplayItemClientWrapper&); | 56 void invalidatePaintOffset(const DisplayItemClient&); |
| 56 #if ENABLE(ASSERT) | 57 #if ENABLE(ASSERT) |
| 57 bool paintOffsetWasInvalidated(DisplayItemClient) const; | 58 bool paintOffsetWasInvalidated(const DisplayItemClient&) const; |
| 58 #endif | 59 #endif |
| 59 | 60 |
| 60 // These methods are called during painting. | 61 // These methods are called during painting. |
| 61 | 62 |
| 62 // Provide a new set of paint chunk properties to apply to recorded display | 63 // Provide a new set of paint chunk properties to apply to recorded display |
| 63 // items, for Slimming Paint v2. | 64 // items, for Slimming Paint v2. |
| 64 void updateCurrentPaintChunkProperties(const PaintChunkProperties&); | 65 void updateCurrentPaintChunkProperties(const PaintChunkProperties&); |
| 65 | 66 |
| 66 // Retrieve the current paint properties. | 67 // Retrieve the current paint properties. |
| 67 const PaintChunkProperties& currentPaintChunkProperties() const; | 68 const PaintChunkProperties& currentPaintChunkProperties() const; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // Returns the approximate memory usage, excluding memory likely to be | 117 // Returns the approximate memory usage, excluding memory likely to be |
| 117 // shared with the embedder after copying to WebPaintController. | 118 // shared with the embedder after copying to WebPaintController. |
| 118 // Should only be called right after commitNewDisplayItems. | 119 // Should only be called right after commitNewDisplayItems. |
| 119 size_t approximateUnsharedMemoryUsage() const; | 120 size_t approximateUnsharedMemoryUsage() const; |
| 120 | 121 |
| 121 // Get the artifact generated after the last commit. | 122 // Get the artifact generated after the last commit. |
| 122 const PaintArtifact& paintArtifact() const; | 123 const PaintArtifact& paintArtifact() const; |
| 123 const DisplayItemList& displayItemList() const { return paintArtifact().disp
layItemList(); } | 124 const DisplayItemList& displayItemList() const { return paintArtifact().disp
layItemList(); } |
| 124 const Vector<PaintChunk>& paintChunks() const { return paintArtifact().paint
Chunks(); } | 125 const Vector<PaintChunk>& paintChunks() const { return paintArtifact().paint
Chunks(); } |
| 125 | 126 |
| 126 bool clientCacheIsValid(DisplayItemClient) const; | 127 bool clientCacheIsValid(const DisplayItemClient&) const; |
| 127 bool cacheIsEmpty() const { return m_currentPaintArtifact.isEmpty(); } | 128 bool cacheIsEmpty() const { return m_currentPaintArtifact.isEmpty(); } |
| 128 | 129 |
| 129 bool displayItemConstructionIsDisabled() const { return m_constructionDisabl
ed; } | 130 bool displayItemConstructionIsDisabled() const { return m_constructionDisabl
ed; } |
| 130 void setDisplayItemConstructionIsDisabled(const bool disable) { m_constructi
onDisabled = disable; } | 131 void setDisplayItemConstructionIsDisabled(const bool disable) { m_constructi
onDisabled = disable; } |
| 131 | 132 |
| 132 bool textPainted() const { return m_textPainted; } | 133 bool textPainted() const { return m_textPainted; } |
| 133 void setTextPainted() { m_textPainted = true; } | 134 void setTextPainted() { m_textPainted = true; } |
| 134 bool imagePainted() const { return m_imagePainted; } | 135 bool imagePainted() const { return m_imagePainted; } |
| 135 void setImagePainted() { m_imagePainted = true; } | 136 void setImagePainted() { m_imagePainted = true; } |
| 136 | 137 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 151 { | 152 { |
| 152 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 153 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
| 153 m_trackedPaintInvalidationObjects = nullptr; | 154 m_trackedPaintInvalidationObjects = nullptr; |
| 154 } | 155 } |
| 155 Vector<String> trackedPaintInvalidationObjects() | 156 Vector<String> trackedPaintInvalidationObjects() |
| 156 { | 157 { |
| 157 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); | 158 ASSERT(RuntimeEnabledFeatures::slimmingPaintV2Enabled()); |
| 158 return m_trackedPaintInvalidationObjects ? *m_trackedPaintInvalidationOb
jects : Vector<String>(); | 159 return m_trackedPaintInvalidationObjects ? *m_trackedPaintInvalidationOb
jects : Vector<String>(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool clientHasCheckedPaintInvalidation(DisplayItemClient client) const | 162 bool clientHasCheckedPaintInvalidation(const DisplayItemClient& client) cons
t |
| 162 { | 163 { |
| 163 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); | 164 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); |
| 164 return m_clientsCheckedPaintInvalidation.contains(client); | 165 return m_clientsCheckedPaintInvalidation.contains(&client); |
| 165 } | 166 } |
| 166 void setClientHasCheckedPaintInvalidation(DisplayItemClient client) | 167 void setClientHasCheckedPaintInvalidation(const DisplayItemClient& client) |
| 167 { | 168 { |
| 168 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); | 169 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled(
)); |
| 169 m_clientsCheckedPaintInvalidation.add(client); | 170 m_clientsCheckedPaintInvalidation.add(&client); |
| 170 } | 171 } |
| 171 | 172 |
| 172 protected: | 173 protected: |
| 173 PaintController() | 174 PaintController() |
| 174 : m_newDisplayItemList(kInitialDisplayItemListCapacityBytes) | 175 : m_newDisplayItemList(kInitialDisplayItemListCapacityBytes) |
| 175 , m_validlyCachedClientsDirty(false) | 176 , m_validlyCachedClientsDirty(false) |
| 176 , m_constructionDisabled(false) | 177 , m_constructionDisabled(false) |
| 177 , m_textPainted(false) | 178 , m_textPainted(false) |
| 178 , m_imagePainted(false) | 179 , m_imagePainted(false) |
| 179 , m_skippingCacheCount(0) | 180 , m_skippingCacheCount(0) |
| 180 , m_numCachedItems(0) | 181 , m_numCachedItems(0) |
| 181 , m_nextScope(1) { } | 182 , m_nextScope(1) { } |
| 182 | 183 |
| 183 private: | 184 private: |
| 184 // Set new item state (scopes, cache skipping, etc) for a new item. | 185 // Set new item state (scopes, cache skipping, etc) for a new item. |
| 185 void processNewItem(DisplayItem&); | 186 void processNewItem(DisplayItem&); |
| 186 | 187 |
| 187 void updateValidlyCachedClientsIfNeeded() const; | 188 void updateValidlyCachedClientsIfNeeded() const; |
| 188 | 189 |
| 189 void invalidateClient(const DisplayItemClientWrapper&); | 190 void invalidateClient(const DisplayItemClient&); |
| 190 | 191 |
| 191 #ifndef NDEBUG | 192 #ifndef NDEBUG |
| 192 WTF::String displayItemListAsDebugString(const DisplayItemList&) const; | 193 WTF::String displayItemListAsDebugString(const DisplayItemList&) const; |
| 193 #endif | 194 #endif |
| 194 | 195 |
| 195 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis
playItems of each client. | 196 // Indices into PaintList of all DrawingDisplayItems and BeginSubsequenceDis
playItems of each client. |
| 196 // Temporarily used during merge to find out-of-order display items. | 197 // Temporarily used during merge to find out-of-order display items. |
| 197 using DisplayItemIndicesByClientMap = HashMap<DisplayItemClient, Vector<size
_t>>; | 198 using DisplayItemIndicesByClientMap = HashMap<const DisplayItemClient*, Vect
or<size_t>>; |
| 198 | 199 |
| 199 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa
yItemIndicesByClientMap&, const DisplayItemList&); | 200 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, const Displa
yItemIndicesByClientMap&, const DisplayItemList&); |
| 200 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display
ItemIndicesByClientMap&); | 201 static void addItemToIndexIfNeeded(const DisplayItem&, size_t index, Display
ItemIndicesByClientMap&); |
| 201 | 202 |
| 202 struct OutOfOrderIndexContext; | 203 struct OutOfOrderIndexContext; |
| 203 DisplayItemList::iterator findOutOfOrderCachedItem(const DisplayItem::Id&, O
utOfOrderIndexContext&); | 204 DisplayItemList::iterator findOutOfOrderCachedItem(const DisplayItem::Id&, O
utOfOrderIndexContext&); |
| 204 DisplayItemList::iterator findOutOfOrderCachedItemForward(const DisplayItem:
:Id&, OutOfOrderIndexContext&); | 205 DisplayItemList::iterator findOutOfOrderCachedItemForward(const DisplayItem:
:Id&, OutOfOrderIndexContext&); |
| 205 void copyCachedSubsequence(DisplayItemList::iterator& currentIt, DisplayItem
List& updatedList); | 206 void copyCachedSubsequence(DisplayItemList::iterator& currentIt, DisplayItem
List& updatedList); |
| 206 | 207 |
| 207 #if ENABLE(ASSERT) | 208 #if ENABLE(ASSERT) |
| 208 // The following two methods are for checking under-invalidations | 209 // The following two methods are for checking under-invalidations |
| 209 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). | 210 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). |
| 210 void checkUnderInvalidation(DisplayItemList::iterator& newIt, DisplayItemLis
t::iterator& currentIt); | 211 void checkUnderInvalidation(DisplayItemList::iterator& newIt, DisplayItemLis
t::iterator& currentIt); |
| 211 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp
layItem& newItem, const DisplayItem& oldItem); | 212 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp
layItem& newItem, const DisplayItem& oldItem); |
| 212 void checkNoRemainingCachedDisplayItems(); | 213 void checkNoRemainingCachedDisplayItems(); |
| 213 #endif | 214 #endif |
| 214 | 215 |
| 215 // The last complete paint artifact. | 216 // The last complete paint artifact. |
| 216 // In SPv2, this includes paint chunks as well as display items. | 217 // In SPv2, this includes paint chunks as well as display items. |
| 217 PaintArtifact m_currentPaintArtifact; | 218 PaintArtifact m_currentPaintArtifact; |
| 218 | 219 |
| 219 // Data being used to build the next paint artifact. | 220 // Data being used to build the next paint artifact. |
| 220 DisplayItemList m_newDisplayItemList; | 221 DisplayItemList m_newDisplayItemList; |
| 221 PaintChunker m_newPaintChunks; | 222 PaintChunker m_newPaintChunks; |
| 222 | 223 |
| 223 // Contains all clients having valid cached paintings if updated. | 224 // Contains all clients having valid cached paintings if updated. |
| 224 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). | 225 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). |
| 225 // TODO(wangxianzhu): In the future we can replace this with client-side rep
aint flags | 226 // TODO(wangxianzhu): In the future we can replace this with client-side rep
aint flags |
| 226 // to avoid the cost of building and querying the hash table. | 227 // to avoid the cost of building and querying the hash table. |
| 227 mutable HashSet<DisplayItemClient> m_validlyCachedClients; | 228 mutable HashSet<const DisplayItemClient*> m_validlyCachedClients; |
| 228 mutable bool m_validlyCachedClientsDirty; | 229 mutable bool m_validlyCachedClientsDirty; |
| 229 | 230 |
| 230 // Used during painting. Contains clients that have checked paint invalidati
on and | 231 // Used during painting. Contains clients that have checked paint invalidati
on and |
| 231 // are known to be valid. | 232 // are known to be valid. |
| 232 // TODO(wangxianzhu): Use client side flag to avoid const of hash table. | 233 // TODO(wangxianzhu): Use client side flag to avoid const of hash table. |
| 233 HashSet<DisplayItemClient> m_clientsCheckedPaintInvalidation; | 234 HashSet<const DisplayItemClient*> m_clientsCheckedPaintInvalidation; |
| 234 | 235 |
| 235 #if ENABLE(ASSERT) | 236 #if ENABLE(ASSERT) |
| 236 // Set of clients which had paint offset changes since the last commit. This
is used for | 237 // Set of clients which had paint offset changes since the last commit. This
is used for |
| 237 // ensuring paint offsets are only updated once and are the same in all phas
es. | 238 // ensuring paint offsets are only updated once and are the same in all phas
es. |
| 238 HashSet<DisplayItemClient> m_clientsWithPaintOffsetInvalidations; | 239 HashSet<const DisplayItemClient*> m_clientsWithPaintOffsetInvalidations; |
| 239 #endif | 240 #endif |
| 240 | 241 |
| 241 // Allow display item construction to be disabled to isolate the costs of co
nstruction | 242 // Allow display item construction to be disabled to isolate the costs of co
nstruction |
| 242 // in performance metrics. | 243 // in performance metrics. |
| 243 bool m_constructionDisabled; | 244 bool m_constructionDisabled; |
| 244 | 245 |
| 245 // Indicates this PaintController has ever had text. It is never reset to fa
lse. | 246 // Indicates this PaintController has ever had text. It is never reset to fa
lse. |
| 246 bool m_textPainted; | 247 bool m_textPainted; |
| 247 bool m_imagePainted; | 248 bool m_imagePainted; |
| 248 | 249 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 262 // easily find where the duplicated ids are from. | 263 // easily find where the duplicated ids are from. |
| 263 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; | 264 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; |
| 264 #endif | 265 #endif |
| 265 | 266 |
| 266 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; | 267 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; |
| 267 }; | 268 }; |
| 268 | 269 |
| 269 } // namespace blink | 270 } // namespace blink |
| 270 | 271 |
| 271 #endif // PaintController_h | 272 #endif // PaintController_h |
| OLD | NEW |