return HAL_TBM_ERROR_NONE;
}
+#define LOG2(x) ((unsigned int)(sizeof(unsigned int) * 8 - 1 - __builtin_clz(x)))
+
+static inline unsigned int dirty_sqrt(unsigned int v)
+{
+ unsigned int log2 = LOG2(v);
+
+ if (log2 < 0)
+ return 0;
+
+ if (log2 == 0)
+ return 1;
+
+ log2 += !!(v & (1 << (log2 - 1)));
+ log2 >>= 1;
+
+ return 1 << log2;
+}
+
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)
//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 = 32; // virtio-gpu refuses to accept bpp=8
- create_dumb_arg.width = (size + 4 - 1) / 4;
+ if (size <= 16384) {
+ create_dumb_arg.height = 1;
+ create_dumb_arg.width = (size + 4 - 1) / 4;
+ } else {
+ unsigned int words = (size + 4 - 1) / 4;
+ unsigned int root = dirty_sqrt(words);
+
+ create_dumb_arg.height = root;
+ create_dumb_arg.width = (words + root - 1) / root;
+ }
+
create_dumb_arg.flags = dumb_flags;
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",