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 Fill(RSPaintFilterCanvas& canvas,
54         float mainWidth, float mainHeight, float mirrorWidth, float mirrorHeight);
55     void UniScale(RSPaintFilterCanvas& canvas,
56         float mainWidth, float mainHeight, float mirrorWidth, float mirrorHeight);
57 
GetCanvas()58     std::shared_ptr<RSPaintFilterCanvas> GetCanvas()
59     {
60         return canvas_;
61     }
GetMirrorScaleX()62     float GetMirrorScaleX() const
63     {
64         return mirrorScaleX_;
65     }
GetMirrorScaleY()66     float GetMirrorScaleY() const
67     {
68         return mirrorScaleY_;
69     }
GetCanvasMatrix()70     const Drawing::Matrix& GetCanvasMatrix() const
71     {
72         return canvasMatrix_;
73     }
74     void SetDirtyInfo(std::vector<RectI>& damageRegion);
75     int32_t GetBufferAge() const;
76     // when virtual screen partial refresh closed, use this function to reset RoiRegion in buffer
77     GSError SetRoiRegionToCodec(std::vector<RectI>& damageRegion);
78     void CalculateTransform(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
79     void ScaleMirrorIfNeed(const ScreenRotation angle, RSPaintFilterCanvas& canvas);
80     void CanvasClipRegionForUniscaleMode();
81 private:
82     void CanvasInit(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
83     void OriginScreenRotation(ScreenRotation screenRotation, float width, float height);
84 
85     sptr<Surface> producerSurface_;
86     std::unique_ptr<RSRenderFrame> renderFrame_;
87     std::shared_ptr<RSPaintFilterCanvas> canvas_;
88     bool forceCPU_ = false;
89     bool isExpand_ = false;
90     float originalVirtualScreenWidth_ = 0.f; // used for recording the original virtual screen width
91     float originalVirtualScreenHeight_ = 0.f; // used for recording the original virtual screen height
92     float virtualScreenWidth_ = 0.f;
93     float virtualScreenHeight_ = 0.f;
94     float mirroredScreenWidth_ = 0.f;
95     float mirroredScreenHeight_ = 0.f;
96     bool canvasRotation_ = false;
97     ScreenScaleMode scaleMode_ = ScreenScaleMode::INVALID_MODE;
98     ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0;
99     ScreenRotation screenCorrection_ = ScreenRotation::ROTATION_0;
100     float mirrorScaleX_ = 1.0f;
101     float mirrorScaleY_ = 1.0f;
102     Drawing::Matrix canvasMatrix_;
103     sptr<RSScreenManager> screenManager_ = nullptr;
104     ScreenId virtualScreenId_ = INVALID_SCREEN_ID;
105     ScreenId mirroredScreenId_ = INVALID_SCREEN_ID;
106 };
107 } // namespace Rosen
108 } // namespace OHOS
109 #endif // RS_CORE_PIPELINE_UNI_RENDER_MIRROR_PROCESSOR_H
110