glamor: return the result of gbm_format_for_depth
This way the caller knows if the conversion failed. While at it, check for width/height at the same time. Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1764>
This commit is contained in:
parent
080fb49eff
commit
87afcc7699
|
@ -520,6 +520,31 @@ glamor_egl_fd_name_from_pixmap(ScreenPtr screen,
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
gbm_format_for_depth(CARD8 depth, uint32_t *format)
|
||||||
|
{
|
||||||
|
switch (depth) {
|
||||||
|
case 15:
|
||||||
|
*format = GBM_FORMAT_ARGB1555;
|
||||||
|
return true;
|
||||||
|
case 16:
|
||||||
|
*format = GBM_FORMAT_RGB565;
|
||||||
|
return true;
|
||||||
|
case 24:
|
||||||
|
*format = GBM_FORMAT_XRGB8888;
|
||||||
|
return true;
|
||||||
|
case 30:
|
||||||
|
*format = GBM_FORMAT_ARGB2101010;
|
||||||
|
return true;
|
||||||
|
case 32:
|
||||||
|
*format = GBM_FORMAT_ARGB8888;
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
ErrorF("unexpected depth: %d\n", depth);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
glamor_back_pixmap_from_fd(PixmapPtr pixmap,
|
glamor_back_pixmap_from_fd(PixmapPtr pixmap,
|
||||||
int fd,
|
int fd,
|
||||||
|
@ -558,25 +583,6 @@ glamor_back_pixmap_from_fd(PixmapPtr pixmap,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
gbm_format_for_depth(CARD8 depth)
|
|
||||||
{
|
|
||||||
switch (depth) {
|
|
||||||
case 15:
|
|
||||||
return GBM_FORMAT_ARGB1555;
|
|
||||||
case 16:
|
|
||||||
return GBM_FORMAT_RGB565;
|
|
||||||
case 24:
|
|
||||||
return GBM_FORMAT_XRGB8888;
|
|
||||||
case 30:
|
|
||||||
return GBM_FORMAT_ARGB2101010;
|
|
||||||
default:
|
|
||||||
ErrorF("unexpected depth: %d\n", depth);
|
|
||||||
case 32:
|
|
||||||
return GBM_FORMAT_ARGB8888;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PixmapPtr
|
PixmapPtr
|
||||||
glamor_pixmap_from_fds(ScreenPtr screen,
|
glamor_pixmap_from_fds(ScreenPtr screen,
|
||||||
CARD8 num_fds, const int *fds,
|
CARD8 num_fds, const int *fds,
|
||||||
|
@ -599,6 +605,10 @@ glamor_pixmap_from_fds(ScreenPtr screen,
|
||||||
struct gbm_import_fd_modifier_data import_data = { 0 };
|
struct gbm_import_fd_modifier_data import_data = { 0 };
|
||||||
struct gbm_bo *bo;
|
struct gbm_bo *bo;
|
||||||
|
|
||||||
|
if (!gbm_format_for_depth(depth, &import_data.format) ||
|
||||||
|
width == 0 || height == 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
import_data.width = width;
|
import_data.width = width;
|
||||||
import_data.height = height;
|
import_data.height = height;
|
||||||
import_data.num_fds = num_fds;
|
import_data.num_fds = num_fds;
|
||||||
|
@ -608,7 +618,6 @@ glamor_pixmap_from_fds(ScreenPtr screen,
|
||||||
import_data.strides[i] = strides[i];
|
import_data.strides[i] = strides[i];
|
||||||
import_data.offsets[i] = offsets[i];
|
import_data.offsets[i] = offsets[i];
|
||||||
}
|
}
|
||||||
import_data.format = gbm_format_for_depth(depth);
|
|
||||||
bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_FD_MODIFIER, &import_data, 0);
|
bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_FD_MODIFIER, &import_data, 0);
|
||||||
if (bo) {
|
if (bo) {
|
||||||
screen->ModifyPixmapHeader(pixmap, width, height, 0, 0, strides[0], NULL);
|
screen->ModifyPixmapHeader(pixmap, width, height, 0, 0, strides[0], NULL);
|
||||||
|
@ -624,6 +633,7 @@ glamor_pixmap_from_fds(ScreenPtr screen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error:
|
||||||
if (ret == FALSE) {
|
if (ret == FALSE) {
|
||||||
screen->DestroyPixmap(pixmap);
|
screen->DestroyPixmap(pixmap);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue