Skip to content

Commit

Permalink
Date: Sat, 24 Aug 2002 22:20:01 -0600
Browse files Browse the repository at this point in the history
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
  • Loading branch information
slouken committed Aug 25, 2002
1 parent 8eb8d06 commit 7fd5507
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 108 deletions.
48 changes: 32 additions & 16 deletions README.NanoX
@@ -1,21 +1,35 @@
=================================================================
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
this situation, we need to insert "nxSocket = -1" after
"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
=============
Expand All @@ -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.
=============================================
Expand All @@ -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
=========
Expand All @@ -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
Expand All @@ -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
19 changes: 6 additions & 13 deletions configure.in
Expand Up @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_syswm.h
Expand Up @@ -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 <X11/Xlib.h>
#include <X11/Xatom.h>
Expand Down
17 changes: 17 additions & 0 deletions src/video/nanox/SDL_nxevents.c
Expand Up @@ -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
Expand Down Expand Up @@ -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") ;
Expand Down
129 changes: 89 additions & 40 deletions src/video/nanox/SDL_nximage.c
Expand Up @@ -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
Expand Down Expand Up @@ -32,41 +33,50 @@

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 ;

for (i = 0; i < numrects; ++ i) {
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)] ;
Expand All @@ -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") ;
}
Expand All @@ -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 ;
Expand Down Expand Up @@ -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 ;
}
Expand All @@ -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") ;
}
2 changes: 1 addition & 1 deletion src/video/nanox/SDL_nxmodes_c.h
Expand Up @@ -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) ;
Expand Down

0 comments on commit 7fd5507

Please sign in to comment.