• 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_INNER_H
17 #define OHOS_ROSEN_WM_COMMON_INNER_H
18 
19 #include <cfloat>
20 #include <cinttypes>
21 #include <unordered_set>
22 #include "wm_common.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 enum class LifeCycleEvent : uint32_t {
27     CREATE_EVENT,
28     SHOW_EVENT,
29     HIDE_EVENT,
30     DESTROY_EVENT,
31 };
32 
33 enum class WindowStateChangeReason : uint32_t {
34     NORMAL,
35     KEYGUARD,
36     TOGGLING,
37 };
38 
39 enum class WindowUpdateReason : uint32_t {
40     NEED_SWITCH_CASCADE_BASE,
41     UPDATE_ALL = NEED_SWITCH_CASCADE_BASE,
42     UPDATE_MODE,
43     UPDATE_RECT,
44     UPDATE_FLAGS,
45     UPDATE_TYPE,
46     NEED_SWITCH_CASCADE_END,
47     UPDATE_OTHER_PROPS,
48     UPDATE_TRANSFORM,
49 };
50 
51 enum class AvoidPosType : uint32_t {
52     AVOID_POS_LEFT,
53     AVOID_POS_TOP,
54     AVOID_POS_RIGHT,
55     AVOID_POS_BOTTOM,
56     AVOID_POS_UNKNOWN
57 };
58 
59 enum class WindowRootNodeType : uint32_t {
60     APP_WINDOW_NODE,
61     ABOVE_WINDOW_NODE,
62     BELOW_WINDOW_NODE,
63 };
64 
65 enum class PropertyChangeAction : uint32_t {
66     ACTION_UPDATE_RECT = 1,
67     ACTION_UPDATE_MODE = 1 << 1,
68     ACTION_UPDATE_FLAGS = 1 << 2,
69     ACTION_UPDATE_OTHER_PROPS = 1 << 3,
70     ACTION_UPDATE_FOCUSABLE = 1 << 4,
71     ACTION_UPDATE_TOUCHABLE = 1 << 5,
72     ACTION_UPDATE_CALLING_WINDOW = 1 << 6,
73     ACTION_UPDATE_ORIENTATION = 1 << 7,
74     ACTION_UPDATE_TURN_SCREEN_ON = 1 << 8,
75     ACTION_UPDATE_KEEP_SCREEN_ON = 1 << 9,
76     ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
77     ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11,
78     ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
79     ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
80     ACTION_UPDATE_ANIMATION_FLAG = 1 << 14,
81     ACTION_UPDATE_PRIVACY_MODE = 1 << 15,
82 };
83 
84 struct ModeChangeHotZonesConfig {
85     bool isModeChangeHotZoneConfigured_;
86     uint32_t fullscreenRange_;
87     uint32_t primaryRange_;
88     uint32_t secondaryRange_;
89 };
90 
91 struct WindowShadowParameters {
92     float elevation_;
93     std::string color_;
94     float offsetX_;
95     float offsetY_;
96     float alpha_;
97 };
98 
99 struct AppWindowEffectConfig {
100     float fullScreenCornerRadius_;
101     float splitCornerRadius_;
102     float floatCornerRadius_;
103 
104     WindowShadowParameters focusedShadow_;
105     WindowShadowParameters unfocusedShadow_;
106 
107     // defaultCornerRadiusL = 16.0vp
AppWindowEffectConfigAppWindowEffectConfig108     AppWindowEffectConfig() : fullScreenCornerRadius_(0.0), splitCornerRadius_(0.0), floatCornerRadius_(0.0)
109     {
110         focusedShadow_ = {0, "#000000", 0, 0, 0};
111         unfocusedShadow_ = {0, "#000000", 0, 0, 0};
112     }
113 };
114 
115 struct SystemConfig : public Parcelable {
116     bool isSystemDecorEnable_ = true;
117     bool isStretchable_ = false;
118     WindowMode defaultWindowMode_ = WindowMode::WINDOW_MODE_FULLSCREEN;
119     AppWindowEffectConfig effectConfig_;
120 
MarshallingSystemConfig121     virtual bool Marshalling(Parcel& parcel) const override
122     {
123         if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_)) {
124             return false;
125         }
126 
127         if (!parcel.WriteUint32(static_cast<uint32_t>(defaultWindowMode_))) {
128             return false;
129         }
130 
131         if (!parcel.WriteFloat(effectConfig_.fullScreenCornerRadius_) ||
132             !parcel.WriteFloat(effectConfig_.splitCornerRadius_) ||
133             !parcel.WriteFloat(effectConfig_.floatCornerRadius_)) {
134             return false;
135         }
136 
137         if (!parcel.WriteFloat(effectConfig_.focusedShadow_.elevation_) ||
138             !parcel.WriteString(effectConfig_.focusedShadow_.color_) ||
139             !parcel.WriteFloat(effectConfig_.focusedShadow_.offsetX_) ||
140             !parcel.WriteFloat(effectConfig_.focusedShadow_.offsetY_) ||
141             !parcel.WriteFloat(effectConfig_.focusedShadow_.alpha_)) {
142             return false;
143         }
144 
145         if (!parcel.WriteFloat(effectConfig_.unfocusedShadow_.elevation_) ||
146             !parcel.WriteString(effectConfig_.unfocusedShadow_.color_) ||
147             !parcel.WriteFloat(effectConfig_.unfocusedShadow_.offsetX_) ||
148             !parcel.WriteFloat(effectConfig_.unfocusedShadow_.offsetY_) ||
149             !parcel.WriteFloat(effectConfig_.unfocusedShadow_.alpha_)) {
150             return false;
151         }
152         return true;
153     }
154 
UnmarshallingSystemConfig155     static SystemConfig* Unmarshalling(Parcel& parcel)
156     {
157         SystemConfig* config = new SystemConfig();
158         config->isSystemDecorEnable_ = parcel.ReadBool();
159         config->isStretchable_ = parcel.ReadBool();
160         config->defaultWindowMode_ = static_cast<WindowMode>(parcel.ReadUint32());
161         config->effectConfig_.fullScreenCornerRadius_ = parcel.ReadFloat();
162         config->effectConfig_.splitCornerRadius_ = parcel.ReadFloat();
163         config->effectConfig_.floatCornerRadius_ = parcel.ReadFloat();
164         config->effectConfig_.focusedShadow_.elevation_ = parcel.ReadFloat();
165         config->effectConfig_.focusedShadow_.color_ = parcel.ReadString();
166         config->effectConfig_.focusedShadow_.offsetX_ = parcel.ReadFloat();
167         config->effectConfig_.focusedShadow_.offsetY_ = parcel.ReadFloat();
168         config->effectConfig_.focusedShadow_.alpha_ = parcel.ReadFloat();
169         config->effectConfig_.unfocusedShadow_.elevation_ = parcel.ReadFloat();
170         config->effectConfig_.unfocusedShadow_.color_ = parcel.ReadString();
171         config->effectConfig_.unfocusedShadow_.offsetX_ = parcel.ReadFloat();
172         config->effectConfig_.unfocusedShadow_.offsetY_ = parcel.ReadFloat();
173         config->effectConfig_.unfocusedShadow_.alpha_ = parcel.ReadFloat();
174         return config;
175     }
176 };
177 
178 struct WindowSizeLimits {
179     uint32_t maxWidth_;
180     uint32_t maxHeight_;
181     uint32_t minWidth_;
182     uint32_t minHeight_;
183     float maxRatio_;
184     float minRatio_;
WindowSizeLimitsWindowSizeLimits185     WindowSizeLimits() : maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX),
186         minWidth_(0),  minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {}
WindowSizeLimitsWindowSizeLimits187     WindowSizeLimits(uint32_t maxWidth, uint32_t maxHeight,
188         uint32_t minWidth, uint32_t minHeight, float maxRatio, float minRatio)
189         : maxWidth_(maxWidth), maxHeight_(maxHeight),
190         minWidth_(minWidth), minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {}
191 };
192 
193 struct ModeChangeHotZones {
194     Rect fullscreen_;
195     Rect primary_;
196     Rect secondary_;
197 };
198 
199 struct SplitRatioConfig {
200     // when divider reaches this position, the top/left window will hide. Valid range: (0, 0.5)
201     float exitSplitStartRatio;
202     // when divider reaches this position, the bottom/right window will hide. Valid range: (0.5, 1)
203     float exitSplitEndRatio;
204     std::vector<float> splitRatios;
205 };
206 
207 enum class DragType : uint32_t {
208     DRAG_UNDEFINED,
209     DRAG_LEFT_OR_RIGHT,
210     DRAG_BOTTOM_OR_TOP,
211     DRAG_LEFT_TOP_CORNER,
212     DRAG_RIGHT_TOP_CORNER,
213 };
214 
215 enum class TraceTaskId : int32_t {
216     STARTING_WINDOW = 0,
217     REMOTE_ANIMATION,
218     CONNECT_EXTENSION,
219 };
220 
221 struct MoveDragProperty : public Parcelable {
222     int32_t startPointPosX_;
223     int32_t startPointPosY_;
224     int32_t startPointerId_;
225     int32_t targetDisplayId_;
226     int32_t sourceType_;
227     bool startDragFlag_;
228     bool startMoveFlag_;
229     bool pointEventStarted_;
230     DragType dragType_;
231     Rect startPointRect_;
232     Rect startRectExceptFrame_;
233     Rect startRectExceptCorner_;
234 
MoveDragPropertyMoveDragProperty235     MoveDragProperty() : startPointPosX_(0), startPointPosY_(0), startPointerId_(0), targetDisplayId_(0),
236         sourceType_(0), startDragFlag_(false), startMoveFlag_(false), pointEventStarted_(false),
237         dragType_(DragType::DRAG_UNDEFINED)
238     {
239         startPointRect_ = {0, 0, 0, 0};
240         startRectExceptFrame_ = {0, 0, 0, 0};
241         startRectExceptCorner_ = {0, 0, 0, 0};
242     }
243 
MoveDragPropertyMoveDragProperty244     MoveDragProperty(int32_t startPointPosX, int32_t startPointPosY, int32_t startPointerId, int32_t targetDisplayId,
245         int32_t sourceType, bool startDragFlag, bool startMoveFlag, bool pointEventStarted, DragType dragType,
246         Rect startPointRect, Rect startRectExceptFrame, Rect startRectExceptCorner)
247         : startPointPosX_(startPointPosX), startPointPosY_(startPointPosY), startPointerId_(startPointerId),
248         targetDisplayId_(targetDisplayId), sourceType_(sourceType), startDragFlag_(startDragFlag),
249         startMoveFlag_(startMoveFlag), pointEventStarted_(pointEventStarted), dragType_(dragType),
250         startPointRect_(startPointRect), startRectExceptFrame_(startRectExceptFrame),
251         startRectExceptCorner_(startRectExceptCorner) {}
252 
MarshallingMoveDragProperty253     virtual bool Marshalling(Parcel& parcel) const override
254     {
255         if (!parcel.WriteInt32(startPointPosX_) || !parcel.WriteInt32(startPointPosY_) ||
256             !parcel.WriteInt32(startPointerId_) || !parcel.WriteInt32(targetDisplayId_) ||
257             !parcel.WriteInt32(sourceType_) || !parcel.WriteBool(startDragFlag_) ||
258             !parcel.WriteBool(startMoveFlag_) || !parcel.WriteBool(pointEventStarted_) ||
259             !parcel.WriteUint32(static_cast<uint32_t>(dragType_))) {
260             return false;
261         }
262 
263         if (!parcel.WriteInt32(startPointRect_.posX_) || !parcel.WriteInt32(startPointRect_.posY_) ||
264             !parcel.WriteUint32(startPointRect_.width_) || !parcel.WriteUint32(startPointRect_.height_)) {
265             return false;
266         }
267 
268         if (!parcel.WriteInt32(startRectExceptFrame_.posX_) || !parcel.WriteInt32(startRectExceptFrame_.posY_) ||
269             !parcel.WriteUint32(startRectExceptFrame_.width_) || !parcel.WriteUint32(startRectExceptFrame_.height_)) {
270             return false;
271         }
272 
273         if (!parcel.WriteInt32(startRectExceptCorner_.posX_) || !parcel.WriteInt32(startRectExceptCorner_.posY_) ||
274             !parcel.WriteUint32(startRectExceptCorner_.width_) || !parcel.WriteUint32(startRectExceptCorner_.height_)) {
275             return false;
276         }
277 
278         return true;
279     }
280 
UnmarshallingMoveDragProperty281     static MoveDragProperty* Unmarshalling(Parcel& parcel)
282     {
283         MoveDragProperty* info = new MoveDragProperty();
284         info->startPointPosX_ = parcel.ReadInt32();
285         info->startPointPosY_ = parcel.ReadInt32();
286         info->startPointerId_ = parcel.ReadInt32();
287         info->targetDisplayId_ = parcel.ReadInt32();
288         info->sourceType_ = parcel.ReadInt32();
289         info->startDragFlag_ = parcel.ReadBool();
290         info->startMoveFlag_ = parcel.ReadBool();
291         info->pointEventStarted_ = parcel.ReadBool();
292         info->dragType_ = static_cast<DragType>(parcel.ReadUint32());
293         Rect startPointRect = { parcel.ReadInt32(), parcel.ReadInt32(),
294                                 parcel.ReadUint32(), parcel.ReadUint32() };
295         Rect startRectExceptFrame = { parcel.ReadInt32(), parcel.ReadInt32(),
296                                       parcel.ReadUint32(), parcel.ReadUint32() };
297         Rect startRectExceptCorner = { parcel.ReadInt32(), parcel.ReadInt32(),
298                                        parcel.ReadUint32(), parcel.ReadUint32() };
299         info->startPointRect_ = startPointRect;
300         info->startRectExceptFrame_ = startRectExceptFrame;
301         info->startRectExceptCorner_ = startRectExceptCorner;
302         return info;
303     }
304 
CopyFromMoveDragProperty305     void CopyFrom(const sptr<MoveDragProperty>& property)
306     {
307         startPointPosX_ = property->startPointPosX_;
308         startPointPosY_ = property->startPointPosY_;
309         startPointerId_ = property->startPointerId_;
310         targetDisplayId_ = property->targetDisplayId_;
311         sourceType_ = property->sourceType_;
312         startDragFlag_ = property->startDragFlag_;
313         startMoveFlag_ = property->startMoveFlag_;
314         pointEventStarted_ = property->pointEventStarted_;
315         dragType_ = property->dragType_;
316         startPointRect_ = property->startPointRect_;
317         startRectExceptFrame_ = property->startRectExceptFrame_;
318         startRectExceptCorner_ = property->startRectExceptCorner_;
319     }
320 };
321 
322 struct AbilityInfo {
323     std::string bundleName_ = "";
324     std::string abilityName_ = "";
325     int32_t missionId_ = -1;
326 };
327 
328 namespace {
329     constexpr float DEFAULT_SPLIT_RATIO = 0.5;
330     constexpr float DEFAULT_ASPECT_RATIO = 0.67;
331     constexpr float DISPLAY_ZOOM_OFF_SCALE = 1.0;
332     constexpr float DISPLAY_ZOOM_MIN_SCALE = 2.0;
333     constexpr float DISPLAY_ZOOM_MAX_SCALE = 8.0;
334     constexpr int32_t IVALID_DIALOG_WINDOW_ID = -1;
335     constexpr uint32_t DIVIDER_WIDTH = 8;
336     constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 37;
337     constexpr uint32_t WINDOW_FRAME_WIDTH = 5;
338     constexpr uint32_t WINDOW_FRAME_CORNER_WIDTH = 16; // the frame width of corner
339     constexpr uint32_t HOTZONE_TOUCH = 20;
340     constexpr uint32_t HOTZONE_POINTER = 4;
341     constexpr uint32_t MIN_FLOATING_WIDTH = 320;
342     constexpr uint32_t MIN_FLOATING_HEIGHT = 240;
343     constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240;
344     constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320;
345     constexpr uint32_t MAX_FLOATING_SIZE = 1920;
346     constexpr unsigned int WMS_WATCHDOG_CHECK_INTERVAL = 6; // actual check interval is 3000ms(6 * 500)
347     const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0};
348     const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512};
349     const std::unordered_set<WindowType> INPUT_WINDOW_TYPE_SKIPPED {
350         WindowType::WINDOW_TYPE_POINTER,
351         WindowType::WINDOW_TYPE_DRAGGING_EFFECT,
352     };
353 }
354 }
355 }
356 #endif // OHOS_ROSEN_WM_COMMON_INNER_H