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

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: Rebase 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 // The class for objects that can be associated with display items.
20 //
21 // 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 // 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 // matches the paint controller's cache generation.
26 //
27 // 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 // 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 // clients were painted on multiple paint controllers) so the performance penalt y is trivial.
32 class PLATFORM_EXPORT DisplayItemCacheGeneration {
33 DISALLOW_NEW();
34 public:
35 DisplayItemCacheGeneration() : m_value(kInvalidGeneration) { }
36
37 void invalidate() { m_value = kInvalidGeneration; }
38 static DisplayItemCacheGeneration next() { return DisplayItemCacheGeneration (s_nextGeneration++); }
39 bool matches(const DisplayItemCacheGeneration& other)
40 {
41 return m_value != kInvalidGeneration && other.m_value != kInvalidGenerat ion && m_value == other.m_value;
42 }
43
44 private:
45 typedef uint32_t Generation;
46 DisplayItemCacheGeneration(Generation value) : m_value(value) { }
47
48 static const Generation kInvalidGeneration = 0;
49 static Generation s_nextGeneration;
50 Generation m_value;
51 };
52
53 // The interface for objects that can be associated with display items.
54 // A DisplayItemClient object should live at least longer than the document cycl e 21 // A DisplayItemClient object should live at least longer than the document cycl e
55 // in which its display items are created during painting. 22 // in which its display items are created during painting.
56 // After the document cycle, a pointer/reference to DisplayItemClient should be 23 // 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. 24 // no longer dereferenced unless we can make sure the client is still valid.
58 class PLATFORM_EXPORT DisplayItemClient { 25 class PLATFORM_EXPORT DisplayItemClient {
59 public: 26 public:
60 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS 27 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS
61 DisplayItemClient(); 28 DisplayItemClient();
62 virtual ~DisplayItemClient(); 29 virtual ~DisplayItemClient();
63 30
64 // Tests if this DisplayItemClient object has been created and has not been deleted yet. 31 // Tests if this DisplayItemClient object has been created and has not been deleted yet.
65 bool isAlive() const; 32 bool isAlive() const;
66 33
67 // Called when any DisplayItem of this DisplayItemClient is added into Paint Controller 34 // Called when any DisplayItem of this DisplayItemClient is added into Paint Controller
68 // using PaintController::createAndAppend() or into a cached subsequence. 35 // using PaintController::createAndAppend() or into a cached subsequence.
69 void beginShouldKeepAlive(const void* owner) const; 36 void beginShouldKeepAlive(const void* owner) const;
70 37
71 // Called when the DisplayItemClient is sure that it can safely die before i ts owners 38 // Called when the DisplayItemClient is sure that it can safely die before i ts owners
72 // have chance to remove it from the aliveness control. 39 // have chance to remove it from the aliveness control.
73 void endShouldKeepAlive() const; 40 void endShouldKeepAlive() const;
74 41
75 // Clears all should-keep-alive DisplayItemClients of a PaintController. Cal led after 42 // Clears all should-keep-alive DisplayItemClients of a PaintController. Cal led after
76 // PaintController commits new display items or the subsequence owner is inv alidated. 43 // PaintController commits new display items or the subsequence owner is inv alidated.
77 static void endShouldKeepAliveAllClients(const void* owner); 44 static void endShouldKeepAliveAllClients(const void* owner);
78 static void endShouldKeepAliveAllClients(); 45 static void endShouldKeepAliveAllClients();
79
80 // Called to clear should-keep-alive of DisplayItemClients in a subsequence if this
81 // object is a subsequence.
82 #define ON_DISPLAY_ITEM_CLIENT_INVALIDATION() endShouldKeepAliveAllClients(this)
83 #else
84 virtual ~DisplayItemClient() { }
85 #define ON_DISPLAY_ITEM_CLIENT_INVALIDATION()
86 #endif 46 #endif
87 47
88 virtual String debugName() const = 0; 48 virtual String debugName() const = 0;
89 49
90 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e. 50 // The visual rect of this DisplayItemClient, in object space of the object that owns the GraphicsLayer, i.e.
91 // offset by offsetFromLayoutObjectWithSubpixelAccumulation(). 51 // offset by offsetFromLayoutObjectWithSubpixelAccumulation().
92 virtual LayoutRect visualRect() const = 0; 52 virtual LayoutRect visualRect() const = 0;
93 53
94 virtual bool displayItemsAreCached(DisplayItemCacheGeneration) const = 0; 54 void setDisplayItemsUncached(PaintInvalidationReason reason = PaintInvalidat ionFull) const
95 virtual void setDisplayItemsCached(DisplayItemCacheGeneration) const = 0; 55 {
96 virtual void setDisplayItemsUncached() const = 0; 56 m_cacheGenerationOrInvalidationReason.invalidate(reason);
57 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS
58 // Clear should-keep-alive of DisplayItemClients in a subsequence if thi s
59 // object is a subsequence.
60 endShouldKeepAliveAllClients(this);
61 #endif
62 }
63
64 PaintInvalidationReason getPaintInvalidationReason() const { return m_cacheG enerationOrInvalidationReason.getPaintInvalidationReason(); }
65
66 private:
67 friend class PaintController;
68
69 // Holds a unique cache generation id of DisplayItemClients and PaintControl lers,
70 // or PaintInvalidationReason if the DisplayItemClient or PaintController is
71 // invalidated.
72 //
73 // A paint controller sets its cache generation to DisplayItemCacheGeneratio n::next()
74 // at the end of each commitNewDisplayItems, and updates the cache generatio n of each
75 // client with cached drawings by calling DisplayItemClient::setDisplayItems Cached().
76 // A display item is treated as validly cached in a paint controller if its cache generation
77 // matches the paint controller's cache generation.
78 //
79 // SPv1 only: If a display item is painted on multiple paint controllers, be cause cache
80 // generations are unique, the client's cache generation matches the last pa int controller
81 // only. The client will be treated as invalid on other paint controllers re gardless if
82 // it's validly cached by these paint controllers. The situation is very rar e (about 0.07%
83 // clients were painted on multiple paint controllers) so the performance pe nalty is trivial.
84 class CacheGenerationOrInvalidationReason {
85 DISALLOW_NEW();
86 public:
87 CacheGenerationOrInvalidationReason() { invalidate(); }
88
89 void invalidate(PaintInvalidationReason reason = PaintInvalidationFull) { m_value = static_cast<ValueType>(reason); }
90
91 static CacheGenerationOrInvalidationReason next()
92 {
93 // In case the value overflowed in the previous call.
94 if (s_nextGeneration < kFirstValidGeneration)
95 s_nextGeneration = kFirstValidGeneration;
96 return CacheGenerationOrInvalidationReason(s_nextGeneration++);
97 }
98
99 bool matches(const CacheGenerationOrInvalidationReason& other) const
100 {
101 return m_value >= kFirstValidGeneration && other.m_value >= kFirstVa lidGeneration && m_value == other.m_value;
102 }
103
104 PaintInvalidationReason getPaintInvalidationReason() const
105 {
106 return m_value < kFirstValidGeneration ? static_cast<PaintInvalidati onReason>(m_value) : PaintInvalidationNone;
107 }
108
109 private:
110 typedef uint32_t ValueType;
111 explicit CacheGenerationOrInvalidationReason(ValueType value) : m_value( value) { }
112
113 static const ValueType kFirstValidGeneration = static_cast<ValueType>(Pa intInvalidationReasonMax) + 1;
114 static ValueType s_nextGeneration;
115 ValueType m_value;
116 };
117
118 bool displayItemsAreCached(CacheGenerationOrInvalidationReason other) const { return m_cacheGenerationOrInvalidationReason.matches(other); }
119 void setDisplayItemsCached(CacheGenerationOrInvalidationReason cacheGenerati on) const { m_cacheGenerationOrInvalidationReason = cacheGeneration; }
120
121 mutable CacheGenerationOrInvalidationReason m_cacheGenerationOrInvalidationR eason;
97 }; 122 };
98 123
99 #define DISPLAY_ITEM_CACHE_STATUS_IMPLEMENTATION \
100 bool displayItemsAreCached(DisplayItemCacheGeneration cacheGeneration) const final { return m_cacheGeneration.matches(cacheGeneration); } \
101 void setDisplayItemsCached(DisplayItemCacheGeneration cacheGeneration) const final { m_cacheGeneration = cacheGeneration; } \
102 void setDisplayItemsUncached() const final \
103 { \
104 m_cacheGeneration.invalidate(); \
105 ON_DISPLAY_ITEM_CLIENT_INVALIDATION(); \
106 } \
107 mutable DisplayItemCacheGeneration m_cacheGeneration;
108
109 #define DISPLAY_ITEM_CACHE_STATUS_UNCACHEABLE_IMPLEMENTATION \
110 bool displayItemsAreCached(DisplayItemCacheGeneration) const final { return false; } \
111 void setDisplayItemsCached(DisplayItemCacheGeneration) const final { } \
112 void setDisplayItemsUncached() const final { }
113
114 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; } 124 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; }
115 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; } 125 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; }
116 126
117 } // namespace blink 127 } // namespace blink
118 128
119 #endif // DisplayItemClient_h 129 #endif // DisplayItemClient_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698