Chromium Code Reviews| 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 DisplayItemList_h |
| 6 #define DisplayItemList_h | 6 #define DisplayItemList_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" | |
| 16 #include "platform/graphics/paint/PaintArtifact.h" | |
| 15 #include "platform/graphics/paint/PaintChunk.h" | 17 #include "platform/graphics/paint/PaintChunk.h" |
| 16 #include "platform/graphics/paint/PaintChunker.h" | 18 #include "platform/graphics/paint/PaintChunker.h" |
| 17 #include "platform/graphics/paint/Transform3DDisplayItem.h" | 19 #include "platform/graphics/paint/Transform3DDisplayItem.h" |
| 18 #include "wtf/Alignment.h" | 20 #include "wtf/Alignment.h" |
| 19 #include "wtf/HashMap.h" | 21 #include "wtf/HashMap.h" |
| 20 #include "wtf/PassOwnPtr.h" | 22 #include "wtf/PassOwnPtr.h" |
| 21 #include "wtf/Utility.h" | 23 #include "wtf/Utility.h" |
| 22 #include "wtf/Vector.h" | 24 #include "wtf/Vector.h" |
| 23 | 25 |
| 24 namespace blink { | 26 namespace blink { |
| 25 | 27 |
| 26 class GraphicsLayer; | 28 class GraphicsLayer; |
| 27 class GraphicsContext; | 29 class GraphicsContext; |
| 28 | 30 |
| 29 // kDisplayItemAlignment must be a multiple of alignof(derived display item) for | |
| 30 // each derived display item; the ideal value is the least common multiple. | |
| 31 // Currently the limiting factor is TransformtionMatrix (in | |
| 32 // BeginTransform3DDisplayItem), which requests 16-byte alignment. | |
| 33 static const size_t kDisplayItemAlignment = WTF_ALIGN_OF(BeginTransform3DDisplay Item); | |
| 34 static const size_t kInitialDisplayItemsCapacity = 64; | 31 static const size_t kInitialDisplayItemsCapacity = 64; |
| 35 static const size_t kMaximumDisplayItemSize = sizeof(BeginTransform3DDisplayItem ); | |
| 36 | 32 |
| 37 class DisplayItems : public ContiguousContainer<DisplayItem, kDisplayItemAlignme nt> { | 33 // Responsible for processing display items as they are produced, and producing |
| 38 public: | 34 // a final paint artifact when complete. This class includes logic for caching, |
| 39 DisplayItems(size_t initialSizeBytes) | 35 // cache invalidation, and merging. |
|
pdr.
2015/10/09 03:57:50
+1, I think this is the right abstraction with the
| |
| 40 : ContiguousContainer(kMaximumDisplayItemSize, initialSizeBytes) {} | |
| 41 | |
| 42 DisplayItem& appendByMoving(DisplayItem& item) | |
| 43 { | |
| 44 #ifndef NDEBUG | |
| 45 WTF::String originalDebugString = item.asDebugString(); | |
| 46 #endif | |
| 47 ASSERT(item.isValid()); | |
| 48 DisplayItem& result = ContiguousContainer::appendByMoving(item, item.der ivedSize()); | |
| 49 // ContiguousContainer::appendByMoving() called in-place constructor on item, which invalidated it. | |
| 50 ASSERT(!item.isValid()); | |
| 51 #ifndef NDEBUG | |
| 52 // Save original debug string in the old item to help debugging. | |
| 53 item.setClientDebugString(originalDebugString); | |
| 54 #endif | |
| 55 return result; | |
| 56 } | |
| 57 }; | |
| 58 | |
| 59 class PLATFORM_EXPORT DisplayItemList { | 36 class PLATFORM_EXPORT DisplayItemList { |
|
pdr.
2015/10/09 03:57:50
I'm worried about the name of this class because i
jbroman
2015/10/13 18:20:56
Right, as I said in the original review email, I'd
pdr.
2015/10/13 18:30:32
I sort of think of builders as having temporary st
| |
| 60 WTF_MAKE_NONCOPYABLE(DisplayItemList); | 37 WTF_MAKE_NONCOPYABLE(DisplayItemList); |
| 61 WTF_MAKE_FAST_ALLOCATED(DisplayItemList); | 38 WTF_MAKE_FAST_ALLOCATED(DisplayItemList); |
| 62 public: | 39 public: |
| 63 static PassOwnPtr<DisplayItemList> create() | 40 static PassOwnPtr<DisplayItemList> create() |
| 64 { | 41 { |
| 65 return adoptPtr(new DisplayItemList()); | 42 return adoptPtr(new DisplayItemList()); |
| 66 } | 43 } |
| 67 | 44 |
| 68 // 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). |
| 69 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); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 106 |
| 130 // 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 |
| 131 // GraphicsLayer. | 108 // GraphicsLayer. |
| 132 void commitNewDisplayItems(GraphicsLayer* = 0); | 109 void commitNewDisplayItems(GraphicsLayer* = 0); |
| 133 | 110 |
| 134 // Returns the approximate memory usage, excluding memory likely to be | 111 // Returns the approximate memory usage, excluding memory likely to be |
| 135 // shared with the embedder after copying to WebDisplayItemList. | 112 // shared with the embedder after copying to WebDisplayItemList. |
| 136 // Should only be called right after commitNewDisplayItems. | 113 // Should only be called right after commitNewDisplayItems. |
| 137 size_t approximateUnsharedMemoryUsage() const; | 114 size_t approximateUnsharedMemoryUsage() const; |
| 138 | 115 |
| 139 // Get the paint list generated after the last painting. | 116 // Get the artifact generated after the last commit. |
| 140 const DisplayItems& displayItems() const; | 117 const PaintArtifact& paintArtifact() const; |
| 141 | 118 const DisplayItems& displayItems() const { return paintArtifact().displayIte ms(); } |
|
pdr.
2015/10/09 03:57:50
We could just return PaintArtifact from a finish/c
jbroman
2015/10/13 18:20:56
The tricky thing here is that this class does need
| |
| 142 // Get the paint chunks generated after the last painting. | 119 const Vector<PaintChunk>& paintChunks() const { return paintArtifact().paint Chunks(); } |
| 143 const Vector<PaintChunk>& paintChunks() const; | |
| 144 | 120 |
| 145 bool clientCacheIsValid(DisplayItemClient) const; | 121 bool clientCacheIsValid(DisplayItemClient) const; |
| 146 | 122 |
| 147 // Commits the new display items and plays back the updated display items in to the given context. | |
| 148 void commitNewDisplayItemsAndReplay(GraphicsContext& context) | |
| 149 { | |
| 150 commitNewDisplayItems(); | |
| 151 replay(context); | |
| 152 } | |
| 153 | |
| 154 void appendToWebDisplayItemList(WebDisplayItemList*); | |
| 155 void commitNewDisplayItemsAndAppendToWebDisplayItemList(WebDisplayItemList*) ; | |
| 156 | |
| 157 bool displayItemConstructionIsDisabled() const { return m_constructionDisabl ed; } | 123 bool displayItemConstructionIsDisabled() const { return m_constructionDisabl ed; } |
| 158 void setDisplayItemConstructionIsDisabled(const bool disable) { m_constructi onDisabled = disable; } | 124 void setDisplayItemConstructionIsDisabled(const bool disable) { m_constructi onDisabled = disable; } |
| 159 | 125 |
| 160 bool textPainted() const { return m_textPainted; } | 126 bool textPainted() const { return m_textPainted; } |
| 161 void setTextPainted() { m_textPainted = true; } | 127 void setTextPainted() { m_textPainted = true; } |
| 162 | 128 |
| 163 // Returns displayItems added using createAndAppend() since beginning or the last | 129 // Returns displayItems added using createAndAppend() since beginning or the last |
| 164 // commitNewDisplayItems(). Use with care. | 130 // commitNewDisplayItems(). Use with care. |
| 165 DisplayItems& newDisplayItems() { return m_newDisplayItems; } | 131 DisplayItems& newDisplayItems() { return m_newDisplayItems; } |
| 166 | 132 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 190 return m_clientsCheckedPaintInvalidation.contains(client); | 156 return m_clientsCheckedPaintInvalidation.contains(client); |
| 191 } | 157 } |
| 192 void setClientHasCheckedPaintInvalidation(DisplayItemClient client) | 158 void setClientHasCheckedPaintInvalidation(DisplayItemClient client) |
| 193 { | 159 { |
| 194 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled( )); | 160 ASSERT(RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled( )); |
| 195 m_clientsCheckedPaintInvalidation.add(client); | 161 m_clientsCheckedPaintInvalidation.add(client); |
| 196 } | 162 } |
| 197 | 163 |
| 198 protected: | 164 protected: |
| 199 DisplayItemList() | 165 DisplayItemList() |
| 200 : m_currentDisplayItems(0) | 166 : m_newDisplayItems(kInitialDisplayItemsCapacity * kMaximumDisplayItemSi ze) |
| 201 , m_newDisplayItems(kInitialDisplayItemsCapacity * kMaximumDisplayItemSi ze) | |
| 202 , m_validlyCachedClientsDirty(false) | 167 , m_validlyCachedClientsDirty(false) |
| 203 , m_constructionDisabled(false) | 168 , m_constructionDisabled(false) |
| 204 , m_textPainted(false) | 169 , m_textPainted(false) |
| 205 , m_skippingCacheCount(0) | 170 , m_skippingCacheCount(0) |
| 206 , m_numCachedItems(0) | 171 , m_numCachedItems(0) |
| 207 , m_nextScope(1) { } | 172 , m_nextScope(1) { } |
| 208 | 173 |
| 209 private: | 174 private: |
| 210 // 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. |
| 211 void processNewItem(DisplayItem&); | 176 void processNewItem(DisplayItem&); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 231 void copyCachedSubsequence(DisplayItems::iterator& currentIt, DisplayItems& updatedList); | 196 void copyCachedSubsequence(DisplayItems::iterator& currentIt, DisplayItems& updatedList); |
| 232 | 197 |
| 233 #if ENABLE(ASSERT) | 198 #if ENABLE(ASSERT) |
| 234 // The following two methods are for checking under-invalidations | 199 // The following two methods are for checking under-invalidations |
| 235 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl ed). | 200 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl ed). |
| 236 void checkUnderInvalidation(DisplayItems::iterator& newIt, DisplayItems::ite rator& currentIt); | 201 void checkUnderInvalidation(DisplayItems::iterator& newIt, DisplayItems::ite rator& currentIt); |
| 237 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp layItem& newItem, const DisplayItem& oldItem); | 202 void checkCachedDisplayItemIsUnchanged(const char* messagePrefix, const Disp layItem& newItem, const DisplayItem& oldItem); |
| 238 void checkNoRemainingCachedDisplayItems(); | 203 void checkNoRemainingCachedDisplayItems(); |
| 239 #endif | 204 #endif |
| 240 | 205 |
| 241 void replay(GraphicsContext&) const; | 206 // The last complete paint artifact. |
| 207 // In SPv2, this includes paint chunks as well as display items. | |
| 208 PaintArtifact m_currentPaintArtifact; | |
|
pdr.
2015/10/09 03:57:51
Replacing m_currentDisplayItems and m_currentPaint
jbroman
2015/10/13 18:20:56
See my previous comment for why I did this.
Argua
| |
| 242 | 209 |
| 243 DisplayItems m_currentDisplayItems; | 210 // Data being used to build the next paint artifact. |
| 244 DisplayItems m_newDisplayItems; | 211 DisplayItems m_newDisplayItems; |
| 245 | |
| 246 // In Slimming Paint v2, paint properties (e.g. transform) useful for | |
| 247 // compositing are stored in corresponding paint chunks instead of in the | |
| 248 // display items. | |
| 249 Vector<PaintChunk> m_currentPaintChunks; | |
| 250 PaintChunker m_newPaintChunks; | 212 PaintChunker m_newPaintChunks; |
| 251 | 213 |
| 252 // Contains all clients having valid cached paintings if updated. | 214 // Contains all clients having valid cached paintings if updated. |
| 253 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). | 215 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). |
| 254 // TODO(wangxianzhu): In the future we can replace this with client-side rep aint flags | 216 // TODO(wangxianzhu): In the future we can replace this with client-side rep aint flags |
| 255 // to avoid the cost of building and querying the hash table. | 217 // to avoid the cost of building and querying the hash table. |
| 256 mutable HashSet<DisplayItemClient> m_validlyCachedClients; | 218 mutable HashSet<DisplayItemClient> m_validlyCachedClients; |
| 257 mutable bool m_validlyCachedClientsDirty; | 219 mutable bool m_validlyCachedClientsDirty; |
| 258 | 220 |
| 259 // Used during painting. Contains clients that have checked paint invalidati on and | 221 // Used during painting. Contains clients that have checked paint invalidati on and |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // the duplicated ids are from. | 256 // the duplicated ids are from. |
| 295 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; | 257 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; |
| 296 #endif | 258 #endif |
| 297 | 259 |
| 298 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; | 260 OwnPtr<Vector<String>> m_trackedPaintInvalidationObjects; |
| 299 }; | 261 }; |
| 300 | 262 |
| 301 } // namespace blink | 263 } // namespace blink |
| 302 | 264 |
| 303 #endif // DisplayItemList_h | 265 #endif // DisplayItemList_h |
| OLD | NEW |