• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "ui/rs_root_node.h"
17 
18 #include "command/rs_root_node_command.h"
19 #include "pipeline/rs_node_map.h"
20 #include "platform/common/rs_log.h"
21 #include "transaction/rs_transaction_proxy.h"
22 #include "ui/rs_surface_node.h"
23 #include "ui/rs_ui_director.h"
24 
25 namespace OHOS {
26 namespace Rosen {
Create(bool isRenderServiceNode)27 std::shared_ptr<RSNode> RSRootNode::Create(bool isRenderServiceNode)
28 {
29     std::shared_ptr<RSRootNode> node(new RSRootNode(isRenderServiceNode));
30     RSNodeMap::MutableInstance().RegisterNode(node);
31 
32     auto transactionProxy = RSTransactionProxy::GetInstance();
33     if (transactionProxy == nullptr) {
34         return node;
35     }
36     std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeCreate>(node->GetId());
37     transactionProxy->AddCommand(command, node->IsRenderServiceNode());
38     if (node->NeedSendExtraCommand()) {
39         std::unique_ptr<RSCommand> extraCommand = std::make_unique<RSRootNodeCreate>(node->GetId());
40         transactionProxy->AddCommand(extraCommand, !node->IsRenderServiceNode());
41     }
42     return node;
43 }
44 
RSRootNode(bool isRenderServiceNode)45 RSRootNode::RSRootNode(bool isRenderServiceNode) : RSCanvasNode(isRenderServiceNode) {}
46 
AttachRSSurfaceNode(std::shared_ptr<RSSurfaceNode> surfaceNode) const47 void RSRootNode::AttachRSSurfaceNode(std::shared_ptr<RSSurfaceNode> surfaceNode) const
48 {
49     auto transactionProxy = RSTransactionProxy::GetInstance();
50     if (transactionProxy == nullptr) {
51         return;
52     }
53     std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeAttachRSSurfaceNode>(GetId(),
54         surfaceNode->GetId());
55     transactionProxy->AddCommand(command, false);
56 
57     if (IsUniRenderEnabled()) {
58         std::unique_ptr<RSCommand> extraCommand = std::make_unique<RSRootNodeAttachToUniSurfaceNode>(GetId(),
59             surfaceNode->GetId());
60         transactionProxy->AddCommand(extraCommand, true);
61     }
62 }
63 
SetEnableRender(bool flag) const64 void RSRootNode::SetEnableRender(bool flag) const
65 {
66     auto transactionProxy = RSTransactionProxy::GetInstance();
67     if (transactionProxy == nullptr) {
68         return;
69     }
70     std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeSetEnableRender>(GetId(), flag);
71     transactionProxy->AddCommand(command, IsRenderServiceNode());
72     if (NeedSendExtraCommand()) {
73         std::unique_ptr<RSCommand> extraCommand = std::make_unique<RSRootNodeSetEnableRender>(GetId(), flag);
74         transactionProxy->AddCommand(extraCommand, !IsRenderServiceNode());
75     }
76     transactionProxy->FlushImplicitTransaction();
77 }
78 
OnBoundsSizeChanged() const79 void RSRootNode::OnBoundsSizeChanged() const
80 {
81     // Planning: we should use frame size instead of bounds size to calculate the surface size.
82     auto bounds = GetStagingProperties().GetBounds();
83     // Set RootNode Surface Size with animation final value. NOTE: this logic is only used in RenderThreadVisitor
84     std::unique_ptr<RSCommand> command =
85         std::make_unique<RSRootNodeUpdateSuggestedBufferSize>(GetId(), bounds.z_, bounds.w_);
86     auto transactionProxy = RSTransactionProxy::GetInstance();
87     if (transactionProxy != nullptr) {
88         transactionProxy->AddCommand(command, false);
89     }
90 }
91 } // namespace Rosen
92 } // namespace OHOS
93