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 #include "rs_window_animation_target.h"
17
18 #include "rs_window_animation_log.h"
19
20 #include "ui/rs_surface_node.h"
21
22 namespace OHOS {
23 namespace Rosen {
Unmarshalling(Parcel & parcel)24 RSWindowAnimationTarget* RSWindowAnimationTarget::Unmarshalling(Parcel& parcel)
25 {
26 auto windowAnimationTarget = new (std::nothrow) RSWindowAnimationTarget();
27 if (windowAnimationTarget != nullptr && !windowAnimationTarget->ReadFromParcel(parcel)) {
28 WALOGE("Failed to unmarshalling window animation target!");
29 delete windowAnimationTarget;
30 windowAnimationTarget = nullptr;
31 }
32
33 return windowAnimationTarget;
34 }
35
Marshalling(Parcel & parcel) const36 bool RSWindowAnimationTarget::Marshalling(Parcel& parcel) const
37 {
38 if (!(parcel.WriteString(bundleName_) &&
39 parcel.WriteString(abilityName_) &&
40 parcel.WriteFloat(windowBounds_.rect_.left_) &&
41 parcel.WriteFloat(windowBounds_.rect_.top_) &&
42 parcel.WriteFloat(windowBounds_.rect_.width_) &&
43 parcel.WriteFloat(windowBounds_.rect_.height_) &&
44 parcel.WriteFloat(windowBounds_.radius_[0].x_))) {
45 WALOGE("RSWindowAnimationTarget::Marshalling, write param failed");
46 return false;
47 }
48
49 // marshalling as RSSurfaceNode
50 if (!surfaceNode_) {
51 if (!parcel.WriteBool(false)) {
52 WALOGE("RSWindowAnimationTarget::Marshalling, write param failed");
53 return false;
54 }
55 } else if (auto surfaceNode = surfaceNode_->ReinterpretCastTo<RSSurfaceNode>()) {
56 if (!(parcel.WriteBool(true) && surfaceNode->Marshalling(parcel))) {
57 WALOGE("RSWindowAnimationTarget::Marshalling, write param failed");
58 return false;
59 }
60 } else {
61 return false;
62 }
63
64 if (!(parcel.WriteUint32(windowId_) &&
65 parcel.WriteUint64(displayId_) &&
66 parcel.WriteInt32(missionId_))) {
67 WALOGE("RSWindowAnimationTarget::Marshalling, write param failed");
68 return false;
69 }
70 return true;
71 }
72
ReadFromParcel(Parcel & parcel)73 bool RSWindowAnimationTarget::ReadFromParcel(Parcel& parcel)
74 {
75 if (!(parcel.ReadString(bundleName_) &&
76 parcel.ReadString(abilityName_) &&
77 parcel.ReadFloat(windowBounds_.rect_.left_) &&
78 parcel.ReadFloat(windowBounds_.rect_.top_) &&
79 parcel.ReadFloat(windowBounds_.rect_.width_) &&
80 parcel.ReadFloat(windowBounds_.rect_.height_) &&
81 parcel.ReadFloat(windowBounds_.radius_[0].x_))) {
82 WALOGE("RSWindowAnimationTarget::ReadFromParcel, read param failed");
83 return false;
84 }
85 bool isRSProxyNode;
86 if (!parcel.ReadBool(isRSProxyNode)) {
87 WALOGE("RSWindowAnimationTarget::ReadFromParcel, read param failed");
88 return false;
89 }
90 // unmarshalling as RSProxyNode
91 if (isRSProxyNode) {
92 surfaceNode_ = RSSurfaceNode::UnmarshallingAsProxyNode(parcel);
93 }
94 if (!(parcel.ReadUint32(windowId_) &&
95 parcel.ReadUint64(displayId_) &&
96 parcel.ReadInt32(missionId_))) {
97 WALOGE("RSWindowAnimationTarget::ReadFromParcel, read param failed");
98 return false;
99 }
100 return true;
101 }
102 } // namespace Rosen
103 } // namespace OHOS
104