hardcode sandbox/mmajewski2/hardcode
authorMateusz Majewski <m.majewski2@samsung.com>
Fri, 9 Feb 2024 12:48:39 +0000 (13:48 +0100)
committerMateusz Majewski <m.majewski2@samsung.com>
Fri, 9 Feb 2024 12:48:39 +0000 (13:48 +0100)
src/tbm_backend_dumb.c

index 0edb5dca78ec297dcb5220807b8cc09d4d905572..0f7eea643b211e08489ff1aa8e283735f758bf06 100644 (file)
@@ -678,6 +678,43 @@ tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
 
        dumb_flags = _get_dumb_flag_from_tbm(flags);
 
+       const struct {
+               int w;
+               int h;
+       } hardcoded_sizes[] = {
+               // These are the modes that are available.
+               { 640, 480 },
+               { 800, 600 },
+               { 1024, 768 },
+               { 1280, 1024 },
+               { 1280, 768 },
+               { 1280, 960 },
+               { 1360, 768 },
+               { 1400, 1050 },
+               { 1440, 900 },
+               { 1600, 1200 },
+               { 1680, 1050 },
+               { 1792, 1344 },
+               { 1856, 1392 },
+               { 1920, 1080 },
+               { 1920, 1200 },
+               { 1920, 1440 },
+               { 2048, 1152 },
+               { 2560, 1080 },
+               { 3840, 2160 },
+               { 4096, 2160 },
+               { 5120, 2160 },
+
+               // This are some random sizes that Enlightenment creates.
+               { 1, 1 },
+               { 190, 32 },
+               { 245, 137 },
+               { 408, 32 },
+               { 409, 32 },
+               { 1024, 256 },
+       };
+       const int hardcoded_sizes_count = sizeof(hardcoded_sizes) / sizeof(hardcoded_sizes[0]);
+
        //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.bpp = 32; // virtio-gpu refuses to accept bpp=8
@@ -691,6 +728,13 @@ tbm_dumb_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
                create_dumb_arg.height = root;
                create_dumb_arg.width = (words + root - 1) / root;
        }
+       for (int i = 0; i < hardcoded_sizes_count; ++i) {
+               if (hardcoded_sizes[i].w * hardcoded_sizes[i].h * 4 == size) {
+                       create_dumb_arg.height = hardcoded_sizes[i].h;
+                       create_dumb_arg.width = hardcoded_sizes[i].w;
+                       break;
+               }
+       }
 
        create_dumb_arg.flags = dumb_flags;
        if (drmIoctl(bufmgr_data->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb_arg)) {