• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_VISITOR_H
16 #define RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_VISITOR_H
17 
18 #include <set>
19 #include <parameters.h>
20 
21 #include "platform/ohos/overdraw/rs_cpu_overdraw_canvas_listener.h"
22 #include "platform/ohos/overdraw/rs_gpu_overdraw_canvas_listener.h"
23 #include "platform/ohos/overdraw/rs_overdraw_controller.h"
24 #include "pipeline/rs_dirty_region_manager.h"
25 #include "pipeline/rs_processor.h"
26 #include "screen_manager/rs_screen_manager.h"
27 #include "visitor/rs_node_visitor.h"
28 
29 class SkPicture;
30 namespace OHOS {
31 namespace Rosen {
32 class RSPaintFilterCanvas;
33 class RSUniRenderVisitor : public RSNodeVisitor {
34 public:
35     RSUniRenderVisitor();
36     ~RSUniRenderVisitor() override;
37 
38     void PrepareBaseRenderNode(RSBaseRenderNode& node) override;
39     void PrepareCanvasRenderNode(RSCanvasRenderNode& node) override;
40     void PrepareDisplayRenderNode(RSDisplayRenderNode& node) override;
41     void PrepareProxyRenderNode(RSProxyRenderNode& node) override;
42     void PrepareRootRenderNode(RSRootRenderNode& node) override;
43     void PrepareSurfaceRenderNode(RSSurfaceRenderNode& node) override;
44 
45     void ProcessBaseRenderNode(RSBaseRenderNode& node) override;
46     void ProcessCanvasRenderNode(RSCanvasRenderNode& node) override;
47     void ProcessDisplayRenderNode(RSDisplayRenderNode& node) override;
48     void ProcessProxyRenderNode(RSProxyRenderNode& node) override;
49     void ProcessRootRenderNode(RSRootRenderNode& node) override;
50     void ProcessSurfaceRenderNode(RSSurfaceRenderNode& node) override;
51 
SetAnimateState(bool doAnimate)52     void SetAnimateState(bool doAnimate)
53     {
54         doAnimate_ = doAnimate;
55     }
56 
SetDirtyFlag(bool isDirty)57     void SetDirtyFlag(bool isDirty)
58     {
59         isDirty_ = isDirty;
60     }
61 
SetFocusedWindowPid(pid_t pid)62     void SetFocusedWindowPid(pid_t pid)
63     {
64         currentFocusedPid_ = pid;
65     }
66 private:
67     void DrawDirtyRectForDFX(const RectI& dirtyRect, const SkColor color,
68         const SkPaint::Style fillType, float alpha);
69     void DrawDirtyRegionForDFX(std::vector<RectI> dirtyRects);
70     void DrawAllSurfaceDirtyRegionForDFX(RSDisplayRenderNode& node, const Occlusion::Region& region);
71     void DrawTargetSurfaceDirtyRegionForDFX(RSDisplayRenderNode& node);
72     std::vector<RectI> GetDirtyRects(const Occlusion::Region &region);
73     /* calculate display/global (between windows) level dirty region, current include:
74      * 1. window move/add/remove 2. transparent dirty region
75      * when process canvas culling, canvas intersect with surface's visibledirty region or
76      * global dirty region will be skipped
77      */
78     void CalcDirtyDisplayRegion(std::shared_ptr<RSDisplayRenderNode>& node) const;
79     void CalcDirtyRegionForFilterNode(std::shared_ptr<RSDisplayRenderNode>& node) const;
80     // set global dirty region to each surface node
81     void SetSurfaceGlobalDirtyRegion(std::shared_ptr<RSDisplayRenderNode>& node);
82 
83     void InitCacheSurface(RSSurfaceRenderNode& node, int width, int height);
84     void SetPaintOutOfParentFlag(RSBaseRenderNode& node);
85     void CheckColorSpace(RSSurfaceRenderNode& node);
86     void AddOverDrawListener(std::unique_ptr<RSRenderFrame>& renderFrame,
87         std::shared_ptr<RSCanvasListener>& overdrawListener);
88 
89     void RecordAppWindowNodeAndPostTask(RSSurfaceRenderNode& node, float width, float height);
90 
91     // offscreen render related
92     void PrepareOffscreenRender(RSRenderNode& node);
93     void FinishOffscreenRender();
94     sk_sp<SkSurface> offscreenSurface_;                 // temporary holds offscreen surface
95     std::shared_ptr<RSPaintFilterCanvas> canvasBackup_; // backup current canvas before offscreen render
96 
97     ScreenInfo screenInfo_;
98     std::shared_ptr<RSDirtyRegionManager> curSurfaceDirtyManager_;
99     std::shared_ptr<RSSurfaceRenderNode> curSurfaceNode_;
100     float curAlpha_ = 1.f;
101     bool dirtyFlag_ { false };
102     std::shared_ptr<RSPaintFilterCanvas> canvas_;
103     std::map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> dirtySurfaceNodeMap_;
104     SkRect boundsRect_;
105     Gravity frameGravity_ = Gravity::DEFAULT;
106 
107     int32_t offsetX_ { 0 };
108     int32_t offsetY_ { 0 };
109     std::shared_ptr<RSProcessor> processor_;
110     SkMatrix parentSurfaceNodeMatrix_;
111 
112     ScreenId currentVisitDisplay_;
113     std::map<ScreenId, bool> displayHasSecSurface_;
114     std::set<ScreenId> mirroredDisplays_;
115     bool isSecurityDisplay_ = false;
116 
117     std::shared_ptr<RSBaseRenderEngine> renderEngine_;
118 
119     std::shared_ptr<RSDirtyRegionManager> curDisplayDirtyManager_;
120     std::shared_ptr<RSDisplayRenderNode> curDisplayNode_;
121     bool doAnimate_ = false;
122     bool isPartialRenderEnabled_ = false;
123     bool isOpDropped_ = false;
124     bool isDirtyRegionDfxEnabled_ = false; // dirtyRegion DFX visualization
125     bool isTargetDirtyRegionDfxEnabled_ = false;
126     bool isOcclusionEnabled_ = false;
127     std::vector<std::string> dfxTargetSurfaceNames_;
128     PartialRenderType partialRenderType_;
129     bool isDirty_ = false;
130     bool needFilter_ = false;
131     std::unordered_map<NodeId, std::vector<RectI>> filterRects_;
132     ColorGamut newColorSpace_ = ColorGamut::COLOR_GAMUT_SRGB;
133     std::vector<ScreenColorGamut> colorGamutmodes_;
134     ContainerWindowConfigType containerWindowConfig_;
135     pid_t currentFocusedPid_ = -1;
136 
137     bool needColdStartThread_ = false; // flag used for cold start app window
138     bool needDrawStartingWindow_ = true; // flag used for avoiding drawing both app and starting window
139     bool needCheckFirstFrame_ = false; // flag used for avoiding notifying first frame repeatedly
140 };
141 } // namespace Rosen
142 } // namespace OHOS
143 
144 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_VISITOR_H
145