• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, int32_t, int32_t)>;
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     }
SetNodeSize(float width,float height)38     void SetNodeSize(float width, float height)
39     {
40         nodeWidth_ = width;
41         nodeHeight_ = height;
42     }
SetNodeScale(float scaleX,float scaleY)43     void SetNodeScale(float scaleX, float scaleY)
44     {
45         nodeScaleX_ = scaleX;
46         nodeScaleY_ = scaleY;
47     }
SetAbsRect(int32_t width,int32_t height)48     void SetAbsRect(int32_t width, int32_t height)
49     {
50         absWidth_ = width;
51         absHeight_ = height;
52         absArea_ = absWidth_ * absHeight_;
53         absLength_ = std::max(absWidth_, absHeight_);
54     }
55     void Reset();
56     void AddDecisionElement(PropertyId id, const PropertyValue& velocity, FrameRateRange range);
57     void MakeDecision(const FrameRateGetFunc& func);
58     const FrameRateRange& GetFrameRateRange() const;
59 private:
60     int32_t CalculatePreferredRate(const PropertyValue& property, const FrameRateGetFunc& func);
61     int32_t ProcessVector4f(const PropertyValue& property, const FrameRateGetFunc& func);
62     int32_t ProcessVector2f(const PropertyValue& property, const FrameRateGetFunc& func);
63     int32_t ProcessFloat(const PropertyValue& property, const FrameRateGetFunc& func);
64 
65     bool isEnabled_ = true;
66     float nodeWidth_ = 0.0f;    // unit: pixel
67     float nodeHeight_ = 0.0f;   // unit: pixel
68     float nodeScaleX_ = 1.0f;
69     float nodeScaleY_ = 1.0f;
70     int32_t absWidth_ = 0;
71     int32_t absHeight_ = 0;
72     int32_t absArea_ = 0;
73     int32_t absLength_ = 0;
74 
75     FrameRateRange frameRateRange_;
76     std::unordered_map<PropertyId, std::pair<PropertyValue, FrameRateRange>> decisionElements_;
77 };
78 } // namespace Rosen
79 } // namespace OHOS
80 
81 #endif // ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_RATE_DECIDER_H