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 "modifier/rs_modifier_type.h" 27 #include "rs_animation_rate_decider.h" 28 #include "rs_frame_rate_range.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 class RSDirtyRegionManager; 33 class RSPaintFilterCanvas; 34 class RSProperties; 35 class RSRenderAnimation; 36 class RSRenderNode; 37 38 class RSB_EXPORT RSAnimationManager { 39 public: 40 RSAnimationManager() = default; 41 RSAnimationManager(const RSAnimationManager&) = delete; 42 RSAnimationManager(const RSAnimationManager&&) = delete; 43 RSAnimationManager& operator=(const RSAnimationManager&) = delete; 44 RSAnimationManager& operator=(const RSAnimationManager&&) = delete; 45 ~RSAnimationManager() = default; 46 47 void DumpAnimations(std::string& out) const; 48 void AddAnimation(const std::shared_ptr<RSRenderAnimation>& animation); 49 void RemoveAnimation(AnimationId keyId); 50 void CancelAnimationByPropertyId(PropertyId id); 51 void AttemptCancelAnimationByAnimationId(const std::vector<AnimationId>& animations); 52 const std::shared_ptr<RSRenderAnimation> GetAnimation(AnimationId id) const; 53 void FilterAnimationByPid(pid_t pid); 54 uint32_t GetAnimationsSize(); 55 pid_t GetAnimationPid() const; 56 57 std::tuple<bool, bool, bool> Animate(int64_t time, 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 SetRateDeciderScaleSize(float width, float height); 78 79 private: 80 void OnAnimationFinished(const std::shared_ptr<RSRenderAnimation>& animation); 81 82 std::unordered_map<AnimationId, std::shared_ptr<RSRenderAnimation>> animations_; 83 std::unordered_map<PropertyId, AnimationId> springAnimations_; 84 std::unordered_map<PropertyId, AnimationId> pathAnimations_; 85 std::unordered_map<PropertyId, AnimationId> particleAnimations_; 86 std::vector<AnimationId> pendingCancelAnimation_; 87 friend class RSRenderNode; 88 #ifdef RS_PROFILER_ENABLED 89 friend class RSProfiler; 90 #endif 91 92 FrameRateRange rsRange_ = {0, 0, 0}; 93 RSAnimationRateDecider rateDecider_; 94 FrameRateGetFunc frameRateGetFunc_; 95 }; 96 } // namespace Rosen 97 } // namespace OHOS 98 99 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H