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 150 RRect GetPhysicalTouchBounds(); 151 152 void SetPhysicalTouchBounds(bool isSecondaryDevice); 153 154 int32_t GetInputOffsetX(); 155 156 int32_t GetInputOffsetY(); 157 158 void SetInputOffsetY(bool isSecondaryDevice, FoldDisplayMode foldDisplayMode); 159 private: IsVertical(Rotation rotation)160 static inline bool IsVertical(Rotation rotation) 161 { 162 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 163 } 164 float rotation_ { 0.0f }; 165 float physicalRotation_ { 0.0f }; 166 float screenComponentRotation_ { 0.0f }; 167 RRect bounds_; 168 RRect phyBounds_; 169 170 float scaleX_ { 1.0f }; 171 float scaleY_ { 1.0f }; 172 float pivotX_ { 0.5f }; 173 float pivotY_ { 0.5f }; 174 float translateX_ { 0.0f }; 175 float translateY_ { 0.0f }; 176 177 uint32_t phyWidth_ { UINT32_MAX }; 178 uint32_t phyHeight_ { UINT32_MAX }; 179 180 uint32_t dpiPhyWidth_ { UINT32_MAX }; 181 uint32_t dpiPhyHeight_ { UINT32_MAX }; 182 183 uint32_t refreshRate_ { 0 }; 184 uint32_t defaultDeviceRotationOffset_ { 0 }; 185 186 std::string propertyChangeReason_ { "" }; 187 188 float virtualPixelRatio_ { 1.0f }; 189 float defaultDensity_ { 1.0f }; 190 float densityInCurResolution_ { 1.0f }; 191 192 Orientation orientation_ { Orientation::UNSPECIFIED }; 193 DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN }; 194 DisplayOrientation deviceOrientation_ { DisplayOrientation::UNKNOWN }; 195 Rotation screenRotation_ { Rotation::ROTATION_0 }; 196 Rotation deviceRotation_ { Rotation::ROTATION_0 }; 197 Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED }; 198 DisplayState displayState_ { DisplayState::UNKNOWN }; 199 200 float xDpi_ { 0.0f }; 201 float yDpi_ { 0.0f }; 202 203 int32_t offsetX_ { 0 }; 204 int32_t offsetY_ { 0 }; 205 206 ScreenType type_ { ScreenType::REAL }; 207 208 void UpdateXDpi(); 209 void UpdateYDpi(); 210 void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight); 211 DMRect availableArea_; 212 213 RRect physicalTouchBounds_; 214 int32_t inputOffsetX_ { 0 }; 215 int32_t inputOffsetY_ { 0 }; 216 }; 217 } // namespace OHOS::Rosen 218 219 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 220