1 /*
2 * Copyright (c) 2021-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 #include "window_node.h"
17
18 #include "rs_adapter.h"
19 #include "window_helper.h"
20 #include "window_manager_hilog.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowNode"};
26 }
27
~WindowNode()28 WindowNode::~WindowNode()
29 {
30 WLOGI("~WindowNode id:%{public}u", GetWindowId());
31 }
32
SetDisplayId(DisplayId displayId)33 void WindowNode::SetDisplayId(DisplayId displayId)
34 {
35 property_->SetDisplayId(displayId);
36 }
37
SetEntireWindowTouchHotArea(const Rect & rect)38 void WindowNode::SetEntireWindowTouchHotArea(const Rect& rect)
39 {
40 entireWindowTouchHotArea_ = rect;
41 }
42
SetEntireWindowPointerHotArea(const Rect & rect)43 void WindowNode::SetEntireWindowPointerHotArea(const Rect& rect)
44 {
45 entireWindowPointerHotArea_ = rect;
46 }
47
SetWindowRect(const Rect & rect)48 void WindowNode::SetWindowRect(const Rect& rect)
49 {
50 property_->SetWindowRect(rect);
51 }
52
SetDecorEnable(bool decorEnable)53 void WindowNode::SetDecorEnable(bool decorEnable)
54 {
55 property_->SetDecorEnable(decorEnable);
56 }
57
SetDecoStatus(bool decoStatus)58 void WindowNode::SetDecoStatus(bool decoStatus)
59 {
60 property_->SetDecoStatus(decoStatus);
61 }
62
SetRequestRect(const Rect & rect)63 void WindowNode::SetRequestRect(const Rect& rect)
64 {
65 property_->SetRequestRect(rect);
66 }
67
SetWindowProperty(const sptr<WindowProperty> & property)68 void WindowNode::SetWindowProperty(const sptr<WindowProperty>& property)
69 {
70 property_ = property;
71 }
72
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)73 void WindowNode::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
74 {
75 property_->SetSystemBarProperty(type, property);
76 }
77
SetWindowMode(WindowMode mode)78 void WindowNode::SetWindowMode(WindowMode mode)
79 {
80 property_->SetWindowMode(mode);
81 }
82
SetBrightness(float brightness)83 void WindowNode::SetBrightness(float brightness)
84 {
85 property_->SetBrightness(brightness);
86 }
87
SetFocusable(bool focusable)88 void WindowNode::SetFocusable(bool focusable)
89 {
90 property_->SetFocusable(focusable);
91 }
92
SetTouchable(bool touchable)93 void WindowNode::SetTouchable(bool touchable)
94 {
95 property_->SetTouchable(touchable);
96 }
97
SetTurnScreenOn(bool turnScreenOn)98 void WindowNode::SetTurnScreenOn(bool turnScreenOn)
99 {
100 property_->SetTurnScreenOn(turnScreenOn);
101 }
102
SetKeepScreenOn(bool keepScreenOn)103 void WindowNode::SetKeepScreenOn(bool keepScreenOn)
104 {
105 property_->SetKeepScreenOn(keepScreenOn);
106 }
107
SetCallingWindow(uint32_t windowId)108 void WindowNode::SetCallingWindow(uint32_t windowId)
109 {
110 property_->SetCallingWindow(windowId);
111 }
112
GetCallingWindow() const113 uint32_t WindowNode::GetCallingWindow() const
114 {
115 return property_->GetCallingWindow();
116 }
117
SetWindowSizeChangeReason(WindowSizeChangeReason reason)118 void WindowNode::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
119 {
120 windowSizeChangeReason_ = reason;
121 }
122
SetRequestedOrientation(Orientation orientation)123 void WindowNode::SetRequestedOrientation(Orientation orientation)
124 {
125 property_->SetRequestedOrientation(orientation);
126 }
127
SetShowingDisplays(const std::vector<DisplayId> & displayIdVec)128 void WindowNode::SetShowingDisplays(const std::vector<DisplayId>& displayIdVec)
129 {
130 showingDisplays_.clear();
131 showingDisplays_.assign(displayIdVec.begin(), displayIdVec.end());
132 }
133
SetWindowModeSupportType(uint32_t windowModeSupportType)134 void WindowNode::SetWindowModeSupportType(uint32_t windowModeSupportType)
135 {
136 property_->SetWindowModeSupportType(windowModeSupportType);
137 }
138
ResetWindowSizeChangeReason()139 void WindowNode::ResetWindowSizeChangeReason()
140 {
141 windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
142 }
143
GetWindowToken() const144 const sptr<IWindow>& WindowNode::GetWindowToken() const
145 {
146 return windowToken_;
147 }
148
SetWindowToken(sptr<IWindow> window)149 void WindowNode::SetWindowToken(sptr<IWindow> window)
150 {
151 windowToken_ = window;
152 }
153
SetInputEventCallingPid(int32_t pid)154 void WindowNode::SetInputEventCallingPid(int32_t pid)
155 {
156 inputCallingPid_ = pid;
157 }
158
SetCallingPid(int32_t pid)159 void WindowNode::SetCallingPid(int32_t pid)
160 {
161 callingPid_ = pid;
162 SetInputEventCallingPid(pid);
163 }
164
SetCallingUid(int32_t uid)165 void WindowNode::SetCallingUid(int32_t uid)
166 {
167 callingUid_ = uid;
168 }
169
SetDragType(DragType dragType)170 void WindowNode::SetDragType(DragType dragType)
171 {
172 property_->SetDragType(dragType);
173 }
174
SetOriginRect(const Rect & rect)175 void WindowNode::SetOriginRect(const Rect& rect)
176 {
177 property_->SetOriginRect(rect);
178 }
179
SetTouchHotAreas(const std::vector<Rect> & rects)180 void WindowNode::SetTouchHotAreas(const std::vector<Rect>& rects)
181 {
182 touchHotAreas_ = rects;
183 }
184
SetPointerHotAreas(const std::vector<Rect> & rects)185 void WindowNode::SetPointerHotAreas(const std::vector<Rect>& rects)
186 {
187 pointerHotAreas_ = rects;
188 }
189
SetWindowSizeLimits(const WindowLimits & sizeLimits)190 void WindowNode::SetWindowSizeLimits(const WindowLimits& sizeLimits)
191 {
192 property_->SetSizeLimits(sizeLimits);
193 }
194
SetWindowUpdatedSizeLimits(const WindowLimits & sizeLimits)195 void WindowNode::SetWindowUpdatedSizeLimits(const WindowLimits& sizeLimits)
196 {
197 property_->SetUpdatedSizeLimits(sizeLimits);
198 }
199
ComputeTransform()200 void WindowNode::ComputeTransform()
201 {
202 property_->ComputeTransform();
203 }
204
SetTransform(const Transform & trans)205 void WindowNode::SetTransform(const Transform& trans)
206 {
207 property_->SetTransform(trans);
208 }
209
GetZoomTransform() const210 Transform WindowNode::GetZoomTransform() const
211 {
212 return property_->GetZoomTransform();
213 }
214
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)215 void WindowNode::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
216 {
217 property_->SetZoomTransform(trans);
218 property_->SetDisplayZoomState(isDisplayZoomOn);
219 if (windowToken_) {
220 windowToken_->UpdateZoomTransform(trans, isDisplayZoomOn);
221 }
222 }
223
GetWindowSizeLimits() const224 WindowLimits WindowNode::GetWindowSizeLimits() const
225 {
226 return property_->GetSizeLimits();
227 }
228
GetWindowUpdatedSizeLimits() const229 WindowLimits WindowNode::GetWindowUpdatedSizeLimits() const
230 {
231 return property_->GetUpdatedSizeLimits();
232 }
233
GetDragType() const234 DragType WindowNode::GetDragType() const
235 {
236 return property_->GetDragType();
237 }
238
GetStretchable() const239 bool WindowNode::GetStretchable() const
240 {
241 return property_->GetStretchable();
242 }
243
GetOriginRect() const244 const Rect& WindowNode::GetOriginRect() const
245 {
246 return property_->GetOriginRect();
247 }
248
GetDisplayId() const249 DisplayId WindowNode::GetDisplayId() const
250 {
251 return property_->GetDisplayId();
252 }
253
GetWindowName() const254 const std::string& WindowNode::GetWindowName() const
255 {
256 return property_->GetWindowName();
257 }
258
GetWindowId() const259 uint32_t WindowNode::GetWindowId() const
260 {
261 return property_->GetWindowId();
262 }
263
GetParentId() const264 uint32_t WindowNode::GetParentId() const
265 {
266 return property_->GetParentId();
267 }
268
GetEntireWindowTouchHotArea() const269 Rect WindowNode::GetEntireWindowTouchHotArea() const
270 {
271 return entireWindowTouchHotArea_;
272 }
273
GetEntireWindowPointerHotArea() const274 Rect WindowNode::GetEntireWindowPointerHotArea() const
275 {
276 return entireWindowPointerHotArea_;
277 }
278
GetWindowRect() const279 Rect WindowNode::GetWindowRect() const
280 {
281 return property_->GetWindowRect();
282 }
283
GetDecoStatus() const284 bool WindowNode::GetDecoStatus() const
285 {
286 return property_->GetDecoStatus();
287 }
288
GetRequestRect() const289 Rect WindowNode::GetRequestRect() const
290 {
291 return property_->GetRequestRect();
292 }
293
GetWindowType() const294 WindowType WindowNode::GetWindowType() const
295 {
296 return property_->GetWindowType();
297 }
298
GetWindowMode() const299 WindowMode WindowNode::GetWindowMode() const
300 {
301 return property_->GetWindowMode();
302 }
303
EnableDefaultAnimation(bool animationPlayed)304 bool WindowNode::EnableDefaultAnimation(bool animationPlayed)
305 {
306 // system config enabled && not in remote animation && not custom animation && not crash
307 bool defaultAnimation = property_->GetAnimationFlag() == (static_cast<uint32_t>(WindowAnimation::DEFAULT));
308 return ((!animationPlayed) && (defaultAnimation) && (!isAppCrash_));
309 }
310
GetBrightness() const311 float WindowNode::GetBrightness() const
312 {
313 return property_->GetBrightness();
314 }
315
IsTurnScreenOn() const316 bool WindowNode::IsTurnScreenOn() const
317 {
318 return property_->IsTurnScreenOn();
319 }
320
IsKeepScreenOn() const321 bool WindowNode::IsKeepScreenOn() const
322 {
323 return property_->IsKeepScreenOn();
324 }
325
GetWindowFlags() const326 uint32_t WindowNode::GetWindowFlags() const
327 {
328 return property_->GetWindowFlags();
329 }
330
GetWindowProperty() const331 const sptr<WindowProperty>& WindowNode::GetWindowProperty() const
332 {
333 return property_;
334 }
335
GetInputEventCallingPid() const336 int32_t WindowNode::GetInputEventCallingPid() const
337 {
338 return inputCallingPid_;
339 }
340
GetCallingPid() const341 int32_t WindowNode::GetCallingPid() const
342 {
343 return callingPid_;
344 }
345
GetCallingUid() const346 int32_t WindowNode::GetCallingUid() const
347 {
348 return callingUid_;
349 }
350
GetSystemBarProperty() const351 const std::unordered_map<WindowType, SystemBarProperty>& WindowNode::GetSystemBarProperty() const
352 {
353 return property_->GetSystemBarProperty();
354 }
355
IsSplitMode() const356 bool WindowNode::IsSplitMode() const
357 {
358 return (property_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ||
359 property_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
360 }
361
GetWindowSizeChangeReason() const362 WindowSizeChangeReason WindowNode::GetWindowSizeChangeReason() const
363 {
364 return windowSizeChangeReason_;
365 }
366
GetRequestedOrientation() const367 Orientation WindowNode::GetRequestedOrientation() const
368 {
369 return property_->GetRequestedOrientation();
370 }
371
GetShowingDisplays() const372 std::vector<DisplayId> WindowNode::GetShowingDisplays() const
373 {
374 return showingDisplays_;
375 }
376
GetWindowModeSupportType() const377 uint32_t WindowNode::GetWindowModeSupportType() const
378 {
379 return property_->GetWindowModeSupportType();
380 }
381
GetTouchHotAreas(std::vector<Rect> & rects) const382 void WindowNode::GetTouchHotAreas(std::vector<Rect>& rects) const
383 {
384 rects = touchHotAreas_;
385 }
386
GetPointerHotAreas(std::vector<Rect> & rects) const387 void WindowNode::GetPointerHotAreas(std::vector<Rect>& rects) const
388 {
389 rects = pointerHotAreas_;
390 }
391
GetAccessTokenId() const392 uint32_t WindowNode::GetAccessTokenId() const
393 {
394 return property_->GetAccessTokenId();
395 }
396
SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap)397 void WindowNode::SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap)
398 {
399 snapshot_ = pixelMap;
400 }
401
GetSnapshot()402 std::shared_ptr<Media::PixelMap> WindowNode::GetSnapshot()
403 {
404 return snapshot_;
405 }
406
SetAspectRatio(float ratio)407 void WindowNode::SetAspectRatio(float ratio)
408 {
409 property_->SetAspectRatio(ratio);
410 }
411
GetAspectRatio() const412 float WindowNode::GetAspectRatio() const
413 {
414 return property_->GetAspectRatio();
415 }
416
SetWindowGravity(WindowGravity gravity,uint32_t percent)417 void WindowNode::SetWindowGravity(WindowGravity gravity, uint32_t percent)
418 {
419 property_->SetWindowGravity(gravity, percent);
420 }
421
GetWindowGravity(WindowGravity & gravity,uint32_t & percent) const422 void WindowNode::GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const
423 {
424 property_->GetWindowGravity(gravity, percent);
425 }
426
SetVisibilityState(WindowVisibilityState state)427 void WindowNode::SetVisibilityState(WindowVisibilityState state)
428 {
429 visibilityState_ = state;
430 }
431
GetVisibilityState() const432 WindowVisibilityState WindowNode::GetVisibilityState() const
433 {
434 return visibilityState_;
435 }
436
GetTouchable() const437 bool WindowNode::GetTouchable() const
438 {
439 return property_->GetTouchable();
440 }
441
GetRSUIContext() const442 std::shared_ptr<RSUIContext> WindowNode::GetRSUIContext() const
443 {
444 RETURN_IF_RS_CLIENT_MULTI_INSTANCE_DISABLED(nullptr);
445 std::shared_ptr<RSUIContext> rsUIContext;
446 for (const auto& node : {surfaceNode_, leashWinSurfaceNode_, startingWinSurfaceNode_, closeWinSurfaceNode_}) {
447 if (node) {
448 rsUIContext = node->GetRSUIContext();
449 if (rsUIContext) {
450 break;
451 }
452 }
453 }
454 TLOGD(WmsLogTag::WMS_SCB, "%{public}s",
455 RSAdapterUtil::RSUIContextToStr(rsUIContext).c_str());
456 return rsUIContext;
457 }
458 } // namespace Rosen
459 } // namespace OHOS
460