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 "rs_frame_rate_range.h" 20 21 #include "common/rs_common_def.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 enum class RSPropertyUnit : uint8_t; 26 class RSRenderPropertyBase; 27 using FrameRateGetFunc = std::function<int32_t(RSPropertyUnit, float, int32_t, int32_t)>; 28 using PropertyValue = std::shared_ptr<RSRenderPropertyBase>; 29 30 class RSB_EXPORT RSAnimationRateDecider { 31 public: 32 RSAnimationRateDecider() = default; 33 ~RSAnimationRateDecider() = default; 34 SetEnable(bool enabled)35 void SetEnable(bool enabled) 36 { 37 isEnabled_ = enabled; 38 } SetNodeSize(float width,float height)39 void SetNodeSize(float width, float height) 40 { 41 nodeWidth_ = width; 42 nodeHeight_ = height; 43 } SetNodeScale(float scaleX,float scaleY)44 void SetNodeScale(float scaleX, float scaleY) 45 { 46 nodeScaleX_ = scaleX; 47 nodeScaleY_ = scaleY; 48 } SetAbsRect(int32_t width,int32_t height)49 void SetAbsRect(int32_t width, int32_t height) 50 { 51 absWidth_ = width; 52 absHeight_ = height; 53 absArea_ = absWidth_ * absHeight_; 54 absLength_ = std::max(absWidth_, absHeight_); 55 } 56 void Reset(); 57 void AddDecisionElement(PropertyId id, const PropertyValue& velocity, FrameRateRange range); 58 void MakeDecision(const FrameRateGetFunc& func); 59 const FrameRateRange& GetFrameRateRange() const; 60 private: 61 int32_t CalculatePreferredRate(const PropertyValue& property, const FrameRateGetFunc& func); 62 int32_t ProcessVector4f(const PropertyValue& property, const FrameRateGetFunc& func); 63 int32_t ProcessVector2f(const PropertyValue& property, const FrameRateGetFunc& func); 64 int32_t ProcessFloat(const PropertyValue& property, const FrameRateGetFunc& func); 65 66 bool isEnabled_ = true; 67 float nodeWidth_ = 0.0f; // unit: pixel 68 float nodeHeight_ = 0.0f; // unit: pixel 69 float nodeScaleX_ = 1.0f; 70 float nodeScaleY_ = 1.0f; 71 int32_t absWidth_ = 0; 72 int32_t absHeight_ = 0; 73 int32_t absArea_ = 0; 74 int32_t absLength_ = 0; 75 76 FrameRateRange frameRateRange_; 77 std::unordered_map<PropertyId, std::pair<PropertyValue, FrameRateRange>> decisionElements_; 78 }; 79 } // namespace Rosen 80 } // namespace OHOS 81 82 #endif // ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_RATE_DECIDER_H