1 /* 2 * Copyright (c) 2021 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 "animation/rs_animatable_property.h" 24 #include "common/rs_common_def.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class RSDirtyRegionManager; 29 class RSPaintFilterCanvas; 30 class RSProperties; 31 class RSRenderAnimation; 32 class RSRenderNode; 33 class RSTransitionProperties; 34 35 class RSAnimationManager { 36 public: 37 using TransitionCallback = std::function<void(const std::unique_ptr<RSTransitionProperties>& transitionProperties)>; 38 RSAnimationManager() = default; 39 ~RSAnimationManager() = default; 40 41 void AddAnimation(const std::shared_ptr<RSRenderAnimation>& animation); 42 void RemoveAnimation(AnimationId keyId); 43 const std::shared_ptr<RSRenderAnimation> GetAnimation(AnimationId id) const; 44 45 bool Animate(int64_t time); 46 47 void RegisterTransition(AnimationId id, const TransitionCallback& transition); 48 void UnregisterTransition(AnimationId id); 49 std::unique_ptr<RSTransitionProperties> GetTransitionProperties(); 50 bool HasTransition() const; 51 52 private: 53 void OnAnimationRemove(const std::shared_ptr<RSRenderAnimation>& animation); 54 void OnAnimationAdd(const std::shared_ptr<RSRenderAnimation>& animation); 55 void OnAnimationFinished(const std::shared_ptr<RSRenderAnimation>& animation); 56 void ClearTransition(AnimationId id); 57 58 std::unordered_map<AnimationId, std::shared_ptr<RSRenderAnimation>> animations_; 59 std::unordered_map<RSAnimatableProperty, int> animationNum_; 60 std::list<std::pair<AnimationId, TransitionCallback>> transition_; 61 62 friend class RSRenderNode; 63 }; 64 } // namespace Rosen 65 } // namespace OHOS 66 67 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_MANAGER_H