• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_DRAWABLE_RS_LOGICAL_DISPLAY_RENDER_NODE_DRAWABLE_H
17 #define RENDER_SERVICE_DRAWABLE_RS_LOGICAL_DISPLAY_RENDER_NODE_DRAWABLE_H
18 
19 #include <memory>
20 
21 #include "common/rs_common_def.h"
22 
23 #include "drawable/rs_render_node_drawable.h"
24 #include "drawable/rs_screen_render_node_drawable.h"
25 #include "params/rs_render_thread_params.h"
26 #include "params/rs_logical_display_render_params.h"
27 #include "pipeline/render_thread/rs_uni_render_virtual_processor.h"
28 #include "pipeline/rs_render_node.h"
29 
30 namespace OHOS::Rosen {
31 class RSScreenRenderParams;
32 namespace DrawableV2 {
33 class RSLogicalDisplayRenderNodeDrawable : public RSRenderNodeDrawable {
34 public:
35     ~RSLogicalDisplayRenderNodeDrawable() override;
36 
37     static RSRenderNodeDrawable::Ptr OnGenerate(std::shared_ptr<const RSRenderNode> node);
38 
39     void OnDraw(Drawing::Canvas& canvas) override;
40     void OnCapture(Drawing::Canvas& canvas) override;
41 
42     int32_t GetSpecialLayerType(RSLogicalDisplayRenderParams& params, bool isSecLayerInVisibleRect = true);
SetOriginScreenRotation(const ScreenRotation & rotate)43     void SetOriginScreenRotation(const ScreenRotation& rotate)
44     {
45         originScreenRotation_ = rotate;
46         isFirstTimeToProcessor_ = false;
47     }
48 
GetOriginScreenRotation()49     ScreenRotation GetOriginScreenRotation() const
50     {
51         return originScreenRotation_;
52     }
53 
IsFirstTimeToProcessor()54     bool IsFirstTimeToProcessor() const
55     {
56         return isFirstTimeToProcessor_;
57     }
58 
GetDrawableType()59     RSRenderNodeDrawableType GetDrawableType() const override
60     {
61         return RSRenderNodeDrawableType::LOGICAL_DISPLAY_NODE_DRAWABLE;
62     }
63 
64 protected:
65     explicit RSLogicalDisplayRenderNodeDrawable(std::shared_ptr<const RSRenderNode>&& node);
66 
67 private:
68     void DrawSecurityMask();
69     void ClearCanvasStencil(RSPaintFilterCanvas& canvas, const RSLogicalDisplayRenderParams& params,
70         const RSRenderThreadParams& uniParam, const ScreenInfo& screenInfo);
71     void CheckDirtyRefresh(CompositeType type, bool hasSecLayerInVisibleRect);
72     void ScaleAndRotateMirrorForWiredScreen(RSLogicalDisplayRenderNodeDrawable& mirroredDrawable);
73     void RotateMirrorCanvas(ScreenRotation& rotation, float width, float height);
74     void WiredScreenProjection(RSLogicalDisplayRenderParams& params, std::shared_ptr<RSProcessor> processor);
75     void DrawMirror(RSLogicalDisplayRenderParams& params, std::shared_ptr<RSUniRenderVirtualProcessor> virtualProcesser,
76         RSRenderThreadParams& uniParam);
77     void DrawMirrorCopy(RSLogicalDisplayRenderParams& params,
78         std::shared_ptr<RSUniRenderVirtualProcessor> virtualProcesser, RSRenderThreadParams& uniParam);
79     void DrawWiredMirrorCopy(
80         RSLogicalDisplayRenderNodeDrawable& mirroredDrawable, RSLogicalDisplayRenderParams& params);
81     void DrawWiredMirrorOnDraw(RSLogicalDisplayRenderNodeDrawable& mirroredDrawable,
82         RSLogicalDisplayRenderParams& params, std::shared_ptr<RSProcessor> processor);
83     void DrawMirrorScreen(RSLogicalDisplayRenderParams& params, std::shared_ptr<RSProcessor> processor);
84     void DrawExpandDisplay(RSLogicalDisplayRenderParams& params);
85     void PrepareOffscreenRender(const RSLogicalDisplayRenderNodeDrawable& displayDrawable, bool useFixedSize = false,
86         bool useCanvasSize = true);
87     void FinishOffscreenRender(const Drawing::SamplingOptions& sampling,
88         bool isSamplingOn = false, float hdrBrightnessRatio = 1.0f);
89     void UpdateSlrScale(ScreenInfo& screenInfo, RSScreenRenderParams* params = nullptr);
90     void ScaleCanvasIfNeeded(const ScreenInfo& screenInfo);
91     void ClearTransparentBeforeSaveLayer();
92     std::vector<RectI> CalculateVirtualDirtyForWiredScreen(
93         RSScreenRenderNodeDrawable& curScreenDrawable, Drawing::Matrix canvasMatrix);
94     std::vector<RectI> CalculateVirtualDirty(std::shared_ptr<RSUniRenderVirtualProcessor> virtualProcesser,
95         RSScreenRenderNodeDrawable& curScreenDrawable, RSLogicalDisplayRenderParams& params,
96         Drawing::Matrix canvasMatrix);
97     void UpdateDisplayDirtyManager(std::shared_ptr<RSDirtyRegionManager> dirtyManager,
98         int32_t bufferage, bool useAlignedDirtyRegion = false);
99     std::shared_ptr<Drawing::ShaderEffect> MakeBrightnessAdjustmentShader(const std::shared_ptr<Drawing::Image>& image,
100         const Drawing::SamplingOptions& sampling, float hdrBrightnessRatio);
101 
102     void DrawHardwareEnabledNodes(Drawing::Canvas& canvas, RSLogicalDisplayRenderParams& params);
103     void DrawAdditionalContent(RSPaintFilterCanvas& canvas);
104     void DrawWatermarkIfNeed(RSPaintFilterCanvas& canvas);
105 
106     void MirrorRedrawDFX(bool mirrorRedraw, ScreenId screenId);
107 
108     void SetScreenRotationForPointLight(RSLogicalDisplayRenderParams& params);
109 
110     using AncestorParams = std::pair<std::shared_ptr<RSScreenRenderNodeDrawable>, RSScreenRenderParams*>;
111     AncestorParams GetScreenParams(RSRenderParams& params);
112     using MirrorSourceParams = std::tuple<std::shared_ptr<RSLogicalDisplayRenderNodeDrawable>,
113         RSLogicalDisplayRenderParams*, std::shared_ptr<RSScreenRenderNodeDrawable>, RSScreenRenderParams*>;
114     MirrorSourceParams GetMirrorSourceParams(RSRenderParams& params);
115 
116     ScreenRotation originScreenRotation_ = ScreenRotation::INVALID_SCREEN_ROTATION;
117     bool useFixedOffscreenSurfaceSize_ = true;
118     int32_t offscreenTranslateX_ = 0;
119     int32_t offscreenTranslateY_ = 0;
120     // temporarily holds offscreen surface
121     std::shared_ptr<Drawing::Surface> offscreenSurface_ = nullptr;
122     std::shared_ptr<RSPaintFilterCanvas> offscreenCanvas_ = nullptr;
123     RSPaintFilterCanvas* curCanvas_ = nullptr;
124     // backup current canvas before offscreen render
125     RSPaintFilterCanvas* canvasBackup_ = nullptr;
126     std::unordered_set<NodeId> currentBlackList_ = {};
127     std::unordered_set<NodeType> currentTypeBlackList_ = {};
128     std::unordered_set<NodeId> lastBlackList_ = {};
129     std::unordered_set<NodeType> lastTypeBlackList_ = {};
130 
131     bool curSecExemption_ = false;
132     bool lastSecExemption_ = false;
133     bool virtualDirtyNeedRefresh_ = false;
134     bool enableVisibleRect_ = false;
135     Drawing::RectI curVisibleRect_;
136     Drawing::RectI lastVisibleRect_;
137     std::shared_ptr<RSSLRScaleFunction> scaleManager_ = nullptr;
138     bool isMirrorSLRCopy_ = false;
139     bool isFirstTimeToProcessor_ = true;
140     Drawing::Matrix visibleClipRectMatrix_;
141     Drawing::Matrix lastCanvasMatrix_;
142     Drawing::Matrix lastMirrorMatrix_;
143     static std::shared_ptr<Drawing::RuntimeEffect> brightnessAdjustmentShaderEffect_;
144 
145     using Registrar = RenderNodeDrawableRegistrar<RSRenderNodeType::LOGICAL_DISPLAY_NODE, OnGenerate>;
146     static Registrar instance_;
147 
148     // mirror display drawing path dfx
149     std::optional<bool> mirrorRedraw_;
150 };
151 } // namespace DrawableV2
152 } // namespace OHOS::Rosen
153 #endif // RENDER_SERVICE_DRAWABLE_RS_LOGICAL_DISPLAY_RENDER_NODE_DRAWABLE_H