xref: /aosp_15_r20/external/skia/modules/skottie/src/SkottieProperty.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "modules/skottie/include/SkottieProperty.h"
9 
10 #include "modules/skottie/src/SkottiePriv.h"
11 #include "modules/skottie/src/Transform.h"
12 #include "modules/skottie/src/text/TextAdapter.h"
13 #include "modules/sksg/include/SkSGOpacityEffect.h"
14 #include "modules/sksg/include/SkSGPaint.h"
15 
16 namespace skottie {
17 
operator ==(const TextPropertyValue & other) const18 bool TextPropertyValue::operator==(const TextPropertyValue& other) const {
19     return fTypeface == other.fTypeface
20         && fText == other.fText
21         && fTextSize == other.fTextSize
22         && fStrokeWidth == other.fStrokeWidth
23         && fLineHeight == other.fLineHeight
24         && fLineShift == other.fLineShift
25         && fAscent == other.fAscent
26         && fMaxLines == other.fMaxLines
27         && fHAlign == other.fHAlign
28         && fVAlign == other.fVAlign
29         && fResize == other.fResize
30         && fLineBreak == other.fLineBreak
31         && fDirection == other.fDirection
32         && fCapitalization == other.fCapitalization
33         && fBox == other.fBox
34         && fFillColor == other.fFillColor
35         && fStrokeColor == other.fStrokeColor
36         && fPaintOrder == other.fPaintOrder
37         && fStrokeJoin == other.fStrokeJoin
38         && fHasFill == other.fHasFill
39         && fHasStroke == other.fHasStroke
40         && fDecorator == other.fDecorator
41         && fLocale == other.fLocale
42         && fFontFamily == other.fFontFamily;
43 }
44 
operator !=(const TextPropertyValue & other) const45 bool TextPropertyValue::operator!=(const TextPropertyValue& other) const {
46     return !(*this== other);
47 }
48 
operator ==(const TransformPropertyValue & other) const49 bool TransformPropertyValue::operator==(const TransformPropertyValue& other) const {
50     return this->fAnchorPoint == other.fAnchorPoint
51         && this->fPosition    == other.fPosition
52         && this->fScale       == other.fScale
53         && this->fSkew        == other.fSkew
54         && this->fSkewAxis    == other.fSkewAxis;
55 }
56 
operator !=(const TransformPropertyValue & other) const57 bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const {
58     return !(*this == other);
59 }
60 
61 // The SK_API attributes are important here due o them being declared as a template.
62 
63 template <> SK_API
PropertyHandle(sk_sp<sksg::Color> node)64 ColorPropertyHandle::PropertyHandle(sk_sp<sksg::Color> node)
65     : fNode(std::move(node)), fRevalidator(nullptr) {}
66 
67 template <> SK_API
PropertyHandle(const ColorPropertyHandle & other)68 ColorPropertyHandle::PropertyHandle(const ColorPropertyHandle& other)
69     : fNode(other.fNode), fRevalidator(other.fRevalidator) {}
70 
71 template <> SK_API
~PropertyHandle()72 ColorPropertyHandle::~PropertyHandle() {}
73 
74 template <> SK_API
get() const75 ColorPropertyValue ColorPropertyHandle::get() const {
76     return fNode->getColor();
77 }
78 
79 template <> SK_API
set(const ColorPropertyValue & c)80 void ColorPropertyHandle::set(const ColorPropertyValue& c) {
81     fNode->setColor(c);
82 
83     if (fRevalidator) {
84         fRevalidator->revalidate();
85     }
86 }
87 
88 template <> SK_API
PropertyHandle(sk_sp<sksg::OpacityEffect> node)89 OpacityPropertyHandle::PropertyHandle(sk_sp<sksg::OpacityEffect> node)
90     : fNode(std::move(node)), fRevalidator(nullptr) {}
91 
92 template <> SK_API
PropertyHandle(const OpacityPropertyHandle & other)93 OpacityPropertyHandle::PropertyHandle(const OpacityPropertyHandle& other)
94     : fNode(other.fNode), fRevalidator(other.fRevalidator) {}
95 
96 template <> SK_API
~PropertyHandle()97 OpacityPropertyHandle::~PropertyHandle() {}
98 
99 template <> SK_API
get() const100 OpacityPropertyValue OpacityPropertyHandle::get() const {
101     return fNode->getOpacity() * 100;
102 }
103 
104 template <> SK_API
set(const OpacityPropertyValue & o)105 void OpacityPropertyHandle::set(const OpacityPropertyValue& o) {
106     fNode->setOpacity(o / 100);
107 
108     if (fRevalidator) {
109         fRevalidator->revalidate();
110     }
111 }
112 
113 template <> SK_API
PropertyHandle(sk_sp<internal::TextAdapter> node)114 TextPropertyHandle::PropertyHandle(sk_sp<internal::TextAdapter> node)
115     : fNode(std::move(node)), fRevalidator(nullptr) {}
116 
117 template <> SK_API
PropertyHandle(const TextPropertyHandle & other)118 TextPropertyHandle::PropertyHandle(const TextPropertyHandle& other)
119     : fNode(other.fNode), fRevalidator(other.fRevalidator) {}
120 
121 template <> SK_API
~PropertyHandle()122 TextPropertyHandle::~PropertyHandle() {}
123 
124 template <> SK_API
get() const125 TextPropertyValue TextPropertyHandle::get() const {
126     return fNode->getText();
127 }
128 
129 template<> SK_API
set(const TextPropertyValue & t)130 void TextPropertyHandle::set(const TextPropertyValue& t) {
131     fNode->setText(t);
132 
133     if (fRevalidator) {
134         fRevalidator->revalidate();
135     }
136 }
137 
138 template <> SK_API
PropertyHandle(sk_sp<internal::TransformAdapter2D> node)139 TransformPropertyHandle::PropertyHandle(sk_sp<internal::TransformAdapter2D> node)
140     : fNode(std::move(node)), fRevalidator(nullptr) {}
141 
142 template <> SK_API
PropertyHandle(const TransformPropertyHandle & other)143 TransformPropertyHandle::PropertyHandle(const TransformPropertyHandle& other)
144     : fNode(other.fNode), fRevalidator(other.fRevalidator) {}
145 
146 template <> SK_API
~PropertyHandle()147 TransformPropertyHandle::~PropertyHandle() {}
148 
149 template <> SK_API
get() const150 TransformPropertyValue TransformPropertyHandle::get() const {
151     return {
152         fNode->getAnchorPoint(),
153         fNode->getPosition(),
154         fNode->getScale(),
155         fNode->getRotation(),
156         fNode->getSkew(),
157         fNode->getSkewAxis()
158     };
159 }
160 
161 template <> SK_API
set(const TransformPropertyValue & t)162 void TransformPropertyHandle::set(const TransformPropertyValue& t) {
163     fNode->setAnchorPoint(t.fAnchorPoint);
164     fNode->setPosition(t.fPosition);
165     fNode->setScale(t.fScale);
166     fNode->setRotation(t.fRotation);
167     fNode->setSkew(t.fSkew);
168     fNode->setSkewAxis(t.fSkewAxis);
169 
170     if (fRevalidator) {
171         fRevalidator->revalidate();
172     }
173 }
174 
onColorProperty(const char[],const LazyHandle<ColorPropertyHandle> &)175 void PropertyObserver::onColorProperty(const char[],
176                                        const LazyHandle<ColorPropertyHandle>&) {}
177 
onOpacityProperty(const char[],const LazyHandle<OpacityPropertyHandle> &)178 void PropertyObserver::onOpacityProperty(const char[],
179                                          const LazyHandle<OpacityPropertyHandle>&) {}
180 
onTextProperty(const char[],const LazyHandle<TextPropertyHandle> &)181 void PropertyObserver::onTextProperty(const char[],
182                                       const LazyHandle<TextPropertyHandle>&) {}
183 
onTransformProperty(const char[],const LazyHandle<TransformPropertyHandle> &)184 void PropertyObserver::onTransformProperty(const char[],
185                                            const LazyHandle<TransformPropertyHandle>&) {}
186 
onEnterNode(const char node_name[],NodeType)187 void PropertyObserver::onEnterNode(const char node_name[], NodeType) {}
188 
onLeavingNode(const char node_name[],NodeType)189 void PropertyObserver::onLeavingNode(const char node_name[], NodeType) {}
190 
191 }  // namespace skottie
192