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 constexpr int32_t NO_SPECIAL_LAYER = 0; 26 constexpr int32_t HAS_SPECIAL_LAYER = 0; 27 struct RoiRegionInfo { 28 uint32_t startX = 0; 29 uint32_t startY = 0; 30 uint32_t width = 0; 31 uint32_t height = 0; 32 }; 33 34 struct RoiRegions { 35 uint32_t regionCnt = 0; 36 RoiRegionInfo regions[ROI_REGIONS_MAX_CNT]; 37 }; 38 39 class RSUniRenderVirtualProcessor : public RSUniRenderProcessor { 40 public: 41 static inline constexpr RSProcessorType Type = RSProcessorType::UNIRENDER_VIRTUAL_PROCESSOR; GetType()42 RSProcessorType GetType() const override 43 { 44 return Type; 45 } 46 47 RSUniRenderVirtualProcessor() = default; 48 ~RSUniRenderVirtualProcessor() noexcept override = default; 49 50 bool InitForRenderThread(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable, 51 std::shared_ptr<RSBaseRenderEngine> renderEngine) override; 52 bool UpdateMirrorInfo(DrawableV2::RSLogicalDisplayRenderNodeDrawable& displayDrawable) override; 53 void ProcessScreenSurfaceForRenderThread(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable) override; 54 void ProcessSurface(RSSurfaceRenderNode& node) override; 55 void ProcessRcdSurface(RSRcdSurfaceRenderNode& node) override; 56 void PostProcess() override; 57 void Fill(RSPaintFilterCanvas& canvas, 58 float mainWidth, float mainHeight, float mirrorWidth, float mirrorHeight); 59 void UniScale(RSPaintFilterCanvas& canvas, 60 float mainWidth, float mainHeight, float mirrorWidth, float mirrorHeight); 61 GetSlrManager()62 std::shared_ptr<RSSLRScaleFunction> GetSlrManager() 63 { 64 return slrManager_; 65 } GetCanvas()66 std::shared_ptr<RSPaintFilterCanvas> GetCanvas() 67 { 68 return canvas_; 69 } GetMirrorScaleX()70 float GetMirrorScaleX() const 71 { 72 return mirrorScaleX_; 73 } GetMirrorScaleY()74 float GetMirrorScaleY() const 75 { 76 return mirrorScaleY_; 77 } GetCanvasMatrix()78 const Drawing::Matrix& GetCanvasMatrix() const 79 { 80 return canvasMatrix_; 81 } 82 void SetDirtyInfo(const std::vector<RectI>& damageRegion); 83 int32_t GetBufferAge() const; 84 // when virtual screen partial refresh closed, use this function to reset RoiRegion in buffer 85 GSError SetRoiRegionToCodec(const std::vector<RectI>& damageRegion); 86 void CalculateTransform(ScreenRotation rotation); 87 void ScaleMirrorIfNeed(const ScreenRotation angle, RSPaintFilterCanvas& canvas); 88 void CanvasClipRegionForUniscaleMode(const Drawing::Matrix& visibleClipRectMatrix = Drawing::Matrix(), 89 const ScreenInfo& mainScreenInfo = ScreenInfo()); 90 void ProcessCacheImage(Drawing::Image& cacheImage); SetDrawVirtualMirrorCopy(bool drawMirrorCopy)91 void SetDrawVirtualMirrorCopy(bool drawMirrorCopy) 92 { 93 drawMirrorCopy_ = drawMirrorCopy; 94 } GetDrawVirtualMirrorCopy()95 bool GetDrawVirtualMirrorCopy() const 96 { 97 return drawMirrorCopy_; 98 } 99 void CanvasInit(DrawableV2::RSLogicalDisplayRenderNodeDrawable& displayDrawable); 100 private: 101 void MergeFenceForHardwareEnabledDrawables(); 102 void SetVirtualScreenSize(DrawableV2::RSScreenRenderNodeDrawable& screenNodeDrawble, 103 const sptr<RSScreenManager>& screenManager); 104 bool CheckIfBufferSizeNeedChange(ScreenRotation firstBufferRotation, ScreenRotation curBufferRotation); 105 void OriginScreenRotation(ScreenRotation screenRotation, float width, float height); 106 bool EnableSlrScale(); 107 GSError SetColorSpaceForMetadata(GraphicColorGamut colorSpace); 108 109 static inline const std::map<GraphicColorGamut, 110 HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceType> COLORSPACE_TYPE { 111 { GRAPHIC_COLOR_GAMUT_SRGB, HDI::Display::Graphic::Common::V1_0::CM_SRGB_LIMIT }, 112 { GRAPHIC_COLOR_GAMUT_DISPLAY_P3, HDI::Display::Graphic::Common::V1_0::CM_P3_LIMIT } 113 }; 114 sptr<Surface> producerSurface_; 115 std::unique_ptr<RSRenderFrame> renderFrame_; 116 std::shared_ptr<RSPaintFilterCanvas> canvas_; 117 bool forceCPU_ = false; 118 float originalVirtualScreenWidth_ = 0.f; // used for recording the original virtual screen width 119 float originalVirtualScreenHeight_ = 0.f; // used for recording the original virtual screen height 120 float virtualScreenWidth_ = 0.f; 121 float virtualScreenHeight_ = 0.f; 122 float mirroredScreenWidth_ = 0.f; 123 float mirroredScreenHeight_ = 0.f; 124 bool canvasRotation_ = false; 125 bool autoBufferRotation_ = false; // whether buffer rotation is automatically adjusted based on the screen rotation 126 bool isMirroredDisplayRotating_ = false; 127 ScreenScaleMode scaleMode_ = ScreenScaleMode::INVALID_MODE; 128 ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0; 129 ScreenRotation screenCorrection_ = ScreenRotation::ROTATION_0; 130 float mirrorScaleX_ = 1.0f; 131 float mirrorScaleY_ = 1.0f; 132 float mirroredTranslateX_ = 0.f; 133 float mirroredTranslateY_ = 0.f; 134 Drawing::Matrix canvasMatrix_; 135 bool enableVisibleRect_ = false; 136 Drawing::Rect visibleRect_; 137 sptr<RSScreenManager> screenManager_ = nullptr; 138 ScreenId virtualScreenId_ = INVALID_SCREEN_ID; 139 ScreenId mirroredScreenId_ = INVALID_SCREEN_ID; 140 std::shared_ptr<RSSLRScaleFunction> slrManager_ = nullptr; 141 bool drawMirrorCopy_ = false; 142 }; 143 } // namespace Rosen 144 } // namespace OHOS 145 #endif // RS_CORE_PIPELINE_UNI_RENDER_MIRROR_PROCESSOR_H 146