• 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 #ifndef RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H
18 
19 #include <list>
20 #include <memory>
21 #include <unordered_map>
22 
23 #include "common/rs_common_def.h"
24 #include "common/rs_macros.h"
25 #include "modifier/rs_modifier_type.h"
26 #include "rs_animation_rate_decider.h"
27 #include "rs_frame_rate_range.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 class RSDirtyRegionManager;
32 class RSPaintFilterCanvas;
33 class RSProperties;
34 class RSRenderAnimation;
35 class RSRenderNode;
36 
37 class RSB_EXPORT RSAnimationManager {
38 public:
39     RSAnimationManager() = default;
40     RSAnimationManager(const RSAnimationManager&) = delete;
41     RSAnimationManager(const RSAnimationManager&&) = delete;
42     RSAnimationManager& operator=(const RSAnimationManager&) = delete;
43     RSAnimationManager& operator=(const RSAnimationManager&&) = delete;
44     ~RSAnimationManager() = default;
45 
46     void DumpAnimations(std::string& out) const;
47     void AddAnimation(const std::shared_ptr<RSRenderAnimation>& animation);
48     void RemoveAnimation(AnimationId keyId);
49     void CancelAnimationByPropertyId(PropertyId id);
50     const std::shared_ptr<RSRenderAnimation> GetAnimation(AnimationId id) const;
51     void FilterAnimationByPid(pid_t pid);
52     uint32_t GetAnimationsSize();
53 
54     std::tuple<bool, bool, bool> Animate(int64_t time, bool nodeIsOnTheTree);
55 
56     // spring animation related
57     void RegisterSpringAnimation(PropertyId propertyId, AnimationId animId);
58     void UnregisterSpringAnimation(PropertyId propertyId, AnimationId animId);
59     std::shared_ptr<RSRenderAnimation> QuerySpringAnimation(PropertyId propertyId);
60     // path animation related
61     void RegisterPathAnimation(PropertyId propertyId, AnimationId animId);
62     void UnregisterPathAnimation(PropertyId propertyId, AnimationId animId);
63     std::shared_ptr<RSRenderAnimation> QueryPathAnimation(PropertyId propertyId);
64     // particle animation related
65     void RegisterParticleAnimation(PropertyId propertyId, AnimationId animId);
66     void UnregisterParticleAnimation(PropertyId propertyId, AnimationId animId);
67     const std::unordered_map<PropertyId, AnimationId>& GetParticleAnimations();
68 
69     const FrameRateRange& GetFrameRateRange() const;
70     const FrameRateRange& GetDecideFrameRateRange() const;
71 
72     void SetRateDeciderEnable(bool enabled, const FrameRateGetFunc& func);
73     void SetRateDeciderScaleSize(float width, float height);
74 
75 private:
76     void OnAnimationFinished(const std::shared_ptr<RSRenderAnimation>& animation);
77 
78     std::unordered_map<AnimationId, std::shared_ptr<RSRenderAnimation>> animations_;
79     std::unordered_map<PropertyId, AnimationId> springAnimations_;
80     std::unordered_map<PropertyId, AnimationId> pathAnimations_;
81     std::unordered_map<PropertyId, AnimationId> particleAnimations_;
82     friend class RSRenderNode;
83 
84     FrameRateRange rsRange_ = {0, 0, 0};
85     RSAnimationRateDecider rateDecider_;
86     FrameRateGetFunc frameRateGetFunc_;
87 };
88 } // namespace Rosen
89 } // namespace OHOS
90 
91 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H