1 /*
2 * Copyright (c) 2021-2022 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 "animation/rs_transition_effect.h"
17
18 #include "animation/rs_render_transition_effect.h"
19 #include "platform/common/rs_log.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 constexpr float DEGREE_TO_RADIAN = M_PI / 180;
24
25 const std::shared_ptr<const RSTransitionEffect> RSTransitionEffect::OPACITY = RSTransitionEffect::Create()->Opacity(0);
26
27 const std::shared_ptr<const RSTransitionEffect> RSTransitionEffect::SCALE =
28 RSTransitionEffect::Create()->Scale({ 0.f, 0.f, 0.f });
29
30 const std::shared_ptr<const RSTransitionEffect> RSTransitionEffect::EMPTY = RSTransitionEffect::Create();
31
Create()32 std::shared_ptr<RSTransitionEffect> RSTransitionEffect::Create()
33 {
34 return std::shared_ptr<RSTransitionEffect>(new RSTransitionEffect());
35 }
36
Opacity(float opacity)37 std::shared_ptr<RSTransitionEffect> RSTransitionEffect::Opacity(float opacity)
38 {
39 if (opacity == 1.0f) {
40 ROSEN_LOGI("RSTransitionEffect::Opacity: Skip empty transition effect");
41 return shared_from_this();
42 }
43 auto opacityEffect = std::make_shared<RSTransitionFade>(opacity);
44 transitionInEffects_.push_back(opacityEffect);
45 transitionOutEffects_.push_back(opacityEffect);
46 return shared_from_this();
47 }
48
Scale(const Vector3f & scale)49 std::shared_ptr<RSTransitionEffect> RSTransitionEffect::Scale(const Vector3f& scale)
50 {
51 if (scale.x_ == 1.0f && scale.y_ == 1.0f && scale.z_ == 1.0f) {
52 ROSEN_LOGI("RSTransitionEffect::Scale: Skip empty transition effect");
53 return shared_from_this();
54 }
55 auto scaleEffect = std::make_shared<RSTransitionScale>(scale.x_, scale.y_, scale.z_);
56 transitionInEffects_.push_back(scaleEffect);
57 transitionOutEffects_.push_back(scaleEffect);
58 return shared_from_this();
59 }
60
Translate(const Vector3f & translate)61 std::shared_ptr<RSTransitionEffect> RSTransitionEffect::Translate(const Vector3f& translate)
62 {
63 if (translate.x_ == 0.0f && translate.y_ == 0.0f && translate.z_ == 0.0f) {
64 ROSEN_LOGI("RSTransitionEffect::Translate: Skip empty transition effect");
65 return shared_from_this();
66 }
67 auto translateEffect = std::make_shared<RSTransitionTranslate>(translate.x_, translate.y_, translate.z_);
68 transitionInEffects_.push_back(translateEffect);
69 transitionOutEffects_.push_back(translateEffect);
70 return shared_from_this();
71 }
72
Rotate(const Vector4f & axisAngle)73 std::shared_ptr<RSTransitionEffect> RSTransitionEffect::Rotate(const Vector4f& axisAngle)
74 {
75 if (axisAngle.w_ == 0.0f) {
76 ROSEN_LOGI("RSTransitionEffect::Rotate: Skip empty transition effect");
77 return shared_from_this();
78 }
79 auto angleRadian = axisAngle.w_ * DEGREE_TO_RADIAN;
80 auto rotateEffect = std::make_shared<RSTransitionRotate>(axisAngle.x_, axisAngle.y_, axisAngle.z_, angleRadian);
81 transitionInEffects_.push_back(rotateEffect);
82 transitionOutEffects_.push_back(rotateEffect);
83 return shared_from_this();
84 }
85
Asymmetric(const std::shared_ptr<RSTransitionEffect> & transitionIn,const std::shared_ptr<RSTransitionEffect> & transitionOut)86 std::shared_ptr<RSTransitionEffect> RSTransitionEffect::Asymmetric(
87 const std::shared_ptr<RSTransitionEffect>& transitionIn, const std::shared_ptr<RSTransitionEffect>& transitionOut)
88 {
89 return std::shared_ptr<RSTransitionEffect>(new RSTransitionEffect(transitionIn, transitionOut));
90 }
91
RSTransitionEffect(const std::shared_ptr<RSTransitionEffect> & transitionIn,const std::shared_ptr<RSTransitionEffect> & transitionOut)92 RSTransitionEffect::RSTransitionEffect(
93 const std::shared_ptr<RSTransitionEffect>& transitionIn, const std::shared_ptr<RSTransitionEffect>& transitionOut)
94 : transitionInEffects_(transitionIn->GetTransitionInEffects()),
95 transitionOutEffects_(transitionOut->GetTransitionOutEffects())
96 {}
97
GetTransitionInEffects() const98 const std::vector<std::shared_ptr<RSRenderTransitionEffect>>& RSTransitionEffect::GetTransitionInEffects() const
99 {
100 return transitionInEffects_;
101 }
102
GetTransitionOutEffects() const103 const std::vector<std::shared_ptr<RSRenderTransitionEffect>>& RSTransitionEffect::GetTransitionOutEffects() const
104 {
105 return transitionOutEffects_;
106 }
107 } // namespace Rosen
108 } // namespace OHOS
109