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