src/video/directfb/SDL_DirectFB_window.c
author Sam Lantinga
Sun, 13 Feb 2011 13:46:10 -0800
changeset 5288 d4381f3b0d1e
parent 5262 b530ef003506
child 5478 6b65ff3cee62
permissions -rw-r--r--
A few fixes:
Fixed creating render texture framebuffer.
Removed the need for palette watch, added surface format caching.
Added an SDL_DONTFREE flag so you can't free the window and 1.2 shadow surfaces.
slouken@2737
     1
/*
slouken@2737
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 Sam Lantinga
slouken@2737
     4
slouken@2737
     5
    This library is free software; you can redistribute it and/or
slouken@2737
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2737
     7
    License as published by the Free Software Foundation; either
slouken@2737
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2737
     9
slouken@2737
    10
    This library is distributed in the hope that it will be useful,
slouken@2737
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2737
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2737
    13
    Lesser General Public License for more details.
slouken@2737
    14
slouken@2737
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2737
    16
    License along with this library; if not, write to the Free Software
slouken@2737
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2737
    18
slouken@2737
    19
    Sam Lantinga
slouken@2737
    20
    slouken@libsdl.org
slouken@5199
    21
slouken@5199
    22
    SDL1.3 DirectFB driver by couriersud@arcor.de
slouken@5199
    23
	
slouken@2737
    24
*/
slouken@2737
    25
slouken@2737
    26
#include "SDL_DirectFB_video.h"
slouken@5199
    27
#include "SDL_DirectFB_modes.h"
slouken@5199
    28
#include "SDL_DirectFB_window.h"
slouken@5199
    29
#include "SDL_DirectFB_shape.h"
slouken@5199
    30
slouken@4636
    31
#if SDL_DIRECTFB_OPENGL
slouken@4636
    32
#include "SDL_DirectFB_opengl.h"
slouken@4636
    33
#endif
slouken@2737
    34
slouken@5199
    35
#include "SDL_syswm.h"
slouken@5199
    36
slouken@5199
    37
#include "../SDL_pixels_c.h"
couriersud@3023
    38
slouken@2737
    39
int
slouken@2737
    40
DirectFB_CreateWindow(_THIS, SDL_Window * window)
slouken@2737
    41
{
slouken@2737
    42
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
    43
    SDL_DFB_DISPLAYDATA(window);
couriersud@3023
    44
    DFB_WindowData *windata = NULL;
slouken@2737
    45
    DFBWindowOptions wopts;
slouken@2737
    46
    DFBWindowDescription desc;
slouken@4636
    47
    int x, y;
slouken@5199
    48
    int bshaped = 0;
slouken@2737
    49
slouken@5199
    50
    SDL_DFB_ALLOC_CLEAR(window->driverdata, sizeof(DFB_WindowData));
slouken@2737
    51
    windata = (DFB_WindowData *) window->driverdata;
slouken@2737
    52
couriersud@3023
    53
    windata->is_managed = devdata->has_own_wm;
slouken@5199
    54
#if 1
couriersud@3023
    55
    SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb,
couriersud@3023
    56
                                                       DFSCL_NORMAL));
couriersud@3023
    57
    SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
couriersud@3023
    58
                                                          DLSCL_ADMINISTRATIVE));
slouken@5199
    59
#endif
slouken@5199
    60
	/* FIXME ... ughh, ugly */
slouken@5199
    61
	if (window->x == -1000 && window->y == -1000)
slouken@5199
    62
		bshaped = 1;
slouken@5199
    63
	
slouken@2737
    64
    /* Fill the window description. */
slouken@5246
    65
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@2737
    66
        x = (dispdata->cw - window->w) / 2;
slouken@5246
    67
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
slouken@2737
    68
        x = 0;
slouken@2737
    69
    } else {
slouken@2737
    70
        x = window->x;
slouken@2737
    71
    }
slouken@5199
    72
    
slouken@5246
    73
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@2737
    74
        y = (dispdata->ch - window->h) / 2;
slouken@5246
    75
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
slouken@2737
    76
        y = 0;
slouken@2737
    77
    } else {
slouken@2737
    78
        y = window->y;
slouken@2737
    79
    }
slouken@5199
    80
    
slouken@2737
    81
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
    82
        x = 0;
slouken@2737
    83
        y = 0;
slouken@2737
    84
    }
slouken@2737
    85
slouken@4636
    86
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@2737
    87
couriersud@3023
    88
    /* Create Window */
slouken@5199
    89
	desc.caps = 0;
couriersud@3023
    90
    desc.flags =
slouken@5199
    91
        DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
slouken@5199
    92
slouken@5199
    93
    if (bshaped) {
slouken@5199
    94
    	desc.flags |= DWDESC_CAPS;
slouken@5199
    95
    	desc.caps |= DWCAPS_ALPHACHANNEL;
slouken@5199
    96
    }
slouken@5199
    97
    else
slouken@5199
    98
    {
slouken@5199
    99
    	desc.flags |= DWDESC_PIXELFORMAT;
slouken@5199
   100
    }
slouken@5199
   101
slouken@5199
   102
    if (!(window->flags & SDL_WINDOW_BORDERLESS))
slouken@5199
   103
		desc.caps |= DWCAPS_NODECORATION;
slouken@5199
   104
slouken@2737
   105
    desc.posx = x;
slouken@2737
   106
    desc.posy = y;
couriersud@3023
   107
    desc.width = windata->size.w;
couriersud@3023
   108
    desc.height = windata->size.h;
slouken@2737
   109
    desc.pixelformat = dispdata->pixelformat;
slouken@2737
   110
    desc.surface_caps = DSCAPS_PREMULTIPLIED;
slouken@5199
   111
    
slouken@2737
   112
    /* Create the window. */
couriersud@3023
   113
    SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
slouken@5199
   114
                                                   &windata->dfbwin));
slouken@2737
   115
couriersud@3023
   116
    /* Set Options */
slouken@5199
   117
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@2737
   118
slouken@5199
   119
    /* explicit rescaling of surface */
slouken@5199
   120
    wopts |= DWOP_SCALE;
slouken@5199
   121
    if (window->flags & SDL_WINDOW_RESIZABLE) {
slouken@5199
   122
        wopts &= ~DWOP_KEEP_SIZE;
slouken@5199
   123
    }
slouken@5199
   124
    else {
slouken@2737
   125
        wopts |= DWOP_KEEP_SIZE;
slouken@5199
   126
    }
slouken@2737
   127
couriersud@3023
   128
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
   129
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
slouken@5199
   130
        SDL_DFB_CHECK(windata->dfbwin->SetStackingClass(windata->dfbwin, DWSC_UPPER));
couriersud@3023
   131
    }
slouken@5199
   132
    
slouken@5199
   133
    if (bshaped) {
slouken@5199
   134
        wopts |= DWOP_SHAPED | DWOP_ALPHACHANNEL;
slouken@5199
   135
        wopts &= ~DWOP_OPAQUE_REGION;
slouken@5199
   136
    }
slouken@5199
   137
slouken@5199
   138
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@2737
   139
couriersud@3023
   140
    /* See what we got */
slouken@5199
   141
    SDL_DFB_CHECK(DirectFB_WM_GetClientSize
slouken@3040
   142
                     (_this, window, &window->w, &window->h));
couriersud@3023
   143
slouken@2737
   144
    /* Get the window's surface. */
slouken@5199
   145
    SDL_DFB_CHECKERR(windata->dfbwin->GetSurface(windata->dfbwin,
couriersud@3023
   146
                                                 &windata->window_surface));
slouken@5199
   147
couriersud@3023
   148
    /* And get a subsurface for rendering */
couriersud@3023
   149
    SDL_DFB_CHECKERR(windata->window_surface->
couriersud@3023
   150
                     GetSubSurface(windata->window_surface, &windata->client,
couriersud@3023
   151
                                   &windata->surface));
couriersud@3023
   152
slouken@5199
   153
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0xFF));
couriersud@3023
   154
couriersud@3023
   155
    /* Create Eventbuffer */
slouken@5199
   156
slouken@5199
   157
    SDL_DFB_CHECKERR(windata->dfbwin->CreateEventBuffer(windata->dfbwin,
slouken@3040
   158
                                                        &windata->
slouken@3040
   159
                                                        eventbuffer));
slouken@5199
   160
    SDL_DFB_CHECKERR(windata->dfbwin->
slouken@5199
   161
                     EnableEvents(windata->dfbwin, DWET_ALL));
slouken@2737
   162
couriersud@3023
   163
    /* Create a font */
couriersud@3023
   164
    /* FIXME: once during Video_Init */
slouken@4636
   165
    windata->font = NULL;
couriersud@3023
   166
slouken@2737
   167
    /* Make it the top most window. */
slouken@5199
   168
    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
slouken@2737
   169
slouken@2737
   170
    /* remember parent */
slouken@5199
   171
    //windata->sdlwin = window;
slouken@2737
   172
slouken@2737
   173
    /* Add to list ... */
slouken@2737
   174
slouken@2737
   175
    windata->next = devdata->firstwin;
slouken@2737
   176
    windata->opacity = 0xFF;
slouken@5199
   177
    devdata->firstwin = window;
slouken@2737
   178
couriersud@3023
   179
    /* Draw Frame */
slouken@4636
   180
    DirectFB_WM_RedrawLayout(_this, window);
couriersud@3023
   181
slouken@2737
   182
    return 0;
slouken@2737
   183
  error:
slouken@5199
   184
	SDL_DFB_RELEASE(windata->surface);
slouken@5199
   185
    SDL_DFB_RELEASE(windata->dfbwin);
slouken@2737
   186
    return -1;
slouken@2737
   187
}
slouken@2737
   188
slouken@2737
   189
int
slouken@2737
   190
DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
slouken@2737
   191
{
slouken@2737
   192
    SDL_Unsupported();
slouken@2737
   193
    return -1;
slouken@2737
   194
}
slouken@2737
   195
slouken@2737
   196
void
slouken@2737
   197
DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
slouken@2737
   198
{
couriersud@3023
   199
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   200
couriersud@3023
   201
    if (windata->is_managed) {
couriersud@3023
   202
        windata->wm_needs_redraw = 1;
slouken@4636
   203
        DirectFB_WM_RedrawLayout(_this, window);
couriersud@3023
   204
    } else
couriersud@3023
   205
        SDL_Unsupported();
couriersud@3023
   206
}
couriersud@3023
   207
couriersud@3023
   208
void
couriersud@3023
   209
DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
couriersud@3023
   210
{
couriersud@3023
   211
    SDL_DFB_DEVICEDATA(_this);
couriersud@3023
   212
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   213
    SDL_Surface *surface = NULL;
couriersud@3023
   214
couriersud@3023
   215
    if (icon) {
couriersud@3023
   216
        SDL_PixelFormat format;
couriersud@3023
   217
        DFBSurfaceDescription dsc;
couriersud@3023
   218
        Uint32 *dest;
couriersud@3023
   219
        Uint32 *p;
couriersud@3023
   220
        int pitch, i;
couriersud@3023
   221
couriersud@3023
   222
        /* Convert the icon to ARGB for modern window managers */
slouken@5288
   223
        SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
couriersud@3023
   224
        surface = SDL_ConvertSurface(icon, &format, 0);
couriersud@3023
   225
        if (!surface) {
couriersud@3023
   226
            return;
couriersud@3023
   227
        }
couriersud@3023
   228
        dsc.flags =
couriersud@3023
   229
            DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
couriersud@3023
   230
        dsc.caps = DSCAPS_VIDEOONLY;
couriersud@3023
   231
        dsc.width = surface->w;
couriersud@3023
   232
        dsc.height = surface->h;
couriersud@3023
   233
        dsc.pixelformat = DSPF_ARGB;
couriersud@3023
   234
couriersud@3023
   235
        SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
couriersud@3023
   236
                                                     &windata->icon));
couriersud@3023
   237
couriersud@3023
   238
        SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE,
couriersud@3023
   239
                                             (void *) &dest, &pitch));
couriersud@3023
   240
couriersud@3023
   241
        p = surface->pixels;
couriersud@3023
   242
        for (i = 0; i < surface->h; i++)
couriersud@3023
   243
            memcpy((char *) dest + i * pitch,
couriersud@3023
   244
                   (char *) p + i * surface->pitch, 4 * surface->w);
couriersud@3023
   245
slouken@4636
   246
        SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
couriersud@3023
   247
        SDL_FreeSurface(surface);
couriersud@3023
   248
    } else {
couriersud@3023
   249
        SDL_DFB_RELEASE(windata->icon);
couriersud@3023
   250
    }
couriersud@3023
   251
    return;
couriersud@3023
   252
  error:
couriersud@3023
   253
    if (surface)
couriersud@3023
   254
        SDL_FreeSurface(surface);
couriersud@3023
   255
    SDL_DFB_RELEASE(windata->icon);
couriersud@3023
   256
    return;
slouken@2737
   257
}
slouken@2737
   258
slouken@2737
   259
void
slouken@2737
   260
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
slouken@2737
   261
{
slouken@2737
   262
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   263
    SDL_DFB_DISPLAYDATA(window);
slouken@2737
   264
    int x, y;
slouken@2737
   265
slouken@5246
   266
    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
slouken@5199
   267
        x = (dispdata->cw - window->w) / 2;
slouken@5246
   268
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
slouken@5199
   269
        x = 0;
slouken@5199
   270
    } else {
slouken@5199
   271
        x = window->x;
slouken@5199
   272
    }
slouken@5199
   273
    
slouken@5246
   274
    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
slouken@5199
   275
        y = (dispdata->ch - window->h) / 2;
slouken@5246
   276
    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
slouken@2737
   277
        y = 0;
slouken@5199
   278
    } else {
slouken@2737
   279
        y = window->y;
slouken@5199
   280
    }
slouken@2737
   281
slouken@2737
   282
    if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@2737
   283
        x = 0;
slouken@2737
   284
        y = 0;
slouken@2737
   285
    }
slouken@4636
   286
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@5199
   287
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
slouken@2737
   288
}
slouken@2737
   289
slouken@2737
   290
void
slouken@2737
   291
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
slouken@2737
   292
{
couriersud@3023
   293
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   294
slouken@5199
   295
    if(SDL_IsShapedWindow(window))
slouken@5199
   296
        DirectFB_ResizeWindowShape(window);
slouken@5199
   297
slouken@2737
   298
    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
slouken@2737
   299
        int cw;
slouken@2737
   300
        int ch;
slouken@2737
   301
slouken@2737
   302
        /* Make sure all events are disabled for this operation ! */
slouken@5199
   303
        SDL_DFB_CHECKERR(windata->dfbwin->DisableEvents(windata->dfbwin,
couriersud@3023
   304
                                                        DWET_ALL));
couriersud@3023
   305
        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
couriersud@3023
   306
couriersud@3023
   307
        if (cw != window->w || ch != window->h) {
slouken@2737
   308
slouken@4636
   309
		    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
slouken@5199
   310
            SDL_DFB_CHECKERR(windata->dfbwin->Resize(windata->dfbwin,
couriersud@3023
   311
                                                     windata->size.w,
couriersud@3023
   312
                                                     windata->size.h));
couriersud@3023
   313
        }
slouken@2737
   314
slouken@4636
   315
        SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
slouken@4636
   316
                     (_this, window, &window->w, &window->h));
slouken@5199
   317
        DirectFB_AdjustWindowSurface(window);
slouken@4636
   318
slouken@5199
   319
        SDL_DFB_CHECKERR(windata->dfbwin->EnableEvents(windata->dfbwin,
couriersud@3023
   320
                                                       DWET_ALL));
couriersud@3023
   321
slouken@2737
   322
    }
slouken@2737
   323
    return;
slouken@2737
   324
  error:
slouken@5199
   325
    SDL_DFB_CHECK(windata->dfbwin->EnableEvents(windata->dfbwin, DWET_ALL));
slouken@2737
   326
    return;
slouken@2737
   327
}
slouken@2737
   328
slouken@2737
   329
void
slouken@2737
   330
DirectFB_ShowWindow(_THIS, SDL_Window * window)
slouken@2737
   331
{
slouken@2737
   332
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   333
slouken@5199
   334
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, windata->opacity));
slouken@2737
   335
slouken@2737
   336
}
slouken@2737
   337
slouken@2737
   338
void
slouken@2737
   339
DirectFB_HideWindow(_THIS, SDL_Window * window)
slouken@2737
   340
{
slouken@2737
   341
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   342
slouken@5199
   343
    SDL_DFB_CHECK(windata->dfbwin->GetOpacity(windata->dfbwin, &windata->opacity));
slouken@5199
   344
    SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0));
slouken@2737
   345
}
slouken@2737
   346
slouken@2737
   347
void
slouken@2737
   348
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
slouken@2737
   349
{
slouken@2737
   350
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   351
slouken@5199
   352
    SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
slouken@5199
   353
    SDL_DFB_CHECK(windata->dfbwin->RequestFocus(windata->dfbwin));
slouken@2737
   354
}
slouken@2737
   355
slouken@2737
   356
void
slouken@2737
   357
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
slouken@2737
   358
{
couriersud@3023
   359
    SDL_DFB_WINDOWDATA(window);
slouken@5246
   360
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
slouken@5199
   361
    DFBWindowOptions wopts;
slouken@2737
   362
slouken@5199
   363
    SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin,
slouken@5199
   364
                                 &windata->restore.x, &windata->restore.y));
slouken@5199
   365
    SDL_DFB_CHECK(windata->dfbwin->GetSize(windata->dfbwin, &windata->restore.w,
slouken@5199
   366
                             &windata->restore.h));
slouken@5199
   367
slouken@5199
   368
    DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
slouken@5199
   369
slouken@5199
   370
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, 0, 0));
slouken@5199
   371
    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin,
slouken@5199
   372
                            display->current_mode.w, display->current_mode.h));
slouken@5199
   373
slouken@5199
   374
    /* Set Options */
slouken@5199
   375
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@5199
   376
    wopts |= DWOP_KEEP_SIZE | DWOP_KEEP_POSITION;
slouken@5199
   377
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@2737
   378
}
slouken@2737
   379
slouken@2737
   380
void
slouken@2737
   381
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
slouken@2737
   382
{
slouken@2737
   383
    /* FIXME: Size to 32x32 ? */
slouken@2737
   384
slouken@2737
   385
    SDL_Unsupported();
slouken@2737
   386
}
slouken@2737
   387
slouken@2737
   388
void
slouken@2737
   389
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
slouken@2737
   390
{
couriersud@3023
   391
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   392
    DFBWindowOptions wopts;
couriersud@3023
   393
slouken@5199
   394
    /* Set Options */
slouken@5199
   395
    SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
slouken@5199
   396
    wopts &= ~(DWOP_KEEP_SIZE | DWOP_KEEP_POSITION);
slouken@5199
   397
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@5199
   398
slouken@5199
   399
    /* Window layout */
slouken@5199
   400
    DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED),
slouken@5199
   401
    	windata->restore.w, windata->restore.h);
slouken@5199
   402
    SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin, windata->restore.w,
slouken@5199
   403
                            windata->restore.h));
slouken@5199
   404
    SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, windata->restore.x,
slouken@5199
   405
                            windata->restore.y));
slouken@5199
   406
slouken@5199
   407
    if (!(window->flags & SDL_WINDOW_RESIZABLE))
slouken@5199
   408
        wopts |= DWOP_KEEP_SIZE;
slouken@5199
   409
slouken@5199
   410
    if (window->flags & SDL_WINDOW_FULLSCREEN)
slouken@5199
   411
        wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_SIZE;
slouken@5199
   412
    SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
slouken@5199
   413
slouken@5199
   414
slouken@2737
   415
}
slouken@2737
   416
slouken@2737
   417
void
slouken@2737
   418
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
slouken@2737
   419
{
slouken@4636
   420
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   421
    SDL_DFB_WINDOWDATA(window);
slouken@4636
   422
    DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
slouken@2737
   423
couriersud@3023
   424
    if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
slouken@4636
   425
        if (gwindata != NULL)
slouken@4636
   426
        {
slouken@5199
   427
		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
slouken@5199
   428
		    SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
slouken@4636
   429
        }
slouken@5199
   430
        SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
slouken@5199
   431
        SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
slouken@4636
   432
        devdata->grabbed_window = window;
slouken@2737
   433
    } else {
slouken@5199
   434
        SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
slouken@5199
   435
        SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
slouken@4636
   436
        devdata->grabbed_window = NULL;
slouken@2737
   437
    }
slouken@2737
   438
}
slouken@2737
   439
slouken@2737
   440
void
slouken@2737
   441
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
slouken@2737
   442
{
slouken@2737
   443
    SDL_DFB_DEVICEDATA(_this);
slouken@2737
   444
    SDL_DFB_WINDOWDATA(window);
slouken@2737
   445
    DFB_WindowData *p;
slouken@2737
   446
slouken@4636
   447
    /* Some cleanups */
slouken@5199
   448
    SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
slouken@5199
   449
    SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
slouken@2737
   450
slouken@4636
   451
#if SDL_DIRECTFB_OPENGL
slouken@4636
   452
	DirectFB_GL_DestroyWindowContexts(_this, window);
slouken@4636
   453
#endif
couriersud@3023
   454
slouken@5199
   455
	if (window->shaper)
slouken@5199
   456
	{
slouken@5199
   457
	    SDL_ShapeData *data = window->shaper->driverdata;
slouken@5199
   458
	    SDL_DFB_CHECK(data->surface->ReleaseSource(data->surface));
slouken@5199
   459
    	SDL_DFB_RELEASE(data->surface);
slouken@5199
   460
    	SDL_DFB_FREE(data);
slouken@5199
   461
    	SDL_DFB_FREE(window->shaper);
slouken@5199
   462
	}
slouken@5199
   463
slouken@4636
   464
    SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
slouken@4636
   465
    SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
slouken@4636
   466
    SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
slouken@4636
   467
  	SDL_DFB_RELEASE(windata->icon);
slouken@4636
   468
    SDL_DFB_RELEASE(windata->font);
slouken@2737
   469
    SDL_DFB_RELEASE(windata->eventbuffer);
slouken@2737
   470
    SDL_DFB_RELEASE(windata->surface);
couriersud@3023
   471
    SDL_DFB_RELEASE(windata->window_surface);
couriersud@3023
   472
slouken@5199
   473
    SDL_DFB_RELEASE(windata->dfbwin);
slouken@2737
   474
slouken@2737
   475
    /* Remove from list ... */
slouken@2737
   476
slouken@5199
   477
    p = devdata->firstwin->driverdata;
slouken@5199
   478
slouken@5199
   479
    while (p && p->next != window)
slouken@5199
   480
        p = (p->next ? p->next->driverdata : NULL);
slouken@2737
   481
    if (p)
slouken@2737
   482
        p->next = windata->next;
slouken@2737
   483
    else
slouken@2737
   484
        devdata->firstwin = windata->next;
slouken@2737
   485
    SDL_free(windata);
slouken@2737
   486
    return;
slouken@2737
   487
}
slouken@2737
   488
slouken@2737
   489
SDL_bool
slouken@2737
   490
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@2737
   491
                         struct SDL_SysWMinfo * info)
slouken@2737
   492
{
slouken@5199
   493
    SDL_DFB_DEVICEDATA(_this);
slouken@5199
   494
    SDL_DFB_WINDOWDATA(window);
slouken@5199
   495
slouken@5199
   496
    if (info->version.major == SDL_MAJOR_VERSION &&
slouken@5199
   497
        info->version.minor == SDL_MINOR_VERSION) {
slouken@5199
   498
        info->subsystem = SDL_SYSWM_DIRECTFB;
slouken@5199
   499
        info->info.dfb.dfb = devdata->dfb;
slouken@5199
   500
        info->info.dfb.window = windata->dfbwin;
slouken@5199
   501
        info->info.dfb.surface = windata->surface;
slouken@5199
   502
        return SDL_TRUE;
slouken@5199
   503
    } else {
slouken@5199
   504
        SDL_SetError("Application not compiled with SDL %d.%d\n",
slouken@5199
   505
                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
slouken@5199
   506
        return SDL_FALSE;
slouken@5199
   507
    }
slouken@2737
   508
}
couriersud@3023
   509
slouken@5199
   510
void
slouken@5199
   511
DirectFB_AdjustWindowSurface(SDL_Window * window)
couriersud@3023
   512
{
couriersud@3023
   513
    SDL_DFB_WINDOWDATA(window);
couriersud@3023
   514
    int adjust = windata->wm_needs_redraw;
couriersud@3023
   515
    int cw, ch;
couriersud@3023
   516
slouken@4636
   517
    DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
couriersud@3023
   518
couriersud@3023
   519
    SDL_DFB_CHECKERR(windata->
couriersud@3023
   520
                     window_surface->GetSize(windata->window_surface, &cw,
couriersud@3023
   521
                                             &ch));
couriersud@3023
   522
    if (cw != windata->size.w || ch != windata->size.h) {
couriersud@3023
   523
        adjust = 1;
couriersud@3023
   524
    }
couriersud@3023
   525
couriersud@3023
   526
    if (adjust) {
slouken@4636
   527
#if SDL_DIRECTFB_OPENGL
slouken@5246
   528
		DirectFB_GL_FreeWindowContexts(SDL_GetVideoDevice(), window);
slouken@4636
   529
#endif
slouken@4636
   530
slouken@5199
   531
#if (DFB_VERSION_ATLEAST(1,2,1))
slouken@5199
   532
        SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
couriersud@3023
   533
                                                        windata->size.w,
couriersud@3023
   534
                                                        windata->size.h));
slouken@3040
   535
        SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
couriersud@3023
   536
                                                          windata->
couriersud@3023
   537
                                                          window_surface,
couriersud@3023
   538
                                                          &windata->client));
couriersud@3037
   539
#else
slouken@3040
   540
        DFBWindowOptions opts;
slouken@3040
   541
slouken@5199
   542
        SDL_DFB_CHECKERR(windata->dfbwin->GetOptions(windata->dfbwin, &opts));
slouken@3040
   543
        /* recreate subsurface */
slouken@3040
   544
        SDL_DFB_RELEASE(windata->surface);
couriersud@3039
   545
slouken@3040
   546
        if (opts & DWOP_SCALE)
slouken@5199
   547
            SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
slouken@3040
   548
                                                            windata->size.w,
slouken@3040
   549
                                                            windata->size.h));
slouken@3040
   550
        SDL_DFB_CHECKERR(windata->window_surface->
slouken@3040
   551
                         GetSubSurface(windata->window_surface,
slouken@3040
   552
                                       &windata->client, &windata->surface));
couriersud@3037
   553
#endif
slouken@5246
   554
        DirectFB_WM_RedrawLayout(SDL_GetVideoDevice(), window);
slouken@4636
   555
        
slouken@4636
   556
#if SDL_DIRECTFB_OPENGL
slouken@5246
   557
		DirectFB_GL_ReAllocWindowContexts(SDL_GetVideoDevice(), window);
slouken@4636
   558
#endif
slouken@4636
   559
   }
couriersud@3023
   560
  error:
couriersud@3023
   561
    return;
couriersud@3023
   562
}