• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_FRAME_RATE_RANGE_H
17 #define ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_FRAME_RATE_RANGE_H
18 #include <string>
19 
20 #define RANGE_MAX_REFRESHRATE 144
21 
22 namespace OHOS {
23 namespace Rosen {
24 // different ltpo frame rate vote type
25 constexpr uint32_t RS_ANIMATION_FRAME_RATE_TYPE = 1;
26 constexpr uint32_t UI_ANIMATION_FRAME_RATE_TYPE = 2;
27 constexpr uint32_t DISPLAY_SYNC_FRAME_RATE_TYPE = 3;
28 constexpr uint32_t ACE_COMPONENT_FRAME_RATE_TYPE = 4;
29 constexpr uint32_t DISPLAY_SOLOIST_FRAME_RATE_TYPE = 5;
30 constexpr uint32_t DRAG_SCENE_FRAME_RATE_TYPE = 6;
31 constexpr uint32_t NATIVE_VSYNC_FRAME_RATE_TYPE = 7;
32 // extent info of ltpo frame rate vote: it indicates the frame contains the first frame of animation,
33 // its value should be independent from above types
34 constexpr uint32_t ANIMATION_STATE_FIRST_FRAME = 0x1000;
35 
36 enum ComponentScene : int32_t {
37     UNKNOWN_SCENE = 0,
38     SWIPER_FLING = 1,
39 };
40 
41 class FrameRateRange {
42 public:
FrameRateRange()43     FrameRateRange() : min_(0), max_(0), preferred_(0), type_(0), isEnergyAssurance_(false),
44         componentScene_(ComponentScene::UNKNOWN_SCENE) {}
45 
FrameRateRange(int min,int max,int preferred)46     FrameRateRange(int min, int max, int preferred) : min_(min), max_(max), preferred_(preferred) {}
47 
FrameRateRange(int min,int max,int preferred,uint32_t type)48     FrameRateRange(int min, int max, int preferred, uint32_t type) : min_(min), max_(max),
49         preferred_(preferred), type_(type) {}
50 
FrameRateRange(int min,int max,int preferred,uint32_t type,ComponentScene componentScene)51     FrameRateRange(int min, int max, int preferred, uint32_t type, ComponentScene componentScene)
52         : min_(min), max_(max), preferred_(preferred), type_(type), componentScene_(componentScene) {}
53 
IsZero()54     bool IsZero() const
55     {
56         return this->preferred_ == 0;
57     }
58 
IsValid()59     bool IsValid() const
60     {
61         return !this->IsZero() && this->min_ <= this->preferred_ && this->preferred_ <= this->max_ &&
62             this->min_ >= 0 && this->max_ <= RANGE_MAX_REFRESHRATE;
63     }
64 
IsDynamic()65     bool IsDynamic() const
66     {
67         return IsValid() && this->min_ != this->max_;
68     }
69 
Reset()70     void Reset()
71     {
72         this->min_ = 0;
73         this->max_ = 0;
74         this->preferred_ = 0;
75         this->type_ = 0;
76         this->isEnergyAssurance_ = false;
77         this->componentScene_ = ComponentScene::UNKNOWN_SCENE;
78     }
79 
Set(int min,int max,int preferred)80     void Set(int min, int max, int preferred)
81     {
82         this->min_ = min;
83         this->max_ = max;
84         this->preferred_ = preferred;
85     }
86 
Set(int min,int max,int preferred,uint32_t type)87     void Set(int min, int max, int preferred, uint32_t type)
88     {
89         this->min_ = min;
90         this->max_ = max;
91         this->preferred_ = preferred;
92         this->type_ = type;
93     }
94 
Merge(const FrameRateRange & other)95     bool Merge(const FrameRateRange& other)
96     {
97         if (this->preferred_ < other.preferred_) {
98             this->Set(other.min_, other.max_, other.preferred_, other.type_);
99             this->isEnergyAssurance_ = other.isEnergyAssurance_;
100             this->componentScene_ = other.componentScene_;
101             return true;
102         }
103         return false;
104     }
105 
GetExtInfo()106     std::string GetExtInfo() const
107     {
108         auto componentName = GetComponentName();
109         if (isEnergyAssurance_ && componentName != "UNKNOWN_SCENE") {
110             return std::string("COMPONENT_") + componentName + "_ASSURANCE";
111         }
112         std::string extInfo = "";
113         switch (type_ & ~ANIMATION_STATE_FIRST_FRAME) {
114             case RS_ANIMATION_FRAME_RATE_TYPE:
115                 extInfo = "RS_ANIMATION";
116                 break;
117             case UI_ANIMATION_FRAME_RATE_TYPE:
118                 extInfo = "UI_ANIMATION";
119                 break;
120             case DISPLAY_SYNC_FRAME_RATE_TYPE:
121                 extInfo = "DISPLAY_SYNC";
122                 break;
123             case ACE_COMPONENT_FRAME_RATE_TYPE:
124                 extInfo = "ACE_COMPONENT";
125                 break;
126             case DISPLAY_SOLOIST_FRAME_RATE_TYPE:
127                 extInfo = "DISPLAY_SOLOIST";
128                 break;
129             default:
130                 return "";
131         }
132         if ((type_ & ANIMATION_STATE_FIRST_FRAME) != 0) {
133             extInfo += "_FIRST_UI_ANIMATION_FRAME";
134         }
135         return extInfo + (isEnergyAssurance_ ? "_ENERGY_ASSURANCE" : "");
136     }
137 
GetComponentName()138     std::string GetComponentName() const
139     {
140         switch (componentScene_) {
141             case ComponentScene::SWIPER_FLING:
142                 return "SWIPER_FLING";
143             default:
144                 return "UNKNOWN_SCENE";
145         }
146     }
147 
148     bool operator==(const FrameRateRange& other) const
149     {
150         return this->min_ == other.min_ && this->max_ == other.max_ &&
151             this->preferred_ == other.preferred_ && this->type_ == other.type_;
152     }
153 
154     bool operator!=(const FrameRateRange& other) const
155     {
156         return !operator==(other);
157     }
158 
159     int min_ = 0;
160     int max_ = 0;
161     int preferred_ = 0;
162     uint32_t type_ = 0;
163     bool isEnergyAssurance_ = false;
164     ComponentScene componentScene_ = ComponentScene::UNKNOWN_SCENE;
165 };
166 } // namespace Rosen
167 } // namespace OHOS
168 #endif // ROSEN_RENDER_SERVICE_BASE_ANIMATION_RS_FRAME_RATE_RANGE_H