| 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/graphics/ListContainer.h" |
| 9 #include "platform/graphics/paint/DisplayItem.h" | 10 #include "platform/graphics/paint/DisplayItem.h" |
| 10 #include "platform/graphics/paint/DisplayItems.h" | 11 #include "platform/graphics/paint/Transform3DDisplayItem.h" |
| 11 #include "wtf/HashMap.h" | 12 #include "wtf/HashMap.h" |
| 12 #include "wtf/PassOwnPtr.h" | 13 #include "wtf/PassOwnPtr.h" |
| 14 #include "wtf/Utility.h" |
| 13 #include "wtf/Vector.h" | 15 #include "wtf/Vector.h" |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 | 18 |
| 17 class GraphicsContext; | 19 class GraphicsContext; |
| 18 | 20 |
| 21 using DisplayItems = ListContainer<DisplayItem>; |
| 22 |
| 23 static const size_t kInitialDisplayItemsCapacity = 64; |
| 24 static const size_t kMaximumDisplayItemSize = sizeof(BeginTransform3DDisplayItem
); |
| 25 |
| 19 class PLATFORM_EXPORT DisplayItemList { | 26 class PLATFORM_EXPORT DisplayItemList { |
| 20 WTF_MAKE_NONCOPYABLE(DisplayItemList); | 27 WTF_MAKE_NONCOPYABLE(DisplayItemList); |
| 21 WTF_MAKE_FAST_ALLOCATED(DisplayItemList); | 28 WTF_MAKE_FAST_ALLOCATED(DisplayItemList); |
| 22 public: | 29 public: |
| 23 static PassOwnPtr<DisplayItemList> create() | 30 static PassOwnPtr<DisplayItemList> create() |
| 24 { | 31 { |
| 25 return adoptPtr(new DisplayItemList()); | 32 return adoptPtr(new DisplayItemList()); |
| 26 } | 33 } |
| 27 | 34 |
| 28 // These methods are called during paint invalidation. | 35 // These methods are called during paint invalidation. |
| 29 void invalidate(DisplayItemClient); | 36 void invalidate(DisplayItemClient); |
| 30 void invalidateAll(); | 37 void invalidateAll(); |
| 31 | 38 |
| 32 // These methods are called during painting. | 39 // These methods are called during painting. |
| 33 void add(WTF::PassOwnPtr<DisplayItem>); | 40 template <typename DisplayItemClass, typename... Args> |
| 41 DisplayItemClass& createAndAppend(Args&&... args) |
| 42 { |
| 43 static_assert(WTF::IsSubclass<DisplayItemClass, DisplayItem>::value, |
| 44 "Can only createAndAppend subclasses of DisplayItem."); |
| 45 static_assert(sizeof(DisplayItemClass) <= kMaximumDisplayItemSize, |
| 46 "DisplayItem subclass is larger than kMaximumDisplayItemSize."); |
| 47 |
| 48 DisplayItemClass* displayItem = m_newDisplayItems.allocateAndConstruct<D
isplayItemClass>(WTF::forward<Args>(args)...); |
| 49 processNewItem(displayItem); |
| 50 return *displayItem; |
| 51 } |
| 34 void beginScope(DisplayItemClient); | 52 void beginScope(DisplayItemClient); |
| 35 void endScope(DisplayItemClient); | 53 void endScope(DisplayItemClient); |
| 36 | 54 |
| 37 // True if the last display item is a begin that doesn't draw content. | 55 // True if the last display item is a begin that doesn't draw content. |
| 38 bool lastDisplayItemIsNoopBegin() const; | 56 bool lastDisplayItemIsNoopBegin() const; |
| 39 void removeLastDisplayItem(); | 57 void removeLastDisplayItem(); |
| 40 | 58 |
| 41 void beginSkippingCache() { ++m_skippingCacheCount; } | 59 void beginSkippingCache() { ++m_skippingCacheCount; } |
| 42 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach
eCount; } | 60 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach
eCount; } |
| 43 bool skippingCache() const { return m_skippingCacheCount; } | 61 bool skippingCache() const { return m_skippingCacheCount; } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 #if ENABLE(ASSERT) | 83 #if ENABLE(ASSERT) |
| 66 size_t newDisplayItemsSize() const { return m_newDisplayItems.size(); } | 84 size_t newDisplayItemsSize() const { return m_newDisplayItems.size(); } |
| 67 #endif | 85 #endif |
| 68 | 86 |
| 69 #ifndef NDEBUG | 87 #ifndef NDEBUG |
| 70 void showDebugData() const; | 88 void showDebugData() const; |
| 71 #endif | 89 #endif |
| 72 | 90 |
| 73 protected: | 91 protected: |
| 74 DisplayItemList() | 92 DisplayItemList() |
| 75 : m_validlyCachedClientsDirty(false) | 93 : m_currentDisplayItems(kMaximumDisplayItemSize, 0) |
| 94 , m_newDisplayItems(kMaximumDisplayItemSize, kInitialDisplayItemsCapacit
y) |
| 95 , m_validlyCachedClientsDirty(false) |
| 76 , m_constructionDisabled(false) | 96 , m_constructionDisabled(false) |
| 77 , m_skippingCacheCount(0) | 97 , m_skippingCacheCount(0) |
| 78 , m_numCachedItems(0) { } | 98 , m_numCachedItems(0) { } |
| 79 | 99 |
| 80 private: | 100 private: |
| 81 friend class DisplayItemListTest; | 101 friend class DisplayItemListTest; |
| 82 friend class DisplayItemListPaintTest; | 102 friend class DisplayItemListPaintTest; |
| 83 friend class LayoutObjectDrawingRecorderTest; | 103 friend class LayoutObjectDrawingRecorderTest; |
| 84 | 104 |
| 105 // Set new item state (scopes, cache skipping, etc) for a new item. |
| 106 // TODO(pdr): This only passes a pointer to make the patch easier to review.
Change to a reference. |
| 107 void processNewItem(DisplayItem*); |
| 108 |
| 85 void updateValidlyCachedClientsIfNeeded() const; | 109 void updateValidlyCachedClientsIfNeeded() const; |
| 86 | 110 |
| 87 #ifndef NDEBUG | 111 #ifndef NDEBUG |
| 88 WTF::String displayItemsAsDebugString(const DisplayItems&) const; | 112 WTF::String displayItemsAsDebugString(const DisplayItems&) const; |
| 89 #endif | 113 #endif |
| 90 | 114 |
| 91 // Indices into PaintList of all DrawingDisplayItems and BeginSubtreeDisplay
Items of each client. | 115 // Indices into PaintList of all DrawingDisplayItems and BeginSubtreeDisplay
Items of each client. |
| 92 // Temporarily used during merge to find out-of-order display items. | 116 // Temporarily used during merge to find out-of-order display items. |
| 93 using DisplayItemIndicesByClientMap = HashMap<DisplayItemClient, Vector<size
_t>>; | 117 using DisplayItemIndicesByClientMap = HashMap<DisplayItemClient, Vector<size
_t>>; |
| 94 | 118 |
| 95 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, DisplayItem:
:Type matchingType, const DisplayItemIndicesByClientMap&, const DisplayItems&); | 119 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, DisplayItem:
:Type matchingType, const DisplayItemIndicesByClientMap&, const DisplayItems&); |
| 96 static void addItemToIndex(DisplayItemClient, DisplayItem::Type, size_t inde
x, DisplayItemIndicesByClientMap&); | 120 static void addItemToIndex(DisplayItemClient, DisplayItem::Type, size_t inde
x, DisplayItemIndicesByClientMap&); |
| 97 DisplayItems::Iterator findOutOfOrderCachedItem(DisplayItems::Iterator curre
ntIt, const DisplayItem::Id&, DisplayItem::Type, DisplayItemIndicesByClientMap&)
; | 121 DisplayItems::Iterator findOutOfOrderCachedItem(DisplayItems::Iterator curre
ntIt, const DisplayItem::Id&, DisplayItem::Type, DisplayItemIndicesByClientMap&)
; |
| 98 DisplayItems::Iterator findOutOfOrderCachedItemForward(DisplayItems::Iterato
r currentIt, const DisplayItem::Id&, DisplayItem::Type, DisplayItemIndicesByClie
ntMap&); | 122 DisplayItems::Iterator findOutOfOrderCachedItemForward(DisplayItems::Iterato
r currentIt, const DisplayItem::Id&, DisplayItem::Type, DisplayItemIndicesByClie
ntMap&); |
| 99 | 123 |
| 100 #if ENABLE(ASSERT) | 124 #if ENABLE(ASSERT) |
| 101 // The following two methods are for checking under-invalidations | 125 // The following two methods are for checking under-invalidations |
| 102 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). | 126 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl
ed). |
| 103 void checkCachedDisplayItemIsUnchanged(const DisplayItems::ItemHandle&, Disp
layItemIndicesByClientMap&); | 127 void checkCachedDisplayItemIsUnchanged(const DisplayItem&, DisplayItemIndice
sByClientMap&); |
| 104 void checkNoRemainingCachedDisplayItems(); | 128 void checkNoRemainingCachedDisplayItems(); |
| 105 #endif | 129 #endif |
| 106 | 130 |
| 107 void replay(GraphicsContext&) const; | 131 void replay(GraphicsContext&); |
| 108 | 132 |
| 109 DisplayItems m_currentDisplayItems; | 133 DisplayItems m_currentDisplayItems; |
| 110 DisplayItems m_newDisplayItems; | 134 DisplayItems m_newDisplayItems; |
| 111 | 135 |
| 112 // Contains all clients having valid cached paintings if updated. | 136 // Contains all clients having valid cached paintings if updated. |
| 113 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). | 137 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). |
| 114 // FIXME: In the future we can replace this with client-side repaint flags | 138 // FIXME: In the future we can replace this with client-side repaint flags |
| 115 // to avoid the cost of building and querying the hash table. | 139 // to avoid the cost of building and querying the hash table. |
| 116 mutable HashSet<DisplayItemClient> m_validlyCachedClients; | 140 mutable HashSet<DisplayItemClient> m_validlyCachedClients; |
| 117 mutable bool m_validlyCachedClientsDirty; | 141 mutable bool m_validlyCachedClientsDirty; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 140 // This is used to check duplicated ids during add(). We could also check du
ring | 164 // This is used to check duplicated ids during add(). We could also check du
ring |
| 141 // updatePaintList(), but checking during add() helps developer easily find
where | 165 // updatePaintList(), but checking during add() helps developer easily find
where |
| 142 // the duplicated ids are from. | 166 // the duplicated ids are from. |
| 143 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; | 167 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; |
| 144 #endif | 168 #endif |
| 145 }; | 169 }; |
| 146 | 170 |
| 147 } // namespace blink | 171 } // namespace blink |
| 148 | 172 |
| 149 #endif // DisplayItemList_h | 173 #endif // DisplayItemList_h |
| OLD | NEW |