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 }; 32 class ScreenProperty { 33 public: 34 ScreenProperty() = default; 35 ~ScreenProperty() = default; 36 37 void SetRotation(float rotation); 38 float GetRotation() const; 39 40 void SetBounds(const RRect& bounds); 41 RRect GetBounds() const; 42 43 float GetDensity(); 44 45 void SetPhyWidth(uint32_t phyWidth); 46 int32_t GetPhyWidth() const; 47 48 void SetPhyHeight(uint32_t phyHeight); 49 int32_t GetPhyHeight() const; 50 51 void SetRefreshRate(uint32_t refreshRate); 52 uint32_t GetRefreshRate() const; 53 54 void UpdateVirtualPixelRatio(const RRect& bounds); 55 void SetVirtualPixelRatio(float virtualPixelRatio); 56 float GetVirtualPixelRatio() const; 57 58 void SetScreenRotation(Rotation rotation); 59 Rotation GetScreenRotation() const; 60 61 void SetOrientation(Orientation orientation); 62 Orientation GetOrientation() const; 63 64 void SetDisplayOrientation(DisplayOrientation displayOrientation); 65 DisplayOrientation GetDisplayOrientation() const; 66 67 float GetXDpi(); 68 float GetYDpi(); 69 70 void SetOffsetX(int32_t offsetX); 71 int32_t GetOffsetX() const; 72 73 void SetOffsetY(int32_t offsetY); 74 int32_t GetOffsetY() const; 75 76 void SetOffset(int32_t offsetX, int32_t offsetY); 77 78 void SetScreenType(ScreenType type); 79 ScreenType GetScreenType() const; 80 81 void SetScreenRequestedOrientation(Orientation orientation); 82 Orientation GetScreenRequestedOrientation() const; 83 84 private: IsVertical(Rotation rotation)85 static inline bool IsVertical(Rotation rotation) 86 { 87 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 88 } 89 float rotation_ { 0.0f }; 90 RRect bounds_; 91 92 uint32_t phyWidth_ { UINT32_MAX }; 93 uint32_t phyHeight_ { UINT32_MAX }; 94 95 uint32_t refreshRate_ { 0 }; 96 float virtualPixelRatio_ { 1.0f }; 97 98 Orientation orientation_ { Orientation::UNSPECIFIED }; 99 DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN }; 100 Rotation screenRotation_ { Rotation::ROTATION_0 }; 101 Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED }; 102 103 float xDpi_ { 0.0f }; 104 float yDpi_ { 0.0f }; 105 106 int32_t offsetX_ { 0 }; 107 int32_t offsetY_ { 0 }; 108 109 ScreenType type_ { ScreenType::REAL }; 110 111 void UpdateXDpi(); 112 void UpdateYDpi(); 113 void UpdateDisplayOrientation(); 114 void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight); 115 }; 116 } // namespace OHOS::Rosen 117 118 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H 119