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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/DisplayItemClient.h

Issue 2095013003: Changes in DisplayItemClient for spv2 paint invalidation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes to DisplayItemClient Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 DisplayItemClient_h 5 #ifndef DisplayItemClient_h
6 #define DisplayItemClient_h 6 #define DisplayItemClient_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/geometry/LayoutRect.h" 9 #include "platform/geometry/LayoutRect.h"
10 #include "platform/graphics/PaintInvalidationReason.h"
10 #include "wtf/Assertions.h" 11 #include "wtf/Assertions.h"
11 #include "wtf/text/WTFString.h" 12 #include "wtf/text/WTFString.h"
12 13
13 #define CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS 1 14 #define CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS 1
14 // TODO(wangxianzhu): Restore the following line after we fix crbug.com/609218. 15 // TODO(wangxianzhu): Restore the following line after we fix crbug.com/609218.
15 // #define CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS DCHECK_IS_ON() 16 // #define CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS DCHECK_IS_ON()
16 17
17 namespace blink { 18 namespace blink {
18 19
19 // Holds a unique cache generation id of display items and paint controllers. 20 // Holds a unique cache generation id of display items and paint controllers.
20 // 21 //
21 // A paint controller sets its cache generation to DisplayItemCacheGeneration::n ext() 22 // A paint controller sets its cache generation to DisplayItemCacheGeneration::n ext()
22 // at the end of each commitNewDisplayItems, and updates the cache generation of each 23 // at the end of each commitNewDisplayItems, and updates the cache generation of each
23 // client with cached drawings by calling DisplayItemClient::setDisplayItemsCach ed(). 24 // client with cached drawings by calling DisplayItemClient::setDisplayItemsCach ed().
24 // A display item is treated as validly cached in a paint controller if its cach e generation 25 // A display item is treated as validly cached in a paint controller if its cach e generation
25 // matches the paint controller's cache generation. 26 // matches the paint controller's cache generation.
26 // 27 //
27 // SPv1 only: If a display item is painted on multiple paint controllers, becaus e cache 28 // SPv1 only: If a display item is painted on multiple paint controllers, becaus e cache
28 // generations are unique, the client's cache generation matches the last paint controller 29 // generations are unique, the client's cache generation matches the last paint controller
29 // only. The client will be treated as invalid on other paint controllers regard less if 30 // only. The client will be treated as invalid on other paint controllers regard less if
30 // it's validly cached by these paint controllers. The situation is very rare (a bout 0.07% 31 // it's validly cached by these paint controllers. The situation is very rare (a bout 0.07%
31 // clients were painted on multiple paint controllers) so the performance penalt y is trivial. 32 // clients were painted on multiple paint controllers) so the performance penalt y is trivial.
32 class PLATFORM_EXPORT DisplayItemCacheGeneration { 33 class PLATFORM_EXPORT DisplayItemCacheGeneration {
33 DISALLOW_NEW(); 34 DISALLOW_NEW();
34 public: 35 public:
35 DisplayItemCacheGeneration() : m_value(kInvalidGeneration) { } 36 DisplayItemCacheGeneration() { invalidate(); }
36 37
37 void invalidate() { m_value = kInvalidGeneration; } 38 void invalidate(PaintInvalidationReason reason = PaintInvalidationFull) { m_ value = static_cast<Generation>(reason); }
38 static DisplayItemCacheGeneration next() { return DisplayItemCacheGeneration (s_nextGeneration++); } 39
39 bool matches(const DisplayItemCacheGeneration& other) 40 static DisplayItemCacheGeneration next()
40 { 41 {
41 return m_value != kInvalidGeneration && other.m_value != kInvalidGenerat ion && m_value == other.m_value; 42 // In case the value overflowed in the previous call.
43 if (s_nextGeneration < kFirstValidGeneration)
pdr. 2016/06/27 18:55:04 I did some back-of-the-envelope math and this woul
Xianzhu 2016/06/27 20:02:19 There is analysis about cache generation overflow
44 s_nextGeneration = kFirstValidGeneration;
45 return DisplayItemCacheGeneration(s_nextGeneration++);
46 }
47
48 bool matches(const DisplayItemCacheGeneration& other) const
49 {
50 return m_value >= kFirstValidGeneration && other.m_value >= kFirstValidG eneration && m_value == other.m_value;
51 }
52
53 PaintInvalidationReason getPaintInvalidationReason() const
54 {
55 return m_value < kFirstValidGeneration ? static_cast<PaintInvalidationRe ason>(m_value) : PaintInvalidationNone;
42 } 56 }
43 57
44 private: 58 private:
45 typedef uint32_t Generation; 59 typedef uint32_t Generation;
46 DisplayItemCacheGeneration(Generation value) : m_value(value) { } 60 explicit DisplayItemCacheGeneration(Generation value) : m_value(value) { }
47 61
48 static const Generation kInvalidGeneration = 0; 62 static const Generation kFirstValidGeneration = static_cast<Generation>(Pain tInvalidationReasonMax) + 1;
49 static Generation s_nextGeneration; 63 static Generation s_nextGeneration;
50 Generation m_value; 64 Generation m_value;
51 }; 65 };
52 66
53 // The interface for objects that can be associated with display items. 67 // The class for objects that can be associated with display items.
54 // A DisplayItemClient object should live at least longer than the document cycl e 68 // A DisplayItemClient object should live at least longer than the document cycl e
55 // in which its display items are created during painting. 69 // in which its display items are created during painting.
56 // After the document cycle, a pointer/reference to DisplayItemClient should be 70 // After the document cycle, a pointer/reference to DisplayItemClient should be
57 // no longer dereferenced unless we can make sure the client is still valid. 71 // no longer dereferenced unless we can make sure the client is still valid.
58 class PLATFORM_EXPORT DisplayItemClient { 72 class PLATFORM_EXPORT DisplayItemClient {
59 public: 73 public:
60 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS 74 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS
61 DisplayItemClient(); 75 DisplayItemClient();
62 virtual ~DisplayItemClient(); 76 virtual ~DisplayItemClient();
63 77
64 // Tests if this DisplayItemClient object has been created and has not been deleted yet. 78 // Tests if this DisplayItemClient object has been created and has not been deleted yet.
65 bool isAlive() const; 79 bool isAlive() const;
66 // Called when any DisplayItem of this DisplayItemClient is added into Paint Controller 80 // Called when any DisplayItem of this DisplayItemClient is added into Paint Controller
67 // using PaintController::createAndAppend() or into a cached subsequence. 81 // using PaintController::createAndAppend() or into a cached subsequence.
68 void beginShouldKeepAlive(const void* owner) const; 82 void beginShouldKeepAlive(const void* owner) const;
69 // Clears all should-keep-alive DisplayItemClients of a PaintController. Cal led after 83 // Clears all should-keep-alive DisplayItemClients of a PaintController. Cal led after
70 // PaintController commits new display items or the subsequence owner is inv alidated. 84 // PaintController commits new display items or the subsequence owner is inv alidated.
71 static void endShouldKeepAliveAllClients(const void* owner); 85 static void endShouldKeepAliveAllClients(const void* owner);
72 static void endShouldKeepAliveAllClients(); 86 static void endShouldKeepAliveAllClients();
73
74 // Called to clear should-keep-alive of DisplayItemClients in a subsequence if this
75 // object is a subsequence.
76 #define ON_DISPLAY_ITEM_CLIENT_INVALIDATION() endShouldKeepAliveAllClients(this)
77 #else
78 virtual ~DisplayItemClient() { }
79 #define ON_DISPLAY_ITEM_CLIENT_INVALIDATION()
80 #endif 87 #endif
81 88
82 virtual String debugName() const = 0; 89 virtual String debugName() const = 0;
83 90
84 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e. 91 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e.
85 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). 92 // offset by offsetFromLayoutObjectWithSubpixelAccumulation().
86 virtual LayoutRect visualRect() const = 0; 93 virtual LayoutRect visualRect() const = 0;
87 94
88 virtual bool displayItemsAreCached(DisplayItemCacheGeneration) const = 0; 95 bool displayItemsAreCached(DisplayItemCacheGeneration cacheGeneration) const { return m_cacheGeneration.matches(cacheGeneration); }
89 virtual void setDisplayItemsCached(DisplayItemCacheGeneration) const = 0; 96 void setDisplayItemsCached(DisplayItemCacheGeneration cacheGeneration) const { m_cacheGeneration = cacheGeneration; }
90 virtual void setDisplayItemsUncached() const = 0; 97 void setDisplayItemsUncached(PaintInvalidationReason reason = PaintInvalidat ionFull) const
98 {
99 m_cacheGeneration.invalidate(reason);
100 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS
101 // Clear should-keep-alive of DisplayItemClients in a subsequence if thi s
102 // object is a subsequence.
103 endShouldKeepAliveAllClients(this);
104 #endif
105 }
106
107 PaintInvalidationReason getPaintInvalidationReason() const { return m_cacheG eneration.getPaintInvalidationReason(); }
108
109 private:
110 mutable DisplayItemCacheGeneration m_cacheGeneration;
pdr. 2016/06/27 18:55:04 It's confusing to me that we're using cache genera
Xianzhu 2016/06/27 20:02:19 I'm not sure if I understand your comment. I think
91 }; 111 };
92 112
93 #define DISPLAY_ITEM_CACHE_STATUS_IMPLEMENTATION \
94 bool displayItemsAreCached(DisplayItemCacheGeneration cacheGeneration) const final { return m_cacheGeneration.matches(cacheGeneration); } \
95 void setDisplayItemsCached(DisplayItemCacheGeneration cacheGeneration) const final { m_cacheGeneration = cacheGeneration; } \
96 void setDisplayItemsUncached() const final \
97 { \
98 m_cacheGeneration.invalidate(); \
99 ON_DISPLAY_ITEM_CLIENT_INVALIDATION(); \
100 } \
101 mutable DisplayItemCacheGeneration m_cacheGeneration;
102
103 #define DISPLAY_ITEM_CACHE_STATUS_UNCACHEABLE_IMPLEMENTATION \
104 bool displayItemsAreCached(DisplayItemCacheGeneration) const final { return false; } \
105 void setDisplayItemsCached(DisplayItemCacheGeneration) const final { } \
106 void setDisplayItemsUncached() const final { }
107
108 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; } 113 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; }
109 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; } 114 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; }
110 115
111 } // namespace blink 116 } // namespace blink
112 117
113 #endif // DisplayItemClient_h 118 #endif // DisplayItemClient_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698