modesetting: attempt to work out if we want 24 or 32bpp

the cirrus driver presents certain challenges, and this is a
workaround, until we can possibly agree some sane interface
for exposing this information.

Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Dave Airlie 2012-05-01 17:12:29 +01:00
parent 610f532e6a
commit d063f64b5c
3 changed files with 68 additions and 7 deletions

View File

@ -59,10 +59,6 @@
#include "driver.h"
#ifndef DRM_CAP_DUMB_PREFER_SHADOW
#define DRM_CAP_DUMB_PREFER_SHADOW 4
#endif
static void AdjustFrame(int scrnIndex, int x, int y, int flags);
static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
static Bool EnterVT(int scrnIndex, int flags);
@ -397,6 +393,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
Bool prefer_shadow = TRUE;
uint64_t value = 0;
int ret;
int bppflags;
int defaultdepth, defaultbpp;
if (pScrn->numEntities != 1)
return FALSE;
@ -459,9 +457,16 @@ PreInit(ScrnInfoPtr pScrn, int flags)
if (ms->fd < 0)
return FALSE;
ms->drmmode.fd = ms->fd;
drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
if (defaultdepth == 24 && defaultbpp == 24)
bppflags = Support24bppFb;
else
bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
if (!xf86SetDepthBpp
(pScrn, 0, 0, 0,
PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
(pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags))
return FALSE;
switch (pScrn->depth) {
@ -501,7 +506,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
ms->drmmode.fd = ms->fd;
if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
goto fail;

View File

@ -1355,3 +1355,50 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
}
}
/* ugly workaround to see if we can create 32bpp */
void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, int *bpp)
{
drmModeResPtr mode_res;
uint64_t value;
struct dumb_bo *bo;
uint32_t fb_id;
int ret;
/* 16 is fine */
ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value);
if (!ret && (value == 16 || value == 8)) {
*depth = value;
*bpp = value;
return;
}
*depth = 24;
mode_res = drmModeGetResources(drmmode->fd);
if (!mode_res)
return;
/*create a bo */
bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32);
if (!bo) {
*bpp = 24;
goto out;
}
ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height,
24, 32, bo->pitch, bo->handle, &fb_id);
if (ret) {
*bpp = 24;
dumb_bo_destroy(drmmode->fd, bo);
goto out;
}
drmModeRmFB(drmmode->fd, fb_id);
*bpp = 32;
dumb_bo_destroy(drmmode->fd, bo);
out:
drmModeFreeResources(mode_res);
return;
}

View File

@ -103,4 +103,14 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
void *drmmode_map_front_bo(drmmode_ptr drmmode);
Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp);
#ifndef DRM_CAP_DUMB_PREFERRED_DEPTH
#define DRM_CAP_DUMB_PREFERRED_DEPTH 3
#endif
#ifndef DRM_CAP_DUMB_PREFER_SHADOW
#define DRM_CAP_DUMB_PREFER_SHADOW 4
#endif
#endif