Date: Sat, 14 Feb 2004 14:52:40 +0200
authorSam Lantinga <slouken@libsdl.org>
Sat, 14 Feb 2004 20:22:21 +0000
changeset 82130168104389f
parent 820 0b9b4bf3c1e7
child 822 abb915adb1b0
Date: Sat, 14 Feb 2004 14:52:40 +0200
From: "Mike Gorchak"
Subject: Batch of the QNX6 fixes for the SDL

1. Updated readme.QNX
2. Fixed crashes during intensive window updating under fast machines (got over 200 rectangles for update).
3. Fixed double-buffered fullscreen modes, now it works as needed.
4. Fixed Photon detection algorithm.
5. Fixed HWSURFACE update function.
6. Added SDL_PHOTON_FULLSCREEN_REFRESH environment variable support for control refresh rates under Photon.
7. Added 640x400 fullscreen mode emulation via 640x480 (if videodriver not supports original 640x400 mode of course) shifted by 40 vertical pixels from begin, to center it. It's needed for some old DOS games which ran in doubled 320x200 mode.
8. Added available video ram amount support.
8. Added hardware surface allocation/deallocation support if current videomode and videodriver supports it.
9. Added hardware filling support.
10. Added hardware blits support (simple and colorkeyed).

And I've added to testvidinfo test color-keyed blits benchmark (maybe need to add alpha blits benchmark too ?). Currently Photon not supporting any alpha hardware blittings (all drivers lack of alpha blitting code support, only software alpha blitting exist in photon, which is hundreds times slowest than the SDL's one). So I've not added the alpha support. I suppose new QNX 6.3 will have the hardware alpha support, so when it will be done, I'll add alpha support.
README.QNX
src/video/photon/SDL_ph_events.c
src/video/photon/SDL_ph_events_c.h
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_video.c
src/video/photon/SDL_ph_video.h
test/testvidinfo.c
     1.1 --- a/README.QNX	Sat Feb 14 10:12:27 2004 +0000
     1.2 +++ b/README.QNX	Sat Feb 14 20:22:21 2004 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  README by Mike Gorchak <mike@malva.ua>, <lestat@i.com.ua>
     1.5 -Last changed at 30 Sep 2003.
     1.6 +Last changed at 14 Feb 2004.
     1.7  
     1.8  ======================================================================
     1.9  Table of Contents:
    1.10 @@ -13,7 +13,7 @@
    1.11  7. Environment variables.
    1.12  
    1.13  ======================================================================
    1.14 -OpenGL:
    1.15 +1. OpenGL:
    1.16  
    1.17      OpenGL works well and is stable, but fullscreen mode has not  been
    1.18  heavily tested yet.
    1.19 @@ -34,7 +34,7 @@
    1.20  PHOGL_ATTRIB_FORCE_HW or PHOGL_ATTRIB_FAVOR_HW.
    1.21  
    1.22  ======================================================================
    1.23 -Wheel and multi-button mouses:
    1.24 +2. Wheel and multi-button mouses:
    1.25  
    1.26      Photon emits  keyboard  events (key up and down)  when  the  mouse
    1.27  wheel is moved. The key_scan field appears valid, and it contains zero.
    1.28 @@ -54,14 +54,14 @@
    1.29     front, but works not with any window, looks like bug-o-feature :).
    1.30  
    1.31  ======================================================================
    1.32 -CDROM handling issues:
    1.33 +3. CDROM handling issues:
    1.34  
    1.35      Access to CDROM can only be  provided  with  'root'  privileges. I
    1.36  can't do anything about that, /dev/cd0 has brw------- permissions  and
    1.37  root:root rights.
    1.38  
    1.39  ======================================================================
    1.40 -Hardware video overlays:
    1.41 +4. Hardware video overlays:
    1.42  
    1.43      Overlays can flicker  during  window  movement,  resizing, etc. It
    1.44  happens because the photon driver updates the real window contents be-
    1.45 @@ -82,20 +82,20 @@
    1.46  negative coordinates.
    1.47  
    1.48  =======================================================================
    1.49 -Shared library building:
    1.50 +5. Shared library building:
    1.51  
    1.52      A shared library can be built, but before running  the  autogen.sh
    1.53  script you must manually delete the libtool.m4 stuff from the acinclu-
    1.54  de.m4 file (it comes after the ESD detection code up to the end of the
    1.55 -file), because the libtool stuff in the acinclude.m4 file is very  old
    1.56 -in SDL distribution before the version 1.2.7 and doesn't know anything
    1.57 +file), because the libtool stuff in the acinclude.m4 file was very old
    1.58 +in SDL distribution before the version 1.2.7 and doesn't knew anything
    1.59  about QNX. SDL 1.2.7 distribution contain  the  new libtool.m4 script,
    1.60  but anyway  it  is  broken :), Just  remove  it, then  run "libtoolize
    1.61  --force --copy",  delete the file aclocal.m4 and after  that  run  the
    1.62  autogen.sh script.
    1.63  
    1.64  ======================================================================
    1.65 -Some building issues:
    1.66 +6. Some building issues:
    1.67  
    1.68      Feel free to not use the --disable-shared configure option if you'
    1.69  ve read the above comment about 'Shared  library  building'. Otherwise
    1.70 @@ -123,11 +123,16 @@
    1.71                   --prefix=/usr --without-x
    1.72  
    1.73  ======================================================================
    1.74 -Environment variables:
    1.75 +7. Environment variables:
    1.76  
    1.77      Please note that the photon driver  is  sensible to the  following
    1.78  environmental variables:
    1.79  
    1.80 + * SDL_PHOTON_FULLSCREEN_REFRESH - this environment variable controls
    1.81 +the refresh rate in all fullscreen modes. Be carefull !!! Photon drivers
    1.82 +usually do not checking the maximum refresh rate, which video adapter or
    1.83 +monitor supports.
    1.84 +
    1.85   * SDL_VIDEO_WINDOW_POS - can be  set in the "X,Y" format.  If X and Y
    1.86  coordinates are bigger than the current desktop resolution, then  win-
    1.87  dow positioning across  virtual  consoles is activated. If X and Y are
     2.1 --- a/src/video/photon/SDL_ph_events.c	Sat Feb 14 10:12:27 2004 +0000
     2.2 +++ b/src/video/photon/SDL_ph_events.c	Sat Feb 14 20:22:21 2004 +0000
     2.3 @@ -47,17 +47,13 @@
     2.4  #include "SDL_ph_events_c.h"
     2.5  #include "SDL_phyuv_c.h"
     2.6  
     2.7 -
     2.8 -
     2.9  /* The translation tables from a photon keysym to a SDL keysym */
    2.10  static SDLKey ODD_keymap[256];
    2.11  static SDLKey MISC_keymap[0xFF + 1];
    2.12  SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
    2.13  
    2.14  /* Check to see if this is a repeated key.
    2.15 -   (idea shamelessly lifted from GII -- thanks guys! :)
    2.16 - */
    2.17 -
    2.18 +   (idea shamelessly lifted from GII -- thanks guys! :) */
    2.19  static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
    2.20  {
    2.21      PhRect_t *rect = PhGetRects( winEvent );
    2.22 @@ -117,8 +113,6 @@
    2.23      return (mouse_button);
    2.24  }
    2.25  
    2.26 -//                   void* PtAppCreateContext();
    2.27 -
    2.28  static int ph_DispatchEvent(_THIS)
    2.29  {
    2.30      int posted;
    2.31 @@ -127,7 +121,7 @@
    2.32      PhKeyEvent_t* keyEvent;
    2.33      PhWindowEvent_t* winEvent;
    2.34      int i, buttons;
    2.35 -    SDL_Rect sdlrects[50]; 
    2.36 +    SDL_Rect sdlrects[PH_SDL_MAX_RECTS];
    2.37  	
    2.38      posted = 0;
    2.39  	
    2.40 @@ -217,12 +211,12 @@
    2.41                  set_motion_sensitivity(this, -1);
    2.42                  posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
    2.43              }
    2.44 -            /* quit request */
    2.45 +            /* request quit */
    2.46              else if (winEvent->event_f==Ph_WM_CLOSE)
    2.47              {
    2.48                  posted = SDL_PrivateQuit();
    2.49              }
    2.50 -            /* hide/unhide request */
    2.51 +            /* request hide/unhide */
    2.52              else if (winEvent->event_f==Ph_WM_HIDE)
    2.53              {
    2.54                  if (currently_hided)
    2.55 @@ -287,9 +281,16 @@
    2.56          {
    2.57              if (event->num_rects!=0)
    2.58              {
    2.59 +                int numrects;
    2.60 +
    2.61                  if (SDL_VideoSurface)
    2.62                  {
    2.63                      rect = PhGetRects(event);
    2.64 +                    if (event->num_rects>PH_SDL_MAX_RECTS)
    2.65 +                    {
    2.66 +                       /* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */
    2.67 +                       numrects=PH_SDL_MAX_RECTS;
    2.68 +                    }
    2.69  
    2.70                      for(i=0; i<event->num_rects; i++)
    2.71                      {
    2.72 @@ -368,6 +369,32 @@
    2.73          
    2.74          case Ph_EV_INFO:
    2.75          {
    2.76 +           if (event->subtype==Ph_OFFSCREEN_INVALID)
    2.77 +           {
    2.78 +              unsigned long* EvInfoData;
    2.79 +
    2.80 +              EvInfoData=(unsigned long*)PhGetData(event);
    2.81 +
    2.82 +              switch (*EvInfoData)
    2.83 +              {
    2.84 +                 case Pg_VIDEO_MODE_SWITCHED:
    2.85 +                      {
    2.86 +                      }
    2.87 +                      break;
    2.88 +                 case Pg_ENTERED_DIRECT:
    2.89 +                      {
    2.90 +                      }
    2.91 +                      break;
    2.92 +                 case Pg_EXITED_DIRECT:
    2.93 +                      {
    2.94 +                      }
    2.95 +                      break;
    2.96 +                 case Pg_DRIVER_STARTED:
    2.97 +                      {
    2.98 +                      }
    2.99 +                      break;
   2.100 +              }
   2.101 +           }
   2.102          }
   2.103          break;
   2.104      }
   2.105 @@ -387,10 +414,9 @@
   2.106          {
   2.107              case Ph_EVENT_MSG:
   2.108                   return 1;
   2.109 -                 break;
   2.110              case -1:
   2.111 -                 perror("ph_Pending(): PhEventNext failed");
   2.112 -                 break;
   2.113 +                 SDL_SetError("ph_Pending(): PhEventNext failed.\n");
   2.114 +                 return 0;
   2.115              default:
   2.116                   return 0;
   2.117          }
     3.1 --- a/src/video/photon/SDL_ph_events_c.h	Sat Feb 14 10:12:27 2004 +0000
     3.2 +++ b/src/video/photon/SDL_ph_events_c.h	Sat Feb 14 20:22:21 2004 +0000
     3.3 @@ -30,7 +30,9 @@
     3.4  
     3.5  #include "SDL_ph_video.h"
     3.6  
     3.7 -#define EVENT_SIZE sizeof(PhEvent_t) + 1000
     3.8 +#define PH_SDL_MAX_RECTS 256
     3.9 +#define PH_EVENT_SAFETY_POOL 512
    3.10 +#define EVENT_SIZE (sizeof(PhEvent_t) + 1000 + PH_EVENT_SAFETY_POOL)
    3.11  
    3.12  /* Functions to be exported */
    3.13  extern void ph_InitOSKeymap(_THIS);
     4.1 --- a/src/video/photon/SDL_ph_image.c	Sat Feb 14 10:12:27 2004 +0000
     4.2 +++ b/src/video/photon/SDL_ph_image.c	Sat Feb 14 20:22:21 2004 +0000
     4.3 @@ -164,7 +164,7 @@
     4.4  
     4.5      screen->pitch = OCImage.offscreen_context->pitch;
     4.6  
     4.7 -    OCImage.dc_ptr = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
     4.8 +    OCImage.dc_ptr = (unsigned char *)PdGetOffscreenContextPtr(OCImage.offscreen_context);
     4.9  
    4.10      if (OCImage.dc_ptr == NULL)
    4.11      {
    4.12 @@ -212,7 +212,7 @@
    4.13      
    4.14      if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
    4.15      {
    4.16 -        OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_CRTC_SAFE | Pg_OSC_MEM_PAGE_ALIGN);
    4.17 +        OCImage.offscreen_backcontext = PdDupOffscreenContext(OCImage.offscreen_context, Pg_OSC_MEM_PAGE_ALIGN | Pg_OSC_CRTC_SAFE);
    4.18          if (OCImage.offscreen_backcontext == NULL)
    4.19          {
    4.20              SDL_SetError("ph_SetupFullScreenImage(): PdCreateOffscreenContext(back) function failed !\n");
    4.21 @@ -240,15 +240,32 @@
    4.22      }
    4.23  
    4.24      /* wait for the hardware */
    4.25 +    PgFlush();
    4.26      PgWaitHWIdle();
    4.27  
    4.28      if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF)
    4.29      {
    4.30 -        OCImage.current = 1;
    4.31 -        PhDCSetCurrent(OCImage.offscreen_backcontext);
    4.32 -        screen->pitch = OCImage.offscreen_backcontext->pitch;
    4.33 -        screen->pixels = OCImage.FrameData1;
    4.34 -        PgSwapDisplay(OCImage.offscreen_context, 0);
    4.35 +        OCImage.current = 0;
    4.36 +        PhDCSetCurrent(OCImage.offscreen_context);
    4.37 +        screen->pitch = OCImage.offscreen_context->pitch;
    4.38 +        screen->pixels = OCImage.FrameData0;
    4.39 +        
    4.40 +        /* emulate 640x400 videomode */
    4.41 +        if (videomode_emulatemode==1)
    4.42 +        {
    4.43 +           int i;
    4.44 +           
    4.45 +           for (i=0; i<40; i++)
    4.46 +           {
    4.47 +              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
    4.48 +           }
    4.49 +           for (i=440; i<480; i++)
    4.50 +           {
    4.51 +              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
    4.52 +           }
    4.53 +           screen->pixels+=screen->pitch*40;
    4.54 +        }
    4.55 +        PgSwapDisplay(OCImage.offscreen_backcontext, 0);
    4.56      }
    4.57      else
    4.58      {
    4.59 @@ -256,11 +273,29 @@
    4.60          PhDCSetCurrent(OCImage.offscreen_context);
    4.61          screen->pitch = OCImage.offscreen_context->pitch;
    4.62          screen->pixels = OCImage.FrameData0;
    4.63 +
    4.64 +        /* emulate 640x400 videomode */
    4.65 +        if (videomode_emulatemode==1)
    4.66 +        {
    4.67 +           int i;
    4.68 +           
    4.69 +           for (i=0; i<40; i++)
    4.70 +           {
    4.71 +              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
    4.72 +           }
    4.73 +           for (i=440; i<480; i++)
    4.74 +           {
    4.75 +              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
    4.76 +           }
    4.77 +           screen->pixels+=screen->pitch*40;
    4.78 +        }
    4.79      }
    4.80  
    4.81      this->UpdateRects = ph_OCDCUpdate;
    4.82  
    4.83 +    /* wait for the hardware */
    4.84      PgFlush();
    4.85 +    PgWaitHWIdle();
    4.86  
    4.87      return 0;
    4.88  }
    4.89 @@ -427,75 +462,497 @@
    4.90      }
    4.91  }
    4.92  
    4.93 +int ph_UpdateHWInfo(_THIS)
    4.94 +{
    4.95 +    PgVideoModeInfo_t vmode;
    4.96 +    PgHWCaps_t hwcaps;
    4.97 +
    4.98 +    /* Update video ram amount */
    4.99 +    if (PgGetGraphicsHWCaps(&hwcaps) < 0)
   4.100 +    {
   4.101 +        SDL_SetError("ph_UpdateHWInfo(): GetGraphicsHWCaps() function failed !\n");
   4.102 +        return -1;
   4.103 +    }
   4.104 +    this->info.video_mem=hwcaps.currently_available_video_ram/1024;
   4.105 +
   4.106 +    /* obtain current mode capabilities */
   4.107 +    if (PgGetVideoModeInfo(hwcaps.current_video_mode, &vmode) < 0)
   4.108 +    {
   4.109 +        SDL_SetError("ph_UpdateHWInfo(): GetVideoModeInfo() function failed !\n");
   4.110 +        return -1;
   4.111 +    }
   4.112 +
   4.113 +    this->info.blit_hw = 1;
   4.114 +
   4.115 +    if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_ALPHA_BLEND) == PgVM_MODE_CAP2_ALPHA_BLEND)
   4.116 +    {
   4.117 +       this->info.blit_hw_A = 1;
   4.118 +    }
   4.119 +    else
   4.120 +    {
   4.121 +       this->info.blit_hw_A = 0;
   4.122 +    }
   4.123 +    
   4.124 +    if ((vmode.mode_capabilities2 & PgVM_MODE_CAP2_CHROMA) == PgVM_MODE_CAP2_CHROMA)
   4.125 +    {
   4.126 +       this->info.blit_hw_CC = 1;
   4.127 +    }
   4.128 +    else
   4.129 +    {
   4.130 +       this->info.blit_hw_CC = 0;
   4.131 +    }
   4.132 +    
   4.133 +    return 0;
   4.134 +}
   4.135 +
   4.136  int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags)
   4.137  {
   4.138 +    int setupresult=-1;
   4.139 +
   4.140      ph_DestroyImage(this, screen);
   4.141      
   4.142  #ifdef HAVE_OPENGL
   4.143      if ((flags & SDL_OPENGL)==SDL_OPENGL)
   4.144      {
   4.145 -        return ph_SetupOpenGLImage(this, screen);
   4.146 +        setupresult=ph_SetupOpenGLImage(this, screen);
   4.147 +    }
   4.148 +    else
   4.149 +    {
   4.150 +#endif /* HAVE_OPENGL */
   4.151 +       if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
   4.152 +       {
   4.153 +           setupresult=ph_SetupFullScreenImage(this, screen);
   4.154 +       }
   4.155 +       else
   4.156 +       {
   4.157 +          if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
   4.158 +          {
   4.159 +              setupresult=ph_SetupOCImage(this, screen);
   4.160 +          }
   4.161 +          else
   4.162 +          {
   4.163 +              setupresult=ph_SetupImage(this, screen);
   4.164 +          }
   4.165 +       }
   4.166 +#ifdef HAVE_OPENGL
   4.167      }
   4.168  #endif /* HAVE_OPENGL */
   4.169 -    if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
   4.170 +    if (setupresult!=-1)
   4.171      {
   4.172 -        return ph_SetupFullScreenImage(this, screen);
   4.173 +       ph_UpdateHWInfo(this);
   4.174      }
   4.175 -    if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
   4.176 -    {
   4.177 -        return ph_SetupOCImage(this, screen);
   4.178 -    }
   4.179 -
   4.180 -    return ph_SetupImage(this, screen);
   4.181 +    
   4.182 +    return setupresult;
   4.183  }
   4.184  
   4.185  int ph_AllocHWSurface(_THIS, SDL_Surface* surface)
   4.186  {
   4.187 -    return(-1);
   4.188 +    PgHWCaps_t hwcaps;
   4.189 +
   4.190 +    if (surface->hwdata!=NULL)
   4.191 +    {
   4.192 +       SDL_SetError("ph_AllocHWSurface(): hwdata already exists!\n");
   4.193 +       return -1;
   4.194 +    }
   4.195 +    surface->hwdata=malloc(sizeof(struct private_hwdata));
   4.196 +    memset(surface->hwdata, 0x00, sizeof(struct private_hwdata));
   4.197 +    surface->hwdata->offscreenctx=PdCreateOffscreenContext(0, surface->w, surface->h, Pg_OSC_MEM_PAGE_ALIGN);
   4.198 +    if (surface->hwdata->offscreenctx == NULL)
   4.199 +    {
   4.200 +        SDL_SetError("ph_AllocHWSurface(): PdCreateOffscreenContext() function failed !\n");
   4.201 +        return -1;
   4.202 +    }
   4.203 +    surface->pixels=PdGetOffscreenContextPtr(surface->hwdata->offscreenctx);
   4.204 +    if (surface->pixels==NULL)
   4.205 +    {
   4.206 +        PhDCRelease(surface->hwdata->offscreenctx);
   4.207 +        SDL_SetError("ph_AllocHWSurface(): PdGetOffscreenContextPtr() function failed !\n");
   4.208 +        return -1;
   4.209 +    }
   4.210 +    surface->pitch=surface->hwdata->offscreenctx->pitch;
   4.211 +    surface->flags|=SDL_HWSURFACE;
   4.212 +    surface->flags|=SDL_PREALLOC;
   4.213 +    
   4.214 +#if 0 /* FIXME */
   4.215 +    /* create simple offscreen lock */
   4.216 +    surface->hwdata->crlockparam.flags=0;
   4.217 +    if (PdCreateOffscreenLock(surface->hwdata->offscreenctx, &surface->hwdata->crlockparam)!=EOK)
   4.218 +    {
   4.219 +        PhDCRelease(surface->hwdata->offscreenctx);
   4.220 +        SDL_SetError("ph_AllocHWSurface(): Can't create offscreen lock !\n");
   4.221 +        return -1;
   4.222 +    }
   4.223 +#endif /* 0 */
   4.224 +
   4.225 +    /* Update video ram amount */
   4.226 +    if (PgGetGraphicsHWCaps(&hwcaps) < 0)
   4.227 +    {
   4.228 +        PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
   4.229 +        PhDCRelease(surface->hwdata->offscreenctx);
   4.230 +        SDL_SetError("ph_AllocHWSurface(): GetGraphicsHWCaps() function failed !\n");
   4.231 +        return -1;
   4.232 +    }
   4.233 +    this->info.video_mem=hwcaps.currently_available_video_ram/1024;
   4.234 +
   4.235 +    return 0;
   4.236  }
   4.237  
   4.238  void ph_FreeHWSurface(_THIS, SDL_Surface* surface)
   4.239  {
   4.240 +    PgHWCaps_t hwcaps;
   4.241 +
   4.242 +    if (surface->hwdata==NULL)
   4.243 +    {
   4.244 +       SDL_SetError("ph_FreeHWSurface(): no hwdata!\n");
   4.245 +       return;
   4.246 +    }
   4.247 +    if (surface->hwdata->offscreenctx == NULL)
   4.248 +    {
   4.249 +       SDL_SetError("ph_FreeHWSurface(): no offscreen context to delete!\n");
   4.250 +       return;
   4.251 +    }
   4.252 +
   4.253 +#if 0 /* FIXME */
   4.254 +    /* unlock the offscreen context if it has been locked before destroy it */
   4.255 +    if (PdIsOffscreenLocked(surface->hwdata->offscreenctx)==Pg_OSC_LOCKED)
   4.256 +    {
   4.257 +       PdUnlockOffscreen(surface->hwdata->offscreenctx);
   4.258 +    }
   4.259 +
   4.260 +    PdDestroyOffscreenLock(surface->hwdata->offscreenctx);
   4.261 +#endif /* 0 */
   4.262 +
   4.263 +    PhDCRelease(surface->hwdata->offscreenctx);
   4.264 +    
   4.265 +    free(surface->hwdata);
   4.266 +    surface->hwdata=NULL;
   4.267 +
   4.268 +    /* Update video ram amount */
   4.269 +    if (PgGetGraphicsHWCaps(&hwcaps) < 0)
   4.270 +    {
   4.271 +        SDL_SetError("ph_FreeHWSurface(): GetGraphicsHWCaps() function failed !\n");
   4.272 +        return;
   4.273 +    }
   4.274 +    this->info.video_mem=hwcaps.currently_available_video_ram/1024;
   4.275 +
   4.276      return;
   4.277  }
   4.278  
   4.279 +int ph_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
   4.280 +{
   4.281 +   if ((src->hwdata==NULL) && (src != this->screen))
   4.282 +   {
   4.283 +      SDL_SetError("ph_CheckHWBlit(): Source surface haven't hardware specific data.\n");
   4.284 +      src->flags&=~SDL_HWACCEL;
   4.285 +      return -1;
   4.286 +   }
   4.287 +   if ((src->flags & SDL_HWSURFACE) != SDL_HWSURFACE)
   4.288 +   {
   4.289 +      SDL_SetError("ph_CheckHWBlit(): Source surface isn't a hardware surface.\n");
   4.290 +      src->flags&=~SDL_HWACCEL;
   4.291 +      return -1;
   4.292 +   }
   4.293 +
   4.294 +   if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
   4.295 +   {
   4.296 +       if (this->info.blit_hw_CC!=1)
   4.297 +       {
   4.298 +           src->flags&=~SDL_HWACCEL;
   4.299 +           src->map->hw_blit=NULL;
   4.300 +           return -1;
   4.301 +       }
   4.302 +   }
   4.303 +
   4.304 +   if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA)
   4.305 +   {
   4.306 +       if (this->info.blit_hw_A!=1)
   4.307 +       {
   4.308 +           src->flags&=~SDL_HWACCEL;
   4.309 +           src->map->hw_blit=NULL;
   4.310 +           return -1;
   4.311 +       }
   4.312 +   }
   4.313 +
   4.314 +   src->flags|=SDL_HWACCEL;
   4.315 +   src->map->hw_blit = ph_HWAccelBlit;
   4.316 +
   4.317 +   return 1;
   4.318 +}
   4.319 +
   4.320 +PgColor_t ph_ExpandColor(_THIS, SDL_Surface* surface, Uint32 color)
   4.321 +{
   4.322 +    Uint32 truecolor;
   4.323 +
   4.324 +    /* Photon API accepts true colors only during hw filling operations */
   4.325 +    switch(surface->format->BitsPerPixel)
   4.326 +    {
   4.327 +       case 8:
   4.328 +            {
   4.329 +                if ((surface->format->palette) && (color<=surface->format->palette->ncolors))
   4.330 +                {
   4.331 +                    truecolor=PgRGB(surface->format->palette->colors[color].r,
   4.332 +                                    surface->format->palette->colors[color].g,
   4.333 +                                    surface->format->palette->colors[color].b);
   4.334 +                }
   4.335 +                else
   4.336 +                {
   4.337 +                    SDL_SetError("ph_ExpandColor(): Color out of range for the 8bpp mode !\n");
   4.338 +                    return 0xFFFFFFFFUL;
   4.339 +                }
   4.340 +            }
   4.341 +            break;
   4.342 +       case 15: 
   4.343 +            {
   4.344 +                truecolor = ((color & 0x00007C00UL) << 9) |   /* R */
   4.345 +                            ((color & 0x000003E0UL) << 6) |   /* G */
   4.346 +                            ((color & 0x0000001FUL) << 3) |   /* B */
   4.347 +                            ((color & 0x00007000UL) << 4) |   /* R compensation */
   4.348 +                            ((color & 0x00000380UL) << 1) |   /* G compensation */
   4.349 +                            ((color & 0x0000001CUL) >> 2);    /* B compensation */
   4.350 +            }
   4.351 +            break;
   4.352 +       case 16: 
   4.353 +            {
   4.354 +                truecolor = ((color & 0x0000F800UL) << 8) |   /* R */
   4.355 +                            ((color & 0x000007E0UL) << 5) |   /* G */
   4.356 +                            ((color & 0x0000001FUL) << 3) |   /* B */
   4.357 +                            ((color & 0x0000E000UL) << 3) |   /* R compensation */
   4.358 +                            ((color & 0x00000600UL) >> 1) |   /* G compensation */
   4.359 +                            ((color & 0x0000001CUL) >> 2);    /* B compensation */
   4.360 +
   4.361 +            }
   4.362 +            break;
   4.363 +       case 24: 
   4.364 +            {
   4.365 +                truecolor=color & 0x00FFFFFFUL;
   4.366 +            }
   4.367 +            break;
   4.368 +       case 32: 
   4.369 +            {
   4.370 +                truecolor=color;
   4.371 +            }
   4.372 +            break;
   4.373 +       default:
   4.374 +            {
   4.375 +                SDL_SetError("ph_ExpandColor(): Unsupported depth for the hardware operations !\n");
   4.376 +                return 0xFFFFFFFFUL;
   4.377 +            }
   4.378 +    }
   4.379 +
   4.380 +    return truecolor;
   4.381 +}
   4.382 +
   4.383 +int ph_FillHWRect(_THIS, SDL_Surface* surface, SDL_Rect* rect, Uint32 color)
   4.384 +{
   4.385 +    PgColor_t oldcolor;
   4.386 +    Uint32 truecolor;
   4.387 +    int ydisp=0;
   4.388 +
   4.389 +    truecolor=ph_ExpandColor(this, surface, color);
   4.390 +    if (truecolor==0xFFFFFFFFUL)
   4.391 +    {
   4.392 +        return -1;
   4.393 +    }
   4.394 +
   4.395 +    oldcolor=PgSetFillColor(truecolor);
   4.396 +
   4.397 +    /* 640x400 videomode emulation */
   4.398 +    if (videomode_emulatemode==1)
   4.399 +    {
   4.400 +        ydisp+=40;
   4.401 +    }
   4.402 +
   4.403 +    PgDrawIRect(rect->x, rect->y+ydisp, rect->w+rect->x-1, rect->h+rect->y+ydisp-1, Pg_DRAW_FILL);
   4.404 +    PgSetFillColor(oldcolor);
   4.405 +    PgFlush();
   4.406 +    PgWaitHWIdle();
   4.407 +
   4.408 +    return 0;
   4.409 +}
   4.410 +
   4.411  int ph_FlipHWSurface(_THIS, SDL_Surface* screen)
   4.412  {
   4.413 +    PhArea_t farea;
   4.414 +
   4.415      if ((screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
   4.416      {
   4.417 +        /* flush all drawing ops before blitting */
   4.418 +        PgFlush();
   4.419          PgWaitHWIdle();
   4.420 -        if (OCImage.current==0)
   4.421 +
   4.422 +        farea.pos.x=0;
   4.423 +        farea.pos.y=0;
   4.424 +        farea.size.w=screen->w;
   4.425 +        farea.size.h=screen->h;
   4.426 +
   4.427 +        /* emulate 640x400 videomode */
   4.428 +        if (videomode_emulatemode==1)
   4.429          {
   4.430 -            PgSwapDisplay(OCImage.offscreen_context, 0);
   4.431 -            OCImage.current=1;
   4.432 -            screen->pitch = OCImage.offscreen_backcontext->pitch;
   4.433 -            screen->pixels = OCImage.FrameData1;
   4.434 -            PhDCSetCurrent(OCImage.offscreen_backcontext);
   4.435 -            PgFlush();
   4.436 +            farea.pos.y+=40;
   4.437          }
   4.438 -        else
   4.439 -        {
   4.440 -            PgSwapDisplay(OCImage.offscreen_backcontext, 0);
   4.441 -            OCImage.current=0;
   4.442 -            screen->pitch = OCImage.offscreen_context->pitch;
   4.443 -            screen->pixels = OCImage.FrameData0;
   4.444 -            PhDCSetCurrent(OCImage.offscreen_context);
   4.445 -            PgFlush();
   4.446 -        }
   4.447 +
   4.448 +        PgContextBlitArea(OCImage.offscreen_context, &farea, OCImage.offscreen_backcontext, &farea);
   4.449 +
   4.450 +        /* flush the blitting */
   4.451 +        PgFlush();
   4.452 +        PgWaitHWIdle();
   4.453      }
   4.454      return 0;
   4.455  }
   4.456  
   4.457 -int ph_LockHWSurface(_THIS, SDL_Surface *surface)
   4.458 +int ph_LockHWSurface(_THIS, SDL_Surface* surface)
   4.459  {
   4.460 -    return(0);
   4.461 +
   4.462 +#if 0 /* FIXME */
   4.463 +    int lockresult;
   4.464 +
   4.465 +    if (surface->hwdata == NULL)
   4.466 +    {
   4.467 +        return;
   4.468 +    }
   4.469 +
   4.470 +    surface->hwdata->lockparam.flags=0;
   4.471 +    surface->hwdata->lockparam.time_out=NULL;
   4.472 +    lockresult=PdLockOffscreen(surface->hwdata->offscreenctx, &surface->hwdata->lockparam);
   4.473 +
   4.474 +    switch (lockresult)
   4.475 +    {
   4.476 +       case EOK:
   4.477 +                 break;
   4.478 +       case Pg_OSC_LOCK_DEADLOCK: 
   4.479 +                 SDL_SetError("ph_LockHWSurface(): Deadlock detected !\n");
   4.480 +                 return -1;
   4.481 +       case Pg_OSC_LOCK_INVALID:
   4.482 +                 SDL_SetError("ph_LockHWSurface(): Lock invalid !\n");
   4.483 +                 return -1;
   4.484 +       default:
   4.485 +                 SDL_SetError("ph_LockHWSurface(): Can't lock the surface !\n");
   4.486 +                 return -1;
   4.487 +    }
   4.488 +#endif /* 0 */
   4.489 +
   4.490 +    return 0;
   4.491  }
   4.492  
   4.493 -void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
   4.494 +void ph_UnlockHWSurface(_THIS, SDL_Surface* surface)
   4.495  {
   4.496 +
   4.497 +#if 0 /* FIXME */
   4.498 +    int unlockresult;
   4.499 +
   4.500 +    if ((surface == NULL) || (surface->hwdata == NULL))
   4.501 +    {
   4.502 +        return;
   4.503 +    }
   4.504 +
   4.505 +    if (PdIsOffscreenLocked(surface->hwdata->offscreenctx)==Pg_OSC_LOCKED)
   4.506 +    {
   4.507 +        unlockresult=PdUnlockOffscreen(surface->hwdata->offscreenctx);
   4.508 +    }
   4.509 +#endif /* 0 */
   4.510 +
   4.511      return;
   4.512  }
   4.513  
   4.514 +int ph_HWAccelBlit(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect)
   4.515 +{
   4.516 +    SDL_VideoDevice* this=current_video;
   4.517 +    PhArea_t srcarea;
   4.518 +    PhArea_t dstarea;
   4.519 +    int ydisp=0;
   4.520 +
   4.521 +    /* 640x400 videomode emulation */
   4.522 +    if (videomode_emulatemode==1)
   4.523 +    {
   4.524 +       ydisp+=40;
   4.525 +    }
   4.526 +
   4.527 +    srcarea.pos.x=srcrect->x;
   4.528 +    srcarea.pos.y=srcrect->y;
   4.529 +    srcarea.size.w=srcrect->w;
   4.530 +    srcarea.size.h=srcrect->h;
   4.531 +
   4.532 +    dstarea.pos.x=dstrect->x;
   4.533 +    dstarea.pos.y=dstrect->y;
   4.534 +    dstarea.size.w=dstrect->w;
   4.535 +    dstarea.size.h=dstrect->h;
   4.536 +
   4.537 +    if (((src == this->screen) || (src->hwdata!=NULL)) && ((dst == this->screen) || (dst->hwdata!=NULL)))
   4.538 +    {
   4.539 +        if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
   4.540 +        {
   4.541 +            ph_SetHWColorKey(this, src, src->format->colorkey);
   4.542 +            PgChromaOn();
   4.543 +        }
   4.544 +
   4.545 +        if (dst == this->screen)
   4.546 +        {
   4.547 +            if (src == this->screen)
   4.548 +            {
   4.549 +                /* blitting from main screen to main screen */
   4.550 +                dstarea.pos.y+=ydisp;
   4.551 +                srcarea.pos.y+=ydisp;
   4.552 +                PgContextBlitArea(OCImage.offscreen_context, &srcarea, OCImage.offscreen_context, &dstarea);
   4.553 +            }
   4.554 +            else
   4.555 +            {
   4.556 +                /* blitting from offscreen to main screen */
   4.557 +                dstarea.pos.y+=ydisp;
   4.558 +                PgContextBlitArea(src->hwdata->offscreenctx, &srcarea, OCImage.offscreen_context, &dstarea);
   4.559 +            }
   4.560 +        }
   4.561 +        else
   4.562 +        {
   4.563 +            if (src == this->screen)
   4.564 +            {
   4.565 +                /* blitting from main screen to offscreen */
   4.566 +                srcarea.pos.y+=ydisp;
   4.567 +                PgContextBlitArea(OCImage.offscreen_context, &srcarea, dst->hwdata->offscreenctx, &dstarea);
   4.568 +            }
   4.569 +            else
   4.570 +            {
   4.571 +                /* blitting offscreen to offscreen */
   4.572 +                PgContextBlitArea(src->hwdata->offscreenctx, &srcarea, dst->hwdata->offscreenctx, &dstarea);
   4.573 +            }
   4.574 +        }
   4.575 +
   4.576 +        if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY)
   4.577 +        {
   4.578 +            PgChromaOff();
   4.579 +        }
   4.580 +    }
   4.581 +    else
   4.582 +    {
   4.583 +        SDL_SetError("ph_HWAccelBlit(): Source or target surface is not a hardware surface !\n");
   4.584 +        return -1;
   4.585 +    }
   4.586 +
   4.587 +    PgFlush();
   4.588 +    PgWaitHWIdle();
   4.589 +
   4.590 +    return 0;
   4.591 +}
   4.592 +
   4.593 +int ph_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
   4.594 +{
   4.595 +    if (surface->hwdata!=NULL)
   4.596 +    {
   4.597 +        surface->hwdata->colorkey=ph_ExpandColor(this, surface, key);
   4.598 +        if (surface->hwdata->colorkey==0xFFFFFFFFUL)
   4.599 +        {
   4.600 +            return -1;
   4.601 +        }
   4.602 +    }
   4.603 +    PgSetChroma(surface->hwdata->colorkey, Pg_CHROMA_SRC_MATCH | Pg_CHROMA_NODRAW);
   4.604 +
   4.605 +    return 0;
   4.606 +}
   4.607 +
   4.608 +int ph_SetHWAlpha(_THIS, SDL_Surface* surface, Uint8 alpha)
   4.609 +{
   4.610 +    return -1;
   4.611 +}
   4.612 +
   4.613  #ifdef HAVE_OPENGL
   4.614  void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
   4.615  {
   4.616 @@ -513,12 +970,12 @@
   4.617  
   4.618      for (i=0; i<numrects; ++i) 
   4.619      {
   4.620 -    	if (rects[i].w==0) /* Clipped? */
   4.621 +    	if (rects[i].w==0) /* Clipped? dunno why but this occurs sometime. */
   4.622          { 
   4.623              continue;
   4.624          }
   4.625  
   4.626 -    	if (rects[i].h==0) /* Clipped? */
   4.627 +    	if (rects[i].h==0) /* Clipped? dunno why but this occurs sometime. */
   4.628          { 
   4.629              continue;
   4.630          }
   4.631 @@ -532,13 +989,14 @@
   4.632  
   4.633          if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
   4.634          {
   4.635 -            SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
   4.636 +            SDL_SetError("ph_NormalUpdate(): PgDrawPhImageRectmx failed!\n");
   4.637 +            return;
   4.638          }
   4.639      }
   4.640  
   4.641      if (PgFlush() < 0)
   4.642      {
   4.643 -    	SDL_SetError("ph_NormalUpdate(): PgFlush failed.\n");
   4.644 +    	SDL_SetError("ph_NormalUpdate(): PgFlush() function failed!\n");
   4.645      }
   4.646  }
   4.647  
   4.648 @@ -546,12 +1004,15 @@
   4.649  {
   4.650      int i;
   4.651  
   4.652 -    PhPoint_t zero = {0};
   4.653 +    PhPoint_t zero = {0, 0};
   4.654      PhArea_t src_rect;
   4.655      PhArea_t dest_rect;
   4.656  
   4.657 +    PgSetTranslation(&zero, 0);
   4.658      PgSetRegion(PtWidgetRid(window));
   4.659      PgSetClipping(0, NULL);
   4.660 +
   4.661 +    PgFlush();
   4.662      PgWaitHWIdle();
   4.663  
   4.664      for (i=0; i<numrects; ++i)
   4.665 @@ -565,7 +1026,7 @@
   4.666          {
   4.667              continue;
   4.668          }
   4.669 -
   4.670 +        
   4.671          src_rect.pos.x=rects[i].x;
   4.672          src_rect.pos.y=rects[i].y;
   4.673          dest_rect.pos.x=rects[i].x;
   4.674 @@ -575,12 +1036,7 @@
   4.675          src_rect.size.h=rects[i].h;
   4.676          dest_rect.size.w=rects[i].w;
   4.677          dest_rect.size.h=rects[i].h;
   4.678 -
   4.679 -        zero.x = 0;
   4.680 -        zero.y = 0;
   4.681 -        PgSetTranslation(&zero, 0);
   4.682 -        PgSetRegion(PtWidgetRid(window));
   4.683 -        PgSetClipping(0, NULL);
   4.684 +        
   4.685          PgContextBlitArea(OCImage.offscreen_context, &src_rect, NULL, &dest_rect);
   4.686      }
   4.687  
     5.1 --- a/src/video/photon/SDL_ph_image_c.h	Sat Feb 14 10:12:27 2004 +0000
     5.2 +++ b/src/video/photon/SDL_ph_image_c.h	Sat Feb 14 20:22:21 2004 +0000
     5.3 @@ -31,19 +31,33 @@
     5.4  #include "SDL_events_c.h"
     5.5  #include "SDL_ph_video.h"
     5.6  
     5.7 +struct private_hwdata
     5.8 +{
     5.9 +   PdOffscreenContext_t* offscreenctx;
    5.10 +   PdOSCCreateLockParams_t crlockparam;
    5.11 +   PdOSCLockParams_t lockparam;
    5.12 +   Uint32 colorkey;
    5.13 +};
    5.14 +
    5.15  extern int ph_SetupImage(_THIS, SDL_Surface* screen);
    5.16  extern void ph_DestroyImage(_THIS, SDL_Surface* screen);
    5.17  extern int ph_SetupUpdateFunction(_THIS, SDL_Surface* screen, Uint32 flags);
    5.18  
    5.19 -extern int ph_AllocHWSurface(_THIS, SDL_Surface *surface);
    5.20 -extern void ph_FreeHWSurface(_THIS, SDL_Surface *surface);
    5.21 -extern int ph_LockHWSurface(_THIS, SDL_Surface *surface);
    5.22 -extern void ph_UnlockHWSurface(_THIS, SDL_Surface *surface);
    5.23 -extern int ph_FlipHWSurface(_THIS, SDL_Surface *surface);
    5.24 +extern int ph_AllocHWSurface(_THIS, SDL_Surface* surface);
    5.25 +extern void ph_FreeHWSurface(_THIS, SDL_Surface* surface);
    5.26 +extern int ph_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
    5.27 +extern int ph_FillHWRect(_THIS, SDL_Surface* surface, SDL_Rect* rect, Uint32 color);
    5.28 +extern int ph_LockHWSurface(_THIS, SDL_Surface* surface);
    5.29 +extern void ph_UnlockHWSurface(_THIS, SDL_Surface* surface);
    5.30 +extern int ph_FlipHWSurface(_THIS, SDL_Surface* surface);
    5.31 +extern int ph_SetHWColorKey(_THIS, SDL_Surface* surface, Uint32 key);
    5.32 +extern int ph_SetHWAlpha(_THIS, SDL_Surface* surface, Uint8 alpha);
    5.33 +extern int ph_HWAccelBlit(SDL_Surface* src, SDL_Rect *srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
    5.34 +extern int ph_UpdateHWInfo(_THIS);
    5.35  
    5.36 -extern void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects);
    5.37 -extern void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects);
    5.38 -extern void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect *rects);
    5.39 -extern void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect *rects);
    5.40 +extern void ph_NormalUpdate(_THIS, int numrects, SDL_Rect* rects);
    5.41 +extern void ph_OCUpdate(_THIS, int numrects, SDL_Rect* rects);
    5.42 +extern void ph_OCDCUpdate(_THIS, int numrects, SDL_Rect* rects);
    5.43 +extern void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects);
    5.44  
    5.45  #endif /* __SDL_PH_IMAGE_H__ */
     6.1 --- a/src/video/photon/SDL_ph_modes.c	Sat Feb 14 10:12:27 2004 +0000
     6.2 +++ b/src/video/photon/SDL_ph_modes.c	Sat Feb 14 20:22:21 2004 +0000
     6.3 @@ -80,7 +80,7 @@
     6.4          SDL_modearray[i]=&SDL_modelist[i];
     6.5      }
     6.6  
     6.7 -    if (PgGetVideoModeList( &mode_list ) < 0)
     6.8 +    if (PgGetVideoModeList(&mode_list) < 0)
     6.9      {
    6.10         SDL_SetError("ph_ListModes(): PgGetVideoModeList() function failed !\n");
    6.11         return NULL;
    6.12 @@ -109,10 +109,10 @@
    6.13  
    6.14      for(i=0; i<j; i++)
    6.15      {
    6.16 -        SDL_modelist[i].w = Amodelist[j - i -1].w;
    6.17 -        SDL_modelist[i].h = Amodelist[j - i -1].h;
    6.18 -        SDL_modelist[i].x = Amodelist[j - i -1].x;
    6.19 -        SDL_modelist[i].y = Amodelist[j - i -1].y;
    6.20 +        SDL_modelist[i].w = Amodelist[j - i - 1].w;
    6.21 +        SDL_modelist[i].h = Amodelist[j - i - 1].h;
    6.22 +        SDL_modelist[i].x = Amodelist[j - i - 1].x;
    6.23 +        SDL_modelist[i].y = Amodelist[j - i - 1].y;
    6.24      }
    6.25      SDL_modearray[j]=NULL;
    6.26  	
    6.27 @@ -129,32 +129,54 @@
    6.28  int ph_GetVideoMode(int width, int height, int bpp)
    6.29  {
    6.30      int i;
    6.31 +    int modestage=0;
    6.32 +    int closestmode=0;
    6.33  
    6.34      if (PgGetVideoModeList(&mode_list) < 0)
    6.35      {
    6.36          return -1;
    6.37      }
    6.38  
    6.39 +    /* special case for the double-sized 320x200 mode */
    6.40 +    if ((width==640) && (height==400))
    6.41 +    {
    6.42 +       modestage=1;
    6.43 +    }
    6.44 +
    6.45      /* search list for exact match */
    6.46 -    for (i=0;i<mode_list.num_modes;i++)
    6.47 +    for (i=0; i<mode_list.num_modes; i++)
    6.48      {
    6.49          if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
    6.50          {
    6.51              return 0;
    6.52          }
    6.53  
    6.54 -        if ((mode_info.width == width) && 
    6.55 -            (mode_info.height == height) && 
    6.56 +        if ((mode_info.width == width) && (mode_info.height == height) && 
    6.57              (mode_info.bits_per_pixel == bpp))
    6.58          {
    6.59              return mode_list.modes[i];
    6.60          }
    6.61 +        else
    6.62 +        {
    6.63 +           if ((modestage) && (mode_info.width == width) && (mode_info.height == height+80) && 
    6.64 +               (mode_info.bits_per_pixel == bpp))
    6.65 +           {
    6.66 +              modestage=2;
    6.67 +              closestmode=mode_list.modes[i];
    6.68 +           }
    6.69 +        }
    6.70 +    }
    6.71 +
    6.72 +    /* if we are here, then no 640x400xbpp mode found and we'll emulate it via 640x480xbpp mode */
    6.73 +    if (modestage==2)
    6.74 +    {
    6.75 +       return closestmode;
    6.76      }
    6.77  
    6.78      return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
    6.79  }
    6.80  
    6.81 -/* return the mode associated with width, height and bpp */
    6.82 +/* return the mode associated with width, height and bpp               */
    6.83  /* if requested bpp is not found the mode with closest bpp is returned */
    6.84  int get_mode_any_format(int width, int height, int bpp)
    6.85  {
    6.86 @@ -235,6 +257,8 @@
    6.87  {
    6.88      PgDisplaySettings_t settings;
    6.89      int mode;
    6.90 +    char* refreshrate;
    6.91 +    int refreshratenum;
    6.92  
    6.93      if (!currently_fullscreen)
    6.94      {
    6.95 @@ -254,6 +278,22 @@
    6.96                  SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
    6.97                  return 0;
    6.98              }
    6.99 +            if (PgGetVideoModeInfo(mode, &mode_info) < 0)
   6.100 +            {
   6.101 +                SDL_SetError("ph_EnterFullScreen(): can't get video mode capabilities !\n");
   6.102 +                return 0;
   6.103 +            }
   6.104 +            if (mode_info.height != screen->h)
   6.105 +            {
   6.106 +               if ((mode_info.height==480) && (screen->h==400))
   6.107 +               {
   6.108 +                  videomode_emulatemode=1;
   6.109 +               }
   6.110 +            }
   6.111 +            else
   6.112 +            {
   6.113 +               videomode_emulatemode=0;
   6.114 +            }
   6.115          }
   6.116  
   6.117          /* save old video mode caps */
   6.118 @@ -266,6 +306,15 @@
   6.119          settings.refresh = 0;
   6.120          settings.flags = 0;
   6.121  
   6.122 +        refreshrate=getenv("SDL_PHOTON_FULLSCREEN_REFRESH");
   6.123 +        if (refreshrate!=NULL)
   6.124 +        {
   6.125 +           if (sscanf(refreshrate, "%d", &refreshratenum)==1)
   6.126 +           {
   6.127 +               settings.refresh = refreshratenum;
   6.128 +           }
   6.129 +        }
   6.130 +
   6.131          if (PgSetVideoMode(&settings) < 0)
   6.132          {
   6.133              SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
     7.1 --- a/src/video/photon/SDL_ph_video.c	Sat Feb 14 10:12:27 2004 +0000
     7.2 +++ b/src/video/photon/SDL_ph_video.c	Sat Feb 14 20:22:21 2004 +0000
     7.3 @@ -68,7 +68,7 @@
     7.4  
     7.5  static int ph_Available(void)
     7.6  {
     7.7 -    if (phstatus==-1)
     7.8 +    if (phstatus!=0)
     7.9      {
    7.10          phstatus=PtInit(NULL);
    7.11          if (phstatus==0)
    7.12 @@ -116,10 +116,10 @@
    7.13      device->UpdateRects = NULL;         /* set up in ph_SetupUpdateFunction */
    7.14      device->VideoQuit = ph_VideoQuit;
    7.15      device->AllocHWSurface = ph_AllocHWSurface;
    7.16 -    device->CheckHWBlit = NULL;
    7.17 -    device->FillHWRect = NULL;
    7.18 -    device->SetHWColorKey = NULL;
    7.19 -    device->SetHWAlpha = NULL;
    7.20 +    device->CheckHWBlit = ph_CheckHWBlit;
    7.21 +    device->FillHWRect = ph_FillHWRect;
    7.22 +    device->SetHWColorKey = ph_SetHWColorKey;
    7.23 +    device->SetHWAlpha = ph_SetHWAlpha;
    7.24      device->LockHWSurface = ph_LockHWSurface;
    7.25      device->UnlockHWSurface = ph_UnlockHWSurface;
    7.26      device->FlipHWSurface = ph_FlipHWSurface;
    7.27 @@ -254,6 +254,14 @@
    7.28      }
    7.29      else
    7.30      {
    7.31 +        if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE)
    7.32 +        {
    7.33 +            PtSetArg(&args[nargs++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
    7.34 +        }
    7.35 +        else
    7.36 +        {
    7.37 +            PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
    7.38 +        }
    7.39          if (!currently_maximized)
    7.40          {
    7.41              windowpos = getenv("SDL_VIDEO_WINDOW_POS");
    7.42 @@ -293,8 +301,6 @@
    7.43              }
    7.44          }
    7.45  
    7.46 -        PtSetArg(&args[nargs++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);
    7.47 -        
    7.48          /* if window is maximized render it as maximized */
    7.49          if (currently_maximized)
    7.50          {
    7.51 @@ -311,7 +317,7 @@
    7.52          /* bring the focus to the window */
    7.53          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFOCUS);
    7.54  
    7.55 -        /* allow to catch hide events */
    7.56 +        /* allow to catch hide event */
    7.57          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_HIDE);
    7.58          PtSetArg(&args[nargs++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE, Ph_WM_HIDE);
    7.59      }
    7.60 @@ -320,6 +326,11 @@
    7.61      PtRealizeWidget(window);
    7.62      PtWindowToFront(window);
    7.63  
    7.64 +#if 0 /* FIXME */
    7.65 +    PtGetResource(window, Pt_ARG_POS, &olddim, 0);
    7.66 +    fprintf(stderr, "POSITION: %d, %d\n", olddim->w, olddim->h);
    7.67 +#endif
    7.68 +
    7.69      return 0;
    7.70  }
    7.71  
    7.72 @@ -350,9 +361,9 @@
    7.73      return NULL;
    7.74  }
    7.75  
    7.76 -static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
    7.77 +static int ph_VideoInit(_THIS, SDL_PixelFormat* vformat)
    7.78  {
    7.79 -    PgHWCaps_t my_hwcaps;
    7.80 +    PgHWCaps_t hwcaps;
    7.81      int i;
    7.82  
    7.83      window=NULL;
    7.84 @@ -391,14 +402,14 @@
    7.85          return -1;
    7.86      }
    7.87  
    7.88 -    if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
    7.89 +    if (PgGetGraphicsHWCaps(&hwcaps) < 0)
    7.90      {
    7.91          SDL_SetError("ph_VideoInit(): GetGraphicsHWCaps function failed !\n");
    7.92          this->FreeWMCursor(this, SDL_BlankCursor);
    7.93          return -1;
    7.94      }
    7.95  
    7.96 -    if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &desktop_mode) < 0)
    7.97 +    if (PgGetVideoModeInfo(hwcaps.current_video_mode, &desktop_mode) < 0)
    7.98      {
    7.99          SDL_SetError("ph_VideoInit(): PgGetVideoModeInfo function failed !\n");
   7.100          this->FreeWMCursor(this, SDL_BlankCursor);
   7.101 @@ -437,15 +448,22 @@
   7.102      OCImage.CurrentFrameData = NULL;
   7.103      OCImage.FrameData0 = NULL;
   7.104      OCImage.FrameData1 = NULL;
   7.105 +    videomode_emulatemode = 0;
   7.106      
   7.107 +    this->info.video_mem=hwcaps.currently_available_video_ram/1024;
   7.108      this->info.wm_available = 1;
   7.109 +    this->info.hw_available = 1;
   7.110 +    this->info.blit_fill = 1;
   7.111 +    this->info.blit_hw = 1;
   7.112 +    this->info.blit_hw_A = 0;
   7.113 +    this->info.blit_hw_CC = 1;
   7.114      
   7.115      return 0;
   7.116  }
   7.117  
   7.118 -static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
   7.119 -                int width, int height, int bpp, Uint32 flags)
   7.120 +static SDL_Surface* ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
   7.121  {
   7.122 +    PgHWCaps_t hwcaps;
   7.123      const struct ColourMasks* mask;
   7.124  
   7.125      /* Lock the event thread, in multi-threading environments */
   7.126 @@ -474,13 +492,13 @@
   7.127          return NULL;
   7.128      }
   7.129  
   7.130 -#ifdef HAVE_OPENGL
   7.131      if ((current->flags & SDL_OPENGL)==SDL_OPENGL)
   7.132      {
   7.133 -#else
   7.134 -    if ((current->flags & SDL_OPENGL)==SDL_OPENGL) /* if no built-in OpenGL support */
   7.135 +#if !defined(HAVE_OPENGL)
   7.136 +    if ((current->flags & SDL_OPENGL)==SDL_OPENGL)
   7.137      {
   7.138 -        SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n");
   7.139 +        /* if no built-in OpenGL support */
   7.140 +        SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n");
   7.141          current->flags &= ~SDL_OPENGL;
   7.142          return NULL;
   7.143  #endif /* HAVE_OPENGL */
   7.144 @@ -500,13 +518,12 @@
   7.145          }
   7.146          else
   7.147          {
   7.148 -            /* remove this if we'll support non-fullscreen sw/hw+doublebuf */
   7.149 +            /* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */
   7.150              current->flags &= ~SDL_DOUBLEBUF;
   7.151  
   7.152              /* Use offscreen memory if SDL_HWSURFACE flag is set */
   7.153              if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
   7.154              {
   7.155 -
   7.156                  if (desktopbpp!=bpp)
   7.157                  {
   7.158                     current->flags &= ~SDL_HWSURFACE;
   7.159 @@ -556,9 +573,18 @@
   7.160         PgFlush();
   7.161      }
   7.162  
   7.163 +    visualbpp=bpp;
   7.164 +
   7.165 +    if (PgGetGraphicsHWCaps(&hwcaps) < 0)
   7.166 +    {
   7.167 +        SDL_SetError("ph_SetVideoMode(): GetGraphicsHWCaps function failed !\n");
   7.168 +        return NULL;
   7.169 +    }
   7.170 +    this->info.video_mem=hwcaps.currently_available_video_ram/1024;
   7.171 +
   7.172      SDL_Unlock_EventThread();
   7.173  
   7.174 -    /* We're done! */
   7.175 +    /* We've done! */
   7.176      return (current);
   7.177  }
   7.178  
     8.1 --- a/src/video/photon/SDL_ph_video.h	Sat Feb 14 10:12:27 2004 +0000
     8.2 +++ b/src/video/photon/SDL_ph_video.h	Sat Feb 14 20:22:21 2004 +0000
     8.3 @@ -96,8 +96,9 @@
     8.4  
     8.5      int mouse_relative;
     8.6      WMcursor* BlankCursor;
     8.7 +    uint32_t videomode_emulatemode;
     8.8  
     8.9 -    Uint32 depth;	            /* current visual depth (not bpp)              */
    8.10 +    Uint32 visualbpp;	            /* current visual bpp                          */
    8.11      Uint32 desktopbpp;              /* bpp of desktop at the moment of start       */
    8.12      Uint32 desktoppal;              /* palette mode emulation or system            */
    8.13  
    8.14 @@ -109,25 +110,27 @@
    8.15      SDL_Overlay* overlay;
    8.16  };
    8.17  
    8.18 -#define mode_settings        (this->hidden->mode_settings)
    8.19 -#define window	             (this->hidden->Window)
    8.20 -#define SDL_Image            (this->hidden->image)
    8.21 -#define OCImage              (this->hidden->ocimage)
    8.22 -#define old_video_mode       (this->hidden->old_video_mode)
    8.23 -#define old_refresh_rate     (this->hidden->old_refresh_rate)
    8.24 -#define graphics_card_caps   (this->hidden->graphics_card_caps)
    8.25 -#define desktopbpp           (this->hidden->desktopbpp)
    8.26 -#define desktoppal           (this->hidden->desktoppal)
    8.27 -#define savedpal             (this->hidden->savedpal)
    8.28 -#define syspalph             (this->hidden->syspalph)
    8.29 -#define currently_fullscreen (this->hidden->currently_fullscreen)
    8.30 -#define currently_hided      (this->hidden->currently_hided)
    8.31 -#define currently_maximized  (this->hidden->currently_maximized)
    8.32 -#define event                (this->hidden->event)
    8.33 -#define current_overlay      (this->hidden->overlay)
    8.34 -#define desktop_mode         (this->hidden->desktop_mode)
    8.35 -#define mouse_relative       (this->hidden->mouse_relative)
    8.36 -#define SDL_BlankCursor      (this->hidden->BlankCursor)
    8.37 +#define mode_settings         (this->hidden->mode_settings)
    8.38 +#define window	              (this->hidden->Window)
    8.39 +#define SDL_Image             (this->hidden->image)
    8.40 +#define OCImage               (this->hidden->ocimage)
    8.41 +#define old_video_mode        (this->hidden->old_video_mode)
    8.42 +#define old_refresh_rate      (this->hidden->old_refresh_rate)
    8.43 +#define graphics_card_caps    (this->hidden->graphics_card_caps)
    8.44 +#define desktopbpp            (this->hidden->desktopbpp)
    8.45 +#define visualbpp             (this->hidden->visualbpp)
    8.46 +#define desktoppal            (this->hidden->desktoppal)
    8.47 +#define savedpal              (this->hidden->savedpal)
    8.48 +#define syspalph              (this->hidden->syspalph)
    8.49 +#define currently_fullscreen  (this->hidden->currently_fullscreen)
    8.50 +#define currently_hided       (this->hidden->currently_hided)
    8.51 +#define currently_maximized   (this->hidden->currently_maximized)
    8.52 +#define event                 (this->hidden->event)
    8.53 +#define current_overlay       (this->hidden->overlay)
    8.54 +#define desktop_mode          (this->hidden->desktop_mode)
    8.55 +#define mouse_relative        (this->hidden->mouse_relative)
    8.56 +#define SDL_BlankCursor       (this->hidden->BlankCursor)
    8.57 +#define videomode_emulatemode (this->hidden->videomode_emulatemode)
    8.58  
    8.59  #ifdef HAVE_OPENGL
    8.60       #define oglctx               (this->hidden->OGLContext)
     9.1 --- a/test/testvidinfo.c	Sat Feb 14 10:12:27 2004 +0000
     9.2 +++ b/test/testvidinfo.c	Sat Feb 14 20:22:21 2004 +0000
     9.3 @@ -27,6 +27,12 @@
     9.4  	if ( flags & SDL_DOUBLEBUF ) {
     9.5  		printf(" | SDL_DOUBLEBUF");
     9.6  	}
     9.7 +	if ( flags & SDL_SRCCOLORKEY ) {
     9.8 +		printf(" | SDL_SRCCOLORKEY");
     9.9 +	}
    9.10 +	if ( flags & SDL_RLEACCEL ) {
    9.11 +		printf(" | SDL_RLEACCEL");
    9.12 +	}
    9.13  }
    9.14  
    9.15  int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
    9.16 @@ -67,7 +73,7 @@
    9.17  	float seconds;
    9.18  	int i;
    9.19  	Uint8 r, g, b;
    9.20 -	SDL_Surface *bmp, *tmp;
    9.21 +	SDL_Surface *bmp, *bmpcc, *tmp;
    9.22  	SDL_Event event;
    9.23  
    9.24  	while ( SDL_PollEvent(&event) ) {
    9.25 @@ -116,6 +122,7 @@
    9.26  			return 0;
    9.27  	}
    9.28  
    9.29 +        /* run the generic blit test */
    9.30  	bmp = SDL_LoadBMP("sample.bmp");
    9.31  	if ( ! bmp ) {
    9.32  		printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
    9.33 @@ -135,6 +142,29 @@
    9.34  		printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
    9.35  	}
    9.36  
    9.37 +        /* run the colorkeyed blit test */
    9.38 +	bmpcc = SDL_LoadBMP("sample.bmp");
    9.39 +	if ( ! bmpcc ) {
    9.40 +		printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
    9.41 +		return 0;
    9.42 +	}
    9.43 +	printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ",
    9.44 +		bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
    9.45 +        SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels);
    9.46 +
    9.47 +	PrintFlags(bmpcc->flags);
    9.48 +	printf("\n");
    9.49 +	then = SDL_GetTicks();
    9.50 +	frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
    9.51 +	now = SDL_GetTicks();
    9.52 +	seconds = (float)(now - then) / 1000.0f;
    9.53 +	if ( seconds > 0.0f ) {
    9.54 +		printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
    9.55 +	} else {
    9.56 +		printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
    9.57 +	}
    9.58 +
    9.59 +        /* run the generic blit test */
    9.60  	tmp = bmp;
    9.61  	bmp = SDL_DisplayFormat(bmp);
    9.62  	SDL_FreeSurface(tmp);
    9.63 @@ -155,6 +185,30 @@
    9.64  	} else {
    9.65  		printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
    9.66  	}
    9.67 +
    9.68 +        /* run the colorkeyed blit test */
    9.69 +	tmp = bmpcc;
    9.70 +	bmpcc = SDL_DisplayFormat(bmpcc);
    9.71 +	SDL_FreeSurface(tmp);
    9.72 +	if ( ! bmpcc ) {
    9.73 +		printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
    9.74 +		return 0;
    9.75 +	}
    9.76 +	printf("Running display format cc blit test: %dx%d at %d bpp, flags: ",
    9.77 +		bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
    9.78 +	PrintFlags(bmpcc->flags);
    9.79 +	printf("\n");
    9.80 +	then = SDL_GetTicks();
    9.81 +	frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
    9.82 +	now = SDL_GetTicks();
    9.83 +	seconds = (float)(now - then) / 1000.0f;
    9.84 +	if ( seconds > 0.0f ) {
    9.85 +		printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
    9.86 +	} else {
    9.87 +		printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
    9.88 +	}
    9.89 +
    9.90 +	SDL_FreeSurface(bmpcc);
    9.91  	SDL_FreeSurface(bmp);
    9.92  
    9.93  	while ( SDL_PollEvent(&event) ) {