• 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 };
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     float GetDensity();
51     float GetDefaultDensity();
52     void SetDefaultDensity(float defaultDensity);
53 
54     float GetDensityInCurResolution() const;
55     void SetDensityInCurResolution(float densityInCurResolution);
56 
57     void SetPhyWidth(uint32_t phyWidth);
58     int32_t GetPhyWidth() const;
59 
60     void SetPhyHeight(uint32_t phyHeight);
61     int32_t GetPhyHeight() const;
62 
63     void SetRefreshRate(uint32_t refreshRate);
64     uint32_t GetRefreshRate() const;
65 
66     void UpdateVirtualPixelRatio(const RRect& bounds);
67     void SetVirtualPixelRatio(float virtualPixelRatio);
68     float GetVirtualPixelRatio() const;
69 
70     void SetScreenRotation(Rotation rotation);
71     Rotation GetScreenRotation() const;
72     void UpdateScreenRotation(Rotation rotation);
73 
74     void SetOrientation(Orientation orientation);
75     Orientation GetOrientation() const;
76 
77     void SetDisplayOrientation(DisplayOrientation displayOrientation);
78     DisplayOrientation GetDisplayOrientation() const;
79     void CalcDefaultDisplayOrientation();
80 
81     float GetXDpi();
82     float GetYDpi();
83 
84     void SetOffsetX(int32_t offsetX);
85     int32_t GetOffsetX() const;
86 
87     void SetOffsetY(int32_t offsetY);
88     int32_t GetOffsetY() const;
89 
90     void SetOffset(int32_t offsetX, int32_t offsetY);
91 
92     void SetScreenType(ScreenType type);
93     ScreenType GetScreenType() const;
94 
95     void SetScreenRequestedOrientation(Orientation orientation);
96     Orientation GetScreenRequestedOrientation() const;
97 
GetAvailableArea()98     DMRect GetAvailableArea()
99     {
100         return availableArea_;
101     }
102 
SetAvailableArea(DMRect area)103     void SetAvailableArea(DMRect area)
104     {
105         availableArea_ = area;
106     }
107 private:
IsVertical(Rotation rotation)108     static inline bool IsVertical(Rotation rotation)
109     {
110         return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180);
111     }
112     float rotation_ { 0.0f };
113     RRect bounds_;
114     RRect phyBounds_;
115 
116     uint32_t phyWidth_ { UINT32_MAX };
117     uint32_t phyHeight_ { UINT32_MAX };
118 
119     uint32_t refreshRate_ { 0 };
120     float virtualPixelRatio_ { 1.0f };
121     float defaultDensity_ { 1.0f };
122     float densityInCurResolution_ { 1.0f };
123 
124     Orientation orientation_ { Orientation::UNSPECIFIED };
125     DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN };
126     Rotation screenRotation_ { Rotation::ROTATION_0 };
127     Orientation screenRequestedOrientation_ { Orientation::UNSPECIFIED };
128 
129     float xDpi_ { 0.0f };
130     float yDpi_ { 0.0f };
131 
132     int32_t offsetX_ { 0 };
133     int32_t offsetY_ { 0 };
134 
135     ScreenType type_ { ScreenType::REAL };
136 
137     void UpdateXDpi();
138     void UpdateYDpi();
139     void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight);
140     DMRect availableArea_;
141 };
142 } // namespace OHOS::Rosen
143 
144 #endif // OHOS_ROSEN_WINDOW_SCENE_SCREEN_PROPERTY_H
145