summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Ruban <intx82@gmail.com>2023-11-29 12:48:41 +0100
committerDaniil Ruban <intx82@gmail.com>2023-11-29 12:48:41 +0100
commit2f200d5f0f57e25af8494af6a0b6135734bf74f7 (patch)
tree02495da1ee973e6151b20fd96a64dbf5a04a83b1
parent95112b0f09a94c78df3bea1f229a4c3dee4aadc5 (diff)
downloadlibtbm-dumb-sandbox/intx82/qemu.tar.gz
libtbm-dumb-sandbox/intx82/qemu.tar.bz2
libtbm-dumb-sandbox/intx82/qemu.zip
try to preidct h/w from provided sizesandbox/intx82/qemu
Change-Id: If433aee4ff608897ee9007a662ef2a9150513a3f Signed-off-by: Daniil Ruban <intx82@gmail.com>
-rw-r--r--configure.ac2
-rw-r--r--src/tbm_backend_dumb.c47
2 files changed, 43 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 59839c5..1c6e50a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,7 +65,7 @@ if test "x${have_dma_buf}" = "xyes" ; then
fi
LIBHAL_BACKEND_TBM_DUMB_CFLAGS="$HAL_API_COMMON_CFLAGS $HAL_API_TBM_CFLAGS $LIBDRM_CFLAGS $DLOG_CFLAGS $LIBUDEV_CFLAGS "
-LIBHAL_BACKEND_TBM_DUMB_LIBS="$HAL_API_COMMON_LIBS $HAL_API_TBM_LIBS $LIBDRM_LIBS $DLOG_LIBS $LIBUDEV_LIBS "
+LIBHAL_BACKEND_TBM_DUMB_LIBS="$HAL_API_COMMON_LIBS $HAL_API_TBM_LIBS $LIBDRM_LIBS $DLOG_LIBS $LIBUDEV_LIBS"
AC_SUBST(LIBHAL_BACKEND_TBM_DUMB_CFLAGS)
AC_SUBST(LIBHAL_BACKEND_TBM_DUMB_LIBS)
diff --git a/src/tbm_backend_dumb.c b/src/tbm_backend_dumb.c
index 4c78088..c52e985 100644
--- a/src/tbm_backend_dumb.c
+++ b/src/tbm_backend_dumb.c
@@ -628,6 +628,36 @@ tbm_dumb_bufmgr_get_plane_data(hal_tbm_bufmgr *bufmgr,
return HAL_TBM_ERROR_NONE;
}
+static const unsigned short std_res[] = {
+ 600, 640, 720, 768, 800, 854, 864, 900, 960, 1024, 1050, 1080, 1152,
+ 1200, 1280, 1440, 1504, 1536, 1600, 1620, 1800, 1920, 2048, 2100, 2160, 2400, 2560, 2880,
+ 3072, 3456, 4320
+};
+
+static uint8_t tbm_dumb_try_std_res(uint32_t val, uint32_t* width, uint32_t* height) {
+ double sval = sqrt((double)val);
+ uint64_t lval = lround(sval);
+
+ if (sval != lval) {
+ for(uint8_t idy = 0; idy < sizeof(std_res)/sizeof(std_res[0]); idy++) {
+ for(uint8_t idx = 0; idx < sizeof(std_res)/sizeof(std_res[0]); idx++) {
+ unsigned short _x = std_res[idx];
+ unsigned short _y = std_res[idy];
+ if (_x * _y == val) {
+ *width = _x;
+ *height = _y;
+ return 1;
+ }
+ }
+ }
+ } else {
+ *width = lval;
+ *height = lval;
+ return 1;
+ }
+ return 0;
+}
+
static hal_tbm_bo *
tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
hal_tbm_bo_memory_type flags, hal_tbm_error *error)
@@ -648,12 +678,19 @@ tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
dumb_flags = _get_dumb_flag_from_tbm(flags);
- //as we know only size for new bo set height=1 and bpp=8 and in this case
- //width will by equal to size in bytes;
- create_dumb_arg.height = 1;
- create_dumb_arg.bpp = 8;
- create_dumb_arg.width = size;
+ if (size == 4096000) {
+ create_dumb_arg.width = 1280;
+ create_dumb_arg.height = 720;
+ } else {
+ if(!tbm_dumb_try_std_res(size >> 2, &create_dumb_arg.height, &create_dumb_arg.width)) {
+ TBM_BACKEND_INFO("tbm_dumb_try_std_res FAILS: %ld ", size);
+ create_dumb_arg.width = 2048;
+ create_dumb_arg.height = ((uint32_t) size + (create_dumb_arg.width * 4) - 1) / (create_dumb_arg.width * 4);
+ }
+ }
+
create_dumb_arg.flags = dumb_flags;
+ create_dumb_arg.size = size;
if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb_arg)) {
TBM_BACKEND_ERR("fail to DRM_IOCTL_MODE_CREATE_DUMB flag:%x size:%d",
create_dumb_arg.flags, (unsigned int)size);