• 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 #include "pipeline/slr_scale/rs_slr_scale.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 constexpr uint32_t ROI_REGIONS_MAX_CNT = 8;
25 struct RoiRegionInfo {
26     uint32_t startX = 0;
27     uint32_t startY = 0;
28     uint32_t width = 0;
29     uint32_t height = 0;
30 };
31 
32 struct RoiRegions {
33     uint32_t regionCnt = 0;
34     RoiRegionInfo regions[ROI_REGIONS_MAX_CNT];
35 };
36 
37 class RSUniRenderVirtualProcessor : public RSUniRenderProcessor {
38 public:
39     static inline constexpr RSProcessorType Type = RSProcessorType::UNIRENDER_VIRTUAL_PROCESSOR;
GetType()40     RSProcessorType GetType() const override
41     {
42         return Type;
43     }
44 
45     RSUniRenderVirtualProcessor() = default;
46     ~RSUniRenderVirtualProcessor() noexcept override = default;
47 
48     bool InitForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable, ScreenId mirroredId,
49         std::shared_ptr<RSBaseRenderEngine> renderEngine) override;
50     void ProcessDisplaySurfaceForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable) override;
51     void ProcessSurface(RSSurfaceRenderNode& node) override;
52     void ProcessRcdSurface(RSRcdSurfaceRenderNode& node) override;
53     void PostProcess() override;
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 
GetSlrManager()59     std::shared_ptr<RSSLRScaleFunction> GetSlrManager()
60     {
61         return slrManager_;
62     }
GetCanvas()63     std::shared_ptr<RSPaintFilterCanvas> GetCanvas()
64     {
65         return canvas_;
66     }
GetMirrorScaleX()67     float GetMirrorScaleX() const
68     {
69         return mirrorScaleX_;
70     }
GetMirrorScaleY()71     float GetMirrorScaleY() const
72     {
73         return mirrorScaleY_;
74     }
GetCanvasMatrix()75     const Drawing::Matrix& GetCanvasMatrix() const
76     {
77         return canvasMatrix_;
78     }
79     void SetDirtyInfo(std::vector<RectI>& damageRegion);
80     int32_t GetBufferAge() const;
81     // when virtual screen partial refresh closed, use this function to reset RoiRegion in buffer
82     GSError SetRoiRegionToCodec(std::vector<RectI>& damageRegion);
83     bool RequestVirtualFrame(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
84     void CalculateTransform(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
85     void ScaleMirrorIfNeed(const ScreenRotation angle, RSPaintFilterCanvas& canvas);
86     void ProcessVirtualDisplaySurface(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
87     void CanvasClipRegionForUniscaleMode();
88     void ProcessCacheImage(Drawing::Image& cacheImage);
SetDrawVirtualMirrorCopy(bool drawMirrorCopy)89     void SetDrawVirtualMirrorCopy(bool drawMirrorCopy)
90     {
91         drawMirrorCopy_ = drawMirrorCopy;
92     }
93 private:
94     void CanvasInit(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable);
95     void OriginScreenRotation(ScreenRotation screenRotation, float width, float height);
96     bool EnableVisibleRect();
97     bool EnableSlrScale();
98     GSError SetColorSpaceForMetadata(GraphicColorGamut colorSpace);
99 
100     static inline const std::map<GraphicColorGamut,
101         HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType> COLORSPACE_TYPE {
102             { GRAPHIC_COLOR_GAMUT_SRGB, HDI::Display::Graphic::Common::V1_0::CM_SRGB_LIMIT },
103             { GRAPHIC_COLOR_GAMUT_DISPLAY_P3, HDI::Display::Graphic::Common::V1_0::CM_P3_LIMIT }
104     };
105     sptr<Surface> producerSurface_;
106     std::unique_ptr<RSRenderFrame> renderFrame_;
107     std::shared_ptr<RSPaintFilterCanvas> canvas_;
108     bool forceCPU_ = false;
109     bool isExpand_ = false;
110     float mirrorWidth_ = 0.f;
111     float mirrorHeight_ = 0.f;
112     float mainWidth_ = 0.f;
113     float mainHeight_ = 0.f;
114     float originalVirtualScreenWidth_ = 0.f; // used for recording the original virtual screen width
115     float originalVirtualScreenHeight_ = 0.f; // used for recording the original virtual screen height
116     float virtualScreenWidth_ = 0.f;
117     float virtualScreenHeight_ = 0.f;
118     float mirroredScreenWidth_ = 0.f;
119     float mirroredScreenHeight_ = 0.f;
120     bool updateFlag_ = false;
121     bool canvasRotation_ = false;
122     ScreenScaleMode scaleMode_ = ScreenScaleMode::INVALID_MODE;
123     ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0;
124     ScreenRotation screenCorrection_ = ScreenRotation::ROTATION_0;
125     float mirrorScaleX_ = 1.0f;
126     float mirrorScaleY_ = 1.0f;
127     Drawing::Matrix canvasMatrix_;
128     Drawing::Rect visibleRect_;
129     sptr<RSScreenManager> screenManager_ = nullptr;
130     ScreenId virtualScreenId_ = INVALID_SCREEN_ID;
131     ScreenId mirroredScreenId_ = INVALID_SCREEN_ID;
132     std::shared_ptr<RSSLRScaleFunction> slrManager_ = nullptr;
133     bool drawMirrorCopy_ = false;
134 };
135 } // namespace Rosen
136 } // namespace OHOS
137 #endif // RS_CORE_PIPELINE_UNI_RENDER_MIRROR_PROCESSOR_H
138