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 #include <vector> 23 24 #include "common/rs_common_def.h" 25 #include "common/rs_macros.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 void AttemptCancelAnimationByAnimationId(const std::vector<AnimationId>& animations); 51 const std::shared_ptr<RSRenderAnimation> GetAnimation(AnimationId id) const; 52 void FilterAnimationByPid(pid_t pid); 53 uint32_t GetAnimationsSize(); 54 pid_t GetAnimationPid() const; 55 56 std::tuple<bool, bool, bool> Animate( 57 int64_t time, int64_t& minLeftDelayTime, bool nodeIsOnTheTree, RSSurfaceNodeAbilityState abilityState); 58 59 // spring animation related 60 void RegisterSpringAnimation(PropertyId propertyId, AnimationId animId); 61 void UnregisterSpringAnimation(PropertyId propertyId, AnimationId animId); 62 std::shared_ptr<RSRenderAnimation> QuerySpringAnimation(PropertyId propertyId); 63 // path animation related 64 void RegisterPathAnimation(PropertyId propertyId, AnimationId animId); 65 void UnregisterPathAnimation(PropertyId propertyId, AnimationId animId); 66 std::shared_ptr<RSRenderAnimation> QueryPathAnimation(PropertyId propertyId); 67 // particle animation related 68 void RegisterParticleAnimation(PropertyId propertyId, AnimationId animId); 69 void UnregisterParticleAnimation(PropertyId propertyId, AnimationId animId); 70 const std::unordered_map<PropertyId, AnimationId>& GetParticleAnimations(); 71 std::shared_ptr<RSRenderAnimation> GetParticleAnimation(); 72 73 const FrameRateRange& GetFrameRateRange() const; 74 const FrameRateRange& GetDecideFrameRateRange() const; 75 76 void SetRateDeciderEnable(bool enabled, const FrameRateGetFunc& func); 77 void SetRateDeciderSize(float width, float height); 78 void SetRateDeciderScale(float scaleX, float scaleY); 79 void SetRateDeciderAbsRect(int32_t width, int32_t height); 80 81 private: 82 void OnAnimationFinished(const std::shared_ptr<RSRenderAnimation>& animation); 83 84 std::unordered_map<AnimationId, std::shared_ptr<RSRenderAnimation>> animations_; 85 std::unordered_map<PropertyId, AnimationId> springAnimations_; 86 std::unordered_map<PropertyId, AnimationId> pathAnimations_; 87 std::unordered_map<PropertyId, AnimationId> particleAnimations_; 88 std::vector<AnimationId> pendingCancelAnimation_; 89 friend class RSRenderNode; 90 #ifdef RS_PROFILER_ENABLED 91 friend class RSProfiler; 92 #endif 93 94 FrameRateRange rsRange_ = {0, 0, 0}; 95 RSAnimationRateDecider rateDecider_; 96 FrameRateGetFunc frameRateGetFunc_; 97 }; 98 } // namespace Rosen 99 } // namespace OHOS 100 101 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H