From 7fd55070fab7610e9c923f7caeaeb5db497d8ba4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 25 Aug 2002 06:21:49 +0000 Subject: [PATCH] Date: Sat, 24 Aug 2002 22:20:01 -0600 From: "Greg Haerr" Subject: Announce: sdl-nanox-patch Sam, I've created an update patch for enhanced Nano-X support with SDL. I've created the patch against SDL-1.2.4. I'd appreciate it if you would apply it to the next SDL version. Enhancements include: 1. Small bugfixes to compile without errors 2. Support for direct client-side framebuffer access with configure option 3. Add dynamic pixel type support for hardware framebuffer; eliminating the need for compile-time configuration option. I've updated the README.NanoX file with the details. This version has been tested with Microwindows v0.89pre9 CVS and SMPEG 0.4.4. I've added multi-threading support to Microwindows to support the multi-threaded SMPEG, and all works fine. To turn on thread safety in Microwindows, use THREADSAFE=Y in the Microwindows config file. Thanks! Regards, Greg Founder, The Microwindows Project http://microwindows.org --- README.NanoX | 48 ++++++++---- configure.in | 19 ++--- include/SDL_syswm.h | 2 +- src/video/nanox/SDL_nxevents.c | 17 +++++ src/video/nanox/SDL_nximage.c | 129 ++++++++++++++++++++++---------- src/video/nanox/SDL_nxmodes_c.h | 2 +- src/video/nanox/SDL_nxvideo.c | 52 ++++--------- src/video/nanox/SDL_nxvideo.h | 8 +- 8 files changed, 169 insertions(+), 108 deletions(-) diff --git a/README.NanoX b/README.NanoX index a9570a970..8418ff332 100644 --- a/README.NanoX +++ b/README.NanoX @@ -1,14 +1,23 @@ ================================================================= - Patch version 0.8 of SDL(Simple DirectMedia Layer) for Nano-X API + Patch version 0.9 of SDL(Simple DirectMedia Layer) for Nano-X API ================================================================= - Author: Hsieh-Fu Tsai, clare@setabox.com + Authors: Hsieh-Fu Tsai, clare@setabox.com + Greg Haerr, greg@censoft.com - There are two patch files in this package. + This patch is against SDL version 1.2.4. + It enhances previous patch 0.8 by providing direct framebuffer + access as well as dynamic hardware pixel type support, not + requiring a compile-time option setting for different framebuffer + modes. + Tested against Microwindows version 0.89pre9. - 1. The first patch file, nanox.patch, is to fix a bug in Nano-X. - This patch is proposed by Gary James (gjames@twcny.rr.com). + Older Microwindows versions + =========================== + If running on a version older than Microwindows 0.89pre9, + the following items might need to be patched in Microwindows. + 1. Patch src/nanox/client.c::GrClose() It fixes the client side GrClose(). In the original version, GrOpen() can only be called once. When the GrOpen() is called at the second time, the program will terminate. In order to prevent @@ -16,6 +25,11 @@ "close(nxSocket)" in GrClose(). If you do not have this problem, you may skip this step. + 2. Patch src/nanox/clientfb.c to return absolute x,y coordinates + when using GrGetWindowFBInfo(). Copy the version 0.89pre9 + of src/nanox/clientfb.c to your system, or configure + using --disable-nanox-direct-fb. + ============= Quick Install ============= @@ -31,18 +45,14 @@ Nitty-gritty ============ - --with-nanox-pixel-type=[rgb/0888/888/565/555/332/pal] - - If the wrong pixel type is used, the program will crash when the - sub-routine updates the screen. This option depends on SCREEN_PIXTYPE - which is defined in Microwin0.89pre7/src/config. SCREEN_PIXTYPE - is used to define the pixel type in Microwindows/Nano-X. - I only test the program when the pixel type is in "rgb" - (Microwin under X11) or "888" (framebuffer in 24-bit). - + --enable-nanox-direct-fb Use direct framebuffer access --enable-nanox-debug Show debug messages --enable-nanox-share-memory Use shared-memory to speed up + When running multi-threaded applications using SDL, such + as SMPEG, set THREADSAFE=Y in Microwindows' config file, + to enable GrXXX() system call critical section support. + ============================================= Some programs can be used to test this patch. ============================================= @@ -52,7 +62,8 @@ 3. http://www.libsdl.org/projects/xflame/ 4. http://www.libsdl.org/projects/optimum/ 5. http://www.gnugeneration.com/software/loop/ - + 6: http://www.lokigames.com/development/smpeg.php3 (SMPEG version 0.4.4) + ========= Todo List ========= @@ -62,6 +73,8 @@ 3. Use OpenGL 4. Gamma correction 5. Hide/Change mouse pointer + 6. Better window movement control with direct fb access + 7. Palette handling in 8bpp could be improved ===================== Supporting Institutes @@ -72,10 +85,13 @@ Department of Computer Science and Information Engineering of National Taiwan University for supporting this porting project. + Century Embedded Technologies (http://embedded.censoft.com) + for this patch. + =================== Contact Information =================== Welcome to give me any suggestion and to report bugs. My e-mail address : clare@setabox.com or niky@cmlab.csie.ntu.edu.tw - + or greg@censoft.com diff --git a/configure.in b/configure.in index 5c5b8b5bf..cefa22915 100644 --- a/configure.in +++ b/configure.in @@ -511,9 +511,9 @@ CheckNANOX() AC_ARG_ENABLE(nanox-share-memory, [ --enable-nanox-share-memory use share memory [default=no]], , enable_nanox_share_memory=no) - - AC_ARG_WITH(nanox_pixel_type, - [ --with-nanox-pixel-type=[rgb/0888/888/565/555/332/pal]]) + AC_ARG_ENABLE(nanox_direct_fb, + [ --enable-nanox-direct-fb use direct framebuffer access [default=no]], + , enable_nanox_direct_fb=no) if test x$enable_video = xyes -a x$enable_video_nanox = xyes; then if test x$enable_nanox_debug = xyes; then @@ -524,16 +524,9 @@ CheckNANOX() CFLAGS="$CFLAGS -DNANOX_SHARE_MEMORY" fi - case "$with_nanox_pixel_type" in - rgb) CFLAGS="$CFLAGS -DNANOX_PIXEL_RGB" ;; - 0888) CFLAGS="$CFLAGS -DNANOX_PIXEL_0888" ;; - 888) CFLAGS="$CFLAGS -DNANOX_PIXEL_888" ;; - 565) CFLAGS="$CFLAGS -DNANOX_PIXEL_565" ;; - 555) CFLAGS="$CFLAGS -DNANOX_PIXEL_555" ;; - 332) CFLAGS="$CFLAGS -DNANOX_PIXEL_332" ;; - pal) CFLAGS="$CFLAGS -DNANOX_PIXEL_PAL" ;; - *) AC_MSG_ERROR([Invalid nanox_pixel_type]);; - esac + if test x$enable_nanox_direct_fb = xyes; then + CFLAGS="$CFLAGS -DENABLE_NANOX_DIRECT_FB" + fi CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_NANOX" SYSTEM_LIBS="$SYSTEM_LIBS -lnano-X" diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index a0cb08a81..805b28f71 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -50,7 +50,7 @@ typedef struct SDL_SysWMinfo SDL_SysWMinfo; /* This is the structure for custom window manager events */ #if (defined(unix) || defined(__unix__) || defined(_AIX) || defined(__OpenBSD__)) && \ - (!defined(DISABLE_X11) && !defined(__CYGWIN32__)) + (!defined(DISABLE_X11) && !defined(__CYGWIN32__) && !defined(ENABLE_NANOX)) /* AIX is unix, of course, but the native compiler CSet doesn't define unix */ #include #include diff --git a/src/video/nanox/SDL_nxevents.c b/src/video/nanox/SDL_nxevents.c index 716b034a3..033c6683c 100644 --- a/src/video/nanox/SDL_nxevents.c +++ b/src/video/nanox/SDL_nxevents.c @@ -2,6 +2,7 @@ SDL - Simple DirectMedia Layer Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga Copyright (C) 2001 Hsieh-Fu Tsai + Copyright (C) 2002 Greg Haerr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -345,6 +346,22 @@ void NX_PumpEvents (_THIS) SDL_PrivateResize (event.update.width, event.update.height) ; break ; } + + case GR_UPDATE_MOVE : + case GR_UPDATE_REPARENT : + { + Dprintf ("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n") ; +#ifdef ENABLE_NANOX_DIRECT_FB + if (Clientfb) { + /* Get current window position and fb pointer*/ + if (currently_fullscreen) + GrGetWindowFBInfo(FSwindow, &fbinfo); + else + GrGetWindowFBInfo(SDL_Window, &fbinfo); + } +#endif + break ; + } default : Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ; diff --git a/src/video/nanox/SDL_nximage.c b/src/video/nanox/SDL_nximage.c index 05eb69998..5847bf46a 100644 --- a/src/video/nanox/SDL_nximage.c +++ b/src/video/nanox/SDL_nximage.c @@ -2,6 +2,7 @@ SDL - Simple DirectMedia Layer Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga Copyright (C) 2001 Hsieh-Fu Tsai + Copyright (C) 2002 Greg Haerr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -32,12 +33,13 @@ void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) { - int i, j, xinc, yinc, destinc ; + int i, j, xinc, yinc, destinc, rowinc ; int x, y, w, h ; unsigned char * src = NULL, * dest = NULL ; - - Dprintf ("enter NX_NormalUpdate\n") ; + Dprintf ("enter NX_NormalUpdate\n") ; + + /* These are the values for the incoming image */ xinc = this -> screen -> format -> BytesPerPixel ; yinc = this -> screen -> pitch ; @@ -45,28 +47,36 @@ void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) x = rects [i].x, y = rects [i].y ; w = rects [i].w, h = rects [i].h ; src = SDL_Image + y * yinc + x * xinc ; - dest = Image_buff ; - destinc = w * xinc ; +#ifdef ENABLE_NANOX_DIRECT_FB + if (Clientfb) { + if (currently_fullscreen) + dest = fbinfo.winpixels + (((y+OffsetY) * fbinfo.pitch) + + ((x+OffsetX) * fbinfo.bytespp)); + else + dest = fbinfo.winpixels + ((y * fbinfo.pitch) + (x * fbinfo.bytespp)); + destinc = fbinfo.pitch; + } else { +#endif + dest = Image_buff ; + destinc = w * xinc ; +#ifdef ENABLE_NANOX_DIRECT_FB + } +#endif + rowinc = w * xinc; // apply GammaRamp table -#if (defined (NANOX_PIXEL_RGB) || defined (NANOX_PIXEL_0888) || \ - defined (NANOX_PIXEL_888)) - if (GammaRamp_R && GammaRamp_G && GammaRamp_B) { + if ((pixel_type == MWPF_TRUECOLOR0888 || pixel_type == MWPF_TRUECOLOR888) + && GammaRamp_R && GammaRamp_G && GammaRamp_B) { Uint8 * ptr ; int k ; for (j = h; j > 0; -- j, src += yinc) { ptr = src - 1 ; for (k = w; k > 0; -- k) { -#ifdef NANOX_PIXEL_RGB - ptr += 2 ; -#endif -#ifdef NANOX_PIXEL_0888 - ptr += 2 ; -#endif -#ifdef NANOX_PIXEL_888 - ++ ptr ; -#endif + if (pixel_type == MWPF_TRUECOLOR0888) + ptr += 2 ; + else + ++ ptr ; (* ptr) = GammaRamp_B [(* ptr)] ; ++ ptr ; (* ptr) = GammaRamp_G [(* ptr)] ; @@ -76,19 +86,19 @@ void NX_NormalUpdate (_THIS, int numrects, SDL_Rect * rects) } src = SDL_Image + y * yinc + x * xinc ; } -#endif // apply Gamma table - - for (j = h; j > 0; -- j, src += yinc, dest += destinc) { - memcpy (dest, src, destinc) ; - } - if (currently_fullscreen) { - GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, - pixel_type) ; - } else { - GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ; - } + for (j = h; j > 0; -- j, src += yinc, dest += destinc) + memcpy (dest, src, rowinc) ; + if (!Clientfb) { + if (currently_fullscreen) { + GrArea (FSwindow, SDL_GC, x + OffsetX, y + OffsetY, w, h, Image_buff, + pixel_type) ; + } else { + GrArea (SDL_Window, SDL_GC, x, y, w, h, Image_buff, pixel_type) ; + } + } } + GrFlush(); Dprintf ("leave NX_NormalUpdate\n") ; } @@ -100,12 +110,15 @@ int NX_SetupImage (_THIS, SDL_Surface * screen) Dprintf ("enter NX_SetupImage\n") ; screen -> pixels = (void *) malloc (size) ; - Image_buff = (unsigned char *) malloc (size) ; - if (screen -> pixels == NULL || Image_buff == NULL) { - free (screen -> pixels) ; - free (Image_buff) ; - SDL_OutOfMemory () ; - return -1 ; + + if (!Clientfb) { + Image_buff = (unsigned char *) malloc (size) ; + if (screen -> pixels == NULL || Image_buff == NULL) { + free (screen -> pixels) ; + free (Image_buff) ; + SDL_OutOfMemory () ; + return -1 ; + } } SDL_Image = (unsigned char *) screen -> pixels ; @@ -140,7 +153,16 @@ int NX_ResizeImage (_THIS, SDL_Surface * screen, Uint32 flags) GrGetScreenInfo (& si) ; OffsetX = (si.cols - screen -> w) / 2 ; OffsetY = (si.rows - screen -> h) / 2 ; - + +#ifdef ENABLE_NANOX_DIRECT_FB + if (Clientfb) { + /* Get current window position and fb pointer*/ + if (currently_fullscreen) + GrGetWindowFBInfo(FSwindow, &fbinfo); + else + GrGetWindowFBInfo(SDL_Window, &fbinfo); + } +#endif Dprintf ("leave NX_ResizeImage\n") ; return retval ; } @@ -154,13 +176,40 @@ void NX_RefreshDisplay (_THIS) return; } - if (currently_fullscreen) { - GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, - this -> screen -> h, SDL_Image, pixel_type) ; +#ifdef ENABLE_NANOX_DIRECT_FB + if (Clientfb) { + int j; + char *src, *dest = NULL; + int xinc, yinc, rowinc; + + GrGetWindowFBInfo(SDL_Window, &fbinfo); + + xinc = this -> screen -> format -> BytesPerPixel ; + yinc = this -> screen -> pitch ; + + src = SDL_Image; + if (currently_fullscreen) + dest = fbinfo.winpixels + ((OffsetY * fbinfo.pitch) + + (OffsetX * fbinfo.bytespp)); + else + dest = fbinfo.winpixels; + rowinc = xinc * this -> screen -> w; + + for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch) + memcpy (dest, src, rowinc) ; } else { - GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, - this -> screen -> h, SDL_Image, pixel_type) ; +#endif + if (currently_fullscreen) { + GrArea (FSwindow, SDL_GC, OffsetX, OffsetY, this -> screen -> w, + this -> screen -> h, SDL_Image, pixel_type) ; + } else { + GrArea (SDL_Window, SDL_GC, 0, 0, this -> screen -> w, + this -> screen -> h, SDL_Image, pixel_type) ; + } +#ifdef ENABLE_NANOX_DIRECT_FB } +#endif + GrFlush(); Dprintf ("leave NX_RefreshDisplay\n") ; } diff --git a/src/video/nanox/SDL_nxmodes_c.h b/src/video/nanox/SDL_nxmodes_c.h index 73f96626f..8281faab6 100644 --- a/src/video/nanox/SDL_nxmodes_c.h +++ b/src/video/nanox/SDL_nxmodes_c.h @@ -25,7 +25,7 @@ */ #include "SDL_nxvideo.h" -#include +#include extern SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) ; extern void NX_FreeVideoModes (_THIS) ; diff --git a/src/video/nanox/SDL_nxvideo.c b/src/video/nanox/SDL_nxvideo.c index b090c95c8..4f2a21ece 100644 --- a/src/video/nanox/SDL_nxvideo.c +++ b/src/video/nanox/SDL_nxvideo.c @@ -2,6 +2,7 @@ SDL - Simple DirectMedia Layer Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga Copyright (C) 2001 Hsieh-Fu Tsai + Copyright (C) 2002 Greg Haerr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -222,42 +223,10 @@ int NX_VideoInit (_THIS, SDL_PixelFormat * vformat) SDL_modelist [1] = NULL ; } -#ifdef NANOX_PIXEL_RGB - pixel_type = MWPF_RGB ; - SDL_Visual.red_mask = 0x000000FF ; - SDL_Visual.green_mask = 0x0000FF00 ; - SDL_Visual.blue_mask = 0x00FF0000 ; -#endif -#ifdef NANOX_PIXEL_0888 - pixel_type = MWPF_TRUECOLOR0888 ; - SDL_Visual.red_mask = 0x00FF0000 ; - SDL_Visual.green_mask = 0x0000FF00 ; - SDL_Visual.blue_mask = 0x000000FF ; -#endif -#ifdef NANOX_PIXEL_888 - pixel_type = MWPF_TRUECOLOR888 ; - SDL_Visual.red_mask = 0xFF0000 ; - SDL_Visual.green_mask = 0x00FF00 ; - SDL_Visual.blue_mask = 0x0000FF ; -#endif -#ifdef NANOX_PIXEL_565 - pixel_type = MWPF_TRUECOLOR565 ; - SDL_Visual.red_mask = 0xF800 ; - SDL_Visual.green_mask = 0x07E0 ; - SDL_Visual.blue_mask = 0x001F ; -#endif -#ifdef NANOX_PIXEL_555 - pixel_type = MWPF_TRUECOLOR555 ; - SDL_Visual.red_mask = 0x7C00 ; - SDL_Visual.green_mask = 0x03E0 ; - SDL_Visual.blue_mask = 0x001F ; -#endif -#ifdef NANOX_PIXEL_332 - pixel_type = MWPF_TRUECOLOR332 ; -#endif -#ifdef NANOX_PIXEL_PAL - pixel_type = MWPF_PALETTE ; -#endif + pixel_type = si.pixtype; + SDL_Visual.red_mask = si.rmask; + SDL_Visual.green_mask = si.gmask; + SDL_Visual.blue_mask = si.bmask; vformat -> BitsPerPixel = SDL_Visual.bpp ; if (vformat -> BitsPerPixel > 8) { @@ -290,6 +259,11 @@ void NX_VideoQuit (_THIS) free (GammaRamp_R) ; free (GammaRamp_G) ; free (GammaRamp_B) ; + +#ifdef ENABLE_NANOX_DIRECT_FB + if (Clientfb) + GrCloseClientFramebuffer(); +#endif GrClose () ; Dprintf ("leave NX_VideoQuit\n") ; @@ -373,6 +347,12 @@ static int NX_CreateWindow (_THIS, SDL_Surface * screen, } } +#ifdef ENABLE_NANOX_DIRECT_FB + /* attempt allocating the client side framebuffer */ + Clientfb = GrOpenClientFramebuffer(); + /* NULL return will default to using GrArea()*/ +#endif + Dprintf ("leave NX_CreateWindow\n") ; return 0 ; } diff --git a/src/video/nanox/SDL_nxvideo.h b/src/video/nanox/SDL_nxvideo.h index b0675c95f..2912ef261 100644 --- a/src/video/nanox/SDL_nxvideo.h +++ b/src/video/nanox/SDL_nxvideo.h @@ -55,7 +55,8 @@ struct SDL_PrivateVideoData { char * SDL_windowid ; GR_GC_ID GC ; unsigned char * Image ; - unsigned char * Image_buff ; + unsigned char * Image_buff ; /* for GrArea*/ + unsigned char * Clientfb; /* for DirectFB*/ nx_sdl_visual_t SDL_Visual ; // The current list of available video modes SDL_Rect ** modelist ; @@ -66,6 +67,9 @@ struct SDL_PrivateVideoData { Uint16 * GammaRamp_R, * GammaRamp_G, * GammaRamp_B ; // for GrArea, r_mask, g_mask, b_mask int pixel_type ; +#ifdef ENABLE_NANOX_DIRECT_FB + GR_WINDOW_FB_INFO fbinfo; +#endif } ; #define SDL_Window (this -> hidden -> SDL_Window) @@ -74,6 +78,7 @@ struct SDL_PrivateVideoData { #define SDL_GC (this -> hidden -> GC) #define SDL_Image (this -> hidden -> Image) #define Image_buff (this -> hidden -> Image_buff) +#define Clientfb (this -> hidden -> Clientfb) #define SDL_Visual (this -> hidden -> SDL_Visual) #define SDL_modelist (this -> hidden -> modelist) #define currently_fullscreen (this -> hidden -> currently_fullscreen) @@ -83,6 +88,7 @@ struct SDL_PrivateVideoData { #define GammaRamp_G (this -> hidden -> GammaRamp_G) #define GammaRamp_B (this -> hidden -> GammaRamp_B) #define pixel_type (this -> hidden -> pixel_type) +#define fbinfo (this -> hidden -> fbinfo) #define CI_SIZE 256 // color index size