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 bool isJustCreated() const { return m_cacheGenerationOrInvalidationReason.is JustCreated(); } | |
pdr.
2016/07/15 19:11:28
Can you add a comment here?
Maybe something like:
Xianzhu
2016/07/15 23:48:00
Done.
| |
67 | |
66 private: | 68 private: |
69 friend class FakeDisplayItemClient; | |
67 friend class PaintController; | 70 friend class PaintController; |
68 | 71 |
69 // Holds a unique cache generation id of DisplayItemClients and PaintControl lers, | 72 // Holds a unique cache generation id of DisplayItemClients and PaintControl lers, |
70 // or PaintInvalidationReason if the DisplayItemClient or PaintController is | 73 // or PaintInvalidationReason if the DisplayItemClient or PaintController is |
71 // invalidated. | 74 // invalidated. |
72 // | 75 // |
73 // A paint controller sets its cache generation to DisplayItemCacheGeneratio n::next() | 76 // 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 | 77 // at the end of each commitNewDisplayItems, and updates the cache generatio n of each |
75 // client with cached drawings by calling DisplayItemClient::setDisplayItems Cached(). | 78 // 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 | 79 // A display item is treated as validly cached in a paint controller if its cache generation |
77 // matches the paint controller's cache generation. | 80 // matches the paint controller's cache generation. |
78 // | 81 // |
79 // SPv1 only: If a display item is painted on multiple paint controllers, be cause cache | 82 // 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 | 83 // 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 | 84 // 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% | 85 // 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. | 86 // clients were painted on multiple paint controllers) so the performance pe nalty is trivial. |
84 class CacheGenerationOrInvalidationReason { | 87 class CacheGenerationOrInvalidationReason { |
85 DISALLOW_NEW(); | 88 DISALLOW_NEW(); |
86 public: | 89 public: |
87 CacheGenerationOrInvalidationReason() { invalidate(); } | 90 CacheGenerationOrInvalidationReason() : m_value(kJustCreated) { } |
88 | 91 |
89 void invalidate(PaintInvalidationReason reason = PaintInvalidationFull) { m_value = static_cast<ValueType>(reason); } | 92 void invalidate(PaintInvalidationReason reason = PaintInvalidationFull) { m_value = static_cast<ValueType>(reason); } |
90 | 93 |
91 static CacheGenerationOrInvalidationReason next() | 94 static CacheGenerationOrInvalidationReason next() |
92 { | 95 { |
93 // In case the value overflowed in the previous call. | 96 // In case the value overflowed in the previous call. |
94 if (s_nextGeneration < kFirstValidGeneration) | 97 if (s_nextGeneration < kFirstValidGeneration) |
95 s_nextGeneration = kFirstValidGeneration; | 98 s_nextGeneration = kFirstValidGeneration; |
96 return CacheGenerationOrInvalidationReason(s_nextGeneration++); | 99 return CacheGenerationOrInvalidationReason(s_nextGeneration++); |
97 } | 100 } |
98 | 101 |
99 bool matches(const CacheGenerationOrInvalidationReason& other) const | 102 bool matches(const CacheGenerationOrInvalidationReason& other) const |
100 { | 103 { |
101 return m_value >= kFirstValidGeneration && other.m_value >= kFirstVa lidGeneration && m_value == other.m_value; | 104 return m_value >= kFirstValidGeneration && other.m_value >= kFirstVa lidGeneration && m_value == other.m_value; |
102 } | 105 } |
103 | 106 |
104 PaintInvalidationReason getPaintInvalidationReason() const | 107 PaintInvalidationReason getPaintInvalidationReason() const |
105 { | 108 { |
106 return m_value < kFirstValidGeneration ? static_cast<PaintInvalidati onReason>(m_value) : PaintInvalidationNone; | 109 return m_value < kJustCreated ? static_cast<PaintInvalidationReason> (m_value) : PaintInvalidationNone; |
107 } | 110 } |
108 | 111 |
112 bool isJustCreated() const { return m_value == kJustCreated; } | |
113 | |
109 private: | 114 private: |
110 typedef uint32_t ValueType; | 115 typedef uint32_t ValueType; |
111 explicit CacheGenerationOrInvalidationReason(ValueType value) : m_value( value) { } | 116 explicit CacheGenerationOrInvalidationReason(ValueType value) : m_value( value) { } |
112 | 117 |
113 static const ValueType kFirstValidGeneration = static_cast<ValueType>(Pa intInvalidationReasonMax) + 1; | 118 static const ValueType kJustCreated = static_cast<ValueType>(PaintInvali dationReasonMax) + 1; |
119 static const ValueType kFirstValidGeneration = static_cast<ValueType>(Pa intInvalidationReasonMax) + 2; | |
114 static ValueType s_nextGeneration; | 120 static ValueType s_nextGeneration; |
115 ValueType m_value; | 121 ValueType m_value; |
116 }; | 122 }; |
117 | 123 |
118 bool displayItemsAreCached(CacheGenerationOrInvalidationReason other) const { return m_cacheGenerationOrInvalidationReason.matches(other); } | 124 bool displayItemsAreCached(CacheGenerationOrInvalidationReason other) const { return m_cacheGenerationOrInvalidationReason.matches(other); } |
119 void setDisplayItemsCached(CacheGenerationOrInvalidationReason cacheGenerati on) const { m_cacheGenerationOrInvalidationReason = cacheGeneration; } | 125 void setDisplayItemsCached(CacheGenerationOrInvalidationReason cacheGenerati on) const { m_cacheGenerationOrInvalidationReason = cacheGeneration; } |
120 | 126 |
121 mutable CacheGenerationOrInvalidationReason m_cacheGenerationOrInvalidationR eason; | 127 mutable CacheGenerationOrInvalidationReason m_cacheGenerationOrInvalidationR eason; |
122 }; | 128 }; |
123 | 129 |
124 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; } | 130 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; } | 131 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; } |
126 | 132 |
127 } // namespace blink | 133 } // namespace blink |
128 | 134 |
129 #endif // DisplayItemClient_h | 135 #endif // DisplayItemClient_h |
OLD | NEW |