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 OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 18 19 #include "common/rs_rect.h" 20 #include "dm_common.h" 21 #include "class_var_definition.h" 22 #include "screen_info.h" 23 24 namespace OHOS::Rosen { 25 26 enum class ScreenPropertyChangeReason : uint32_t { 27 UNDEFINED = 0, 28 ROTATION, 29 CHANGE_MODE, 30 FOLD_SCREEN_EXPAND, 31 SCREEN_CONNECT, 32 SCREEN_DISCONNECT, 33 FOLD_SCREEN_FOLDING, 34 VIRTUAL_SCREEN_RESIZE, 35 }; 36 class ScreenProperty { 37 public: 38 ScreenProperty() = default; 39 ~ScreenProperty() = default; 40 41 void SetRotation(float rotation); 42 float GetRotation() const; 43 44 void SetBounds(const RRect& bounds); 45 RRect GetBounds() const; 46 47 void SetPhyBounds(const RRect& phyBounds); 48 RRect GetPhyBounds() const; 49 50 void SetScaleX(float scaleX); 51 float GetScaleX() const; 52 53 void SetScaleY(float scaleY); 54 float GetScaleY() const; 55 56 void SetPivotX(float pivotX); 57 float GetPivotX() const; 58 59 void SetPivotY(float pivotY); 60 float GetPivotY() const; 61 62 void SetTranslateX(float translateX); 63 float GetTranslateX() const; 64 65 void SetTranslateY(float translateY); 66 float GetTranslateY() const; 67 68 float GetDensity(); 69 float GetDefaultDensity(); 70 void SetDefaultDensity(float defaultDensity); 71 72 float GetDensityInCurResolution() const; 73 void SetDensityInCurResolution(float densityInCurResolution); 74 75 void SetPhyWidth(uint32_t phyWidth); 76 int32_t GetPhyWidth() const; 77 78 void SetPhyHeight(uint32_t phyHeight); 79 int32_t GetPhyHeight() const; 80 81 void SetDpiPhyBounds(uint32_t phyWidth, uint32_t phyHeight); 82 83 void SetRefreshRate(uint32_t refreshRate); 84 uint32_t GetRefreshRate() const; 85 86 void SetPropertyChangeReason(std::string propertyChangeReason); 87 std::string GetPropertyChangeReason() const; 88 89 void SetDefaultDeviceRotationOffset(uint32_t defaultRotationOffset); 90 uint32_t GetDefaultDeviceRotationOffset() const; 91 92 void UpdateVirtualPixelRatio(const RRect& bounds); 93 void SetVirtualPixelRatio(float virtualPixelRatio); 94 float GetVirtualPixelRatio() const; 95 96 void SetScreenRotation(Rotation rotation); 97 void SetRotationAndScreenRotationOnly(Rotation rotation); 98 Rotation GetScreenRotation() const; 99 void UpdateScreenRotation(Rotation rotation); 100 101 Rotation GetDeviceRotation() const; 102 void UpdateDeviceRotation(Rotation rotation); 103 104 void SetOrientation(Orientation orientation); 105 Orientation GetOrientation() const; 106 107 void SetDisplayState(DisplayState displayState); 108 DisplayState GetDisplayState() const; 109 110 void SetDisplayOrientation(DisplayOrientation displayOrientation); 111 DisplayOrientation GetDisplayOrientation() const; 112 void CalcDefaultDisplayOrientation(); 113 114 void SetDeviceOrientation(DisplayOrientation displayOrientation); 115 DisplayOrientation GetDeviceOrientation() const; 116 117 void SetPhysicalRotation(float rotation); 118 float GetPhysicalRotation() const; 119 120 void SetScreenComponentRotation(float rotation); 121 float GetScreenComponentRotation() const; 122 123 float GetXDpi(); 124 float GetYDpi(); 125 126 void SetOffsetX(int32_t offsetX); 127 int32_t GetOffsetX() const; 128 129 void SetOffsetY(int32_t offsetY); 130 int32_t GetOffsetY() const; 131 132 void SetOffset(int32_t offsetX, int32_t offsetY); 133 134 void SetScreenType(ScreenType type); 135 ScreenType GetScreenType() const; 136 137 void SetScreenRequestedOrientation(Orientation orientation); 138 Orientation GetScreenRequestedOrientation() const; 139 GetAvailableArea()140 DMRect GetAvailableArea() 141 { 142 return availableArea_; 143 } 144 SetAvailableArea(DMRect area)145 void SetAvailableArea(DMRect area) 146 { 147 availableArea_ = area; 148 } 149 private: IsVertical(Rotation rotation)150 static inline bool IsVertical(Rotation rotation) 151 { 152 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 153 } 154 float rotation_ { 0.0f }; 155 float physicalRotation_ { 0.0f }; 156 float screenComponentRotation_ { 0.0f }; 157 RRect bounds_; 158 RRect phyBounds_; 159 160 float scaleX_ { 1.0f }; 161 float scaleY_ { 1.0f }; 162 float pivotX_ { 0.5f }; 163 float pivotY_ { 0.5f }; 164 float translateX_ { 0.0f }; 165 float translateY_ { 0.0f }; 166 167 uint32_t phyWidth_ { UINT32_MAX }; 168 uint32_t phyHeight_ { UINT32_MAX }; 169 170 uint32_t dpiPhyWidth_ { UINT32_MAX }; 171 uint32_t dpiPhyHeight_ { UINT32_MAX }; 172 173 uint32_t refreshRate_ { 0 }; 174 uint32_t defaultDeviceRotationOffset_ { 0 }; 175 176 std::string propertyChangeReason_ { "" }; 177 178 float virtualPixelRatio_ { 1.0f }; 179 float defaultDensity_ { 1.0f }; 180 float densityInCurResolution_ { 1.0f }; 181 182 Orientation orientation_ { Orientation::UNSPECIFIED }; 183 DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN }; 184 DisplayOrientation deviceOrientation_ { DisplayOrientation::UNKNOWN }; 185 Rotation screenRotation_ { Rotation::ROTATION_0 }; 186 Rotation deviceRotation_ { Rotation::ROTATION_0 }; 187 Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED }; 188 DisplayState displayState_ { DisplayState::UNKNOWN }; 189 190 float xDpi_ { 0.0f }; 191 float yDpi_ { 0.0f }; 192 193 int32_t offsetX_ { 0 }; 194 int32_t offsetY_ { 0 }; 195 196 ScreenType type_ { ScreenType::REAL }; 197 198 void UpdateXDpi(); 199 void UpdateYDpi(); 200 void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight); 201 DMRect availableArea_; 202 }; 203 } // namespace OHOS::Rosen 204 205 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 206