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 RELATIVE_POSITION_CHANGE, 36 SUPER_FOLD_STATUS_CHANGE, 37 VIRTUAL_PIXEL_RATIO_CHANGE, 38 ACCESS_INFO_CHANGE, 39 }; 40 class ScreenProperty { 41 public: 42 ScreenProperty() = default; 43 ~ScreenProperty() = default; 44 45 void SetRotation(float rotation); 46 float GetRotation() const; 47 48 void SetBounds(const RRect& bounds); 49 RRect GetBounds() const; 50 51 void SetPhyBounds(const RRect& phyBounds); 52 RRect GetPhyBounds() const; 53 54 void SetFakeBounds(const RRect& fakeBounds); 55 RRect GetFakeBounds() const; 56 57 void SetIsFakeInUse(bool isFakeInUse); 58 bool GetIsFakeInUse() const; 59 60 void SetScaleX(float scaleX); 61 float GetScaleX() const; 62 63 void SetScaleY(float scaleY); 64 float GetScaleY() const; 65 66 void SetPivotX(float pivotX); 67 float GetPivotX() const; 68 69 void SetPivotY(float pivotY); 70 float GetPivotY() const; 71 72 void SetTranslateX(float translateX); 73 float GetTranslateX() const; 74 75 void SetTranslateY(float translateY); 76 float GetTranslateY() const; 77 78 float GetDensity(); 79 float GetDefaultDensity(); 80 void SetDefaultDensity(float defaultDensity); 81 82 float GetDensityInCurResolution() const; 83 void SetDensityInCurResolution(float densityInCurResolution); 84 85 void SetPhyWidth(uint32_t phyWidth); 86 int32_t GetPhyWidth() const; 87 88 void SetPhyHeight(uint32_t phyHeight); 89 int32_t GetPhyHeight() const; 90 91 void SetDpiPhyBounds(uint32_t phyWidth, uint32_t phyHeight); 92 93 void SetRefreshRate(uint32_t refreshRate); 94 uint32_t GetRefreshRate() const; 95 96 void SetPropertyChangeReason(std::string propertyChangeReason); 97 std::string GetPropertyChangeReason() const; 98 99 void SetDefaultDeviceRotationOffset(uint32_t defaultRotationOffset); 100 uint32_t GetDefaultDeviceRotationOffset() const; 101 102 void UpdateVirtualPixelRatio(const RRect& bounds); 103 void SetVirtualPixelRatio(float virtualPixelRatio); 104 float GetVirtualPixelRatio() const; 105 106 void SetScreenRotation(Rotation rotation); 107 void SetRotationAndScreenRotationOnly(Rotation rotation); 108 Rotation GetScreenRotation() const; 109 void UpdateScreenRotation(Rotation rotation); 110 111 Rotation GetDeviceRotation() const; 112 void UpdateDeviceRotation(Rotation rotation); 113 114 void SetOrientation(Orientation orientation); 115 Orientation GetOrientation() const; 116 117 void SetDisplayState(DisplayState displayState); 118 DisplayState GetDisplayState() const; 119 120 void SetDisplayOrientation(DisplayOrientation displayOrientation); 121 DisplayOrientation GetDisplayOrientation() const; 122 void CalcDefaultDisplayOrientation(); 123 124 void SetDeviceOrientation(DisplayOrientation displayOrientation); 125 DisplayOrientation GetDeviceOrientation() const; 126 127 void SetPhysicalRotation(float rotation); 128 float GetPhysicalRotation() const; 129 130 void SetScreenComponentRotation(float rotation); 131 float GetScreenComponentRotation() const; 132 133 float GetXDpi() const; 134 float GetYDpi() const; 135 136 void SetOffsetX(int32_t offsetX); 137 int32_t GetOffsetX() const; 138 139 void SetOffsetY(int32_t offsetY); 140 int32_t GetOffsetY() const; 141 142 void SetOffset(int32_t offsetX, int32_t offsetY); 143 144 void SetStartX(uint32_t startX); 145 uint32_t GetStartX() const; 146 147 void SetStartY(uint32_t startY); 148 uint32_t GetStartY() const; 149 150 void SetValidHeight(uint32_t validHeight); 151 int32_t GetValidHeight() const; 152 153 void SetValidWidth(uint32_t validWidth); 154 int32_t GetValidWidth() const; 155 156 void SetStartPosition(uint32_t startX, uint32_t startY); 157 158 void SetScreenType(ScreenType type); 159 ScreenType GetScreenType() const; 160 161 void SetScreenRequestedOrientation(Orientation orientation); 162 Orientation GetScreenRequestedOrientation() const; 163 164 void SetScreenShape(ScreenShape screenShape); 165 ScreenShape GetScreenShape() const; 166 167 void SetX(int32_t x); 168 int32_t GetX() const; 169 170 void SetY(int32_t y); 171 int32_t GetY() const; 172 173 void SetXYPosition(int32_t x, int32_t y); 174 GetAvailableArea()175 DMRect GetAvailableArea() 176 { 177 return availableArea_; 178 } 179 SetAvailableArea(DMRect area)180 void SetAvailableArea(DMRect area) 181 { 182 availableArea_ = area; 183 } 184 GetExpandAvailableArea()185 DMRect GetExpandAvailableArea() 186 { 187 return expandAvailableArea_; 188 } 189 SetExpandAvailableArea(DMRect area)190 void SetExpandAvailableArea(DMRect area) 191 { 192 expandAvailableArea_ = area; 193 } 194 GetCreaseRect()195 DMRect GetCreaseRect() 196 { 197 return creaseRect_; 198 } 199 SetCreaseRect(DMRect creaseRect)200 void SetCreaseRect(DMRect creaseRect) 201 { 202 creaseRect_ = creaseRect; 203 } 204 205 RRect GetPhysicalTouchBounds(); 206 207 void SetPhysicalTouchBounds(); 208 209 int32_t GetInputOffsetX(); 210 211 int32_t GetInputOffsetY(); 212 213 void SetInputOffsetY(); 214 215 float CalculatePPI(); 216 uint32_t CalculateDPI(); 217 218 // OffScreenRender SetCurrentOffScreenRendering(bool enable)219 void SetCurrentOffScreenRendering(bool enable) { isCurrentOffScreenRendering_ = enable; } GetCurrentOffScreenRendering()220 bool GetCurrentOffScreenRendering() { return isCurrentOffScreenRendering_; } SetScreenRealWidth(uint32_t width)221 void SetScreenRealWidth(uint32_t width) { screenRealWidth_ = width; } GetScreenRealWidth()222 uint32_t GetScreenRealWidth() { return screenRealWidth_; } SetScreenRealHeight(uint32_t height)223 void SetScreenRealHeight(uint32_t height) { screenRealHeight_ = height; } GetScreenRealHeight()224 uint32_t GetScreenRealHeight() { return screenRealHeight_; } SetScreenRealPPI()225 void SetScreenRealPPI() { screenRealPPI_ = CalculatePPI(); } GetScreenRealPPI()226 float GetScreenRealPPI() { return screenRealPPI_; } SetScreenRealDPI()227 void SetScreenRealDPI() { screenRealDPI_ = CalculateDPI(); } GetScreenRealDPI()228 uint32_t GetScreenRealDPI() { return screenRealDPI_; } 229 230 void SetPointerActiveWidth(uint32_t pointerActiveWidth); 231 uint32_t GetPointerActiveWidth(); 232 void SetPointerActiveHeight(uint32_t pointerActiveHeight); 233 uint32_t GetPointerActiveHeight(); 234 235 private: IsVertical(Rotation rotation)236 static inline bool IsVertical(Rotation rotation) 237 { 238 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 239 } 240 float rotation_ { 0.0f }; 241 float physicalRotation_ { 0.0f }; 242 float screenComponentRotation_ { 0.0f }; 243 RRect bounds_; 244 RRect phyBounds_; 245 RRect fakeBounds_; 246 bool isFakeInUse_ = false; // is fake bounds in use 247 248 float scaleX_ { 1.0f }; 249 float scaleY_ { 1.0f }; 250 float pivotX_ { 0.5f }; 251 float pivotY_ { 0.5f }; 252 float translateX_ { 0.0f }; 253 float translateY_ { 0.0f }; 254 255 uint32_t phyWidth_ { UINT32_MAX }; 256 uint32_t phyHeight_ { UINT32_MAX }; 257 258 uint32_t dpiPhyWidth_ { UINT32_MAX }; 259 uint32_t dpiPhyHeight_ { UINT32_MAX }; 260 261 uint32_t refreshRate_ { 0 }; 262 uint32_t defaultDeviceRotationOffset_ { 0 }; 263 264 std::string propertyChangeReason_ { "" }; 265 266 float virtualPixelRatio_ { 1.0f }; 267 float defaultDensity_ { 1.0f }; 268 float densityInCurResolution_ { 1.0f }; 269 270 Orientation orientation_ { Orientation::UNSPECIFIED }; 271 DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN }; 272 DisplayOrientation deviceOrientation_ { DisplayOrientation::UNKNOWN }; 273 Rotation screenRotation_ { Rotation::ROTATION_0 }; 274 Rotation deviceRotation_ { Rotation::ROTATION_0 }; 275 Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED }; 276 DisplayState displayState_ { DisplayState::UNKNOWN }; 277 278 float xDpi_ { 0.0f }; 279 float yDpi_ { 0.0f }; 280 281 int32_t offsetX_ { 0 }; 282 int32_t offsetY_ { 0 }; 283 284 uint32_t startX_ { 0 }; 285 uint32_t startY_ { 0 }; 286 287 int32_t x_ { 0 }; 288 int32_t y_ { 0 }; 289 290 uint32_t validWidth_ { UINT32_MAX }; 291 uint32_t validHeight_ { UINT32_MAX }; 292 293 uint32_t pointerActiveWidth_ { 0 }; 294 uint32_t pointerActiveHeight_ { 0 }; 295 296 ScreenShape screenShape_ { ScreenShape::RECTANGLE }; 297 298 ScreenType type_ { ScreenType::REAL }; 299 300 void UpdateXDpi(); 301 void UpdateYDpi(); 302 void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight); 303 DMRect availableArea_; 304 DMRect expandAvailableArea_; 305 DMRect creaseRect_; 306 307 RRect physicalTouchBounds_; 308 int32_t inputOffsetX_ { 0 }; 309 int32_t inputOffsetY_ { 0 }; 310 311 // OffScreenRender 312 bool isCurrentOffScreenRendering_ { false }; 313 uint32_t screenRealWidth_ { UINT32_MAX }; 314 uint32_t screenRealHeight_ { UINT32_MAX }; 315 float screenRealPPI_ { 0.0f }; 316 uint32_t screenRealDPI_ { 0 }; 317 }; 318 } // namespace OHOS::Rosen 319 320 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 321