• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ui/rs_effect_node.h"
17 
18 #include "command/rs_effect_node_command.h"
19 #include "command/rs_node_command.h"
20 #include "platform/common/rs_log.h"
21 #include "pipeline/rs_node_map.h"
22 #include "transaction/rs_transaction_proxy.h"
23 
24 #include "ui/rs_ui_context.h"
25 namespace OHOS {
26 namespace Rosen {
Create(bool isRenderServiceNode,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext)27 RSEffectNode::SharedPtr RSEffectNode::Create(
28     bool isRenderServiceNode, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext)
29 {
30     SharedPtr node(new RSEffectNode(isRenderServiceNode, isTextureExportNode, rsUIContext));
31     if (rsUIContext != nullptr) {
32         rsUIContext->GetMutableNodeMap().RegisterNode(node);
33     } else {
34         RSNodeMap::MutableInstance().RegisterNode(node);
35     }
36     std::unique_ptr<RSCommand> command = std::make_unique<RSEffectNodeCreate>(node->GetId(), isTextureExportNode);
37     auto transaction = node->GetRSTransaction();
38     if (transaction == nullptr) {
39         auto transactionProxy = RSTransactionProxy::GetInstance();
40         if (transactionProxy == nullptr) {
41             return node;
42         }
43         transactionProxy->AddCommand(command, node->IsRenderServiceNode());
44         return node;
45     }
46     transaction->AddCommand(command, node->IsRenderServiceNode());
47     return node;
48 }
49 
SetFreeze(bool isFreeze)50 void RSEffectNode::SetFreeze(bool isFreeze)
51 {
52     if (!IsUniRenderEnabled()) {
53         ROSEN_LOGE("SetFreeze is not supported in separate render");
54         return;
55     }
56     std::unique_ptr<RSCommand> command = std::make_unique<RSSetFreeze>(GetId(), isFreeze);
57     auto transaction = GetRSTransaction();
58     AddCommand(command, true);
59 }
60 
RegisterNodeMap()61 void RSEffectNode::RegisterNodeMap()
62 {
63     auto rsContext = GetRSUIContext();
64     if (rsContext == nullptr) {
65         return;
66     }
67     auto& nodeMap = rsContext->GetMutableNodeMap();
68     nodeMap.RegisterNode(shared_from_this());
69 }
70 
RSEffectNode(bool isRenderServiceNode,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext)71 RSEffectNode::RSEffectNode(bool isRenderServiceNode, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext)
72     : RSNode(isRenderServiceNode, isTextureExportNode, rsUIContext) {}
73 } // namespace Rosen
74 } // namespace OHOS
75