1 /*
2 * Copyright (c) 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 "command/rs_node_showing_command.h"
17
18 #include "pipeline/rs_render_node.h"
19 #include "platform/common/rs_log.h"
20 #include "transaction/rs_marshalling_helper.h"
21
22 namespace OHOS {
23 namespace Rosen {
24
25 RSCommandRegister<RSNodeGetShowingPropertyAndCancelAnimation::commandType,
26 RSNodeGetShowingPropertyAndCancelAnimation::commandSubType,
27 RSNodeGetShowingPropertyAndCancelAnimation::Unmarshalling>
28 RSNodeGetShowingPropertyAndCancelAnimation::registry;
29
Marshalling(Parcel & parcel) const30 bool RSNodeGetShowingPropertyAndCancelAnimation::Marshalling(Parcel& parcel) const
31 {
32 return RSMarshallingHelper::Marshalling(parcel, commandType) &&
33 RSMarshallingHelper::Marshalling(parcel, commandSubType) &&
34 RSMarshallingHelper::Marshalling(parcel, targetId_) &&
35 RSMarshallingHelper::Marshalling(parcel, timeoutNS_) &&
36 RSMarshallingHelper::Marshalling(parcel, result_) &&
37 (property_ == nullptr || RSRenderPropertyBase::Marshalling(parcel, property_));
38 }
39
Unmarshalling(Parcel & parcel)40 RSCommand* RSNodeGetShowingPropertyAndCancelAnimation::Unmarshalling(Parcel& parcel)
41 {
42 NodeId targetId;
43 std::shared_ptr<RSRenderPropertyBase> property;
44 uint64_t timeoutNS;
45 if (!(RSMarshallingHelper::Unmarshalling(parcel, targetId) &&
46 RSMarshallingHelper::Unmarshalling(parcel, timeoutNS))) {
47 return nullptr;
48 }
49 auto command = new RSNodeGetShowingPropertyAndCancelAnimation(targetId, property, timeoutNS);
50 if (!command->ReadFromParcel(parcel)) {
51 delete command;
52 return nullptr;
53 }
54 return command;
55 }
56
CheckHeader(Parcel & parcel) const57 bool RSNodeGetShowingPropertyAndCancelAnimation::CheckHeader(Parcel& parcel) const
58 {
59 uint16_t type;
60 uint16_t subType;
61 uint64_t timeoutNS;
62 NodeId targetId;
63 return RSMarshallingHelper::Unmarshalling(parcel, type) && type == commandType &&
64 RSMarshallingHelper::Unmarshalling(parcel, subType) && subType == commandSubType &&
65 RSMarshallingHelper::Unmarshalling(parcel, targetId) && targetId == targetId_ &&
66 RSMarshallingHelper::Unmarshalling(parcel, timeoutNS) && timeoutNS == timeoutNS_;
67 }
68
ReadFromParcel(Parcel & parcel)69 bool RSNodeGetShowingPropertyAndCancelAnimation::ReadFromParcel(Parcel& parcel)
70 {
71 return RSMarshallingHelper::Unmarshalling(parcel, result_) &&
72 RSRenderPropertyBase::Unmarshalling(parcel, property_);
73 }
74
Process(RSContext & context)75 void RSNodeGetShowingPropertyAndCancelAnimation::Process(RSContext& context)
76 {
77 auto& nodeMap = context.GetNodeMap();
78 auto node = nodeMap.GetRenderNode<RSRenderNode>(targetId_);
79 if (!node || !property_) {
80 result_ = false;
81 return;
82 }
83 auto modifier = node->GetModifier(property_->GetId());
84 if (!modifier) {
85 result_ = false;
86 return;
87 }
88 property_ = modifier->GetProperty();
89 result_ = (property_ != nullptr);
90 if (result_) {
91 auto& animationManager = node->GetAnimationManager();
92 animationManager.CancelAnimationByPropertyId(property_->GetId());
93 }
94 }
95 } // namespace Rosen
96 } // namespace OHOS
97