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_gc.h"
20
21 namespace OHOS {
22 namespace Rosen {
23
Create(RSContext & context,NodeId id,bool isTextureExportNode)24 void RSCanvasNodeCommandHelper::Create(RSContext& context, NodeId id, bool isTextureExportNode)
25 {
26 auto node = std::shared_ptr<RSCanvasRenderNode>(new RSCanvasRenderNode(id,
27 context.weak_from_this(), isTextureExportNode), RSRenderNodeGC::NodeDestructor);
28 context.GetMutableNodeMap().RegisterRenderNode(node);
29 }
30
AddCmdToSingleFrameComposer(std::shared_ptr<RSCanvasRenderNode> node,std::shared_ptr<Drawing::DrawCmdList> drawCmds,RSModifierType type)31 bool RSCanvasNodeCommandHelper::AddCmdToSingleFrameComposer(std::shared_ptr<RSCanvasRenderNode> node,
32 std::shared_ptr<Drawing::DrawCmdList> drawCmds, RSModifierType type)
33 {
34 if (node->GetNodeIsSingleFrameComposer()) {
35 if (RSSingleFrameComposer::IsShouldSingleFrameComposer()) {
36 node->UpdateRecording(drawCmds, type, true);
37 } else {
38 node->UpdateRecording(drawCmds, type);
39 }
40 } else {
41 if (RSSingleFrameComposer::IsShouldSingleFrameComposer()) {
42 return true;
43 } else {
44 node->UpdateRecording(drawCmds, type);
45 }
46 }
47 return false;
48 }
49
UpdateRecording(RSContext & context,NodeId id,std::shared_ptr<Drawing::DrawCmdList> drawCmds,uint16_t modifierType)50 void RSCanvasNodeCommandHelper::UpdateRecording(
51 RSContext& context, NodeId id, std::shared_ptr<Drawing::DrawCmdList> drawCmds, uint16_t modifierType)
52 {
53 auto type = static_cast<RSModifierType>(modifierType);
54 if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(id)) {
55 if (RSSystemProperties::GetSingleFrameComposerEnabled()) {
56 if (AddCmdToSingleFrameComposer(node, drawCmds, type)) {
57 return;
58 }
59 } else {
60 node->UpdateRecording(drawCmds, type);
61 }
62 if (!drawCmds) {
63 return;
64 }
65 drawCmds->UpdateNodeIdToPicture(id);
66 }
67 }
68
ClearRecording(RSContext & context,NodeId id)69 void RSCanvasNodeCommandHelper::ClearRecording(RSContext& context, NodeId id)
70 {
71 if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(id)) {
72 node->ClearRecording();
73 }
74 }
75
SetHDRPresent(RSContext & context,NodeId nodeId,bool hdrPresent)76 void RSCanvasNodeCommandHelper::SetHDRPresent(RSContext& context, NodeId nodeId, bool hdrPresent)
77 {
78 if (auto node = context.GetNodeMap().GetRenderNode<RSCanvasRenderNode>(nodeId)) {
79 node->SetHDRPresent(hdrPresent);
80 }
81 }
82
83 } // namespace Rosen
84 } // namespace OHOS
85