• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ng/rs_modifier_ng.h"
21 #include "pipeline/rs_node_map.h"
22 #include "ui/rs_node.h"
23 #include "platform/common/rs_log.h"
24 
25 namespace OHOS {
26 namespace Rosen {
RSShowingPropertiesFreezer(NodeId id,std::shared_ptr<RSUIContext> rsUIContext)27 RSShowingPropertiesFreezer::RSShowingPropertiesFreezer(NodeId id, std::shared_ptr<RSUIContext> rsUIContext)
28     : id_(id), rsUIContext_(rsUIContext)
29 {}
30 
31 template<typename T, ModifierNG::RSModifierType ModifierType, ModifierNG::RSPropertyType PropertyType>
GetPropertyImplNG() const32 std::optional<T> RSShowingPropertiesFreezer::GetPropertyImplNG() const
33 {
34     auto context = rsUIContext_.lock();
35     auto node = context ? context->GetNodeMap().GetNode<RSNode>(id_) : RSNodeMap::Instance().GetNode<RSNode>(id_);
36     if (!node) {
37         return std::nullopt;
38     }
39     std::unique_lock<std::recursive_mutex> lock(node->propertyMutex_);
40     auto& modifier = node->modifiersNGCreatedBySetter_[static_cast<uint16_t>(ModifierType)];
41     if (!modifier) {
42         ROSEN_LOGE("RSShowingPropertiesFreezer::GetPropertyImplNG Type %{public}d failed, modifierNG is null!",
43             static_cast<int>(ModifierType));
44         return std::nullopt;
45     }
46     auto property = std::static_pointer_cast<RSAnimatableProperty<T>>(modifier->GetProperty(PropertyType));
47     if (!property) {
48         ROSEN_LOGE("RSShowingPropertiesFreezer::GetPropertyImplNG Type %{public}d failed, no such modifierNG!",
49             static_cast<int>(ModifierType));
50         return std::nullopt;
51     }
52     bool success = property->GetShowingValueAndCancelAnimation();
53     if (!success) {
54         ROSEN_LOGE("RSShowingPropertiesFreezer::GetPropertyImplNG Type %{public}d failed, cancel animation failed!",
55             static_cast<int>(PropertyType));
56         return std::nullopt;
57     }
58     return property->Get();
59 }
60 
GetBounds() const61 std::optional<Vector4f> RSShowingPropertiesFreezer::GetBounds() const
62 {
63     return GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::BOUNDS, ModifierNG::RSPropertyType::BOUNDS>();
64 }
65 
GetFrame() const66 std::optional<Vector4f> RSShowingPropertiesFreezer::GetFrame() const
67 {
68     return GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::FRAME, ModifierNG::RSPropertyType::FRAME>();
69 }
70 
GetPositionZ() const71 std::optional<float> RSShowingPropertiesFreezer::GetPositionZ() const
72 {
73     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::POSITION_Z>();
74 }
75 
GetPivot() const76 std::optional<Vector2f> RSShowingPropertiesFreezer::GetPivot() const
77 {
78     return GetPropertyImplNG<Vector2f, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::PIVOT>();
79 }
80 
GetPivotZ() const81 std::optional<float> RSShowingPropertiesFreezer::GetPivotZ() const
82 {
83     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::PIVOT_Z>();
84 }
85 
GetQuaternion() const86 std::optional<Quaternion> RSShowingPropertiesFreezer::GetQuaternion() const
87 {
88     return GetPropertyImplNG<Quaternion, ModifierNG::RSModifierType::TRANSFORM,
89         ModifierNG::RSPropertyType::QUATERNION>();
90 }
91 
GetRotation() const92 std::optional<float> RSShowingPropertiesFreezer::GetRotation() const
93 {
94     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::ROTATION>();
95 }
96 
GetRotationX() const97 std::optional<float> RSShowingPropertiesFreezer::GetRotationX() const
98 {
99     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::ROTATION_X>();
100 }
101 
GetRotationY() const102 std::optional<float> RSShowingPropertiesFreezer::GetRotationY() const
103 {
104     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::ROTATION_Y>();
105 }
106 
GetCameraDistance() const107 std::optional<float> RSShowingPropertiesFreezer::GetCameraDistance() const
108 {
109     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM,
110         ModifierNG::RSPropertyType::CAMERA_DISTANCE>();
111 }
112 
GetTranslate() const113 std::optional<Vector2f> RSShowingPropertiesFreezer::GetTranslate() const
114 {
115     return GetPropertyImplNG<Vector2f, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::TRANSLATE>();
116 }
117 
GetTranslateZ() const118 std::optional<float> RSShowingPropertiesFreezer::GetTranslateZ() const
119 {
120     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::TRANSLATE_Z>();
121 }
122 
GetScale() const123 std::optional<Vector2f> RSShowingPropertiesFreezer::GetScale() const
124 {
125     return GetPropertyImplNG<Vector2f, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::SCALE>();
126 }
127 
GetScaleZ() const128 std::optional<float> RSShowingPropertiesFreezer::GetScaleZ() const
129 {
130     return GetPropertyImplNG<float, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::SCALE_Z>();
131 }
132 
GetSkew() const133 std::optional<Vector3f> RSShowingPropertiesFreezer::GetSkew() const
134 {
135     return GetPropertyImplNG<Vector3f, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::SKEW>();
136 }
137 
GetPersp() const138 std::optional<Vector4f> RSShowingPropertiesFreezer::GetPersp() const
139 {
140     return GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::TRANSFORM, ModifierNG::RSPropertyType::PERSP>();
141 }
142 
GetAlpha() const143 std::optional<float> RSShowingPropertiesFreezer::GetAlpha() const
144 {
145     return GetPropertyImplNG<float, ModifierNG::RSModifierType::ALPHA, ModifierNG::RSPropertyType::ALPHA>();
146 }
147 
GetCornerRadius() const148 std::optional<Vector4f> RSShowingPropertiesFreezer::GetCornerRadius() const
149 {
150     return GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::CLIP_TO_BOUNDS,
151         ModifierNG::RSPropertyType::CORNER_RADIUS>();
152 }
153 
GetForegroundColor() const154 std::optional<Color> RSShowingPropertiesFreezer::GetForegroundColor() const
155 {
156     return GetPropertyImplNG<Color, ModifierNG::RSModifierType::FOREGROUND_COLOR,
157         ModifierNG::RSPropertyType::FOREGROUND_COLOR>();
158 }
159 
GetBackgroundColor() const160 std::optional<Color> RSShowingPropertiesFreezer::GetBackgroundColor() const
161 {
162     return GetPropertyImplNG<Color, ModifierNG::RSModifierType::BACKGROUND_COLOR,
163         ModifierNG::RSPropertyType::BACKGROUND_COLOR>();
164 }
165 
GetBgImageWidth() const166 std::optional<float> RSShowingPropertiesFreezer::GetBgImageWidth() const
167 {
168     auto rect = GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::BACKGROUND_IMAGE,
169         ModifierNG::RSPropertyType::BG_IMAGE_RECT>();
170     if (!rect.has_value()) {
171         return std::nullopt;
172     }
173     return rect.value()[2]; // 2 index of width
174 }
175 
GetBgImageHeight() const176 std::optional<float> RSShowingPropertiesFreezer::GetBgImageHeight() const
177 {
178     auto rect = GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::BACKGROUND_IMAGE,
179         ModifierNG::RSPropertyType::BG_IMAGE_RECT>();
180     if (!rect.has_value()) {
181         return std::nullopt;
182     }
183     return rect.value()[3]; // 3 index of height
184 }
185 
GetBgImagePositionX() const186 std::optional<float> RSShowingPropertiesFreezer::GetBgImagePositionX() const
187 {
188     auto rect = GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::BACKGROUND_IMAGE,
189         ModifierNG::RSPropertyType::BG_IMAGE_RECT>();
190     if (!rect.has_value()) {
191         return std::nullopt;
192     }
193     return rect.value()[0]; // 0 index of position x
194 }
195 
GetBgImagePositionY() const196 std::optional<float> RSShowingPropertiesFreezer::GetBgImagePositionY() const
197 {
198     auto rect = GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::BACKGROUND_IMAGE,
199         ModifierNG::RSPropertyType::BG_IMAGE_RECT>();
200     if (!rect.has_value()) {
201         return std::nullopt;
202     }
203     return rect.value()[1]; // 1 index of position y
204 }
205 
GetBorderColor() const206 std::optional<Vector4<Color>> RSShowingPropertiesFreezer::GetBorderColor() const
207 {
208     return GetPropertyImplNG<Vector4<Color>, ModifierNG::RSModifierType::BORDER,
209         ModifierNG::RSPropertyType::BORDER_COLOR>();
210 }
211 
GetBorderWidth() const212 std::optional<Vector4f> RSShowingPropertiesFreezer::GetBorderWidth() const
213 {
214     return GetPropertyImplNG<Vector4f, ModifierNG::RSModifierType::BORDER, ModifierNG::RSPropertyType::BORDER_WIDTH>();
215 }
216 
GetShadowColor() const217 std::optional<Color> RSShowingPropertiesFreezer::GetShadowColor() const
218 {
219     return GetPropertyImplNG<Color, ModifierNG::RSModifierType::SHADOW, ModifierNG::RSPropertyType::SHADOW_COLOR>();
220 }
221 
GetShadowOffsetX() const222 std::optional<float> RSShowingPropertiesFreezer::GetShadowOffsetX() const
223 {
224     return GetPropertyImplNG<float, ModifierNG::RSModifierType::SHADOW, ModifierNG::RSPropertyType::SHADOW_OFFSET_X>();
225 }
226 
GetShadowOffsetY() const227 std::optional<float> RSShowingPropertiesFreezer::GetShadowOffsetY() const
228 {
229     return GetPropertyImplNG<float, ModifierNG::RSModifierType::SHADOW, ModifierNG::RSPropertyType::SHADOW_OFFSET_Y>();
230 }
231 
GetShadowAlpha() const232 std::optional<float> RSShowingPropertiesFreezer::GetShadowAlpha() const
233 {
234     return GetPropertyImplNG<float, ModifierNG::RSModifierType::SHADOW, ModifierNG::RSPropertyType::SHADOW_ALPHA>();
235 }
236 
GetShadowElevation() const237 std::optional<float> RSShowingPropertiesFreezer::GetShadowElevation() const
238 {
239     return GetPropertyImplNG<float, ModifierNG::RSModifierType::SHADOW, ModifierNG::RSPropertyType::SHADOW_ELEVATION>();
240 }
241 
GetShadowRadius() const242 std::optional<float> RSShowingPropertiesFreezer::GetShadowRadius() const
243 {
244     return GetPropertyImplNG<float, ModifierNG::RSModifierType::SHADOW, ModifierNG::RSPropertyType::SHADOW_RADIUS>();
245 }
246 
GetSpherizeDegree() const247 std::optional<float> RSShowingPropertiesFreezer::GetSpherizeDegree() const
248 {
249     return GetPropertyImplNG<float, ModifierNG::RSModifierType::FOREGROUND_FILTER,
250         ModifierNG::RSPropertyType::SPHERIZE>();
251 }
252 
GetHDRUIBrightness() const253 std::optional<float> RSShowingPropertiesFreezer::GetHDRUIBrightness() const
254 {
255     return GetPropertyImplNG<float, ModifierNG::RSModifierType::HDR_BRIGHTNESS,
256         ModifierNG::RSPropertyType::HDR_UI_BRIGHTNESS>();
257 }
258 
GetAttractionFractionValue() const259 std::optional<float> RSShowingPropertiesFreezer::GetAttractionFractionValue() const
260 {
261     return GetPropertyImplNG<float, ModifierNG::RSModifierType::FOREGROUND_FILTER,
262         ModifierNG::RSPropertyType::ATTRACTION_FRACTION>();
263 }
264 
GetAttractionDstPointValue() const265 std::optional<Vector2f> RSShowingPropertiesFreezer::GetAttractionDstPointValue() const
266 {
267     return GetPropertyImplNG<Vector2f, ModifierNG::RSModifierType::FOREGROUND_FILTER,
268         ModifierNG::RSPropertyType::ATTRACTION_DSTPOINT>();
269 }
270 
GetLightUpEffectDegree() const271 std::optional<float> RSShowingPropertiesFreezer::GetLightUpEffectDegree() const
272 {
273     return GetPropertyImplNG<float, ModifierNG::RSModifierType::COMPOSITING_FILTER,
274         ModifierNG::RSPropertyType::LIGHT_UP_EFFECT_DEGREE>();
275 }
276 
GetDynamicDimDegree() const277 std::optional<float> RSShowingPropertiesFreezer::GetDynamicDimDegree() const
278 {
279     return GetPropertyImplNG<float, ModifierNG::RSModifierType::COMPOSITING_FILTER,
280         ModifierNG::RSPropertyType::DYNAMIC_DIM_DEGREE>();
281 }
282 } // namespace Rosen
283 } // namespace OHOS
284