• 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_interfaces.h"
22 #include "transaction/rs_transaction_proxy.h"
23 #include "ui/rs_surface_node.h"
24 #include "ui/rs_ui_director.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
RegisterTypefaceCallback()29 bool RegisterTypefaceCallback()
30 {
31     static std::once_flag flag;
32     std::call_once(flag, []() {
33         std::function<bool (std::shared_ptr<Drawing::Typeface>)> registerTypefaceFunc =
34             [] (std::shared_ptr<Drawing::Typeface> typeface) -> bool {
35                 static Rosen::RSInterfaces& interface = Rosen::RSInterfaces::GetInstance();
36                 return interface.RegisterTypeface(typeface);
37             };
38         Drawing::Typeface::RegisterCallBackFunc(registerTypefaceFunc);
39 
40         std::function<bool (std::shared_ptr<Drawing::Typeface>)> unregisterTypefaceFunc =
41             [] (std::shared_ptr<Drawing::Typeface> typeface) -> bool {
42                 static Rosen::RSInterfaces& interface = Rosen::RSInterfaces::GetInstance();
43                 return interface.UnRegisterTypeface(typeface);
44             };
45         Drawing::Typeface::UnRegisterCallBackFunc(unregisterTypefaceFunc);
46     });
47     return true;
48 }
49 
50 bool g_typefaceAutoRegister = RegisterTypefaceCallback();
51 }
52 
Create(bool isRenderServiceNode,bool isTextureExportNode)53 std::shared_ptr<RSNode> RSRootNode::Create(bool isRenderServiceNode, bool isTextureExportNode)
54 {
55     RegisterTypefaceCallback();
56 
57     std::shared_ptr<RSRootNode> node(new RSRootNode(isRenderServiceNode, isTextureExportNode));
58     RSNodeMap::MutableInstance().RegisterNode(node);
59 
60     auto transactionProxy = RSTransactionProxy::GetInstance();
61     if (transactionProxy == nullptr) {
62         return node;
63     }
64     std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeCreate>(node->GetId(), isTextureExportNode);
65     transactionProxy->AddCommand(command, node->IsRenderServiceNode());
66     return node;
67 }
68 
RSRootNode(bool isRenderServiceNode,bool isSamelayerRender)69 RSRootNode::RSRootNode(bool isRenderServiceNode, bool isSamelayerRender)
70     : RSCanvasNode(isRenderServiceNode, isSamelayerRender) {}
71 
AttachRSSurfaceNode(std::shared_ptr<RSSurfaceNode> surfaceNode) const72 void RSRootNode::AttachRSSurfaceNode(std::shared_ptr<RSSurfaceNode> surfaceNode) const
73 {
74     auto transactionProxy = RSTransactionProxy::GetInstance();
75     if (transactionProxy == nullptr) {
76         return;
77     }
78     if (!IsUniRenderEnabled() || isTextureExportNode_) {
79         std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeAttachRSSurfaceNode>(GetId(),
80             surfaceNode->GetId());
81         transactionProxy->AddCommand(command, false);
82     } else {
83         std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeAttachToUniSurfaceNode>(GetId(),
84             surfaceNode->GetId());
85         transactionProxy->AddCommand(command, true);
86     }
87 }
88 
SetEnableRender(bool flag) const89 void RSRootNode::SetEnableRender(bool flag) const
90 {
91     auto transactionProxy = RSTransactionProxy::GetInstance();
92     if (transactionProxy == nullptr) {
93         return;
94     }
95     std::unique_ptr<RSCommand> command = std::make_unique<RSRootNodeSetEnableRender>(GetId(), flag);
96     transactionProxy->AddCommand(command, IsRenderServiceNode());
97     if (!isTextureExportNode_) {
98         transactionProxy->FlushImplicitTransaction();
99     }
100 }
101 
OnBoundsSizeChanged() const102 void RSRootNode::OnBoundsSizeChanged() const
103 {
104     if (IsUniRenderEnabled() && !isTextureExportNode_) {
105         return;
106     }
107     // Planning: we should use frame size instead of bounds size to calculate the surface size.
108     auto bounds = GetStagingProperties().GetBounds();
109     // Set RootNode Surface Size with animation final value. NOTE: this logic is only used in RenderThreadVisitor
110     std::unique_ptr<RSCommand> command =
111         std::make_unique<RSRootNodeUpdateSuggestedBufferSize>(GetId(), bounds.z_, bounds.w_);
112     auto transactionProxy = RSTransactionProxy::GetInstance();
113     if (transactionProxy != nullptr) {
114         transactionProxy->AddCommand(command, false);
115     }
116 }
117 } // namespace Rosen
118 } // namespace OHOS
119