| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 PropertyTreeState_h | 5 #ifndef PropertyTreeState_h |
| 6 #define PropertyTreeState_h | 6 #define PropertyTreeState_h |
| 7 | 7 |
| 8 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 8 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 9 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 9 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
| 10 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 10 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 12 #include "wtf/HashFunctions.h" | 12 #include "wtf/HashFunctions.h" |
| 13 #include "wtf/HashTraits.h" | 13 #include "wtf/HashTraits.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 // A complete set of paint properties including those that are inherited from | 17 // A complete set of paint properties including those that are inherited from |
| 18 // other objects. RefPtrs are used to guard against use-after-free bugs and | 18 // other objects. RefPtrs are only used to guard against use-after-free bugs. |
| 19 // DCHECKs ensure PropertyTreeState never retains the last reference to a | |
| 20 // property tree node. | |
| 21 class PropertyTreeState { | 19 class PropertyTreeState { |
| 22 public: | 20 public: |
| 23 PropertyTreeState(const TransformPaintPropertyNode* transform, | 21 PropertyTreeState(const TransformPaintPropertyNode* transform, |
| 24 const ClipPaintPropertyNode* clip, | 22 const ClipPaintPropertyNode* clip, |
| 25 const EffectPaintPropertyNode* effect, | 23 const EffectPaintPropertyNode* effect, |
| 26 const ScrollPaintPropertyNode* scroll) | 24 const ScrollPaintPropertyNode* scroll) |
| 27 : m_transform(transform), | 25 : m_transform(transform), |
| 28 m_clip(clip), | 26 m_clip(clip), |
| 29 m_effect(effect), | 27 m_effect(effect), |
| 30 m_scroll(scroll) { | 28 m_scroll(scroll) { |
| 31 DCHECK(!m_transform || !m_transform->hasOneRef()); | 29 DCHECK(!m_transform || !m_transform->hasOneRef()); |
| 32 DCHECK(!m_clip || !m_clip->hasOneRef()); | 30 DCHECK(!m_clip || !m_clip->hasOneRef()); |
| 33 DCHECK(!m_effect || !m_effect->hasOneRef()); | 31 DCHECK(!m_effect || !m_effect->hasOneRef()); |
| 34 DCHECK(!m_scroll || !m_scroll->hasOneRef()); | 32 DCHECK(!m_scroll || !m_scroll->hasOneRef()); |
| 35 } | 33 } |
| 36 | 34 |
| 37 const TransformPaintPropertyNode* transform() const { | 35 const TransformPaintPropertyNode* transform() const { |
| 38 DCHECK(!m_transform || !m_transform->hasOneRef()); | |
| 39 return m_transform.get(); | 36 return m_transform.get(); |
| 40 } | 37 } |
| 41 void setTransform(const TransformPaintPropertyNode* node) { | 38 void setTransform(const TransformPaintPropertyNode* node) { |
| 42 m_transform = node; | 39 m_transform = node; |
| 43 DCHECK(!node->hasOneRef()); | 40 DCHECK(!node->hasOneRef()); |
| 44 } | 41 } |
| 45 | 42 |
| 46 const ClipPaintPropertyNode* clip() const { | 43 const ClipPaintPropertyNode* clip() const { |
| 47 DCHECK(!m_clip || !m_clip->hasOneRef()); | |
| 48 return m_clip.get(); | 44 return m_clip.get(); |
| 49 } | 45 } |
| 50 void setClip(const ClipPaintPropertyNode* node) { | 46 void setClip(const ClipPaintPropertyNode* node) { |
| 51 m_clip = node; | 47 m_clip = node; |
| 52 DCHECK(!node->hasOneRef()); | 48 DCHECK(!node->hasOneRef()); |
| 53 } | 49 } |
| 54 | 50 |
| 55 const EffectPaintPropertyNode* effect() const { | 51 const EffectPaintPropertyNode* effect() const { |
| 56 DCHECK(!m_effect || !m_effect->hasOneRef()); | |
| 57 return m_effect.get(); | 52 return m_effect.get(); |
| 58 } | 53 } |
| 59 void setEffect(const EffectPaintPropertyNode* node) { | 54 void setEffect(const EffectPaintPropertyNode* node) { |
| 60 m_effect = node; | 55 m_effect = node; |
| 61 DCHECK(!node->hasOneRef()); | 56 DCHECK(!node->hasOneRef()); |
| 62 } | 57 } |
| 63 | 58 |
| 64 const ScrollPaintPropertyNode* scroll() const { | 59 const ScrollPaintPropertyNode* scroll() const { |
| 65 DCHECK(!m_scroll || !m_scroll->hasOneRef()); | |
| 66 return m_scroll.get(); | 60 return m_scroll.get(); |
| 67 } | 61 } |
| 68 void setScroll(const ScrollPaintPropertyNode* node) { | 62 void setScroll(const ScrollPaintPropertyNode* node) { |
| 69 m_scroll = node; | 63 m_scroll = node; |
| 70 DCHECK(!node->hasOneRef()); | 64 DCHECK(!node->hasOneRef()); |
| 71 } | 65 } |
| 72 | 66 |
| 73 private: | 67 private: |
| 74 RefPtr<const TransformPaintPropertyNode> m_transform; | 68 RefPtr<const TransformPaintPropertyNode> m_transform; |
| 75 RefPtr<const ClipPaintPropertyNode> m_clip; | 69 RefPtr<const ClipPaintPropertyNode> m_clip; |
| 76 RefPtr<const EffectPaintPropertyNode> m_effect; | 70 RefPtr<const EffectPaintPropertyNode> m_effect; |
| 77 RefPtr<const ScrollPaintPropertyNode> m_scroll; | 71 RefPtr<const ScrollPaintPropertyNode> m_scroll; |
| 78 }; | 72 }; |
| 79 | 73 |
| 80 inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) { | 74 inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) { |
| 81 return a.transform() == b.transform() && a.clip() == b.clip() && | 75 return a.transform() == b.transform() && a.clip() == b.clip() && |
| 82 a.effect() == b.effect() && a.scroll() == b.scroll(); | 76 a.effect() == b.effect() && a.scroll() == b.scroll(); |
| 83 } | 77 } |
| 84 | 78 |
| 85 } // namespace blink | 79 } // namespace blink |
| 86 | 80 |
| 87 #endif // PropertyTreeState_h | 81 #endif // PropertyTreeState_h |
| OLD | NEW |