1 /* 2 * Copyright (c) 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_COMPOSER_ADAPTER_H 17 #define RS_CORE_PIPELINE_UNI_RENDER_COMPOSER_ADAPTER_H 18 19 #include "hdi_backend.h" 20 #include "rs_composer_adapter.h" 21 #include "pipeline/hardware_thread/rs_hardware_thread.h" 22 #include "pipeline/main_thread/rs_main_thread.h" 23 #include "pipeline/rs_screen_render_node.h" 24 #include "pipeline/rs_surface_render_node.h" 25 #include "pipeline/rs_render_node_map.h" 26 #include "screen_manager/rs_screen_manager.h" 27 #include "rs_base_render_util.h" 28 // hpae offline 29 #include "feature/hwc/hpae_offline/rs_hpae_offline_processor.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 class RSComposerAdapter; 34 class RSRcdSurfaceRenderNode; 35 namespace DrawableV2 { 36 class RSScreenRenderNodeDrawable; 37 class RSSurfaceRenderNodeDrawable; 38 class RSLogicalDisplayRenderNodeDrawable; 39 class RSRcdSurfaceRenderNodeDrawable; 40 } 41 class RSUniRenderComposerAdapter { 42 public: 43 RSUniRenderComposerAdapter() = default; 44 ~RSUniRenderComposerAdapter() noexcept = default; 45 LayerInfoPtr CreateLayer(RSScreenRenderNode& node); 46 LayerInfoPtr CreateLayer(RSRcdSurfaceRenderNode& node); 47 bool Init(const ScreenInfo& screenInfo, int32_t offsetX, int32_t offsetY); 48 bool UpdateMirrorInfo(float mirrorAdaptiveCoefficient); 49 50 LayerInfoPtr CreateLayer(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable); 51 LayerInfoPtr CreateLayer(DrawableV2::RSRcdSurfaceRenderNodeDrawable& rcdDrawable); 52 void CommitLayers(const std::vector<LayerInfoPtr>& layers); 53 void SetMetaDataInfoToLayer(const LayerInfoPtr& layer, const sptr<SurfaceBuffer>& buffer, 54 const sptr<IConsumerSurface>& surface) const; 55 56 // hpae offline 57 LayerInfoPtr CreateOfflineLayer(RSSurfaceRenderNode& node, ProcessOfflineResult& processOfflineResult) const; 58 LayerInfoPtr CreateOfflineLayer(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable, 59 ProcessOfflineResult& processOfflineResult) const; 60 61 private: 62 bool IsOutOfScreenRegion(const ComposeInfo& info) const; 63 static RectI SrcRectRotateTransform(RSSurfaceRenderNode& node); 64 static RectI SrcRectRotateTransform(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable); 65 66 ComposeInfo BuildComposeInfo(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable, 67 const std::vector<RectI>& dirtyRegion); 68 ComposeInfo BuildComposeInfo(RSRcdSurfaceRenderNode& node) const; 69 ComposeInfo BuildComposeInfo(DrawableV2::RSRcdSurfaceRenderNodeDrawable& rcdDrawable) const; 70 71 void SetComposeInfoToLayer( 72 const LayerInfoPtr& layer, 73 const ComposeInfo& info, 74 const sptr<IConsumerSurface>& surface) const; 75 static void SetBufferColorSpace(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable); 76 void LayerRotate(const LayerInfoPtr& layer, RSSurfaceRenderNode& node) const; 77 void LayerRotate(const LayerInfoPtr& layer, DrawableV2::RSRenderNodeDrawableAdapter& drawable) const; 78 void DealWithNodeGravity(const RSSurfaceRenderNode& node, ComposeInfo& info) const; 79 void DealWithNodeGravity(const DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable, ComposeInfo& info) const; 80 81 void LayerCrop(const LayerInfoPtr& layer) const; 82 static void LayerScaleDown(const LayerInfoPtr& layer, RSSurfaceRenderNode& node); 83 static void LayerScaleDown(const LayerInfoPtr& layer, DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable); 84 void LayerScaleFit(const LayerInfoPtr& layer) const; 85 static void LayerPresentTimestamp(const LayerInfoPtr& layer, const sptr<Surface>& surface); 86 87 static void GetComposerInfoSrcRect(ComposeInfo &info, const RSSurfaceRenderNode& node); 88 static void GetComposerInfoSrcRect( 89 ComposeInfo& info, const DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable); 90 bool GetComposerInfoNeedClient(const ComposeInfo& info, RSRenderParams& params) const; 91 bool CheckStatusBeforeCreateLayer(RSSurfaceRenderNode& node) const; 92 bool CheckStatusBeforeCreateLayer(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) const; 93 void SetPreBufferInfo(RSSurfaceHandler& surfaceHandler, ComposeInfo& info) const; 94 95 // hpae offline 96 ComposeInfo BuildOfflineComposeInfo(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable, 97 const ProcessOfflineResult& processOfflineResult) const; 98 ComposeInfo BuildOfflineComposeInfo(RSSurfaceRenderNode& node, 99 const ProcessOfflineResult& processOfflineResult) const; 100 void OfflineLayerRotate(const LayerInfoPtr& layer) const; 101 102 std::shared_ptr<HdiOutput> output_; 103 ScreenInfo screenInfo_; 104 HdiBackend *hdiBackend_ = nullptr; 105 // The offset on dst screen for all layers. 106 int32_t offsetX_ = 0; 107 int32_t offsetY_ = 0; 108 float mirrorAdaptiveCoefficient_ = 1.0f; 109 }; 110 } // namespace Rosen 111 } // namespace OHOS 112 #endif // RS_CORE_PIPELINE_UNI_RENDER_COMPOSER_ADAPTER_H 113