1 /*
2  * Copyright (c) 2021-2022 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 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_CANVAS_RENDER_NODE_H
16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_CANVAS_RENDER_NODE_H
17 
18 #include <memory>
19 #include <unordered_set>
20 
21 #include "memory/rs_memory_track.h"
22 
23 #include "modifier/rs_modifier_type.h"
24 #include "pipeline/rs_render_node.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 class DrawCmdList;
30 }
31 class RSModifierContext;
32 
33 class RSCanvasRenderNode : public RSRenderNode {
34 public:
35     using WeakPtr = std::weak_ptr<RSCanvasRenderNode>;
36     using SharedPtr = std::shared_ptr<RSCanvasRenderNode>;
37     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::CANVAS_NODE;
38 
39     virtual ~RSCanvasRenderNode();
40 
41     void UpdateRecording(std::shared_ptr<Drawing::DrawCmdList> drawCmds,
42         RSModifierType type, bool isSingleFrameComposer = false);
43     void ClearRecording();
44 
45     void ProcessTransitionBeforeChildren(RSPaintFilterCanvas& canvas) override;
46     void ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty) override;
47     void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas) override;
48     void ProcessRenderContents(RSPaintFilterCanvas& canvas) override;
49 
50     void ProcessTransitionAfterChildren(RSPaintFilterCanvas& canvas) override;
51     void ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas) override;
52     void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas) override;
53 
54     void QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
55     void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override;
56     void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override;
57 
58     RSB_EXPORT void ProcessShadowBatching(RSPaintFilterCanvas& canvas);
59 
60     bool OpincGetNodeSupportFlag() override;
61 
GetType()62     RSRenderNodeType GetType() const override
63     {
64         return RSRenderNodeType::CANVAS_NODE;
65     }
66 
67     void OnTreeStateChanged() override;
68 
69     void SetHDRPresent(bool hasHdrPresent);
70     bool GetHDRPresent() const;
71 
72 protected:
73     explicit RSCanvasRenderNode(NodeId id,
74         const std::weak_ptr<RSContext>& context = {}, bool isTextureExportNode = false);
75 
76 private:
77     void ApplyDrawCmdModifier(RSModifierContext& context, RSModifierType type);
78     void InternalDrawContent(RSPaintFilterCanvas& canvas, bool needApplyMatrix);
79 
80     void PropertyDrawableRender(RSPaintFilterCanvas& canvas, bool includeProperty);
81     void DrawShadow(RSModifierContext& context, RSPaintFilterCanvas& canvas);
82 
83     RSPaintFilterCanvas::SaveStatus canvasNodeSaveCount_;
84 
85     friend class RSCanvasNodeCommandHelper;
86     friend class RSColorfulShadowDrawable;
87     friend class RSRenderTransition;
88     friend class RSPropertiesPainter;
89     bool hasHdrPresent_ = false;
90 };
91 } // namespace Rosen
92 } // namespace OHOS
93 
94 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_CANVAS_RENDER_NODE_H
95