Date: Sat, 24 Aug 2002 22:20:01 -0600
authorSam Lantinga <slouken@libsdl.org>
Sun, 25 Aug 2002 06:21:49 +0000
changeset 471 26dafefeebb2
parent 470 877b992f2d0c
child 472 34fb7043b18b
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
configure.in
include/SDL_syswm.h
src/video/nanox/SDL_nxevents.c
src/video/nanox/SDL_nximage.c
src/video/nanox/SDL_nxmodes_c.h
src/video/nanox/SDL_nxvideo.c
src/video/nanox/SDL_nxvideo.h
--- a/README.NanoX	Sun Aug 25 02:05:24 2002 +0000
+++ b/README.NanoX	Sun Aug 25 06:21:49 2002 +0000
@@ -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
-
-  There are two patch files in this package. 
+  Authors: Hsieh-Fu Tsai, clare@setabox.com
+           Greg Haerr, greg@censoft.com
 
-  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).
+  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.
 
+  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
--- a/configure.in	Sun Aug 25 02:05:24 2002 +0000
+++ b/configure.in	Sun Aug 25 06:21:49 2002 +0000
@@ -511,9 +511,9 @@
     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 @@
             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"
--- a/include/SDL_syswm.h	Sun Aug 25 02:05:24 2002 +0000
+++ b/include/SDL_syswm.h	Sun Aug 25 06:21:49 2002 +0000
@@ -50,7 +50,7 @@
 
 /* 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 <X11/Xlib.h>
 #include <X11/Xatom.h>
--- a/src/video/nanox/SDL_nxevents.c	Sun Aug 25 02:05:24 2002 +0000
+++ b/src/video/nanox/SDL_nxevents.c	Sun Aug 25 06:21:49 2002 +0000
@@ -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 <greg@censoft.com>
 
     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 @@
                         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") ;
--- a/src/video/nanox/SDL_nximage.c	Sun Aug 25 02:05:24 2002 +0000
+++ b/src/video/nanox/SDL_nximage.c	Sun Aug 25 06:21:49 2002 +0000
@@ -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 <greg@censoft.com>
 
     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") ;
-
+    
+    /* These are the values for the incoming image */
     xinc = this -> screen -> format -> BytesPerPixel ;
     yinc = this -> screen -> pitch ;
         
@@ -45,28 +47,36 @@
         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 @@
             }
             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 @@
     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 @@
     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 @@
         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") ;
 }
--- a/src/video/nanox/SDL_nxmodes_c.h	Sun Aug 25 02:05:24 2002 +0000
+++ b/src/video/nanox/SDL_nxmodes_c.h	Sun Aug 25 06:21:49 2002 +0000
@@ -25,7 +25,7 @@
 */
 
 #include "SDL_nxvideo.h"
-#include <SDL/SDL.h>
+#include <SDL.h>
 
 extern SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) ;
 extern void NX_FreeVideoModes (_THIS) ;
--- a/src/video/nanox/SDL_nxvideo.c	Sun Aug 25 02:05:24 2002 +0000
+++ b/src/video/nanox/SDL_nxvideo.c	Sun Aug 25 06:21:49 2002 +0000
@@ -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 <greg@censoft.com>
 
     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 @@
         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 @@
     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 @@
         }
     }
 
+#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 ;
 }
--- a/src/video/nanox/SDL_nxvideo.h	Sun Aug 25 02:05:24 2002 +0000
+++ b/src/video/nanox/SDL_nxvideo.h	Sun Aug 25 06:21:49 2002 +0000
@@ -55,7 +55,8 @@
     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 @@
     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 @@
 #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 @@
 #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