Date: Sat, 2 Aug 2003 16:22:51 +0300
authorSam Lantinga <slouken@libsdl.org>
Mon, 04 Aug 2003 00:52:42 +0000
changeset 6638bedd6d61642
parent 662 66c02f83f5bf
child 664 abfdc08eb289
Date: Sat, 2 Aug 2003 16:22:51 +0300
From: "Mike Gorchak"
Subject: New patches for QNX6

Here my patches for the SDL/QNX:

QNXSDL.diff - diff to non-QNX related sources:

- updated BUGS file, I think QNX6 is now will be officially supported
- configure.in - added shared library support for QNX, and removed dependency between the ALSA and QNX6.
- SDL_audio.c - added QNX NTO sound bootstrap insted of ALSA's.
- SDL_sysaudio.h - the same.
- SDL_nto_audio.c - the same.
- SDL_video.c - right now, QNX doesn't offer any method to obtain pointers to the OpenGL functions by function name, so they must be hardcoded in library, otherwise OpenGL will not be supported.
- testsprite.c - fixed: do not draw vertical red line if we are in non-double-buffered mode.

sdlqnxph.tar.gz - archive of the ./src/video/photon/* . Too many changes in code to make diffs :) :

+ Added stub for support hide/unhide window event
+ Added full YUV overlays support.
+ Added window maximize support.
+ Added mouse wheel events.
+ Added support for some specific key codes in Unicode mode (like ESC).
+ Added more checks to the all memory allocation code.
+ Added SDL_DOUBLEBUF support in all fullscreen modes.
+ Added fallback to window mode, if desired fullscreen mode is not supported.
+ Added stub support for the GL_LoadLibrary and GL_GetProcAddress functions.
+ Added resizable window support without caption.
! Fixed bug in the Ph_EV_EXPOSE event handler, when rectangles to update is 0 and when width or height of the rectangle is 0.
! Fixed bug in the event handler code. Events has not been passed to the window widget handler.
! Fixed codes for Win keys (Super/Hyper/Menu).
! Fixed memory leak, when deallocation palette.
! Fixed palette emulation code bugs.
! Fixed fullscreen and hwsurface handling.
! Fixed CLOSE button bug. First event was passed to the handler, but second terminated the application. Now all events passed to the application correctly.
- Removed all printfs in code, now SDL_SetError used instead of them.
- Disabled ToggleFullScreen function.

README.QNX - updated README.QNX file. Added much more issues.
BUGS
README.QNX
configure.in
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/nto/SDL_nto_audio.c
src/video/SDL_video.c
src/video/photon/SDL_ph_events.c
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_image_c.h
src/video/photon/SDL_ph_modes.c
src/video/photon/SDL_ph_modes_c.h
src/video/photon/SDL_ph_mouse.c
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_video.h
src/video/photon/SDL_ph_wm.c
src/video/photon/SDL_phyuv.c
src/video/photon/SDL_phyuv_c.h
test/testsprite.c
     1.1 --- a/BUGS	Mon Jul 28 01:47:55 2003 +0000
     1.2 +++ b/BUGS	Mon Aug 04 00:52:42 2003 +0000
     1.3 @@ -141,6 +141,10 @@
     1.4      
     1.5      No console output screen. Printing to stdout do not have any effect.
     1.6  
     1.7 +QNX:
     1.8 +	Fullscreen switch doesn't work correctly.
     1.9 + 
    1.10 +
    1.11  OpenBSD:  -= NOT YET SUPPORTED =-
    1.12  	This is reported to work, but I haven't verified this.
    1.13  
    1.14 @@ -183,13 +187,6 @@
    1.15  	More information on this port is available at:
    1.16  	http://www.kom.e-technik.tu-darmstadt.de/~griff/SDL/
    1.17  
    1.18 -QNX:  -= NOT YET SUPPORTED =-
    1.19 -	Only static libraries are being made, no shared ones.
    1.20 - 
    1.21 -	The only hardware surface is the primary view surface.
    1.22 - 
    1.23 -	Fullscreen doesn't display correctly.
    1.24 - 
    1.25  AmigaOS:  -= NOT YET SUPPORTED =-
    1.26  	The OpenGL support isn't implemented yet.
    1.27  
     2.1 --- a/README.QNX	Mon Jul 28 01:47:55 2003 +0000
     2.2 +++ b/README.QNX	Mon Aug 04 00:52:42 2003 +0000
     2.3 @@ -1,27 +1,94 @@
     2.4  README by Mike Gorchak <mike@malva.ua>, <lestat@i.com.ua>
     2.5 +Last changed at 29 Jul 2003.
     2.6 +
     2.7 +=========================================================================
     2.8 +OpenGL:
     2.9  
    2.10      OpenGL in window mode  works well  and  stable, in fullscreen
    2.11 -mode too, but fullscreen mode has not been heavily tested.
    2.12 -    If you have QNX RtP 6.1.0 w/ or w/o Patch A you must download
    2.13 -new Photon3D runtime from http://developers.qnx.com. The versions
    2.14 -of OS before 6.1.0 are not supported.
    2.15 +mode too, but fullscreen mode has not been heavily tested yet.
    2.16 +    If you have QNX RtP version 6.1.0 and above you must download
    2.17 +new Photon3D runtime from http://developers.qnx.com or install it
    2.18 +from public repository or from public CD, available with QNX. The
    2.19 +versions of OS before 6.1.0 are not supported.
    2.20 +    While  creating  OpenGL  context  software  renderer  mode is
    2.21 +artificially selected (QSSL  made  acceleration  only for  Voodoo
    2.22 +boards in fullscreen mode, sorry but I  don't have  this board to
    2.23 +test OpenGL - maybe it work or maybe not :)). If you want accele-
    2.24 +ration - you may remove some line in source code: find  the  file
    2.25 +SDL_ph_video.c and remove the following
    2.26  
    2.27 -Problems:
    2.28 -1. While  creating  OpenGL  context  software  renderer  mode  is
    2.29 -   artificially selected (QSSL made acceleration only for  Voodoo
    2.30 -   boards in fullscreen mode, sorry but I don't have  this board,
    2.31 -   if you want acceleration - you may remove some line  in source
    2.32 -   code).
    2.33 -2. Photon has some errors in detecting  how  much bits  per pixel
    2.34 -   videomode has.
    2.35 -3. No  shared  libraries  yet.  We  need  manually  set  flag  to
    2.36 -   'configure' --disable-shared.
    2.37 -4. Due to Photon API limitation, flag SDL_HWSURFACE supported on-
    2.38 -   ly in case of desktop bpp is equal requested bpp in window mo-
    2.39 -   de.
    2.40 +    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;
    2.41 +     
    2.42 +line in the ph_SetupOpenGLContext() function or  change  argument
    2.43 +to the PHOGL_ATTRIB_FORCE_HW or PHOGL_ATTRIB_FAVOR_HW.
    2.44  
    2.45 +=========================================================================
    2.46 +Wheel and multibutton mouses:
    2.47 +
    2.48 +    Photon emitting keyboard events (key up and down) when  moved
    2.49 +mouse wheel. But key_scan field appears valid according to flags,
    2.50 +and it contain zero. It is base method of detecting  mouse  wheel
    2.51 +events under photon. It looks like a hack, but it works for me :)
    2.52 +on different PC configurations.
    2.53 +
    2.54 +I'm tested it on:
    2.55 +
    2.56 +1. Genius Optical NetScroll/+ (1 wheel)
    2.57 +2. A4Tech Optical GreatEye WheelMouse, model: WOP-35. (2 wheels +
    2.58 +   2 additional buttons). Wheel for vertical scrolling  works  as
    2.59 +   usual, but second wheel for horizontal scrolling emitting  two
    2.60 +   consequented events up or down, so it can  provide  more  fast
    2.61 +   scrolling then the  first  wheel. Additional  buttons  doesn't
    2.62 +   emitting any events, but its look like  handled by  photon  in
    2.63 +   unusual way - like click to front, but works not with any win-
    2.64 +   dow, looks like bug-o-feature :).
    2.65 +
    2.66 +=========================================================================
    2.67 +CDROM handling issues:
    2.68 +
    2.69 +    Access to CDROM can be provided only with 'root'  previleges.
    2.70 +I can't do anything with this fact. /dev/cd0 have  the brw-------
    2.71 +flags and root:root rights.
    2.72 +
    2.73 +=========================================================================
    2.74 +Video Overlays:
    2.75 +
    2.76 +    Overlays can flickering during the window movement, resizing,
    2.77 +etc. It happens because photon driver  updates  the  real  window
    2.78 +contents behind the overlay, then draws the temporary  chroma key
    2.79 +color over window contents. It can be done without the chroma key
    2.80 +using but it cause overlay will be  always  on top. So flickering
    2.81 +during the movement much better in that case.
    2.82 +    Double buffering code temporary disabled in the photon driver
    2.83 +code, beacuse on my GF2-MX it  cause  accidently  buffer  switch,
    2.84 +which going to the old frame showing. S3 Savage3D have  the  same
    2.85 +problem, but ATI Rage 128 has not this problem. I think it can be
    2.86 +fixed later. Current code works very fine, so maybe double buffe-
    2.87 +ring is not needed right now.
    2.88 +    Something strange appears when you tried to move window  with
    2.89 +overlay beyond the left border of the screen. Overlay  trying  to
    2.90 +stay at position x=0, but when tried to move  it  a  bit  more it
    2.91 +jumps  at  posituin  x=-60. Really  strange, looks  like  overlay
    2.92 +doesn't love the negotive coordinates.
    2.93 +
    2.94 +=========================================================================
    2.95 +Shared library building:
    2.96 +
    2.97 +    Shared  library can be  built, but before  running autogen.sh
    2.98 +script you  need  manually  delete  the  libtool  m4  stuff  from
    2.99 +the acinclude.m4 file (it comes after ESD  detection  code  up to
   2.100 +end of the file). Because libtool stuff in the  acinclude.m4 file
   2.101 +very old and doesn't know anything about the QNX. Just  remove it
   2.102 +and run autogen.sh script.
   2.103 +
   2.104 +=========================================================================
   2.105  Some building issues:
   2.106  
   2.107 +    Feel free to not pass --disable-shared option  to  configure,
   2.108 +if you read comment above about 'Shared library building'. Other-
   2.109 +wise this option is strongly  recomended, because  the sdl-config
   2.110 +script will be unfunctional.
   2.111 +
   2.112      Run configure script without x11 support, e.g.:
   2.113  
   2.114      a) for OpenGL support:
   2.115 @@ -42,3 +109,4 @@
   2.116                   --with-sdl-exec-prefix=/usr/local \
   2.117                   --prefix=/usr/local --without-x
   2.118  
   2.119 +
     3.1 --- a/configure.in	Mon Jul 28 01:47:55 2003 +0000
     3.2 +++ b/configure.in	Mon Aug 04 00:52:42 2003 +0000
     3.3 @@ -2531,6 +2531,9 @@
     3.4    openbsd | netbsd | bsdi)
     3.5      SHARED_SYSTEM_LIBS="$SYSTEM_LIBS"
     3.6      ;;
     3.7 +  qnx)
     3.8 +    SHARED_SYSTEM_LIBS="$SYSTEM_LIBS"
     3.9 +    ;;
    3.10    macosx)
    3.11      SHARED_SYSTEM_LIBS="-framework Cocoa"
    3.12      if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
     4.1 --- a/src/audio/SDL_audio.c	Mon Jul 28 01:47:55 2003 +0000
     4.2 +++ b/src/audio/SDL_audio.c	Mon Aug 04 00:52:42 2003 +0000
     4.3 @@ -50,6 +50,9 @@
     4.4  #ifdef ALSA_SUPPORT
     4.5  	&ALSA_bootstrap,
     4.6  #endif
     4.7 +#ifdef QNXNTOAUDIO_SUPPORT
     4.8 +	&QNXNTOAUDIO_bootstrap,
     4.9 +#endif
    4.10  #ifdef SUNAUDIO_SUPPORT
    4.11  	&SUNAUDIO_bootstrap,
    4.12  #endif
     5.1 --- a/src/audio/SDL_sysaudio.h	Mon Jul 28 01:47:55 2003 +0000
     5.2 +++ b/src/audio/SDL_sysaudio.h	Mon Aug 04 00:52:42 2003 +0000
     5.3 @@ -114,6 +114,9 @@
     5.4  #ifdef ALSA_SUPPORT
     5.5  extern AudioBootStrap ALSA_bootstrap;
     5.6  #endif
     5.7 +#ifdef QNXNTOAUDIO_SUPPORT
     5.8 +extern AudioBootStrap QNXNTOAUDIO_bootstrap;
     5.9 +#endif
    5.10  #ifdef SUNAUDIO_SUPPORT
    5.11  extern AudioBootStrap SUNAUDIO_bootstrap;
    5.12  #endif
     6.1 --- a/src/audio/nto/SDL_nto_audio.c	Mon Jul 28 01:47:55 2003 +0000
     6.2 +++ b/src/audio/nto/SDL_nto_audio.c	Mon Aug 04 00:52:42 2003 +0000
     6.3 @@ -163,9 +163,8 @@
     6.4  	return this;
     6.5  }
     6.6  
     6.7 -/* Don't change the name from "ALSA_bootstrap" - that's how it's called */
     6.8 -AudioBootStrap ALSA_bootstrap = {
     6.9 -	DRIVER_NAME, "Neutrino PCM audio",
    6.10 +AudioBootStrap QNXNTOAUDIO_bootstrap = {
    6.11 +	DRIVER_NAME, "QNX6 NTO PCM audio",
    6.12  	Audio_Available, Audio_CreateDevice
    6.13  };
    6.14  
    6.15 @@ -489,4 +488,3 @@
    6.16  	/* We're ready to rock and roll. :-) */
    6.17  	return(0);
    6.18  }
    6.19 -
     7.1 --- a/src/video/SDL_video.c	Mon Jul 28 01:47:55 2003 +0000
     7.2 +++ b/src/video/SDL_video.c	Mon Aug 04 00:52:42 2003 +0000
     7.3 @@ -727,6 +727,7 @@
     7.4  #ifdef HAVE_OPENGL
     7.5  	/* Load GL symbols (before MakeCurrent, where we need glGetString). */
     7.6  	if ( flags & (SDL_OPENGL | SDL_OPENGLBLIT) ) {
     7.7 +#ifndef __QNXNTO__
     7.8  #define SDL_PROC(ret,func,params) \
     7.9  do { \
    7.10  	video->func = SDL_GL_GetProcAddress(#func); \
    7.11 @@ -735,6 +736,9 @@
    7.12  		return(NULL); \
    7.13  	} \
    7.14  } while ( 0 );
    7.15 +#else
    7.16 +#define SDL_PROC(ret,func,params) video->func=func;
    7.17 +#endif /* __QNXNTO__ */
    7.18  #include "SDL_glfuncs.h"
    7.19  #undef SDL_PROC	
    7.20  	}
     8.1 --- a/src/video/photon/SDL_ph_events.c	Mon Jul 28 01:47:55 2003 +0000
     8.2 +++ b/src/video/photon/SDL_ph_events.c	Mon Aug 04 00:52:42 2003 +0000
     8.3 @@ -29,11 +29,12 @@
     8.4  
     8.5  #define DISABLE_X11
     8.6  
     8.7 -#include <Ph.h>
     8.8  #include <stdio.h>
     8.9  #include <setjmp.h>
    8.10 +#include <sys/time.h>
    8.11 +
    8.12 +#include <Ph.h>
    8.13  #include <photon/PkKeyDef.h>
    8.14 -#include <sys/time.h>
    8.15  
    8.16  #include "SDL.h"
    8.17  #include "SDL_syswm.h"
    8.18 @@ -44,6 +45,8 @@
    8.19  #include "SDL_ph_modes_c.h"
    8.20  #include "SDL_ph_image_c.h"
    8.21  #include "SDL_ph_events_c.h"
    8.22 +#include "SDL_phyuv_c.h"
    8.23 +
    8.24  
    8.25  
    8.26  /* The translation tables from a photon keysym to a SDL keysym */
    8.27 @@ -90,8 +93,8 @@
    8.28  
    8.29      if( window )
    8.30      {
    8.31 -        rid = PtWidgetRid( window );
    8.32 -        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
    8.33 +        rid = PtWidgetRid(window);
    8.34 +        if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )
    8.35          {
    8.36              region.events_sense=(region.events_sense & ~fields)|(flags & fields);
    8.37              PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
    8.38 @@ -114,6 +117,8 @@
    8.39      return (mouse_button);
    8.40  }
    8.41  
    8.42 +//                   void* PtAppCreateContext();
    8.43 +
    8.44  static int ph_DispatchEvent(_THIS)
    8.45  {
    8.46      int posted;
    8.47 @@ -217,15 +222,56 @@
    8.48              {
    8.49                  posted = SDL_PrivateQuit();
    8.50              }
    8.51 +            /* request to hide/unhide */
    8.52 +            else if (winEvent->event_f==Ph_WM_HIDE)
    8.53 +            {
    8.54 +                if (currently_hided)
    8.55 +                {
    8.56 +                   /* got unhide window event                                */
    8.57 +                   /* TODO: restore application's palette if in palette mode */
    8.58 +                   currently_hided=0;
    8.59 +                }
    8.60 +                else
    8.61 +                {
    8.62 +                   /* got hide window event                                  */
    8.63 +                   /* TODO: restore original palette if in palette mode      */
    8.64 +                   currently_hided=1;
    8.65 +                }
    8.66 +            }
    8.67              /* request to resize */
    8.68              else if (winEvent->event_f==Ph_WM_RESIZE)
    8.69              {
    8.70                  SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
    8.71              }
    8.72 +            /* request to move */
    8.73 +            else if (winEvent->event_f==Ph_WM_MOVE)
    8.74 +            {
    8.75 +                if (current_overlay!=NULL)
    8.76 +                {
    8.77 +                   int lockedstate=current_overlay->hwdata->locked;
    8.78 +                   int chromastate=current_overlay->hwdata->ischromakey;
    8.79 +                   SDL_Rect target;
    8.80 +
    8.81 +                   current_overlay->hwdata->locked=1;
    8.82 +                   target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
    8.83 +                   target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
    8.84 +                   target.w=current_overlay->hwdata->CurrentViewPort.size.w;
    8.85 +                   target.h=current_overlay->hwdata->CurrentViewPort.size.h;
    8.86 +                   current_overlay->hwdata->ischromakey=0;
    8.87 +                   ph_DisplayYUVOverlay(this, current_overlay, &target);
    8.88 +                   current_overlay->hwdata->ischromakey=chromastate;
    8.89 +                   current_overlay->hwdata->locked=lockedstate;
    8.90 +                }
    8.91 +            }
    8.92              /* request to maximize */
    8.93              else if (winEvent->event_f==Ph_WM_MAX)
    8.94              {
    8.95 -                /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */
    8.96 +                /* window already moved and resized here */
    8.97 +                SDL_PrivateResize(winEvent->size.w-winEvent->pos.x, winEvent->size.h-winEvent->pos.y);
    8.98 +            }
    8.99 +            /* request to restore */
   8.100 +            else if (winEvent->event_f==Ph_WM_RESTORE)
   8.101 +            {
   8.102              }
   8.103          }
   8.104          break;
   8.105 @@ -233,19 +279,38 @@
   8.106          /* window has been resized, moved or removed */
   8.107          case Ph_EV_EXPOSE:
   8.108          {
   8.109 -            if (SDL_VideoSurface)
   8.110 +            if (event->num_rects!=0)
   8.111              {
   8.112 -                rect = PhGetRects(event);
   8.113 +                if (SDL_VideoSurface)
   8.114 +                {
   8.115 +                    rect = PhGetRects(event);
   8.116  
   8.117 -                for(i=0;i<event->num_rects;i++)
   8.118 -                {
   8.119 -                    sdlrects[i].x = rect[i].ul.x;
   8.120 -                    sdlrects[i].y = rect[i].ul.y;
   8.121 -                    sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   8.122 -                    sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   8.123 +                    for(i=0;i<event->num_rects;i++)
   8.124 +                    {
   8.125 +                        sdlrects[i].x = rect[i].ul.x;
   8.126 +                        sdlrects[i].y = rect[i].ul.y;
   8.127 +                        sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   8.128 +                        sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   8.129 +                    }
   8.130 +
   8.131 +                    this->UpdateRects(this, event->num_rects, sdlrects);
   8.132 +
   8.133 +                    if (current_overlay!=NULL)
   8.134 +                    {
   8.135 +                        int lockedstate=current_overlay->hwdata->locked;
   8.136 +                        SDL_Rect target;
   8.137 +
   8.138 +                        current_overlay->hwdata->locked=1;
   8.139 +                        target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
   8.140 +                        target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
   8.141 +                        target.w=current_overlay->hwdata->CurrentViewPort.size.w;
   8.142 +                        target.h=current_overlay->hwdata->CurrentViewPort.size.h;
   8.143 +                        current_overlay->hwdata->forcedredraw=1;
   8.144 +                        ph_DisplayYUVOverlay(this, current_overlay, &target);
   8.145 +                        current_overlay->hwdata->forcedredraw=0;
   8.146 +                        current_overlay->hwdata->locked=lockedstate;
   8.147 +                    }
   8.148                  }
   8.149 -
   8.150 -                this->UpdateRects(this, event->num_rects, sdlrects);
   8.151              }
   8.152          }
   8.153  	break;
   8.154 @@ -260,13 +325,32 @@
   8.155  
   8.156              if (Pk_KF_Key_Down & keyEvent->key_flags)
   8.157              {
   8.158 +                /* split the wheel events from real key events */
   8.159 +                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   8.160 +                {
   8.161 +                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
   8.162 +                   break;
   8.163 +                }
   8.164 +                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   8.165 +                {
   8.166 +                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
   8.167 +                   break;
   8.168 +                }
   8.169                  posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
   8.170              }
   8.171              else /* must be key release */
   8.172              {
   8.173 -                 /* Ignore repeated key release events */
   8.174 -                 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */
   8.175 -
   8.176 +                /* split the wheel events from real key events */
   8.177 +                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   8.178 +                {
   8.179 +                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
   8.180 +                   break;
   8.181 +                }
   8.182 +                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   8.183 +                {
   8.184 +                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
   8.185 +                   break;
   8.186 +                }
   8.187                  posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
   8.188              }
   8.189          }
   8.190 @@ -282,9 +366,9 @@
   8.191      /* Flush the display connection and look to see if events are queued */
   8.192      PgFlush();
   8.193  
   8.194 -    while( 1 )
   8.195 -    {   /* note this is a non-blocking call */
   8.196 -        switch( PhEventPeek( event, EVENT_SIZE ) )
   8.197 +    while (1)
   8.198 +    {
   8.199 +        switch(PhEventPeek(event, EVENT_SIZE))
   8.200          {
   8.201              case Ph_EVENT_MSG:
   8.202                   return 1;
   8.203 @@ -308,6 +392,7 @@
   8.204  
   8.205      while (ph_Pending(this))
   8.206      {
   8.207 +        PtEventHandler(event);
   8.208          ph_DispatchEvent(this);
   8.209      }
   8.210  }
   8.211 @@ -318,11 +403,15 @@
   8.212  
   8.213      /* Odd keys used in international keyboards */
   8.214      for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
   8.215 +    {
   8.216          ODD_keymap[i] = SDLK_UNKNOWN;
   8.217 +    }
   8.218  
   8.219      /* Map the miscellaneous keys */
   8.220      for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
   8.221 +    {
   8.222          MISC_keymap[i] = SDLK_UNKNOWN;
   8.223 +    }
   8.224  
   8.225      MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   8.226      MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   8.227 @@ -388,15 +477,19 @@
   8.228      MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   8.229      MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   8.230      MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   8.231 -    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
   8.232 -    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   8.233 +    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;
   8.234 +    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;
   8.235      MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
   8.236  
   8.237      MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   8.238      MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   8.239      MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   8.240 -    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   8.241 -    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   8.242 +    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;        /* Windows "Menu" key */
   8.243 +
   8.244 +    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   8.245 +
   8.246 +    /* Left "Windows" key, but it can't be catched by application */
   8.247 +    MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER;
   8.248  }
   8.249  
   8.250  static unsigned long cap;
   8.251 @@ -447,13 +540,23 @@
   8.252          int utf8len;
   8.253          wchar_t unicode;
   8.254  
   8.255 -        utf8len = PhKeyToMb(utf8, key);
   8.256 -        if (utf8len > 0)
   8.257 +        switch (keysym->scancode)
   8.258          {
   8.259 -            utf8len = mbtowc(&unicode, utf8, utf8len);
   8.260 -            if (utf8len > 0)
   8.261 -                keysym->unicode = unicode;
   8.262 +           case 0x01: keysym->unicode = 27;
   8.263 +                      break;
   8.264 +           default:
   8.265 +                      utf8len = PhKeyToMb(utf8, key);
   8.266 +                      if (utf8len > 0)
   8.267 +                      {
   8.268 +                          utf8len = mbtowc(&unicode, utf8, utf8len);
   8.269 +                         if (utf8len > 0)
   8.270 +                         {
   8.271 +                             keysym->unicode = unicode;
   8.272 +                         }
   8.273 +                      }
   8.274 +                      break;
   8.275          }
   8.276 +
   8.277      }
   8.278  
   8.279      return (keysym);
     9.1 --- a/src/video/photon/SDL_ph_image.c	Mon Jul 28 01:47:55 2003 +0000
     9.2 +++ b/src/video/photon/SDL_ph_image.c	Mon Aug 04 00:52:42 2003 +0000
     9.3 @@ -35,54 +35,11 @@
     9.4  #include "SDL_video.h"
     9.5  #include "SDL_pixels_c.h"
     9.6  #include "SDL_ph_image_c.h"
     9.7 -
     9.8 -/* Mask values for SDL_ReallocFormat() */
     9.9 -struct ColourMasks
    9.10 -{
    9.11 -    Uint32 red;
    9.12 -    Uint32 green;
    9.13 -    Uint32 blue;
    9.14 -    Uint32 alpha;
    9.15 -    Uint32 bpp;
    9.16 -};
    9.17 -
    9.18 -static const struct ColourMasks *ph_GetColourMasks( int format )
    9.19 -{
    9.20 -    /* The alpha mask doesn't appear to be needed */
    9.21 -    static const struct ColourMasks phColorMasks[5] = {
    9.22 -        /*  8 bit      */  {0, 0, 0, 0, 8},
    9.23 -        /* 15 bit ARGB */  {0x7C00, 0x03E0, 0x001F, 0x8000, 16},
    9.24 -        /* 16 bit  RGB */  {0xF800, 0x07E0, 0x001F, 0x0000, 16},
    9.25 -        /* 24 bit  RGB */  {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
    9.26 -        /* 32 bit ARGB */  {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
    9.27 -    };
    9.28 -
    9.29 -    switch( format )
    9.30 -    {
    9.31 -        case Pg_IMAGE_PALETTE_BYTE:
    9.32 -             return &phColorMasks[0];
    9.33 -             break;
    9.34 -        case Pg_IMAGE_DIRECT_1555:
    9.35 -        case Pg_IMAGE_DIRECT_555:
    9.36 -             return &phColorMasks[1];
    9.37 -             break;
    9.38 -        case Pg_IMAGE_DIRECT_565:
    9.39 -             return &phColorMasks[2];
    9.40 -             break;
    9.41 -        case Pg_IMAGE_DIRECT_888:
    9.42 -             return &phColorMasks[3];
    9.43 -             break;
    9.44 -        case Pg_IMAGE_DIRECT_8888:
    9.45 -             return &phColorMasks[4];
    9.46 -             break;
    9.47 -    }
    9.48 -    return NULL;
    9.49 -}
    9.50 +#include "SDL_ph_modes_c.h"
    9.51  
    9.52  int ph_SetupImage(_THIS, SDL_Surface *screen)
    9.53  {
    9.54      PgColor_t* palette=NULL;
    9.55 -    const struct ColourMasks* mask;
    9.56      int type=0;
    9.57      int bpp;
    9.58      
    9.59 @@ -112,7 +69,7 @@
    9.60          }
    9.61          break;
    9.62          default:{
    9.63 -            fprintf(stderr,"ph_SetupImage(): unsupported bpp=%d !\n", bpp);
    9.64 +            SDL_SetError("ph_SetupImage(): unsupported bpp=%d !\n", bpp);
    9.65              return -1;
    9.66          }
    9.67          break;
    9.68 @@ -123,12 +80,18 @@
    9.69      {
    9.70          /* creating image palette */
    9.71          palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
    9.72 +        if (palette==NULL)
    9.73 +        {
    9.74 +            SDL_SetError("ph_SetupImage(): can't allocate memory for palette !\n");
    9.75 +            return -1;
    9.76 +        }
    9.77          PgGetPalette(palette);
    9.78  
    9.79          /* using shared memory for speed (set last param to 1) */
    9.80          if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
    9.81          {
    9.82 -            fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8 !\n");
    9.83 +            SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n");
    9.84 +            free(palette);
    9.85              return -1;
    9.86          }
    9.87      }
    9.88 @@ -137,19 +100,13 @@
    9.89          /* using shared memory for speed (set last param to 1) */
    9.90          if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
    9.91          {
    9.92 -            fprintf(stderr,"ph_SetupImage: PhCreateImage failed !\n");
    9.93 +            SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=%d !\n", bpp);
    9.94              return -1;
    9.95          }
    9.96      }
    9.97  
    9.98      screen->pixels = SDL_Image->image;
    9.99 -    screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */
   9.100 -
   9.101 -    mask = ph_GetColourMasks(type);
   9.102 -    if (mask != NULL)
   9.103 -    {
   9.104 -        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
   9.105 -    }
   9.106 +    screen->pitch = SDL_Image->bpl;
   9.107  
   9.108      this->UpdateRects = ph_NormalUpdate;
   9.109  
   9.110 @@ -158,11 +115,9 @@
   9.111  
   9.112  int ph_SetupOCImage(_THIS, SDL_Surface *screen)
   9.113  {
   9.114 -    const struct ColourMasks *mask;
   9.115      int type = 0;
   9.116      int bpp;
   9.117  
   9.118 -    screen->flags &= ~SDL_DOUBLEBUF;
   9.119      OCImage.flags = screen->flags;
   9.120      
   9.121      bpp=screen->format->BitsPerPixel;
   9.122 @@ -191,7 +146,7 @@
   9.123                  }
   9.124                  break;
   9.125          default:{
   9.126 -                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
   9.127 +                    SDL_SetError("ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
   9.128                      return -1;
   9.129                  }
   9.130                  break;
   9.131 @@ -203,35 +158,22 @@
   9.132  
   9.133      if (OCImage.offscreen_context == NULL)
   9.134      {
   9.135 -        fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n");
   9.136 +        SDL_SetError("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n");
   9.137          return -1;
   9.138      }
   9.139  
   9.140 -    /* If the bit depth of the context is different than was requested,
   9.141 -     * these values need to be updated accordingly.  SDL will
   9.142 -     * allocate a shadow surface if it needs to. */
   9.143 -    mask = ph_GetColourMasks(OCImage.offscreen_context->format);
   9.144 -    if (mask != NULL)
   9.145 +    screen->pitch = OCImage.offscreen_context->pitch;
   9.146 +
   9.147 +    OCImage.dc_ptr = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
   9.148 +
   9.149 +    if (OCImage.dc_ptr == NULL)
   9.150      {
   9.151 -        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
   9.152 -
   9.153 -        if (mask->bpp > 8)
   9.154 -        {
   9.155 -            screen->flags &= ~SDL_HWPALETTE;
   9.156 -        }
   9.157 -    }
   9.158 -
   9.159 -    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
   9.160 -
   9.161 -    OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
   9.162 -
   9.163 -    if (OCImage.dc_ptr.ptr8 == NULL)
   9.164 -    {
   9.165 -        fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
   9.166 +        SDL_SetError("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n");
   9.167 +        PhDCRelease(OCImage.offscreen_context);
   9.168          return -1;
   9.169      }
   9.170  
   9.171 -    OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
   9.172 +    OCImage.FrameData0 = OCImage.dc_ptr;
   9.173      OCImage.CurrentFrameData = OCImage.FrameData0;
   9.174      OCImage.current = 0;
   9.175  
   9.176 @@ -253,67 +195,108 @@
   9.177  
   9.178  int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
   9.179  {
   9.180 -    const struct ColourMasks *mask;
   9.181 -    screen->flags &= ~SDL_DOUBLEBUF;
   9.182      OCImage.flags = screen->flags;
   9.183  
   9.184 -    OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
   9.185 -
   9.186 -    if (OCImage.offscreen_context == NULL)
   9.187 +    /* Begin direct mode */
   9.188 +    if (!ph_EnterFullScreen(this, screen))
   9.189      {
   9.190 -        fprintf(stderr, "ph_SetupFullScreenImage(): PdCreateOffscreenContext failed !\n");
   9.191          return -1;
   9.192      }
   9.193  
   9.194 -    /* If the bit depth of the context is different than was requested,
   9.195 -     * these values need to be updated accordingly.  SDL will
   9.196 -     * allocate a shadow surface if it needs to. */
   9.197 -    mask = ph_GetColourMasks(OCImage.offscreen_context->format);
   9.198 -    if (mask != NULL)
   9.199 +    /* store palette for fullscreen */
   9.200 +    if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
   9.201      {
   9.202 -        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
   9.203 +        PgGetPalette(savedpal);
   9.204 +        PgGetPalette(syspalph);
   9.205 +    }
   9.206  
   9.207 -        if (mask->bpp > 8)
   9.208 +    OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
   9.209 +    if (OCImage.offscreen_context == NULL)
   9.210 +    {
   9.211 +        SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext() function failed !\n");
   9.212 +        return -1;
   9.213 +    }
   9.214 +    
   9.215 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
   9.216 +    {
   9.217 +        OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE);
   9.218 +        if (OCImage.offscreen_backcontext == NULL)
   9.219          {
   9.220 -            screen->flags &= ~SDL_HWPALETTE;
   9.221 +            SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
   9.222 +            return -1;
   9.223          }
   9.224      }
   9.225  
   9.226 -    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
   9.227 -
   9.228 -    OCImage.dc_ptr.ptr8 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
   9.229 -
   9.230 -    if (OCImage.dc_ptr.ptr8 == NULL)
   9.231 +    OCImage.FrameData0 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
   9.232 +    if (OCImage.FrameData0 == NULL)
   9.233      {
   9.234 -        fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
   9.235 +        SDL_SetError("ph_SetupFullScreenImage(): PdGetOffscreenContextPtr() function failed !\n");
   9.236 +        ph_DestroyImage(this, screen);
   9.237          return -1;
   9.238      }
   9.239  
   9.240 -    /* wait for hw */
   9.241 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
   9.242 +    {
   9.243 +        OCImage.FrameData1 = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_backcontext);
   9.244 +        if (OCImage.FrameData1 == NULL)
   9.245 +        {
   9.246 +            SDL_SetError("ph_SetupFullScreenImage(back): PdGetOffscreenContextPtr() function failed !\n");
   9.247 +            ph_DestroyImage(this, screen);
   9.248 +            return -1;
   9.249 +        }
   9.250 +    }
   9.251 +
   9.252 +    /* wait for the hardware */
   9.253      PgWaitHWIdle();
   9.254  
   9.255 -    OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
   9.256 -    OCImage.CurrentFrameData = OCImage.FrameData0;
   9.257 -    OCImage.current = 0;
   9.258 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
   9.259 +    {
   9.260 +        OCImage.current = 1;
   9.261 +        PhDCSetCurrent(OCImage.offscreen_backcontext);
   9.262 +        screen->pitch = OCImage.offscreen_backcontext->pitch;
   9.263 +        screen->pixels = OCImage.FrameData1;
   9.264 +        PgSwapDisplay(OCImage.offscreen_context, 0);
   9.265 +    }
   9.266 +    else
   9.267 +    {
   9.268 +        OCImage.current = 0;
   9.269 +        PhDCSetCurrent(OCImage.offscreen_context);
   9.270 +        screen->pitch = OCImage.offscreen_context->pitch;
   9.271 +        screen->pixels = OCImage.FrameData0;
   9.272 +    }
   9.273  
   9.274 -    PhDCSetCurrent(OCImage.offscreen_context);
   9.275 -
   9.276 -    screen->pixels = OCImage.CurrentFrameData;
   9.277 -
   9.278 -    this->UpdateRects = ph_OCUpdate;
   9.279 +    this->UpdateRects = ph_OCDCUpdate;
   9.280  
   9.281      return 0;
   9.282  }
   9.283  
   9.284  void ph_DestroyImage(_THIS, SDL_Surface *screen)
   9.285  {
   9.286 +    if (currently_fullscreen)
   9.287 +    {
   9.288 +        /* if we right now in 8bpp fullscreen we must release palette */
   9.289 +        if ((screen->format->BitsPerPixel==8) && (desktopbpp!=8))
   9.290 +        {
   9.291 +            PgSetPalette(syspalph, 0, -1, 0, 0, 0);
   9.292 +            PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
   9.293 +            PgFlush();
   9.294 +        }
   9.295 +        ph_LeaveFullScreen(this);
   9.296 +    }
   9.297 +
   9.298      if (OCImage.offscreen_context != NULL)
   9.299      {
   9.300          PhDCRelease(OCImage.offscreen_context);
   9.301          OCImage.offscreen_context = NULL;
   9.302          OCImage.FrameData0 = NULL;
   9.303 +    }
   9.304 +    if (OCImage.offscreen_backcontext != NULL)
   9.305 +    {
   9.306 +        PhDCRelease(OCImage.offscreen_backcontext);
   9.307 +        OCImage.offscreen_backcontext = NULL;
   9.308          OCImage.FrameData1 = NULL;
   9.309      }
   9.310 +    OCImage.CurrentFrameData = NULL;
   9.311  
   9.312      if (SDL_Image)
   9.313      {
   9.314 @@ -354,6 +337,7 @@
   9.315  
   9.316      return ph_SetupImage(this, screen);
   9.317  }
   9.318 +
   9.319  int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
   9.320  {
   9.321      return(-1);
   9.322 @@ -364,9 +348,41 @@
   9.323      return;
   9.324  }
   9.325  
   9.326 -int ph_FlipHWSurface(_THIS, SDL_Surface *surface)
   9.327 +int ph_FlipHWSurface(_THIS, SDL_Surface *screen)
   9.328  {
   9.329 -    return(0);
   9.330 +    PhArea_t area;
   9.331 +
   9.332 +    area.pos.x=0;
   9.333 +    area.pos.y=0;
   9.334 +    area.size.w=screen->w;
   9.335 +    area.size.h=screen->h;
   9.336 +
   9.337 +    if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
   9.338 +    {
   9.339 +        if (OCImage.current==0)
   9.340 +        {
   9.341 +            PgSwapDisplay(OCImage.offscreen_context, 0);
   9.342 +            OCImage.current=1;
   9.343 +            screen->pitch = OCImage.offscreen_backcontext->pitch;
   9.344 +            screen->pixels = OCImage.FrameData1;
   9.345 +//            memcpy(OCImage.FrameData1, OCImage.FrameData0, OCImage.offscreen_context->shared_size);
   9.346 +            PgContextBlitArea(OCImage.offscreen_context, &area, OCImage.offscreen_backcontext, &area);
   9.347 +            PhDCSetCurrent(OCImage.offscreen_backcontext);
   9.348 +            PgFlush();
   9.349 +        }
   9.350 +        else
   9.351 +        {
   9.352 +            PgSwapDisplay(OCImage.offscreen_backcontext, 0);
   9.353 +            OCImage.current=0;
   9.354 +            screen->pitch = OCImage.offscreen_context->pitch;
   9.355 +            screen->pixels = OCImage.FrameData0;
   9.356 +//            memcpy(OCImage.FrameData0, OCImage.FrameData1, OCImage.offscreen_context->shared_size);
   9.357 +            PgContextBlitArea(OCImage.offscreen_backcontext, &area, OCImage.offscreen_context, &area);
   9.358 +            PhDCSetCurrent(OCImage.offscreen_context);
   9.359 +            PgFlush();
   9.360 +        }
   9.361 +    }
   9.362 +    return 0;
   9.363  }
   9.364  
   9.365  int ph_LockHWSurface(_THIS, SDL_Surface *surface)
   9.366 @@ -399,6 +415,11 @@
   9.367              continue;
   9.368          }
   9.369  
   9.370 +    	if (rects[i].h==0) /* Clipped? */
   9.371 +        { 
   9.372 +            continue;
   9.373 +        }
   9.374 +
   9.375          ph_pos.x = rects[i].x;
   9.376          ph_pos.y = rects[i].y;
   9.377          ph_rect.ul.x = rects[i].x;
   9.378 @@ -408,13 +429,13 @@
   9.379  
   9.380          if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
   9.381          {
   9.382 -            fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
   9.383 +            SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
   9.384          }
   9.385      }
   9.386  
   9.387      if (PgFlush() < 0)
   9.388      {
   9.389 -    	fprintf(stderr,"ph_NormalUpdate(): PgFlush failed.\n");
   9.390 +    	SDL_SetError("ph_NormalUpdate(): PgFlush failed.\n");
   9.391      }
   9.392  }
   9.393  
   9.394 @@ -437,6 +458,11 @@
   9.395              continue;
   9.396          }
   9.397  
   9.398 +        if (rects[i].h == 0)  /* Clipped? */
   9.399 +        {
   9.400 +            continue;
   9.401 +        }
   9.402 +
   9.403          src_rect.pos.x=rects[i].x;
   9.404          src_rect.pos.y=rects[i].y;
   9.405          dest_rect.pos.x=rects[i].x;
   9.406 @@ -457,16 +483,16 @@
   9.407  
   9.408      if (PgFlush() < 0)
   9.409      {
   9.410 -        fprintf(stderr,"ph_OCUpdate(): PgFlush failed.\n");
   9.411 -    }
   9.412 -    
   9.413 -    /* later used to toggling double buffer */
   9.414 -    if (OCImage.current == 0)
   9.415 -    {
   9.416 -        OCImage.CurrentFrameData = OCImage.FrameData0;
   9.417 -    }
   9.418 -    else
   9.419 -    {
   9.420 -        OCImage.CurrentFrameData = OCImage.FrameData1;
   9.421 +        SDL_SetError("ph_OCUpdate(): PgFlush failed.\n");
   9.422      }
   9.423  }
   9.424 +
   9.425 +void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect *rects)
   9.426 +{
   9.427 +    PgWaitHWIdle();
   9.428 +
   9.429 +    if (PgFlush() < 0)
   9.430 +    {
   9.431 +        SDL_SetError("ph_OCDCUpdate(): PgFlush failed.\n");
   9.432 +    }
   9.433 +}
    10.1 --- a/src/video/photon/SDL_ph_image_c.h	Mon Jul 28 01:47:55 2003 +0000
    10.2 +++ b/src/video/photon/SDL_ph_image_c.h	Mon Aug 04 00:52:42 2003 +0000
    10.3 @@ -39,4 +39,5 @@
    10.4  
    10.5  extern void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
    10.6  extern void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects);
    10.7 +extern void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect *rects);
    10.8  extern void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect *rects);
    11.1 --- a/src/video/photon/SDL_ph_modes.c	Mon Jul 28 01:47:55 2003 +0000
    11.2 +++ b/src/video/photon/SDL_ph_modes.c	Mon Aug 04 00:52:42 2003 +0000
    11.3 @@ -25,6 +25,7 @@
    11.4   "@(#) $Id$";
    11.5  #endif
    11.6  
    11.7 +#include "SDL_error.h"
    11.8  #include "SDL_ph_modes_c.h"
    11.9  
   11.10  static unsigned long key1, key2;
   11.11 @@ -39,8 +40,6 @@
   11.12  {
   11.13      if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
   11.14      {
   11.15 -        fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
   11.16 -            *(unsigned short*)mode1);
   11.17          return 0;
   11.18      }
   11.19  
   11.20 @@ -48,19 +47,26 @@
   11.21  
   11.22      if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
   11.23      {
   11.24 -        fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
   11.25 -            *(unsigned short*)mode2);
   11.26          return 0;
   11.27      }
   11.28  
   11.29      key2 = mode_info.width * mode_info.height;
   11.30  
   11.31      if (key1 > key2)
   11.32 +    {
   11.33          return 1;
   11.34 -    else if (key1 == key2)
   11.35 -        return 0;
   11.36 +    }
   11.37      else
   11.38 -        return -1;
   11.39 +    {
   11.40 +        if (key1 == key2)
   11.41 +        {
   11.42 +           return 0;
   11.43 +        }
   11.44 +        else
   11.45 +        {
   11.46 +            return -1;
   11.47 +        }
   11.48 +    }
   11.49  }
   11.50  
   11.51  SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   11.52 @@ -76,7 +82,7 @@
   11.53  
   11.54      if (PgGetVideoModeList( &mode_list ) < 0)
   11.55      {
   11.56 -       fprintf(stderr,"error: PgGetVideoModeList failed\n");
   11.57 +       SDL_SetError("ph_ListModes(): PgGetVideoModeList() function failed !\n");
   11.58         return NULL;
   11.59      }
   11.60  
   11.61 @@ -86,7 +92,7 @@
   11.62      {
   11.63          if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
   11.64          {
   11.65 -            fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", mode_list.modes[i]);
   11.66 +            SDL_SetError("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", mode_list.modes[i]);
   11.67              return NULL;
   11.68          }
   11.69          if(mode_info.bits_per_pixel == format->BitsPerPixel)
   11.70 @@ -120,22 +126,12 @@
   11.71  
   11.72  /* return the mode associated with width, height and bpp */
   11.73  /* if there is no mode then zero is returned             */
   11.74 -int get_mode(int width, int height, int bpp)
   11.75 +int ph_GetVideoMode(int width, int height, int bpp)
   11.76  {
   11.77      int i;
   11.78  
   11.79 -    if(width<640)
   11.80 -    {
   11.81 -        width=640;
   11.82 -    }
   11.83 -    if(height<480)
   11.84 -    {
   11.85 -        height=480;
   11.86 -    }
   11.87 -
   11.88      if (PgGetVideoModeList(&mode_list) < 0)
   11.89      {
   11.90 -        fprintf(stderr,"error: PgGetVideoModeList failed\n");
   11.91          return -1;
   11.92      }
   11.93  
   11.94 @@ -144,7 +140,6 @@
   11.95      {
   11.96          if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
   11.97          {
   11.98 -            fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
   11.99              return 0;
  11.100          }
  11.101  
  11.102 @@ -159,89 +154,124 @@
  11.103      return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
  11.104  }
  11.105  
  11.106 -int get_mode_any_format(int width, int height, int bpp)
  11.107  /* return the mode associated with width, height and bpp */
  11.108  /* if requested bpp is not found the mode with closest bpp is returned */
  11.109 +int get_mode_any_format(int width, int height, int bpp)
  11.110  {
  11.111      int i, closest, delta, min_delta;
  11.112  
  11.113 -	if (PgGetVideoModeList( &mode_list ) < 0)
  11.114 -	{
  11.115 -	    fprintf(stderr,"error: PgGetVideoModeList failed\n");
  11.116 -	    return -1;
  11.117 -	}
  11.118 +    if (PgGetVideoModeList(&mode_list) < 0)
  11.119 +    {
  11.120 +        return -1;
  11.121 +    }
  11.122  
  11.123 -	qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
  11.124 -	for(i=0;i<mode_list.num_modes;i++)
  11.125 -	{
  11.126 -       if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
  11.127 -       {
  11.128 -           fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
  11.129 -           return 0;
  11.130 -       }
  11.131 -       if ((mode_info.width == width) &&
  11.132 -           (mode_info.height == height))
  11.133 +    qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
  11.134 +
  11.135 +    for(i=0;i<mode_list.num_modes;i++)
  11.136 +    {
  11.137 +        if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
  11.138 +        {
  11.139 +            return 0;
  11.140 +        }
  11.141 +        if ((mode_info.width == width) && (mode_info.height == height))
  11.142 +        {
  11.143             break;
  11.144 -	}
  11.145 -	if (i<mode_list.num_modes)
  11.146 -	{
  11.147 -		/* get closest bpp */
  11.148 -		closest = i++;
  11.149 -		if (mode_info.bits_per_pixel == bpp)
  11.150 -			return mode_list.modes[closest];
  11.151 +        }
  11.152 +    }
  11.153  
  11.154 -		min_delta = abs(mode_info.bits_per_pixel - bpp);
  11.155 -		while(1)
  11.156 -		{
  11.157 -			if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
  11.158 -			{
  11.159 -			    fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
  11.160 -			    return 0;
  11.161 -			}
  11.162 +    if (i<mode_list.num_modes)
  11.163 +    {
  11.164 +        /* get closest bpp */
  11.165 +        closest = i++;
  11.166 +        if (mode_info.bits_per_pixel == bpp)
  11.167 +        {
  11.168 +            return mode_list.modes[closest];
  11.169 +        }
  11.170  
  11.171 -			if ((mode_info.width != width) ||
  11.172 -				(mode_info.height != height))
  11.173 -				break;
  11.174 -			else if (mode_info.bits_per_pixel == bpp)
  11.175 -			{
  11.176 -				closest = i;
  11.177 -				break;
  11.178 -			}
  11.179 -			else
  11.180 -			{
  11.181 -				delta = abs(mode_info.bits_per_pixel - bpp);
  11.182 -				if (delta < min_delta)
  11.183 -				{
  11.184 -					closest = i;
  11.185 -					min_delta = delta;
  11.186 -				}
  11.187 -				i++;
  11.188 -			}
  11.189 -		}
  11.190 -		return mode_list.modes[closest];
  11.191 -	}
  11.192 -	else
  11.193 +        min_delta = abs(mode_info.bits_per_pixel - bpp);
  11.194 +
  11.195 +        while(1)
  11.196 +        {
  11.197 +            if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
  11.198 +            {
  11.199 +                return 0;
  11.200 +            }
  11.201 +
  11.202 +            if ((mode_info.width != width) || (mode_info.height != height))
  11.203 +            {
  11.204 +                break;
  11.205 +            }
  11.206 +            else
  11.207 +            {
  11.208 +                if (mode_info.bits_per_pixel == bpp)
  11.209 +                {
  11.210 +                    closest = i;
  11.211 +                    break;
  11.212 +                }
  11.213 +                else
  11.214 +                {
  11.215 +                    delta = abs(mode_info.bits_per_pixel - bpp);
  11.216 +                    if (delta < min_delta)
  11.217 +                    {
  11.218 +                        closest = i;
  11.219 +                        min_delta = delta;
  11.220 +                    }
  11.221 +                    i++;
  11.222 +                }
  11.223 +            }
  11.224 +        }
  11.225 +        return mode_list.modes[closest];
  11.226 +    }
  11.227 +
  11.228      return 0;
  11.229  }
  11.230  
  11.231  int ph_ToggleFullScreen(_THIS, int on)
  11.232  {
  11.233 -    if (currently_fullscreen)
  11.234 -    {
  11.235 -        return ph_LeaveFullScreen(this);
  11.236 -    }
  11.237 -    else
  11.238 -    {
  11.239 -        return ph_EnterFullScreen(this);
  11.240 -    }
  11.241 -      
  11.242 -    return 0;     
  11.243 +    return -1;
  11.244  }
  11.245  
  11.246 -int ph_EnterFullScreen(_THIS)
  11.247 +int ph_EnterFullScreen(_THIS, SDL_Surface* screen)
  11.248  {
  11.249 +    PgDisplaySettings_t settings;
  11.250 +    int mode;
  11.251 +
  11.252      if (!currently_fullscreen)
  11.253      {
  11.254 +        /* Get the video mode and set it */
  11.255 +        if (screen->flags & SDL_ANYFORMAT)
  11.256 +        {
  11.257 +            if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
  11.258 +            {
  11.259 +                SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
  11.260 +                return 0;
  11.261 +            }
  11.262 +        }
  11.263 +        else
  11.264 +        {
  11.265 +            if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
  11.266 +            {
  11.267 +                SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
  11.268 +                return 0;
  11.269 +            }
  11.270 +        }
  11.271 +
  11.272 +        /* save old video mode caps */
  11.273 +        PgGetVideoMode(&settings);
  11.274 +        old_video_mode=settings.mode;
  11.275 +        old_refresh_rate=settings.refresh;
  11.276 +
  11.277 +        /* setup new video mode */
  11.278 +        settings.mode = mode;
  11.279 +        settings.refresh = 0;
  11.280 +        settings.flags = 0;
  11.281 +
  11.282 +        if (PgSetVideoMode(&settings) < 0)
  11.283 +        {
  11.284 +            SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
  11.285 +            return 0;
  11.286 +        }
  11.287 +
  11.288          if (this->screen)
  11.289          {
  11.290              if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
  11.291 @@ -255,12 +285,12 @@
  11.292          if (OCImage.direct_context==NULL)
  11.293          {
  11.294              OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
  11.295 -        }
  11.296 -
  11.297 -        if (!OCImage.direct_context)
  11.298 -        {
  11.299 -            fprintf(stderr, "ph_EnterFullScreen(): Can't create direct context !\n");
  11.300 -            return 0;
  11.301 +            if (!OCImage.direct_context)
  11.302 +            {
  11.303 +                SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
  11.304 +                ph_LeaveFullScreen(this);
  11.305 +                return 0;
  11.306 +            }
  11.307          }
  11.308  
  11.309          OCImage.oldDC=PdDirectStart(OCImage.direct_context);
  11.310 @@ -277,7 +307,7 @@
  11.311         
  11.312      if (currently_fullscreen)
  11.313      {
  11.314 -        if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
  11.315 +        if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
  11.316          {
  11.317  #ifdef HAVE_OPENGL
  11.318  #endif /* HAVE_OPENGL */
  11.319 @@ -285,22 +315,30 @@
  11.320          }
  11.321          else
  11.322          {
  11.323 -            PdDirectStop(OCImage.direct_context);
  11.324 -            PdReleaseDirectContext(OCImage.direct_context);
  11.325 -            PhDCSetCurrent(OCImage.oldDC);
  11.326 +            if (OCImage.direct_context)
  11.327 +            {
  11.328 +                PdDirectStop(OCImage.direct_context);
  11.329 +                PdReleaseDirectContext(OCImage.direct_context);
  11.330 +                OCImage.direct_context=NULL;
  11.331 +            }
  11.332 +            if (OCImage.oldDC)
  11.333 +            {
  11.334 +                PhDCSetCurrent(OCImage.oldDC);
  11.335 +                OCImage.oldDC=NULL;
  11.336 +            }
  11.337  
  11.338              currently_fullscreen=0;
  11.339  
  11.340              /* Restore old video mode */
  11.341              if (old_video_mode != -1)
  11.342              {
  11.343 -                mymode_settings.mode= (unsigned short) old_video_mode;
  11.344 -                mymode_settings.refresh= (unsigned short) old_refresh_rate;
  11.345 -                mymode_settings.flags= 0;
  11.346 +                mymode_settings.mode = (unsigned short) old_video_mode;
  11.347 +                mymode_settings.refresh = (unsigned short) old_refresh_rate;
  11.348 +                mymode_settings.flags = 0;
  11.349                  
  11.350                  if (PgSetVideoMode(&mymode_settings) < 0)
  11.351                  {
  11.352 -                    fprintf(stderr, "Ph_LeaveFullScreen(): PgSetVideoMode failed !\n");
  11.353 +                    SDL_SetError("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n");
  11.354                      return 0;
  11.355                  }
  11.356              }
  11.357 @@ -308,7 +346,6 @@
  11.358              old_video_mode=-1;
  11.359              old_refresh_rate=-1;
  11.360          }
  11.361 -
  11.362      }
  11.363      return 1;
  11.364  }
    12.1 --- a/src/video/photon/SDL_ph_modes_c.h	Mon Jul 28 01:47:55 2003 +0000
    12.2 +++ b/src/video/photon/SDL_ph_modes_c.h	Mon Aug 04 00:52:42 2003 +0000
    12.3 @@ -36,9 +36,9 @@
    12.4  extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags);
    12.5  extern void ph_FreeVideoModes(_THIS);
    12.6  extern int ph_ResizeFullScreen(_THIS);
    12.7 -extern int ph_EnterFullScreen(_THIS);
    12.8 +extern int ph_EnterFullScreen(_THIS, SDL_Surface* screen);
    12.9  extern int ph_LeaveFullScreen(_THIS);
   12.10 -extern int get_mode(int width, int height, int bpp);
   12.11 +extern int ph_GetVideoMode(int width, int height, int bpp);
   12.12  extern int get_mode_any_format(int width, int height, int bpp);
   12.13  extern int ph_ToggleFullScreen(_THIS, int on);
   12.14  
    13.1 --- a/src/video/photon/SDL_ph_mouse.c	Mon Jul 28 01:47:55 2003 +0000
    13.2 +++ b/src/video/photon/SDL_ph_mouse.c	Mon Aug 04 00:52:42 2003 +0000
    13.3 @@ -46,19 +46,18 @@
    13.4      {
    13.5          SDL_Lock_EventThread();
    13.6  
    13.7 -        if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0)
    13.8 +        if (PtSetResource(window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0) < 0)
    13.9          {
   13.10              /* TODO: output error msg */
   13.11          }
   13.12  
   13.13          SDL_Unlock_EventThread();
   13.14      }	
   13.15 -    /* free(cursor->ph_cursor.images); */
   13.16 +
   13.17      free(cursor);
   13.18  }
   13.19  
   13.20 -WMcursor *ph_CreateWMCursor(_THIS,
   13.21 -		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
   13.22 +WMcursor *ph_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
   13.23  {
   13.24      WMcursor* cursor;
   13.25      int clen, i;
   13.26 @@ -73,8 +72,12 @@
   13.27      memset(cursor,0,sizeof(WMcursor));
   13.28  
   13.29      cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
   13.30 +
   13.31      if (cursor->ph_cursor == NULL)
   13.32 -        printf("cursor malloc failed\n");
   13.33 +    {
   13.34 +        SDL_SetError("ph_CreateWMCursor(): cursor malloc failed !\n");
   13.35 +        return NULL;
   13.36 +    }
   13.37  
   13.38      memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
   13.39  
   13.40 @@ -137,7 +140,7 @@
   13.41          return (0);
   13.42      }
   13.43  
   13.44 -    /* Set the photon cursor cursor, or blank if cursor is NULL */
   13.45 +    /* Set the photon cursor, or blank if cursor is NULL */
   13.46      if (cursor!=NULL)
   13.47      {
   13.48          PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
   13.49 @@ -148,7 +151,7 @@
   13.50      }
   13.51      else /* Ph_CURSOR_NONE */
   13.52      {
   13.53 -        PtSetArg( &args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
   13.54 +        PtSetArg(&args[0], Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
   13.55          nargs = 1;
   13.56      }
   13.57  
    14.1 --- a/src/video/photon/SDL_ph_video.c	Mon Jul 28 01:47:55 2003 +0000
    14.2 +++ b/src/video/photon/SDL_ph_video.c	Mon Aug 04 00:52:42 2003 +0000
    14.3 @@ -59,9 +59,12 @@
    14.4  static void ph_UpdateMouse(_THIS);
    14.5  
    14.6  #ifdef HAVE_OPENGL
    14.7 -int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
    14.8 +static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags);
    14.9  static void ph_GL_SwapBuffers(_THIS);
   14.10  static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
   14.11 +static int ph_GL_LoadLibrary(_THIS, const char* path);
   14.12 +static void* ph_GL_GetProcAddress(_THIS, const char* proc);
   14.13 +
   14.14  #endif /* HAVE_OPENGL */
   14.15  
   14.16  static int ph_Available(void)
   14.17 @@ -109,7 +112,7 @@
   14.18      device->ToggleFullScreen = ph_ToggleFullScreen;
   14.19      device->UpdateMouse = ph_UpdateMouse;
   14.20      device->SetColors = ph_SetColors;
   14.21 -    device->UpdateRects = NULL;         /* ph_SetupUpdateFunction */
   14.22 +    device->UpdateRects = NULL;         /* set up in ph_SetupUpdateFunction */
   14.23      device->VideoQuit = ph_VideoQuit;
   14.24      device->AllocHWSurface = ph_AllocHWSurface;
   14.25      device->CheckHWBlit = NULL;
   14.26 @@ -134,19 +137,21 @@
   14.27      device->PumpEvents = ph_PumpEvents;
   14.28  
   14.29      /* OpenGL support. */
   14.30 -    device->GL_LoadLibrary = NULL;
   14.31 -    device->GL_GetProcAddress = NULL;
   14.32      device->GL_MakeCurrent = NULL;
   14.33  #ifdef HAVE_OPENGL
   14.34      device->GL_SwapBuffers = ph_GL_SwapBuffers;
   14.35      device->GL_GetAttribute = ph_GL_GetAttribute;
   14.36 +    device->GL_LoadLibrary = ph_GL_LoadLibrary;
   14.37 +    device->GL_GetProcAddress = ph_GL_GetProcAddress;
   14.38  #else
   14.39      device->GL_SwapBuffers = NULL;
   14.40      device->GL_GetAttribute = NULL;
   14.41 +    device->GL_LoadLibrary = NULL;
   14.42 +    device->GL_GetProcAddress = NULL;
   14.43  #endif /* HAVE_OPENGL */
   14.44  
   14.45      device->free = ph_DeleteDevice;
   14.46 -
   14.47 +    
   14.48      return device;
   14.49  }
   14.50  
   14.51 @@ -179,10 +184,6 @@
   14.52      PtWidget_t *widget;
   14.53      
   14.54      widget = PtCreateWidget(PtWindow, NULL, 0, 0);
   14.55 -    if (widget == NULL)
   14.56 -    {
   14.57 -        SDL_SetError("Couldn't create video window");
   14.58 -    }
   14.59  
   14.60      return widget;
   14.61  }
   14.62 @@ -199,28 +200,38 @@
   14.63  
   14.64      if ((flags & SDL_RESIZABLE) == SDL_RESIZABLE)
   14.65      {
   14.66 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
   14.67 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MAX);
   14.68 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX);
   14.69 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_CLOSE);
   14.70 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_MAX | Ph_WM_RESTORE);
   14.71 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_RESIZE | Ph_WM_MOVE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE);
   14.72 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
   14.73      }
   14.74      else
   14.75      {
   14.76 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
   14.77 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX);
   14.78 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE);
   14.79 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE | Ph_WM_CLOSE);
   14.80 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE, Ph_WM_RESIZE | Ph_WM_MAX | Ph_WM_RESTORE);
   14.81 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_MOVE | Ph_WM_CLOSE);
   14.82 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RETURN);
   14.83      }
   14.84  
   14.85      if (((flags & SDL_NOFRAME)==SDL_NOFRAME) || ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN))
   14.86      {
   14.87 -        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
   14.88 +       if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)
   14.89 +       {
   14.90 +           PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
   14.91 +       }
   14.92 +       else
   14.93 +       {
   14.94 +           PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Pt_TRUE);
   14.95 +           PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_BORDER);
   14.96 +       }
   14.97      }
   14.98      else
   14.99      {
  14.100          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, Ph_WM_RENDER_BORDER | Ph_WM_RENDER_TITLE |
  14.101 -                                  Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
  14.102 +                                 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN);
  14.103      }
  14.104  
  14.105 -    if (flags & SDL_FULLSCREEN)
  14.106 +    if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
  14.107      {
  14.108          PtSetArg(&args[nargs++], Pt_ARG_POS, &pos, 0);
  14.109          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_MAX);
  14.110 @@ -231,6 +242,7 @@
  14.111      {
  14.112          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISMAX | Ph_WM_STATE_ISALTKEY);
  14.113          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
  14.114 +        PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE);
  14.115          PtSetArg(&args[nargs++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
  14.116      }
  14.117  
  14.118 @@ -240,10 +252,38 @@
  14.119      return 0;
  14.120  }
  14.121  
  14.122 +static const struct ColourMasks* ph_GetColourMasks(int bpp)
  14.123 +{
  14.124 +    /* The alpha mask doesn't appears to be needed */
  14.125 +    static const struct ColourMasks phColorMasks[5] = {
  14.126 +        /*  8 bit      */  {0, 0, 0, 0, 8},
  14.127 +        /* 15 bit ARGB */  {0x7C00, 0x03E0, 0x001F, 0x8000, 15},
  14.128 +        /* 16 bit  RGB */  {0xF800, 0x07E0, 0x001F, 0x0000, 16},
  14.129 +        /* 24 bit  RGB */  {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
  14.130 +        /* 32 bit ARGB */  {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
  14.131 +    };
  14.132 +
  14.133 +    switch (bpp)
  14.134 +    {
  14.135 +        case 8:
  14.136 +             return &phColorMasks[0];
  14.137 +        case 15:
  14.138 +             return &phColorMasks[1];
  14.139 +        case 16:
  14.140 +             return &phColorMasks[2];
  14.141 +        case 24:
  14.142 +             return &phColorMasks[3];
  14.143 +        case 32:
  14.144 +             return &phColorMasks[4];
  14.145 +    }
  14.146 +    return NULL;
  14.147 +}
  14.148 +
  14.149  static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
  14.150  {
  14.151      PgVideoModeInfo_t my_mode_info;
  14.152      PgHWCaps_t my_hwcaps;
  14.153 +    int i;
  14.154  
  14.155      window=NULL;
  14.156      desktoppal=SDLPH_PAL_NONE;
  14.157 @@ -264,6 +304,7 @@
  14.158      window = ph_CreateWindow(this);
  14.159      if (window == NULL)
  14.160      {
  14.161 +        SDL_SetError("ph_VideoInit(): Couldn't create video window !\n");
  14.162          return -1;
  14.163      }
  14.164  
  14.165 @@ -274,17 +315,21 @@
  14.166  
  14.167      if (SDL_BlankCursor == NULL)
  14.168      {
  14.169 -        fprintf(stderr, "ph_VideoInit(): could not create blank cursor !\n");
  14.170 +        return -1;
  14.171      }
  14.172  
  14.173      if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
  14.174      {
  14.175 -        fprintf(stderr,"ph_VideoInit(): GetGraphicsHWCaps failed !\n");
  14.176 +        SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
  14.177 +        this->FreeWMCursor(this, SDL_BlankCursor);
  14.178 +        return -1;
  14.179      }
  14.180  
  14.181      if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
  14.182      {
  14.183 -        fprintf(stderr,"ph_VideoInit(): PgGetVideoModeInfo failed !\n");
  14.184 +        SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
  14.185 +        this->FreeWMCursor(this, SDL_BlankCursor);
  14.186 +        return -1;
  14.187      }
  14.188  
  14.189      /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
  14.190 @@ -298,8 +343,27 @@
  14.191          PgGetPalette(savedpal);
  14.192          PgGetPalette(syspalph);
  14.193      }
  14.194 +    else
  14.195 +    {
  14.196 +        for(i=0; i<_Pg_MAX_PALETTE; i++)
  14.197 +        {
  14.198 +            savedpal[i]=PgRGB(0, 0, 0);
  14.199 +            syspalph[i]=PgRGB(0, 0, 0);
  14.200 +        }
  14.201 +    }
  14.202           
  14.203      currently_fullscreen = 0;
  14.204 +    currently_hided = 0;
  14.205 +    current_overlay = NULL;
  14.206 +
  14.207 +    OCImage.direct_context = NULL;
  14.208 +    OCImage.offscreen_context = NULL;
  14.209 +    OCImage.offscreen_backcontext = NULL;
  14.210 +    OCImage.oldDC = NULL;
  14.211 +    OCImage.CurrentFrameData = NULL;
  14.212 +    OCImage.FrameData0 = NULL;
  14.213 +    OCImage.FrameData1 = NULL;
  14.214 +
  14.215      
  14.216      this->info.wm_available = 1;
  14.217      
  14.218 @@ -309,18 +373,33 @@
  14.219  static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
  14.220                  int width, int height, int bpp, Uint32 flags)
  14.221  {
  14.222 -    PgDisplaySettings_t settings;
  14.223 -    SDL_Color* colors;
  14.224 -    int mode;
  14.225 -    int rtnval;
  14.226 -    int i;
  14.227 +    const struct ColourMasks* mask;
  14.228  
  14.229      /* Lock the event thread, in multi-threading environments */
  14.230      SDL_Lock_EventThread();
  14.231  
  14.232      current->flags = flags;
  14.233  
  14.234 -    ph_SetupWindow(this, width, height, flags);
  14.235 +    /* if we do not have desired fullscreen mode, then fallback into window mode */
  14.236 +    if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0))
  14.237 +    {
  14.238 +       current->flags &= ~SDL_FULLSCREEN;
  14.239 +       current->flags &= ~SDL_NOFRAME;
  14.240 +       current->flags &= ~SDL_RESIZABLE;
  14.241 +    }
  14.242 +
  14.243 +    ph_SetupWindow(this, width, height, current->flags);
  14.244 +
  14.245 +    mask = ph_GetColourMasks(bpp);
  14.246 +    if (mask != NULL)
  14.247 +    {
  14.248 +        SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0);
  14.249 +    }
  14.250 +    else
  14.251 +    {
  14.252 +        SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n");
  14.253 +        return NULL;
  14.254 +    }
  14.255  
  14.256  #ifdef HAVE_OPENGL
  14.257      if (current->flags & SDL_OPENGL)
  14.258 @@ -334,72 +413,41 @@
  14.259          {
  14.260              /* if context creation fail, report no OpenGL to high level */
  14.261              current->flags &= ~SDL_OPENGL;
  14.262 +            return NULL;
  14.263          }
  14.264  #else
  14.265      if (current->flags & SDL_OPENGL) /* if no built-in OpenGL support */
  14.266      {
  14.267 -        fprintf(stderr, "ph_SetVideoMode(): no OpenGL support, try to recompile library.\n");
  14.268 +        SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n");
  14.269          current->flags &= ~SDL_OPENGL;
  14.270          return NULL;
  14.271  #endif /* HAVE_OPENGL */
  14.272      }
  14.273      else
  14.274      {
  14.275 -        /* Initialize the window */
  14.276 -        if (current->flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */
  14.277 +        /* Initialize internal variables */
  14.278 +        if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
  14.279          {
  14.280 -            /* Get the video mode and set it */
  14.281 -            if (current->flags & SDL_ANYFORMAT)
  14.282 -            {
  14.283 -                if ((mode = get_mode_any_format(width, height, bpp)) == 0)
  14.284 -                {
  14.285 -                    fprintf(stderr,"ph_SetVideoMode(): get_mode_any_format failed !\n");
  14.286 -                    exit(1);
  14.287 -                }
  14.288 -            }
  14.289 -            else
  14.290 -            {
  14.291 -                if ((mode = get_mode(width, height, bpp)) == 0)
  14.292 -                {
  14.293 -                    fprintf(stderr,"ph_SetVideoMode(): get_mode failed !\n");
  14.294 -                    exit(1);
  14.295 -                }
  14.296 -            }
  14.297 -            
  14.298              if (bpp==8)
  14.299              {
  14.300                 desktoppal=SDLPH_PAL_SYSTEM;
  14.301              }
  14.302 -            
  14.303 -            /* save old video mode caps */
  14.304 -            PgGetVideoMode(&settings);
  14.305 -            old_video_mode=settings.mode;
  14.306 -            old_refresh_rate=settings.refresh;
  14.307 -
  14.308 -            /* setup new video mode */
  14.309 -            settings.mode = mode;
  14.310 -            settings.refresh = 0;
  14.311 -            settings.flags = 0;
  14.312 -
  14.313 -            if (PgSetVideoMode(&settings) < 0)
  14.314 -            {
  14.315 -                fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n");
  14.316 -            }
  14.317  
  14.318              current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */
  14.319 -            current->flags |= SDL_HWSURFACE;
  14.320 -
  14.321 -            /* Begin direct mode */
  14.322 -            ph_EnterFullScreen(this);
  14.323 -
  14.324 -        } /* end fullscreen flag */
  14.325 +        }
  14.326          else
  14.327          {
  14.328 -            /* Use offscreen memory iff SDL_HWSURFACE flag is set */
  14.329 -            if (current->flags & SDL_HWSURFACE)
  14.330 +            /* remove this if we'll support non-fullscreen sw/hw+doublebuf */
  14.331 +            current->flags &= ~SDL_DOUBLEBUF;
  14.332 +
  14.333 +            /* Use offscreen memory if SDL_HWSURFACE flag is set */
  14.334 +            if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
  14.335              {
  14.336 -                /* no stretch blit in offscreen context */
  14.337 -                current->flags &= ~SDL_RESIZABLE;
  14.338 +
  14.339 +                if (desktopbpp!=bpp)
  14.340 +                {
  14.341 +                   current->flags &= ~SDL_HWSURFACE;
  14.342 +                }
  14.343              }
  14.344  
  14.345              /* using palette emulation code in window mode */
  14.346 @@ -407,33 +455,16 @@
  14.347              {
  14.348                  if (desktopbpp>=15)
  14.349                  {
  14.350 -                    desktoppal=SDLPH_PAL_EMULATE;
  14.351 +                    desktoppal = SDLPH_PAL_EMULATE;
  14.352                  }
  14.353                  else
  14.354                  {
  14.355 -                    desktoppal=SDLPH_PAL_SYSTEM;
  14.356 -                }
  14.357 -
  14.358 -                /* fill the palette */
  14.359 -                PgGetPalette(savedpal);
  14.360 -                PgGetPalette(syspalph);
  14.361 -
  14.362 -                current->format->palette = calloc(1, sizeof(SDL_Palette));
  14.363 -                current->format->palette->ncolors = _Pg_MAX_PALETTE;
  14.364 -                current->format->palette->colors = (SDL_Color *)calloc(_Pg_MAX_PALETTE, sizeof(SDL_Color));
  14.365 -
  14.366 -                colors = current->format->palette->colors;
  14.367 -
  14.368 -                for(i=0; i<256; i++)
  14.369 -                {
  14.370 -                    colors[i].r = PgRedValue(syspalph[i]);
  14.371 -                    colors[i].g = PgGreenValue(syspalph[i]);
  14.372 -                    colors[i].b = PgBlueValue(syspalph[i]);
  14.373 +                    desktoppal = SDLPH_PAL_SYSTEM;
  14.374                  }
  14.375              }
  14.376              else
  14.377              {
  14.378 -               desktoppal=SDLPH_PAL_NONE;
  14.379 +               desktoppal = SDLPH_PAL_NONE;
  14.380              }
  14.381          }
  14.382      }
  14.383 @@ -441,22 +472,22 @@
  14.384      current->w = width;
  14.385      current->h = height;
  14.386  
  14.387 -    /* These values can be overridden in ph_SetupUpdateFunction() */
  14.388 -    current->format->BitsPerPixel = bpp;
  14.389 -    current->format->BytesPerPixel = (bpp+7)/8;
  14.390 -    current->pitch = SDL_CalculatePitch(current);
  14.391 +    if (desktoppal==SDLPH_PAL_SYSTEM)
  14.392 +    {
  14.393 +       current->flags|=SDL_HWPALETTE;
  14.394 +    }
  14.395  
  14.396 -    /* Must call at least once it setup image planes */
  14.397 -    rtnval = ph_SetupUpdateFunction(this, current, current->flags);
  14.398 -    
  14.399 -    if (rtnval==-1)
  14.400 +    /* Must call at least once for setup image planes */
  14.401 +    if (ph_SetupUpdateFunction(this, current, current->flags)==-1)
  14.402      {
  14.403 -        fprintf(stderr,"ph_SetVideoMode(): ph_SetupUpdateFunction failed !\n");
  14.404          return NULL;
  14.405      }
  14.406  
  14.407 -    /* finish window drawing */
  14.408 -    PtFlush();
  14.409 +    /* finish window drawing, if we are not in fullscreen, of course */
  14.410 +    if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
  14.411 +    {
  14.412 +       PtFlush();
  14.413 +    }
  14.414  
  14.415      SDL_Unlock_EventThread();
  14.416  
  14.417 @@ -470,13 +501,16 @@
  14.418      PhRegion_t region_info;
  14.419  #endif /* HAVE_OPENGL */
  14.420  
  14.421 +    /* restore palette */
  14.422 +    if (desktopbpp==8)
  14.423 +    {
  14.424 +        PgSetPalette(syspalph, 0, -1, 0, 0, 0);
  14.425 +        PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
  14.426 +        PgFlush();
  14.427 +    }
  14.428 +
  14.429      ph_DestroyImage(this, SDL_VideoSurface); 
  14.430  
  14.431 -    if (currently_fullscreen)
  14.432 -    {
  14.433 -        ph_LeaveFullScreen(this);
  14.434 -    }
  14.435 -
  14.436  #ifdef HAVE_OPENGL
  14.437      /* prevent double SEGFAULT during parachute mode */
  14.438      if (this->screen)
  14.439 @@ -509,14 +543,6 @@
  14.440      }
  14.441  #endif /* HAVE_OPENGL */
  14.442  
  14.443 -    /* restore palette */
  14.444 -    if (desktoppal!=SDLPH_PAL_NONE)
  14.445 -    {
  14.446 -        PgSetPalette(savedpal, 1, 0, _Pg_MAX_PALETTE, Pg_PALSET_HARD | Pg_PALSET_FORCE_EXPOSE, 0);
  14.447 -        /* pass -1, to force release palette */
  14.448 -        PgSetPalette(savedpal, 1, 0, -1, Pg_PALSET_HARD | Pg_PALSET_FORCE_EXPOSE, 0);
  14.449 -    }
  14.450 -
  14.451      if (event!=NULL)
  14.452      {
  14.453          free(event);
  14.454 @@ -543,6 +569,7 @@
  14.455                  syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b);
  14.456                  SDL_Image->palette[i] = syspalph[i];
  14.457              }
  14.458 +
  14.459              /* image needs to be redrawn */
  14.460              this->UpdateRects(this, 1, &updaterect);
  14.461          }
  14.462 @@ -559,14 +586,14 @@
  14.463              if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
  14.464              {
  14.465                   /* window mode must use soft palette */
  14.466 -                PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
  14.467 +                PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
  14.468                  /* image needs to be redrawn */
  14.469                  this->UpdateRects(this, 1, &updaterect);
  14.470              }
  14.471              else
  14.472              {
  14.473                  /* fullscreen mode must use hardware palette */
  14.474 -                PgSetPalette(&syspalph[firstcolor], 1, firstcolor, ncolors, Pg_PALSET_HARDLOCKED, 0);
  14.475 +                PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
  14.476              }
  14.477          }
  14.478          else
  14.479 @@ -628,7 +655,7 @@
  14.480  
  14.481      if (oglctx==NULL)
  14.482      {
  14.483 -        fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n");
  14.484 +        SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n");
  14.485          return (-1);
  14.486      }
  14.487  
  14.488 @@ -675,6 +702,19 @@
  14.489      return 0;
  14.490  }
  14.491  
  14.492 +int ph_GL_LoadLibrary(_THIS, const char* path)
  14.493 +{
  14.494 +   /* if code compiled with HAVE_OPENGL, the library already linked */
  14.495 +   this->gl_config.driver_loaded = 1;
  14.496 +
  14.497 +   return 0;
  14.498 +}
  14.499 +
  14.500 +void* ph_GL_GetProcAddress(_THIS, const char* proc)
  14.501 +{
  14.502 +   return NULL;
  14.503 +}
  14.504 +
  14.505  #endif /* HAVE_OPENGL */
  14.506  
  14.507  static void ph_UpdateMouse(_THIS)
    15.1 --- a/src/video/photon/SDL_ph_video.h	Mon Jul 28 01:47:55 2003 +0000
    15.2 +++ b/src/video/photon/SDL_ph_video.h	Mon Aug 04 00:52:42 2003 +0000
    15.3 @@ -20,22 +20,23 @@
    15.4      slouken@libsdl.org
    15.5  */
    15.6  
    15.7 -#ifndef _SDL_ph_video_h
    15.8 -#define _SDL_ph_video_h
    15.9 +#ifndef __SDL_PH_VIDEO_H__
   15.10 +#define __SDL_PH_VIDEO_H__
   15.11  
   15.12  #include "SDL_mouse.h"
   15.13  #include "SDL_sysvideo.h"
   15.14  
   15.15 -#include "Ph.h"
   15.16 -#include "Pt.h"
   15.17 +#include <Ph.h>
   15.18 +#include <Pt.h>
   15.19  #include <photon/Pg.h>
   15.20  #include <photon/PdDirect.h>
   15.21 +
   15.22  #ifdef HAVE_OPENGL
   15.23 -#include <photon/PdGL.h>
   15.24 +    #include <photon/PdGL.h>
   15.25  #endif /* HAVE_OPENGL */
   15.26  
   15.27  /* Hidden "this" pointer for the video functions */
   15.28 -#define _THIS	SDL_VideoDevice *this
   15.29 +#define _THIS	SDL_VideoDevice* this
   15.30  
   15.31  #define PH_OGL_MAX_ATTRIBS 32
   15.32  
   15.33 @@ -43,18 +44,23 @@
   15.34  #define SDLPH_PAL_EMULATE 0x00000001L
   15.35  #define SDLPH_PAL_SYSTEM  0x00000002L
   15.36  
   15.37 -typedef union vidptr{
   15.38 -  uint8_t*  volatile ptr8;
   15.39 -  uint16_t* volatile ptr16;
   15.40 -  uint32_t* volatile ptr32;
   15.41 - } VidPtr_t;
   15.42 -
   15.43 -typedef struct {
   15.44 +typedef struct
   15.45 +{
   15.46  	unsigned char* Y;
   15.47  	unsigned char* V;
   15.48  	unsigned char* U;
   15.49  } FRAMEDATA;
   15.50  
   15.51 +/* Mask values for SDL_ReallocFormat() */
   15.52 +struct ColourMasks
   15.53 +{
   15.54 +    Uint32 red;
   15.55 +    Uint32 green;
   15.56 +    Uint32 blue;
   15.57 +    Uint32 alpha;
   15.58 +    Uint32 bpp;
   15.59 +};
   15.60 +
   15.61  /* Private display data */
   15.62  struct SDL_PrivateVideoData {
   15.63      PgDisplaySettings_t mode_settings;	
   15.64 @@ -69,8 +75,9 @@
   15.65      struct {
   15.66          PdDirectContext_t*    direct_context;
   15.67          PdOffscreenContext_t* offscreen_context;
   15.68 +        PdOffscreenContext_t* offscreen_backcontext;
   15.69          PhDrawContext_t*      oldDC;
   15.70 -        VidPtr_t dc_ptr;
   15.71 +        uint8_t*              dc_ptr;
   15.72          unsigned char* CurrentFrameData;
   15.73          unsigned char* FrameData0;
   15.74          unsigned char* FrameData1;
   15.75 @@ -85,13 +92,15 @@
   15.76      int mouse_relative;
   15.77      WMcursor* BlankCursor;
   15.78  
   15.79 -    int depth;			/* current visual depth (not bpp)        */
   15.80 -    int desktopbpp;             /* bpp of desktop at the moment of start */
   15.81 -    int desktoppal;             /* palette mode emulation or system      */
   15.82 +    int depth;			/* current visual depth (not bpp)           */
   15.83 +    int desktopbpp;             /* bpp of desktop at the moment of start    */
   15.84 +    int desktoppal;             /* palette mode emulation or system         */
   15.85  
   15.86      int currently_fullscreen;
   15.87 +    int currently_hided;        /* 1 - window hided (minimazed), 0 - normal */
   15.88  
   15.89      PhEvent_t* event;
   15.90 +    SDL_Overlay* overlay;
   15.91  };
   15.92  
   15.93  #define mode_settings        (this->hidden->mode_settings)
   15.94 @@ -106,11 +115,13 @@
   15.95  #define desktoppal           (this->hidden->desktoppal)
   15.96  #define savedpal             (this->hidden->savedpal)
   15.97  #define syspalph             (this->hidden->syspalph)
   15.98 +#define currently_fullscreen (this->hidden->currently_fullscreen)
   15.99 +#define currently_hided      (this->hidden->currently_hided)
  15.100 +#define event                (this->hidden->event)
  15.101 +#define current_overlay      (this->hidden->overlay)
  15.102  
  15.103  /* Old variable names */
  15.104  #define mouse_relative       (this->hidden->mouse_relative)
  15.105 -#define currently_fullscreen (this->hidden->currently_fullscreen)
  15.106 -#define event                (this->hidden->event)
  15.107  #define SDL_BlankCursor      (this->hidden->BlankCursor)
  15.108  
  15.109 -#endif /* _SDL_x11video_h */
  15.110 +#endif /* __SDL_PH_VIDEO_H__ */
    16.1 --- a/src/video/photon/SDL_ph_wm.c	Mon Jul 28 01:47:55 2003 +0000
    16.2 +++ b/src/video/photon/SDL_ph_wm.c	Mon Aug 04 00:52:42 2003 +0000
    16.3 @@ -75,8 +75,9 @@
    16.4      memset( &windowevent, 0, sizeof (event) );
    16.5      windowevent.event_f = Ph_WM_HIDE;
    16.6      windowevent.event_state = Ph_WM_EVSTATE_HIDE;
    16.7 -    windowevent.rid = PtWidgetRid( window );
    16.8 -    PtForwardWindowEvent( &windowevent );
    16.9 +    windowevent.rid = PtWidgetRid(window);
   16.10 +    PtForwardWindowEvent(&windowevent);
   16.11 +
   16.12      SDL_Unlock_EventThread();
   16.13  
   16.14      return 0;
    17.1 --- a/src/video/photon/SDL_phyuv.c	Mon Jul 28 01:47:55 2003 +0000
    17.2 +++ b/src/video/photon/SDL_phyuv.c	Mon Aug 04 00:52:42 2003 +0000
    17.3 @@ -25,7 +25,7 @@
    17.4   "@(#) $Id$";
    17.5  #endif
    17.6  
    17.7 -/* This is the QNX Realtime Platform version for SDL YUV video overlays */
    17.8 +/* This is the QNX Realtime Platform version of SDL YUV video overlays */
    17.9  
   17.10  #include <stdlib.h>
   17.11  #include <string.h>
   17.12 @@ -43,36 +43,15 @@
   17.13  #define OVERLAY_STATE_ACTIVE 1
   17.14  
   17.15  /* The functions used to manipulate software video overlays */
   17.16 -static struct private_yuvhwfuncs ph_yuvfuncs = {
   17.17 +static struct private_yuvhwfuncs ph_yuvfuncs =
   17.18 +{
   17.19      ph_LockYUVOverlay,
   17.20      ph_UnlockYUVOverlay,
   17.21      ph_DisplayYUVOverlay,
   17.22      ph_FreeYUVOverlay
   17.23  };
   17.24  
   17.25 -struct private_yuvhwdata {
   17.26 -    FRAMEDATA* CurrentFrameData;
   17.27 -    FRAMEDATA* FrameData0;
   17.28 -    FRAMEDATA* FrameData1;
   17.29 -    PgScalerProps_t   props;
   17.30 -    PgScalerCaps_t    caps;
   17.31 -    PgVideoChannel_t* channel;
   17.32 -    PhArea_t CurrentWindow;
   17.33 -    long format;
   17.34 -    int planar;
   17.35 -    int scaler_on;
   17.36 -    int current;
   17.37 -    long YStride;
   17.38 -    long VStride;
   17.39 -    long UStride;
   17.40 -    int ischromakey;
   17.41 -    long chromakey;
   17.42 -    unsigned long State;
   17.43 -    long flags;
   17.44 -    int locked;
   17.45 -};
   17.46 -
   17.47 -int grab_ptrs2(PgVideoChannel_t* channel, FRAMEDATA* Frame0, FRAMEDATA* Frame1 )
   17.48 +int grab_ptrs2(PgVideoChannel_t* channel, FRAMEDATA* Frame0, FRAMEDATA* Frame1)
   17.49  {
   17.50      int planes = 0;
   17.51  
   17.52 @@ -96,11 +75,11 @@
   17.53      return planes;
   17.54  }
   17.55  
   17.56 -SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
   17.57 +SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display)
   17.58  {
   17.59 -    SDL_Overlay *overlay;
   17.60 -    struct private_yuvhwdata *hwdata;
   17.61 -    int xv_port;
   17.62 +    SDL_Overlay* overlay;
   17.63 +    struct private_yuvhwdata* hwdata;
   17.64 +    int vidport;
   17.65      int rtncode;
   17.66      int planes;
   17.67      int i=0;
   17.68 @@ -109,15 +88,17 @@
   17.69      /* Create the overlay structure */
   17.70      overlay = calloc(1, sizeof(SDL_Overlay));
   17.71  
   17.72 -    if (overlay == NULL) {
   17.73 +    if (overlay == NULL)
   17.74 +    {
   17.75          SDL_OutOfMemory();
   17.76 -        return (NULL);
   17.77 +        return NULL;
   17.78      }
   17.79  
   17.80      /* Fill in the basic members */
   17.81      overlay->format = format;
   17.82      overlay->w = width;
   17.83      overlay->h = height;
   17.84 +    overlay->hwdata = NULL;
   17.85  	
   17.86      /* Set up the YUV surface function structure */
   17.87      overlay->hwfuncs = &ph_yuvfuncs;
   17.88 @@ -125,36 +106,41 @@
   17.89      /* Create the pixel data and lookup tables */
   17.90      hwdata = calloc(1, sizeof(struct private_yuvhwdata));
   17.91  
   17.92 -    overlay->hwdata = hwdata;
   17.93 -    if (hwdata == NULL) {
   17.94 +    if (hwdata == NULL)
   17.95 +    {
   17.96          SDL_OutOfMemory();
   17.97          SDL_FreeYUVOverlay(overlay);
   17.98 -        return(NULL);
   17.99 +        return NULL;
  17.100      }
  17.101  
  17.102 +    overlay->hwdata = hwdata;
  17.103 +
  17.104      PhDCSetCurrent(0);
  17.105      if (overlay->hwdata->channel == NULL)
  17.106      {
  17.107 -        if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) 
  17.108 +        if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER, 0)) == NULL)
  17.109          {
  17.110              SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror(errno));
  17.111              SDL_FreeYUVOverlay(overlay);
  17.112 -
  17.113 -            return(NULL);
  17.114 +            return NULL;
  17.115  
  17.116          }
  17.117      }
  17.118  
  17.119 +    overlay->hwdata->forcedredraw=0;
  17.120 +
  17.121      PtGetAbsPosition(window, &pos.x, &pos.y);
  17.122 -    overlay->hwdata->CurrentWindow.pos.x = pos.x;
  17.123 -    overlay->hwdata->CurrentWindow.pos.y = pos.y;
  17.124 -    overlay->hwdata->CurrentWindow.size.w = width;
  17.125 -    overlay->hwdata->CurrentWindow.size.h = height;
  17.126 +    overlay->hwdata->CurrentWindowPos.x = pos.x;
  17.127 +    overlay->hwdata->CurrentWindowPos.y = pos.y;
  17.128 +    overlay->hwdata->CurrentViewPort.pos.x = 0;
  17.129 +    overlay->hwdata->CurrentViewPort.pos.y = 0;
  17.130 +    overlay->hwdata->CurrentViewPort.size.w = width;
  17.131 +    overlay->hwdata->CurrentViewPort.size.h = height;
  17.132      overlay->hwdata->State = OVERLAY_STATE_UNINIT;
  17.133      overlay->hwdata->FrameData0 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
  17.134      overlay->hwdata->FrameData1 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
  17.135  
  17.136 -    xv_port = -1;
  17.137 +    vidport = -1;
  17.138      i=0;
  17.139      
  17.140      overlay->hwdata->ischromakey=0;
  17.141 @@ -171,7 +157,7 @@
  17.142                 {
  17.143                     overlay->hwdata->ischromakey=1;
  17.144                 }
  17.145 -               xv_port=1;
  17.146 +               vidport=1;
  17.147                 break;
  17.148              }
  17.149          }
  17.150 @@ -183,33 +169,28 @@
  17.151      } while(1);
  17.152  
  17.153  
  17.154 -    if (xv_port == -1)
  17.155 +    if (vidport == -1)
  17.156      {
  17.157          SDL_SetError("No available video ports for requested format\n");
  17.158          SDL_FreeYUVOverlay(overlay);
  17.159 -        return(NULL);
  17.160 +        return NULL;
  17.161      }
  17.162 - 
  17.163 +
  17.164      overlay->hwdata->format = format;
  17.165      overlay->hwdata->props.format = format;
  17.166      overlay->hwdata->props.size = sizeof(PgScalerProps_t);
  17.167 -    overlay->hwdata->props.src_dim.w = width;   
  17.168 -    overlay->hwdata->props.src_dim.h = height;   
  17.169 -	
  17.170 -    /* Don't use chromakey for now, blitting a surface will cover the window,
  17.171 -     * and therefore the chroma. */
  17.172 -    overlay->hwdata->chromakey = 0;
  17.173 -    PtSetResource(window, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0);
  17.174 +    overlay->hwdata->props.src_dim.w = width;
  17.175 +    overlay->hwdata->props.src_dim.h = height;
  17.176  
  17.177 -    PhAreaToRect(&overlay->hwdata->CurrentWindow, &overlay->hwdata->props.viewport);
  17.178 +    overlay->hwdata->chromakey = PgGetOverlayChromaColor();
  17.179 +
  17.180 +    PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
  17.181  
  17.182      overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER;
  17.183  
  17.184      if ((overlay->hwdata->ischromakey)&&(overlay->hwdata->chromakey))
  17.185      {
  17.186          overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
  17.187 -        overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
  17.188 -        overlay->hwdata->props.color_key_mask = 0x00FFFFFFUL;
  17.189      } 
  17.190      else
  17.191      {
  17.192 @@ -221,9 +202,8 @@
  17.193      switch(rtncode)
  17.194      {
  17.195          case -1: SDL_SetError("PgConfigScalerChannel failed\n");
  17.196 -		 SDL_FreeYUVOverlay(overlay);
  17.197 -		 return(NULL);
  17.198 -   		 break;
  17.199 +                 SDL_FreeYUVOverlay(overlay);
  17.200 +                 return NULL;
  17.201          case 1:
  17.202          case 0:
  17.203          default:
  17.204 @@ -232,21 +212,39 @@
  17.205  
  17.206      planes = grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  17.207  
  17.208 -    if(overlay->hwdata->channel->yplane1 != NULL)			
  17.209 +    if(overlay->hwdata->channel->yplane1 != NULL)
  17.210          overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
  17.211 -    if(overlay->hwdata->channel->uplane1 != NULL)			
  17.212 +    if(overlay->hwdata->channel->uplane1 != NULL)
  17.213          overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
  17.214 -    if(overlay->hwdata->channel->vplane1 != NULL)			
  17.215 +    if(overlay->hwdata->channel->vplane1 != NULL)
  17.216          overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
  17.217  
  17.218 +    /* check for the validness of all planes */
  17.219 +    if ((overlay->hwdata->channel->yplane1 == NULL) &&
  17.220 +        (overlay->hwdata->channel->uplane1 == NULL) &&
  17.221 +        (overlay->hwdata->channel->vplane1 == NULL))
  17.222 +    {
  17.223 +       SDL_FreeYUVOverlay(overlay);
  17.224 +       SDL_SetError("PgConfigScaler() returns all planes equal NULL\n");
  17.225 +       return NULL;
  17.226 +    }
  17.227 +/*
  17.228      overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  17.229  
  17.230 -    if(overlay->hwdata->current==0)
  17.231 +    if (overlay->hwdata->current==0)
  17.232 +    {
  17.233          overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  17.234 +    }
  17.235      else
  17.236 +    {
  17.237          overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  17.238 +    }
  17.239 +*/
  17.240 +    overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  17.241  
  17.242 +/*
  17.243      overlay->hwdata->locked = 1;
  17.244 +*/
  17.245  
  17.246      /* Find the pitch and offset values for the overlay */
  17.247      overlay->planes = planes;
  17.248 @@ -279,29 +277,36 @@
  17.249      overlay->hwdata->scaler_on = 0;
  17.250      overlay->hw_overlay = 1;
  17.251  
  17.252 -    return (overlay);
  17.253 +    current_overlay=overlay;
  17.254 +
  17.255 +    return overlay;
  17.256  }
  17.257  
  17.258 -int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
  17.259 +int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay)
  17.260  {
  17.261      if (overlay == NULL)
  17.262 +    {
  17.263          return 0;
  17.264 -
  17.265 -    overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  17.266 -    if (overlay->hwdata->current == -1)
  17.267 -    {
  17.268 -        SDL_SetError("PgNextFrame failed, bailing out\n");
  17.269 -        SDL_FreeYUVOverlay(overlay);
  17.270 -        return(NULL);
  17.271      }
  17.272  
  17.273      overlay->hwdata->locked = 1;
  17.274  
  17.275 -    /* set current frame for double buffering */
  17.276 +/*  overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  17.277 +    if (overlay->hwdata->current == -1)
  17.278 +    {
  17.279 +        SDL_SetError("ph_LockYUVOverlay: PgNextFrame() failed, bailing out\n");
  17.280 +        SDL_FreeYUVOverlay(overlay);
  17.281 +        return 0;
  17.282 +    }
  17.283 +
  17.284      if (overlay->hwdata->current == 0)
  17.285 +    {
  17.286          overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  17.287 +    }
  17.288      else
  17.289 +    {
  17.290          overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  17.291 +    }
  17.292  
  17.293      if (overlay->planes > 0)
  17.294      {
  17.295 @@ -318,67 +323,83 @@
  17.296          overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
  17.297          overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
  17.298      }
  17.299 +*/
  17.300  
  17.301      return(0);
  17.302  }
  17.303  
  17.304 -void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
  17.305 +void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay)
  17.306  {
  17.307 -    int rtncode;
  17.308 -
  17.309 -    if(overlay == NULL)
  17.310 +    if (overlay == NULL)
  17.311 +    {
  17.312           return;
  17.313 -
  17.314 -    if(overlay->hwdata->scaler_on == 1) 
  17.315 -    {
  17.316 -        rtncode =PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
  17.317 -        switch(rtncode)
  17.318 -        {
  17.319 -            case -1:
  17.320 -                     SDL_SetError("PgConfigScalerChannel failed\n");
  17.321 -                     SDL_FreeYUVOverlay(overlay);
  17.322 -                     break;
  17.323 -            case 1:
  17.324 -                     grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
  17.325 -                     break;
  17.326 -            case 0:
  17.327 -            default:
  17.328 -                     break;
  17.329 -        }
  17.330      }
  17.331  
  17.332 -    /* This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
  17.333 -     * This means we might see a chromakey flicker at startup. */
  17.334 +    overlay->hwdata->locked = 0;
  17.335  }
  17.336  
  17.337 -int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
  17.338 +int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect)
  17.339  {
  17.340      int rtncode;
  17.341      PhPoint_t pos;
  17.342 +    SDL_Rect backrect;
  17.343 +    PhRect_t windowextent;
  17.344 +    int winchanged=0;
  17.345  
  17.346 -    if(overlay == NULL)
  17.347 +    if ((overlay == NULL) || (overlay->hwdata==NULL))
  17.348 +    {
  17.349          return -1;
  17.350 +    }
  17.351  
  17.352 -    /* If CurrentWindow has change, move the viewport */
  17.353 -    if((overlay->hwdata->CurrentWindow.pos.x != dstrect->x) ||
  17.354 -       (overlay->hwdata->CurrentWindow.pos.y != dstrect->y) ||
  17.355 -       (overlay->hwdata->CurrentWindow.size.w != dstrect->w) ||
  17.356 -       (overlay->hwdata->CurrentWindow.size.h != dstrect->h) ||
  17.357 -       (overlay->hwdata->scaler_on==0))
  17.358 +    if (overlay->hwdata->State == OVERLAY_STATE_UNINIT)
  17.359      {
  17.360 -        if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
  17.361 -            return -1;
  17.362 +        return -1;
  17.363 +    }
  17.364 +
  17.365 +    PtGetAbsPosition(window, &pos.x, &pos.y);
  17.366 +    if ((pos.x!=overlay->hwdata->CurrentWindowPos.x) ||
  17.367 +        (pos.y!=overlay->hwdata->CurrentWindowPos.y))
  17.368 +    {
  17.369 +       winchanged=1;
  17.370 +       overlay->hwdata->CurrentWindowPos.x=pos.x;
  17.371 +       overlay->hwdata->CurrentWindowPos.y=pos.y;
  17.372 +    }
  17.373 +
  17.374 +    /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
  17.375 +    if ((overlay->hwdata->CurrentViewPort.pos.x != dstrect->x) ||
  17.376 +        (overlay->hwdata->CurrentViewPort.pos.y != dstrect->y) ||
  17.377 +        (overlay->hwdata->CurrentViewPort.size.w != dstrect->w) ||
  17.378 +        (overlay->hwdata->CurrentViewPort.size.h != dstrect->h) ||
  17.379 +        (overlay->hwdata->scaler_on==0) || (winchanged==1) ||
  17.380 +        (overlay->hwdata->forcedredraw==1))
  17.381 +    {
  17.382 +
  17.383 +        if (overlay->hwdata->ischromakey==1)
  17.384 +        {
  17.385 +            /* restore screen behind the overlay/chroma color. */
  17.386 +            backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
  17.387 +            backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
  17.388 +            backrect.w=overlay->hwdata->CurrentViewPort.size.w;
  17.389 +            backrect.h=overlay->hwdata->CurrentViewPort.size.h;
  17.390 +            this->UpdateRects(this, 1, &backrect);
  17.391 +
  17.392 +            /* Draw the new rectangle of the chroma color at the viewport position */
  17.393 +            PgSetFillColor(overlay->hwdata->chromakey);
  17.394 +            PgDrawIRect(dstrect->x, dstrect->y, dstrect->x+dstrect->w-1, dstrect->y+dstrect->h-1, Pg_DRAW_FILL);
  17.395 +            PgFlush();
  17.396 +        }
  17.397  
  17.398          overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
  17.399          overlay->hwdata->scaler_on = 1;
  17.400  
  17.401 -        PtGetAbsPosition(window, &pos.x, &pos.y);
  17.402 -        overlay->hwdata->CurrentWindow.pos.x = pos.x + dstrect->x;
  17.403 -        overlay->hwdata->CurrentWindow.pos.y = pos.y + dstrect->y;
  17.404 -        overlay->hwdata->CurrentWindow.size.w = dstrect->w;
  17.405 -        overlay->hwdata->CurrentWindow.size.h = dstrect->h;
  17.406 -
  17.407 -        PhAreaToRect(&overlay->hwdata->CurrentWindow, &overlay->hwdata->props.viewport);
  17.408 +        PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent);
  17.409 +        overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dstrect->x;
  17.410 +        overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dstrect->y;
  17.411 +        overlay->hwdata->CurrentViewPort.size.w = dstrect->w;
  17.412 +        overlay->hwdata->CurrentViewPort.size.h = dstrect->h;
  17.413 +        PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
  17.414 +        overlay->hwdata->CurrentViewPort.pos.x = dstrect->x;
  17.415 +        overlay->hwdata->CurrentViewPort.pos.y = dstrect->y;
  17.416  
  17.417          rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
  17.418  
  17.419 @@ -397,19 +418,26 @@
  17.420          }
  17.421      }
  17.422  
  17.423 -    if (!overlay->hwdata->locked)
  17.424 +
  17.425 +/*
  17.426 +    if (overlay->hwdata->locked==0)
  17.427      {
  17.428          overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
  17.429          if (overlay->hwdata->current == -1)
  17.430          {
  17.431 -            SDL_SetError("PgNextVideoFrame failed\n");
  17.432 +            SDL_SetError("ph_LockYUVOverlay: PgNextFrame() failed, bailing out\n");
  17.433              SDL_FreeYUVOverlay(overlay);
  17.434              return 0;
  17.435          }
  17.436 +
  17.437          if (overlay->hwdata->current == 0)
  17.438 +        {
  17.439              overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
  17.440 +        }
  17.441          else
  17.442 +        {
  17.443              overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
  17.444 +        }
  17.445  
  17.446          if (overlay->planes > 0)
  17.447          {
  17.448 @@ -427,17 +455,33 @@
  17.449              overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
  17.450          }
  17.451      }
  17.452 +*/
  17.453          
  17.454      return 0;
  17.455  }
  17.456  
  17.457  void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
  17.458  {
  17.459 +    SDL_Rect backrect;
  17.460 +
  17.461      if (overlay == NULL)
  17.462 +    {
  17.463          return;
  17.464 +    }
  17.465  
  17.466      if (overlay->hwdata == NULL)
  17.467 +    {
  17.468          return;
  17.469 +    }
  17.470 +
  17.471 +    current_overlay=NULL;
  17.472 +
  17.473 +    /* restore screen behind the overlay/chroma color. */
  17.474 +    backrect.x=overlay->hwdata->CurrentViewPort.pos.x;
  17.475 +    backrect.y=overlay->hwdata->CurrentViewPort.pos.y;
  17.476 +    backrect.w=overlay->hwdata->CurrentViewPort.size.w;
  17.477 +    backrect.h=overlay->hwdata->CurrentViewPort.size.h;
  17.478 +    this->UpdateRects(this, 1, &backrect);
  17.479  
  17.480      /* it is need for some buggy drivers, that can't hide overlay before */
  17.481      /* freeing buffer, so we got trash on the srceen                     */
    18.1 --- a/src/video/photon/SDL_phyuv_c.h	Mon Jul 28 01:47:55 2003 +0000
    18.2 +++ b/src/video/photon/SDL_phyuv_c.h	Mon Aug 04 00:52:42 2003 +0000
    18.3 @@ -25,13 +25,37 @@
    18.4   "@(#) $Id$";
    18.5  #endif
    18.6  
    18.7 -/* This is the XFree86 Xv extension implementation of YUV video overlays */
    18.8 +/* This is the photon implementation of YUV video overlays */
    18.9  
   18.10  #include "SDL_video.h"
   18.11  #include "SDL_ph_video.h"
   18.12  
   18.13 -extern SDL_Overlay *ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display);
   18.14 -extern int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay);
   18.15 -extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
   18.16 -extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
   18.17 -extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
   18.18 +struct private_yuvhwdata
   18.19 +{
   18.20 +    FRAMEDATA* CurrentFrameData;
   18.21 +    FRAMEDATA* FrameData0;
   18.22 +    FRAMEDATA* FrameData1;
   18.23 +    PgScalerProps_t   props;
   18.24 +    PgScalerCaps_t    caps;
   18.25 +    PgVideoChannel_t* channel;
   18.26 +    PhArea_t CurrentViewPort;
   18.27 +    PhPoint_t CurrentWindowPos;
   18.28 +    long format;
   18.29 +    int scaler_on;
   18.30 +    int current;
   18.31 +    long YStride;
   18.32 +    long VStride;
   18.33 +    long UStride;
   18.34 +    int ischromakey;
   18.35 +    long chromakey;
   18.36 +    int forcedredraw;
   18.37 +    unsigned long State;
   18.38 +    long flags;
   18.39 +    int locked;
   18.40 +};
   18.41 +
   18.42 +extern SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display);
   18.43 +extern int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay);
   18.44 +extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay);
   18.45 +extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect);
   18.46 +extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay* overlay);
    19.1 --- a/test/testsprite.c	Mon Jul 28 01:47:55 2003 +0000
    19.2 +++ b/test/testsprite.c	Mon Aug 04 00:52:42 2003 +0000
    19.3 @@ -54,10 +54,6 @@
    19.4  
    19.5  void MoveSprites(SDL_Surface *screen, Uint32 background)
    19.6  {
    19.7 -#if DEBUG_FLIP
    19.8 -    static int t = 0;
    19.9 -#endif
   19.10 -
   19.11  	int i, nupdates;
   19.12  	SDL_Rect area, *position, *velocity;
   19.13  
   19.14 @@ -90,15 +86,19 @@
   19.15  
   19.16  #if DEBUG_FLIP
   19.17      {
   19.18 -        Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
   19.19 -        SDL_Rect r;
   19.20 -        r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20);
   19.21 -        r.y = 0;
   19.22 -        r.w = 20;
   19.23 -        r.h = screen->h;
   19.24 +	if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   19.25 +            static int t = 0;
   19.26 +
   19.27 +            Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
   19.28 +            SDL_Rect r;
   19.29 +            r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20);
   19.30 +            r.y = 0;
   19.31 +            r.w = 20;
   19.32 +            r.h = screen->h;
   19.33          
   19.34 -        SDL_FillRect (screen, &r, color);
   19.35 -        t+=2;
   19.36 +            SDL_FillRect (screen, &r, color);
   19.37 +            t+=2;
   19.38 +        }
   19.39      }
   19.40  #endif
   19.41