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
25 namespace OHOS {
26 namespace Rosen {
RSShowingPropertiesFreezer(NodeId id)27 RSShowingPropertiesFreezer::RSShowingPropertiesFreezer(NodeId id) : id_(id) {}
28
29 template<typename T, RSModifierType Type>
GetPropertyImpl() const30 std::optional<T> RSShowingPropertiesFreezer::GetPropertyImpl() const
31 {
32 auto node = RSNodeMap::Instance().GetNode<RSNode>(id_);
33 if (node == nullptr) {
34 return std::nullopt;
35 }
36 auto iter = node->propertyModifiers_.find(Type);
37 if (iter == node->propertyModifiers_.end()) {
38 ROSEN_LOGE(
39 "RSShowingPropertiesFreezer::GetPropertyImpl Type %d failed, no such property!", static_cast<int>(Type));
40 return std::nullopt;
41 }
42 auto property = std::static_pointer_cast<RSAnimatableProperty<T>>(iter->second->GetProperty());
43 if (property == nullptr) {
44 ROSEN_LOGE(
45 "RSShowingPropertiesFreezer::GetPropertyImpl Type %d failed, property is null!", static_cast<int>(Type));
46 return std::nullopt;
47 }
48 bool success = property->GetShowingValueAndCancelAnimation();
49 if (!success) {
50 ROSEN_LOGE("RSShowingPropertiesFreezer::GetPropertyImpl Type %d failed, cancel animation failed!",
51 static_cast<int>(Type));
52 return std::nullopt;
53 }
54 return property->Get();
55 }
56
GetBounds() const57 std::optional<Vector4f> RSShowingPropertiesFreezer::GetBounds() const
58 {
59 return GetPropertyImpl<Vector4f, RSModifierType::BOUNDS>();
60 }
61
GetFrame() const62 std::optional<Vector4f> RSShowingPropertiesFreezer::GetFrame() const
63 {
64 return GetPropertyImpl<Vector4f, RSModifierType::FRAME>();
65 }
66
GetPositionZ() const67 std::optional<float> RSShowingPropertiesFreezer::GetPositionZ() const
68 {
69 return GetPropertyImpl<float, RSModifierType::POSITION_Z>();
70 }
71
GetPivot() const72 std::optional<Vector2f> RSShowingPropertiesFreezer::GetPivot() const
73 {
74 return GetPropertyImpl<Vector2f, RSModifierType::PIVOT>();
75 }
76
GetPivotZ() const77 std::optional<float> RSShowingPropertiesFreezer::GetPivotZ() const
78 {
79 return GetPropertyImpl<float, RSModifierType::PIVOT_Z>();
80 }
81
GetQuaternion() const82 std::optional<Quaternion> RSShowingPropertiesFreezer::GetQuaternion() const
83 {
84 return GetPropertyImpl<Quaternion, RSModifierType::QUATERNION>();
85 }
86
GetRotation() const87 std::optional<float> RSShowingPropertiesFreezer::GetRotation() const
88 {
89 return GetPropertyImpl<float, RSModifierType::ROTATION>();
90 }
91
GetRotationX() const92 std::optional<float> RSShowingPropertiesFreezer::GetRotationX() const
93 {
94 return GetPropertyImpl<float, RSModifierType::ROTATION_X>();
95 }
96
GetRotationY() const97 std::optional<float> RSShowingPropertiesFreezer::GetRotationY() const
98 {
99 return GetPropertyImpl<float, RSModifierType::ROTATION_Y>();
100 }
101
GetCameraDistance() const102 std::optional<float> RSShowingPropertiesFreezer::GetCameraDistance() const
103 {
104 return GetPropertyImpl<float, RSModifierType::CAMERA_DISTANCE>();
105 }
106
GetTranslate() const107 std::optional<Vector2f> RSShowingPropertiesFreezer::GetTranslate() const
108 {
109 return GetPropertyImpl<Vector2f, RSModifierType::TRANSLATE>();
110 }
111
GetTranslateZ() const112 std::optional<float> RSShowingPropertiesFreezer::GetTranslateZ() const
113 {
114 return GetPropertyImpl<float, RSModifierType::TRANSLATE_Z>();
115 }
116
GetScale() const117 std::optional<Vector2f> RSShowingPropertiesFreezer::GetScale() const
118 {
119 return GetPropertyImpl<Vector2f, RSModifierType::SCALE>();
120 }
121
GetAlpha() const122 std::optional<float> RSShowingPropertiesFreezer::GetAlpha() const
123 {
124 return GetPropertyImpl<float, RSModifierType::ALPHA>();
125 }
126
GetCornerRadius() const127 std::optional<Vector4f> RSShowingPropertiesFreezer::GetCornerRadius() const
128 {
129 return GetPropertyImpl<Vector4f, RSModifierType::CORNER_RADIUS>();
130 }
131
GetForegroundColor() const132 std::optional<Color> RSShowingPropertiesFreezer::GetForegroundColor() const
133 {
134 return GetPropertyImpl<Color, RSModifierType::FOREGROUND_COLOR>();
135 }
136
GetBackgroundColor() const137 std::optional<Color> RSShowingPropertiesFreezer::GetBackgroundColor() const
138 {
139 return GetPropertyImpl<Color, RSModifierType::BACKGROUND_COLOR>();
140 }
141
GetSurfaceBgColor() const142 std::optional<Color> RSShowingPropertiesFreezer::GetSurfaceBgColor() const
143 {
144 return GetPropertyImpl<Color, RSModifierType::SURFACE_BG_COLOR>();
145 }
146
GetBgImageWidth() const147 std::optional<float> RSShowingPropertiesFreezer::GetBgImageWidth() const
148 {
149 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_WIDTH>();
150 }
151
GetBgImageHeight() const152 std::optional<float> RSShowingPropertiesFreezer::GetBgImageHeight() const
153 {
154 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_HEIGHT>();
155 }
156
GetBgImagePositionX() const157 std::optional<float> RSShowingPropertiesFreezer::GetBgImagePositionX() const
158 {
159 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_POSITION_X>();
160 }
161
GetBgImagePositionY() const162 std::optional<float> RSShowingPropertiesFreezer::GetBgImagePositionY() const
163 {
164 return GetPropertyImpl<float, RSModifierType::BG_IMAGE_POSITION_Y>();
165 }
166
GetBorderColor() const167 std::optional<Vector4<Color>> RSShowingPropertiesFreezer::GetBorderColor() const
168 {
169 return GetPropertyImpl<Vector4<Color>, RSModifierType::BORDER_COLOR>();
170 }
171
GetBorderWidth() const172 std::optional<Vector4f> RSShowingPropertiesFreezer::GetBorderWidth() const
173 {
174 return GetPropertyImpl<Vector4f, RSModifierType::BORDER_WIDTH>();
175 }
176
GetBackgroundFilter() const177 std::optional<std::shared_ptr<RSFilter>> RSShowingPropertiesFreezer::GetBackgroundFilter() const
178 {
179 return GetPropertyImpl<std::shared_ptr<RSFilter>, RSModifierType::BACKGROUND_FILTER>();
180 }
181
GetFilter() const182 std::optional<std::shared_ptr<RSFilter>> RSShowingPropertiesFreezer::GetFilter() const
183 {
184 return GetPropertyImpl<std::shared_ptr<RSFilter>, RSModifierType::FILTER>();
185 }
186
GetShadowColor() const187 std::optional<Color> RSShowingPropertiesFreezer::GetShadowColor() const
188 {
189 return GetPropertyImpl<Color, RSModifierType::SHADOW_COLOR>();
190 }
191
GetShadowOffsetX() const192 std::optional<float> RSShowingPropertiesFreezer::GetShadowOffsetX() const
193 {
194 return GetPropertyImpl<float, RSModifierType::SHADOW_OFFSET_X>();
195 }
196
GetShadowOffsetY() const197 std::optional<float> RSShowingPropertiesFreezer::GetShadowOffsetY() const
198 {
199 return GetPropertyImpl<float, RSModifierType::SHADOW_OFFSET_Y>();
200 }
201
GetShadowAlpha() const202 std::optional<float> RSShowingPropertiesFreezer::GetShadowAlpha() const
203 {
204 return GetPropertyImpl<float, RSModifierType::SHADOW_ALPHA>();
205 }
206
GetShadowElevation() const207 std::optional<float> RSShowingPropertiesFreezer::GetShadowElevation() const
208 {
209 return GetPropertyImpl<float, RSModifierType::SHADOW_ELEVATION>();
210 }
211
GetShadowRadius() const212 std::optional<float> RSShowingPropertiesFreezer::GetShadowRadius() const
213 {
214 return GetPropertyImpl<float, RSModifierType::SHADOW_RADIUS>();
215 }
216
GetSpherizeDegree() const217 std::optional<float> RSShowingPropertiesFreezer::GetSpherizeDegree() const
218 {
219 return GetPropertyImpl<float, RSModifierType::SPHERIZE>();
220 }
221
GetLightUpEffectDegree() const222 std::optional<float> RSShowingPropertiesFreezer::GetLightUpEffectDegree() const
223 {
224 return GetPropertyImpl<float, RSModifierType::LIGHT_UP_EFFECT>();
225 }
226 } // namespace Rosen
227 } // namespace OHOS
228