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