1 /* 2 * Copyright (c) 2024 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 UNI_HWC_PREVALIDATE_UTIL_H 17 #define UNI_HWC_PREVALIDATE_UTIL_H 18 19 #include <array> 20 #include <map> 21 #include <vector> 22 23 #include "screen_manager/screen_types.h" 24 #include "screen_manager/rs_screen_manager.h" 25 #include "feature/hwc/rs_uni_hwc_prevalidate_common.h" 26 #include "feature/round_corner_display/rs_rcd_surface_render_node.h" 27 #include "feature/round_corner_display/rs_rcd_surface_render_node_drawable.h" 28 #include "pipeline/rs_screen_render_node.h" 29 #include "pipeline/rs_surface_render_node.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 34 typedef struct RequestLayerInfo { 35 uint64_t id; /**< Layer ID */ 36 RequestRect srcRect; /**< Source Rect of Surface */ 37 RequestRect dstRect; /**< Destination Rect of Surface */ 38 uint32_t zOrder; /**< Zorder of Surface */ 39 int format; /**< Format of Surface Buffer */ 40 int transform; /**< Transform of Surface Buffer */ 41 int compressType; /**< CompressType of Surface Buffer */ 42 uint64_t bufferUsage; /**< Usage of Surface Buffer */ 43 uint64_t layerUsage; /**< Usage of RequestLayerInfo */ 44 /**< Extra parameters of frame, format: [key, parameter] */ 45 std::unordered_map<std::string, std::vector<int8_t>> perFrameParameters; 46 CldInfo cldInfo; 47 uint32_t fps = 120; 48 BufferHandle* bufferHandle = nullptr; 49 } RequestLayerInfo; 50 51 using RequestCompositionType = enum class RequestComposition : int32_t { 52 INVALID = 0, 53 CLIENT = 1, 54 DEVICE = 2, 55 OFFLINE_DEVICE = 3, 56 DEVICE_VSCF = 4, 57 }; 58 59 using PreValidateFunc = int32_t (*)(uint32_t, 60 const std::vector<RequestLayerInfo> &, std::map<uint64_t, RequestCompositionType> &); 61 using HandleEventFunc = int32_t (*)(uint32_t, uint32_t, const std::vector<int32_t>& eventData); 62 63 class RSUniHwcPrevalidateUtil { 64 public: 65 static RSUniHwcPrevalidateUtil& GetInstance(); 66 void Init(); 67 bool PreValidate( 68 ScreenId id, std::vector<RequestLayerInfo> infos, std::map<uint64_t, RequestCompositionType> &strategy); 69 bool CreateSurfaceNodeLayerInfo(uint32_t zorder, 70 RSSurfaceRenderNode::SharedPtr node, GraphicTransformType transform, uint32_t fps, RequestLayerInfo &info); 71 bool CreateScreenNodeLayerInfo(uint32_t zorder, 72 RSScreenRenderNode::SharedPtr node, const ScreenInfo &screenInfo, uint32_t fps, RequestLayerInfo &info); 73 bool CreateRCDLayerInfo( 74 RSRcdSurfaceRenderNode::SharedPtr node, const ScreenInfo &screenInfo, uint32_t fps, RequestLayerInfo &info); 75 static void OnHwcEvent(uint32_t devId, uint32_t eventId, const std::vector<int32_t>& eventData, void* data); 76 bool IsPrevalidateEnable(); 77 bool GetPrevalidateEnabled(); 78 void CollectSurfaceNodeLayerInfo( 79 std::vector<RequestLayerInfo>& prevalidLayers, std::vector<RSBaseRenderNode::SharedPtr>& surfaceNodes, 80 uint32_t curFps, uint32_t& zOrder, const ScreenInfo& screenInfo); 81 private: 82 RSUniHwcPrevalidateUtil(); 83 ~RSUniHwcPrevalidateUtil(); 84 85 bool IsYUVBufferFormat(RSSurfaceRenderNode::SharedPtr node) const; 86 bool IsNeedDssRotate(GraphicTransformType transform) const; 87 void CopyCldInfo(const CldInfo& src, RequestLayerInfo& info); 88 void LayerRotate( 89 RequestLayerInfo& info, const sptr<IConsumerSurface>& surface, const ScreenInfo &screenInfo); 90 bool CheckIfDoArsrPre(const RSSurfaceRenderNode::SharedPtr node); 91 void CheckIfDoCopybit(const RSSurfaceRenderNode::SharedPtr node, GraphicTransformType transform, 92 RequestLayerInfo& info); 93 static bool CheckHwcNodeAndGetPointerWindow( 94 const RSSurfaceRenderNode::SharedPtr& node, RSSurfaceRenderNode::SharedPtr& pointerWindow); 95 static void EmplaceSurfaceNodeLayer( 96 std::vector<RequestLayerInfo>& prevalidLayers, RSSurfaceRenderNode::SharedPtr node, 97 uint32_t curFps, uint32_t& zOrder, const ScreenInfo& screenInfo); 98 99 void *preValidateHandle_ = nullptr; 100 PreValidateFunc preValidateFunc_ = nullptr; 101 HandleEventFunc handleEventFunc_ = nullptr; 102 bool loadSuccess_ = false; 103 bool isPrevalidateHwcNodeEnable_ = false; 104 bool arsrPreEnabled_ = false; 105 bool isCopybitSupported_ = false; 106 }; 107 } // namespace Rosen 108 } // namespace OHOS 109 #endif // UNI_HWC_PREVALIDATE_UTIL_H