Skip to content

Commit 17f4db4

Browse files
committed
modesetting: Implement everything with libgbm alongside dumb_bo
Signed-off-by: stefan11111 <[email protected]>
1 parent f405bd5 commit 17f4db4

File tree

1 file changed

+67
-16
lines changed

1 file changed

+67
-16
lines changed

hw/xfree86/drivers/video/modesetting/drmmode_display.c

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
#define MIN(a,b) ((a) < (b) ? (a) : (b))
6363
#define MAX(a,b) ((a) > (b) ? (a) : (b))
6464

65+
#ifndef GBM_BO_USE_FRONT_RENDERING
66+
#define GBM_BO_USE_FRONT_RENDERING 0
67+
#endif
68+
6569
static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
6670
static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, int height,
6771
int depth, int bitsPerPixel, int devKind,
@@ -1090,7 +1094,7 @@ drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo)
10901094
/* We shouldn't read from gpu memory */
10911095
uint32_t stride;
10921096
void* unused;
1093-
void* map = gbm_bo_map(bo->gbm, 0, 0, bo->width, bo->height, GBM_BO_TRANSFER_WRITE | GBM_BO_TRANSFER_READ, &stride, &unused);
1097+
void* map = gbm_bo_map(bo->gbm, 0, 0, bo->width, bo->height, GBM_BO_TRANSFER_WRITE, &stride, &unused);
10941098
if (map) {
10951099
bo->map = map;
10961100
return bo->map;
@@ -1228,6 +1232,7 @@ drmmode_create_cursor_bo(drmmode_ptr drmmode, drmmode_bo *bo,
12281232
format,
12291233
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
12301234
if (bo->gbm) {
1235+
bo->used_modifiers = FALSE;
12311236
return TRUE;
12321237
}
12331238
}
@@ -1237,6 +1242,35 @@ drmmode_create_cursor_bo(drmmode_ptr drmmode, drmmode_bo *bo,
12371242
return bo->dumb != NULL;
12381243
}
12391244

1245+
/* XXX Do we really need to do this? XXX */
1246+
static Bool
1247+
drmmode_create_bpp_probe_bo(drmmode_ptr drmmode, drmmode_bo *bo,
1248+
unsigned width, unsigned height, unsigned bpp, void **out_gbm_dev)
1249+
{
1250+
*out_gbm_dev = NULL;
1251+
#ifdef GLAMOR_HAS_GBM
1252+
struct gbm_device *gbm_dev = drmmode->gbm;
1253+
if (!gbm_dev) {
1254+
/* There is no way this is set right now, as glamor isn't yet initialized. */
1255+
gbm_dev = gbm_create_device(drmmode->fd);
1256+
*out_gbm_dev = gbm_dev;
1257+
}
1258+
1259+
if (gbm_dev) {
1260+
uint32_t format = drmmode_gbm_format_for_depth(bpp);
1261+
1262+
bo->gbm = gbm_bo_create(gbm_dev, width, height, format,
1263+
GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
1264+
if (bo->gbm) {
1265+
bo->used_modifiers = FALSE;
1266+
return TRUE;
1267+
}
1268+
}
1269+
#endif
1270+
bo->dumb = dumb_bo_create(drmmode->fd, width, height, bpp);
1271+
return bo->dumb != NULL;
1272+
}
1273+
12401274
static Bool
12411275
drmmode_create_front_bo(drmmode_ptr drmmode, drmmode_bo *bo,
12421276
unsigned width, unsigned height, unsigned bpp)
@@ -1245,14 +1279,10 @@ drmmode_create_front_bo(drmmode_ptr drmmode, drmmode_bo *bo,
12451279
bo->height = height;
12461280

12471281
#ifdef GLAMOR_HAS_GBM
1248-
if (drmmode->glamor) {
1249-
uint32_t format = drmmode_gbm_format_for_depth(drmmode->scrn->depth);
1250-
1251-
#ifndef GBM_BO_USE_FRONT_RENDERING
1252-
#define GBM_BO_USE_FRONT_RENDERING 0
1253-
#endif
1282+
uint32_t format = drmmode_gbm_format_for_depth(drmmode->scrn->depth);
12541283

12551284
#ifdef GBM_BO_WITH_MODIFIERS
1285+
if (drmmode->glamor && drmmode->gbm) {
12561286
uint32_t num_modifiers;
12571287
uint64_t *modifiers = NULL;
12581288
num_modifiers = get_modifiers_set(drmmode->scrn, format, &modifiers,
@@ -1274,13 +1304,18 @@ drmmode_create_front_bo(drmmode_ptr drmmode, drmmode_bo *bo,
12741304
return TRUE;
12751305
}
12761306
}
1307+
}
12771308
#endif
12781309

1310+
if (drmmode->gbm) {
1311+
/* We don't need glamor if modifiers aren't used */
12791312
bo->gbm = gbm_bo_create(drmmode->gbm, width, height, format,
12801313
GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT |
12811314
GBM_BO_USE_FRONT_RENDERING);
1282-
bo->used_modifiers = FALSE;
1283-
return bo->gbm != NULL;
1315+
if (bo->gbm) {
1316+
bo->used_modifiers = FALSE;
1317+
return TRUE;
1318+
}
12841319
}
12851320
#endif
12861321

@@ -5029,7 +5064,7 @@ drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth,
50295064
{
50305065
drmModeResPtr mode_res;
50315066
uint64_t value;
5032-
struct dumb_bo *bo;
5067+
drmmode_bo bo = {0};
50335068
uint32_t fb_id;
50345069
int ret;
50355070

@@ -5041,6 +5076,8 @@ drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth,
50415076
return;
50425077
}
50435078

5079+
/* XXX Why do we not trust the above value if it isn't 16 or 8? XXX */
5080+
50445081
*depth = 24;
50455082
mode_res = drmModeGetResources(drmmode->fd);
50465083
if (!mode_res)
@@ -5050,28 +5087,42 @@ drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth,
50505087
mode_res->min_width = 1;
50515088
if (mode_res->min_height == 0)
50525089
mode_res->min_height = 1;
5090+
5091+
/* We don't have to worry about overriding anything, this is not yet set */
5092+
drmmode->kbpp = 32;
5093+
5094+
void* free_gbm_device;
5095+
50535096
/*create a bo */
5054-
bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height,
5055-
32);
5056-
if (!bo) {
5097+
ret = drmmode_create_bpp_probe_bo(drmmode, &bo, mode_res->min_width, mode_res->min_height, 32, &free_gbm_device);
5098+
5099+
if (!ret) {
50575100
*bpp = 24;
50585101
goto out;
50595102
}
50605103

5104+
uint32_t handle = drmmode_bo_get_handle(&bo);
5105+
uint32_t pitch = drmmode_bo_get_pitch(&bo);
5106+
50615107
ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height,
5062-
24, 32, bo->pitch, bo->handle, &fb_id);
5108+
24, 32, pitch, handle, &fb_id);
50635109

50645110
if (ret) {
50655111
*bpp = 24;
5066-
dumb_bo_destroy(drmmode->fd, bo);
5112+
drmmode_bo_destroy(drmmode, &bo);
50675113
goto out;
50685114
}
50695115

50705116
drmModeRmFB(drmmode->fd, fb_id);
50715117
*bpp = 32;
50725118

5073-
dumb_bo_destroy(drmmode->fd, bo);
5119+
drmmode_bo_destroy(drmmode, &bo);
50745120
out:
5121+
#ifdef GLAMOR_HAS_GBM
5122+
if (free_gbm_device) {
5123+
gbm_device_destroy(free_gbm_device);
5124+
}
5125+
#endif
50755126
drmModeFreeResources(mode_res);
50765127
return;
50775128
}

0 commit comments

Comments
 (0)