modesetting: Create a drmmode_bo wrapper; use it for front_bo.

This code is going to be extended to support GBM BOs soon.  This small
abstraction removes a lot of direct dumb_bo access, so we can add that
support in one place, rather than putting conditionals at every
pitch/handle/etc access.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Tested-by: Jason Ekstrand <jason.ekstrand@intel.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Kenneth Graunke 2014-12-09 15:20:44 -08:00
parent c6388964b0
commit 980535757d
3 changed files with 61 additions and 24 deletions

View File

@ -861,7 +861,7 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8; stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8;
*size = stride; *size = stride;
return ((uint8_t *) ms->drmmode.front_bo->ptr + row * stride + offset); return ((uint8_t *) ms->drmmode.front_bo.dumb->ptr + row * stride + offset);
} }
static void static void

View File

@ -55,6 +55,40 @@
#include "glamor.h" #include "glamor.h"
#endif #endif
static int
drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
{
int ret;
if (bo->dumb) {
ret = dumb_bo_destroy(drmmode->fd, bo->dumb);
if (ret == 0)
bo->dumb = NULL;
}
return 0;
}
static uint32_t
drmmode_bo_get_pitch(drmmode_bo *bo)
{
return bo->dumb->pitch;
}
uint32_t
drmmode_bo_get_handle(drmmode_bo *bo)
{
return bo->dumb->handle;
}
static Bool
drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
unsigned width, unsigned height, unsigned bpp)
{
bo->dumb = dumb_bo_create(drmmode->fd, width, height, bpp);
return bo->dumb != NULL;
}
Bool Bool
drmmode_SetSlaveBO(PixmapPtr ppix, drmmode_SetSlaveBO(PixmapPtr ppix,
drmmode_ptr drmmode, int fd_handle, int pitch, int size) drmmode_ptr drmmode, int fd_handle, int pitch, int size)
@ -213,8 +247,9 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
ret = drmModeAddFB(drmmode->fd, ret = drmModeAddFB(drmmode->fd,
pScrn->virtualX, height, pScrn->virtualX, height,
pScrn->depth, pScrn->bitsPerPixel, pScrn->depth, pScrn->bitsPerPixel,
drmmode->front_bo->pitch, drmmode_bo_get_pitch(&drmmode->front_bo),
drmmode->front_bo->handle, &drmmode->fb_id); drmmode_bo_get_handle(&drmmode->front_bo),
&drmmode->fb_id);
if (ret < 0) { if (ret < 0) {
ErrorF("failed to add fb %d\n", ret); ErrorF("failed to add fb %d\n", ret);
return FALSE; return FALSE;
@ -1080,7 +1115,7 @@ drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode)
return TRUE; return TRUE;
if (!glamor_egl_create_textured_screen(screen, if (!glamor_egl_create_textured_screen(screen,
drmmode->front_bo->handle, drmmode_bo_get_handle(&drmmode->front_bo),
scrn->displayWidth * scrn->displayWidth *
scrn->bitsPerPixel / 8)) { scrn->bitsPerPixel / 8)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
@ -1100,7 +1135,7 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
drmmode_crtc_private_ptr drmmode_crtc_private_ptr
drmmode_crtc = xf86_config->crtc[0]->driver_private; drmmode_crtc = xf86_config->crtc[0]->driver_private;
drmmode_ptr drmmode = drmmode_crtc->drmmode; drmmode_ptr drmmode = drmmode_crtc->drmmode;
struct dumb_bo *old_front = NULL; drmmode_bo old_front;
Bool ret; Bool ret;
ScreenPtr screen = xf86ScrnToScreen(scrn); ScreenPtr screen = xf86ScrnToScreen(scrn);
uint32_t old_fb_id; uint32_t old_fb_id;
@ -1122,16 +1157,15 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
old_width = scrn->virtualX; old_width = scrn->virtualX;
old_height = scrn->virtualY; old_height = scrn->virtualY;
old_pitch = drmmode->front_bo->pitch; old_pitch = drmmode_bo_get_pitch(&drmmode->front_bo);
old_fb_id = drmmode->fb_id; old_fb_id = drmmode->fb_id;
old_front = drmmode->front_bo; old_front = drmmode->front_bo;
drmmode->front_bo = if (!drmmode_create_bo(drmmode, &drmmode->front_bo,
dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel); width, height, scrn->bitsPerPixel))
if (!drmmode->front_bo)
goto fail; goto fail;
pitch = drmmode->front_bo->pitch; pitch = drmmode_bo_get_pitch(&drmmode->front_bo);
scrn->virtualX = width; scrn->virtualX = width;
scrn->virtualY = height; scrn->virtualY = height;
@ -1139,7 +1173,8 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth, ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
scrn->bitsPerPixel, pitch, scrn->bitsPerPixel, pitch,
drmmode->front_bo->handle, &drmmode->fb_id); drmmode_bo_get_handle(&drmmode->front_bo),
&drmmode->fb_id);
if (ret) if (ret)
goto fail; goto fail;
@ -1174,14 +1209,13 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
if (old_fb_id) { if (old_fb_id) {
drmModeRmFB(drmmode->fd, old_fb_id); drmModeRmFB(drmmode->fd, old_fb_id);
dumb_bo_destroy(drmmode->fd, old_front); drmmode_bo_destroy(drmmode, &old_front);
} }
return TRUE; return TRUE;
fail: fail:
if (drmmode->front_bo) drmmode_bo_destroy(drmmode, &drmmode->front_bo);
dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
drmmode->front_bo = old_front; drmmode->front_bo = old_front;
scrn->virtualX = old_width; scrn->virtualX = old_width;
scrn->virtualY = old_height; scrn->virtualY = old_height;
@ -1467,10 +1501,9 @@ drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
width = pScrn->virtualX; width = pScrn->virtualX;
height = pScrn->virtualY; height = pScrn->virtualY;
drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp); if (!drmmode_create_bo(drmmode, &drmmode->front_bo, width, height, bpp))
if (!drmmode->front_bo)
return FALSE; return FALSE;
pScrn->displayWidth = drmmode->front_bo->pitch / cpp; pScrn->displayWidth = drmmode_bo_get_pitch(&drmmode->front_bo) / cpp;
width = ms->cursor_width; width = ms->cursor_width;
height = ms->cursor_height; height = ms->cursor_height;
@ -1490,14 +1523,14 @@ drmmode_map_front_bo(drmmode_ptr drmmode)
{ {
int ret; int ret;
if (drmmode->front_bo->ptr) if (drmmode->front_bo.dumb->ptr)
return drmmode->front_bo->ptr; return drmmode->front_bo.dumb->ptr;
ret = dumb_bo_map(drmmode->fd, drmmode->front_bo); ret = dumb_bo_map(drmmode->fd, drmmode->front_bo.dumb);
if (ret) if (ret)
return NULL; return NULL;
return drmmode->front_bo->ptr; return drmmode->front_bo.dumb->ptr;
} }
@ -1544,8 +1577,7 @@ drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
drmmode->fb_id = 0; drmmode->fb_id = 0;
} }
dumb_bo_destroy(drmmode->fd, drmmode->front_bo); drmmode_bo_destroy(drmmode, &drmmode->front_bo);
drmmode->front_bo = NULL;
for (i = 0; i < xf86_config->num_crtc; i++) { for (i = 0; i < xf86_config->num_crtc; i++) {
xf86CrtcPtr crtc = xf86_config->crtc[i]; xf86CrtcPtr crtc = xf86_config->crtc[i];

View File

@ -34,6 +34,10 @@
#include "dumb_bo.h" #include "dumb_bo.h"
typedef struct {
struct dumb_bo *dumb;
} drmmode_bo;
typedef struct { typedef struct {
int fd; int fd;
unsigned fb_id; unsigned fb_id;
@ -47,7 +51,7 @@ typedef struct {
InputHandlerProc uevent_handler; InputHandlerProc uevent_handler;
#endif #endif
drmEventContext event_context; drmEventContext event_context;
struct dumb_bo *front_bo; drmmode_bo front_bo;
Bool sw_cursor; Bool sw_cursor;
Bool glamor; Bool glamor;
@ -123,6 +127,7 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
#define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec)) #define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec))
uint32_t drmmode_bo_get_handle(drmmode_bo *bo);
Bool drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode); Bool drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode);
void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv); void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
Bool drmmode_SetSlaveBO(PixmapPtr ppix, Bool drmmode_SetSlaveBO(PixmapPtr ppix,