Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: Source/platform/graphics/paint/DisplayItemList.h

Issue 1193433004: Blink-side contiguous allocation of display items. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Minor tweaks to make reviewing easier Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 );
jbroman 2015/06/29 18:11:56 I think you should be able to move this to a sourc
danakj 2015/06/29 18:15:29 FWIW there is a static assert that makes it imposs
pdr. 2015/06/29 22:20:03 This is a lot of complexity without much benefit.
jbroman 2015/06/30 14:40:50 You'd still have the other static_assert, but in a
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.allocateWithoutConstru ction<DisplayItemClass>();
danakj 2015/06/29 17:43:51 why isnt it allocateAndContruct<DisplayItemClass>(
jbroman 2015/06/29 18:11:56 Agreed; we can do this in one step.
pdr. 2015/06/29 22:20:03 Agreed x2. Done. This also removes the ListContai
49 new (displayItem) DisplayItemClass(WTF::forward<Args>(args)...);
50 processNewItem(displayItem);
51 return *displayItem;
52 }
34 void beginScope(DisplayItemClient); 53 void beginScope(DisplayItemClient);
35 void endScope(DisplayItemClient); 54 void endScope(DisplayItemClient);
36 55
37 // True if the last display item is a begin that doesn't draw content. 56 // True if the last display item is a begin that doesn't draw content.
38 bool lastDisplayItemIsNoopBegin() const; 57 bool lastDisplayItemIsNoopBegin() const;
39 void removeLastDisplayItem(); 58 void removeLastDisplayItem();
40 59
41 void beginSkippingCache() { ++m_skippingCacheCount; } 60 void beginSkippingCache() { ++m_skippingCacheCount; }
42 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach eCount; } 61 void endSkippingCache() { ASSERT(m_skippingCacheCount > 0); --m_skippingCach eCount; }
43 bool skippingCache() const { return m_skippingCacheCount; } 62 bool skippingCache() const { return m_skippingCacheCount; }
(...skipping 21 matching lines...) Expand all
65 #if ENABLE(ASSERT) 84 #if ENABLE(ASSERT)
66 size_t newDisplayItemsSize() const { return m_newDisplayItems.size(); } 85 size_t newDisplayItemsSize() const { return m_newDisplayItems.size(); }
67 #endif 86 #endif
68 87
69 #ifndef NDEBUG 88 #ifndef NDEBUG
70 void showDebugData() const; 89 void showDebugData() const;
71 #endif 90 #endif
72 91
73 protected: 92 protected:
74 DisplayItemList() 93 DisplayItemList()
75 : m_validlyCachedClientsDirty(false) 94 : m_currentDisplayItems(kMaximumDisplayItemSize, 0)
95 , m_newDisplayItems(kMaximumDisplayItemSize, kInitialDisplayItemsCapacit y)
96 , m_validlyCachedClientsDirty(false)
76 , m_constructionDisabled(false) 97 , m_constructionDisabled(false)
77 , m_skippingCacheCount(0) 98 , m_skippingCacheCount(0)
78 , m_numCachedItems(0) { } 99 , m_numCachedItems(0) { }
79 100
80 private: 101 private:
81 friend class DisplayItemListTest; 102 friend class DisplayItemListTest;
82 friend class DisplayItemListPaintTest; 103 friend class DisplayItemListPaintTest;
83 friend class LayoutObjectDrawingRecorderTest; 104 friend class LayoutObjectDrawingRecorderTest;
84 105
106 // Set new item state (scopes, cache skipping, etc) for a new item.
107 // TODO(pdr): This only passes a pointer to make the patch easier to review. Change to a reference.
108 void processNewItem(DisplayItem*);
109
85 void updateValidlyCachedClientsIfNeeded() const; 110 void updateValidlyCachedClientsIfNeeded() const;
86 111
87 #ifndef NDEBUG 112 #ifndef NDEBUG
88 WTF::String displayItemsAsDebugString(const DisplayItems&) const; 113 WTF::String displayItemsAsDebugString(const DisplayItems&) const;
89 #endif 114 #endif
90 115
91 // Indices into PaintList of all DrawingDisplayItems and BeginSubtreeDisplay Items of each client. 116 // Indices into PaintList of all DrawingDisplayItems and BeginSubtreeDisplay Items of each client.
92 // Temporarily used during merge to find out-of-order display items. 117 // Temporarily used during merge to find out-of-order display items.
93 using DisplayItemIndicesByClientMap = HashMap<DisplayItemClient, Vector<size _t>>; 118 using DisplayItemIndicesByClientMap = HashMap<DisplayItemClient, Vector<size _t>>;
94 119
95 static size_t findMatchingItemFromIndex(const DisplayItem::Id&, DisplayItem: :Type matchingType, const DisplayItemIndicesByClientMap&, const DisplayItems&); 120 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&); 121 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&) ; 122 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&); 123 DisplayItems::Iterator findOutOfOrderCachedItemForward(DisplayItems::Iterato r currentIt, const DisplayItem::Id&, DisplayItem::Type, DisplayItemIndicesByClie ntMap&);
99 124
100 #if ENABLE(ASSERT) 125 #if ENABLE(ASSERT)
101 // The following two methods are for checking under-invalidations 126 // The following two methods are for checking under-invalidations
102 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl ed). 127 // (when RuntimeEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabl ed).
103 void checkCachedDisplayItemIsUnchanged(const DisplayItems::ItemHandle&, Disp layItemIndicesByClientMap&); 128 void checkCachedDisplayItemIsUnchanged(const DisplayItem&, DisplayItemIndice sByClientMap&);
104 void checkNoRemainingCachedDisplayItems(); 129 void checkNoRemainingCachedDisplayItems();
105 #endif 130 #endif
106 131
107 void replay(GraphicsContext&) const; 132 void replay(GraphicsContext&);
108 133
109 DisplayItems m_currentDisplayItems; 134 DisplayItems m_currentDisplayItems;
110 DisplayItems m_newDisplayItems; 135 DisplayItems m_newDisplayItems;
111 136
112 // Contains all clients having valid cached paintings if updated. 137 // Contains all clients having valid cached paintings if updated.
113 // It's lazily updated in updateValidlyCachedClientsIfNeeded(). 138 // It's lazily updated in updateValidlyCachedClientsIfNeeded().
114 // FIXME: In the future we can replace this with client-side repaint flags 139 // 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. 140 // to avoid the cost of building and querying the hash table.
116 mutable HashSet<DisplayItemClient> m_validlyCachedClients; 141 mutable HashSet<DisplayItemClient> m_validlyCachedClients;
117 mutable bool m_validlyCachedClientsDirty; 142 mutable bool m_validlyCachedClientsDirty;
(...skipping 22 matching lines...) Expand all
140 // This is used to check duplicated ids during add(). We could also check du ring 165 // 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 166 // updatePaintList(), but checking during add() helps developer easily find where
142 // the duplicated ids are from. 167 // the duplicated ids are from.
143 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient; 168 DisplayItemIndicesByClientMap m_newDisplayItemIndicesByClient;
144 #endif 169 #endif
145 }; 170 };
146 171
147 } // namespace blink 172 } // namespace blink
148 173
149 #endif // DisplayItemList_h 174 #endif // DisplayItemList_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698