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 <stdint.h> 22 #include <vector> 23 24 #include "screen_manager/screen_types.h" 25 #include "screen_manager/rs_screen_manager.h" 26 #include "pipeline/round_corner_display/rs_rcd_surface_render_node.h" 27 #include "pipeline/rs_display_render_node.h" 28 #include "pipeline/rs_surface_render_node.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 constexpr uint64_t USAGE_UNI_LAYER = 1ULL << 60; 33 34 struct RequestRect { 35 uint32_t x = 0; 36 uint32_t y = 0; 37 uint32_t w = 0; 38 uint32_t h = 0; 39 }; 40 41 typedef struct RequestLayerInfo { 42 uint64_t id; /**< Layer ID */ 43 RequestRect srcRect; /**< Source Rect of Surface */ 44 RequestRect dstRect; /**< Destination Rect of Surface */ 45 uint32_t zOrder; /**< Zorder of Surface */ 46 int format; /**< Format of Surface Buffer */ 47 int transform; /**< Transform of Surface Buffer */ 48 int compressType; /**< CompressType of Surface Buffer */ 49 uint64_t usage; /**< Usage of Surface Buffer */ 50 /**< Extra parameters of frame, format: [key, parameter] */ 51 std::unordered_map<std::string, std::vector<int8_t>> perFrameParameters; 52 CldInfo *cldInfo = nullptr; 53 uint32_t fps = 120; 54 } RequestLayerInfo; 55 56 using RequestCompositionType = enum class RequestComposition : int32_t { 57 INVALID = 0, 58 CLIENT = 1, 59 DEVICE = 2, 60 OFFLINE_DEVICE = 3, 61 DEVICE_VSCF = 4, 62 }; 63 64 using PreValidateFunc = int32_t (*)(uint32_t, 65 const std::vector<RequestLayerInfo> &, std::map<uint64_t, RequestCompositionType> &); 66 67 class RSUniHwcPrevalidateUtil { 68 public: 69 static RSUniHwcPrevalidateUtil& GetInstance(); 70 bool PreValidate( 71 ScreenId id, std::vector<RequestLayerInfo> infos, std::map<uint64_t, RequestCompositionType> &strategy); 72 bool CreateSurfaceNodeLayerInfo(uint32_t zorder, 73 RSSurfaceRenderNode::SharedPtr node, GraphicTransformType transform, uint32_t fps, RequestLayerInfo &info); 74 bool CreateDisplayNodeLayerInfo(uint32_t zorder, 75 RSDisplayRenderNode::SharedPtr node, const ScreenInfo &screenInfo, uint32_t fps, RequestLayerInfo &info); 76 bool CreateRCDLayerInfo( 77 RSRcdSurfaceRenderNode::SharedPtr node, const ScreenInfo &screenInfo, uint32_t fps, RequestLayerInfo &info); 78 bool CreateUIFirstLayerInfo( 79 RSSurfaceRenderNode::SharedPtr node, GraphicTransformType transform, uint32_t fps, RequestLayerInfo &info); 80 bool IsLoadSuccess() const; 81 void CollectSurfaceNodeLayerInfo( 82 std::vector<RequestLayerInfo>& prevalidLayers, std::vector<RSBaseRenderNode::SharedPtr>& surfaceNodes, 83 uint32_t curFps, uint32_t& zOrder, const ScreenInfo& screenInfo); 84 void CollectUIFirstLayerInfo(std::vector<RequestLayerInfo>& uiFirstLayers, uint32_t curFps, float zOrder, 85 const ScreenInfo& screenInfo); 86 private: 87 RSUniHwcPrevalidateUtil(); 88 ~RSUniHwcPrevalidateUtil(); 89 90 bool IsYUVBufferFormat(RSSurfaceRenderNode::SharedPtr node) const; 91 void CopyCldInfo(CldInfo src, RequestLayerInfo& info); 92 void LayerRotate( 93 RequestLayerInfo& info, const sptr<IConsumerSurface>& surface, const ScreenInfo &screenInfo); 94 bool CheckIfDoArsrPre(const RSSurfaceRenderNode::SharedPtr node); 95 void ClearCldInfo(std::vector<RequestLayerInfo>& infos); 96 97 void *preValidateHandle_ = nullptr; 98 PreValidateFunc preValidateFunc_ = nullptr; 99 bool loadSuccess = false; 100 bool arsrPreEnabled_ = false; 101 }; 102 } // namespace Rosen 103 } // namespace OHOS 104 #endif // UNI_HWC_PREVALIDATE_UTIL_H