From 480b2353d815540dca310edc8496da1d3f1b3295 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 30 Sep 2012 09:40:46 +0100 Subject: Split 32bpp support into xrgba, xbgr, and common. Should allow for BGR surfaces as well as RGB. --- src/surface/sdl.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/surface/sdl.c') diff --git a/src/surface/sdl.c b/src/surface/sdl.c index 0554e26..48052a8 100644 --- a/src/surface/sdl.c +++ b/src/surface/sdl.c @@ -411,7 +411,8 @@ sdlcopy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox) } -static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format) +static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, + enum nsfb_format_e format) { if (nsfb->surface_priv != NULL) return -1; /* fail if surface already initialised */ @@ -431,6 +432,8 @@ static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_forma static int sdl_initialise(nsfb_t *nsfb) { SDL_Surface *sdl_screen; + SDL_PixelFormat *sdl_fmt; + enum nsfb_format_e fmt; if (nsfb->surface_priv != NULL) return -1; @@ -455,6 +458,32 @@ static int sdl_initialise(nsfb_t *nsfb) return -1; } + /* find out what pixel format we got */ + sdl_fmt = sdl_screen->format; + + switch (sdl_fmt->BitsPerPixel) { + case 32: + if (sdl_fmt->Rshift == 0) + fmt = NSFB_FMT_XBGR8888; + else + fmt = NSFB_FMT_XRGB8888; + break; + + default: + fmt = nsfb->format; + break; + } + + /* If we didn't get what we asked for, reselect plotters */ + if (nsfb->format != fmt) { + nsfb->format = fmt; + + if (sdl_set_geometry(nsfb, nsfb->width, nsfb->height, + nsfb->format) != 0) { + return -1; + } + } + nsfb->surface_priv = sdl_screen; if (nsfb->bpp == 8) { -- cgit v1.2.3