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