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_frame_rate_range.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class RSDirtyRegionManager; 31 class RSPaintFilterCanvas; 32 class RSProperties; 33 class RSRenderAnimation; 34 class RSRenderNode; 35 36 class RSB_EXPORT RSAnimationManager { 37 public: 38 RSAnimationManager() = default; 39 RSAnimationManager(const RSAnimationManager&) = delete; 40 RSAnimationManager(const RSAnimationManager&&) = delete; 41 RSAnimationManager& operator=(const RSAnimationManager&) = delete; 42 RSAnimationManager& operator=(const RSAnimationManager&&) = delete; 43 ~RSAnimationManager() = default; 44 45 void AddAnimation(const std::shared_ptr<RSRenderAnimation>& animation); 46 void RemoveAnimation(AnimationId keyId); 47 void CancelAnimationByPropertyId(PropertyId id); 48 const std::shared_ptr<RSRenderAnimation> GetAnimation(AnimationId id) const; 49 void FilterAnimationByPid(pid_t pid); 50 51 std::pair<bool, bool> Animate(int64_t time, bool nodeIsOnTheTree); 52 53 // spring animation related 54 void RegisterSpringAnimation(PropertyId propertyId, AnimationId animId); 55 void UnregisterSpringAnimation(PropertyId propertyId, AnimationId animId); 56 std::shared_ptr<RSRenderAnimation> QuerySpringAnimation(PropertyId propertyId); 57 // path animation related 58 void RegisterPathAnimation(PropertyId propertyId, AnimationId animId); 59 void UnregisterPathAnimation(PropertyId propertyId, AnimationId animId); 60 std::shared_ptr<RSRenderAnimation> QueryPathAnimation(PropertyId propertyId); 61 // particle animation related 62 void RegisterParticleAnimation(PropertyId propertyId, AnimationId animId); 63 void UnregisterParticleAnimation(PropertyId propertyId, AnimationId animId); 64 std::unordered_map<PropertyId, AnimationId> GetParticleAnimations(); 65 66 FrameRateRange GetFrameRateRangeFromRSAnimations(); 67 68 private: 69 void OnAnimationFinished(const std::shared_ptr<RSRenderAnimation>& animation); 70 71 std::unordered_map<AnimationId, std::shared_ptr<RSRenderAnimation>> animations_; 72 std::unordered_map<PropertyId, AnimationId> springAnimations_; 73 std::unordered_map<PropertyId, AnimationId> pathAnimations_; 74 std::unordered_map<PropertyId, AnimationId> particleAnimations_; 75 friend class RSRenderNode; 76 77 FrameRateRange rsRange_ = {0, 0, 0}; 78 }; 79 } // namespace Rosen 80 } // namespace OHOS 81 82 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H