• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OHOS_ROSEN_WM_COMMON_H
17 #define OHOS_ROSEN_WM_COMMON_H
18 
19 #include <parcel.h>
20 #include <map>
21 
22 namespace OHOS {
23 namespace Rosen {
24 using DisplayId = uint64_t;
25 enum class WindowType : uint32_t {
26     APP_WINDOW_BASE = 1,
27     APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
28     WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
29     APP_MAIN_WINDOW_END,
30 
31     APP_SUB_WINDOW_BASE = 1000,
32     WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
33     WINDOW_TYPE_APP_SUB_WINDOW,
34     WINDOW_TYPE_APP_COMPONENT,
35     APP_SUB_WINDOW_END,
36     APP_WINDOW_END = APP_SUB_WINDOW_END,
37 
38     SYSTEM_WINDOW_BASE = 2000,
39     BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
40     WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
41     WINDOW_TYPE_DESKTOP,
42     BELOW_APP_SYSTEM_WINDOW_END,
43 
44     ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
45     WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
46     WINDOW_TYPE_DOCK_SLICE,
47     WINDOW_TYPE_INCOMING_CALL,
48     WINDOW_TYPE_SEARCHING_BAR,
49     WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
50     WINDOW_TYPE_INPUT_METHOD_FLOAT,
51     WINDOW_TYPE_FLOAT,
52     WINDOW_TYPE_TOAST,
53     WINDOW_TYPE_STATUS_BAR,
54     WINDOW_TYPE_PANEL,
55     WINDOW_TYPE_KEYGUARD,
56     WINDOW_TYPE_VOLUME_OVERLAY,
57     WINDOW_TYPE_NAVIGATION_BAR,
58     WINDOW_TYPE_DRAGGING_EFFECT,
59     WINDOW_TYPE_POINTER,
60     WINDOW_TYPE_LAUNCHER_RECENT,
61     WINDOW_TYPE_LAUNCHER_DOCK,
62     WINDOW_TYPE_BOOT_ANIMATION,
63     WINDOW_TYPE_FREEZE_DISPLAY,
64     WINDOW_TYPE_VOICE_INTERACTION,
65     WINDOW_TYPE_FLOAT_CAMERA,
66     WINDOW_TYPE_PLACEHOLDER,
67     WINDOW_TYPE_DIALOG,
68     WINDOW_TYPE_SCREENSHOT,
69     ABOVE_APP_SYSTEM_WINDOW_END,
70 
71     SYSTEM_SUB_WINDOW_BASE = 2500,
72     WINDOW_TYPE_SYSTEM_SUB_WINDOW = SYSTEM_SUB_WINDOW_BASE,
73     SYSTEM_SUB_WINDOW_END,
74 
75     SYSTEM_WINDOW_END = SYSTEM_SUB_WINDOW_END,
76 };
77 
78 enum class WindowMode : uint32_t {
79     WINDOW_MODE_UNDEFINED = 0,
80     WINDOW_MODE_FULLSCREEN = 1,
81     WINDOW_MODE_SPLIT_PRIMARY = 100,
82     WINDOW_MODE_SPLIT_SECONDARY,
83     WINDOW_MODE_FLOATING,
84     WINDOW_MODE_PIP
85 };
86 
87 enum WindowModeSupport : uint32_t {
88     WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0,
89     WINDOW_MODE_SUPPORT_FLOATING = 1 << 1,
90     WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2,
91     WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3,
92     WINDOW_MODE_SUPPORT_PIP = 1 << 4,
93     WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN |
94                               WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
95                               WINDOW_MODE_SUPPORT_SPLIT_SECONDARY |
96                               WINDOW_MODE_SUPPORT_FLOATING |
97                               WINDOW_MODE_SUPPORT_PIP
98 };
99 
100 enum class WindowBlurStyle : uint32_t {
101     WINDOW_BLUR_OFF = 0,
102     WINDOW_BLUR_THIN,
103     WINDOW_BLUR_REGULAR,
104     WINDOW_BLUR_THICK
105 };
106 
107 enum class WindowState : uint32_t {
108     STATE_INITIAL,
109     STATE_CREATED,
110     STATE_SHOWN,
111     STATE_HIDDEN,
112     STATE_FROZEN,
113     STATE_DESTROYED,
114     STATE_BOTTOM = STATE_DESTROYED,
115     STATE_UNFROZEN,
116 };
117 
118 enum class WMError : int32_t {
119     WM_OK = 0,
120     WM_DO_NOTHING,
121     WM_ERROR_NO_MEM,
122     WM_ERROR_DESTROYED_OBJECT,
123     WM_ERROR_INVALID_WINDOW,
124     WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,
125     WM_ERROR_INVALID_OPERATION,
126     WM_ERROR_INVALID_PERMISSION,
127     WM_ERROR_NO_REMOTE_ANIMATION,
128 
129     WM_ERROR_DEVICE_NOT_SUPPORT = 801, // the value do not change.It is defined on all system
130 
131     WM_ERROR_NEED_REPORT_BASE = 1000, // error code > 1000 means need report
132     WM_ERROR_NULLPTR,
133     WM_ERROR_INVALID_TYPE,
134     WM_ERROR_INVALID_PARAM,
135     WM_ERROR_SAMGR,
136     WM_ERROR_IPC_FAILED,
137     WM_ERROR_NEED_REPORT_END,
138     WM_ERROR_START_ABILITY_FAILED,
139 };
140 
141 enum class WmErrorCode : int32_t {
142     WM_OK = 0,
143     WM_ERROR_NO_PERMISSION = 201,
144     WM_ERROR_INVALID_PARAM = 401,
145     WM_ERROR_DEVICE_NOT_SUPPORT = 801,
146     WM_ERROR_REPEAT_OPERATION = 1300001,
147     WM_ERROR_STATE_ABNORMALLY = 1300002,
148     WM_ERROR_SYSTEM_ABNORMALLY = 1300003,
149     WM_ERROR_INVALID_CALLING = 1300004,
150     WM_ERROR_STAGE_ABNORMALLY = 1300005,
151     WM_ERROR_CONTEXT_ABNORMALLY = 1300006,
152     WM_ERROR_START_ABILITY_FAILED = 1300007,
153 };
154 
155 const std::map<WMError, WmErrorCode> WM_JS_TO_ERROR_CODE_MAP {
156     {WMError::WM_OK,                                   WmErrorCode::WM_OK                         },
157     {WMError::WM_DO_NOTHING,                           WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
158     {WMError::WM_ERROR_DESTROYED_OBJECT,               WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
159     {WMError::WM_ERROR_DEVICE_NOT_SUPPORT,             WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT   },
160     {WMError::WM_ERROR_INVALID_OPERATION,              WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
161     {WMError::WM_ERROR_INVALID_PARAM,                  WmErrorCode::WM_ERROR_INVALID_PARAM        },
162     {WMError::WM_ERROR_INVALID_PERMISSION,             WmErrorCode::WM_ERROR_NO_PERMISSION        },
163     {WMError::WM_ERROR_INVALID_TYPE,                   WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
164     {WMError::WM_ERROR_INVALID_WINDOW,                 WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
165     {WMError::WM_ERROR_INVALID_WINDOW_MODE_OR_SIZE,    WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
166     {WMError::WM_ERROR_IPC_FAILED,                     WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY    },
167     {WMError::WM_ERROR_NO_MEM,                         WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY    },
168     {WMError::WM_ERROR_NO_REMOTE_ANIMATION,            WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY    },
169     {WMError::WM_ERROR_NULLPTR,                        WmErrorCode::WM_ERROR_STATE_ABNORMALLY     },
170     {WMError::WM_ERROR_SAMGR,                          WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY    },
171     {WMError::WM_ERROR_START_ABILITY_FAILED,           WmErrorCode::WM_ERROR_START_ABILITY_FAILED },
172 };
173 
174 enum class WindowFlag : uint32_t {
175     WINDOW_FLAG_NEED_AVOID = 1,
176     WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
177     WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
178     WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3,
179     WINDOW_FLAG_END = 1 << 4,
180 };
181 
182 enum class WindowSizeChangeReason : uint32_t {
183     UNDEFINED = 0,
184     MAXIMIZE,
185     RECOVER,
186     ROTATION,
187     DRAG,
188     DRAG_START,
189     DRAG_END,
190     RESIZE,
191     MOVE,
192     HIDE,
193     TRANSFORM,
194     CUSTOM_ANIMATION_SHOW,
195     END,
196 };
197 
198 enum class WindowLayoutMode : uint32_t {
199     BASE = 0,
200     CASCADE = BASE,
201     TILE = 1,
202     END,
203 };
204 
205 enum class DragEvent : uint32_t {
206     DRAG_EVENT_IN  = 1,
207     DRAG_EVENT_OUT,
208     DRAG_EVENT_MOVE,
209     DRAG_EVENT_END,
210 };
211 
212 enum class WindowTag : uint32_t {
213     MAIN_WINDOW = 0,
214     SUB_WINDOW = 1,
215     SYSTEM_WINDOW = 2,
216 };
217 
218 struct PointInfo {
219     int32_t x;
220     int32_t y;
221 };
222 
223 namespace {
224     constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
225     constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
226     constexpr uint32_t INVALID_WINDOW_ID = 0;
227     constexpr float UNDEFINED_BRIGHTNESS = -1.0f;
228     constexpr float MINIMUM_BRIGHTNESS = 0.0f;
229     constexpr float MAXIMUM_BRIGHTNESS = 1.0f;
230     constexpr int32_t INVALID_PID = -1;
231     constexpr int32_t INVALID_UID = -1;
232 }
233 
234 class Transform {
235 public:
Transform()236     Transform()
237         : pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), scaleZ_(1.f), rotationX_(0.f),
238           rotationY_(0.f), rotationZ_(0.f), translateX_(0.f), translateY_(0.f), translateZ_(0.f)
239     {}
~Transform()240     ~Transform() {}
241 
242     bool operator==(const Transform& right) const
243     {
244         return NearZero(pivotX_ - right.pivotX_) &&
245             NearZero(pivotY_ - right.pivotY_) &&
246             NearZero(scaleX_ - right.scaleX_) &&
247             NearZero(scaleY_ - right.scaleY_) &&
248             NearZero(scaleZ_ - right.scaleZ_) &&
249             NearZero(rotationX_ - right.rotationX_) &&
250             NearZero(rotationY_ - right.rotationY_) &&
251             NearZero(rotationZ_ - right.rotationZ_) &&
252             NearZero(translateX_ - right.translateX_) &&
253             NearZero(translateY_ - right.translateY_) &&
254             NearZero(translateZ_ - right.translateZ_);
255     }
256 
257     bool operator!=(const Transform& right) const
258     {
259         return !(*this == right);
260     }
261 
262     float pivotX_;
263     float pivotY_;
264     float scaleX_;
265     float scaleY_;
266     float scaleZ_;
267     float rotationX_;
268     float rotationY_;
269     float rotationZ_;
270     float translateX_;
271     float translateY_;
272     float translateZ_;
273 
Identity()274     static const Transform& Identity()
275     {
276         static Transform I;
277         return I;
278     }
279 
Marshalling(Parcel & parcel)280     bool Marshalling(Parcel& parcel) const
281     {
282         return parcel.WriteFloat(pivotX_) && parcel.WriteFloat(pivotY_) &&
283             parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) && parcel.WriteFloat(scaleZ_) &&
284             parcel.WriteFloat(rotationX_) && parcel.WriteFloat(rotationY_) &&
285             parcel.WriteFloat(rotationZ_) && parcel.WriteFloat(translateX_) &&
286             parcel.WriteFloat(translateY_) && parcel.WriteFloat(translateZ_);
287     }
288 
Unmarshalling(Parcel & parcel)289     void Unmarshalling(Parcel& parcel)
290     {
291         pivotX_ = parcel.ReadFloat();
292         pivotY_ = parcel.ReadFloat();
293         scaleX_ = parcel.ReadFloat();
294         scaleY_ = parcel.ReadFloat();
295         scaleZ_ = parcel.ReadFloat();
296         rotationX_ = parcel.ReadFloat();
297         rotationY_ = parcel.ReadFloat();
298         rotationZ_ = parcel.ReadFloat();
299         translateX_ = parcel.ReadFloat();
300         translateY_ = parcel.ReadFloat();
301         translateZ_ = parcel.ReadFloat();
302     }
303 private:
NearZero(float val)304     static inline bool NearZero(float val)
305     {
306         return val < 0.001f && val > -0.001f;
307     }
308 };
309 
310 struct SystemBarProperty {
311     bool enable_;
312     uint32_t backgroundColor_;
313     uint32_t contentColor_;
SystemBarPropertySystemBarProperty314     SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_BLACK), contentColor_(SYSTEM_COLOR_WHITE) {}
SystemBarPropertySystemBarProperty315     SystemBarProperty(bool enable, uint32_t background, uint32_t content)
316         : enable_(enable), backgroundColor_(background), contentColor_(content) {}
317     bool operator == (const SystemBarProperty& a) const
318     {
319         return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_);
320     }
321 };
322 
323 struct Rect {
324     int32_t posX_;
325     int32_t posY_;
326     uint32_t width_;
327     uint32_t height_;
328 
329     bool operator==(const Rect& a) const
330     {
331         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
332     }
333 
334     bool operator!=(const Rect& a) const
335     {
336         return !this->operator==(a);
337     }
338 
isUninitializedRectRect339     bool isUninitializedRect() const
340     {
341         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
342     }
343 
IsInsideOfRect344     bool IsInsideOf(const Rect& a) const
345     {
346         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
347             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
348     }
349 };
350 
351 enum class AvoidAreaType : uint32_t {
352     TYPE_SYSTEM,           // area of SystemUI
353     TYPE_CUTOUT,           // cutout of screen
354     TYPE_SYSTEM_GESTURE,   // area for system gesture
355     TYPE_KEYBOARD,         // area for soft input keyboard
356 };
357 
358 enum class OccupiedAreaType : uint32_t {
359     TYPE_INPUT, // area of input window
360 };
361 
362 enum class ColorSpace : uint32_t {
363     COLOR_SPACE_DEFAULT = 0, // Default color space.
364     COLOR_SPACE_WIDE_GAMUT,  // Wide gamut color space. The specific wide color gamut depends on the screen.
365 };
366 
367 enum class WindowAnimation : uint32_t {
368     NONE,
369     DEFAULT,
370     INPUTE,
371     CUSTOM,
372 };
373 
374 class AvoidArea : public Parcelable {
375 public:
376     Rect topRect_ { 0, 0, 0, 0 };
377     Rect leftRect_ { 0, 0, 0, 0 };
378     Rect rightRect_ { 0, 0, 0, 0 };
379     Rect bottomRect_ { 0, 0, 0, 0 };
380 
381     bool operator==(const AvoidArea& a) const
382     {
383         return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ &&
384             rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
385     }
386 
387     bool operator!=(const AvoidArea& a) const
388     {
389         return !this->operator==(a);
390     }
391 
isEmptyAvoidArea()392     bool isEmptyAvoidArea() const
393     {
394         return topRect_.isUninitializedRect() && leftRect_.isUninitializedRect() &&
395             rightRect_.isUninitializedRect() && bottomRect_.isUninitializedRect();
396     }
397 
WriteParcel(Parcel & parcel,const Rect & rect)398     static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
399     {
400         return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
401             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
402     }
403 
ReadParcel(Parcel & parcel,Rect & rect)404     static inline bool ReadParcel(Parcel& parcel, Rect& rect)
405     {
406         return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
407             parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
408     }
409 
Marshalling(Parcel & parcel)410     virtual bool Marshalling(Parcel& parcel) const override
411     {
412         return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) &&
413             WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_));
414     }
415 
Unmarshalling(Parcel & parcel)416     static AvoidArea* Unmarshalling(Parcel& parcel)
417     {
418         AvoidArea *avoidArea = new(std::nothrow) AvoidArea();
419         if (avoidArea == nullptr) {
420             return nullptr;
421         }
422         if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) &&
423             ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) {
424             return avoidArea;
425         }
426         delete avoidArea;
427         return nullptr;
428     }
429 };
430 
431 enum class WindowUpdateType : int32_t {
432     WINDOW_UPDATE_ADDED = 1,
433     WINDOW_UPDATE_REMOVED,
434     WINDOW_UPDATE_FOCUSED,
435     WINDOW_UPDATE_BOUNDS,
436     WINDOW_UPDATE_ACTIVE,
437     WINDOW_UPDATE_PROPERTY,
438 };
439 
440 using OnCallback = std::function<void(int64_t)>;
441 struct VsyncCallback {
442     OnCallback onCallback;
443 };
444 }
445 }
446 #endif // OHOS_ROSEN_WM_COMMON_H
447