• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 DISPLAY_MANAGER_ADAPTER_H
17 #define DISPLAY_MANAGER_ADAPTER_H
18 
19 #include <memory>
20 #include <vector>
21 
22 namespace OHOS::NWeb {
23 
24 using DisplayId = uint64_t;
25 using ListenerId = uint32_t;
26 
27 enum class RotationType : uint32_t {
28     ROTATION_0,
29     ROTATION_90,
30     ROTATION_180,
31     ROTATION_270,
32     ROTATION_BUTT,
33 };
34 
35 enum class OrientationType : uint32_t {
36     UNSPECIFIED = 0,
37     VERTICAL = 1,
38     HORIZONTAL = 2,
39     REVERSE_VERTICAL = 3,
40     REVERSE_HORIZONTAL = 4,
41     SENSOR = 5,
42     SENSOR_VERTICAL = 6,
43     SENSOR_HORIZONTAL = 7,
44     BUTT,
45 };
46 
47 enum class DisplayOrientation : uint32_t {
48     PORTRAIT = 0,
49     LANDSCAPE,
50     PORTRAIT_INVERTED,
51     LANDSCAPE_INVERTED,
52     UNKNOWN,
53 };
54 
55 enum class FoldStatus : uint32_t {
56     UNKNOWN = 0,
57     FULL = 1,
58     MAIN = 2,
59     SUB = 3,
60     COORDINATION = 4,
61 };
62 
63 enum class DisplayState : uint32_t {
64     UNKNOWN,
65     OFF,
66     ON,
67     DOZE,
68     DOZE_SUSPEND,
69     VR,
70     ON_SUSPEND,
71 };
72 
73 enum class DisplaySourceMode : uint32_t {
74     NONE = 0,
75     MAIN = 1,
76     MIRROR = 2,
77     EXTEND = 3,
78     ALONE = 4,
79 };
80 
81 class DisplayListenerAdapter {
82 public:
83     DisplayListenerAdapter() = default;
84 
85     virtual ~DisplayListenerAdapter() = default;
86 
87     virtual void OnCreate(DisplayId) = 0;
88 
89     virtual void OnDestroy(DisplayId) = 0;
90 
91     virtual void OnChange(DisplayId) = 0;
92 };
93 
94 class FoldStatusListenerAdapter {
95 public:
96     FoldStatusListenerAdapter() = default;
97 
98     virtual ~FoldStatusListenerAdapter() = default;
99 
OnFoldStatusChanged(FoldStatus foldstatus)100     virtual void OnFoldStatusChanged(FoldStatus foldstatus) {}
101 };
102 
103 class DisplayAdapter {
104 public:
105     DisplayAdapter() = default;
106 
107     virtual ~DisplayAdapter() = default;
108 
109     virtual DisplayId GetId() = 0;
110 
111     virtual int32_t GetWidth() = 0;
112 
113     virtual int32_t GetHeight() = 0;
114 
115     virtual float GetVirtualPixelRatio() = 0;
116 
117     virtual RotationType GetRotation() = 0;
118 
119     virtual OrientationType GetOrientation() = 0;
120 
121     virtual int32_t GetDpi() = 0;
122 
123     virtual DisplayOrientation GetDisplayOrientation() = 0;
124 
GetFoldStatus()125     virtual FoldStatus GetFoldStatus()
126     {
127         return FoldStatus::UNKNOWN;
128     }
129 
IsFoldable()130     virtual bool IsFoldable()
131     {
132         return false;
133     }
134 
135     virtual std::string GetName() = 0;
136 
137     virtual int32_t GetAvailableWidth() = 0;
138 
139     virtual int32_t GetAvailableHeight() = 0;
140 
141     virtual bool GetAliveStatus() = 0;
142 
143     virtual DisplayState GetDisplayState() = 0;
144 
145     virtual int32_t GetDensityDpi() = 0;
146 
147     virtual int32_t GetX() = 0;
148 
149     virtual int32_t GetY() = 0;
150 
151     virtual DisplaySourceMode GetDisplaySourceMode() = 0;
152 
153     virtual int32_t GetPhysicalWidth() = 0;
154 
155     virtual int32_t GetPhysicalHeight() = 0;
156 
157     virtual float GetDefaultVirtualPixelRatio() = 0;
158 };
159 
160 class DisplayManagerAdapter {
161 public:
162     DisplayManagerAdapter() = default;
163 
164     virtual ~DisplayManagerAdapter() = default;
165 
166     virtual DisplayId GetDefaultDisplayId() = 0;
167 
168     virtual std::shared_ptr<DisplayAdapter> GetDefaultDisplay() = 0;
169 
170     virtual ListenerId RegisterDisplayListener(std::shared_ptr<DisplayListenerAdapter> listener) = 0;
171 
172     virtual bool UnregisterDisplayListener(ListenerId id) = 0;
173 
174     virtual bool IsDefaultPortrait() = 0;
175 
RegisterFoldStatusListener(std::shared_ptr<FoldStatusListenerAdapter> listener)176     virtual uint32_t RegisterFoldStatusListener(std::shared_ptr<FoldStatusListenerAdapter> listener)
177     {
178         return -1;
179     }
180 
UnregisterFoldStatusListener(uint32_t id)181     virtual bool UnregisterFoldStatusListener(uint32_t id)
182     {
183         return false;
184     }
185 
186     virtual std::shared_ptr<DisplayAdapter> GetPrimaryDisplay() = 0;
187 
188     virtual std::vector<std::shared_ptr<DisplayAdapter>> GetAllDisplays() = 0;
189 };
190 
191 } // namespace OHOS::NWeb
192 
193 #endif // DISPLAY_MANAGER_ADAPTER_H
194