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