1 /*
2 * Copyright (c) 2021-2022 Rockchip Electronics 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 #include <stdio.h>
17 #include <string.h>
18 #include "im2d.h"
19 #include "rga.h"
20 #include "display_common.h"
21 #include "display_gralloc.h"
22 #include "securec.h"
23 #include "display_gfx.h"
24
25 #define ALIGN_UP(x, a) ((((x) + ((a)-1)) / (a)) * (a))
26 GrallocFuncs *grallocFucs = NULL;
rkInitGfx()27 int32_t rkInitGfx()
28 {
29 DISPLAY_LOGE("%s\n", querystring(RGA_ALL));
30 return DISPLAY_SUCCESS;
31 }
32
rkDeinitGfx()33 int32_t rkDeinitGfx()
34 {
35 return DISPLAY_SUCCESS;
36 }
37
colorSpaceModeChange(PixelFormat color,uint8_t * isYuv)38 RgaSURF_FORMAT colorSpaceModeChange(PixelFormat color, uint8_t *isYuv)
39 {
40 RgaSURF_FORMAT rkFormat;
41 switch (color) {
42 case PIXEL_FMT_RGB_565: /**< RGB565 format */
43 rkFormat = RK_FORMAT_RGB_565;
44 *isYuv = 0;
45 break;
46 case PIXEL_FMT_RGBA_4444: /**< RGBA4444 format */
47 rkFormat = RK_FORMAT_RGBA_4444;
48 *isYuv = 0;
49 break;
50 case PIXEL_FMT_RGBA_5551: /**< RGBA5551 format */
51 rkFormat = RK_FORMAT_RGBA_5551;
52 *isYuv = 0;
53 break;
54 case PIXEL_FMT_RGBX_8888: /**< RGBX8888 format */
55 rkFormat = RK_FORMAT_RGBX_8888;
56 *isYuv = 0;
57 break;
58 case PIXEL_FMT_RGBA_8888: /**< RGBA8888 format */
59 rkFormat = RK_FORMAT_RGBA_8888;
60 *isYuv = 0;
61 break;
62 case PIXEL_FMT_RGB_888: /**< RGB888 format */
63 rkFormat = RK_FORMAT_RGB_888;
64 *isYuv = 0;
65 break;
66 case PIXEL_FMT_BGR_565: /**< BGR565 format */
67 rkFormat = RK_FORMAT_BGR_565;
68 *isYuv = 0;
69 break;
70 case PIXEL_FMT_BGRA_4444: /**< BGRA4444 format */
71 rkFormat = RK_FORMAT_BGRA_4444;
72 *isYuv = 0;
73 break;
74 case PIXEL_FMT_BGRA_5551: /**< BGRA5551 format */
75 rkFormat = RK_FORMAT_BGRA_5551;
76 *isYuv = 0;
77 break;
78 case PIXEL_FMT_BGRX_8888: /**< BGRX8888 format */
79 rkFormat = RK_FORMAT_BGRX_8888;
80 *isYuv = 0;
81 break;
82 case PIXEL_FMT_BGRA_8888: /**< BGRA8888 format */
83 rkFormat = RK_FORMAT_BGRA_8888;
84 *isYuv = 0;
85 break;
86 case PIXEL_FMT_YCBCR_422_SP: /**< YCBCR422 semi-planar format */
87 rkFormat = RK_FORMAT_YCbCr_420_SP;
88 *isYuv = 1;
89 break;
90 case PIXEL_FMT_YCRCB_422_SP: /**< YCRCB422 semi-planar format */
91 rkFormat = RK_FORMAT_YCrCb_422_SP;
92 *isYuv = 1;
93 break;
94 case PIXEL_FMT_YCBCR_420_SP: /**< YCBCR420 semi-planar format */
95 rkFormat = RK_FORMAT_YCbCr_420_SP;
96 *isYuv = 1;
97 break;
98 case PIXEL_FMT_YCRCB_420_SP: /**< YCRCB420 semi-planar format */
99 rkFormat = RK_FORMAT_YCrCb_420_SP;
100 *isYuv = 1;
101 break;
102 case PIXEL_FMT_YCBCR_422_P: /**< YCBCR422 planar format */
103 rkFormat = RK_FORMAT_YCbCr_422_P;
104 *isYuv = 1;
105 break;
106 case PIXEL_FMT_YCRCB_422_P: /**< YCRCB422 planar format */
107 rkFormat = RK_FORMAT_YCrCb_422_P;
108 *isYuv = 1;
109 break;
110 case PIXEL_FMT_YCBCR_420_P: /**< YCBCR420 planar format */
111 rkFormat = RK_FORMAT_YCbCr_420_P;
112 *isYuv = 1;
113 break;
114 case PIXEL_FMT_YCRCB_420_P: /**< YCRCB420 planar format */
115 rkFormat = RK_FORMAT_YCrCb_420_P;
116 *isYuv = 1;
117 break;
118 case PIXEL_FMT_YUYV_422_PKG: /**< YUYV422 packed format */
119 rkFormat = RK_FORMAT_YUYV_422;
120 *isYuv = 1;
121 break;
122 case PIXEL_FMT_UYVY_422_PKG: /**< UYVY422 packed format */
123 rkFormat = RK_FORMAT_UYVY_422;
124 *isYuv = 1;
125 break;
126 case PIXEL_FMT_YVYU_422_PKG: /**< YVYU422 packed format */
127 rkFormat = RK_FORMAT_YUYV_422;
128 *isYuv = 1;
129 break;
130 case PIXEL_FMT_VYUY_422_PKG: /**< VYUY422 packed format */
131 rkFormat = RK_FORMAT_VYUY_422;
132 *isYuv = 1;
133 break;
134 default:
135 // PIXEL_FMT_CLUT8: /**< CLUT8 format */
136 // PIXEL_FMT_CLUT1, /**< CLUT1 format */
137 // PIXEL_FMT_CLUT4, /**< CLUT4 format */
138 // PIXEL_FMT_RGBA_5658, /**< RGBA5658 format */
139 // PIXEL_FMT_RGBX_4444, /**< RGBX4444 format */
140 // PIXEL_FMT_RGB_444, /**< RGB444 format */
141 // PIXEL_FMT_RGBX_5551, /**< RGBX5551 format */
142 // PIXEL_FMT_RGB_555, /**< RGB555 format */
143 // PIXEL_FMT_BGRX_4444, /**< BGRX4444 format */
144 // PIXEL_FMT_BGRX_5551, /**< BGRX5551 format */
145 // PIXEL_FMT_YUV_422_I, /**< YUV422 interleaved format */
146 rkFormat = RK_FORMAT_UNKNOWN;
147 break;
148 }
149 return rkFormat;
150 }
151
rkFillRect(ISurface * iSurface,IRect * rect,uint32_t color,GfxOpt * opt)152 int32_t rkFillRect(ISurface *iSurface, IRect *rect, uint32_t color, GfxOpt *opt)
153 {
154 rga_buffer_t dst;
155 im_rect imRect;
156 IM_STATUS ret;
157 uint8_t isYuv;
158
159 errno_t eok = memset_s((void *)&imRect, sizeof(imRect), 0, sizeof(imRect));
160 if (eok != EOK) {
161 DISPLAY_LOGE("memset_s failed");
162 return false;
163 }
164 imRect.x = rect->x;
165 imRect.y = rect->y;
166 imRect.width = rect->w;
167 imRect.height = rect->h;
168
169 eok = memset_s((void *)&dst, sizeof(dst), 0, sizeof(dst));
170 if (eok != EOK) {
171 DISPLAY_LOGE("memset_s failed");
172 return false;
173 }
174 dst.phy_addr = 0; // (void*)iSurface->phyAddr;
175 dst.vir_addr = 0; // iSurface->virAddr;
176 dst.fd = (int32_t)iSurface->phyAddr;
177 if (dst.fd == 0) {
178 DISPLAY_LOGE("source fd is invalid");
179 return DISPLAY_PARAM_ERR;
180 }
181 DISPLAY_DEBUGLOG("fd %{public}d", dst.fd);
182 dst.width = iSurface->width;
183 dst.height = iSurface->height;
184 dst.wstride = ALIGN_UP(iSurface->width, 16);
185 dst.hstride = ALIGN_UP(iSurface->height, 2);
186 dst.format = colorSpaceModeChange(iSurface->enColorFmt, &isYuv);
187 dst.color_space_mode = IM_COLOR_SPACE_DEFAULT;
188 dst.color = color;
189 if (opt->enGlobalAlpha)
190 dst.global_alpha = opt->globalAlpha;
191 ret = imfill(dst, imRect, color);
192 if (ret != IM_STATUS_SUCCESS)
193 return DISPLAY_FAILURE;
194 else
195 return DISPLAY_SUCCESS;
196 }
197
blendTypeChange(BlendType blendType)198 int32_t blendTypeChange(BlendType blendType)
199 {
200 int32_t rkBlendType;
201 switch (blendType) {
202 case BLEND_SRC: /**< SRC blending */
203 rkBlendType = IM_ALPHA_BLEND_SRC;
204 break;
205 case BLEND_DST: /**< SRC blending */
206 rkBlendType = IM_ALPHA_BLEND_DST;
207 break;
208 case BLEND_SRCOVER: /**< SRC_OVER blending */
209 rkBlendType = IM_ALPHA_BLEND_SRC_OVER;
210 break;
211 case BLEND_DSTOVER: /**< DST_OVER blending */
212 rkBlendType = IM_ALPHA_BLEND_DST_OVER;
213 break;
214 default:
215 /* Fix up later */
216 // BLEND_NONE /**< No blending */
217 // BLEND_CLEAR: /**< CLEAR blending */
218 // BLEND_SRCIN: /**< SRC_IN blending */
219 // BLEND_DSTIN: /**< DST_IN blending */
220 // BLEND_SRCOUT: /**< SRC_OUT blending */
221 // BLEND_DSTOUT: /**< DST_OUT blending */
222 // BLEND_SRCATOP: /**< SRC_ATOP blending */
223 // BLEND_DSTATOP: /**< DST_ATOP blending */
224 // BLEND_ADD: /**< ADD blending */
225 // BLEND_XOR: /**< XOR blending */
226 // BLEND_DST: /**< DST blending */
227 // BLEND_AKS: /**< AKS blending */
228 // BLEND_AKD: /**< AKD blending */
229 // BLEND_BUTT: /**< Null operation */
230 rkBlendType = IM_STATUS_NOT_SUPPORTED;
231 break;
232 }
233 return rkBlendType;
234 }
235
TransformTypeChange(TransformType type)236 int32_t TransformTypeChange(TransformType type)
237 {
238 int32_t rkTransformType;
239 switch (type) {
240 case ROTATE_90: /**< Rotation by 90 degrees */
241 rkTransformType = IM_HAL_TRANSFORM_ROT_90;
242 break;
243 case ROTATE_180: /**< Rotation by 180 degrees */
244 rkTransformType = IM_HAL_TRANSFORM_ROT_180;
245 break;
246 case ROTATE_270: /**< Rotation by 270 degrees */
247 rkTransformType = IM_HAL_TRANSFORM_ROT_270;
248 break;
249 case MIRROR_H: /**< Mirror transform horizontally */
250 rkTransformType = IM_HAL_TRANSFORM_FLIP_H;
251 break;
252 case MIRROR_V: /**< Mirror transform vertically */
253 rkTransformType = IM_HAL_TRANSFORM_FLIP_V;
254 break;
255 case MIRROR_H_ROTATE_90: /**< Mirror transform horizontally, rotation by 90 degrees */
256 rkTransformType = IM_HAL_TRANSFORM_ROT_90 | IM_HAL_TRANSFORM_FLIP_V;
257 break;
258 case MIRROR_V_ROTATE_90: /**< Mirror transform vertically, rotation by 90 degrees */
259 rkTransformType = IM_HAL_TRANSFORM_ROT_90 | IM_HAL_TRANSFORM_FLIP_H;
260 break;
261 default:
262 rkTransformType = 0; /**< No rotation */
263 break;
264 }
265 return rkTransformType;
266 }
267
doFlit(ISurface * srcSurface,IRect * srcRect,ISurface * dstSurface,IRect * dstRect,GfxOpt * opt)268 int32_t doFlit(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt)
269 {
270 int32_t usage = 0;
271 uint8_t isYuv = 0;
272 rga_buffer_t dstRgaBuffer, srcRgaBuffer, bRgbBuffer;
273 IM_STATUS ret = 0;
274 im_rect srect;
275 im_rect drect;
276 im_rect prect;
277 int32_t rkBlendType = 0;
278 int32_t rkTransformType = 0;
279
280 errno_t eok = memset_s(&dstRgaBuffer, sizeof(dstRgaBuffer), 0, sizeof(dstRgaBuffer));
281 if (eok != EOK) {
282 DISPLAY_LOGE("memset_s failed");
283 return false;
284 }
285 eok = memset_s(&srcRgaBuffer, sizeof(srcRgaBuffer), 0, sizeof(srcRgaBuffer));
286 if (eok != EOK) {
287 DISPLAY_LOGE("memset_s failed");
288 return false;
289 }
290 eok = memset_s(&bRgbBuffer, sizeof(bRgbBuffer), 0, sizeof(bRgbBuffer));
291 if (eok != EOK) {
292 DISPLAY_LOGE("memset_s failed");
293 return false;
294 }
295 eok = memset_s(&srect, sizeof(srect), 0, sizeof(srect));
296 if (eok != EOK) {
297 DISPLAY_LOGE("memset_s failed");
298 return false;
299 }
300 eok = memset_s(&drect, sizeof(drect), 0, sizeof(drect));
301 if (eok != EOK) {
302 DISPLAY_LOGE("memset_s failed");
303 return false;
304 }
305 eok = memset_s(&prect, sizeof(prect), 0, sizeof(prect));
306 if (eok != EOK) {
307 DISPLAY_LOGE("memset_s failed");
308 return false;
309 }
310 if (opt->enGlobalAlpha) {
311 dstRgaBuffer.global_alpha = opt->globalAlpha;
312 srcRgaBuffer.global_alpha = opt->globalAlpha;
313 }
314 dstRgaBuffer.width = dstSurface->width;
315 dstRgaBuffer.height = dstSurface->height;
316 dstRgaBuffer.wstride = ALIGN_UP(dstSurface->width, 16);
317 dstRgaBuffer.hstride = ALIGN_UP(dstSurface->height, 2);
318 dstRgaBuffer.format = colorSpaceModeChange(dstSurface->enColorFmt, &isYuv);
319 dstRgaBuffer.phy_addr = 0; // (void *)dstSurface->phyAddr;
320 dstRgaBuffer.vir_addr = 0; // dstSurface->virAddr;
321 dstRgaBuffer.color_space_mode = IM_COLOR_SPACE_DEFAULT;
322 dstRgaBuffer.fd = (int32_t)dstSurface->phyAddr;
323 if (isYuv == 1) {
324 DISPLAY_LOGE("rk gfx do not support dst buffer is yuv format");
325 return DISPLAY_PARAM_ERR;
326 }
327
328 srcRgaBuffer.width = srcSurface->width;
329 srcRgaBuffer.height = srcSurface->height;
330 srcRgaBuffer.wstride = ALIGN_UP(srcSurface->width, 16);
331 srcRgaBuffer.hstride = ALIGN_UP(srcSurface->height, 2);
332 srcRgaBuffer.phy_addr = 0; // (void *)srcSurface->phyAddr;
333 srcRgaBuffer.vir_addr = 0; // srcSurface->virAddr;
334 srcRgaBuffer.format = colorSpaceModeChange(srcSurface->enColorFmt, &isYuv);
335 srcRgaBuffer.color_space_mode = IM_COLOR_SPACE_DEFAULT;
336 srcRgaBuffer.fd = (int32_t)srcSurface->phyAddr;
337
338 if (srcRgaBuffer.fd == 0) {
339 DISPLAY_LOGE("source fd is invalid");
340 return DISPLAY_PARAM_ERR;
341 }
342
343 DISPLAY_DEBUGLOG("gfx src fd %{public}d, w %{public}d, h %{publuc}d, sw %{public}d sh %{public}d vir %{public}p",
344 (int32_t)srcSurface->phyAddr, srcSurface->width, srcSurface->height, ALIGN_UP(srcSurface->width, 16),
345 ALIGN_UP(srcSurface->height, 2), srcRgaBuffer.vir_addr);
346 DISPLAY_DEBUGLOG("gfx dst fd %{public}d, w %{public}d, h %{public}d, sw %{public}d sh %{public}d vir %{public}p",
347 (int32_t)dstSurface->phyAddr, dstSurface->width, dstSurface->height, ALIGN_UP(dstSurface->width, 16),
348 ALIGN_UP(dstSurface->height, 2), dstRgaBuffer.vir_addr);
349
350 srect.x = srcRect->x;
351 srect.x = (srect.x % 2 == 1) ? (srect.x - 1) : srect.x; // 2: Is it odd?
352 srect.y = srcRect->y;
353 srect.y = (srect.y % 2 == 1) ? (srect.y - 1) : srect.y; // 2: Is it odd?
354 srect.height = srcRect->h;
355 srect.height = (srect.height % 2 == 1) ? (srect.height + 1) : srect.height; // 2: Is it odd?
356 srect.width = srcRect->w;
357 srect.width = (srect.width % 2 == 1) ? (srect.width + 1) : srect.width; // 2: Is it odd?
358 drect.x = dstRect->x;
359 drect.x = (drect.x % 2 == 1) ? (drect.x - 1) : drect.x; // 2: Is it odd?
360 drect.y = dstRect->y;
361 drect.y = (drect.y % 2 == 1) ? (drect.y - 1) : drect.y; // 2: Is it odd?
362 drect.height = dstRect->h;
363 drect.height = (drect.height % 2 == 1) ? (drect.height + 1) : drect.height; // 2: Is it odd?
364 drect.width = dstRect->w;
365 drect.width = (drect.width % 2 == 1) ? (drect.width + 1) : drect.width; // 2: Is it odd?
366
367 if (opt->blendType) {
368 rkBlendType = blendTypeChange(opt->blendType);
369 if (rkBlendType > 0) {
370 usage |= rkBlendType;
371 } else if (rkBlendType == IM_STATUS_NOT_SUPPORTED) {
372 return DISPLAY_NOT_SUPPORT;
373 }
374 }
375 if (opt->rotateType) {
376 rkTransformType = TransformTypeChange(opt->rotateType);
377 if (rkTransformType != 0)
378 usage |= rkTransformType;
379 }
380 if (opt->enableScale) {
381 DISPLAY_LOGE("gfx scale from (%{puhblic}d, %{public}d) to (%{public}d, %{public}d)", \
382 srcRgaBuffer.width, srcRgaBuffer.height, dstRgaBuffer.width, dstRgaBuffer.height);
383 }
384 usage |= IM_SYNC;
385 if (isYuv == 1) {
386 if (rkBlendType == IM_ALPHA_BLEND_SRC_OVER || rkBlendType == IM_ALPHA_BLEND_SRC) {
387 usage = 0;
388 if (opt->enableScale == 0) {
389 eok = memset_s(&srect, sizeof(srect), 0, sizeof(srect));
390 if (eok != EOK) {
391 DISPLAY_LOGE("memset_s failed");
392 return false;
393 }
394 srect.width = srcRgaBuffer.width;
395 srect.height = srcRgaBuffer.height;
396
397 eok = memset_s(&drect, sizeof(drect), 0, sizeof(drect));
398 if (eok != EOK) {
399 DISPLAY_LOGE("memset_s failed");
400 return false;
401 }
402 drect.x = dstRgaBuffer.width - srcRgaBuffer.width;
403 drect.y = dstRgaBuffer.height - srcRgaBuffer.height;
404 drect.width = srcRgaBuffer.width;
405 drect.height = srcRgaBuffer.height;
406 }
407 srcRgaBuffer.wstride = srcSurface->stride;
408 usage = rkTransformType | IM_SYNC;
409 ret = improcess(srcRgaBuffer, dstRgaBuffer, bRgbBuffer, srect, drect, prect, usage);
410 if (ret != IM_STATUS_SUCCESS) {
411 DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
412 }
413 } else if (rkBlendType == IM_ALPHA_BLEND_DST_OVER) {
414 if (grallocFucs == NULL) {
415 ret = GrallocInitialize(&grallocFucs);
416 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("Gralloc init failed"));
417 }
418 AllocInfo info = {
419 .width = dstRgaBuffer.width,
420 .height = dstRgaBuffer.height,
421 .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
422 .format = PIXEL_FMT_RGBA_8888, // srcSurface->enColorFmt,
423 };
424 BufferHandle *buffer = NULL;
425
426 ret = grallocFucs->AllocMem(&info, &buffer);
427 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not alloc memory"));
428
429 bRgbBuffer.width = dstRgaBuffer.width;
430 bRgbBuffer.height = dstRgaBuffer.height;
431 bRgbBuffer.wstride = dstRgaBuffer.wstride;
432 bRgbBuffer.hstride = dstRgaBuffer.hstride;
433 bRgbBuffer.format = RK_FORMAT_RGBA_8888; // srcRgaBuffer.format;
434 bRgbBuffer.phy_addr = 0; // (void *) buffer->phyAddr;
435 bRgbBuffer.vir_addr = 0; // buffer->virAddr;
436 bRgbBuffer.color_space_mode = dstRgaBuffer.color_space_mode;
437 bRgbBuffer.fd = (int32_t)buffer->phyAddr;
438 int ret = memcpy_s(&prect, sizeof(drect), &drect, sizeof(drect));
439 if (!ret) {
440 printf("memcpy_s failed!\n");
441 }
442 ret = improcess(srcRgaBuffer, bRgbBuffer, dstRgaBuffer, srect, prect, drect, usage);
443 if (ret != IM_STATUS_SUCCESS) {
444 DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
445 } else {
446 ret = imcopy(bRgbBuffer, dstRgaBuffer);
447 if (ret != IM_STATUS_SUCCESS) {
448 DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
449 }
450 }
451 grallocFucs->FreeMem(buffer);
452 }
453 } else {
454 ret = improcess(srcRgaBuffer, dstRgaBuffer, bRgbBuffer, srect, drect, prect, usage);
455 if (ret != IM_STATUS_SUCCESS) {
456 DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
457 }
458 }
459 if (ret != IM_STATUS_SUCCESS)
460 return DISPLAY_FAILURE;
461 else
462 return DISPLAY_SUCCESS;
463 }
464
rkBlit(ISurface * srcSurface,IRect * srcRect,ISurface * dstSurface,IRect * dstRect,GfxOpt * opt)465 int32_t rkBlit(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt)
466 {
467 CHECK_NULLPOINTER_RETURN_VALUE(srcSurface, DISPLAY_NULL_PTR);
468 CHECK_NULLPOINTER_RETURN_VALUE(srcRect, DISPLAY_NULL_PTR);
469 CHECK_NULLPOINTER_RETURN_VALUE(dstSurface, DISPLAY_NULL_PTR);
470 CHECK_NULLPOINTER_RETURN_VALUE(dstRect, DISPLAY_NULL_PTR);
471 CHECK_NULLPOINTER_RETURN_VALUE(opt, DISPLAY_NULL_PTR);
472
473 if (doFlit(srcSurface, srcRect, dstSurface, dstRect, opt) < 0)
474 return DISPLAY_FAILURE;
475 else
476 return DISPLAY_SUCCESS;
477 }
478
rkSync(int32_t timeOut)479 int32_t rkSync(int32_t timeOut)
480 {
481 return DISPLAY_SUCCESS;
482 }
483
GfxInitialize(GfxFuncs ** funcs)484 int32_t GfxInitialize(GfxFuncs **funcs)
485 {
486 DISPLAY_CHK_RETURN((funcs == NULL), DISPLAY_PARAM_ERR, DISPLAY_LOGE("info is null"));
487 GfxFuncs *gfxFuncs = (GfxFuncs *)malloc(sizeof(GfxFuncs));
488 DISPLAY_CHK_RETURN((gfxFuncs == NULL), DISPLAY_NULL_PTR, DISPLAY_LOGE("gfxFuncs is nullptr"));
489 errno_t eok = memset_s((void *)gfxFuncs, sizeof(GfxFuncs), 0, sizeof(GfxFuncs));
490 if (eok != EOK) {
491 DISPLAY_LOGE("memset_s failed");
492 free(gfxFuncs);
493 return DISPLAY_FAILURE;
494 }
495 gfxFuncs->InitGfx = rkInitGfx;
496 gfxFuncs->DeinitGfx = rkDeinitGfx;
497 gfxFuncs->FillRect = rkFillRect;
498 gfxFuncs->Blit = rkBlit;
499 gfxFuncs->Sync = rkSync;
500 *funcs = gfxFuncs;
501
502 return DISPLAY_SUCCESS;
503 }
504
GfxUninitialize(GfxFuncs * funcs)505 int32_t GfxUninitialize(GfxFuncs *funcs)
506 {
507 CHECK_NULLPOINTER_RETURN_VALUE(funcs, DISPLAY_NULL_PTR);
508 free(funcs);
509 DISPLAY_DEBUGLOG("%s: gfx uninitialize success", __func__);
510 return DISPLAY_SUCCESS;
511 }
512