• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SetRsId(ScreenId rsId);
97     ScreenId GetRsId() const;
98 
99     void SetPropertyChangeReason(std::string propertyChangeReason);
100     std::string GetPropertyChangeReason() const;
101 
102     void SetDefaultDeviceRotationOffset(uint32_t defaultRotationOffset);
103     uint32_t GetDefaultDeviceRotationOffset() const;
104 
105     void UpdateVirtualPixelRatio(const RRect& bounds);
106     void SetVirtualPixelRatio(float virtualPixelRatio);
107     float GetVirtualPixelRatio() const;
108 
109     void SetScreenRotation(Rotation rotation);
110     void SetRotationAndScreenRotationOnly(Rotation rotation);
111     Rotation GetScreenRotation() const;
112     void UpdateScreenRotation(Rotation rotation);
113 
114     Rotation GetDeviceRotation() const;
115     void UpdateDeviceRotation(Rotation rotation);
116 
117     void SetOrientation(Orientation orientation);
118     Orientation GetOrientation() const;
119 
120     void SetDisplayState(DisplayState displayState);
121     DisplayState GetDisplayState() const;
122 
123     void SetDisplayOrientation(DisplayOrientation displayOrientation);
124     DisplayOrientation GetDisplayOrientation() const;
125     void CalcDefaultDisplayOrientation();
126 
127     void SetDeviceOrientation(DisplayOrientation displayOrientation);
128     DisplayOrientation GetDeviceOrientation() const;
129 
130     void SetPhysicalRotation(float rotation);
131     float GetPhysicalRotation() const;
132 
133     void SetScreenComponentRotation(float rotation);
134     float GetScreenComponentRotation() const;
135 
136     float GetXDpi() const;
137     float GetYDpi() const;
138 
139     void SetOffsetX(int32_t offsetX);
140     int32_t GetOffsetX() const;
141 
142     void SetOffsetY(int32_t offsetY);
143     int32_t GetOffsetY() const;
144 
145     void SetOffset(int32_t offsetX, int32_t offsetY);
146 
147     void SetStartX(uint32_t startX);
148     uint32_t GetStartX() const;
149 
150     void SetStartY(uint32_t startY);
151     uint32_t GetStartY() const;
152 
153     void SetValidHeight(uint32_t validHeight);
154     uint32_t GetValidHeight() const;
155 
156     void SetValidWidth(uint32_t validWidth);
157     uint32_t GetValidWidth() const;
158 
159     void SetStartPosition(uint32_t startX, uint32_t startY);
160 
161     void SetScreenType(ScreenType type);
162     ScreenType GetScreenType() const;
163 
164     void SetScreenRequestedOrientation(Orientation orientation);
165     Orientation GetScreenRequestedOrientation() const;
166 
167     void SetScreenShape(ScreenShape screenShape);
168     ScreenShape GetScreenShape() const;
169 
170     void SetX(int32_t x);
171     int32_t GetX() const;
172 
173     void SetY(int32_t y);
174     int32_t GetY() const;
175 
176     void SetXYPosition(int32_t x, int32_t y);
177 
GetAvailableArea()178     DMRect GetAvailableArea()
179     {
180         return availableArea_;
181     }
182 
SetAvailableArea(DMRect area)183     void SetAvailableArea(DMRect area)
184     {
185         availableArea_ = area;
186     }
187 
GetExpandAvailableArea()188     DMRect GetExpandAvailableArea()
189     {
190         return expandAvailableArea_;
191     }
192 
SetExpandAvailableArea(DMRect area)193     void SetExpandAvailableArea(DMRect area)
194     {
195         expandAvailableArea_ = area;
196     }
197 
GetCreaseRect()198     DMRect GetCreaseRect()
199     {
200         return creaseRect_;
201     }
202 
SetCreaseRect(DMRect creaseRect)203     void SetCreaseRect(DMRect creaseRect)
204     {
205         creaseRect_ = creaseRect;
206     }
207 
208     RRect GetPhysicalTouchBounds();
209 
210     void SetPhysicalTouchBounds();
211 
212     int32_t GetInputOffsetX();
213 
214     int32_t GetInputOffsetY();
215 
216     void SetInputOffsetY();
217     void SetMirrorWidth(uint32_t mirrorWidth);
218     uint32_t GetMirrorWidth() const;
219     void SetMirrorHeight(uint32_t mirrorHeight);
220     uint32_t GetMirrorHeight() const;
221 
222     float CalculatePPI();
223     uint32_t CalculateDPI();
224 
225     // OffScreenRender
SetCurrentOffScreenRendering(bool enable)226     void SetCurrentOffScreenRendering(bool enable) { isCurrentOffScreenRendering_ = enable; }
GetCurrentOffScreenRendering()227     bool GetCurrentOffScreenRendering() { return isCurrentOffScreenRendering_; }
SetScreenRealWidth(uint32_t width)228     void SetScreenRealWidth(uint32_t width) { screenRealWidth_ = width; }
GetScreenRealWidth()229     uint32_t GetScreenRealWidth() { return screenRealWidth_; }
SetScreenRealHeight(uint32_t height)230     void SetScreenRealHeight(uint32_t height) { screenRealHeight_ = height; }
GetScreenRealHeight()231     uint32_t GetScreenRealHeight() { return screenRealHeight_; }
SetScreenRealPPI()232     void SetScreenRealPPI() { screenRealPPI_ = CalculatePPI(); }
GetScreenRealPPI()233     float GetScreenRealPPI() { return screenRealPPI_; }
SetScreenRealDPI()234     void SetScreenRealDPI() { screenRealDPI_ = CalculateDPI(); }
GetScreenRealDPI()235     uint32_t GetScreenRealDPI() { return screenRealDPI_; }
236 
237     void SetPointerActiveWidth(uint32_t pointerActiveWidth);
238     uint32_t GetPointerActiveWidth();
239     void SetPointerActiveHeight(uint32_t pointerActiveHeight);
240     uint32_t GetPointerActiveHeight();
241 
242     // displayInfo
SetDisplayGroupId(DisplayGroupId displayGroupId)243     void SetDisplayGroupId(DisplayGroupId displayGroupId) { displayGroupId_ = displayGroupId; }
GetDisplayGroupId()244     DisplayGroupId GetDisplayGroupId() const { return displayGroupId_; }
SetMainDisplayIdOfGroup(ScreenId screenId)245     void SetMainDisplayIdOfGroup(ScreenId screenId) { mainDisplayIdOfGroup_ = screenId; }
GetMainDisplayIdOfGroup()246     ScreenId GetMainDisplayIdOfGroup() const { return mainDisplayIdOfGroup_; }
SetScreenAreaOffsetX(uint32_t screenAreaOffsetX)247     void SetScreenAreaOffsetX(uint32_t screenAreaOffsetX) { screenAreaOffsetX_ = screenAreaOffsetX; }
GetScreenAreaOffsetX()248     uint32_t GetScreenAreaOffsetX() const { return screenAreaOffsetX_; }
SetScreenAreaOffsetY(uint32_t screenAreaOffsetY)249     void SetScreenAreaOffsetY(uint32_t screenAreaOffsetY) { screenAreaOffsetY_ = screenAreaOffsetY; }
GetScreenAreaOffsetY()250     uint32_t GetScreenAreaOffsetY() const { return screenAreaOffsetY_; }
SetScreenAreaWidth(uint32_t screenAreaWidth)251     void SetScreenAreaWidth(uint32_t screenAreaWidth) { screenAreaWidth_ = screenAreaWidth; }
GetScreenAreaWidth()252     uint32_t GetScreenAreaWidth() const { return screenAreaWidth_; }
SetScreenAreaHeight(uint32_t screenAreaHeight)253     void SetScreenAreaHeight(uint32_t screenAreaHeight) { screenAreaHeight_ = screenAreaHeight; }
GetScreenAreaHeight()254     uint32_t GetScreenAreaHeight() const { return screenAreaHeight_; }
255 
256 private:
IsVertical(Rotation rotation)257     static inline bool IsVertical(Rotation rotation)
258     {
259         return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180);
260     }
261     DisplayGroupId displayGroupId_ = DISPLAY_GROUP_ID_INVALID;
262     ScreenId mainDisplayIdOfGroup_ = SCREEN_ID_INVALID;
263     float rotation_ { 0.0f };
264     float physicalRotation_ { 0.0f };
265     float screenComponentRotation_ { 0.0f };
266     RRect bounds_;
267     RRect phyBounds_;
268     RRect fakeBounds_;
269     bool isFakeInUse_ = false;  // is fakeBounds can be used
270 
271     float scaleX_ { 1.0f };
272     float scaleY_ { 1.0f };
273     float pivotX_ { 0.5f };
274     float pivotY_ { 0.5f };
275     float translateX_ { 0.0f };
276     float translateY_ { 0.0f };
277 
278     uint32_t phyWidth_ { UINT32_MAX };
279     uint32_t phyHeight_ { UINT32_MAX };
280 
281     uint32_t dpiPhyWidth_ { UINT32_MAX };
282     uint32_t dpiPhyHeight_ { UINT32_MAX };
283 
284     uint32_t refreshRate_ { 0 };
285     uint32_t defaultDeviceRotationOffset_ { 0 };
286 
287     ScreenId rsId_ = SCREEN_ID_INVALID;
288 
289     std::string propertyChangeReason_ { "" };
290 
291     float virtualPixelRatio_ { 1.0f };
292     float defaultDensity_ { 1.0f };
293     float densityInCurResolution_ { 1.0f };
294 
295     Orientation orientation_ { Orientation::UNSPECIFIED };
296     DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN };
297     DisplayOrientation deviceOrientation_ { DisplayOrientation::UNKNOWN };
298     Rotation screenRotation_ { Rotation::ROTATION_0 };
299     Rotation deviceRotation_ { Rotation::ROTATION_0 };
300     Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED };
301     DisplayState displayState_ { DisplayState::UNKNOWN };
302 
303     float xDpi_ { 0.0f };
304     float yDpi_ { 0.0f };
305 
306     int32_t offsetX_ { 0 };
307     int32_t offsetY_ { 0 };
308 
309     uint32_t startX_ { 0 };
310     uint32_t startY_ { 0 };
311 
312     int32_t x_ { 0 };
313     int32_t y_ { 0 };
314 
315     uint32_t validWidth_ { UINT32_MAX };
316     uint32_t validHeight_ { UINT32_MAX };
317 
318     uint32_t pointerActiveWidth_ { 0 };
319     uint32_t pointerActiveHeight_ { 0 };
320 
321     ScreenShape screenShape_ { ScreenShape::RECTANGLE };
322 
323     ScreenType type_ { ScreenType::REAL };
324 
325     void UpdateXDpi();
326     void UpdateYDpi();
327     void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight);
328     DMRect availableArea_;  // can be used for all devices
329     DMRect expandAvailableArea_;  // only used for 2in1 device
330     DMRect creaseRect_;
331 
332     RRect physicalTouchBounds_;
333     int32_t inputOffsetX_ { 0 };
334     int32_t inputOffsetY_ { 0 };
335 
336     // OffScreenRender
337     bool isCurrentOffScreenRendering_ { false };
338     uint32_t screenRealWidth_ { UINT32_MAX };
339     uint32_t screenRealHeight_ { UINT32_MAX };
340     float screenRealPPI_ { 0.0f };
341     uint32_t screenRealDPI_ { 0 };
342 
343     // screenArea
344     uint32_t screenAreaOffsetX_ { 0 };
345     uint32_t screenAreaOffsetY_ { 0 };
346     uint32_t screenAreaWidth_ { 0 };
347     uint32_t screenAreaHeight_ { 0 };
348 
349     uint32_t mirrorWidth_ { 0 };
350     uint32_t mirrorHeight_ { 0 };
351 };
352 } // namespace OHOS::Rosen
353 
354 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H
355