get pixel size from fourcc to calculate pixel stride

pull/143/merge
MazTheMan 2023-09-26 11:59:26 -06:00 committed by Andri Yngvason
parent 8ed08d6f33
commit ec885cf23d
3 changed files with 41 additions and 2 deletions

View File

@ -22,3 +22,4 @@
enum wl_shm_format fourcc_to_wl_shm(uint32_t in); enum wl_shm_format fourcc_to_wl_shm(uint32_t in);
uint32_t fourcc_from_wl_shm(enum wl_shm_format in); uint32_t fourcc_from_wl_shm(enum wl_shm_format in);
int pixel_size_from_fourcc(uint32_t fourcc);

View File

@ -91,9 +91,10 @@ struct wv_buffer* wv_buffer_create_shm(int width,
if (!self->wl_buffer) if (!self->wl_buffer)
goto shm_failure; goto shm_failure;
// TODO: Get the pixel size from the format instead of assuming it's 4. int bpp = pixel_size_from_fourcc(fourcc);
assert(bpp > 0);
self->nvnc_fb = nvnc_fb_from_buffer(self->pixels, width, height, fourcc, self->nvnc_fb = nvnc_fb_from_buffer(self->pixels, width, height, fourcc,
stride / 4); stride / bpp);
if (!self->nvnc_fb) { if (!self->nvnc_fb) {
goto nvnc_fb_failure; goto nvnc_fb_failure;
} }

View File

@ -44,3 +44,40 @@ uint32_t fourcc_from_wl_shm(enum wl_shm_format in)
return in; return in;
} }
int pixel_size_from_fourcc(uint32_t fourcc)
{
switch (fourcc & ~DRM_FORMAT_BIG_ENDIAN) {
case DRM_FORMAT_RGBA1010102:
case DRM_FORMAT_RGBX1010102:
case DRM_FORMAT_BGRA1010102:
case DRM_FORMAT_BGRX1010102:
case DRM_FORMAT_ARGB2101010:
case DRM_FORMAT_XRGB2101010:
case DRM_FORMAT_ABGR2101010:
case DRM_FORMAT_XBGR2101010:
case DRM_FORMAT_RGBA8888:
case DRM_FORMAT_RGBX8888:
case DRM_FORMAT_BGRA8888:
case DRM_FORMAT_BGRX8888:
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ABGR8888:
case DRM_FORMAT_XBGR8888:
return 4;
case DRM_FORMAT_BGR888:
case DRM_FORMAT_RGB888:
return 3;
case DRM_FORMAT_RGBA4444:
case DRM_FORMAT_RGBX4444:
case DRM_FORMAT_BGRA4444:
case DRM_FORMAT_BGRX4444:
case DRM_FORMAT_ARGB4444:
case DRM_FORMAT_XRGB4444:
case DRM_FORMAT_ABGR4444:
case DRM_FORMAT_XBGR4444:
return 2;
}
return 0;
}