Date: Fri, 23 Aug 2002 11:48:56 +0200
authorSam Lantinga <slouken@libsdl.org>
Sat, 24 Aug 2002 15:29:06 +0000
changeset 4641c4be4a16410
parent 463 bf7389310d27
child 465 25f475cd4981
Date: Fri, 23 Aug 2002 11:48:56 +0200
From: Denis Oliver Kropp
Subject: Another patch

this is another patch fixing key code mapping
along with some other fixes and better mode handling.
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_video.h
     1.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Wed Aug 21 04:16:31 2002 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Sat Aug 24 15:29:06 2002 +0000
     1.3 @@ -100,88 +100,88 @@
     1.4    for (i=0; i<SDL_TABLESIZE(keymap); ++i)
     1.5      keymap[i] = SDLK_UNKNOWN;
     1.6  
     1.7 -  keymap[DIKI_A] = SDLK_a;
     1.8 -  keymap[DIKI_B] = SDLK_b;
     1.9 -  keymap[DIKI_C] = SDLK_c;
    1.10 -  keymap[DIKI_D] = SDLK_d;
    1.11 -  keymap[DIKI_E] = SDLK_e;
    1.12 -  keymap[DIKI_F] = SDLK_f;
    1.13 -  keymap[DIKI_G] = SDLK_g;
    1.14 -  keymap[DIKI_H] = SDLK_h;
    1.15 -  keymap[DIKI_I] = SDLK_i;
    1.16 -  keymap[DIKI_J] = SDLK_j;
    1.17 -  keymap[DIKI_K] = SDLK_k;
    1.18 -  keymap[DIKI_L] = SDLK_l;
    1.19 -  keymap[DIKI_M] = SDLK_m;
    1.20 -  keymap[DIKI_N] = SDLK_n;
    1.21 -  keymap[DIKI_O] = SDLK_o;
    1.22 -  keymap[DIKI_P] = SDLK_p;
    1.23 -  keymap[DIKI_Q] = SDLK_q;
    1.24 -  keymap[DIKI_R] = SDLK_r;
    1.25 -  keymap[DIKI_S] = SDLK_s;
    1.26 -  keymap[DIKI_T] = SDLK_t;
    1.27 -  keymap[DIKI_U] = SDLK_u;
    1.28 -  keymap[DIKI_V] = SDLK_v;
    1.29 -  keymap[DIKI_W] = SDLK_w;
    1.30 -  keymap[DIKI_X] = SDLK_x;
    1.31 -  keymap[DIKI_Y] = SDLK_y;
    1.32 -  keymap[DIKI_Z] = SDLK_z;
    1.33 +  keymap[DIKI_A - DIKI_UNKNOWN] = SDLK_a;
    1.34 +  keymap[DIKI_B - DIKI_UNKNOWN] = SDLK_b;
    1.35 +  keymap[DIKI_C - DIKI_UNKNOWN] = SDLK_c;
    1.36 +  keymap[DIKI_D - DIKI_UNKNOWN] = SDLK_d;
    1.37 +  keymap[DIKI_E - DIKI_UNKNOWN] = SDLK_e;
    1.38 +  keymap[DIKI_F - DIKI_UNKNOWN] = SDLK_f;
    1.39 +  keymap[DIKI_G - DIKI_UNKNOWN] = SDLK_g;
    1.40 +  keymap[DIKI_H - DIKI_UNKNOWN] = SDLK_h;
    1.41 +  keymap[DIKI_I - DIKI_UNKNOWN] = SDLK_i;
    1.42 +  keymap[DIKI_J - DIKI_UNKNOWN] = SDLK_j;
    1.43 +  keymap[DIKI_K - DIKI_UNKNOWN] = SDLK_k;
    1.44 +  keymap[DIKI_L - DIKI_UNKNOWN] = SDLK_l;
    1.45 +  keymap[DIKI_M - DIKI_UNKNOWN] = SDLK_m;
    1.46 +  keymap[DIKI_N - DIKI_UNKNOWN] = SDLK_n;
    1.47 +  keymap[DIKI_O - DIKI_UNKNOWN] = SDLK_o;
    1.48 +  keymap[DIKI_P - DIKI_UNKNOWN] = SDLK_p;
    1.49 +  keymap[DIKI_Q - DIKI_UNKNOWN] = SDLK_q;
    1.50 +  keymap[DIKI_R - DIKI_UNKNOWN] = SDLK_r;
    1.51 +  keymap[DIKI_S - DIKI_UNKNOWN] = SDLK_s;
    1.52 +  keymap[DIKI_T - DIKI_UNKNOWN] = SDLK_t;
    1.53 +  keymap[DIKI_U - DIKI_UNKNOWN] = SDLK_u;
    1.54 +  keymap[DIKI_V - DIKI_UNKNOWN] = SDLK_v;
    1.55 +  keymap[DIKI_W - DIKI_UNKNOWN] = SDLK_w;
    1.56 +  keymap[DIKI_X - DIKI_UNKNOWN] = SDLK_x;
    1.57 +  keymap[DIKI_Y - DIKI_UNKNOWN] = SDLK_y;
    1.58 +  keymap[DIKI_Z - DIKI_UNKNOWN] = SDLK_z;
    1.59    
    1.60 -  keymap[DIKI_0] = SDLK_0;
    1.61 -  keymap[DIKI_1] = SDLK_1;
    1.62 -  keymap[DIKI_2] = SDLK_2;
    1.63 -  keymap[DIKI_3] = SDLK_3;
    1.64 -  keymap[DIKI_4] = SDLK_4;
    1.65 -  keymap[DIKI_5] = SDLK_5;
    1.66 -  keymap[DIKI_6] = SDLK_6;
    1.67 -  keymap[DIKI_7] = SDLK_7;
    1.68 -  keymap[DIKI_8] = SDLK_8;
    1.69 -  keymap[DIKI_9] = SDLK_9;
    1.70 +  keymap[DIKI_0 - DIKI_UNKNOWN] = SDLK_0;
    1.71 +  keymap[DIKI_1 - DIKI_UNKNOWN] = SDLK_1;
    1.72 +  keymap[DIKI_2 - DIKI_UNKNOWN] = SDLK_2;
    1.73 +  keymap[DIKI_3 - DIKI_UNKNOWN] = SDLK_3;
    1.74 +  keymap[DIKI_4 - DIKI_UNKNOWN] = SDLK_4;
    1.75 +  keymap[DIKI_5 - DIKI_UNKNOWN] = SDLK_5;
    1.76 +  keymap[DIKI_6 - DIKI_UNKNOWN] = SDLK_6;
    1.77 +  keymap[DIKI_7 - DIKI_UNKNOWN] = SDLK_7;
    1.78 +  keymap[DIKI_8 - DIKI_UNKNOWN] = SDLK_8;
    1.79 +  keymap[DIKI_9 - DIKI_UNKNOWN] = SDLK_9;
    1.80    
    1.81 -  keymap[DIKI_F1] = SDLK_F1;
    1.82 -  keymap[DIKI_F2] = SDLK_F2;
    1.83 -  keymap[DIKI_F3] = SDLK_F3;
    1.84 -  keymap[DIKI_F4] = SDLK_F4;
    1.85 -  keymap[DIKI_F5] = SDLK_F5;
    1.86 -  keymap[DIKI_F6] = SDLK_F6;
    1.87 -  keymap[DIKI_F7] = SDLK_F7;
    1.88 -  keymap[DIKI_F8] = SDLK_F8;
    1.89 -  keymap[DIKI_F9] = SDLK_F9;
    1.90 -  keymap[DIKI_F10] = SDLK_F10;
    1.91 -  keymap[DIKI_F11] = SDLK_F11;
    1.92 -  keymap[DIKI_F12] = SDLK_F12;
    1.93 +  keymap[DIKI_F1 - DIKI_UNKNOWN] = SDLK_F1;
    1.94 +  keymap[DIKI_F2 - DIKI_UNKNOWN] = SDLK_F2;
    1.95 +  keymap[DIKI_F3 - DIKI_UNKNOWN] = SDLK_F3;
    1.96 +  keymap[DIKI_F4 - DIKI_UNKNOWN] = SDLK_F4;
    1.97 +  keymap[DIKI_F5 - DIKI_UNKNOWN] = SDLK_F5;
    1.98 +  keymap[DIKI_F6 - DIKI_UNKNOWN] = SDLK_F6;
    1.99 +  keymap[DIKI_F7 - DIKI_UNKNOWN] = SDLK_F7;
   1.100 +  keymap[DIKI_F8 - DIKI_UNKNOWN] = SDLK_F8;
   1.101 +  keymap[DIKI_F9 - DIKI_UNKNOWN] = SDLK_F9;
   1.102 +  keymap[DIKI_F10 - DIKI_UNKNOWN] = SDLK_F10;
   1.103 +  keymap[DIKI_F11 - DIKI_UNKNOWN] = SDLK_F11;
   1.104 +  keymap[DIKI_F12 - DIKI_UNKNOWN] = SDLK_F12;
   1.105    
   1.106 -  keymap[DIKI_ESCAPE] = SDLK_ESCAPE;
   1.107 -  keymap[DIKI_LEFT] = SDLK_LEFT;
   1.108 -  keymap[DIKI_RIGHT] = SDLK_RIGHT;
   1.109 -  keymap[DIKI_UP] = SDLK_UP;
   1.110 -  keymap[DIKI_DOWN] = SDLK_DOWN;
   1.111 -  keymap[DIKI_CONTROL_L] = SDLK_LCTRL;
   1.112 -  keymap[DIKI_CONTROL_R] = SDLK_RCTRL;
   1.113 -  keymap[DIKI_SHIFT_L] = SDLK_LSHIFT;
   1.114 -  keymap[DIKI_SHIFT_R] = SDLK_RSHIFT;
   1.115 -  keymap[DIKI_ALT_L] = SDLK_LALT;
   1.116 -  keymap[DIKI_ALTGR] = SDLK_RALT;
   1.117 -  keymap[DIKI_TAB] = SDLK_TAB;
   1.118 -  keymap[DIKI_ENTER] = SDLK_RETURN;
   1.119 -  keymap[DIKI_SPACE] = SDLK_SPACE;
   1.120 -  keymap[DIKI_BACKSPACE] = SDLK_BACKSPACE;
   1.121 -  keymap[DIKI_INSERT] = SDLK_INSERT;
   1.122 -  keymap[DIKI_DELETE] = SDLK_DELETE;
   1.123 -  keymap[DIKI_HOME] = SDLK_HOME;
   1.124 -  keymap[DIKI_END] = SDLK_END;
   1.125 -  keymap[DIKI_PAGE_UP] = SDLK_PAGEUP;
   1.126 -  keymap[DIKI_PAGE_DOWN] = SDLK_PAGEDOWN;
   1.127 -  keymap[DIKI_CAPS_LOCK] = SDLK_CAPSLOCK;
   1.128 -  keymap[DIKI_NUM_LOCK] = SDLK_NUMLOCK;
   1.129 -  keymap[DIKI_SCROLL_LOCK] = SDLK_SCROLLOCK;
   1.130 -  keymap[DIKI_PRINT] = SDLK_PRINT;
   1.131 -  keymap[DIKI_PAUSE] = SDLK_PAUSE;
   1.132 -  keymap[DIKI_KP_DIV] = SDLK_KP_DIVIDE;
   1.133 -  keymap[DIKI_KP_MULT] = SDLK_KP_MULTIPLY;
   1.134 -  keymap[DIKI_KP_MINUS] = SDLK_KP_MINUS;
   1.135 -  keymap[DIKI_KP_PLUS] = SDLK_KP_PLUS;
   1.136 -  keymap[DIKI_KP_ENTER] = SDLK_KP_ENTER;
   1.137 +  keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDLK_ESCAPE;
   1.138 +  keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDLK_LEFT;
   1.139 +  keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDLK_RIGHT;
   1.140 +  keymap[DIKI_UP - DIKI_UNKNOWN] = SDLK_UP;
   1.141 +  keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDLK_DOWN;
   1.142 +  keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDLK_LCTRL;
   1.143 +  keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDLK_RCTRL;
   1.144 +  keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
   1.145 +  keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
   1.146 +  keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
   1.147 +  keymap[DIKI_ALTGR - DIKI_UNKNOWN] = SDLK_RALT;
   1.148 +  keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
   1.149 +  keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
   1.150 +  keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
   1.151 +  keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDLK_BACKSPACE;
   1.152 +  keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDLK_INSERT;
   1.153 +  keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDLK_DELETE;
   1.154 +  keymap[DIKI_HOME - DIKI_UNKNOWN] = SDLK_HOME;
   1.155 +  keymap[DIKI_END - DIKI_UNKNOWN] = SDLK_END;
   1.156 +  keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDLK_PAGEUP;
   1.157 +  keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDLK_PAGEDOWN;
   1.158 +  keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDLK_CAPSLOCK;
   1.159 +  keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDLK_NUMLOCK;
   1.160 +  keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDLK_SCROLLOCK;
   1.161 +  keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDLK_PRINT;
   1.162 +  keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDLK_PAUSE;
   1.163 +  keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDLK_KP_DIVIDE;
   1.164 +  keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDLK_KP_MULTIPLY;
   1.165 +  keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDLK_KP_MINUS;
   1.166 +  keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDLK_KP_PLUS;
   1.167 +  keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDLK_KP_ENTER;
   1.168  }
   1.169  
   1.170  
   1.171 @@ -195,7 +195,7 @@
   1.172    if (ev->key_symbol > 0 && ev->key_symbol < 128)
   1.173      keysym->sym = ev->key_symbol;
   1.174    else
   1.175 -    keysym->sym = keymap[ev->key_id];
   1.176 +    keysym->sym = keymap[ev->key_id - DIKI_UNKNOWN];
   1.177  
   1.178    return keysym;
   1.179  }
     2.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Wed Aug 21 04:16:31 2002 +0000
     2.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Sat Aug 24 15:29:06 2002 +0000
     2.3 @@ -29,6 +29,7 @@
     2.4  */
     2.5  
     2.6  #include <stdlib.h>
     2.7 +#include <string.h>
     2.8  #include <stdio.h>
     2.9  #include <fcntl.h>
    2.10  #include <unistd.h>
    2.11 @@ -78,7 +79,7 @@
    2.12  	struct DirectFBEnumRect* next;
    2.13  };
    2.14  
    2.15 -static struct DirectFBEnumRect *enumlists[NUM_MODELISTS];
    2.16 +static struct DirectFBEnumRect *enumlist = NULL;
    2.17  
    2.18  
    2.19  /* DirectFB driver bootstrap functions */
    2.20 @@ -150,6 +151,31 @@
    2.21    DirectFB_Available, DirectFB_CreateDevice
    2.22  };
    2.23  
    2.24 +static DFBSurfacePixelFormat GetFormatForBpp (int bpp, IDirectFBDisplayLayer *layer)
    2.25 +{
    2.26 +  DFBDisplayLayerConfig dlc;
    2.27 +  int                   bytes = (bpp + 7) / 8;
    2.28 +
    2.29 +  layer->GetConfiguration (layer, &dlc);
    2.30 +
    2.31 +  if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat))
    2.32 +    return dlc.pixelformat;
    2.33 +
    2.34 +  switch (bytes)
    2.35 +    {
    2.36 +    case 1:
    2.37 +      return DSPF_RGB332;
    2.38 +    case 2:
    2.39 +      return DSPF_RGB16;
    2.40 +    case 3:
    2.41 +      return DSPF_RGB24;
    2.42 +    case 4:
    2.43 +      return DSPF_RGB32;
    2.44 +    }
    2.45 +
    2.46 +  return DSPF_UNKNOWN;
    2.47 +}
    2.48 +
    2.49  static DFBEnumerationResult EnumModesCallback (unsigned int  width,
    2.50                                                 unsigned int  height,
    2.51                                                 unsigned int  bpp,
    2.52 @@ -158,30 +184,21 @@
    2.53    SDL_VideoDevice *this = (SDL_VideoDevice *)data;
    2.54    struct DirectFBEnumRect *enumrect;
    2.55  
    2.56 -  switch (bpp)
    2.57 +  HIDDEN->nummodes++;
    2.58 +
    2.59 +  enumrect = calloc(1, sizeof(struct DirectFBEnumRect));
    2.60 +  if (!enumrect)
    2.61      {
    2.62 -    case 8:
    2.63 -    case 15:
    2.64 -    case 16:
    2.65 -    case 24:
    2.66 -    case 32:
    2.67 -      bpp /= 8; --bpp;
    2.68 -      ++HIDDEN->SDL_nummodes[bpp];
    2.69 -      enumrect = (struct DirectFBEnumRect*)malloc(sizeof(struct DirectFBEnumRect));
    2.70 -      if ( !enumrect )
    2.71 -        {
    2.72 -          SDL_OutOfMemory();
    2.73 -          return DFENUM_CANCEL;
    2.74 -        }
    2.75 -      enumrect->r.x = 0;
    2.76 -      enumrect->r.y = 0;
    2.77 -      enumrect->r.w = width;
    2.78 -      enumrect->r.h = height;
    2.79 -      enumrect->next = enumlists[bpp];
    2.80 -      enumlists[bpp] = enumrect;
    2.81 -      break;
    2.82 +      SDL_OutOfMemory();
    2.83 +      return DFENUM_CANCEL;
    2.84      }
    2.85  
    2.86 +  enumrect->r.w  = width;
    2.87 +  enumrect->r.h  = height;
    2.88 +  enumrect->next = enumlist;
    2.89 +
    2.90 +  enumlist = enumrect;
    2.91 +
    2.92    return DFENUM_OK;
    2.93  }
    2.94  
    2.95 @@ -219,13 +236,20 @@
    2.96              return DSPF_RGB15;
    2.97            break;
    2.98            
    2.99 +        case 8:
   2.100 +          if (format->Rmask == 0xE0 &&
   2.101 +              format->Gmask == 0x1C &&
   2.102 +              format->Bmask == 0x03)
   2.103 +            return DSPF_RGB332;
   2.104 +          break;
   2.105 +          
   2.106          case 24:
   2.107            if (format->Rmask == 0xFF0000 &&
   2.108                format->Gmask == 0x00FF00 &&
   2.109                format->Bmask == 0x0000FF)
   2.110              return DSPF_RGB24;
   2.111            break;
   2.112 -          
   2.113 +
   2.114          case 32:
   2.115            if (format->Rmask == 0xFF0000 &&
   2.116                format->Gmask == 0x00FF00 &&
   2.117 @@ -243,6 +267,8 @@
   2.118      {
   2.119        switch (format->BitsPerPixel)
   2.120  	{
   2.121 +        case 8:
   2.122 +          return DSPF_RGB332;
   2.123  	case 15:
   2.124  	  return DSPF_RGB15;
   2.125  	case 16:
   2.126 @@ -257,28 +283,67 @@
   2.127    return DSPF_UNKNOWN;
   2.128  }
   2.129  
   2.130 +static const __u8 lookup3to8[] = { 0x00, 0x24, 0x49, 0x6d, 0x92, 0xb6, 0xdb, 0xff };
   2.131 +static const __u8 lookup2to8[] = { 0x00, 0x55, 0xaa, 0xff };
   2.132 +
   2.133 +static SDL_Palette *GenerateRGB332Palette()
   2.134 +{
   2.135 +  int          i;
   2.136 +  SDL_Palette *palette;
   2.137 +  SDL_Color   *colors;
   2.138 +
   2.139 +  palette = calloc (1, sizeof(SDL_Palette));
   2.140 +  if (!palette)
   2.141 +    {
   2.142 +      SDL_OutOfMemory();
   2.143 +      return NULL;
   2.144 +    }
   2.145 +
   2.146 +  colors = calloc (256, sizeof(SDL_Color));
   2.147 +  if (!colors)
   2.148 +    {
   2.149 +      SDL_OutOfMemory();
   2.150 +      return NULL;
   2.151 +    }
   2.152 +
   2.153 +  for (i=0; i<256; i++)
   2.154 +    {
   2.155 +      colors[i].r = lookup3to8[ i >> 5 ];
   2.156 +      colors[i].g = lookup3to8[ (i >> 2) & 7 ];
   2.157 +      colors[i].g = lookup2to8[ i & 3 ];
   2.158 +    }
   2.159 +
   2.160 +  palette->ncolors = 256;
   2.161 +  palette->colors  = colors;
   2.162 +
   2.163 +  return palette;
   2.164 +}
   2.165 +
   2.166  static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelFormat *format)
   2.167  {
   2.168 -  format->BitsPerPixel = 0;
   2.169    format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
   2.170 +  format->BitsPerPixel = format->BytesPerPixel = 0;
   2.171  
   2.172    switch (pixelformat)
   2.173      {
   2.174      case DSPF_A8:
   2.175        format->Amask = 0x000000FF;
   2.176        break;
   2.177 +
   2.178      case DSPF_RGB15:
   2.179        format->Rmask = 0x00007C00;
   2.180        format->Gmask = 0x000003E0;
   2.181        format->Bmask = 0x0000001F;
   2.182        break;
   2.183 +
   2.184      case DSPF_RGB16:
   2.185        format->Rmask = 0x0000F800;
   2.186        format->Gmask = 0x000007E0;
   2.187        format->Bmask = 0x0000001F;
   2.188        break;
   2.189 +
   2.190      case DSPF_ARGB:
   2.191 -      format->Amask = 0xFF000000;
   2.192 +      format->Amask = 0; /* apps don't seem to like that:  0xFF000000; */
   2.193        /* fall through */
   2.194      case DSPF_RGB24:
   2.195      case DSPF_RGB32:
   2.196 @@ -286,11 +351,21 @@
   2.197        format->Gmask = 0x0000FF00;
   2.198        format->Bmask = 0x000000FF;
   2.199        break;
   2.200 +
   2.201 +    case DSPF_RGB332:
   2.202 +      format->Rmask = 0x000000E0;
   2.203 +      format->Gmask = 0x0000001C;
   2.204 +      format->Bmask = 0x00000003;
   2.205 +
   2.206 +      format->palette = GenerateRGB332Palette();
   2.207 +      break;
   2.208 +
   2.209      default:
   2.210        return -1;
   2.211      }
   2.212  
   2.213 -  format->BitsPerPixel = DFB_BITS_PER_PIXEL(pixelformat);
   2.214 +  format->BitsPerPixel  = DFB_BYTES_PER_PIXEL(pixelformat) * 8;
   2.215 +  format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat);
   2.216  
   2.217    return 0;
   2.218  }
   2.219 @@ -298,44 +373,43 @@
   2.220  
   2.221  int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
   2.222  {
   2.223 -  int                    i, j;
   2.224 -  DFBResult              ret;
   2.225 -  IDirectFB             *dfb;
   2.226 -  DFBCardCapabilities    caps;
   2.227 -  IDirectFBDisplayLayer *layer;
   2.228 -  DFBDisplayLayerConfig  dlc;
   2.229 -  IDirectFBEventBuffer  *eventbuffer;
   2.230 +  int                      i;
   2.231 +  DFBResult                ret;
   2.232 +  DFBCardCapabilities      caps;
   2.233 +  DFBDisplayLayerConfig    dlc;
   2.234 +  DFBSurfacePixelFormat    format;
   2.235 +  struct DirectFBEnumRect *rect;
   2.236 +  IDirectFB               *dfb    = NULL;
   2.237 +  IDirectFBDisplayLayer   *layer  = NULL;
   2.238 +  IDirectFBEventBuffer    *events = NULL;
   2.239  
   2.240  
   2.241    ret = DirectFBInit (NULL, NULL);
   2.242    if (ret)
   2.243      {
   2.244        SetDirectFBerror ("DirectFBInit", ret);
   2.245 -      return -1;
   2.246 +      goto error;
   2.247      }
   2.248  
   2.249    ret = DirectFBCreate (&dfb);
   2.250    if (ret)
   2.251      {
   2.252        SetDirectFBerror ("DirectFBCreate", ret);
   2.253 -      return -1;
   2.254 +      goto error;
   2.255      }
   2.256  
   2.257    ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
   2.258    if (ret)
   2.259      {
   2.260        SetDirectFBerror ("dfb->GetDisplayLayer", ret);
   2.261 -      dfb->Release (dfb);
   2.262 -      return -1;
   2.263 +      goto error;
   2.264      }
   2.265  
   2.266 -  ret = dfb->CreateEventBuffer (dfb, DICAPS_ALL, &eventbuffer);
   2.267 +  ret = dfb->CreateEventBuffer (dfb, DICAPS_ALL, &events);
   2.268    if (ret)
   2.269      {
   2.270        SetDirectFBerror ("dfb->CreateEventBuffer", ret);
   2.271 -      layer->Release (layer);
   2.272 -      dfb->Release (dfb);
   2.273 -      return -1;
   2.274 +      goto error;
   2.275      }
   2.276    
   2.277    layer->EnableCursor (layer, 1);
   2.278 @@ -343,43 +417,39 @@
   2.279    /* Query layer configuration to determine the current mode and pixelformat */
   2.280    layer->GetConfiguration (layer, &dlc);
   2.281  
   2.282 -  if (DFBToSDLPixelFormat (dlc.pixelformat, vformat))
   2.283 +  /* FIXME: Returning RGB332 as the default mode doesn't work (everything is black) */
   2.284 +  if ((format = dlc.pixelformat) == DSPF_RGB332)
   2.285 +    format = DSPF_RGB16;
   2.286 +
   2.287 +  if (DFBToSDLPixelFormat (format, vformat))
   2.288      {
   2.289        SDL_SetError ("Unsupported pixelformat");
   2.290 -      layer->Release (layer);
   2.291 -      dfb->Release (dfb);
   2.292 -      return -1;
   2.293 +      goto error;
   2.294      }
   2.295  
   2.296    /* Enumerate the available fullscreen modes */
   2.297 -  for ( i=0; i<NUM_MODELISTS; ++i )
   2.298 -    enumlists[i] = NULL;
   2.299 -
   2.300    ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
   2.301    if (ret)
   2.302      {
   2.303        SetDirectFBerror ("dfb->EnumVideoModes", ret);
   2.304 -      layer->Release (layer);
   2.305 -      dfb->Release (dfb);
   2.306 -      return(-1);
   2.307 +      goto error;
   2.308      }
   2.309 -  for ( i=0; i<NUM_MODELISTS; ++i )
   2.310 +
   2.311 +  HIDDEN->modelist = calloc (HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
   2.312 +  if (!HIDDEN->modelist)
   2.313      {
   2.314 -      struct DirectFBEnumRect *rect;
   2.315 -      HIDDEN->SDL_modelist[i] = (SDL_Rect **) malloc
   2.316 -        ((HIDDEN->SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
   2.317 -      if ( HIDDEN->SDL_modelist[i] == NULL )
   2.318 -        {
   2.319 -          SDL_OutOfMemory();
   2.320 -          return(-1);
   2.321 -        }
   2.322 -      for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next )
   2.323 -        {
   2.324 -          HIDDEN->SDL_modelist[i][j]=(SDL_Rect *)rect;
   2.325 -        }
   2.326 -      HIDDEN->SDL_modelist[i][j] = NULL;
   2.327 +      SDL_OutOfMemory();
   2.328 +      goto error;
   2.329      }
   2.330  
   2.331 +  for (i = 0, rect = enumlist; rect; ++i, rect = rect->next )
   2.332 +    {
   2.333 +      HIDDEN->modelist[i] = &rect->r;
   2.334 +    }
   2.335 +
   2.336 +  HIDDEN->modelist[i] = NULL;
   2.337 +
   2.338 +
   2.339    /* Query card capabilities to get the video memory size */
   2.340    dfb->GetCardCapabilities (dfb, &caps);
   2.341  
   2.342 @@ -394,15 +464,27 @@
   2.343    HIDDEN->initialized = 1;
   2.344    HIDDEN->dfb         = dfb;
   2.345    HIDDEN->layer       = layer;
   2.346 -  HIDDEN->eventbuffer = eventbuffer;
   2.347 +  HIDDEN->eventbuffer = events;
   2.348  
   2.349    return 0;
   2.350 +
   2.351 + error:
   2.352 +  if (events)
   2.353 +    events->Release (events);
   2.354 +  
   2.355 +  if (layer)
   2.356 +    layer->Release (layer);
   2.357 +
   2.358 +  if (dfb)
   2.359 +    dfb->Release (dfb);
   2.360 +
   2.361 +  return -1;
   2.362  }
   2.363  
   2.364  static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   2.365  {
   2.366    if (flags & SDL_FULLSCREEN)
   2.367 -    return HIDDEN->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
   2.368 +    return HIDDEN->modelist;
   2.369    else
   2.370      if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN)
   2.371        return (SDL_Rect**) -1;
   2.372 @@ -410,7 +492,7 @@
   2.373    return NULL;
   2.374  }
   2.375  
   2.376 -SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
   2.377 +static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
   2.378  {
   2.379    DFBResult             ret;
   2.380    DFBSurfaceDescription dsc;
   2.381 @@ -430,13 +512,12 @@
   2.382    else if (!current->hwdata)
   2.383      {
   2.384        /* Allocate the hardware acceleration data */
   2.385 -      current->hwdata = (struct private_hwdata *) malloc (sizeof(*current->hwdata));
   2.386 +      current->hwdata = (struct private_hwdata *) calloc (1, sizeof(*current->hwdata));
   2.387        if (!current->hwdata)
   2.388          {
   2.389            SDL_OutOfMemory();
   2.390            return NULL;
   2.391  	}
   2.392 -      memset (current->hwdata, 0, sizeof(*current->hwdata));
   2.393      }
   2.394  
   2.395    /* Set cooperative level depending on flag SDL_FULLSCREEN */
   2.396 @@ -471,8 +552,9 @@
   2.397      }
   2.398  
   2.399    /* Create primary surface */
   2.400 -  dsc.flags = DSDESC_CAPS;
   2.401 -  dsc.caps  = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
   2.402 +  dsc.flags       = DSDESC_CAPS | DSDESC_PIXELFORMAT;
   2.403 +  dsc.caps        = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
   2.404 +  dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
   2.405  
   2.406    ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &current->hwdata->surface);
   2.407    if (ret && (flags & SDL_DOUBLEBUF))
   2.408 @@ -524,7 +606,7 @@
   2.409    dsc.flags  = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
   2.410    dsc.width  = surface->w;
   2.411    dsc.height = surface->h;
   2.412 -  dsc.caps   = surface->flags & SDL_DOUBLEBUF ? DSCAPS_FLIPPING : 0;
   2.413 +  dsc.caps   = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0;
   2.414  
   2.415    /* find the right pixelformat */
   2.416    dsc.pixelformat = SDLToDFBPixelFormat (surface->format);
   2.417 @@ -532,7 +614,7 @@
   2.418      return -1;
   2.419  
   2.420    /* Allocate the hardware acceleration data */
   2.421 -  surface->hwdata = (struct private_hwdata *) malloc (sizeof(*surface->hwdata));
   2.422 +  surface->hwdata = (struct private_hwdata *) calloc (1, sizeof(*surface->hwdata));
   2.423    if (surface->hwdata == NULL)
   2.424      {
   2.425        SDL_OutOfMemory();
   2.426 @@ -581,21 +663,12 @@
   2.427  static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
   2.428                                  SDL_Surface *dst, SDL_Rect *dstrect)
   2.429  {
   2.430 -  DFBRectangle             sr, dr;
   2.431 -  IDirectFBSurface        *surface;
   2.432 -  DFBSurfaceBlittingFlags  flags = DSBLIT_NOFX;
   2.433 +  DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
   2.434  
   2.435 -  sr.x = srcrect->x;
   2.436 -  sr.y = srcrect->y;
   2.437 -  sr.w = srcrect->w;
   2.438 -  sr.h = srcrect->h;
   2.439 +  DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h };
   2.440 +  DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h };
   2.441  
   2.442 -  dr.x = dstrect->x;
   2.443 -  dr.y = dstrect->y;
   2.444 -  dr.w = dstrect->w;
   2.445 -  dr.h = dstrect->h;
   2.446 -
   2.447 -  surface = dst->hwdata->surface;
   2.448 +  IDirectFBSurface *surface = dst->hwdata->surface;
   2.449  
   2.450    if (src->flags & SDL_SRCCOLORKEY)
   2.451      {
   2.452 @@ -737,29 +810,47 @@
   2.453  int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   2.454  {
   2.455    fprintf(stderr, "SDL: Unimplemented DirectFB_SetColors!\n");
   2.456 -  return 0;
   2.457 +  return -1;
   2.458  }
   2.459  	
   2.460  void DirectFB_VideoQuit(_THIS)
   2.461  {
   2.462 -  int i, j;
   2.463 +  struct DirectFBEnumRect *rect = enumlist;
   2.464  
   2.465 -  HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer);
   2.466 -  HIDDEN->layer->Release (HIDDEN->layer);
   2.467 -  HIDDEN->dfb->Release (HIDDEN->dfb);
   2.468 +  if (HIDDEN->eventbuffer)
   2.469 +    {
   2.470 +      HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer);
   2.471 +      HIDDEN->eventbuffer = NULL;
   2.472 +    }
   2.473  
   2.474 -  /* Free video mode lists */
   2.475 -  for ( i=0; i<NUM_MODELISTS; ++i )
   2.476 +  if (HIDDEN->layer)
   2.477      {
   2.478 -      if ( HIDDEN->SDL_modelist[i] != NULL )
   2.479 -        {
   2.480 -          for ( j=0; HIDDEN->SDL_modelist[i][j]; ++j )
   2.481 -            free(HIDDEN->SDL_modelist[i][j]);
   2.482 -          free(HIDDEN->SDL_modelist[i]);
   2.483 -          HIDDEN->SDL_modelist[i] = NULL;
   2.484 -        }
   2.485 +      HIDDEN->layer->Release (HIDDEN->layer);
   2.486 +      HIDDEN->layer = NULL;
   2.487      }
   2.488  
   2.489 +  if (HIDDEN->dfb)
   2.490 +    {
   2.491 +      HIDDEN->dfb->Release (HIDDEN->dfb);
   2.492 +      HIDDEN->dfb = NULL;
   2.493 +    }
   2.494 +
   2.495 +  /* Free video mode list */
   2.496 +  if (HIDDEN->modelist)
   2.497 +    {
   2.498 +      free (HIDDEN->modelist);
   2.499 +      HIDDEN->modelist = NULL;
   2.500 +    }
   2.501 +
   2.502 +  /* Free mode enumeration list */
   2.503 +  while (rect)
   2.504 +    {
   2.505 +      struct DirectFBEnumRect *next = rect->next;
   2.506 +      free (rect);
   2.507 +      rect = next;
   2.508 +    }
   2.509 +  enumlist = NULL;
   2.510 +
   2.511    HIDDEN->initialized = 0;
   2.512  }
   2.513  
     3.1 --- a/src/video/directfb/SDL_DirectFB_video.h	Wed Aug 21 04:16:31 2002 +0000
     3.2 +++ b/src/video/directfb/SDL_DirectFB_video.h	Sat Aug 24 15:29:06 2002 +0000
     3.3 @@ -45,9 +45,8 @@
     3.4    IDirectFBDisplayLayer *layer;
     3.5    IDirectFBEventBuffer  *eventbuffer;
     3.6  
     3.7 -#define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
     3.8 -  int SDL_nummodes[NUM_MODELISTS];
     3.9 -  SDL_Rect **SDL_modelist[NUM_MODELISTS];
    3.10 +  int nummodes;
    3.11 +  SDL_Rect **modelist;
    3.12  };
    3.13  
    3.14  #define HIDDEN (this->hidden)