• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "command/rs_canvas_node_command.h"
17 
18 #include "pipeline/rs_canvas_render_node.h"
19 #include "pipeline/rs_render_node_allocator.h"
20 #include "pipeline/rs_render_node_gc.h"
21 
22 #include "platform/common/rs_log.h"
23 #include "rs_trace.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 
Create(RSContext & context,NodeId id,bool isTextureExportNode)28 void RSCanvasNodeCommandHelper::Create(RSContext& context, NodeId id, bool isTextureExportNode)
29 {
30     auto node = RSRenderNodeAllocator::Instance().CreateRSCanvasRenderNode(id,
31         context.weak_from_this(), isTextureExportNode);
32     if (context.GetMutableNodeMap().UnRegisterUnTreeNode(id)) {
33         RS_LOGE("RSCanvasNodeCommandHelper::Create after add, id:%{public}" PRIu64 " ", id);
34         RS_TRACE_NAME_FMT("RSCanvasNodeCommandHelper::Create after add, id:%" PRIu64 " ", id);
35     }
36     context.GetMutableNodeMap().RegisterRenderNode(node);
37 }
38 
AddCmdToSingleFrameComposer(std::shared_ptr<RSCanvasRenderNode> node,std::shared_ptr<Drawing::DrawCmdList> drawCmds,uint16_t modifierType)39 bool RSCanvasNodeCommandHelper::AddCmdToSingleFrameComposer(
40     std::shared_ptr<RSCanvasRenderNode> node, std::shared_ptr<Drawing::DrawCmdList> drawCmds, uint16_t modifierType)
41 {
42     if (node->GetNodeIsSingleFrameComposer()) {
43         node->UpdateRecordingNG(drawCmds, static_cast<ModifierNG::RSModifierType>(modifierType),
44             RSSingleFrameComposer::IsShouldSingleFrameComposer());
45     } else {
46         if (RSSingleFrameComposer::IsShouldSingleFrameComposer()) {
47             return true;
48         }
49         node->UpdateRecordingNG(drawCmds, static_cast<ModifierNG::RSModifierType>(modifierType));
50     }
51     return false;
52 }
53 
UpdateRecording(RSContext & context,NodeId id,std::shared_ptr<Drawing::DrawCmdList> drawCmds,uint16_t modifierType)54 void RSCanvasNodeCommandHelper::UpdateRecording(
55     RSContext& context, NodeId id, std::shared_ptr<Drawing::DrawCmdList> drawCmds, uint16_t modifierType)
56 {
57     auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(id);
58     if (node == nullptr) {
59         return;
60     }
61     if (RSSystemProperties::GetSingleFrameComposerEnabled()) {
62         if (AddCmdToSingleFrameComposer(node, drawCmds, modifierType)) {
63             return;
64         }
65     } else {
66         node->UpdateRecordingNG(drawCmds, static_cast<ModifierNG::RSModifierType>(modifierType));
67     }
68     if (!drawCmds) {
69         return;
70     }
71     drawCmds->UpdateNodeIdToPicture(id);
72 }
73 
ClearRecording(RSContext & context,NodeId id)74 void RSCanvasNodeCommandHelper::ClearRecording(RSContext& context, NodeId id)
75 {
76     if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(id)) {
77         node->ClearRecording();
78     }
79 }
80 
SetHDRPresent(RSContext & context,NodeId nodeId,bool hdrPresent)81 void RSCanvasNodeCommandHelper::SetHDRPresent(RSContext& context, NodeId nodeId, bool hdrPresent)
82 {
83     if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(nodeId)) {
84         node->SetHDRPresent(hdrPresent);
85     }
86 }
87 
88 // [Attention] Only used in PC window resize scene now
SetLinkedRootNodeId(RSContext & context,NodeId nodeId,NodeId rootNodeId)89 void RSCanvasNodeCommandHelper::SetLinkedRootNodeId(RSContext& context, NodeId nodeId, NodeId rootNodeId)
90 {
91     if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(nodeId)) {
92         node->SetLinkedRootNodeId(rootNodeId);
93     }
94 }
95 
SetColorGamut(RSContext & context,NodeId nodeId,uint32_t colorGamut)96 void RSCanvasNodeCommandHelper::SetColorGamut(RSContext& context, NodeId nodeId, uint32_t colorGamut)
97 {
98     if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(nodeId)) {
99         node->SetColorGamut(colorGamut);
100     }
101 }
102 
103 } // namespace Rosen
104 } // namespace OHOS
105