src/video/directfb/SDL_DirectFB_window.c
changeset 4636 b196d2758026
parent 4568 25b9cd8bdc30
child 5199 164f20ba08eb
     1.1 --- a/src/video/directfb/SDL_DirectFB_window.c	Sat Aug 14 12:28:43 2010 -0700
     1.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Mon Aug 16 09:04:55 2010 -0700
     1.3 @@ -24,9 +24,14 @@
     1.4  #include "SDL_syswm.h"
     1.5  #include "../SDL_sysvideo.h"
     1.6  #include "../../events/SDL_keyboard_c.h"
     1.7 +#include "../../video/SDL_pixels_c.h"
     1.8  
     1.9  #include "SDL_DirectFB_video.h"
    1.10 +#if SDL_DIRECTFB_OPENGL
    1.11 +#include "SDL_DirectFB_opengl.h"
    1.12 +#endif
    1.13  
    1.14 +static void DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window);
    1.15  
    1.16  int
    1.17  DirectFB_CreateWindow(_THIS, SDL_Window * window)
    1.18 @@ -36,8 +41,7 @@
    1.19      DFB_WindowData *windata = NULL;
    1.20      DFBWindowOptions wopts;
    1.21      DFBWindowDescription desc;
    1.22 -    IDirectFBFont *font;
    1.23 -    int ret, x, y;
    1.24 +    int x, y;
    1.25  
    1.26      SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
    1.27      windata = (DFB_WindowData *) window->driverdata;
    1.28 @@ -69,7 +73,7 @@
    1.29          y = 0;
    1.30      }
    1.31  
    1.32 -    DirectFB_WM_AdjustWindowLayout(window);
    1.33 +    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
    1.34  
    1.35      /* Create Window */
    1.36      desc.flags =
    1.37 @@ -87,7 +91,7 @@
    1.38                                                     &windata->window));
    1.39  
    1.40      /* Set Options */
    1.41 -    windata->window->GetOptions(windata->window, &wopts);
    1.42 +    SDL_DFB_CHECK(windata->window->GetOptions(windata->window, &wopts));
    1.43  
    1.44      if (window->flags & SDL_WINDOW_RESIZABLE)
    1.45          wopts |= DWOP_SCALE;
    1.46 @@ -96,9 +100,9 @@
    1.47  
    1.48      if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.49          wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
    1.50 -        windata->window->SetStackingClass(windata->window, DWSC_UPPER);
    1.51 +        SDL_DFB_CHECK(windata->window->SetStackingClass(windata->window, DWSC_UPPER));
    1.52      }
    1.53 -    windata->window->SetOptions(windata->window, wopts);
    1.54 +    SDL_DFB_CHECK(windata->window->SetOptions(windata->window, wopts));
    1.55  
    1.56      /* See what we got */
    1.57      SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
    1.58 @@ -112,7 +116,7 @@
    1.59                       GetSubSurface(windata->window_surface, &windata->client,
    1.60                                     &windata->surface));
    1.61  
    1.62 -    windata->window->SetOpacity(windata->window, 0xFF);
    1.63 +    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, 0xFF));
    1.64  
    1.65      /* Create Eventbuffer */
    1.66      SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
    1.67 @@ -123,21 +127,10 @@
    1.68  
    1.69      /* Create a font */
    1.70      /* FIXME: once during Video_Init */
    1.71 -    if (windata->is_managed) {
    1.72 -        DFBFontDescription fdesc;
    1.73 -
    1.74 -        fdesc.flags = DFDESC_HEIGHT;
    1.75 -        fdesc.height = windata->theme.font_size;
    1.76 -        font = NULL;
    1.77 -        SDL_DFB_CHECK(devdata->
    1.78 -                      dfb->CreateFont(devdata->dfb, windata->theme.font,
    1.79 -                                      &fdesc, &font));
    1.80 -        windata->window_surface->SetFont(windata->window_surface, font);
    1.81 -        SDL_DFB_RELEASE(font);
    1.82 -    }
    1.83 +    windata->font = NULL;
    1.84  
    1.85      /* Make it the top most window. */
    1.86 -    windata->window->RaiseToTop(windata->window);
    1.87 +    SDL_DFB_CHECK(windata->window->RaiseToTop(windata->window));
    1.88  
    1.89      /* remember parent */
    1.90      windata->sdl_window = window;
    1.91 @@ -149,7 +142,7 @@
    1.92      devdata->firstwin = windata;
    1.93  
    1.94      /* Draw Frame */
    1.95 -    DirectFB_WM_RedrawLayout(window);
    1.96 +    DirectFB_WM_RedrawLayout(_this, window);
    1.97  
    1.98      return 0;
    1.99    error:
   1.100 @@ -172,6 +165,7 @@
   1.101  
   1.102      if (windata->is_managed) {
   1.103          windata->wm_needs_redraw = 1;
   1.104 +        DirectFB_WM_RedrawLayout(_this, window);
   1.105      } else
   1.106          SDL_Unsupported();
   1.107  }
   1.108 @@ -182,7 +176,6 @@
   1.109      SDL_DFB_DEVICEDATA(_this);
   1.110      SDL_DFB_WINDOWDATA(window);
   1.111      SDL_Surface *surface = NULL;
   1.112 -    DFBResult ret;
   1.113  
   1.114      if (icon) {
   1.115          SDL_PixelFormat format;
   1.116 @@ -216,7 +209,7 @@
   1.117              memcpy((char *) dest + i * pitch,
   1.118                     (char *) p + i * surface->pitch, 4 * surface->w);
   1.119  
   1.120 -        windata->icon->Unlock(windata->icon);
   1.121 +        SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
   1.122          SDL_FreeSurface(surface);
   1.123      } else {
   1.124          SDL_DFB_RELEASE(windata->icon);
   1.125 @@ -249,16 +242,15 @@
   1.126          x = 0;
   1.127          y = 0;
   1.128      }
   1.129 -    DirectFB_WM_AdjustWindowLayout(window);
   1.130 -    windata->window->MoveTo(windata->window, x, y);
   1.131 +    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
   1.132 +    SDL_DFB_CHECK(windata->window->MoveTo(windata->window, x, y));
   1.133  }
   1.134  
   1.135  void
   1.136  DirectFB_SetWindowSize(_THIS, SDL_Window * window)
   1.137  {
   1.138 -    SDL_DFB_DEVICEDATA(_this);
   1.139 +    //SDL_DFB_DEVICEDATA(_this);
   1.140      SDL_DFB_WINDOWDATA(window);
   1.141 -    int ret;
   1.142  
   1.143      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   1.144          int cw;
   1.145 @@ -272,23 +264,23 @@
   1.146  
   1.147          if (cw != window->w || ch != window->h) {
   1.148  
   1.149 -            DirectFB_WM_AdjustWindowLayout(window);
   1.150 +		    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
   1.151              SDL_DFB_CHECKERR(windata->window->Resize(windata->window,
   1.152                                                       windata->size.w,
   1.153                                                       windata->size.h));
   1.154          }
   1.155  
   1.156 +        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
   1.157 +                     (_this, window, &window->w, &window->h));
   1.158 +        DirectFB_AdjustWindowSurface(_this, window);
   1.159 +
   1.160          SDL_DFB_CHECKERR(windata->window->EnableEvents(windata->window,
   1.161                                                         DWET_ALL));
   1.162  
   1.163 -        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
   1.164 -                         (_this, window, &window->w, &window->h));
   1.165 -
   1.166 -        SDL_OnWindowResized(window);
   1.167      }
   1.168      return;
   1.169    error:
   1.170 -    windata->window->EnableEvents(windata->window, DWET_ALL);
   1.171 +    SDL_DFB_CHECK(windata->window->EnableEvents(windata->window, DWET_ALL));
   1.172      return;
   1.173  }
   1.174  
   1.175 @@ -297,7 +289,7 @@
   1.176  {
   1.177      SDL_DFB_WINDOWDATA(window);
   1.178  
   1.179 -    windata->window->SetOpacity(windata->window, windata->opacity);
   1.180 +    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, windata->opacity));
   1.181  
   1.182  }
   1.183  
   1.184 @@ -306,8 +298,8 @@
   1.185  {
   1.186      SDL_DFB_WINDOWDATA(window);
   1.187  
   1.188 -    windata->window->GetOpacity(windata->window, &windata->opacity);
   1.189 -    windata->window->SetOpacity(windata->window, 0);
   1.190 +    SDL_DFB_CHECK(windata->window->GetOpacity(windata->window, &windata->opacity));
   1.191 +    SDL_DFB_CHECK(windata->window->SetOpacity(windata->window, 0));
   1.192  }
   1.193  
   1.194  void
   1.195 @@ -315,8 +307,8 @@
   1.196  {
   1.197      SDL_DFB_WINDOWDATA(window);
   1.198  
   1.199 -    windata->window->RaiseToTop(windata->window);
   1.200 -    windata->window->RequestFocus(windata->window);
   1.201 +    SDL_DFB_CHECK(windata->window->RaiseToTop(windata->window));
   1.202 +    SDL_DFB_CHECK(windata->window->RequestFocus(windata->window));
   1.203  }
   1.204  
   1.205  void
   1.206 @@ -352,14 +344,23 @@
   1.207  void
   1.208  DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
   1.209  {
   1.210 +    SDL_DFB_DEVICEDATA(_this);
   1.211      SDL_DFB_WINDOWDATA(window);
   1.212 +    DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
   1.213  
   1.214      if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
   1.215 -        windata->window->GrabPointer(windata->window);
   1.216 -        windata->window->GrabKeyboard(windata->window);
   1.217 +        if (gwindata != NULL)
   1.218 +        {
   1.219 +		    SDL_DFB_CHECK(gwindata->window->UngrabPointer(gwindata->window));
   1.220 +		    SDL_DFB_CHECK(gwindata->window->UngrabKeyboard(gwindata->window));
   1.221 +        }
   1.222 +        SDL_DFB_CHECK(windata->window->GrabPointer(windata->window));
   1.223 +        SDL_DFB_CHECK(windata->window->GrabKeyboard(windata->window));
   1.224 +        devdata->grabbed_window = window;
   1.225      } else {
   1.226 -        windata->window->UngrabPointer(windata->window);
   1.227 -        windata->window->UngrabKeyboard(windata->window);
   1.228 +        SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
   1.229 +        SDL_DFB_CHECK(windata->window->UngrabKeyboard(windata->window));
   1.230 +        devdata->grabbed_window = NULL;
   1.231      }
   1.232  }
   1.233  
   1.234 @@ -370,14 +371,19 @@
   1.235      SDL_DFB_WINDOWDATA(window);
   1.236      DFB_WindowData *p;
   1.237  
   1.238 -    SDL_DFB_DEBUG("Trace\n");
   1.239 +    /* Some cleanups */
   1.240 +    SDL_DFB_CHECK(windata->window->UngrabPointer(windata->window));
   1.241 +    SDL_DFB_CHECK(windata->window->UngrabKeyboard(windata->window));
   1.242  
   1.243 -    /* Some cleanups */
   1.244 -    windata->window->UngrabPointer(windata->window);
   1.245 -    windata->window->UngrabKeyboard(windata->window);
   1.246 +#if SDL_DIRECTFB_OPENGL
   1.247 +	DirectFB_GL_DestroyWindowContexts(_this, window);
   1.248 +#endif
   1.249  
   1.250 -    windata->window_surface->SetFont(windata->window_surface, NULL);
   1.251 -    SDL_DFB_RELEASE(windata->icon);
   1.252 +    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
   1.253 +    SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
   1.254 +    SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
   1.255 +  	SDL_DFB_RELEASE(windata->icon);
   1.256 +    SDL_DFB_RELEASE(windata->font);
   1.257      SDL_DFB_RELEASE(windata->eventbuffer);
   1.258      SDL_DFB_RELEASE(windata->surface);
   1.259      SDL_DFB_RELEASE(windata->window_surface);
   1.260 @@ -405,15 +411,14 @@
   1.261      return SDL_FALSE;
   1.262  }
   1.263  
   1.264 -void
   1.265 -DirectFB_AdjustWindowSurface(SDL_Window * window)
   1.266 +static void
   1.267 +DirectFB_AdjustWindowSurface(_THIS, SDL_Window * window)
   1.268  {
   1.269      SDL_DFB_WINDOWDATA(window);
   1.270      int adjust = windata->wm_needs_redraw;
   1.271      int cw, ch;
   1.272 -    int ret;
   1.273  
   1.274 -    DirectFB_WM_AdjustWindowLayout(window);
   1.275 +    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
   1.276  
   1.277      SDL_DFB_CHECKERR(windata->
   1.278                       window_surface->GetSize(windata->window_surface, &cw,
   1.279 @@ -423,6 +428,10 @@
   1.280      }
   1.281  
   1.282      if (adjust) {
   1.283 +#if SDL_DIRECTFB_OPENGL
   1.284 +		DirectFB_GL_FreeWindowContexts(_this, window);
   1.285 +#endif
   1.286 +
   1.287  #if DFB_VERSION_ATLEAST(1,2,1)
   1.288          SDL_DFB_CHECKERR(windata->window->ResizeSurface(windata->window,
   1.289                                                          windata->size.w,
   1.290 @@ -446,8 +455,12 @@
   1.291                           GetSubSurface(windata->window_surface,
   1.292                                         &windata->client, &windata->surface));
   1.293  #endif
   1.294 -        DirectFB_WM_RedrawLayout(window);
   1.295 -    }
   1.296 +        DirectFB_WM_RedrawLayout(_this, window);
   1.297 +        
   1.298 +#if SDL_DIRECTFB_OPENGL
   1.299 +		DirectFB_GL_ReAllocWindowContexts(_this, window);
   1.300 +#endif
   1.301 +   }
   1.302    error:
   1.303      return;
   1.304  }