• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, 16);
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 rkRotateType;
239     switch (type) {
240         case ROTATE_90:            /**< Rotation by 90 degrees */
241             rkRotateType = IM_HAL_TRANSFORM_ROT_90;
242             break;
243         case ROTATE_180:             /**< Rotation by 180 degrees */
244             rkRotateType = IM_HAL_TRANSFORM_ROT_180;
245             break;
246         case ROTATE_270:             /**< Rotation by 270 degrees */
247             rkRotateType = IM_HAL_TRANSFORM_ROT_270;
248             break;
249         default:
250             rkRotateType = 0;        /**< No rotation */
251             break;
252     }
253     return rkRotateType;
254 }
255 
mirrorTypeChange(MirrorType type)256 int32_t mirrorTypeChange(MirrorType type)
257 {
258     int32_t rkMirrorType;
259     switch (type) {
260         case MIRROR_LR:            /**< Left and right mirrors */
261             rkMirrorType = IM_HAL_TRANSFORM_FLIP_H;
262             break;
263         case MIRROR_TB:            /**< Top and bottom mirrors */
264             rkMirrorType = IM_HAL_TRANSFORM_FLIP_V;
265             break;
266         default:
267             rkMirrorType = 0;
268             break;
269     }
270     return rkMirrorType;
271 }
272 
doFlit(ISurface * srcSurface,IRect * srcRect,ISurface * dstSurface,IRect * dstRect,GfxOpt * opt)273 int32_t doFlit(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt)
274 {
275     int32_t usage = 0;
276     uint8_t isYuv = 0;
277     rga_buffer_t dstRgaBuffer, srcRgaBuffer, bRgbBuffer;
278     IM_STATUS ret = 0;
279     im_rect srect;
280     im_rect drect;
281     im_rect prect;
282     int32_t rkBlendType = 0;
283     int32_t rkRotateType = 0;
284     int32_t rkMirrorType = 0;
285 
286     errno_t eok = memset_s(&dstRgaBuffer, sizeof(dstRgaBuffer), 0, sizeof(dstRgaBuffer));
287     if (eok != EOK) {
288         DISPLAY_LOGE("memset_s failed");
289         return false;
290     }
291     eok = memset_s(&srcRgaBuffer, sizeof(srcRgaBuffer), 0, sizeof(srcRgaBuffer));
292     if (eok != EOK) {
293         DISPLAY_LOGE("memset_s failed");
294         return false;
295     }
296     eok = memset_s(&bRgbBuffer, sizeof(bRgbBuffer), 0, sizeof(bRgbBuffer));
297     if (eok != EOK) {
298         DISPLAY_LOGE("memset_s failed");
299         return false;
300     }
301     eok = memset_s(&srect, sizeof(srect), 0, sizeof(srect));
302     if (eok != EOK) {
303         DISPLAY_LOGE("memset_s failed");
304         return false;
305     }
306     eok = memset_s(&drect, sizeof(drect), 0, sizeof(drect));
307     if (eok != EOK) {
308         DISPLAY_LOGE("memset_s failed");
309         return false;
310     }
311     eok = memset_s(&prect, sizeof(prect), 0, sizeof(prect));
312     if (eok != EOK) {
313         DISPLAY_LOGE("memset_s failed");
314         return false;
315     }
316     if (opt->enGlobalAlpha) {
317         dstRgaBuffer.global_alpha = opt->globalAlpha;
318         srcRgaBuffer.global_alpha = opt->globalAlpha;
319     }
320     dstRgaBuffer.width = dstSurface->width;
321     dstRgaBuffer.height = dstSurface->height;
322     dstRgaBuffer.wstride = ALIGN_UP(dstSurface->width, 16);
323     dstRgaBuffer.hstride = ALIGN_UP(dstSurface->height, 16);
324     dstRgaBuffer.format = colorSpaceModeChange(dstSurface->enColorFmt, &isYuv);
325     dstRgaBuffer.phy_addr = 0; // (void *)dstSurface->phyAddr;
326     dstRgaBuffer.vir_addr = 0; // dstSurface->virAddr;
327     dstRgaBuffer.color_space_mode = IM_COLOR_SPACE_DEFAULT;
328     dstRgaBuffer.fd = (int32_t)dstSurface->phyAddr;
329     if (isYuv == 1) {
330         DISPLAY_LOGE("rk gfx do not support dst buffer is yuv format");
331         return DISPLAY_PARAM_ERR;
332     }
333 
334     srcRgaBuffer.width = srcSurface->width;
335     srcRgaBuffer.height = srcSurface->height;
336     srcRgaBuffer.wstride = ALIGN_UP(srcSurface->width, 16);
337     srcRgaBuffer.hstride = ALIGN_UP(srcSurface->height, 16);
338     srcRgaBuffer.phy_addr = 0; // (void *)srcSurface->phyAddr;
339     srcRgaBuffer.vir_addr = 0; // srcSurface->virAddr;
340     srcRgaBuffer.format = colorSpaceModeChange(srcSurface->enColorFmt, &isYuv);
341     srcRgaBuffer.color_space_mode = IM_COLOR_SPACE_DEFAULT;
342     srcRgaBuffer.fd = (int32_t)srcSurface->phyAddr;
343 
344     if (srcRgaBuffer.fd == 0) {
345         DISPLAY_LOGE("source fd is invalid");
346         return DISPLAY_PARAM_ERR;
347     }
348 
349     DISPLAY_DEBUGLOG("gfx src fd %{public}d, w %{public}d, h %{publuc}d, sw %{public}d sh %{public}d vir %{public}p",
350         (int32_t)srcSurface->phyAddr, srcSurface->width, srcSurface->height, ALIGN_UP(srcSurface->width, 16),
351         ALIGN_UP(srcSurface->height, 16), srcRgaBuffer.vir_addr);
352     DISPLAY_DEBUGLOG("gfx dst fd %{public}d, w %{public}d, h %{public}d, sw %{public}d sh %{public}d vir %{public}p",
353         (int32_t)dstSurface->phyAddr, dstSurface->width, dstSurface->height, ALIGN_UP(dstSurface->width, 16),
354         ALIGN_UP(dstSurface->height, 16), dstRgaBuffer.vir_addr);
355 
356     srect.x = srcRect->x;
357     srect.x = (srect.x == 1) ? 0 : srect.x;
358     srect.y = srcRect->y;
359     srect.y = (srect.y == 1) ? 0 : srect.y;
360     srect.height = srcRect->h;
361     srect.width = srcRect->w;
362     drect.x = dstRect->x;
363     drect.x = (drect.x == 1) ? 0 : drect.x;
364     drect.y = dstRect->y;
365     drect.y = (drect.y == 1) ? 0 : drect.y;
366     drect.height = dstRect->h;
367     drect.width = dstRect->w;
368 
369     if (opt->blendType) {
370         rkBlendType = blendTypeChange(opt->blendType);
371         if (rkBlendType > 0) {
372             usage |= rkBlendType;
373             if (rkBlendType == IM_ALPHA_BLEND_DST_OVER || rkBlendType == IM_ALPHA_BLEND_SRC_OVER)
374                 usage |= IM_ALPHA_BLEND_PRE_MUL;
375         } else if (rkBlendType == IM_STATUS_NOT_SUPPORTED) {
376             return DISPLAY_NOT_SUPPORT;
377         }
378     }
379     if (opt->rotateType) {
380         rkRotateType = TransformTypeChange(opt->rotateType);
381         if (rkRotateType != 0)
382             usage |= rkRotateType;
383     }
384     if (opt->mirrorType == MIRROR_LR || opt->mirrorType == MIRROR_TB) {
385         rkMirrorType = mirrorTypeChange(opt->mirrorType);
386         if (rkMirrorType != 0)
387             usage |= rkMirrorType;
388     }
389     if (opt->enableScale) {
390         DISPLAY_LOGE("gfx scale from (%{puhblic}d, %{public}d) to (%{public}d, %{public}d)", \
391             srcRgaBuffer.width, srcRgaBuffer.height, dstRgaBuffer.width, dstRgaBuffer.height);
392     }
393     usage |= IM_SYNC;
394     if (isYuv == 1) {
395         if (rkBlendType == IM_ALPHA_BLEND_SRC_OVER || rkBlendType == IM_ALPHA_BLEND_SRC) {
396             usage = 0;
397             if (opt->enableScale == 0) {
398                 eok = memset_s(&srect, sizeof(srect), 0, sizeof(srect));
399                 if (eok != EOK) {
400                     DISPLAY_LOGE("memset_s failed");
401                     return false;
402                 }
403                 srect.width = srcRgaBuffer.width;
404                 srect.height = srcRgaBuffer.height;
405 
406                 eok = memset_s(&drect, sizeof(drect), 0, sizeof(drect));
407                 if (eok != EOK) {
408                     DISPLAY_LOGE("memset_s failed");
409                     return false;
410                 }
411                 drect.x = dstRgaBuffer.width - srcRgaBuffer.width;
412                 drect.y = dstRgaBuffer.height - srcRgaBuffer.height;
413                 drect.width = srcRgaBuffer.width;
414                 drect.height = srcRgaBuffer.height;
415             }
416             usage = rkRotateType | rkMirrorType | IM_SYNC;
417             ret = improcess(srcRgaBuffer, dstRgaBuffer, bRgbBuffer, srect, drect, prect, usage);
418             if (ret != IM_STATUS_SUCCESS) {
419                 DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
420             }
421         } else if (rkBlendType == IM_ALPHA_BLEND_DST_OVER) {
422             if (grallocFucs == NULL) {
423                 ret = GrallocInitialize(&grallocFucs);
424                 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("Gralloc init failed"));
425             }
426             AllocInfo info = {
427                 .width = dstRgaBuffer.width,
428                 .height = dstRgaBuffer.height,
429                 .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
430                 .format = PIXEL_FMT_RGBA_8888, // srcSurface->enColorFmt,
431             };
432             BufferHandle *buffer = NULL;
433 
434             ret = grallocFucs->AllocMem(&info, &buffer);
435             DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not alloc memory"));
436 
437             bRgbBuffer.width = dstRgaBuffer.width;
438             bRgbBuffer.height = dstRgaBuffer.height;
439             bRgbBuffer.wstride = dstRgaBuffer.wstride;
440             bRgbBuffer.hstride = dstRgaBuffer.hstride;
441             bRgbBuffer.format = RK_FORMAT_RGBA_8888; // srcRgaBuffer.format;
442             bRgbBuffer.phy_addr = 0; // (void *) buffer->phyAddr;
443             bRgbBuffer.vir_addr = 0; // buffer->virAddr;
444             bRgbBuffer.color_space_mode = dstRgaBuffer.color_space_mode;
445             bRgbBuffer.fd = (int32_t)buffer->phyAddr;
446             int ret = memcpy_s(&prect, sizeof(drect), &drect, sizeof(drect));
447             if (!ret) {
448                 printf("memcpy_s failed!\n");
449             }
450             ret = improcess(srcRgaBuffer, bRgbBuffer, dstRgaBuffer, srect, prect, drect, usage);
451             if (ret != IM_STATUS_SUCCESS) {
452                 DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
453             } else {
454                 ret = imcopy(bRgbBuffer, dstRgaBuffer);
455                 if (ret != IM_STATUS_SUCCESS) {
456                     DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
457                 }
458             }
459             grallocFucs->FreeMem(buffer);
460         }
461     } else {
462         ret = improcess(srcRgaBuffer, dstRgaBuffer, bRgbBuffer, srect, drect, prect, usage);
463         if (ret != IM_STATUS_SUCCESS) {
464             DISPLAY_LOGE("gfx improcess %{public}s", imStrError(ret));
465         }
466     }
467     if (ret != IM_STATUS_SUCCESS)
468         return DISPLAY_FAILURE;
469     else
470         return DISPLAY_SUCCESS;
471 }
472 
rkBlit(ISurface * srcSurface,IRect * srcRect,ISurface * dstSurface,IRect * dstRect,GfxOpt * opt)473 int32_t rkBlit(ISurface *srcSurface, IRect *srcRect, ISurface *dstSurface, IRect *dstRect, GfxOpt *opt)
474 {
475     CHECK_NULLPOINTER_RETURN_VALUE(srcSurface, DISPLAY_NULL_PTR);
476     CHECK_NULLPOINTER_RETURN_VALUE(srcRect, DISPLAY_NULL_PTR);
477     CHECK_NULLPOINTER_RETURN_VALUE(dstSurface, DISPLAY_NULL_PTR);
478     CHECK_NULLPOINTER_RETURN_VALUE(dstRect, DISPLAY_NULL_PTR);
479     CHECK_NULLPOINTER_RETURN_VALUE(opt, DISPLAY_NULL_PTR);
480 
481     if (doFlit(srcSurface, srcRect, dstSurface, dstRect, opt) < 0)
482         return DISPLAY_FAILURE;
483     else
484         return DISPLAY_SUCCESS;
485 }
486 
rkSync(int32_t timeOut)487 int32_t rkSync(int32_t timeOut)
488 {
489     return DISPLAY_SUCCESS;
490 }
491 
GfxInitialize(GfxFuncs ** funcs)492 int32_t GfxInitialize(GfxFuncs **funcs)
493 {
494     DISPLAY_CHK_RETURN((funcs == NULL), DISPLAY_PARAM_ERR, DISPLAY_LOGE("info is null"));
495     GfxFuncs *gfxFuncs = (GfxFuncs *)malloc(sizeof(GfxFuncs));
496     DISPLAY_CHK_RETURN((gfxFuncs == NULL), DISPLAY_NULL_PTR, DISPLAY_LOGE("gfxFuncs is nullptr"));
497     errno_t eok = memset_s((void *)gfxFuncs, sizeof(GfxFuncs), 0, sizeof(GfxFuncs));
498     if (eok != EOK) {
499         DISPLAY_LOGE("memset_s failed");
500         free(gfxFuncs);
501         return DISPLAY_FAILURE;
502     }
503     gfxFuncs->InitGfx = rkInitGfx;
504     gfxFuncs->DeinitGfx = rkDeinitGfx;
505     gfxFuncs->FillRect = rkFillRect;
506     gfxFuncs->Blit = rkBlit;
507     gfxFuncs->Sync = rkSync;
508     *funcs = gfxFuncs;
509 
510     return DISPLAY_SUCCESS;
511 }
512 
GfxUninitialize(GfxFuncs * funcs)513 int32_t GfxUninitialize(GfxFuncs *funcs)
514 {
515     CHECK_NULLPOINTER_RETURN_VALUE(funcs, DISPLAY_NULL_PTR);
516     free(funcs);
517     DISPLAY_DEBUGLOG("%s: gfx uninitialize success", __func__);
518     return DISPLAY_SUCCESS;
519 }
520