• 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 #ifndef ROSEN_RENDER_SERVICE_BASE_PIPELINE_RS_CANVAS_DRAWING_RENDER_NODE_H
17 #define ROSEN_RENDER_SERVICE_BASE_PIPELINE_RS_CANVAS_DRAWING_RENDER_NODE_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <memory>
22 
23 #include "pipeline/rs_canvas_render_node.h"
24 #include "pipeline/rs_recording_canvas.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 
29 using ThreadInfo = std::pair<uint32_t, std::function<void(std::shared_ptr<Drawing::Surface>)>>;
30 class RSRecordingCanvas;
31 
32 class RSB_EXPORT RSCanvasDrawingRenderNode : public RSCanvasRenderNode {
33 public:
34     using WeakPtr = std::weak_ptr<RSCanvasDrawingRenderNode>;
35     using SharedPtr = std::shared_ptr<RSCanvasDrawingRenderNode>;
36     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::CANVAS_DRAWING_NODE;
37 
38     virtual ~RSCanvasDrawingRenderNode();
39 
40     // Used in uni render thread.
41     void InitRenderContent();
42 
43     void ProcessRenderContents(RSPaintFilterCanvas& canvas) override;
44 
GetType()45     RSRenderNodeType GetType() const override
46     {
47         return Type;
48     }
49 
OpincGetNodeSupportFlag()50     bool OpincGetNodeSupportFlag() override
51     {
52         return false;
53     }
54 
55     Drawing::Bitmap GetBitmap();
56     Drawing::Bitmap GetBitmap(const uint64_t tid);
57     std::shared_ptr<Drawing::Image> GetImage(const uint64_t tid);
58     bool GetPixelmap(const std::shared_ptr<Media::PixelMap> pixelmap, const Drawing::Rect* rect,
59         const uint64_t tid = UINT32_MAX, std::shared_ptr<Drawing::DrawCmdList> drawCmdList = nullptr);
60 
61     void SetSurfaceClearFunc(ThreadInfo threadInfo, pid_t threadId = 0)
62     {
63         curThreadInfo_ = threadInfo;
64         threadId_ = threadId;
65     }
66 
67     uint32_t GetTid() const;
68 
69     void AddDirtyType(RSModifierType modifierType) override;
70     void ClearOp();
71     void ResetSurface(int width, int height);
72     bool IsNeedProcess() const;
73     void ContentStyleSlotUpdate();
74     void SetNeedProcess(bool needProcess);
75     void PlaybackInCorrespondThread();
76     const std::map<RSModifierType, std::list<Drawing::DrawCmdListPtr>>& GetDrawCmdLists() const;
77     void ClearResource() override;
78     void ClearNeverOnTree() override;
79     void CheckCanvasDrawingPostPlaybacked();
80     bool GetIsPostPlaybacked();
81 private:
82     explicit RSCanvasDrawingRenderNode(
83         NodeId id, const std::weak_ptr<RSContext>& context = {}, bool isTextureExportNode = false);
84     void ApplyDrawCmdModifier(RSModifierContext& context, RSModifierType type);
85     void CheckDrawCmdListSize(RSModifierType type, size_t originCmdListSize);
86     bool ResetSurface(int width, int height, RSPaintFilterCanvas& canvas);
87     bool GetSizeFromDrawCmdModifiers(int& width, int& height);
88     bool IsNeedResetSurface() const;
89     void InitRenderParams() override;
90 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
91     bool ResetSurfaceWithTexture(int width, int height, RSPaintFilterCanvas& canvas);
92 #endif
93 
94 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
95     bool isGpuSurface_ = true;
96 #endif
97     bool isNeverOnTree_ = true;
98     bool isPostPlaybacked_ = false;
99     bool lastOverflowStatus_ = false;
100     std::atomic<bool> isNeedProcess_ = false;
101     pid_t threadId_ = 0;
102     // Used in uni render thread.
103     uint32_t drawingNodeRenderID = UNI_MAIN_THREAD_INDEX;
104     std::shared_ptr<Drawing::Surface> surface_;
105     std::shared_ptr<Drawing::Image> image_;
106     std::shared_ptr<ExtendRecordingCanvas> recordingCanvas_;
107     std::unique_ptr<RSPaintFilterCanvas> canvas_;
108     std::mutex imageMutex_;
109     ThreadInfo curThreadInfo_ = { UNI_MAIN_THREAD_INDEX, std::function<void(std::shared_ptr<Drawing::Surface>)>() };
110     ThreadInfo preThreadInfo_ = { UNI_MAIN_THREAD_INDEX, std::function<void(std::shared_ptr<Drawing::Surface>)>() };
111     std::mutex taskMutex_;
112     std::mutex drawCmdListsMutex_;
113     std::map<RSModifierType, std::list<Drawing::DrawCmdListPtr>> drawCmdLists_;
114     uint32_t cmdCount_ = 0;
115 
116 
117     friend class RSCanvasDrawingNodeCommandHelper;
118 };
119 
120 } // namespace Rosen
121 } // namespace OHOS
122 
123 #endif // ROSEN_RENDER_SERVICE_BASE_PIPELINE_RS_CANVAS_DRAWING_RENDER_NODE_H