1 /*
2 * Copyright (c) 2025 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_ng/geometry/rs_transform_render_modifier.h"
17
18 #include "pipeline/rs_render_node.h"
19
20 namespace OHOS::Rosen::ModifierNG {
21 const RSTransformRenderModifier::LegacyPropertyApplierMap RSTransformRenderModifier::LegacyPropertyApplierMap_ = {
22 { RSPropertyType::SANDBOX, RSRenderModifier::PropertyApplyHelper<Vector2f, &RSProperties::SetSandBox> },
23 { RSPropertyType::POSITION_Z,
24 RSRenderModifier::PropertyApplyHelperAdd<float, &RSProperties::SetPositionZ, &RSProperties::GetPositionZ> },
25 { RSPropertyType::POSITION_Z_APPLICABLE_CAMERA3D,
26 RSRenderModifier::PropertyApplyHelper<bool, &RSProperties::SetPositionZApplicableCamera3D> },
27 { RSPropertyType::PIVOT, RSRenderModifier::PropertyApplyHelper<Vector2f, &RSProperties::SetPivot> },
28 { RSPropertyType::PIVOT_Z, RSRenderModifier::PropertyApplyHelper<float, &RSProperties::SetPivotZ> },
29 { RSPropertyType::QUATERNION, RSRenderModifier::PropertyApplyHelper<Quaternion, &RSProperties::SetQuaternion> },
30 { RSPropertyType::ROTATION,
31 RSRenderModifier::PropertyApplyHelperAdd<float, &RSProperties::SetRotation, &RSProperties::GetRotation> },
32 { RSPropertyType::ROTATION_X,
33 RSRenderModifier::PropertyApplyHelperAdd<float, &RSProperties::SetRotationX, &RSProperties::GetRotationX> },
34 { RSPropertyType::ROTATION_Y,
35 RSRenderModifier::PropertyApplyHelperAdd<float, &RSProperties::SetRotationY, &RSProperties::GetRotationY> },
36 { RSPropertyType::CAMERA_DISTANCE, RSRenderModifier::PropertyApplyHelper<float, &RSProperties::SetCameraDistance> },
37 { RSPropertyType::TRANSLATE,
38 PropertyApplyHelperAdd<Vector2f, &RSProperties::SetTranslate, &RSProperties::GetTranslate> },
39 { RSPropertyType::TRANSLATE_Z,
40 PropertyApplyHelperAdd<float, &RSProperties::SetTranslateZ, &RSProperties::GetTranslateZ> },
41 { RSPropertyType::SCALE,
42 RSRenderModifier::PropertyApplyHelperMultiply<Vector2f, &RSProperties::SetScale, &RSProperties::GetScale> },
43 { RSPropertyType::SCALE_Z,
44 RSRenderModifier::PropertyApplyHelperMultiply<float, &RSProperties::SetScaleZ, &RSProperties::GetScaleZ> },
45 { RSPropertyType::SKEW,
46 RSRenderModifier::PropertyApplyHelperAdd<Vector3f, &RSProperties::SetSkew, &RSProperties::GetSkew> },
47 { RSPropertyType::PERSP, RSRenderModifier::PropertyApplyHelper<Vector4f, &RSProperties::SetPersp> },
48 };
49
ResetProperties(RSProperties & properties)50 void RSTransformRenderModifier::ResetProperties(RSProperties& properties)
51 {
52 properties.ResetSandBox();
53 properties.SetPositionZ(0.f);
54 properties.SetPositionZApplicableCamera3D(false);
55 properties.SetPivot(Vector2f(0.5f, 0.5f));
56 properties.SetPivotZ(0.f);
57 properties.SetQuaternion(Quaternion());
58 properties.SetRotation(0.f);
59 properties.SetRotationX(0.f);
60 properties.SetRotationY(0.f);
61 properties.SetCameraDistance(0.f);
62 properties.SetTranslate(Vector2f());
63 properties.SetTranslateZ(0.f);
64 properties.SetScale(Vector2f(1.f, 1.f));
65 properties.SetScaleZ(1.f);
66 properties.SetSkew(Vector3f());
67 properties.SetPersp(Vector4f(0.f, 0.f, 0.f, 1.f));
68 }
69
OnSetDirty()70 void RSTransformRenderModifier::OnSetDirty()
71 {
72 if (!HasProperty(RSPropertyType::POSITION_Z)) {
73 return;
74 }
75 if (auto node = target_.lock()) {
76 node->MarkNonGeometryChanged();
77 node->MarkParentNeedRegenerateChildren();
78 }
79 }
80 } // namespace OHOS::Rosen::ModifierNG
81