• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_property.h"
17 #include "window_helper.h"
18 #include "wm_common.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23     constexpr uint32_t SYSTEM_BAR_PROPERTY_MAX_NUM = 2;
24     constexpr uint32_t TOUCH_HOT_AREA_MAX_NUM = 10;
25 }
WindowProperty(const sptr<WindowProperty> & property)26 WindowProperty::WindowProperty(const sptr<WindowProperty>& property)
27 {
28     CopyFrom(property);
29 }
30 
SetWindowName(const std::string & name)31 void WindowProperty::SetWindowName(const std::string& name)
32 {
33     windowName_ = name;
34 }
35 
SetAbilityInfo(const AbilityInfo & info)36 void WindowProperty::SetAbilityInfo(const AbilityInfo& info)
37 {
38     abilityInfo_ = info;
39 }
40 
SetWindowRect(const struct Rect & rect)41 void WindowProperty::SetWindowRect(const struct Rect& rect)
42 {
43     ComputeTransform();
44     windowRect_ = rect;
45 }
46 
SetDecoStatus(bool decoStatus)47 void WindowProperty::SetDecoStatus(bool decoStatus)
48 {
49     decoStatus_ = decoStatus;
50 }
51 
SetRequestRect(const Rect & requestRect)52 void WindowProperty::SetRequestRect(const Rect& requestRect)
53 {
54     requestRect_ = requestRect;
55 }
56 
SetWindowType(WindowType type)57 void WindowProperty::SetWindowType(WindowType type)
58 {
59     type_ = type;
60 }
61 
SetWindowMode(WindowMode mode)62 void WindowProperty::SetWindowMode(WindowMode mode)
63 {
64     if (!WindowHelper::IsValidWindowMode(mode) || !WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) {
65         return;
66     }
67     if (!WindowHelper::IsSplitWindowMode(mode_)) {
68         lastMode_ = mode_;
69     }
70     mode_ = mode;
71 }
72 
SetLastWindowMode(WindowMode mode)73 void WindowProperty::SetLastWindowMode(WindowMode mode)
74 {
75     if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) {
76         return;
77     }
78     lastMode_ = mode;
79 }
80 
SetFullScreen(bool isFullScreen)81 void WindowProperty::SetFullScreen(bool isFullScreen)
82 {
83     isFullScreen_ = isFullScreen;
84 }
85 
SetFocusable(bool isFocusable)86 void WindowProperty::SetFocusable(bool isFocusable)
87 {
88     focusable_ = isFocusable;
89 }
90 
SetTouchable(bool isTouchable)91 void WindowProperty::SetTouchable(bool isTouchable)
92 {
93     touchable_ = isTouchable;
94 }
95 
SetPrivacyMode(bool isPrivate)96 void WindowProperty::SetPrivacyMode(bool isPrivate)
97 {
98     isPrivacyMode_ = isPrivate;
99 }
100 
SetSystemPrivacyMode(bool isSystemPrivate)101 void WindowProperty::SetSystemPrivacyMode(bool isSystemPrivate)
102 {
103     isSystemPrivacyMode_ = isSystemPrivate;
104 }
105 
SetTransparent(bool isTransparent)106 void WindowProperty::SetTransparent(bool isTransparent)
107 {
108     isTransparent_ = isTransparent;
109 }
110 
SetAlpha(float alpha)111 void WindowProperty::SetAlpha(float alpha)
112 {
113     alpha_ = alpha;
114 }
115 
SetTransform(const Transform & trans)116 void WindowProperty::SetTransform(const Transform& trans)
117 {
118     recomputeTransformMat_ = true;
119     trans_ = trans;
120 }
121 
HandleComputeTransform(const Transform & trans)122 void WindowProperty::HandleComputeTransform(const Transform& trans)
123 {
124     TransformHelper::Vector3 pivotPos = { windowRect_.posX_ + trans.pivotX_ * windowRect_.width_,
125         windowRect_.posY_ + trans.pivotY_ * windowRect_.height_, 0 };
126     worldTransformMat_ = TransformHelper::CreateTranslation(-pivotPos) *
127                             WindowHelper::ComputeWorldTransformMat4(trans) *
128                             TransformHelper::CreateTranslation(pivotPos);
129     // transformMat = worldTransformMat * viewProjectionMat
130     transformMat_ = worldTransformMat_;
131     // Z component of camera position is constant value
132     constexpr float cameraZ = -576.f;
133     TransformHelper::Vector3 cameraPos(pivotPos.x_ + trans.translateX_, pivotPos.y_ + trans.translateY_, cameraZ);
134     // Concatenate with view projection matrix
135     transformMat_ *= TransformHelper::CreateLookAt(cameraPos,
136         TransformHelper::Vector3(cameraPos.x_, cameraPos.y_, 0), TransformHelper::Vector3(0, 1, 0)) *
137         TransformHelper::CreatePerspective(cameraPos);
138 }
139 
ComputeTransform()140 void WindowProperty::ComputeTransform()
141 {
142     if (isDisplayZoomOn_) {
143         if (reCalcuZoomTransformMat_) {
144             HandleComputeTransform(zoomTrans_);
145             reCalcuZoomTransformMat_ = false;
146         }
147     } else if (recomputeTransformMat_) {
148         HandleComputeTransform(trans_);
149         recomputeTransformMat_ = false;
150     }
151 }
152 
SetZoomTransform(const Transform & trans)153 void WindowProperty::SetZoomTransform(const Transform& trans)
154 {
155     zoomTrans_ = trans;
156     reCalcuZoomTransformMat_ = true;
157 }
158 
ClearTransformZAxisOffset(Transform & trans)159 void WindowProperty::ClearTransformZAxisOffset(Transform& trans)
160 {
161     // replace Z axis translation by scaling
162     TransformHelper::Matrix4 preTransformMat = transformMat_;
163     HandleComputeTransform(trans);
164     Rect rect = WindowHelper::TransformRect(transformMat_, windowRect_);
165     float translateZ = trans.translateZ_;
166     trans.translateZ_ = 0.f;
167     HandleComputeTransform(trans);
168     Rect rectWithoutZAxisOffset = WindowHelper::TransformRect(transformMat_, windowRect_);
169     if (rectWithoutZAxisOffset.width_ == 0) {
170         trans.translateZ_ = translateZ;
171         return;
172     }
173     float scale = rect.width_ * 1.0f / rectWithoutZAxisOffset.width_;
174     trans.scaleX_ *= scale;
175     trans.scaleY_ *= scale;
176     transformMat_ = preTransformMat;
177 }
178 
UpdatePointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)179 void WindowProperty::UpdatePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
180 {
181     if (trans_ == Transform::Identity() && zoomTrans_ == Transform::Identity()) {
182         return;
183     }
184     ComputeTransform();
185     MMI::PointerEvent::PointerItem pointerItem;
186     if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
187         return;
188     }
189     PointInfo originPos =
190         WindowHelper::CalculateOriginPosition(transformMat_,
191         { pointerItem.GetDisplayX(), pointerItem.GetDisplayY() });
192     pointerItem.SetDisplayX(originPos.x);
193     pointerItem.SetDisplayY(originPos.y);
194     pointerItem.SetWindowX(originPos.x - windowRect_.posX_);
195     pointerItem.SetWindowY(originPos.y - windowRect_.posY_);
196     pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem);
197 }
198 
isNeedComputerTransform()199 bool WindowProperty::isNeedComputerTransform()
200 {
201     return ((!isDisplayZoomOn_ && trans_ != Transform::Identity()) || zoomTrans_ != Transform::Identity());
202 }
203 
SetAnimateWindowFlag(bool isAnimateWindow)204 void WindowProperty::SetAnimateWindowFlag(bool isAnimateWindow)
205 {
206     isAnimateWindow_ = isAnimateWindow;
207 }
208 
SetDisplayZoomState(bool isDisplayZoomOn)209 void WindowProperty::SetDisplayZoomState(bool isDisplayZoomOn)
210 {
211     isDisplayZoomOn_ = isDisplayZoomOn;
212 }
213 
IsDisplayZoomOn() const214 bool WindowProperty::IsDisplayZoomOn() const
215 {
216     return isDisplayZoomOn_;
217 }
218 
IsAnimateWindow() const219 bool WindowProperty::IsAnimateWindow() const
220 {
221     return isAnimateWindow_;
222 }
223 
GetZoomTransform() const224 const Transform& WindowProperty::GetZoomTransform() const
225 {
226     return zoomTrans_;
227 }
228 
SetBrightness(float brightness)229 void WindowProperty::SetBrightness(float brightness)
230 {
231     brightness_ = brightness;
232 }
233 
SetTurnScreenOn(bool turnScreenOn)234 void WindowProperty::SetTurnScreenOn(bool turnScreenOn)
235 {
236     turnScreenOn_ = turnScreenOn;
237 }
238 
SetKeepScreenOn(bool keepScreenOn)239 void WindowProperty::SetKeepScreenOn(bool keepScreenOn)
240 {
241     keepScreenOn_ = keepScreenOn;
242 }
243 
SetCallingWindow(uint32_t windowId)244 void WindowProperty::SetCallingWindow(uint32_t windowId)
245 {
246     callingWindow_ = windowId;
247 }
248 
SetDisplayId(DisplayId displayId)249 void WindowProperty::SetDisplayId(DisplayId displayId)
250 {
251     displayId_ = displayId;
252 }
253 
SetWindowFlags(uint32_t flags)254 void WindowProperty::SetWindowFlags(uint32_t flags)
255 {
256     flags_ = flags;
257 }
258 
SetSizeLimits(const WindowSizeLimits & sizeLimits)259 void WindowProperty::SetSizeLimits(const WindowSizeLimits& sizeLimits)
260 {
261     sizeLimits_ = sizeLimits;
262 }
263 
SetUpdatedSizeLimits(const WindowSizeLimits & sizeLimits)264 void WindowProperty::SetUpdatedSizeLimits(const WindowSizeLimits& sizeLimits)
265 {
266     updatedSizeLimits_ = sizeLimits;
267 }
268 
AddWindowFlag(WindowFlag flag)269 void WindowProperty::AddWindowFlag(WindowFlag flag)
270 {
271     flags_ |= static_cast<uint32_t>(flag);
272 }
273 
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)274 void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
275 {
276     if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
277         sysBarPropMap_[type] = property;
278     }
279 }
280 
SetDecorEnable(bool decorEnable)281 void WindowProperty::SetDecorEnable(bool decorEnable)
282 {
283     isDecorEnable_ = decorEnable;
284 }
285 
SetHitOffset(const PointInfo & offset)286 void WindowProperty::SetHitOffset(const PointInfo& offset)
287 {
288     hitOffset_ = offset;
289 }
290 
SetAnimationFlag(uint32_t animationFlag)291 void WindowProperty::SetAnimationFlag(uint32_t animationFlag)
292 {
293     animationFlag_ = animationFlag;
294 }
295 
SetWindowSizeChangeReason(WindowSizeChangeReason reason)296 void WindowProperty::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
297 {
298     windowSizeChangeReason_ = reason;
299 }
300 
SetDragType(DragType dragType)301 void WindowProperty::SetDragType(DragType dragType)
302 {
303     dragType_ = dragType;
304 }
305 
SetStretchable(bool stretchable)306 void WindowProperty::SetStretchable(bool stretchable)
307 {
308     isStretchable_ = stretchable;
309 }
310 
SetOriginRect(const Rect & rect)311 void WindowProperty::SetOriginRect(const Rect& rect)
312 {
313     originRect_ = rect;
314 }
315 
SetAccessTokenId(uint32_t accessTokenId)316 void WindowProperty::SetAccessTokenId(uint32_t accessTokenId)
317 {
318     accessTokenId_ = accessTokenId;
319 }
320 
GetWindowSizeChangeReason() const321 WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const
322 {
323     return windowSizeChangeReason_;
324 }
325 
ResumeLastWindowMode()326 void WindowProperty::ResumeLastWindowMode()
327 {
328     // if lastMode isn't supported, get supported mode from supportModeInfo
329     if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, lastMode_)) {
330         auto mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo_);
331         if (!WindowHelper::IsSplitWindowMode(mode)) {
332             mode_ = mode;
333         }
334         return;
335     }
336     mode_ = lastMode_;
337 }
338 
GetWindowName() const339 const std::string& WindowProperty::GetWindowName() const
340 {
341     return windowName_ ;
342 }
343 
GetAbilityInfo() const344 const AbilityInfo& WindowProperty::GetAbilityInfo() const
345 {
346     return abilityInfo_ ;
347 }
348 
GetWindowRect() const349 Rect WindowProperty::GetWindowRect() const
350 {
351     return windowRect_;
352 }
353 
GetDecoStatus() const354 bool WindowProperty::GetDecoStatus() const
355 {
356     return decoStatus_;
357 }
358 
GetRequestRect() const359 Rect WindowProperty::GetRequestRect() const
360 {
361     return requestRect_;
362 }
363 
GetWindowType() const364 WindowType WindowProperty::GetWindowType() const
365 {
366     return type_;
367 }
368 
GetWindowMode() const369 WindowMode WindowProperty::GetWindowMode() const
370 {
371     return mode_;
372 }
373 
GetLastWindowMode() const374 WindowMode WindowProperty::GetLastWindowMode() const
375 {
376     return lastMode_;
377 }
378 
GetFullScreen() const379 bool WindowProperty::GetFullScreen() const
380 {
381     return isFullScreen_;
382 }
383 
GetFocusable() const384 bool WindowProperty::GetFocusable() const
385 {
386     return focusable_;
387 }
388 
GetTouchable() const389 bool WindowProperty::GetTouchable() const
390 {
391     return touchable_;
392 }
393 
GetCallingWindow() const394 uint32_t WindowProperty::GetCallingWindow() const
395 {
396     return callingWindow_;
397 }
398 
GetPrivacyMode() const399 bool WindowProperty::GetPrivacyMode() const
400 {
401     return isPrivacyMode_;
402 }
403 
GetSystemPrivacyMode() const404 bool WindowProperty::GetSystemPrivacyMode() const
405 {
406     return isSystemPrivacyMode_;
407 }
408 
GetTransparent() const409 bool WindowProperty::GetTransparent() const
410 {
411     return isTransparent_;
412 }
413 
GetAlpha() const414 float WindowProperty::GetAlpha() const
415 {
416     return alpha_;
417 }
418 
GetTransform() const419 const Transform& WindowProperty::GetTransform() const
420 {
421     return trans_;
422 }
423 
GetBrightness() const424 float WindowProperty::GetBrightness() const
425 {
426     return brightness_;
427 }
428 
IsTurnScreenOn() const429 bool WindowProperty::IsTurnScreenOn() const
430 {
431     return turnScreenOn_;
432 }
433 
IsKeepScreenOn() const434 bool WindowProperty::IsKeepScreenOn() const
435 {
436     return keepScreenOn_;
437 }
438 
GetDisplayId() const439 DisplayId WindowProperty::GetDisplayId() const
440 {
441     return displayId_;
442 }
443 
GetWindowFlags() const444 uint32_t WindowProperty::GetWindowFlags() const
445 {
446     return flags_;
447 }
448 
GetSystemBarProperty() const449 const std::unordered_map<WindowType, SystemBarProperty>& WindowProperty::GetSystemBarProperty() const
450 {
451     return sysBarPropMap_;
452 }
453 
GetDecorEnable() const454 bool WindowProperty::GetDecorEnable() const
455 {
456     return isDecorEnable_;
457 }
458 
SetWindowId(uint32_t windowId)459 void WindowProperty::SetWindowId(uint32_t windowId)
460 {
461     windowId_ = windowId;
462 }
463 
SetParentId(uint32_t parentId)464 void WindowProperty::SetParentId(uint32_t parentId)
465 {
466     parentId_ = parentId;
467 }
468 
SetTokenState(bool hasToken)469 void WindowProperty::SetTokenState(bool hasToken)
470 {
471     tokenState_ = hasToken;
472 }
473 
SetModeSupportInfo(uint32_t modeSupportInfo)474 void WindowProperty::SetModeSupportInfo(uint32_t modeSupportInfo)
475 {
476     modeSupportInfo_ = modeSupportInfo;
477 }
478 
SetRequestModeSupportInfo(uint32_t requestModeSupportInfo)479 void WindowProperty::SetRequestModeSupportInfo(uint32_t requestModeSupportInfo)
480 {
481     requestModeSupportInfo_ = requestModeSupportInfo;
482 }
483 
GetWindowId() const484 uint32_t WindowProperty::GetWindowId() const
485 {
486     return windowId_;
487 }
488 
GetParentId() const489 uint32_t WindowProperty::GetParentId() const
490 {
491     return parentId_;
492 }
493 
GetHitOffset() const494 const PointInfo& WindowProperty::GetHitOffset() const
495 {
496     return hitOffset_;
497 }
498 
GetAnimationFlag() const499 uint32_t WindowProperty::GetAnimationFlag() const
500 {
501     return animationFlag_;
502 }
503 
GetModeSupportInfo() const504 uint32_t WindowProperty::GetModeSupportInfo() const
505 {
506     return modeSupportInfo_;
507 }
508 
GetRequestModeSupportInfo() const509 uint32_t WindowProperty::GetRequestModeSupportInfo() const
510 {
511     return requestModeSupportInfo_;
512 }
513 
GetTokenState() const514 bool WindowProperty::GetTokenState() const
515 {
516     return tokenState_;
517 }
518 
GetDragType() const519 DragType WindowProperty::GetDragType() const
520 {
521     return dragType_;
522 }
523 
GetOriginRect() const524 const Rect& WindowProperty::GetOriginRect() const
525 {
526     return originRect_;
527 }
528 
GetStretchable() const529 bool WindowProperty::GetStretchable() const
530 {
531     return isStretchable_;
532 }
533 
GetSizeLimits() const534 WindowSizeLimits WindowProperty::GetSizeLimits() const
535 {
536     return sizeLimits_;
537 }
538 
GetUpdatedSizeLimits() const539 WindowSizeLimits WindowProperty::GetUpdatedSizeLimits() const
540 {
541     return updatedSizeLimits_;
542 }
543 
GetTransformMat() const544 const TransformHelper::Matrix4& WindowProperty::GetTransformMat() const
545 {
546     return transformMat_;
547 }
548 
GetWorldTransformMat() const549 const TransformHelper::Matrix4& WindowProperty::GetWorldTransformMat() const
550 {
551     return worldTransformMat_;
552 }
553 
SetTouchHotAreas(const std::vector<Rect> & rects)554 void WindowProperty::SetTouchHotAreas(const std::vector<Rect>& rects)
555 {
556     touchHotAreas_ = rects;
557 }
558 
GetTouchHotAreas(std::vector<Rect> & rects) const559 void WindowProperty::GetTouchHotAreas(std::vector<Rect>& rects) const
560 {
561     rects = touchHotAreas_;
562 }
563 
SetAspectRatio(float ratio)564 void WindowProperty::SetAspectRatio(float ratio)
565 {
566     aspectRatio_ = ratio;
567 }
568 
SetMaximizeMode(MaximizeMode maximizeMode)569 void WindowProperty::SetMaximizeMode(MaximizeMode maximizeMode)
570 {
571     maximizeMode_ = maximizeMode;
572 }
573 
SetOnlySkipSnapshot(bool onlySkip)574 void WindowProperty::SetOnlySkipSnapshot(bool onlySkip)
575 {
576     onlySkipSnapshot_ = onlySkip;
577 }
578 
GetAspectRatio() const579 float WindowProperty::GetAspectRatio() const
580 {
581     return aspectRatio_;
582 }
583 
GetMaximizeMode() const584 MaximizeMode WindowProperty::GetMaximizeMode() const
585 {
586     return maximizeMode_;
587 }
GetOnlySkipSnapshot()588 bool WindowProperty::GetOnlySkipSnapshot()
589 {
590     return onlySkipSnapshot_;
591 }
592 
GetAccessTokenId() const593 uint32_t WindowProperty::GetAccessTokenId() const
594 {
595     return accessTokenId_;
596 }
597 
SetWindowGravity(WindowGravity gravity,uint32_t percent)598 void WindowProperty::SetWindowGravity(WindowGravity gravity, uint32_t percent)
599 {
600     windowGravity_ = gravity;
601     windowGravitySizePercent_ = percent;
602 }
603 
GetWindowGravity(WindowGravity & gravity,uint32_t & percent) const604 void WindowProperty::GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const
605 {
606     gravity = windowGravity_;
607     percent = windowGravitySizePercent_;
608 }
609 
MapMarshalling(Parcel & parcel) const610 bool WindowProperty::MapMarshalling(Parcel& parcel) const
611 {
612     auto size = sysBarPropMap_.size();
613     if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
614         return false;
615     }
616     for (auto it : sysBarPropMap_) {
617         // write key(type)
618         if (!parcel.WriteUint32(static_cast<uint32_t>(it.first))) {
619             return false;
620         }
621         // write val(sysBarProps)
622         if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) &&
623             parcel.WriteUint32(it.second.contentColor_))) {
624             return false;
625         }
626     }
627     return true;
628 }
629 
MapUnmarshalling(Parcel & parcel,WindowProperty * property)630 void WindowProperty::MapUnmarshalling(Parcel& parcel, WindowProperty* property)
631 {
632     uint32_t size = parcel.ReadUint32();
633     if (size > SYSTEM_BAR_PROPERTY_MAX_NUM) {
634         return;
635     }
636     for (uint32_t i = 0; i < size; i++) {
637         WindowType type = static_cast<WindowType>(parcel.ReadUint32());
638         SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() };
639         property->SetSystemBarProperty(type, prop);
640     }
641 }
642 
MarshallingTouchHotAreas(Parcel & parcel) const643 bool WindowProperty::MarshallingTouchHotAreas(Parcel& parcel) const
644 {
645     auto size = touchHotAreas_.size();
646     if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
647         return false;
648     }
649     for (const auto& rect : touchHotAreas_) {
650         if (!(parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
651             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_))) {
652             return false;
653         }
654     }
655     return true;
656 }
657 
UnmarshallingTouchHotAreas(Parcel & parcel,WindowProperty * property)658 void WindowProperty::UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property)
659 {
660     uint32_t size = parcel.ReadUint32();
661     if (size > TOUCH_HOT_AREA_MAX_NUM) {
662         return;
663     }
664     for (uint32_t i = 0; i < size; i++) {
665         property->touchHotAreas_.emplace_back(
666             Rect{ parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
667     }
668 }
669 
MarshallingTransform(Parcel & parcel) const670 bool WindowProperty::MarshallingTransform(Parcel& parcel) const
671 {
672     return parcel.WriteFloat(trans_.pivotX_) && parcel.WriteFloat(trans_.pivotY_) &&
673         parcel.WriteFloat(trans_.scaleX_) && parcel.WriteFloat(trans_.scaleY_) &&
674         parcel.WriteFloat(trans_.rotationX_) && parcel.WriteFloat(trans_.rotationY_) &&
675         parcel.WriteFloat(trans_.rotationZ_) && parcel.WriteFloat(trans_.translateX_) &&
676         parcel.WriteFloat(trans_.translateY_) && parcel.WriteFloat(trans_.translateZ_);
677 }
678 
UnmarshallingTransform(Parcel & parcel,WindowProperty * property)679 void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* property)
680 {
681     Transform trans;
682     trans.pivotX_ = parcel.ReadFloat();
683     trans.pivotY_ = parcel.ReadFloat();
684     trans.scaleX_ = parcel.ReadFloat();
685     trans.scaleY_ = parcel.ReadFloat();
686     trans.rotationX_ = parcel.ReadFloat();
687     trans.rotationY_ = parcel.ReadFloat();
688     trans.rotationZ_ = parcel.ReadFloat();
689     trans.translateX_ = parcel.ReadFloat();
690     trans.translateY_ = parcel.ReadFloat();
691     trans.translateZ_ = parcel.ReadFloat();
692     property->SetTransform(trans);
693 }
694 
MarshallingWindowSizeLimits(Parcel & parcel) const695 bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const
696 {
697     if (parcel.WriteUint32(sizeLimits_.maxWidth_) &&
698         parcel.WriteUint32(sizeLimits_.maxHeight_) && parcel.WriteUint32(sizeLimits_.minWidth_) &&
699         parcel.WriteUint32(sizeLimits_.minHeight_) && parcel.WriteFloat(sizeLimits_.maxRatio_) &&
700         parcel.WriteFloat(sizeLimits_.minRatio_)) {
701         return true;
702     }
703     return false;
704 }
705 
UnmarshallingWindowSizeLimits(Parcel & parcel,WindowProperty * property)706 void WindowProperty::UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property)
707 {
708     WindowSizeLimits sizeLimits = { parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(),
709                                     parcel.ReadUint32(), parcel.ReadFloat(), parcel.ReadFloat() };
710     property->SetSizeLimits(sizeLimits);
711 }
712 
Marshalling(Parcel & parcel) const713 bool WindowProperty::Marshalling(Parcel& parcel) const
714 {
715     return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) &&
716         parcel.WriteInt32(windowRect_.posY_) && parcel.WriteUint32(windowRect_.width_) &&
717         parcel.WriteUint32(windowRect_.height_) && parcel.WriteInt32(requestRect_.posX_) &&
718         parcel.WriteInt32(requestRect_.posY_) && parcel.WriteUint32(requestRect_.width_) &&
719         parcel.WriteUint32(requestRect_.height_) && parcel.WriteBool(decoStatus_) &&
720         parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
721         parcel.WriteUint32(static_cast<uint32_t>(mode_)) && parcel.WriteUint32(static_cast<uint32_t>(lastMode_)) &&
722         parcel.WriteUint32(flags_) &&
723         parcel.WriteBool(isFullScreen_) && parcel.WriteBool(focusable_) && parcel.WriteBool(touchable_) &&
724         parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isTransparent_) && parcel.WriteFloat(alpha_) &&
725         parcel.WriteFloat(brightness_) && parcel.WriteUint64(displayId_) && parcel.WriteUint32(windowId_) &&
726         parcel.WriteUint32(parentId_) && MapMarshalling(parcel) && parcel.WriteBool(isDecorEnable_) &&
727         parcel.WriteInt32(hitOffset_.x) && parcel.WriteInt32(hitOffset_.y) && parcel.WriteUint32(animationFlag_) &&
728         parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) &&
729         parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_)) &&
730         parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) &&
731         parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(requestModeSupportInfo_) &&
732         parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
733         parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) &&
734         parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) &&
735         MarshallingTransform(parcel) && MarshallingWindowSizeLimits(parcel) && zoomTrans_.Marshalling(parcel) &&
736         parcel.WriteBool(isDisplayZoomOn_) && parcel.WriteString(abilityInfo_.bundleName_) &&
737         parcel.WriteString(abilityInfo_.abilityName_) && parcel.WriteInt32(abilityInfo_.missionId_) &&
738         parcel.WriteBool(onlySkipSnapshot_);
739 }
740 
Unmarshalling(Parcel & parcel)741 WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel)
742 {
743     WindowProperty* property = new(std::nothrow) WindowProperty();
744     if (property == nullptr) {
745         return nullptr;
746     }
747     property->SetWindowName(parcel.ReadString());
748     Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
749     property->SetWindowRect(rect);
750     Rect reqRect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
751     property->SetRequestRect(reqRect);
752     property->SetDecoStatus(parcel.ReadBool());
753     property->SetWindowType(static_cast<WindowType>(parcel.ReadUint32()));
754     property->SetWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
755     property->SetLastWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
756     property->SetWindowFlags(parcel.ReadUint32());
757     property->SetFullScreen(parcel.ReadBool());
758     property->SetFocusable(parcel.ReadBool());
759     property->SetTouchable(parcel.ReadBool());
760     property->SetPrivacyMode(parcel.ReadBool());
761     property->SetTransparent(parcel.ReadBool());
762     property->SetAlpha(parcel.ReadFloat());
763     property->SetBrightness(parcel.ReadFloat());
764     property->SetDisplayId(parcel.ReadUint64());
765     property->SetWindowId(parcel.ReadUint32());
766     property->SetParentId(parcel.ReadUint32());
767     MapUnmarshalling(parcel, property);
768     property->SetDecorEnable(parcel.ReadBool());
769     PointInfo offset = {parcel.ReadInt32(), parcel.ReadInt32()};
770     property->SetHitOffset(offset);
771     property->SetAnimationFlag(parcel.ReadUint32());
772     property->SetWindowSizeChangeReason(static_cast<WindowSizeChangeReason>(parcel.ReadUint32()));
773     property->SetTokenState(parcel.ReadBool());
774     property->SetCallingWindow(parcel.ReadUint32());
775     property->SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
776     property->SetTurnScreenOn(parcel.ReadBool());
777     property->SetKeepScreenOn(parcel.ReadBool());
778     property->SetModeSupportInfo(parcel.ReadUint32());
779     property->SetRequestModeSupportInfo(parcel.ReadUint32());
780     property->SetDragType(static_cast<DragType>(parcel.ReadUint32()));
781     uint32_t w = parcel.ReadUint32();
782     uint32_t h = parcel.ReadUint32();
783     property->SetOriginRect(Rect { 0, 0, w, h });
784     property->SetStretchable(parcel.ReadBool());
785     UnmarshallingTouchHotAreas(parcel, property);
786     property->SetAccessTokenId(parcel.ReadUint32());
787     UnmarshallingTransform(parcel, property);
788     UnmarshallingWindowSizeLimits(parcel, property);
789     Transform zoomTrans;
790     zoomTrans.Unmarshalling(parcel);
791     property->SetZoomTransform(zoomTrans);
792     property->SetDisplayZoomState(parcel.ReadBool());
793     AbilityInfo info = { parcel.ReadString(), parcel.ReadString(), parcel.ReadInt32() };
794     property->SetAbilityInfo(info);
795     property->SetOnlySkipSnapshot(parcel.ReadBool());
796     return property;
797 }
798 
Write(Parcel & parcel,PropertyChangeAction action)799 bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action)
800 {
801     bool ret = parcel.WriteUint32(static_cast<uint32_t>(windowId_));
802     switch (action) {
803         case PropertyChangeAction::ACTION_UPDATE_RECT:
804             ret = ret && parcel.WriteBool(decoStatus_) && parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
805                 parcel.WriteInt32(originRect_.posX_) && parcel.WriteInt32(originRect_.posY_) &&
806                 parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) &&
807                 parcel.WriteInt32(requestRect_.posX_) && parcel.WriteInt32(requestRect_.posY_) &&
808                 parcel.WriteUint32(requestRect_.width_) && parcel.WriteUint32(requestRect_.height_) &&
809                 parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_));
810             break;
811         case PropertyChangeAction::ACTION_UPDATE_MODE:
812             ret = ret && parcel.WriteUint32(static_cast<uint32_t>(mode_)) && parcel.WriteBool(isDecorEnable_);
813             break;
814         case PropertyChangeAction::ACTION_UPDATE_FLAGS:
815             ret = ret && parcel.WriteUint32(flags_);
816             break;
817         case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS:
818             ret = ret && MapMarshalling(parcel);
819             break;
820         case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE:
821             ret = ret && parcel.WriteBool(focusable_);
822             break;
823         case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE:
824             ret = ret && parcel.WriteBool(touchable_);
825             break;
826         case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW:
827             ret = ret && parcel.WriteUint32(callingWindow_);
828             break;
829         case PropertyChangeAction::ACTION_UPDATE_ORIENTATION:
830             ret = ret && parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_));
831             break;
832         case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON:
833             ret = ret && parcel.WriteBool(turnScreenOn_);
834             break;
835         case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON:
836             ret = ret && parcel.WriteBool(keepScreenOn_);
837             break;
838         case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS:
839             ret = ret && parcel.WriteFloat(brightness_);
840             break;
841         case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO:
842             ret = ret && parcel.WriteUint32(modeSupportInfo_);
843             break;
844         case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
845             ret = ret && MarshallingTouchHotAreas(parcel);
846             break;
847         case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
848             ret = ret && MarshallingTransform(parcel);
849             break;
850         case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG:
851             ret = ret && parcel.WriteUint32(animationFlag_);
852             break;
853         case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE:
854             ret = ret && parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isSystemPrivacyMode_)
855                 && parcel.WriteBool(onlySkipSnapshot_);
856             break;
857         case PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO:
858             ret = ret && parcel.WriteFloat(aspectRatio_);
859             break;
860         case PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE:
861             ret = ret && parcel.WriteUint32(static_cast<uint32_t>(maximizeMode_));
862             break;
863         default:
864             break;
865     }
866     return ret;
867 }
868 
Read(Parcel & parcel,PropertyChangeAction action)869 void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action)
870 {
871     SetWindowId(parcel.ReadUint32());
872     switch (action) {
873         case PropertyChangeAction::ACTION_UPDATE_RECT:
874             SetDecoStatus(parcel.ReadBool());
875             SetDragType(static_cast<DragType>(parcel.ReadUint32()));
876             SetOriginRect(Rect { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
877             SetRequestRect(Rect { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
878             SetWindowSizeChangeReason(static_cast<WindowSizeChangeReason>(parcel.ReadUint32()));
879             break;
880         case PropertyChangeAction::ACTION_UPDATE_MODE:
881             SetWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
882             SetDecorEnable(parcel.ReadBool());
883             break;
884         case PropertyChangeAction::ACTION_UPDATE_FLAGS:
885             SetWindowFlags(parcel.ReadUint32());
886             break;
887         case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS:
888             MapUnmarshalling(parcel, this);
889             break;
890         case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE:
891             SetFocusable(parcel.ReadBool());
892             break;
893         case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE:
894             SetTouchable(parcel.ReadBool());
895             break;
896         case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW:
897             SetCallingWindow(parcel.ReadUint32());
898             break;
899         case PropertyChangeAction::ACTION_UPDATE_ORIENTATION:
900             SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
901             break;
902         case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON:
903             SetTurnScreenOn(parcel.ReadBool());
904             break;
905         case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON:
906             SetKeepScreenOn(parcel.ReadBool());
907             break;
908         case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS:
909             SetBrightness(parcel.ReadFloat());
910             break;
911         case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO:
912             SetModeSupportInfo(parcel.ReadUint32());
913             break;
914         case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
915             UnmarshallingTouchHotAreas(parcel, this);
916             break;
917         case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
918             UnmarshallingTransform(parcel, this);
919             break;
920         case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: {
921             SetAnimationFlag(parcel.ReadUint32());
922             break;
923         }
924         case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE:
925             SetPrivacyMode(parcel.ReadBool());
926             SetSystemPrivacyMode(parcel.ReadBool());
927             SetOnlySkipSnapshot(parcel.ReadBool());
928             break;
929         case PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO:
930             SetAspectRatio(parcel.ReadFloat());
931             break;
932         case PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE:
933             SetMaximizeMode(static_cast<MaximizeMode>(parcel.ReadUint32()));
934             break;
935         default:
936             break;
937     }
938 }
939 
CopyFrom(const sptr<WindowProperty> & property)940 void WindowProperty::CopyFrom(const sptr<WindowProperty>& property)
941 {
942     windowName_ = property->windowName_;
943     windowRect_ = property->windowRect_;
944     requestRect_ = property->requestRect_;
945     decoStatus_ = property->decoStatus_;
946     type_ = property->type_;
947     mode_ = property->mode_;
948     lastMode_ = property->lastMode_;
949     flags_ = property->flags_;
950     isFullScreen_ = property->isFullScreen_;
951     focusable_ = property->focusable_;
952     touchable_ = property->touchable_;
953     isPrivacyMode_ = property->isPrivacyMode_;
954     isTransparent_ = property->isTransparent_;
955     alpha_ = property->alpha_;
956     brightness_ = property->brightness_;
957     displayId_ = property->displayId_;
958     windowId_ = property->windowId_;
959     parentId_ = property->parentId_;
960     hitOffset_ = property->hitOffset_;
961     animationFlag_ = property->animationFlag_;
962     windowSizeChangeReason_ = property->windowSizeChangeReason_;
963     sysBarPropMap_ = property->sysBarPropMap_;
964     isDecorEnable_ = property->isDecorEnable_;
965     tokenState_ = property->tokenState_;
966     callingWindow_ = property->callingWindow_;
967     requestedOrientation_ = property->requestedOrientation_;
968     turnScreenOn_ = property->turnScreenOn_;
969     keepScreenOn_ = property->keepScreenOn_;
970     modeSupportInfo_ = property->modeSupportInfo_;
971     requestModeSupportInfo_ = property->requestModeSupportInfo_;
972     dragType_ = property->dragType_;
973     originRect_ = property->originRect_;
974     isStretchable_ = property->isStretchable_;
975     touchHotAreas_ = property->touchHotAreas_;
976     accessTokenId_ = property->accessTokenId_;
977     trans_ = property->trans_;
978     sizeLimits_ = property->sizeLimits_;
979     zoomTrans_ = property->zoomTrans_;
980     isDisplayZoomOn_ = property->isDisplayZoomOn_;
981     reCalcuZoomTransformMat_ = true;
982     abilityInfo_ = property->abilityInfo_;
983     onlySkipSnapshot_ = property->onlySkipSnapshot_;
984 }
985 }
986 }
987