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