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/paint/DisplayItem.h" | 9 #include "platform/graphics/paint/DisplayItem.h" |
10 #include "wtf/HashSet.h" | 10 #include "wtf/HashMap.h" |
11 #include "wtf/PassOwnPtr.h" | 11 #include "wtf/PassOwnPtr.h" |
12 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class GraphicsContext; | 16 class GraphicsContext; |
17 | 17 |
18 typedef Vector<OwnPtr<DisplayItem>> PaintList; | 18 typedef Vector<OwnPtr<DisplayItem>> PaintList; |
19 | 19 |
20 class PLATFORM_EXPORT DisplayItemList { | 20 class PLATFORM_EXPORT DisplayItemList { |
21 WTF_MAKE_NONCOPYABLE(DisplayItemList); | 21 WTF_MAKE_NONCOPYABLE(DisplayItemList); |
22 WTF_MAKE_FAST_ALLOCATED; | 22 WTF_MAKE_FAST_ALLOCATED; |
23 public: | 23 public: |
24 static PassOwnPtr<DisplayItemList> create() { return adoptPtr(new DisplayIte mList); } | 24 static PassOwnPtr<DisplayItemList> create() { return adoptPtr(new DisplayIte mList); } |
25 | 25 |
26 void endNewPaints() { updatePaintList(); } | 26 void endNewPaints() { updatePaintList(); } |
27 | 27 |
28 const PaintList& paintList(); | 28 const PaintList& paintList(); |
29 void add(WTF::PassOwnPtr<DisplayItem>); | 29 void add(WTF::PassOwnPtr<DisplayItem>); |
30 | 30 |
31 void invalidate(DisplayItemClient); | 31 void invalidate(DisplayItemClient); |
32 void invalidateAll(); | 32 void invalidateAll(); |
33 bool clientCacheIsValid(DisplayItemClient) const; | 33 bool clientCacheIsValid(DisplayItemClient client) const { return m_cachedDis playItemsInfoByClient.contains(client); } |
34 | 34 |
35 // Plays back the current PaintList() into the given context. | 35 // Plays back the current PaintList() into the given context. |
36 void replay(GraphicsContext*); | 36 void replay(GraphicsContext*); |
37 | 37 |
38 #ifndef NDEBUG | 38 #ifndef NDEBUG |
39 void showDebugData() const; | 39 void showDebugData() const; |
40 #endif | 40 #endif |
41 | 41 |
42 protected: | 42 protected: |
43 DisplayItemList() { }; | 43 DisplayItemList() { }; |
44 | 44 |
45 private: | 45 private: |
46 PaintList::iterator findNextMatchingCachedItem(PaintList::iterator, const Di splayItem&); | 46 size_t findNextMatchingCachedItem(const DisplayItem&); |
47 bool wasInvalidated(const DisplayItem&) const; | |
48 void updatePaintList(); | 47 void updatePaintList(); |
49 | 48 |
50 #ifndef NDEBUG | 49 #ifndef NDEBUG |
51 WTF::String paintListAsDebugString(const PaintList&) const; | 50 WTF::String paintListAsDebugString(const PaintList&) const; |
51 WTF::String cachedDisplayItemsInfoByClientAsDebugString() const; | |
52 #endif | 52 #endif |
53 | 53 |
54 struct DisplayItemsInfo { | |
55 // A temporary offset of displayItemIndexes during updatePaintList() use d as the | |
56 // starting point to find the next matching cached display item of the c lient. | |
57 // This helps reduce the complexity of finding the next matching display item | |
58 // from O(m*n) to O(m*n). | |
chrishtr
2015/01/22 20:13:07
From O(m*n) to O(m*n)?
Xianzhu
2015/01/22 21:48:12
Sorry, this should be "From O(m*n) to O(m+n)". The
| |
59 // (m,n = number of existing/new display items of a client, respectively ). | |
60 size_t updateOffset; | |
61 | |
62 // Indexes into PaintList of all display items of a client. | |
63 Vector<size_t> displayItemIndexes; | |
64 }; | |
65 | |
66 typedef HashMap<DisplayItemClient, DisplayItemsInfo> DisplayItemsInfoByClien tMap; | |
67 static void appendDisplayItem(PaintList&, DisplayItemsInfoByClientMap&, WTF: :PassOwnPtr<DisplayItem>); | |
68 static void appendErrorIndicatorDisplayItem(PaintList&, DisplayItemsInfoByCl ientMap&, WTF::PassOwnPtr<DisplayItem>); | |
69 | |
54 PaintList m_paintList; | 70 PaintList m_paintList; |
55 HashSet<DisplayItemClient> m_cachedClients; | 71 DisplayItemsInfoByClientMap m_cachedDisplayItemsInfoByClient; |
56 PaintList m_newPaints; | 72 PaintList m_newPaints; |
57 }; | 73 }; |
58 | 74 |
59 } // namespace blink | 75 } // namespace blink |
60 | 76 |
61 #endif // DisplayItemList_h | 77 #endif // DisplayItemList_h |
OLD | NEW |