1 /* 2 * Copyright (c) 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 HGM_SCREEN_H 17 #define HGM_SCREEN_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <mutex> 22 #include <unistd.h> 23 #include <unordered_map> 24 #include <unordered_set> 25 #include <vector> 26 27 #include "refbase.h" 28 #include "screen_manager/screen_types.h" 29 #include "screen_manager/rs_screen_mode_info.h" 30 31 #include "hgm_command.h" 32 33 namespace OHOS::Rosen { 34 class HgmScreen : public virtual RefBase { 35 public: 36 HgmScreen(); 37 HgmScreen(ScreenId id, int32_t mode); 38 virtual ~HgmScreen(); 39 GetId()40 ScreenId GetId() const 41 { 42 return id_; 43 } 44 GetActiveMode()45 uint32_t GetActiveMode() const 46 { 47 return activeModeId_; 48 } 49 GetSupportedRates()50 std::unordered_set<uint32_t> GetSupportedRates() const 51 { 52 return supportedRefreshRates_; 53 } 54 IsSupportRate(uint32_t rate)55 bool IsSupportRate(uint32_t rate) const 56 { 57 return supportedRefreshRates_.find(rate) != supportedRefreshRates_.end() ? true : false; 58 } 59 GetActiveRefreshRateMode()60 int32_t GetActiveRefreshRateMode() const 61 { 62 return customFrameRateMode_; 63 } 64 65 uint32_t GetActiveRefreshRate(); 66 int32_t SetActiveRefreshRate(int32_t sceneId, uint32_t rate); 67 int32_t SetRateAndResolution(int32_t sceneId, uint32_t rate, int32_t width, int32_t height); 68 int32_t SetRefreshRateRange(uint32_t minRate, uint32_t maxRate); 69 int32_t AddScreenModeInfo(int32_t width, int32_t height, uint32_t rate, int32_t modeId); 70 71 private: 72 class ScreenProfile { 73 public: ScreenProfile(int32_t width,int32_t height,uint32_t rate,int32_t modeId)74 ScreenProfile(int32_t width, int32_t height, uint32_t rate, int32_t modeId) 75 : width_(width), height_(height), refreshrate_(rate), modeId_(modeId) {} 76 77 ~ScreenProfile() = default; 78 79 bool operator==(const ScreenProfile& rValue) const 80 { 81 if (rValue.GetWidth() != width_ || rValue.GetHeight() != height_ || 82 rValue.GetRate() != refreshrate_) { 83 return false; 84 } 85 return true; 86 } 87 GetWidth()88 int32_t GetWidth() const 89 { 90 return width_; 91 } 92 GetHeight()93 int32_t GetHeight() const 94 { 95 return height_; 96 } 97 GetRate()98 uint32_t GetRate() const 99 { 100 return refreshrate_; 101 } 102 GetModeId()103 int32_t GetModeId() const 104 { 105 return modeId_; 106 } 107 108 private: 109 int32_t width_ = -1; 110 int32_t height_ = -1; 111 uint32_t refreshrate_ = 0; 112 int32_t modeId_ = -1; 113 }; 114 115 ScreenId id_ = 0; 116 int32_t activeModeId_ = 0; 117 int32_t customFrameRateMode_ = -1; 118 std::unordered_set<uint32_t> supportedRefreshRates_; 119 std::unordered_set<int32_t> supportedModeIds_; 120 std::vector<std::shared_ptr<ScreenProfile>> screenModeInfos_; 121 std::mutex baseMutex_; 122 123 void SetActiveModeId(int32_t modeId); 124 std::shared_ptr<ScreenProfile> GetModeViaId(int32_t id) const; 125 bool IfSwitchToRate(int32_t screenId, uint32_t rate) const; 126 int32_t GetModeIdViaRate(uint32_t rate) const; 127 int32_t GetModeIdViaResolutionAndRate(int32_t width, int32_t height, uint32_t rate) const; 128 static constexpr uint32_t RATE_NOT_SUPPORTED = 0; 129 130 // defined by xml configuration, participate in refresh rate decision system 131 uint32_t minRefreshRateRange_ = 1; 132 uint32_t maxRefreshRateRange_ = 120; 133 }; 134 } // namespace Ohos::Rosen 135 # endif // HGM_SCREEN_H