From 44d6b2c7ec8fc21cb3151688008384bf5fad39dc Mon Sep 17 00:00:00 2001 From: Hou Qi Date: Fri, 13 Sep 2024 23:13:36 +0900 Subject: [PATCH 13/19] V4L2VideoDecoder: Use dlopen to dynamically use g2d api Upstream-Status: Inappropriate [NXP specific] --- media/gpu/v4l2/BUILD.gn | 1 - media/gpu/v4l2/v4l2_queue.cc | 183 ++++++++++++++++++++++++++++++++++- 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/media/gpu/v4l2/BUILD.gn b/media/gpu/v4l2/BUILD.gn index 836ee0bc7504c..0aa466ba9cec5 100644 --- a/media/gpu/v4l2/BUILD.gn +++ b/media/gpu/v4l2/BUILD.gn @@ -92,7 +92,6 @@ source_set("v4l2") { "EGL", "GLESv2", ] - libs += [ "g2d" ] configs += [ "//third_party/libyuv:libyuv_config" ] diff --git a/media/gpu/v4l2/v4l2_queue.cc b/media/gpu/v4l2/v4l2_queue.cc index 945e7a7df9b93..9fc55cfd59459 100644 --- a/media/gpu/v4l2/v4l2_queue.cc +++ b/media/gpu/v4l2/v4l2_queue.cc @@ -20,10 +20,11 @@ #include "media/gpu/chromeos/platform_video_frame_utils.h" #include "media/gpu/macros.h" -#include "g2d.h" -#include "g2dExt.h" +// #include "g2d.h" +// #include "g2dExt.h" #include #include +#include namespace media { @@ -160,6 +161,159 @@ std::vector GetDmabufsForV4L2Buffer( } // namespace +/* g2d.h g2dExt.h */ +enum g2d_format +{ +//rgb formats + G2D_RGB565 = 0, /* [0:4] Blue; [5:10] Green; [11:15] Red */ + G2D_RGBA8888 = 1, /* [0:7] Red; [8:15] Green; [16:23] Blue; [23:31] Alpha */ + G2D_RGBX8888 = 2, /* [0:7] Red; [8:15] Green; [16:23] Blue; [23:31] don't care */ + G2D_BGRA8888 = 3, /* [0:7] Blue; [8:15] Green; [16:23] Red; [23:31] Alpha */ + G2D_BGRX8888 = 4, /* [0:7] Blue; [8:15] Green; [16:23] Red; [23:31] don't care */ + G2D_BGR565 = 5, /* [0:4] Red; [5:10] Green; [11:15] Blue */ + + G2D_ARGB8888 = 6, /* [0:7] Alpha; [8:15] Red; [16:23] Green; [23:31] Blue */ + G2D_ABGR8888 = 7, /* [0:7] Alpha; [8:15] Blue; [16:23] Green; [23:31] Red */ + G2D_XRGB8888 = 8, /* [0:7] don't care; [8:15] Red; [16:23] Green; [23:31] Blue */ + G2D_XBGR8888 = 9, /* [0:7] don't care; [8:15] Blue; [16:23] Green; [23:31] Red */ + G2D_RGB888 = 10, /* [0:7] Red; [8:15] Green; [16:23] Blue */ + G2D_BGR888 = 11, /* [0:7] Blue; [8:15] Green; [16:23] Red */ + + G2D_RGBA5551 = 12, /* [0:4] Red; [5:9] Green; [10:14] Blue; [15] Alpha */ + G2D_RGBX5551 = 13, /* [0:4] Red; [5:9] Green; [10:14] Blue; [15] don't care */ + G2D_BGRA5551 = 14, /* [0:4] Blue; [5:9] Green; [10:14] Red; [15] Alpha */ + G2D_BGRX5551 = 15, /* [0:4] Blue; [5:9] Green; [10:14] Red; [15] don't care */ + +//yuv formats + G2D_NV12 = 20, /* 2 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] U; [8:15] V */ + G2D_I420 = 21, /* 3 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] U; plane 3: [0:7] V */ + G2D_YV12 = 22, /* 3 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] V; plane 3: [0:7] U */ + G2D_NV21 = 23, /* 2 plane 420 format; plane 1: [0:7] Y ; plane 2: [0:7] V; [8:15] U */ + G2D_YUYV = 24, /* 1 plane 422 format; [0:7] Y; [8:15; U; [16:23] Y; [24:31] V */ + G2D_YVYU = 25, /* 1 plane 422 format; [0:7] Y; [8:15; V; [16:23] Y; [24:31] U */ + G2D_UYVY = 26, /* 1 plane 422 format; [0:7] U; [8:15; Y; [16:23] V; [24:31] Y */ + G2D_VYUY = 27, /* 1 plane 422 format; [0:7] V; [8:15; Y; [16:23] U; [24:31] Y */ + G2D_NV16 = 28, /* 2 plane 422 format; plane 1: [0:7] Y ; plane 2: [0:7] U; [8:15] V */ + G2D_NV61 = 29, /* 2 plane 422 format; plane 1: [0:7] Y ; plane 2: [0:7] V; [8:15] U */ +}; + +enum g2d_tiling +{ + G2D_LINEAR = 0x1, + G2D_TILED = 0x2, + G2D_SUPERTILED = 0x4, + G2D_AMPHION_TILED = 0x8, + G2D_AMPHION_INTERLACED = 0x10, + G2D_TILED_STATUS = 0x20, + G2D_AMPHION_TILED_10BIT = 0x40, +}; + +struct g2d_tile_status +{ + unsigned int ts_addr; + + unsigned int fc_enabled; + unsigned int fc_value; + unsigned int fc_value_upper; +}; + +struct g2d_buf +{ + void *buf_handle; + void *buf_vaddr; + int buf_paddr; + int buf_size; +}; + +enum g2d_blend_func +{ +//basic blend + G2D_ZERO = 0, + G2D_ONE = 1, + G2D_SRC_ALPHA = 2, + G2D_ONE_MINUS_SRC_ALPHA = 3, + G2D_DST_ALPHA = 4, + G2D_ONE_MINUS_DST_ALPHA = 5, + +// extensive blend is set with basic blend together, +// such as, G2D_ONE | G2D_PRE_MULTIPLIED_ALPHA + G2D_PRE_MULTIPLIED_ALPHA = 0x10, + G2D_DEMULTIPLY_OUT_ALPHA = 0x20, +}; + +enum g2d_rotation +{ + G2D_ROTATION_0 = 0, + G2D_ROTATION_90 = 1, + G2D_ROTATION_180 = 2, + G2D_ROTATION_270 = 3, + G2D_FLIP_H = 4, + G2D_FLIP_V = 5, +}; + +struct g2d_surface +{ + enum g2d_format format; + + int planes[3];//surface buffer addresses are set in physical planes separately + //RGB: planes[0] - RGB565/RGBA8888/RGBX8888/BGRA8888/BRGX8888 + //NV12: planes[0] - Y, planes[1] - packed UV + //I420: planes[0] - Y, planes[1] - U, planes[2] - V + //YV12: planes[0] - Y, planes[1] - V, planes[2] - U + //NV21: planes[0] - Y, planes[1] - packed VU + //YUYV: planes[0] - packed YUYV + //YVYU: planes[0] - packed YVYU + //UYVY: planes[0] - packed UYVY + //VYUY: planes[0] - packed VYUY + //NV16: planes[0] - Y, planes[1] - packed UV + //NV61: planes[0] - Y, planes[1] - packed VU + + //blit rectangle in surface + int left; + int top; + int right; + int bottom; + int stride; ///< buffer stride, in Pixels + int width; ///< surface width, in Pixels + int height; ///< surface height, in Pixels + enum g2d_blend_func blendfunc; ///< alpha blending parameters + int global_alpha; ///< value is 0 ~ 255 + //clrcolor format is RGBA8888, used as dst for clear, as src for blend dim + int clrcolor; + + //rotation degree + enum g2d_rotation rot; +}; + +struct g2d_surfaceEx +{ + struct g2d_surface base; + enum g2d_tiling tiling; + + struct g2d_tile_status ts; + int reserved[8]; +}; + +void *dl_handle = NULL; + +typedef int (*g2d_api_open)(void **handle); +typedef int (*g2d_api_close)(void *handle); +typedef int (*g2d_api_free)(struct g2d_buf *buf); +typedef struct g2d_buf* (*g2d_api_alloc)(int size, int cacheable); +typedef int (*g2d_api_buf_export_fd)(struct g2d_buf *); +typedef int (*g2d_api_blitEx)(void *handle, struct g2d_surfaceEx *srcEx, struct g2d_surfaceEx *dstEx); + +#define G2D_LIB_NAME "/usr/lib/libg2d.so.2" +#define G2D_API_SYM(name) g2d_api_##name g2d_##name = nullptr +G2D_API_SYM(open); +G2D_API_SYM(close); +G2D_API_SYM(free); +G2D_API_SYM(alloc); +G2D_API_SYM(buf_export_fd); +G2D_API_SYM(blitEx); +#undef G2D_API_SYM +/* g2d.h g2dExt.h */ + V4L2ExtCtrl::V4L2ExtCtrl(uint32_t id) { memset(&ctrl, 0, sizeof(ctrl)); ctrl.id = id; @@ -1245,6 +1399,31 @@ V4L2Queue::V4L2Queue(const IoctlAsCallback& ioctl_cb, << "This queue does " << (supports_requests_ ? "" : "not") << " support requests."; + if (dl_handle == NULL) { + dl_handle = dlopen(G2D_LIB_NAME, + RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE | RTLD_LAZY); + if (!dl_handle) { + VLOGF(1) << "Failed to dlopen " << G2D_LIB_NAME; + return; + } + +#define G2D_API_DLSYM(lib, name) \ + do { \ + g2d_##name = reinterpret_cast(dlsym(lib, "g2d_" #name)); \ + if (!(g2d_##name)) \ + VLOGF(1) << "Failed to dlsym g2d_" #name; \ + } while (0) + + G2D_API_DLSYM(dl_handle, open); + G2D_API_DLSYM(dl_handle, close); + G2D_API_DLSYM(dl_handle, free); + G2D_API_DLSYM(dl_handle, alloc); + G2D_API_DLSYM(dl_handle, buf_export_fd); + G2D_API_DLSYM(dl_handle, blitEx); + + dlclose(dl_handle); + } + g2d_handle = NULL; if(g2d_open && g2d_open(&g2d_handle)) VLOGF(1) << "g2d_open fail"; -- 2.34.1