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 "pipeline/rs_proxy_render_node.h"
17
18 #include "command/rs_surface_node_command.h"
19 #include "pipeline/rs_surface_render_node.h"
20 #include "platform/common/rs_log.h"
21 #include "visitor/rs_node_visitor.h"
22
23 namespace OHOS {
24 namespace Rosen {
RSProxyRenderNode(NodeId id,std::weak_ptr<RSSurfaceRenderNode> target,NodeId targetId,std::weak_ptr<RSContext> context)25 RSProxyRenderNode::RSProxyRenderNode(
26 NodeId id, std::weak_ptr<RSSurfaceRenderNode> target, NodeId targetId, std::weak_ptr<RSContext> context)
27 : RSRenderNode(id, context), target_(target), targetId_(targetId)
28 {}
29
~RSProxyRenderNode()30 RSProxyRenderNode::~RSProxyRenderNode()
31 {
32 ROSEN_LOGD("RSProxyRenderNode::~RSProxyRenderNode, proxy id:%" PRIu64 " target:%" PRIu64, GetId(), targetId_);
33
34 // if target do not exist (in RT) or already destroyed (in RS), skip reset
35 auto target = target_.lock();
36 if (target == nullptr) {
37 return;
38 }
39
40 // reset target node context properties
41 target->SetContextAlpha(1, false);
42 target->SetContextMatrix(SkMatrix::I(), false);
43
44 // remove all modifiers and animations added via proxy node
45 const auto pid_of_this_node = ExtractPid(GetId());
46 target->FilterModifiersByPid(pid_of_this_node);
47 target->GetAnimationManager().FilterAnimationByPid(pid_of_this_node);
48 }
49
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)50 void RSProxyRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
51 {
52 if (!visitor) {
53 return;
54 }
55 visitor->PrepareProxyRenderNode(*this);
56 }
57
Process(const std::shared_ptr<RSNodeVisitor> & visitor)58 void RSProxyRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
59 {
60 if (!visitor) {
61 return;
62 }
63 RSRenderNode::RenderTraceDebug();
64 visitor->ProcessProxyRenderNode(*this);
65 }
66
SetContextMatrix(const SkMatrix & matrix)67 void RSProxyRenderNode::SetContextMatrix(const SkMatrix& matrix)
68 {
69 if (contextMatrix_ == matrix) {
70 return;
71 }
72 contextMatrix_ = matrix;
73 if (auto target = target_.lock()) {
74 target->SetContextMatrix(matrix, false);
75 return;
76 }
77 // send a Command
78 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextMatrix>(targetId_, matrix);
79 SendCommandFromRT(command, GetId());
80 }
81
SetContextAlpha(float alpha)82 void RSProxyRenderNode::SetContextAlpha(float alpha)
83 {
84 if (contextAlpha_ == alpha) {
85 return;
86 }
87 contextAlpha_ = alpha;
88 if (auto target = target_.lock()) {
89 target->SetContextAlpha(alpha, false);
90 return;
91 }
92 // send a Command
93 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextAlpha>(targetId_, alpha);
94 SendCommandFromRT(command, GetId());
95 }
96
SetContextClipRegion(SkRect clipRegion)97 void RSProxyRenderNode::SetContextClipRegion(SkRect clipRegion)
98 {
99 if (contextClipRect_ == clipRegion) {
100 return;
101 }
102 contextClipRect_ = clipRegion;
103 if (auto target = target_.lock()) {
104 target->SetContextClipRegion(clipRegion, false);
105 return;
106 }
107 // send a Command
108 std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextClipRegion>(targetId_, clipRegion);
109 SendCommandFromRT(command, GetId());
110 }
111
ResetContextVariableCache()112 void RSProxyRenderNode::ResetContextVariableCache()
113 {
114 // reset context variable cache, make sure next visit will flush correct context variables.
115 contextAlpha_ = -1.0f;
116 contextMatrix_ = SkMatrix::InvalidMatrix();
117 }
118 } // namespace Rosen
119 } // namespace OHOS
120