OLD | NEW |
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 "platform/graphics/PaintInvalidationReason.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 m_cacheGenerationOrInvalidationReason.invalidate(reason); | 56 m_cacheGenerationOrInvalidationReason.invalidate(reason); |
57 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS | 57 #if CHECK_DISPLAY_ITEM_CLIENT_ALIVENESS |
58 // Clear should-keep-alive of DisplayItemClients in a subsequence if thi
s | 58 // Clear should-keep-alive of DisplayItemClients in a subsequence if thi
s |
59 // object is a subsequence. | 59 // object is a subsequence. |
60 endShouldKeepAliveAllClients(this); | 60 endShouldKeepAliveAllClients(this); |
61 #endif | 61 #endif |
62 } | 62 } |
63 | 63 |
64 PaintInvalidationReason getPaintInvalidationReason() const { return m_cacheG
enerationOrInvalidationReason.getPaintInvalidationReason(); } | 64 PaintInvalidationReason getPaintInvalidationReason() const { return m_cacheG
enerationOrInvalidationReason.getPaintInvalidationReason(); } |
65 | 65 |
66 // A client is considered "just created" if its display items have never bee
n committed. | |
67 bool isJustCreated() const { return m_cacheGenerationOrInvalidationReason.is
JustCreated(); } | |
68 | |
69 private: | 66 private: |
70 friend class FakeDisplayItemClient; | |
71 friend class PaintController; | 67 friend class PaintController; |
72 | 68 |
73 // Holds a unique cache generation id of DisplayItemClients and PaintControl
lers, | 69 // Holds a unique cache generation id of DisplayItemClients and PaintControl
lers, |
74 // or PaintInvalidationReason if the DisplayItemClient or PaintController is | 70 // or PaintInvalidationReason if the DisplayItemClient or PaintController is |
75 // invalidated. | 71 // invalidated. |
76 // | 72 // |
77 // A paint controller sets its cache generation to DisplayItemCacheGeneratio
n::next() | 73 // A paint controller sets its cache generation to DisplayItemCacheGeneratio
n::next() |
78 // at the end of each commitNewDisplayItems, and updates the cache generatio
n of each | 74 // at the end of each commitNewDisplayItems, and updates the cache generatio
n of each |
79 // client with cached drawings by calling DisplayItemClient::setDisplayItems
Cached(). | 75 // client with cached drawings by calling DisplayItemClient::setDisplayItems
Cached(). |
80 // A display item is treated as validly cached in a paint controller if its
cache generation | 76 // A display item is treated as validly cached in a paint controller if its
cache generation |
81 // matches the paint controller's cache generation. | 77 // matches the paint controller's cache generation. |
82 // | 78 // |
83 // SPv1 only: If a display item is painted on multiple paint controllers, be
cause cache | 79 // SPv1 only: If a display item is painted on multiple paint controllers, be
cause cache |
84 // generations are unique, the client's cache generation matches the last pa
int controller | 80 // generations are unique, the client's cache generation matches the last pa
int controller |
85 // only. The client will be treated as invalid on other paint controllers re
gardless if | 81 // only. The client will be treated as invalid on other paint controllers re
gardless if |
86 // it's validly cached by these paint controllers. The situation is very rar
e (about 0.07% | 82 // it's validly cached by these paint controllers. The situation is very rar
e (about 0.07% |
87 // clients were painted on multiple paint controllers) so the performance pe
nalty is trivial. | 83 // clients were painted on multiple paint controllers) so the performance pe
nalty is trivial. |
88 class PLATFORM_EXPORT CacheGenerationOrInvalidationReason { | 84 class CacheGenerationOrInvalidationReason { |
89 DISALLOW_NEW(); | 85 DISALLOW_NEW(); |
90 public: | 86 public: |
91 CacheGenerationOrInvalidationReason() : m_value(kJustCreated) { } | 87 CacheGenerationOrInvalidationReason() { invalidate(); } |
92 | 88 |
93 void invalidate(PaintInvalidationReason reason = PaintInvalidationFull) | 89 void invalidate(PaintInvalidationReason reason = PaintInvalidationFull)
{ m_value = static_cast<ValueType>(reason); } |
94 { | |
95 if (m_value != kJustCreated) | |
96 m_value = static_cast<ValueType>(reason); | |
97 } | |
98 | 90 |
99 static CacheGenerationOrInvalidationReason next() | 91 static CacheGenerationOrInvalidationReason next() |
100 { | 92 { |
101 // In case the value overflowed in the previous call. | 93 // In case the value overflowed in the previous call. |
102 if (s_nextGeneration < kFirstValidGeneration) | 94 if (s_nextGeneration < kFirstValidGeneration) |
103 s_nextGeneration = kFirstValidGeneration; | 95 s_nextGeneration = kFirstValidGeneration; |
104 return CacheGenerationOrInvalidationReason(s_nextGeneration++); | 96 return CacheGenerationOrInvalidationReason(s_nextGeneration++); |
105 } | 97 } |
106 | 98 |
107 bool matches(const CacheGenerationOrInvalidationReason& other) const | 99 bool matches(const CacheGenerationOrInvalidationReason& other) const |
108 { | 100 { |
109 return m_value >= kFirstValidGeneration && other.m_value >= kFirstVa
lidGeneration && m_value == other.m_value; | 101 return m_value >= kFirstValidGeneration && other.m_value >= kFirstVa
lidGeneration && m_value == other.m_value; |
110 } | 102 } |
111 | 103 |
112 PaintInvalidationReason getPaintInvalidationReason() const | 104 PaintInvalidationReason getPaintInvalidationReason() const |
113 { | 105 { |
114 return m_value < kJustCreated ? static_cast<PaintInvalidationReason>
(m_value) : PaintInvalidationNone; | 106 return m_value < kFirstValidGeneration ? static_cast<PaintInvalidati
onReason>(m_value) : PaintInvalidationNone; |
115 } | 107 } |
116 | 108 |
117 bool isJustCreated() const { return m_value == kJustCreated; } | |
118 | |
119 private: | 109 private: |
120 typedef uint32_t ValueType; | 110 typedef uint32_t ValueType; |
121 explicit CacheGenerationOrInvalidationReason(ValueType value) : m_value(
value) { } | 111 explicit CacheGenerationOrInvalidationReason(ValueType value) : m_value(
value) { } |
122 | 112 |
123 static const ValueType kJustCreated = static_cast<ValueType>(PaintInvali
dationReasonMax) + 1; | 113 static const ValueType kFirstValidGeneration = static_cast<ValueType>(Pa
intInvalidationReasonMax) + 1; |
124 static const ValueType kFirstValidGeneration = static_cast<ValueType>(Pa
intInvalidationReasonMax) + 2; | |
125 static ValueType s_nextGeneration; | 114 static ValueType s_nextGeneration; |
126 ValueType m_value; | 115 ValueType m_value; |
127 }; | 116 }; |
128 | 117 |
129 bool displayItemsAreCached(CacheGenerationOrInvalidationReason other) const
{ return m_cacheGenerationOrInvalidationReason.matches(other); } | 118 bool displayItemsAreCached(CacheGenerationOrInvalidationReason other) const
{ return m_cacheGenerationOrInvalidationReason.matches(other); } |
130 void setDisplayItemsCached(CacheGenerationOrInvalidationReason cacheGenerati
on) const { m_cacheGenerationOrInvalidationReason = cacheGeneration; } | 119 void setDisplayItemsCached(CacheGenerationOrInvalidationReason cacheGenerati
on) const { m_cacheGenerationOrInvalidationReason = cacheGeneration; } |
131 | 120 |
132 mutable CacheGenerationOrInvalidationReason m_cacheGenerationOrInvalidationR
eason; | 121 mutable CacheGenerationOrInvalidationReason m_cacheGenerationOrInvalidationR
eason; |
133 }; | 122 }; |
134 | 123 |
135 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; } |
136 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; } |
137 | 126 |
138 } // namespace blink | 127 } // namespace blink |
139 | 128 |
140 #endif // DisplayItemClient_h | 129 #endif // DisplayItemClient_h |
OLD | NEW |