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