try to preidct h/w from provided size sandbox/intx82/qemu
authorDaniil Ruban <intx82@gmail.com>
Wed, 29 Nov 2023 11:48:41 +0000 (12:48 +0100)
committerDaniil Ruban <intx82@gmail.com>
Wed, 29 Nov 2023 11:48:41 +0000 (12:48 +0100)
Change-Id: If433aee4ff608897ee9007a662ef2a9150513a3f
Signed-off-by: Daniil Ruban <intx82@gmail.com>
configure.ac
src/tbm_backend_dumb.c

index 59839c5c1f112e1a1da8bb4213ee14557e839bbc..1c6e50a686378cac0ecae53da3f457ba674e359d 100644 (file)
@@ -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)
index 4c78088e46dc546403282b358563bbbdd89c3c80..c52e985ba7dfdef7f757cd886ea9bdb359c089a4 100644 (file)
@@ -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);