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