From: Albert H. <he...@us...> - 2006-03-17 22:32:09
|
Update of /cvsroot/gc-linux/libsdl/src/video/gc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12443/src/video/gc Modified Files: SDL_gcevents.c SDL_gcvideo.c SDL_gcvideo.h SDL_gcyuv.c Log Message: Added double buffering and automatic vsync (with near-zero wait). Index: SDL_gcyuv.c =================================================================== RCS file: /cvsroot/gc-linux/libsdl/src/video/gc/SDL_gcyuv.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- SDL_gcyuv.c 23 Jun 2005 18:18:33 -0000 1.1.1.1 +++ SDL_gcyuv.c 17 Mar 2006 22:32:02 -0000 1.2 @@ -3,7 +3,7 @@ Copyright (C) 1997-2004 Sam Lantinga SDL port for the Nintendo GameCube - Copyright (C) 2004-2005 Albert Herranz + Copyright (C) 2004-2006 Albert Herranz Accelerated yuv blitters courtesy of kirin. This library is free software; you can redistribute it and/or @@ -312,7 +312,9 @@ } } - dst = mapped_mem + mapped_offset + + GC_WaitForFlipCompletion(_this); + + dst = page_address[back_page] + page_offset + (dstrect->y * display->pitch) + dstrect->x * 2; height = dstrect->h; /* overlay->h; */ width = dstrect->w * 2; /* overlay->w * 2; */ Index: SDL_gcevents.c =================================================================== RCS file: /cvsroot/gc-linux/libsdl/src/video/gc/SDL_gcevents.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- SDL_gcevents.c 23 Jun 2005 18:18:34 -0000 1.1.1.1 +++ SDL_gcevents.c 17 Mar 2006 22:32:01 -0000 1.2 @@ -25,7 +25,7 @@ sl...@li... */ -#define DEBUG_KEYBOARD 1 +//#define DEBUG_KEYBOARD 1 /* Handle the event stream, converting console events into SDL events */ Index: SDL_gcvideo.c =================================================================== RCS file: /cvsroot/gc-linux/libsdl/src/video/gc/SDL_gcvideo.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SDL_gcvideo.c 23 Jun 2005 19:08:16 -0000 1.2 +++ SDL_gcvideo.c 17 Mar 2006 22:32:02 -0000 1.3 @@ -3,7 +3,7 @@ Copyright (C) 1997-2004 Sam Lantinga SDL port for the Nintendo GameCube - Copyright (C) 2004-2005 Albert Herranz + Copyright (C) 2004-2006 Albert Herranz This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -33,6 +33,7 @@ #include <string.h> #include <fcntl.h> #include <unistd.h> +#include <errno.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <asm/page.h> /* For definition of PAGE_SIZE */ @@ -50,7 +51,7 @@ #ifdef HAVE_OPENGL #include "SDL_gcgl.h" -#endif /* HAVE_OPENGL */ +#endif /* HAVE_OPENGL */ /* Initialization/Query functions */ static int GC_VideoInit(_THIS, SDL_PixelFormat * vformat); @@ -71,19 +72,30 @@ static void GC_InitRGB2YUVTables(void); static void GC_UpdateRects(_THIS, int numrects, SDL_Rect * rects); static void GC_UpdateRectRGB16(_THIS, SDL_Rect * rect, int pitch); -static void GC_UpdateRectRGB24(_THIS, SDL_Rect * rect, int pitch); -static void GC_UpdateRectRGB32(_THIS, SDL_Rect * rect, int pitch); - +void GC_WaitForFlipCompletion(_THIS); #define GC_BLACK 0x00800080 -/* GC driver bootstrap functions */ +/* + * + * Bootstrap functions. + */ + +/* + * + */ static int GC_Available(void) { int console; const char *SDL_fbdev; + /* + * XXX We could check that + * "/sys/devices/platform/gcnfb.0/graphics\:fb0/name" + * exists and contains gcnfb. + */ + SDL_fbdev = getenv("SDL_FBDEV"); if (SDL_fbdev == NULL) { SDL_fbdev = "/dev/fb0"; @@ -95,6 +107,9 @@ return (console >= 0); } +/* + * + */ static void GC_DeleteDevice(_THIS) { if (_this->hidden->buffer) { @@ -103,11 +118,15 @@ } free(_this->hidden); #ifdef HAVE_OPENGL - free(_this->gl_data); /* check for NULL? */ + if (_this->gl_data) + free(_this->gl_data); #endif /* HAVE_OPENGL */ free(_this); } +/* + * + */ static SDL_VideoDevice *GC_CreateDevice(int devindex) { _THIS; @@ -116,31 +135,31 @@ _this = (SDL_VideoDevice *) malloc(sizeof(SDL_VideoDevice)); if (_this) { memset(_this, 0, (sizeof *_this)); - _this->hidden = (struct SDL_PrivateVideoData *) - malloc((sizeof *_this->hidden)); + #ifdef HAVE_OPENGL _this->gl_data = (struct SDL_PrivateGLData *) malloc((sizeof *_this->gl_data)); -#endif /* HAVE_OPENGL */ - } - if ((_this == NULL) || (_this->hidden == NULL) + if (_this->gl_data == NULL) { + SDL_OutOfMemory(); + free(_this); + return 0; + } + memset(_this->gl_data, 0, (sizeof *_this->gl_data)); +#endif /* HAVE_OPENGL */ + + _this->hidden = (struct SDL_PrivateVideoData *) + malloc((sizeof *_this->hidden)); + if (_this->hidden == NULL) { + SDL_OutOfMemory(); #ifdef HAVE_OPENGL - || (_this->gl_data == NULL) -#endif /* HAVE_OPENGL */ - ) { /* mem-leak if only one malloc fails.. */ - SDL_OutOfMemory(); - if (_this) { + free(_this->gl_data); +#endif /* HAVE_OPENGL */ free(_this); + return (0); } - return (0); } memset(_this->hidden, 0, (sizeof *_this->hidden)); -#ifdef HAVE_OPENGL - memset(_this->gl_data, 0, (sizeof *_this->gl_data)); -#endif /* HAVE_OPENGL */ - //wait_vbl = FB_WaitVBL; - //wait_idle = FB_WaitIdle; keyboard_fd = -1; in_graphics_mode = 0; @@ -186,6 +205,15 @@ GC_Available, GC_CreateDevice }; + +/* + * + * Video setup routines. + */ + +/* + * + */ int GC_VideoInit(_THIS, SDL_PixelFormat * vformat) { struct fb_fix_screeninfo finfo; @@ -250,13 +278,6 @@ GC_VideoQuit(_this); return (-1); } -#if 0 - if (vinfo.bits_per_pixel != 16) { - SDL_SetError("XXX Sorry, but I need a 16bpp mode for now..."); - GC_VideoQuit(_this); - return (-1); - } -#endif /* XXX isobel, review */ @@ -288,64 +309,66 @@ return (0); } -#if 0 //defined(GC_DEBUG) -static void print_vinfo(struct fb_var_screeninfo *vinfo) -{ - fprintf(stderr, "Printing vinfo:\n"); - fprintf(stderr, "\txres: %d\n", vinfo->xres); - fprintf(stderr, "\tyres: %d\n", vinfo->yres); - fprintf(stderr, "\txres_virtual: %d\n", vinfo->xres_virtual); - fprintf(stderr, "\tyres_virtual: %d\n", vinfo->yres_virtual); - fprintf(stderr, "\txoffset: %d\n", vinfo->xoffset); - fprintf(stderr, "\tyoffset: %d\n", vinfo->yoffset); - fprintf(stderr, "\tbits_per_pixel: %d\n", vinfo->bits_per_pixel); - fprintf(stderr, "\tgrayscale: %d\n", vinfo->grayscale); - fprintf(stderr, "\tnonstd: %d\n", vinfo->nonstd); - fprintf(stderr, "\tactivate: %d\n", vinfo->activate); - fprintf(stderr, "\theight: %d\n", vinfo->height); - fprintf(stderr, "\twidth: %d\n", vinfo->width); - fprintf(stderr, "\taccel_flags: %d\n", vinfo->accel_flags); - fprintf(stderr, "\tpixclock: %d\n", vinfo->pixclock); - fprintf(stderr, "\tleft_margin: %d\n", vinfo->left_margin); - fprintf(stderr, "\tright_margin: %d\n", vinfo->right_margin); - fprintf(stderr, "\tupper_margin: %d\n", vinfo->upper_margin); - fprintf(stderr, "\tlower_margin: %d\n", vinfo->lower_margin); - fprintf(stderr, "\thsync_len: %d\n", vinfo->hsync_len); - fprintf(stderr, "\tvsync_len: %d\n", vinfo->vsync_len); - fprintf(stderr, "\tsync: %d\n", vinfo->sync); - fprintf(stderr, "\tvmode: %d\n", vinfo->vmode); - fprintf(stderr, "\tred: %d/%d\n", vinfo->red.length, vinfo->red.offset); - fprintf(stderr, "\tgreen: %d/%d\n", vinfo->green.length, - vinfo->green.offset); - fprintf(stderr, "\tblue: %d/%d\n", vinfo->blue.length, - vinfo->blue.offset); - fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length, - vinfo->transp.offset); -} -static void print_finfo(struct fb_fix_screeninfo *finfo) +/* + * + * Note: If we are terminated, this could be called in the middle of + * another SDL video routine -- notably UpdateRects. + */ +static void GC_VideoQuit(_THIS) { - fprintf(stderr, "Printing finfo:\n"); - fprintf(stderr, "\tsmem_start = %p\n", (char *)finfo->smem_start); - fprintf(stderr, "\tsmem_len = %d\n", finfo->smem_len); - fprintf(stderr, "\ttype = %d\n", finfo->type); - fprintf(stderr, "\ttype_aux = %d\n", finfo->type_aux); - fprintf(stderr, "\tvisual = %d\n", finfo->visual); - fprintf(stderr, "\txpanstep = %d\n", finfo->xpanstep); - fprintf(stderr, "\typanstep = %d\n", finfo->ypanstep); - fprintf(stderr, "\tywrapstep = %d\n", finfo->ywrapstep); - fprintf(stderr, "\tline_length = %d\n", finfo->line_length); - fprintf(stderr, "\tmmio_start = %p\n", (char *)finfo->mmio_start); - fprintf(stderr, "\tmmio_len = %d\n", finfo->mmio_len); - fprintf(stderr, "\taccel = %d\n", finfo->accel); + if (_this->hidden->buffer) { + free(_this->hidden->buffer); + _this->hidden->buffer = NULL; + } + if (_this->screen) { + Uint32 *rowp = (Uint32 *) (mapped_mem + page_offset); + int left = + (_this->screen->pitch * _this->screen->h) / sizeof(Uint32); + while (left--) { + *rowp++ = GC_BLACK; + } + if (_this->screen->pixels != NULL) { + /* already freed above */ + _this->screen->pixels = NULL; + } + } + /* Close console and input file descriptors */ + if (console_fd > 0) { + /* Unmap the video framebuffer and I/O registers */ + if (mapped_mem) { + munmap(mapped_mem, mapped_memlen); + mapped_mem = NULL; + } + + /* Restore the original video mode and palette */ + if (GC_InGraphicsMode(_this)) { + //FB_RestorePalette(_this); + ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo); + } + + /* We're all done with the framebuffer */ + close(console_fd); + console_fd = -1; + } + GC_CloseKeyboard(_this); } -#endif + +/* + * + * Video mode handling. + */ + +/* only 640x480 16bpp is currently supported */ const static SDL_Rect RECT_640x480 = { 0, 0, 640, 480 }; const static SDL_Rect *vid_modes[] = { &RECT_640x480, NULL }; +/* + * + */ SDL_Rect **GC_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) { switch (format->BitsPerPixel) { @@ -360,9 +383,11 @@ default: return NULL; } -// return (SDL_Rect **) -1; } +/* + * + */ SDL_Surface *GC_SetVideoMode(_THIS, SDL_Surface * current, int width, int height, int bpp, Uint32 flags) { @@ -373,8 +398,10 @@ Uint32 Gmask; Uint32 Bmask; Uint32 *p, *q; + Uint32 yres; - GC_DPRINTF("Setting %dx%d %dbpp mode\n", width, height, bpp); + GC_DPRINTF("Setting %dx%d %dbpp %smode\n", width, height, bpp, + (flags & SDL_DOUBLEBUF)?"(doublebuf) ":""); /* Set the terminal into graphics mode */ if (GC_EnterGraphicsMode(_this) < 0) { @@ -389,29 +416,22 @@ SDL_SetError("Couldn't get console screen info"); return (NULL); } -#if 0 //defined(GC_DEBUG) - fprintf(stderr, "Printing original vinfo:\n"); - print_vinfo(&vinfo); -#endif + + yres = vinfo.yres; /* hack to center 640x480 resolution on PAL cubes */ if (vinfo.xres == 640 && vinfo.yres == 576) { - mapped_offset = ((576 - 480) / 2) * 640 * ((bpp + 7) / 8); - - p = (Uint32 *)mapped_mem; - q = (Uint32 *)(mapped_mem + mapped_offset); - while (p < q) - *p++ = GC_BLACK; - - q = (Uint32 *)(mapped_mem + mapped_memlen); - p = (Uint32 *)(mapped_mem + mapped_memlen - mapped_offset); - while (p < q) - *p++ = GC_BLACK; - + page_offset = ((576 - 480) / 2) * 640 * ((bpp + 7) / 8); } else { - mapped_offset = 0; + page_offset = 0; } + /* clear all video memory */ + p = (Uint32 *)mapped_mem; + q = (Uint32 *)(mapped_mem + mapped_memlen); + while (p < q) + *p++ = GC_BLACK; + if ((vinfo.xres != width) || (vinfo.yres != height) || (vinfo.bits_per_pixel != bpp)) { vinfo.activate = FB_ACTIVATE_NOW; @@ -419,8 +439,8 @@ vinfo.bits_per_pixel = bpp; vinfo.xres = width; vinfo.xres_virtual = width; - //vinfo.yres = height; - vinfo.yres_virtual = height; + vinfo.yres = height; + vinfo.yres_virtual = 2*height; vinfo.xoffset = 0; vinfo.yoffset = 0; vinfo.red.length = vinfo.red.offset = 0; @@ -428,11 +448,6 @@ vinfo.blue.length = vinfo.blue.offset = 0; vinfo.transp.length = vinfo.transp.offset = 0; -#if 0 //defined(GC_DEBUG) - fprintf(stderr, "Printing wanted vinfo:\n"); - print_vinfo(&vinfo); -#endif - if (ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { SDL_SetError("Couldn't set console screen info"); return (NULL); @@ -441,18 +456,13 @@ int maxheight; /* Figure out how much video memory is available */ - maxheight = height; + maxheight = 2*height; if (vinfo.yres_virtual > maxheight) { vinfo.yres_virtual = maxheight; } } cache_vinfo = vinfo; -#if 0 //defined(GC_DEBUG) - fprintf(stderr, "Printing actual vinfo:\n"); - print_vinfo(&vinfo); -#endif - Rmask = 0; for (i = 0; i < vinfo.red.length; ++i) { Rmask <<= 1; @@ -501,18 +511,21 @@ current->pitch = width * ((bpp + 7) / 8); current->pixels = _this->hidden->buffer; + page_address[0] = mapped_mem; + page_address[1] = mapped_mem + current->pitch * yres; + + back_page = 0; + if (flags & SDL_DOUBLEBUF) { + current->flags |= SDL_DOUBLEBUF; + flip_pending = 1; + } else { + flip_pending = 0; + } + /* Set the update rectangle function */ switch (bpp) { - case 32: - GC_DPRINTF("Using 32bpp blitter (not working)\n"); - _this->hidden->UpdateRect = GC_UpdateRectRGB32; - break; - case 24: - GC_DPRINTF("Using 24bpp blitter (not working)\n"); - _this->hidden->UpdateRect = GC_UpdateRectRGB24; - break; case 16: - GC_DPRINTF("Using new fast 16bpp blitter\n"); + GC_DPRINTF("Using 16bpp blitter\n"); _this->hidden->UpdateRect = GC_UpdateRectRGB16; break; default: @@ -536,32 +549,97 @@ return (current); } -/* We don't actually allow hardware surfaces other than the main one */ + +/* + * + * Hardware surface hooks. + */ + +/* + * + */ static int GC_AllocHWSurface(_THIS, SDL_Surface * surface) { + /* We don't actually allow hardware surfaces other than the main one */ return (-1); } + +/* + * + */ static void GC_FreeHWSurface(_THIS, SDL_Surface * surface) { return; } -/* We need to wait for vertical retrace on page flipped displays */ +/* + * + */ static int GC_LockHWSurface(_THIS, SDL_Surface * surface) { return (0); } +/* + * + */ static void GC_UnlockHWSurface(_THIS, SDL_Surface * surface) { return; } +/* + * + */ static int GC_FlipHWSurface(_THIS, SDL_Surface * surface) { + if (flip_pending) { + /* SDL_UpdateRect was not called */ + SDL_UpdateRect(_this->screen, 0, 0, 0, 0); + } + + /* flip video page as soon as possible */ + ioctl(console_fd, FBIOFLIPHACK, NULL); + flip_pending = 1; + return (0); } +/* + * + */ +void GC_WaitForFlipCompletion(_THIS) +{ + int visible_page; + int result; + + if (flip_pending) { + flip_pending = 0; + back_page ^= 1; + visible_page = back_page; + while (visible_page == back_page) { + /* wait until back_page is not visible */ + result = ioctl(console_fd, FBIOFLIPHACK, &back_page); + if (result < 0) { + if ((errno == EINTR) || (errno == EAGAIN)) + continue; + return; /* ioctl unsupported ... */ + } + visible_page = result; + } + /* + * At this point the back_page is not visible. We can safely + * write to it without tearing. + */ + } +} + + +/* + * + * Color space handling. + */ + #define RGB2YUV_SHIFT 16 #define RGB2YUV_LUMA 16 #define RGB2YUV_CHROMA 128 @@ -595,6 +673,9 @@ static Uint8 RGB16toU[1 << 16]; static Uint8 RGB16toV[1 << 16]; +/* + * + */ static void GC_InitRGB2YUVTables(void) { unsigned int i; @@ -634,6 +715,9 @@ } } +/* + * + */ static inline Uint32 rgbrgb16toyuy2(Uint16 rgb1, Uint16 rgb2) { register int Y1, Cb, Y2, Cr; @@ -665,6 +749,60 @@ | (((char)Cr) << 0); } +/* + * + */ +static int GC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) +{ + int i; + __u16 r[256]; + __u16 g[256]; + __u16 b[256]; + struct fb_cmap cmap; + + /* Set up the colormap */ + for (i = 0; i < ncolors; i++) { + r[i] = colors[i].r << 8; + g[i] = colors[i].g << 8; + b[i] = colors[i].b << 8; + } + cmap.start = firstcolor; + cmap.len = ncolors; + cmap.red = r; + cmap.green = g; + cmap.blue = b; + cmap.transp = NULL; + + if ((ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) || + !(_this->screen->flags & SDL_HWPALETTE)) { + colors = _this->screen->format->palette->colors; + ncolors = _this->screen->format->palette->ncolors; + cmap.start = 0; + cmap.len = ncolors; + memset(r, 0, sizeof(r)); + memset(g, 0, sizeof(g)); + memset(b, 0, sizeof(b)); + if (ioctl(console_fd, FBIOGETCMAP, &cmap) == 0) { + for (i = ncolors - 1; i >= 0; --i) { + colors[i].r = (r[i] >> 8); + colors[i].g = (g[i] >> 8); + colors[i].b = (b[i] >> 8); + } + } + return (0); + } + return (1); +} + + +/* + * + * Blitters. + */ + +/* + * + */ static void GC_UpdateRectRGB16(_THIS, SDL_Rect * rect, int pitch) { int width, height, left, i, mod, mod32; @@ -681,7 +819,8 @@ /* in bytes, src and dest are 16bpp */ src = _this->hidden->buffer + (rect->y * pitch) + left * 2; - dst = mapped_mem + mapped_offset + (rect->y * pitch) + left * 2; + dst = page_address[back_page] + page_offset + + (rect->y * pitch) + left * 2; mod = pitch - width * 2; src32 = (Uint32 *) src; @@ -696,96 +835,14 @@ *dst32++ = rgbrgb16toyuy2(rgb[0], rgb[1]); src32++; } - dst32 += mod32; src32 += mod32; + dst32 += mod32; } } -static inline unsigned long rgbrgbtoyuy2(register int r1, register int g1, - register int b1, register int r2, - register int g2, register int b2) -{ - register int r, g, b; - register int Y1, Cb, Y2, Cr; - - r = (r1 + r2) >> 1; - g = (g1 + g2) >> 1; - b = (b1 + b2) >> 1; - - Y1 = clamp(16, 235, (r_Yr[r1] + g_Yg_[g1] + b_Yb[b1]) >> RGB2YUV_SHIFT); - Y2 = clamp(16, 235, (r_Yr[r2] + g_Yg_[g2] + b_Yb[b2]) >> RGB2YUV_SHIFT); - Cb = (r_Ur[r] + g_Ug_[g] + b_Ub[b]) >> RGB2YUV_SHIFT; - Cr = (r_Vr[r] + g_Vg_[g] + b_Vb[b]) >> RGB2YUV_SHIFT; - - return (((((char)Y1) << 24) | (((char)Cb) << 16) | (((char)Y2) << 8) - | (((char)Cr) << 0))); -} - -static void GC_UpdateRectRGB24(_THIS, SDL_Rect * rect, int pitch) -{ - int width, height, left, i, srcmod, dstmod; - Uint8 *src, *dst; - - /* XXX case width < 2 needs special treatment */ - - /* in pixel units */ - left = rect->x & ~1; /* 2 pixel align */ - width = (rect->w + 1) & ~1; /* 2 pixel align in excess */ - height = rect->h; - - /* in bytes, src is 24bpp (3 bytes) and dst is 16bpp */ - src = _this->hidden->buffer + (rect->y * pitch) + left * 3; - srcmod = pitch - width * 3; - dst = mapped_mem + mapped_offset + (rect->y * pitch) + left * 2; - dstmod = _this->screen->w * 2 - width * 2; - - while (height--) { - i = width / 2; - while (i--) { - *(unsigned long *)dst = - rgbrgbtoyuy2(src[0], src[1], src[2], src[3], src[4], - src[5]); - dst += 4; - src += 6; - } - dst += dstmod; - src += srcmod; - } -} - -static void GC_UpdateRectRGB32(_THIS, SDL_Rect * rect, int pitch) -{ - int width, height, left, i, srcmod, dstmod; - Uint8 *src, *dst; - -/* DOESN'T WORK, WRONG COLORS */ - - /* XXX case width < 2 needs special treatment */ - - /* in pixel units */ - left = rect->x & ~1; /* 2 pixel align */ - width = (rect->w + 1) & ~1; /* 2 pixel align in excess */ - height = rect->h; - - /* in bytes, src is 32bpp (4 bytes) and dst is 16bpp */ - src = _this->hidden->buffer + (rect->y * pitch) + left * 4; - srcmod = pitch - width * 4; - dst = mapped_mem + mapped_offset + (rect->y * pitch) + left * 2; - dstmod = _this->screen->w * 2 - width * 2; - - while (height--) { - i = width / 2; - while (i--) { - *(Uint32 *) dst = rgbrgbtoyuy2(src[2], src[1], src[0], - src[6], src[5], src[4]); - dst += 4; - src += 8; - } - dst += dstmod; - src += srcmod; - } -} - +/* + * + */ static void GC_UpdateRects(_THIS, int numrects, SDL_Rect * rects) { SDL_Surface *screen; @@ -797,6 +854,7 @@ pitch = screen->pitch; /* this is the pitch of the shadow buffer */ if (_this->hidden->UpdateRect) { + GC_WaitForFlipCompletion(_this); while (numrects--) { if (rects->w <= 0 || rects->h <= 0) continue; @@ -806,94 +864,3 @@ } } -#if 0 -static int GC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) -{ - /* do nothing of note. */ - return (1); -} -#endif - -static int GC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) -{ - int i; - __u16 r[256]; - __u16 g[256]; - __u16 b[256]; - struct fb_cmap cmap; - - /* Set up the colormap */ - for (i = 0; i < ncolors; i++) { - r[i] = colors[i].r << 8; - g[i] = colors[i].g << 8; - b[i] = colors[i].b << 8; - } - cmap.start = firstcolor; - cmap.len = ncolors; - cmap.red = r; - cmap.green = g; - cmap.blue = b; - cmap.transp = NULL; - - if ((ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) || - !(_this->screen->flags & SDL_HWPALETTE)) { - colors = _this->screen->format->palette->colors; - ncolors = _this->screen->format->palette->ncolors; - cmap.start = 0; - cmap.len = ncolors; - memset(r, 0, sizeof(r)); - memset(g, 0, sizeof(g)); - memset(b, 0, sizeof(b)); - if (ioctl(console_fd, FBIOGETCMAP, &cmap) == 0) { - for (i = ncolors - 1; i >= 0; --i) { - colors[i].r = (r[i] >> 8); - colors[i].g = (g[i] >> 8); - colors[i].b = (b[i] >> 8); - } - } - return (0); - } - return (1); -} - -/* Note: If we are terminated, this could be called in the middle of - another SDL video routine -- notably UpdateRects. -*/ -static void GC_VideoQuit(_THIS) -{ - if (_this->hidden->buffer) { - free(_this->hidden->buffer); - _this->hidden->buffer = NULL; - } - if (_this->screen) { - Uint32 *rowp = (Uint32 *) (mapped_mem + mapped_offset); - int left = - (_this->screen->pitch * _this->screen->h) / sizeof(Uint32); - while (left--) { - *rowp++ = GC_BLACK; - } - if (_this->screen->pixels != NULL) { - /* already freed above */ - _this->screen->pixels = NULL; - } - } - /* Close console and input file descriptors */ - if (console_fd > 0) { - /* Unmap the video framebuffer and I/O registers */ - if (mapped_mem) { - munmap(mapped_mem, mapped_memlen); - mapped_mem = NULL; - } - - /* Restore the original video mode and palette */ - if (GC_InGraphicsMode(_this)) { - //FB_RestorePalette(_this); - ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo); - } - - /* We're all done with the framebuffer */ - close(console_fd); - console_fd = -1; - } - GC_CloseKeyboard(_this); -} Index: SDL_gcvideo.h =================================================================== RCS file: /cvsroot/gc-linux/libsdl/src/video/gc/SDL_gcvideo.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- SDL_gcvideo.h 23 Jun 2005 18:18:34 -0000 1.1.1.1 +++ SDL_gcvideo.h 17 Mar 2006 22:32:02 -0000 1.2 @@ -40,9 +40,14 @@ #include "SDL_sysvideo.h" #include "SDL_mutex.h" +#define FBIOFLIPHACK 0x4623 /* gc-linux */ + + /* Hidden "this" pointer for the video functions */ #define _THIS SDL_VideoDevice *_this +extern void GC_WaitForFlipCompletion(_THIS); + /* Private display data */ struct SDL_PrivateVideoData { @@ -54,62 +59,46 @@ int console_fd; struct fb_var_screeninfo cache_vinfo; struct fb_var_screeninfo saved_vinfo; - //int saved_cmaplen; - //__u16 *saved_cmap; int current_vt; int saved_vt; int keyboard_fd; int in_graphics_mode; - //int saved_kbd_mode; - //struct termios saved_kbd_termios; //int mouse_fd; char *mapped_mem; int mapped_memlen; - int mapped_offset; - //char *mapped_io; - //long mapped_iolen; - //int flip_page; - //char *flip_address[2]; + int flip_pending; + int back_page; + char *page_address[2]; + int page_offset; #define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */ int SDL_nummodes[NUM_MODELISTS]; SDL_Rect **SDL_modelist[NUM_MODELISTS]; - void (*wait_vbl) (_THIS); - void (*wait_idle) (_THIS); +// SDL_mutex *hw_lock; }; /* Old variable names */ #define console_fd (_this->hidden->console_fd) +#define cache_vinfo (_this->hidden->cache_vinfo) +#define saved_vinfo (_this->hidden->saved_vinfo) #define current_vt (_this->hidden->current_vt) #define saved_vt (_this->hidden->saved_vt) #define keyboard_fd (_this->hidden->keyboard_fd) #define in_graphics_mode (_this->hidden->in_graphics_mode) -//#define saved_kbd_mode (_this->hidden->saved_kbd_mode) -//#define saved_kbd_termios (_this->hidden->saved_kbd_termios) //#define mouse_fd (_this->hidden->mouse_fd) -#define cache_vinfo (_this->hidden->cache_vinfo) -#define saved_vinfo (_this->hidden->saved_vinfo) -#define saved_cmaplen (_this->hidden->saved_cmaplen) -#define saved_cmap (_this->hidden->saved_cmap) #define mapped_mem (_this->hidden->mapped_mem) #define mapped_memlen (_this->hidden->mapped_memlen) -#define mapped_offset (_this->hidden->mapped_offset) -#define mapped_io (_this->hidden->mapped_io) -#define mapped_iolen (_this->hidden->mapped_iolen) -#define flip_page (_this->hidden->flip_page) -#define flip_address (_this->hidden->flip_address) +#define flip_pending (_this->hidden->flip_pending) +#define back_page (_this->hidden->back_page) +#define page_address (_this->hidden->page_address) +#define page_offset (_this->hidden->page_offset) #define SDL_nummodes (_this->hidden->SDL_nummodes) #define SDL_modelist (_this->hidden->SDL_modelist) -#define surfaces (_this->hidden->surfaces) -#define surfaces_memtotal (_this->hidden->surfaces_memtotal) -#define surfaces_memleft (_this->hidden->surfaces_memleft) -#define hw_lock (_this->hidden->hw_lock) -#define wait_vbl (_this->hidden->wait_vbl) -#define wait_idle (_this->hidden->wait_idle) +//#define hw_lock (_this->hidden->hw_lock) #endif /* _SDL_gcvideo_h */ |