modesetting: fully port drmmode_bo_import to gbm

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
This commit is contained in:
stefan11111
2026-02-06 21:40:14 +02:00
committed by Enrico Weigelt
parent 501b60f1d5
commit 99dc40ff07
4 changed files with 29 additions and 28 deletions

View File

@@ -35,6 +35,10 @@ typedef struct {
#define GBM_BO_USE_FRONT_RENDERING 0
#endif
#ifndef GBM_MAX_PLANES
#define GBM_MAX_PLANES 4
#endif
/**
* Thin wrapper around gbm_bo_{create,map,unmap}
* that creates and maps (if necessary) the "best"
@@ -332,19 +336,19 @@ gbm_back_bo_from_fd(drmmode_ptr drmmode, Bool do_map, int fd_handle, uint32_t pi
/* A bit of a misnomer, this is a dmabuf export */
int
drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
drmmode_bo_import(drmmode_ptr drmmode, struct gbm_bo *bo,
uint32_t *fb_id)
{
uint32_t width = gbm_bo_get_width(bo->gbm);
uint32_t height = gbm_bo_get_height(bo->gbm);
uint32_t width = gbm_bo_get_width(bo);
uint32_t height = gbm_bo_get_height(bo);
#ifdef GBM_BO_WITH_MODIFIERS
modesettingPtr ms = modesettingPTR(drmmode->scrn);
if (bo->gbm && ms->kms_has_modifiers &&
gbm_bo_get_modifier(bo->gbm) != DRM_FORMAT_MOD_INVALID) {
if (bo && ms->kms_has_modifiers &&
gbm_bo_get_modifier(bo) != DRM_FORMAT_MOD_INVALID) {
int num_fds;
num_fds = gbm_bo_get_plane_count(bo->gbm);
num_fds = gbm_bo_get_plane_count(bo);
if (num_fds > 0) {
int i;
uint32_t format;
@@ -353,13 +357,13 @@ drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
uint32_t offsets[GBM_MAX_PLANES] = {0};
uint64_t modifiers[GBM_MAX_PLANES] = {0};
format = gbm_bo_get_format(bo->gbm);
format = gbm_bo_get_format(bo);
format = get_opaque_format(format);
for (i = 0; i < num_fds; i++) {
handles[i] = gbm_bo_get_handle_for_plane(bo->gbm, i).u32;
strides[i] = gbm_bo_get_stride_for_plane(bo->gbm, i);
offsets[i] = gbm_bo_get_offset(bo->gbm, i);
modifiers[i] = gbm_bo_get_modifier(bo->gbm);
handles[i] = gbm_bo_get_handle_for_plane(bo, i).u32;
strides[i] = gbm_bo_get_stride_for_plane(bo, i);
offsets[i] = gbm_bo_get_offset(bo, i);
modifiers[i] = gbm_bo_get_modifier(bo);
}
return drmModeAddFB2WithModifiers(drmmode->fd, width, height,
@@ -371,6 +375,6 @@ drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
#endif
return drmModeAddFB(drmmode->fd, width, height,
drmmode->scrn->depth, drmmode->kbpp,
gbm_bo_get_stride(bo->gbm),
gbm_bo_get_handle(bo->gbm).u32, fb_id);
gbm_bo_get_stride(bo),
gbm_bo_get_handle(bo).u32, fb_id);
}

View File

@@ -34,10 +34,9 @@ gbm_back_bo_from_fd(drmmode_ptr drmmode, Bool do_map,
/* A bit of a misnomer, this is a dmabuf export */
int
drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo,
drmmode_bo_import(drmmode_ptr drmmode, struct gbm_bo *bo,
uint32_t *fb_id);
static inline uint32_t
drmmode_gbm_format_for_depth(int depth)
{

View File

@@ -687,7 +687,7 @@ drmmode_crtc_get_fb_id(xf86CrtcPtr crtc, uint32_t *fb_id, int *x, int *y)
}
if (*fb_id == 0) {
ret = drmmode_bo_import(drmmode, &drmmode->front_bo,
ret = drmmode_bo_import(drmmode, drmmode->front_bo.gbm,
&drmmode->fb_id);
if (ret < 0) {
ErrorF("failed to add fb %d\n", ret);
@@ -2335,11 +2335,12 @@ drmmode_shadow_fb_allocate(xf86CrtcPtr crtc, int width, int height,
return NULL;
}
ret = drmmode_bo_import(drmmode, bo, fb_id);
ret = drmmode_bo_import(drmmode, bo->gbm, fb_id);
if (ret) {
ErrorF("failed to add rotate fb\n");
drmmode_bo_destroy(drmmode, bo);
gbm_bo_destroy(bo->gbm);
memset(bo, 0, sizeof(*bo));
return NULL;
}

View File

@@ -393,7 +393,7 @@ ms_do_pageflip(ScreenPtr screen,
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
modesettingPtr ms = modesettingPTR(scrn);
xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
drmmode_bo new_front_bo;
struct gbm_bo *new_front_bo;
uint32_t flags;
int i;
struct ms_flipdata *flipdata;
@@ -415,10 +415,9 @@ ms_do_pageflip(ScreenPtr screen,
ms->glamor.block_handler(screen);
memset(&new_front_bo,0,sizeof(new_front_bo));
new_front_bo.gbm = ms->glamor.gbm_bo_from_pixmap(screen, new_front);
new_front_bo = ms->glamor.gbm_bo_from_pixmap(screen, new_front);
if (!new_front_bo.gbm) {
if (!new_front_bo) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"%s: Failed to get GBM BO for flip to new front.\n",
log_prefix);
@@ -427,7 +426,7 @@ ms_do_pageflip(ScreenPtr screen,
flipdata = calloc(1, sizeof(struct ms_flipdata));
if (!flipdata) {
drmmode_bo_destroy(&ms->drmmode, &new_front_bo);
gbm_bo_destroy(new_front_bo);
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"%s: Failed to allocate flipdata.\n", log_prefix);
goto error_free_event;
@@ -450,9 +449,7 @@ ms_do_pageflip(ScreenPtr screen,
/* Create a new handle for the back buffer */
flipdata->old_fb_id = ms->drmmode.fb_id;
new_front_bo.width = new_front->drawable.width;
new_front_bo.height = new_front->drawable.height;
if (drmmode_bo_import(&ms->drmmode, &new_front_bo,
if (drmmode_bo_import(&ms->drmmode, new_front_bo,
&ms->drmmode.fb_id)) {
if (!ms->drmmode.flip_bo_import_failed) {
xf86DrvMsg(scrn->scrnIndex, X_WARNING, "%s: Import BO failed: %s\n",
@@ -523,7 +520,7 @@ ms_do_pageflip(ScreenPtr screen,
}
}
drmmode_bo_destroy(&ms->drmmode, &new_front_bo);
gbm_bo_destroy(new_front_bo);
/*
* Do we have more than our local reference,
@@ -548,7 +545,7 @@ error_undo:
}
error_out:
drmmode_bo_destroy(&ms->drmmode, &new_front_bo);
gbm_bo_destroy(new_front_bo);
/* if only the local reference - free the structure,
* else drop the local reference and return */
if (flipdata->flip_count == 1) {