• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_RS_RENDER_THREAD_VISITOR_H
17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_RENDER_THREAD_VISITOR_H
18 
19 #include <memory>
20 #include <map>
21 #include <set>
22 
23 #include "pipeline/rs_dirty_region_manager.h"
24 #include "pipeline/rs_paint_filter_canvas.h"
25 #include "transaction/rs_transaction_proxy.h"
26 #include "visitor/rs_node_visitor.h"
27 
28 #ifdef USE_ROSEN_DRAWING
29 #include "draw/brush.h"
30 #include "draw/color.h"
31 #include "draw/pen.h"
32 #endif
33 
34 namespace OHOS {
35 namespace Rosen {
36 class RSDirtyRegionManager;
37 class RSProperties;
38 class RSRenderNode;
39 
40 class RSRenderThreadVisitor : public RSNodeVisitor {
41 public:
42     RSRenderThreadVisitor();
43     virtual ~RSRenderThreadVisitor();
44 
45     void PrepareChildren(RSRenderNode& node) override;
46     void PrepareCanvasRenderNode(RSCanvasRenderNode& node) override;
PrepareDisplayRenderNode(RSDisplayRenderNode & node)47     void PrepareDisplayRenderNode(RSDisplayRenderNode& node) override {}
PrepareProxyRenderNode(RSProxyRenderNode & node)48     void PrepareProxyRenderNode(RSProxyRenderNode& node) override {}
49     void PrepareRootRenderNode(RSRootRenderNode& node) override;
50     void PrepareSurfaceRenderNode(RSSurfaceRenderNode& node) override;
51     void PrepareEffectRenderNode(RSEffectRenderNode& node) override;
52 
53     void ProcessChildren(RSRenderNode& node) override;
54     void ProcessCanvasRenderNode(RSCanvasRenderNode& node) override;
ProcessDisplayRenderNode(RSDisplayRenderNode & node)55     void ProcessDisplayRenderNode(RSDisplayRenderNode& node) override {}
56     void ProcessProxyRenderNode(RSProxyRenderNode& node) override;
57     void ProcessRootRenderNode(RSRootRenderNode& node) override;
58     void ProcessSurfaceRenderNode(RSSurfaceRenderNode& node) override;
59     void ProcessEffectRenderNode(RSEffectRenderNode& node) override;
60 
61     void AddSurfaceChangedCallBack(uint64_t id,
62         const std::function<void(float, float, float, float)>& callback) override;
63     void RemoveSurfaceChangedCallBack(uint64_t id) override;
64 
65     // Partial render status and renderForce flag should be updated by rt thread
66     void SetPartialRenderStatus(PartialRenderType status, bool isRenderForced);
67 private:
68 #ifndef USE_ROSEN_DRAWING
69     void DrawRectOnCanvas(const RectI& dirtyRect, const SkColor color, const SkPaint::Style fillType, float alpha,
70         int strokeWidth = 6);
71 #else
72     enum class RSPaintStyle {
73         FILL,
74         STROKE
75     };
76     void DrawRectOnCanvas(const RectI& dirtyRect, const Drawing::ColorQuad color, RSPaintStyle fillType, float alpha,
77         int strokeWidth = 6);
78 #endif // USE_ROSEN_DRAWING
79     void DrawDirtyRegion();
80     // Update damageRegion based on buffer age, and then set it through egl api
81 #ifdef NEW_RENDER_CONTEXT
82     void UpdateDirtyAndSetEGLDamageRegion(std::shared_ptr<RSRenderSurface>& surface);
83 #else
84     void UpdateDirtyAndSetEGLDamageRegion(std::unique_ptr<RSSurfaceFrame>& surfaceFrame);
85 #endif
86     // Reset and update children node's info like outOfParent and isRemoveChild
87     void ResetAndPrepareChildrenNode(RSRenderNode& node, std::shared_ptr<RSBaseRenderNode> nodeParent);
88 
89     bool UpdateAnimatePropertyCacheSurface(RSRenderNode& node);
90 
91     std::shared_ptr<RSDirtyRegionManager> curDirtyManager_;
92     bool isRenderForced_ = false;
93     bool isEglSetDamageRegion_ = false;
94     bool isOpDropped_ = false;
95     DirtyRegionDebugType dfxDirtyType_ = DirtyRegionDebugType::DISABLED;
96     PartialRenderType partialRenderStatus_ = PartialRenderType::DISABLED;
97     RectI curDirtyRegion_ = RectI();
98     bool dirtyFlag_ = false;
99     bool isIdle_ = true;
100     std::shared_ptr<RSPaintFilterCanvas> canvas_ = nullptr;
101     uint32_t queueSize_ = 0;
102     uint64_t uiTimestamp_ = 0;
103 
104     void ClipHoleForSurfaceNode(RSSurfaceRenderNode& node);
105 
106     std::vector<NodeId> childSurfaceNodeIds_;
107 #ifndef USE_ROSEN_DRAWING
108     SkMatrix parentSurfaceNodeMatrix_;
109     std::optional<SkPath> effectRegion_ = std::nullopt;
110 #else
111     Drawing::Matrix parentSurfaceNodeMatrix_;
112     std::optional<Drawing::Path> effectRegion_ = std::nullopt;
113 #endif // USE_ROSEN_DRAWING
114 
115     std::map<NodeId, std::function<void(float, float, float, float)>> surfaceCallbacks_;
116 
117     static void SendCommandFromRT(std::unique_ptr<RSCommand>& command, NodeId nodeId, FollowType followType);
118     static bool IsValidRootRenderNode(RSRootRenderNode& node);
119 };
120 } // namespace Rosen
121 } // namespace OHOS
122 
123 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_RENDER_THREAD_VISITOR_H
124