• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_HETERO_HDR_UTIL_H
17 #define RS_HETERO_HDR_UTIL_H
18 
19 #include <buffer_handle.h>
20 #include <condition_variable>
21 #include <cstdint>
22 #include <dlfcn.h>
23 #include <set>
24 #include <unordered_map>
25 #include <vector>
26 
27 #include "feature/round_corner_display/rs_rcd_surface_render_node.h"
28 #include "pipeline/rs_surface_render_node.h"
29 #include "rs_trace.h"
30 #include "screen_manager/rs_screen_manager.h"
31 #include "screen_manager/screen_types.h"
32 
33 namespace OHOS::Rosen {
34 #define DVFS_LEVEL_MIDDLE 3
35 #define DVFS_LEVEL_HIGH 4
36 
37 // for scene id capbility bit0 ~ bit55
38 constexpr uint64_t MDC_CAP_HEBCE = 1;
39 constexpr uint64_t MDC_CAP_UVUP = 1 << 1;
40 constexpr uint64_t MDC_CAP_SCALE = 1 << 2;
41 constexpr uint64_t MDC_CAP_ROT = 1 << 3;
42 constexpr uint64_t MDC_CAP_HDR = 1 << 4;
43 
44 constexpr uint64_t EFFECT_RESOURCE_HDR_BIT = 5;
45 
46 /* Rectangle */
47 using MdcRectT = struct MdcRect {
48     int32_t left;
49     int32_t top;
50     int32_t right;
51     int32_t bottom;
52 };
53 
54 using MdcContentsT = struct MdcCopybitContents {
55     /*
56      * Request Direct Mdc Channel
57      *
58      * MDC_POWER_UP = 0x1,
59      * MDC_POWER_DOWN = 0x2,
60      *
61      */
62     union {
63         uint32_t powerMode;
64         uint32_t mdcPowerMode;
65     };
66 
67     /*
68      * Request Direct Mdc Channel
69      *
70      * MDC_VOLTAGE_LOW = 0x1,
71      * MDC_VOLTAGE_NORMAL = 0x2,
72      * MDC_VOLTAGE_HIGH = 0x3,
73      */
74     union {
75         uint32_t mdcVoltaLev;
76         uint32_t perfLev;
77     };
78 
79     /*
80      * MUST use copybit to compose,
81      * input param: 1 is needed.
82      * only for ISP and online play used.
83      */
84     union {
85         uint32_t needHold;
86         uint32_t hold;
87     };
88     /*
89      * handle secure buffer(drm),
90      * input param: 1 is secure.
91      * default 0 is non-secure
92      */
93     uint32_t secure;
94 
95     /*
96      * Transformation to apply to the buffer during copybit.
97      * Reference system/core/include/system/window.h defined
98      * Set default value: 0
99      *        90 degrees: NATIVE_WINDOW_TRANSFORM_ROT_90
100      */
101     uint32_t transform;
102 
103     /*
104      * This is the information of the source buffer to copybit. This handle
105      * is guaranteed to have been allocated from gralloc by caller.
106      * The width, height and format have been set.
107      */
108     union {
109         BufferHandle *srcBufferHandle;
110 
111         BufferHandle *srcHandle;
112 
113         uint64_t srcHandlePadding;
114     };
115 
116     /*
117      * This is the information of the destination buffer to copybit. This handle
118      * is guaranteed to have been allocated from gralloc by caller.
119      * The width, height and format have been set.
120      */
121     union {
122         BufferHandle *dstBufferHandle;
123 
124         BufferHandle *dstHandle;
125 
126         uint64_t dstHandlePadding;
127     };
128 
129     /*
130      * Area of the source to consider, the origin is the top-left corner of
131      * the buffer.
132      */
133     MdcRectT srcRect;
134 
135     /* where to copybit the source rect onto the display. The sourceCrop
136      * is scaled using linear filtering to the displayFrame. The origin is the
137      */
138     MdcRectT dstRect;
139 
140     /*
141      * Sync fence object that will be signaled when the buffer's
142      * contents are available. May be -1 if the contents are already
143      * available. but the MDC must wait for the source buffer
144      * to be signaled before reading from them.
145      */
146     int32_t acquireFenceFd;
147 
148     /*
149      * Sync fence object that will be signaled when the buffer's
150      * contents are available. May be -1 if the contents are already
151      * available. but the caller must wait for the destination buffer
152      * to be signaled before reading from them. The destination buffer will
153      * be signaled when MDC copybit operation had been finished.
154      */
155     int32_t releaseFenceFd;
156 
157     /*
158      * Request MDC effect resources
159      *
160      * EFFECT_ARSR = 1ULL << 0,
161      * AIHDR_LUT = 1ULL << 1,
162      * ROUNDED_CORNER = 1ULL << 2,
163      * AIHDR_ENHANCE_MODE = 1ULL << 3,
164      * AIHDR_HIGHLIGHT_MODE = 1ULL << 4,
165      */
166     uint64_t effectResourceRequest = 0;
167 
168     /*
169     * MDC support async & sync ffts task
170     */
171     bool isAsyncTask = false;
172 
173     /*
174     * taskId For async mode to destroy cmdlist
175     */
176     uint32_t *taskId;
177 
178     /*
179     * taskPtr(cmdlistHeader) For async mode to submit task
180     */
181     void **taskPtr;
182 
183     int32_t expectRunTime = -1;
184 
185     /*
186     * accept nit from rs
187     */
188     float displaySdrNit;
189     float displayHdrNit;
190 };
191 
192 /*
193  * Support set more prelayers
194  * for aihdr lut layer
195  * for cld top bottom layers.
196  */
197 struct mdcLayerInfoT {
198     uint32_t transform = 0;
199     uint64_t effectResourceRequest = 0;
200     MdcRectT srcRect;
201     MdcRectT dstRect;
202     BufferHandle *handle;
203 };
204 
205 /*
206  * Every device data structure must begin with hw_device_t
207  * followed by module specific public methods and attributes.
208  */
209 struct MdcDeviceT {
210     int (* copybit)(struct MdcDeviceT *dev, int channel, MdcContentsT *hwLayers);
211     int (* requestPowerMode) (struct MdcDeviceT *dev, int powerMode);
212     int (* requestVoltaLev) (struct MdcDeviceT *dev, int voltaLev);
213     int (* requestCoreClkLev) (struct MdcDeviceT *dev, int coreClkLev);
214     int (* requestChannel) (struct MdcDeviceT *dev);
215     int (* releaseChannel) (struct MdcDeviceT *dev, int channel);
216     int (* requestChannelByCap) (struct MdcDeviceT *dev, uint64_t needCaps);
217     void (* dump) (struct MdcDeviceT *dev);
218     int (* setMultiPreLayers) (std::vector<mdcLayerInfoT> &preLayers);
219     void (* destroyTask) (uint32_t taskId);
220 };
221 
222 struct hapeTaskInfoT {
223     void** taskPtr;
224     uint32_t* taskId;
225     MdcRectT srcRect;
226     MdcRectT dstRect;
227     int transform = 0;
228     BufferHandle* srcHandle;
229     BufferHandle* dstHandle;
230     int32_t acquireFenceFd = -1;
231     int32_t releaseFenceFd = -1;
232     float displaySDRNits = 500.0f;
233     float displayHDRNits = 500.0f;
234 };
235 
236 class RSHeteroHdrUtil  {
237 public:
238     static RSHeteroHdrUtil  &GetInstance();
239     int32_t BuildHpaeHdrTask(hapeTaskInfoT& taskinfo);
240 
241     int32_t RequestHpaeChannel();
242     void DestroyHpaeHdrTask(uint32_t taskId);
243     void ReleaseHpaeHdrChannel();
244 
245 private:
246     RSHeteroHdrUtil();
247     ~RSHeteroHdrUtil();
248     RSHeteroHdrUtil(const RSHeteroHdrUtil  &);
249     RSHeteroHdrUtil(const RSHeteroHdrUtil  &&);
250     RSHeteroHdrUtil  &operator = (const RSHeteroHdrUtil  &);
251     RSHeteroHdrUtil  &operator = (const RSHeteroHdrUtil  &&);
252 
253     void* mdcHandle = nullptr;
254     const char* mdcLib = "/vendor/lib64/libmediacomm.z.so";
255     MdcDeviceT*(*getMdcDevice)() = nullptr;
256     MdcDeviceT* mdcDev = nullptr;
257     MdcContentsT mdcContent;
258     std::mutex mdcMtx_;
259     std::atomic<bool> mdcStatus_{false};
260     std::atomic<bool> mdcExistedStatus_{false};
261 };
262 }
263 #endif // RS_HETERO_HDR_UTIL_H
264