• 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 RENDER_SERVICE_CORE_RS_DRIVEN_RENDER_MANAGER_H
17 #define RENDER_SERVICE_CORE_RS_DRIVEN_RENDER_MANAGER_H
18 
19 #include "pipeline/rs_processor.h"
20 #include "rs_driven_surface_render_node.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 enum class DrivenUniRenderMode : uint32_t {
25     RENDER_WITH_CLIP_HOLE,
26     REUSE_WITH_CLIP_HOLE,
27     RENDER_WITH_NORMAL,
28 };
29 
30 enum class DrivenUniTreePrepareMode : uint32_t {
31     PREPARE_DRIVEN_NODE_BEFORE,
32     PREPARE_DRIVEN_NODE,
33     PREPARE_DRIVEN_NODE_AFTER,
34 };
35 
36 enum class DrivenDirtyType : uint32_t {
37     INVALID,
38     MARK_DRIVEN_RENDER,
39     MARK_DRIVEN,
40 };
41 
42 struct DrivenDirtyInfo {
43     bool backgroundDirty = false;
44     bool contentDirty = false;
45     bool nonContentDirty = false;
46     DrivenDirtyType type = DrivenDirtyType::INVALID;
47 };
48 
49 struct DrivenPrepareInfo {
50     DrivenDirtyInfo dirtyInfo;
51     RSBaseRenderNode::SharedPtr backgroundNode;
52     RSBaseRenderNode::SharedPtr contentNode;
53     RectI screenRect;
54     bool hasInvalidScene = false;
55     bool hasDrivenNodeOnUniTree = false;
56 };
57 
58 struct DrivenProcessInfo {
59     std::shared_ptr<RSProcessor> uniProcessor = nullptr;
60     GraphicColorGamut uniColorSpace = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
61     float uniGlobalZOrder = 0.0f;
62 };
63 
64 struct DrivenInfo {
65     DrivenPrepareInfo prepareInfo;
66     DrivenProcessInfo processInfo;
67 
68     // used in RSUniRenderVisitor
69     bool hasDrivenNodeMarkRender = false;
70     bool isPrepareLeashWinSubTree = false;
71     std::shared_ptr<RSDirtyRegionManager> surfaceDirtyManager = nullptr;
72     RSBaseRenderNode::SharedPtr currentRootNode = nullptr;
73     DrivenUniTreePrepareMode drivenUniTreePrepareMode = DrivenUniTreePrepareMode::PREPARE_DRIVEN_NODE_BEFORE;
74     DrivenUniRenderMode currDrivenRenderMode = DrivenUniRenderMode::RENDER_WITH_NORMAL;
75 };
76 
77 class RSDrivenRenderManager {
78 public:
79     static RSDrivenRenderManager& GetInstance();
80     static void InitInstance();
81 
82     bool GetDrivenRenderEnabled() const;
83     const DrivenUniRenderMode& GetUniDrivenRenderMode() const;
84     float GetUniRenderGlobalZOrder() const;
85 
86     bool ClipHoleForDrivenNode(RSPaintFilterCanvas& canvas, const RSCanvasRenderNode& node) const;
87     RectI GetUniRenderSurfaceClipHoleRect() const;
88 
GetContentSurfaceNode()89     RSDrivenSurfaceRenderNode::SharedPtr GetContentSurfaceNode() const
90     {
91         return contentSurfaceNode_;
92     }
GetBackgroundSurfaceNode()93     RSDrivenSurfaceRenderNode::SharedPtr GetBackgroundSurfaceNode() const
94     {
95         return backgroundSurfaceNode_;
96     }
97 
98     void DoPrepareRenderTask(const DrivenPrepareInfo& info);
99     void DoProcessRenderTask(const DrivenProcessInfo& info);
100 
101     RSDrivenRenderManager() = default;
102     virtual ~RSDrivenRenderManager() = default;
103 
104 private:
105     void Reset();
106     void UpdateUniDrivenRenderMode(DrivenDirtyType dirtyType);
107     RectI CalcUniRenderSurfaceClipHoleRect();
108 
109     bool drivenRenderEnabled_ = false;
110 
111     std::shared_ptr<RSDrivenSurfaceRenderNode> contentSurfaceNode_ =
112         std::make_shared<RSDrivenSurfaceRenderNode>(0, DrivenSurfaceType::CONTENT);
113     std::shared_ptr<RSDrivenSurfaceRenderNode> backgroundSurfaceNode_ =
114         std::make_shared<RSDrivenSurfaceRenderNode>(0, DrivenSurfaceType::BACKGROUND);
115 
116     DrivenUniRenderMode uniRenderMode_ = DrivenUniRenderMode::RENDER_WITH_NORMAL;
117     float uniRenderGlobalZOrder_ = 0.0;
118     RectI uniRenderSurfaceClipHoleRect_;
119 
120     NodeId contentCanvasNodeId_ = 0;
121     NodeId backgroundCanvasNodeId_ = 0;
122 
123     bool isBufferCacheClear_ = false;
124 };
125 } // namespace Rosen
126 } // namespace OHOS
127 #endif // RENDER_SERVICE_CORE_RS_DRIVEN_RENDER_MANAGER_H
128