1 /* 2 * Copyright (c) 2024 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 ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_RATE_DECIDER_H 17 #define ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_RATE_DECIDER_H 18 19 #include "common/rs_common_def.h" 20 #include "modifier/rs_modifier_type.h" 21 #include "rs_frame_rate_range.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 class RSRenderPropertyBase; 26 using FrameRateGetFunc = std::function<int32_t(RSPropertyUnit, float)>; 27 using PropertyValue = std::shared_ptr<RSRenderPropertyBase>; 28 29 class RSB_EXPORT RSAnimationRateDecider { 30 public: 31 RSAnimationRateDecider() = default; 32 ~RSAnimationRateDecider() = default; 33 SetEnable(bool enabled)34 void SetEnable(bool enabled) 35 { 36 isEnabled_ = enabled; 37 } 38 void SetScaleReferenceSize(float width, float height); 39 void Reset(); 40 void AddDecisionElement(PropertyId id, const PropertyValue& velocity, FrameRateRange range); 41 void MakeDecision(const FrameRateGetFunc& func); 42 const FrameRateRange& GetFrameRateRange() const; 43 private: 44 int32_t CalculatePreferredRate(const PropertyValue& property, const FrameRateGetFunc& func); 45 int32_t ProcessVector4f(const PropertyValue& property, const FrameRateGetFunc& func); 46 int32_t ProcessVector2f(const PropertyValue& property, const FrameRateGetFunc& func); 47 int32_t ProcessFloat(const PropertyValue& property, const FrameRateGetFunc& func); 48 49 bool isEnabled_ = true; 50 float scaleWidth_ = 0.0f; 51 float scaleHeight_ = 0.0f; 52 FrameRateRange frameRateRange_; 53 std::unordered_map<PropertyId, std::pair<PropertyValue, FrameRateRange>> decisionElements_; 54 }; 55 } // namespace Rosen 56 } // namespace OHOS 57 58 #endif // ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_RATE_DECIDER_H