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 SetDefaultDeviceRotationOffset(uint32_t defaultRotationOffset); 87 uint32_t GetDefaultDeviceRotationOffset() const; 88 89 void UpdateVirtualPixelRatio(const RRect& bounds); 90 void SetVirtualPixelRatio(float virtualPixelRatio); 91 float GetVirtualPixelRatio() const; 92 93 void SetScreenRotation(Rotation rotation); 94 void SetRotationAndScreenRotationOnly(Rotation rotation); 95 Rotation GetScreenRotation() const; 96 void UpdateScreenRotation(Rotation rotation); 97 98 void SetOrientation(Orientation orientation); 99 Orientation GetOrientation() const; 100 101 void SetDisplayState(DisplayState displayState); 102 DisplayState GetDisplayState() const; 103 104 void SetDisplayOrientation(DisplayOrientation displayOrientation); 105 DisplayOrientation GetDisplayOrientation() const; 106 void CalcDefaultDisplayOrientation(); 107 108 float GetXDpi(); 109 float GetYDpi(); 110 111 void SetOffsetX(int32_t offsetX); 112 int32_t GetOffsetX() const; 113 114 void SetOffsetY(int32_t offsetY); 115 int32_t GetOffsetY() const; 116 117 void SetOffset(int32_t offsetX, int32_t offsetY); 118 119 void SetScreenType(ScreenType type); 120 ScreenType GetScreenType() const; 121 122 void SetScreenRequestedOrientation(Orientation orientation); 123 Orientation GetScreenRequestedOrientation() const; 124 GetAvailableArea()125 DMRect GetAvailableArea() 126 { 127 return availableArea_; 128 } 129 SetAvailableArea(DMRect area)130 void SetAvailableArea(DMRect area) 131 { 132 availableArea_ = area; 133 } 134 private: IsVertical(Rotation rotation)135 static inline bool IsVertical(Rotation rotation) 136 { 137 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 138 } 139 float rotation_ { 0.0f }; 140 RRect bounds_; 141 RRect phyBounds_; 142 143 float scaleX_ { 1.0f }; 144 float scaleY_ { 1.0f }; 145 float pivotX_ { 0.5f }; 146 float pivotY_ { 0.5f }; 147 float translateX_ { 0.0f }; 148 float translateY_ { 0.0f }; 149 150 uint32_t phyWidth_ { UINT32_MAX }; 151 uint32_t phyHeight_ { UINT32_MAX }; 152 153 uint32_t dpiPhyWidth_ { UINT32_MAX }; 154 uint32_t dpiPhyHeight_ { UINT32_MAX }; 155 156 uint32_t refreshRate_ { 0 }; 157 uint32_t defaultDeviceRotationOffset_ { 0 }; 158 159 float virtualPixelRatio_ { 1.0f }; 160 float defaultDensity_ { 1.0f }; 161 float densityInCurResolution_ { 1.0f }; 162 163 Orientation orientation_ { Orientation::UNSPECIFIED }; 164 DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN }; 165 Rotation screenRotation_ { Rotation::ROTATION_0 }; 166 Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED }; 167 DisplayState displayState_ { DisplayState::UNKNOWN }; 168 169 float xDpi_ { 0.0f }; 170 float yDpi_ { 0.0f }; 171 172 int32_t offsetX_ { 0 }; 173 int32_t offsetY_ { 0 }; 174 175 ScreenType type_ { ScreenType::REAL }; 176 177 void UpdateXDpi(); 178 void UpdateYDpi(); 179 void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight); 180 DMRect availableArea_; 181 }; 182 } // namespace OHOS::Rosen 183 184 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 185