• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "animation/rs_render_transition.h"
17 
18 #include "pipeline/rs_render_node.h"
19 #include "platform/common/rs_log.h"
20 #include "platform/common/rs_system_properties.h"
21 #include "transaction/rs_marshalling_helper.h"
22 
23 namespace OHOS {
24 namespace Rosen {
RSRenderTransition(AnimationId id,const std::vector<std::shared_ptr<RSRenderTransitionEffect>> & effects,bool isTransitionIn)25 RSRenderTransition::RSRenderTransition(
26     AnimationId id, const std::vector<std::shared_ptr<RSRenderTransitionEffect>>& effects, bool isTransitionIn)
27     : RSRenderAnimation(id), effects_(effects), isTransitionIn_(isTransitionIn)
28 {}
29 
DumpAnimationInfo(std::string & out) const30 void RSRenderTransition::DumpAnimationInfo(std::string& out) const
31 {
32     out.append("Type:RSRenderTransition");
33 }
34 
OnAnimate(float fraction)35 void RSRenderTransition::OnAnimate(float fraction)
36 {
37     float valueFraction = interpolator_->Interpolate(fraction);
38     if (isTransitionIn_) {
39         valueFraction = 1 - valueFraction;
40     }
41     for (auto& effect : effects_) {
42         effect->UpdateFraction(valueFraction);
43     }
44 }
45 
OnAttach()46 void RSRenderTransition::OnAttach()
47 {
48     auto target = GetTarget();
49     if (target == nullptr) {
50         ROSEN_LOGE("RSRenderTransition::OnAttach, target is nullptr");
51         return;
52     }
53     // create "transition" modifier and add it to target
54     for (auto& effect : effects_) {
55         const auto& modifier = effect->GetModifierNG();
56         if (modifier == nullptr) {
57             // custom effect may not have modifier
58             continue;
59         }
60         target->AddModifier(modifier);
61     }
62     // update number of disappearing transition animation
63     if (!isTransitionIn_) {
64         target->disappearingTransitionCount_++;
65         ROSEN_LOGD("RSRenderTransition::OnAttach, target have %{public}u disappearing Transitions",
66             target->disappearingTransitionCount_);
67     }
68 }
69 
OnDetach()70 void RSRenderTransition::OnDetach()
71 {
72     auto target = GetTarget();
73     if (target == nullptr) {
74         ROSEN_LOGE("RSRenderTransition::OnDetach, target is nullptr");
75         return;
76     }
77     // remove "transition" modifier from target
78     for (auto& effect : effects_) {
79         target->RemoveModifierNG(effect->GetModifierNG()->GetId());
80     }
81     // update number of disappearing transition animation
82     if (!isTransitionIn_) {
83         target->disappearingTransitionCount_--;
84         ROSEN_LOGD("RSRenderTransition::OnDetach, target have %{public}u disappearing Transitions",
85             target->disappearingTransitionCount_);
86         if (target->disappearingTransitionCount_ == 0) {
87             target->InternalRemoveSelfFromDisappearingChildren();
88         }
89     }
90 }
91 } // namespace Rosen
92 } // namespace OHOS
93