• 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 RS_CORE_PIPELINE_UNI_RENDER_MIRROR_PROCESSOR_H
17 #define RS_CORE_PIPELINE_UNI_RENDER_MIRROR_PROCESSOR_H
18 
19 #include "rs_uni_render_processor.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 constexpr uint32_t ROI_REGIONS_MAX_CNT = 8;
24 struct RoiRegionInfo {
25     uint32_t startX = 0;
26     uint32_t startY = 0;
27     uint32_t width = 0;
28     uint32_t height = 0;
29 };
30 
31 struct RoiRegions {
32     uint32_t regionCnt = 0;
33     RoiRegionInfo regions[ROI_REGIONS_MAX_CNT];
34 };
35 
36 class RSUniRenderVirtualProcessor : public RSUniRenderProcessor {
37 public:
38     static inline constexpr RSProcessorType Type = RSProcessorType::UNIRENDER_VIRTUAL_PROCESSOR;
GetType()39     RSProcessorType GetType() const override
40     {
41         return Type;
42     }
43 
44     RSUniRenderVirtualProcessor() = default;
45     ~RSUniRenderVirtualProcessor() noexcept override = default;
46 
47     bool InitForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable, ScreenId mirroredId,
48         std::shared_ptr<RSBaseRenderEngine> renderEngine) override;
49     void ProcessDisplaySurfaceForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable) override;
50     void ProcessSurface(RSSurfaceRenderNode& node) override;
51     void ProcessRcdSurface(RSRcdSurfaceRenderNode& node) override;
52     void PostProcess() override;
53     void ScaleMirrorIfNeed(RSDisplayRenderNode& node, RSPaintFilterCanvas& canvas);
54     void Fill(RSPaintFilterCanvas& canvas,
55         float mainWidth, float mainHeight, float mirrorWidth, float mirrorHeight);
56     void UniScale(RSPaintFilterCanvas& canvas,
57         float mainWidth, float mainHeight, float mirrorWidth, float mirrorHeight);
58 
GetCanvas()59     std::shared_ptr<RSPaintFilterCanvas> GetCanvas()
60     {
61         return canvas_;
62     }
GetMirrorScaleX()63     float GetMirrorScaleX() const
64     {
65         return mirrorScaleX_;
66     }
GetMirrorScaleY()67     float GetMirrorScaleY() const
68     {
69         return mirrorScaleY_;
70     }
GetCanvasMatrix()71     const Drawing::Matrix& GetCanvasMatrix() const
72     {
73         return canvasMatrix_;
74     }
75     void SetDirtyInfo(std::vector<RectI>& damageRegion);
76     int32_t GetBufferAge() const;
77     // when virtual screen partial refresh closed, use this function to reset RoiRegion in buffer
78     GSError SetRoiRegionToCodec(std::vector<RectI>& damageRegion);
79     bool RequestVirtualFrame(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
80     void CalculateTransform(RSDisplayRenderNode& node);
81     void CalculateTransform(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
82     void ScaleMirrorIfNeed(const ScreenRotation angle, RSPaintFilterCanvas& canvas);
83     void ProcessVirtualDisplaySurface(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
84     void CanvasClipRegionForUniscaleMode();
85 private:
86     void CanvasInit(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
87     void CanvasInit(RSDisplayRenderNode& node);
88     void OriginScreenRotation(ScreenRotation screenRotation, float width, float height);
89 
90     sptr<Surface> producerSurface_;
91     std::unique_ptr<RSRenderFrame> renderFrame_;
92     std::shared_ptr<RSPaintFilterCanvas> canvas_;
93     bool forceCPU_ = false;
94     bool isExpand_ = false;
95     float mirrorWidth_ = 0.f;
96     float mirrorHeight_ = 0.f;
97     float mainWidth_ = 0.f;
98     float mainHeight_ = 0.f;
99     float originalVirtualScreenWidth_ = 0.f; // used for recording the original virtual screen width
100     float originalVirtualScreenHeight_ = 0.f; // used for recording the original virtual screen height
101     float virtualScreenWidth_ = 0.f;
102     float virtualScreenHeight_ = 0.f;
103     float mirroredScreenWidth_ = 0.f;
104     float mirroredScreenHeight_ = 0.f;
105     bool updateFlag_ = false;
106     bool canvasRotation_ = false;
107     ScreenScaleMode scaleMode_ = ScreenScaleMode::INVALID_MODE;
108     ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0;
109     ScreenRotation screenCorrection_ = ScreenRotation::ROTATION_0;
110     float mirrorScaleX_ = 1.0f;
111     float mirrorScaleY_ = 1.0f;
112     Drawing::Matrix canvasMatrix_;
113     sptr<RSScreenManager> screenManager_ = nullptr;
114     ScreenId virtualScreenId_ = INVALID_SCREEN_ID;
115     ScreenId mirroredScreenId_ = INVALID_SCREEN_ID;
116 };
117 } // namespace Rosen
118 } // namespace OHOS
119 #endif // RS_CORE_PIPELINE_UNI_RENDER_MIRROR_PROCESSOR_H
120