1 /* 2 * Copyright (c) 2022-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_MODIFIER_RS_MODIFIER_MANAGER_H 17 #define RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_MANAGER_H 18 19 #include <memory> 20 #include <set> 21 #include <unordered_map> 22 23 #include "animation/rs_animation_rate_decider.h" 24 #include "common/rs_common_def.h" 25 #include "common/rs_macros.h" 26 #include "render_service_base/include/pipeline/rs_render_display_sync.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class RSModifier; 31 class RSRenderAnimation; 32 33 class RSC_EXPORT RSModifierManager { 34 public: 35 RSModifierManager() = default; 36 virtual ~RSModifierManager() = default; 37 38 void AddModifier(const std::shared_ptr<RSModifier>& modifier); 39 void AddAnimation(const std::shared_ptr<RSRenderAnimation>& animation); 40 void RemoveAnimation(const AnimationId keyId); 41 bool HasUIRunningAnimation(); 42 43 bool Animate(int64_t time, int64_t vsyncPeriod = 0); 44 void Draw(); 45 bool GetAndResetFirstFrameAnimationState(); 46 47 void SetFrameRateGetFunc(const FrameRateGetFunc& func); 48 const FrameRateRange GetFrameRateRange() const; 49 50 // spring animation related 51 void RegisterSpringAnimation(PropertyId propertyId, AnimationId animId); 52 void UnregisterSpringAnimation(PropertyId propertyId, AnimationId animId); 53 std::shared_ptr<RSRenderAnimation> QuerySpringAnimation(PropertyId propertyId); 54 55 bool JudgeAnimateWhetherSkip(AnimationId animId, int64_t time, int64_t vsyncPeriod); 56 void SetDisplaySyncEnable(bool isDisplaySyncEnabled); 57 bool IsDisplaySyncEnabled() const; 58 void FlushStartAnimation(int64_t time); 59 60 private: 61 void OnAnimationFinished(const std::shared_ptr<RSRenderAnimation>& animation); 62 const std::shared_ptr<RSRenderAnimation> GetAnimation(AnimationId id) const; 63 64 std::set<std::shared_ptr<RSModifier>> modifiers_; 65 std::unordered_map<AnimationId, std::weak_ptr<RSRenderAnimation>> animations_; 66 std::unordered_map<PropertyId, AnimationId> springAnimations_; 67 68 RSAnimationRateDecider rateDecider_; 69 FrameRateGetFunc frameRateGetFunc_; 70 bool hasFirstFrameAnimation_ = false; 71 72 std::unordered_map<AnimationId, std::shared_ptr<RSRenderDisplaySync>> displaySyncs_; 73 bool isDisplaySyncEnabled_ = false; 74 75 template <typename T> 76 friend class RSAnimatableProperty; 77 }; 78 } // namespace Rosen 79 } // namespace OHOS 80 81 #endif // RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_MANAGER_H 82