• 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     node->SetUIContextToken();
48     return node;
49 }
50 
SetFreeze(bool isFreeze)51 void RSEffectNode::SetFreeze(bool isFreeze)
52 {
53     if (!IsUniRenderEnabled()) {
54         ROSEN_LOGE("SetFreeze is not supported in separate render");
55         return;
56     }
57     // The variable preFreeze_ is only used to print the freeze status.
58     if (preFreeze_ != isFreeze) {
59         ROSEN_LOGI("RSEffectNode[%{public}lld]::SetFreeze: %{public}d", static_cast<long long>(GetId()), isFreeze);
60     }
61     preFreeze_ = isFreeze;
62     std::unique_ptr<RSCommand> command = std::make_unique<RSSetFreeze>(GetId(), isFreeze);
63     auto transaction = GetRSTransaction();
64     AddCommand(command, true);
65 }
66 
RegisterNodeMap()67 void RSEffectNode::RegisterNodeMap()
68 {
69     auto rsContext = GetRSUIContext();
70     if (rsContext == nullptr) {
71         return;
72     }
73     auto& nodeMap = rsContext->GetMutableNodeMap();
74     nodeMap.RegisterNode(shared_from_this());
75 }
76 
RSEffectNode(bool isRenderServiceNode,bool isTextureExportNode,std::shared_ptr<RSUIContext> rsUIContext)77 RSEffectNode::RSEffectNode(bool isRenderServiceNode, bool isTextureExportNode, std::shared_ptr<RSUIContext> rsUIContext)
78     : RSNode(isRenderServiceNode, isTextureExportNode, rsUIContext) {}
79 } // namespace Rosen
80 } // namespace OHOS
81