1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "modifier/rs_showing_properties_freezer.h"
17
18 #include <securec.h>
19
20 #include "modifier/rs_modifier_type.h"
21 #include "modifier/rs_property_modifier.h"
22 #include "pipeline/rs_node_map.h"
23 #include "ui/rs_node.h"
24 #include "platform/common/rs_log.h"
25
26 namespace OHOS {
27 namespace Rosen {
RSShowingPropertiesFreezer(NodeId id)28 RSShowingPropertiesFreezer::RSShowingPropertiesFreezer(NodeId id) : id_(id) {}
29
30 template<typename T, RSModifierType Type>
GetPropertyImpl() const31 std::optional<T> RSShowingPropertiesFreezer::GetPropertyImpl() const
32 {
33 auto node = RSNodeMap::Instance().GetNode<RSNode>(id_);
34 if (node == nullptr) {
35 return std::nullopt;
36 }
37 std::unique_lock<std::recursive_mutex> lock(node->propertyMutex_);
38 auto iter = node->propertyModifiers_.find(Type);
39 if (iter == node->propertyModifiers_.end()) {
40 ROSEN_LOGE(
41 "RSShowingPropertiesFreezer::GetPropertyImpl Type %{public}d failed, no such property!",
42 static_cast<int>(Type));
43 return std::nullopt;
44 }
45 auto property = std::static_pointer_cast<RSAnimatableProperty<T>>(iter->second->GetProperty());
46 if (property == nullptr) {
47 ROSEN_LOGE(
48 "RSShowingPropertiesFreezer::GetPropertyImpl Type %{public}d failed, property is null!",
49 static_cast<int>(Type));
50 return std::nullopt;
51 }
52 bool success = property->GetShowingValueAndCancelAnimation();
53 if (!success) {
54 ROSEN_LOGE("RSShowingPropertiesFreezer::GetPropertyImpl Type %{public}d failed, cancel animation failed!",
55 static_cast<int>(Type));
56 return std::nullopt;
57 }
58 return property->Get();
59 }
60
GetBounds() const61 std::optional<Vector4f> RSShowingPropertiesFreezer::GetBounds() const
62 {
63 return GetPropertyImpl<Vector4f, RSModifierType::BOUNDS>();
64 }
65
GetFrame() const66 std::optional<Vector4f> RSShowingPropertiesFreezer::GetFrame() const
67 {
68 return GetPropertyImpl<Vector4f, RSModifierType::FRAME>();
69 }
70
GetPositionZ() const71 std::optional<float> RSShowingPropertiesFreezer::GetPositionZ() const
72 {
73 return GetPropertyImpl<float, RSModifierType::POSITION_Z>();
74 }
75
GetPivot() const76 std::optional<Vector2f> RSShowingPropertiesFreezer::GetPivot() const
77 {
78 return GetPropertyImpl<Vector2f, RSModifierType::PIVOT>();
79 }
80
GetPivotZ() const81 std::optional<float> RSShowingPropertiesFreezer::GetPivotZ() const
82 {
83 return GetPropertyImpl<float, RSModifierType::PIVOT_Z>();
84 }
85
GetQuaternion() const86 std::optional<Quaternion> RSShowingPropertiesFreezer::GetQuaternion() const
87 {
88 return GetPropertyImpl<Quaternion, RSModifierType::QUATERNION>();
89 }
90
GetRotation() const91 std::optional<float> RSShowingPropertiesFreezer::GetRotation() const
92 {
93 return GetPropertyImpl<float, RSModifierType::ROTATION>();
94 }
95
GetRotationX() const96 std::optional<float> RSShowingPropertiesFreezer::GetRotationX() const
97 {
98 return GetPropertyImpl<float, RSModifierType::ROTATION_X>();
99 }
100
GetRotationY() const101 std::optional<float> RSShowingPropertiesFreezer::GetRotationY() const
102 {
103 return GetPropertyImpl<float, RSModifierType::ROTATION_Y>();
104 }
105
GetCameraDistance() const106 std::optional<float> RSShowingPropertiesFreezer::GetCameraDistance() const
107 {
108 return GetPropertyImpl<float, RSModifierType::CAMERA_DISTANCE>();
109 }
110
GetTranslate() const111 std::optional<Vector2f> RSShowingPropertiesFreezer::GetTranslate() const
112 {
113 return GetPropertyImpl<Vector2f, RSModifierType::TRANSLATE>();
114 }
115
GetTranslateZ() const116 std::optional<float> RSShowingPropertiesFreezer::GetTranslateZ() const
117 {
118 return GetPropertyImpl<float, RSModifierType::TRANSLATE_Z>();
119 }
120
GetScale() const121 std::optional<Vector2f> RSShowingPropertiesFreezer::GetScale() const
122 {
123 return GetPropertyImpl<Vector2f, RSModifierType::SCALE>();
124 }
125
GetSkew() const126 std::optional<Vector2f> RSShowingPropertiesFreezer::GetSkew() const
127 {
128 return GetPropertyImpl<Vector2f, RSModifierType::SKEW>();
129 }
130
GetPersp() const131 std::optional<Vector2f> RSShowingPropertiesFreezer::GetPersp() const
132 {
133 return GetPropertyImpl<Vector2f, RSModifierType::PERSP>();
134 }
135
GetAlpha() const136 std::optional<float> RSShowingPropertiesFreezer::GetAlpha() const
137 {
138 return GetPropertyImpl<float, RSModifierType::ALPHA>();
139 }
140
GetCornerRadius() const141 std::optional<Vector4f> RSShowingPropertiesFreezer::GetCornerRadius() const
142 {
143 return GetPropertyImpl<Vector4f, RSModifierType::CORNER_RADIUS>();
144 }
145
GetForegroundColor() const146 std::optional<Color> RSShowingPropertiesFreezer::GetForegroundColor() const
147 {
148 return GetPropertyImpl<Color, RSModifierType::FOREGROUND_COLOR>();
149 }
150
GetBackgroundColor() const151 std::optional<Color> RSShowingPropertiesFreezer::GetBackgroundColor() const
152 {
153 return GetPropertyImpl<Color, RSModifierType::BACKGROUND_COLOR>();
154 }
155
GetSurfaceBgColor() const156 std::optional<Color> RSShowingPropertiesFreezer::GetSurfaceBgColor() const
157 {
158 return GetPropertyImpl<Color, RSModifierType::SURFACE_BG_COLOR>();
159 }
160
GetBgImageWidth() const161 std::optional<float> RSShowingPropertiesFreezer::GetBgImageWidth() const
162 {
163 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_WIDTH>();
164 }
165
GetBgImageHeight() const166 std::optional<float> RSShowingPropertiesFreezer::GetBgImageHeight() const
167 {
168 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_HEIGHT>();
169 }
170
GetBgImagePositionX() const171 std::optional<float> RSShowingPropertiesFreezer::GetBgImagePositionX() const
172 {
173 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_POSITION_X>();
174 }
175
GetBgImagePositionY() const176 std::optional<float> RSShowingPropertiesFreezer::GetBgImagePositionY() const
177 {
178 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_POSITION_Y>();
179 }
180
GetBorderColor() const181 std::optional<Vector4<Color>> RSShowingPropertiesFreezer::GetBorderColor() const
182 {
183 return GetPropertyImpl<Vector4<Color>, RSModifierType::BORDER_COLOR>();
184 }
185
GetBorderWidth() const186 std::optional<Vector4f> RSShowingPropertiesFreezer::GetBorderWidth() const
187 {
188 return GetPropertyImpl<Vector4f, RSModifierType::BORDER_WIDTH>();
189 }
190
GetBackgroundFilter() const191 std::optional<std::shared_ptr<RSFilter>> RSShowingPropertiesFreezer::GetBackgroundFilter() const
192 {
193 return GetPropertyImpl<std::shared_ptr<RSFilter>, RSModifierType::BACKGROUND_FILTER>();
194 }
195
GetFilter() const196 std::optional<std::shared_ptr<RSFilter>> RSShowingPropertiesFreezer::GetFilter() const
197 {
198 return GetPropertyImpl<std::shared_ptr<RSFilter>, RSModifierType::FILTER>();
199 }
200
GetShadowColor() const201 std::optional<Color> RSShowingPropertiesFreezer::GetShadowColor() const
202 {
203 return GetPropertyImpl<Color, RSModifierType::SHADOW_COLOR>();
204 }
205
GetShadowOffsetX() const206 std::optional<float> RSShowingPropertiesFreezer::GetShadowOffsetX() const
207 {
208 return GetPropertyImpl<float, RSModifierType::SHADOW_OFFSET_X>();
209 }
210
GetShadowOffsetY() const211 std::optional<float> RSShowingPropertiesFreezer::GetShadowOffsetY() const
212 {
213 return GetPropertyImpl<float, RSModifierType::SHADOW_OFFSET_Y>();
214 }
215
GetShadowAlpha() const216 std::optional<float> RSShowingPropertiesFreezer::GetShadowAlpha() const
217 {
218 return GetPropertyImpl<float, RSModifierType::SHADOW_ALPHA>();
219 }
220
GetShadowElevation() const221 std::optional<float> RSShowingPropertiesFreezer::GetShadowElevation() const
222 {
223 return GetPropertyImpl<float, RSModifierType::SHADOW_ELEVATION>();
224 }
225
GetShadowRadius() const226 std::optional<float> RSShowingPropertiesFreezer::GetShadowRadius() const
227 {
228 return GetPropertyImpl<float, RSModifierType::SHADOW_RADIUS>();
229 }
230
GetSpherizeDegree() const231 std::optional<float> RSShowingPropertiesFreezer::GetSpherizeDegree() const
232 {
233 return GetPropertyImpl<float, RSModifierType::SPHERIZE>();
234 }
235
GetAttractionFractionValue() const236 std::optional<float> RSShowingPropertiesFreezer::GetAttractionFractionValue() const
237 {
238 return GetPropertyImpl<float, RSModifierType::ATTRACTION_FRACTION>();
239 }
240
GetAttractionDstPointValue() const241 std::optional<Vector2f> RSShowingPropertiesFreezer::GetAttractionDstPointValue() const
242 {
243 return GetPropertyImpl<Vector2f, RSModifierType::ATTRACTION_DSTPOINT>();
244 }
245
GetLightUpEffectDegree() const246 std::optional<float> RSShowingPropertiesFreezer::GetLightUpEffectDegree() const
247 {
248 return GetPropertyImpl<float, RSModifierType::LIGHT_UP_EFFECT>();
249 }
250
GetDynamicDimDegree() const251 std::optional<float> RSShowingPropertiesFreezer::GetDynamicDimDegree() const
252 {
253 return GetPropertyImpl<float, RSModifierType::DYNAMIC_DIM_DEGREE>();
254 }
255 } // namespace Rosen
256 } // namespace OHOS
257