This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_DirectFB_video.c
1184 lines (980 loc) · 33.2 KB
1
/*
2
3
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
4
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
13
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
14
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
Sam Lantinga
slouken@libsdl.org
21
22
23
SDL1.3 implementation by couriersud@arcor.de
24
*/
25
26
27
#include "SDL_config.h"
28
29
30
31
32
33
34
35
36
/* DirectFB video driver implementation.
*/
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <directfb.h>
37
#include <directfb_version.h>
38
39
40
#include "SDL_video.h"
#include "SDL_mouse.h"
41
42
43
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
44
45
46
47
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_events.h"
/* This is the rect EnumModes2 uses */
48
49
50
51
struct DirectFBEnumRect
{
SDL_Rect r;
struct DirectFBEnumRect *next;
52
53
};
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
struct DirectFB_GLContext
{
IDirectFBGL *context;
};
/* Initialization/Query functions */
static int DirectFB_VideoInit(_THIS);
static void DirectFB_VideoQuit(_THIS);
static int DirectFB_CreateWindow(_THIS, SDL_Window * window);
static int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
const void *data);
static void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
static void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
static void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
static void DirectFB_ShowWindow(_THIS, SDL_Window * window);
static void DirectFB_HideWindow(_THIS, SDL_Window * window);
static void DirectFB_RaiseWindow(_THIS, SDL_Window * window);
static void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
static void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
static void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
static void DirectFB_SetWindowGrab(_THIS, SDL_Window * window);
static void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
static SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
static void DirectFB_GetDisplayModes(_THIS);
static int DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
static int DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp);
static int DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp);
#if SDL_DIRECTFB_OPENGL
static int DirectFB_GL_LoadLibrary(_THIS, const char *path);
static void DirectFB_GL_UnloadLibrary(_THIS);
static void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
static SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
static int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context);
static int DirectFB_GL_SetSwapInterval(_THIS, int interval);
static int DirectFB_GL_GetSwapInterval(_THIS);
static void DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
static void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
97
98
#endif
99
100
101
/* DirectFB driver bootstrap functions */
102
103
static int
DirectFB_Available(void)
104
{
105
return 1;
106
107
}
108
109
static void
DirectFB_DeleteDevice(SDL_VideoDevice * device)
110
{
111
SDL_free(device->driverdata);
112
SDL_free(device);
113
114
}
115
116
static SDL_VideoDevice *
DirectFB_CreateDevice(int devindex)
117
{
118
119
120
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
121
122
123
124
SDL_DFB_CALLOC(device, 1, sizeof(SDL_VideoDevice));
SDL_DFB_CALLOC(device->gl_data, 1, sizeof(*device->gl_data));
/* Set the function pointers */
125
126
127
128
/* Set the function pointers */
device->VideoInit = DirectFB_VideoInit;
device->VideoQuit = DirectFB_VideoQuit;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
device->GetDisplayModes = DirectFB_GetDisplayModes;
device->SetDisplayMode = DirectFB_SetDisplayMode;
#if 0
device->SetDisplayGammaRamp = DirectFB_SetDisplayGammaRamp;
device->GetDisplayGammaRamp = DirectFB_GetDisplayGammaRamp;
#else
device->SetDisplayGammaRamp = NULL;
device->GetDisplayGammaRamp = NULL;
#endif
device->PumpEvents = DirectFB_PumpEventsWindow;
device->CreateWindow = DirectFB_CreateWindow;
device->CreateWindowFrom = DirectFB_CreateWindowFrom;
device->SetWindowTitle = DirectFB_SetWindowTitle;
device->SetWindowPosition = DirectFB_SetWindowPosition;
device->SetWindowSize = DirectFB_SetWindowSize;
device->ShowWindow = DirectFB_ShowWindow;
device->HideWindow = DirectFB_HideWindow;
device->RaiseWindow = DirectFB_RaiseWindow;
device->MaximizeWindow = DirectFB_MaximizeWindow;
device->MinimizeWindow = DirectFB_MinimizeWindow;
device->RestoreWindow = DirectFB_RestoreWindow;
device->SetWindowGrab = DirectFB_SetWindowGrab;
device->DestroyWindow = DirectFB_DestroyWindow;
device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
#if SDL_DIRECTFB_OPENGL
device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
device->GL_CreateContext = DirectFB_GL_CreateContext;
device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
device->GL_SwapWindow = DirectFB_GL_SwapWindow;
device->GL_DeleteContext = DirectFB_GL_DeleteContext;
#endif
166
167
168
169
device->free = DirectFB_DeleteDevice;
return device;
170
171
172
173
error:
if (device)
free(device);
return (0);
174
175
176
}
VideoBootStrap DirectFB_bootstrap = {
177
178
"directfb", "DirectFB",
DirectFB_Available, DirectFB_CreateDevice
179
180
};
181
182
static DFBEnumerationResult
EnumModesCallback(int width, int height, int bpp, void *data)
183
{
184
185
186
187
188
189
190
191
192
193
194
195
SDL_VideoDisplay *this = (SDL_VideoDisplay *) data;
DFB_DisplayData *dispdata = (DFB_DisplayData *) this->driverdata;
SDL_DisplayMode mode;
mode.w = width;
mode.h = height;
mode.refresh_rate = 0;
mode.driverdata = NULL;
mode.format = 0;
if (dispdata->nummodes < DFB_MAX_MODES) {
dispdata->modelist[dispdata->nummodes++] = mode;
196
197
}
198
SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
199
return DFENUM_OK;
200
201
}
202
static int
203
DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt)
204
{
205
switch (pixelformat) {
206
207
case DSPF_ALUT44:
*fmt = SDL_PIXELFORMAT_INDEX4LSB;
208
break;
209
210
211
212
213
214
215
216
217
218
219
case DSPF_LUT8:
*fmt = SDL_PIXELFORMAT_INDEX8;
break;
case DSPF_RGB332:
*fmt = SDL_PIXELFORMAT_RGB332;
break;
case DSPF_ARGB4444:
*fmt = SDL_PIXELFORMAT_ARGB4444;
break;
case SDL_PIXELFORMAT_ARGB1555:
*fmt = SDL_PIXELFORMAT_ARGB1555;
220
break;
221
case DSPF_RGB16:
222
*fmt = SDL_PIXELFORMAT_RGB565;
223
break;
224
case DSPF_RGB24:
225
226
*fmt = SDL_PIXELFORMAT_RGB24;
break;
227
case DSPF_RGB32:
228
*fmt = SDL_PIXELFORMAT_RGB888;
229
break;
230
231
case DSPF_ARGB:
*fmt = SDL_PIXELFORMAT_ARGB8888;
232
break;
233
234
235
236
237
238
239
240
241
242
243
244
case DSPF_YV12:
*fmt = SDL_PIXELFORMAT_YV12;
break; /* Planar mode: Y + V + U (3 planes) */
case DSPF_I420:
*fmt = SDL_PIXELFORMAT_IYUV;
break; /* Planar mode: Y + U + V (3 planes) */
case DSPF_YUY2:
*fmt = SDL_PIXELFORMAT_YUY2;
break; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
case DSPF_UYVY:
*fmt = SDL_PIXELFORMAT_UYVY;
break; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
245
default:
246
return -1;
247
}
248
249
return 0;
}
250
251
252
253
254
255
static DFBEnumerationResult
cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
void *callbackdata)
{
DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
256
257
258
devdata->screenid[devdata->numscreens++] = screen_id;
return DFENUM_OK;
259
260
}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
DFBEnumerationResult
cbLayers(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
void *callbackdata)
{
DFB_DeviceData *devdata = (DFB_DeviceData *) callbackdata;
if (desc.caps & DLCAPS_SURFACE) {
if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
if (devdata->vidlayer[devdata->aux] == -1)
devdata->vidlayer[devdata->aux] = layer_id;
} else if (desc.type & DLTF_GRAPHICS) {
if (devdata->gralayer[devdata->aux] == -1)
devdata->gralayer[devdata->aux] = layer_id;
}
}
return DFENUM_OK;
}
278
279
280
static int
DirectFB_VideoInit(_THIS)
281
{
282
#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
283
DFBCardCapabilities caps;
284
#else
285
DFBGraphicsDeviceDescription caps;
286
#endif
287
288
289
290
291
DFBDisplayLayerConfig dlc;
struct DirectFBEnumRect *rect;
IDirectFB *dfb = NULL;
IDirectFBDisplayLayer *layer = NULL;
292
293
294
295
296
297
298
299
SDL_VideoDisplay display;
DFB_DisplayData *dispdata;
DFB_DeviceData *devdata;
SDL_DisplayMode mode;
int i;
DFBResult ret;
int tcw[DFB_MAX_SCREENS];
int tch[DFB_MAX_SCREENS];
300
301
302
SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
303
304
305
306
307
308
SDL_DFB_CALLOC(devdata, 1, sizeof(*devdata));
devdata->numscreens = 0;
for (i = 0; i < DFB_MAX_SCREENS; i++) {
devdata->gralayer[i] = -1;
devdata->vidlayer[i] = -1;
309
}
310
311
312
SDL_DFB_CHECKERR(dfb->EnumScreens(dfb, &cbScreens, devdata));
for (i = 0; i < devdata->numscreens; i++) {
IDirectFBScreen *screen;
313
314
SDL_DFB_CHECKERR(dfb->GetScreen(dfb, devdata->screenid[i], &screen));
315
316
devdata->aux = i;
317
318
SDL_DFB_CHECKERR(screen->EnumDisplayLayers
(screen, &cbLayers, devdata));
319
#if (DIRECTFB_MAJOR_VERSION >= 1)
320
screen->GetSize(screen, &tcw[i], &tch[i]);
321
322
323
324
325
326
327
#else
/* FIXME: this is only used to center windows
* Should be done otherwise, e.g. get surface from layer
*/
tcw[i] = 800;
tch[i] = 600;
#endif
328
329
screen->Release(screen);
}
330
331
/* Query card capabilities */
332
333
dfb->GetDeviceDescription(dfb, &caps);
334
335
336
337
SDL_DFB_DEBUG("SDL directfb video driver - %s %s\n", __DATE__, __TIME__);
SDL_DFB_DEBUG("Using %s (%s) driver.\n", caps.name, caps.vendor);
SDL_DFB_DEBUG("Found %d screens\n", devdata->numscreens);
338
339
340
for (i = 0; i < devdata->numscreens; i++) {
//SDL_DFB_CHECKERR( dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer) );
341
342
SDL_DFB_CHECKERR(dfb->GetDisplayLayer
(dfb, devdata->gralayer[i], &layer));
343
//SDL_DFB_CHECKERR( dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events) );
344
345
346
SDL_DFB_CHECKERR(layer->SetCooperativeLevel
(layer, DLSCL_ADMINISTRATIVE));
347
348
349
layer->EnableCursor(layer, 1);
SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
350
351
352
/* Query layer configuration to determine the current mode and pixelformat */
layer->GetConfiguration(layer, &dlc);
353
354
DFBToSDLPixelFormat(dlc.pixelformat, &mode.format);
355
356
357
358
359
mode.w = dlc.width;
mode.h = dlc.height;
mode.refresh_rate = 0;
mode.driverdata = NULL;
360
361
SDL_DFB_CALLOC(dispdata, 1, sizeof(*dispdata));
362
363
364
365
366
dispdata->layer = layer;
dispdata->pixelformat = dlc.pixelformat;
dispdata->cw = tcw[i];
dispdata->ch = tch[i];
367
368
/* YUV - Video layer */
369
370
dispdata->vidID = devdata->vidlayer[i];
371
dispdata->vidIDinuse = 0;
372
373
SDL_zero(display);
374
375
376
377
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = dispdata;
378
379
380
381
/* Enumerate the available fullscreen modes */
SDL_DFB_CALLOC(dispdata->modelist, DFB_MAX_MODES,
sizeof(SDL_DisplayMode));
382
383
SDL_DFB_CHECKERR(dfb->EnumVideoModes
(dfb, EnumModesCallback, &display));
384
385
SDL_AddVideoDisplay(&display);
386
387
}
388
389
390
devdata->initialized = 1;
devdata->dfb = dfb;
devdata->firstwin = NULL;
391
392
_this->driverdata = devdata;
393
394
395
396
397
398
399
#if SDL_DIRECTFB_OPENGL
/* Opengl */
_this->gl_data->gl_active = 0;
_this->gl_data->gl_context = NULL;
#endif
400
401
402
DirectFB_AddRenderDriver(_this);
DirectFB_InitMouse(_this);
403
DirectFB_InitKeyboard(_this);
404
//devdata->mouse = SDL_AddMouse(&mouse, -1);
405
406
return 0;
407
408
409
410
411
412
413
414
415
error:
//FIXME: Cleanup not complete, Free existing displays
SDL_DFB_FREE(dispdata);
SDL_DFB_FREE(dispdata->modelist);
SDL_DFB_RELEASE(layer);
SDL_DFB_RELEASE(dfb);
return -1;
416
417
}
418
419
static void
DirectFB_VideoQuit(_THIS)
420
{
421
422
DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
SDL_DisplayMode tmode;
423
DFBResult ret;
424
int i;
425
426
427
428
429
430
431
432
433
434
435
tmode = _this->displays[0].desktop_mode;
tmode.format = SDL_PIXELFORMAT_UNKNOWN;
DirectFB_SetDisplayMode(_this, &tmode);
tmode = _this->displays[0].desktop_mode;
DirectFB_SetDisplayMode(_this, &tmode);
for (i = 0; i < devdata->numscreens; i++) {
DFB_DisplayData *dispdata =
(DFB_DisplayData *) _this->displays[i].driverdata;
if (dispdata->layer) {
436
437
438
439
440
441
442
443
SDL_DFB_CHECK(dispdata->
layer->SetCooperativeLevel(dispdata->layer,
DLSCL_ADMINISTRATIVE));
SDL_DFB_CHECK(dispdata->
layer->SetCursorOpacity(dispdata->layer, 0x00));
SDL_DFB_CHECK(dispdata->
layer->SetCooperativeLevel(dispdata->layer,
DLSCL_SHARED));
444
}
445
SDL_DFB_RELEASE(dispdata->layer);
446
447
448
449
450
/* Free video mode list */
if (dispdata->modelist) {
SDL_free(dispdata->modelist);
dispdata->modelist = NULL;
451
}
452
453
// Done by core
//SDL_free(dispdata);
454
455
}
456
SDL_DFB_RELEASE(devdata->dfb);
457
458
459
SDL_DelMouse(devdata->mouse);
SDL_DelKeyboard(devdata->keyboard);
460
461
462
463
#if SDL_DIRECTFB_OPENGL
DirectFB_GL_UnloadLibrary(_this);
#endif
464
465
466
devdata->initialized = 0;
}
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
static DFBSurfacePixelFormat
SDLToDFBPixelFormat(Uint32 format)
{
switch (format) {
case SDL_PIXELFORMAT_INDEX4LSB:
return DSPF_ALUT44;
case SDL_PIXELFORMAT_INDEX8:
return DSPF_LUT8;
case SDL_PIXELFORMAT_RGB332:
return DSPF_RGB332;
case SDL_PIXELFORMAT_RGB555:
return DSPF_ARGB1555;
case SDL_PIXELFORMAT_ARGB4444:
return DSPF_ARGB4444;
case SDL_PIXELFORMAT_ARGB1555:
return DSPF_ARGB1555;
case SDL_PIXELFORMAT_RGB565:
return DSPF_RGB16;
case SDL_PIXELFORMAT_RGB24:
return DSPF_RGB24;
case SDL_PIXELFORMAT_RGB888:
return DSPF_RGB32;
case SDL_PIXELFORMAT_ARGB8888:
return DSPF_ARGB;
case SDL_PIXELFORMAT_YV12:
return DSPF_YV12; /* Planar mode: Y + V + U (3 planes) */
case SDL_PIXELFORMAT_IYUV:
return DSPF_I420; /* Planar mode: Y + U + V (3 planes) */
case SDL_PIXELFORMAT_YUY2:
return DSPF_YUY2; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
case SDL_PIXELFORMAT_UYVY:
return DSPF_UYVY; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
case SDL_PIXELFORMAT_YVYU:
return DSPF_UNKNOWN; /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
case SDL_PIXELFORMAT_INDEX1LSB:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_INDEX1MSB:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_INDEX4MSB:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_RGB444:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_BGR24:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_BGR888:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_RGBA8888:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_ABGR8888:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_BGRA8888:
return DSPF_UNKNOWN;
case SDL_PIXELFORMAT_ARGB2101010:
return DSPF_UNKNOWN;
default:
return DSPF_UNKNOWN;
525
}
526
}
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
static void
CheckSetDisplayMode(_THIS, DFB_DisplayData * data, SDL_DisplayMode * mode)
{
DFBDisplayLayerConfig config;
DFBDisplayLayerConfigFlags failed;
config.width = mode->w;
config.height = mode->h;
config.pixelformat = SDLToDFBPixelFormat(mode->format);
config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
failed = 0;
data->layer->TestConfiguration(data->layer, &config, &failed);
if (failed == 0)
SDL_AddDisplayMode(_this->current_display, mode);
542
543
}
544
545
546
547
548
549
550
static void
DirectFB_GetDisplayModes(_THIS)
{
//SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
//SDL_DisplayMode mode;
//SDL_AddDisplayMode(_this->current_display, &mode);
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
int i;
SDL_DisplayMode mode;
for (i = 0; i < data->nummodes; ++i) {
mode = data->modelist[i];
//mode.format = SDL_PIXELFORMAT_UNKNOWN;
mode.format = SDL_PIXELFORMAT_INDEX8;
CheckSetDisplayMode(_this, data, &mode);
mode.format = SDL_PIXELFORMAT_RGB565;
CheckSetDisplayMode(_this, data, &mode);
mode.format = SDL_PIXELFORMAT_RGB24;
CheckSetDisplayMode(_this, data, &mode);
mode.format = SDL_PIXELFORMAT_RGB888;
CheckSetDisplayMode(_this, data, &mode);
569
570
}
}
571
572
573
int
DirectFB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
574
{
575
576
577
578
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *data = (DFB_DisplayData *) SDL_CurrentDisplay.driverdata;
DFBDisplayLayerConfig config, rconfig;
DFBDisplayLayerConfigFlags fail = 0;
579
DFBResult ret;
580
DFB_WindowData *win;
581
582
583
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
584
585
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
586
config.flags = DLCONF_WIDTH | DLCONF_HEIGHT; // | DLCONF_BUFFERMODE;
587
588
589
590
591
592
593
if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
config.flags |= DLCONF_PIXELFORMAT;
config.pixelformat = SDLToDFBPixelFormat(mode->format);
data->pixelformat = config.pixelformat;
}
config.width = mode->w;
config.height = mode->h;
594
595
//config.buffermode = DLBM_BACKVIDEO;
596
597
//config.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
598
599
600
601
602
data->layer->TestConfiguration(data->layer, &config, &fail);
if (fail & (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT)) {
SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
603
return -1;
604
}
605
606
607
SDL_DFB_DEBUG("Trace\n");
config.flags &= ~fail;
SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
608
609
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
610
611
612
613
614
615
/* Double check */
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
if ((config.width != rconfig.width) ||
(config.height != rconfig.height) ||
616
617
((mode->format != SDL_PIXELFORMAT_UNKNOWN)
&& (config.pixelformat != rconfig.pixelformat))) {
618
619
SDL_DFB_DEBUG("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
620
return -1;
621
622
}
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
data->pixelformat = rconfig.pixelformat;
data->cw = config.width;
data->ch = config.height;
SDL_CurrentDisplay.current_mode = *mode;
/*
* FIXME: video mode switch is currently broken
*
* DirectFB 1.2.0-rc1 even has a broken cursor after a switch
* The following code needs to be revisited whether it is still
* needed once the switch works again.
*/
win = devdata->firstwin;
while (win) {
SDL_DFB_RELEASE(win->surface);
SDL_DFB_CHECKERR(win->window->GetSurface(win->window, &win->surface));
win = win->next;
}
645
return 0;
646
647
error:
return -1;
648
649
}
650
651
static int
DirectFB_SetDisplayGammaRamp(_THIS, Uint16 * ramp)
652
{
653
return -1;
654
655
}
656
static int
657
DirectFB_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
658
{
659
return -1;
660
661
}
662
static int
663
DirectFB_CreateWindow(_THIS, SDL_Window * window)
664
{
665
666
667
668
669
670
671
672
673
674
675
676
677
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_DISPLAYDATA(_this, window);
DFB_WindowData *windata;
DFBWindowOptions wopts;
DFBWindowDescription desc;
int ret, x, y;
SDL_DFB_DEBUG("Trace x %d y %d w %d h %d\n", window->x, window->y,
window->w, window->h);
window->driverdata = NULL;
SDL_DFB_CALLOC(window->driverdata, 1, sizeof(DFB_WindowData));
windata = (DFB_WindowData *) window->driverdata;
678
679
680
681
682
SDL_DFB_CHECKERR(devdata->
dfb->SetCooperativeLevel(devdata->dfb, DFSCL_NORMAL));
SDL_DFB_CHECKERR(dispdata->
layer->SetCooperativeLevel(dispdata->layer,
DLSCL_ADMINISTRATIVE));
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/* Fill the window description. */
if (window->x == SDL_WINDOWPOS_CENTERED) {
x = (dispdata->cw - window->w) / 2;
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
x = 0;
} else {
x = window->x;
}
if (window->y == SDL_WINDOWPOS_CENTERED) {
y = (dispdata->ch - window->h) / 2;
} else if (window->y == SDL_WINDOWPOS_UNDEFINED) {
y = 0;
} else {
y = window->y;
}
699
700
701
702
if (window->flags & SDL_WINDOW_FULLSCREEN) {
x = 0;
y = 0;
}
703
704
705
desc.flags = DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS */ | DWDESC_PIXELFORMAT
| DWDESC_SURFACE_CAPS;
706
707
708
709
710
711
712
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
/* Needed for 1.2 */
desc.flags |= DWDESC_POSX | DWDESC_POSY;
desc.posx = x;
desc.posy = y;
#else
713
714
715
716
717
718
719
if (!(window->flags & SDL_WINDOW_FULLSCREEN)
&& window->x != SDL_WINDOWPOS_UNDEFINED
&& window->y != SDL_WINDOWPOS_UNDEFINED) {
desc.flags |= DWDESC_POSX | DWDESC_POSY;
desc.posx = x;
desc.posy = y;
}
720
#endif
721
722
723
724
desc.width = window->w;
desc.height = window->h;
desc.pixelformat = dispdata->pixelformat;
725
726
desc.caps = 0; // DWCAPS_DOUBLEBUFFER;
desc.surface_caps = DSCAPS_DOUBLE | DSCAPS_TRIPLE / DSCAPS_PREMULTIPLIED;
727
728
/* Create the window. */
729
730
SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
&windata->window));
731
732
733
windata->window->GetOptions(windata->window, &wopts);
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
734
735
736
if (window->flags & SDL_WINDOW_RESIZABLE)
wopts |= DWOP_SCALE;
737
else
738
739
740
741
742
743
744
745
746
747
wopts |= DWOP_KEEP_SIZE;
#else
wopts |= DWOP_KEEP_SIZE; // if not we will crash ...
#endif
if (window->flags & SDL_WINDOW_FULLSCREEN)
wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
windata->window->SetOptions(windata->window, wopts);
/* Get the window's surface. */
748
749
SDL_DFB_CHECKERR(windata->
window->GetSurface(windata->window, &windata->surface));
750
windata->window->SetOpacity(windata->window, 0xFF);
751
752
753
754
SDL_DFB_CHECKERR(windata->window->CreateEventBuffer(windata->window,
&
(windata->
eventbuffer)));
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
SDL_DFB_CHECKERR(windata->window->
EnableEvents(windata->window,
DWET_POSITION | DWET_SIZE | DWET_CLOSE |
DWET_ALL));
if (window->flags & SDL_WINDOW_FULLSCREEN)
windata->window->SetStackingClass(windata->window, DWSC_UPPER);
/* Make it the top most window. */
windata->window->RaiseToTop(windata->window);
windata->window->GetID(windata->window, &windata->windowID);
windata->id = window->id;
#if SDL_DIRECTFB_OPENGL
if (window->flags & SDL_WINDOW_OPENGL) {
if (!_this->gl_config.driver_loaded) {
/* no driver has been loaded, use default (ourselves) */
if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
goto error;
}
}
_this->gl_data->gl_active = 1;
}
#endif
/* Add to list ... */
windata->next = devdata->firstwin;
windata->opacity = 0xFF;
devdata->firstwin = windata;
//SDL_DFB_CHECKERR( windata->surface->GetPalette(windata->surface, &windata->palette) );
787
788
return 0;
789
790
791
792
error:
SDL_DFB_RELEASE(windata->window);
SDL_DFB_RELEASE(windata->surface);
return -1;
793
794
}
795
static int
796
DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
797
{
798
799
800
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
801
802
803
SDL_Unsupported();
return -1;
804
805
}
806
807
static void
DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
808
{
809
810
811
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
812
813
814
SDL_Unsupported();
//return -1;
815
816
}
817
818
819
static void
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
820
{
821
822
823
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
824
825
826
827
828
829
int x, y;
if (window->y == SDL_WINDOWPOS_UNDEFINED)
y = 0;
else
y = window->y;
830
831
832
833
834
835
836
837
838
839
840
841
if (window->x == SDL_WINDOWPOS_UNDEFINED)
x = 0;
else
x = window->x;
if (window->flags & SDL_WINDOW_FULLSCREEN) {
x = 0;
y = 0;
}
//if (!(window->flags & SDL_WINDOW_FULLSCREEN))
windata->window->MoveTo(windata->window, x, y);
842
843
}
844
845
static void
DirectFB_SetWindowSize(_THIS, SDL_Window * window)
846
{
847
int ret;
848
849
850
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
int ch, cw;
// SDL_DFB_DEBUG("Resize %d %d %d %d\n", cw, ch, window->w, window->h);
#if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 0)
SDL_DFB_CHECKERR(windata->window->
ResizeSurface(windata->window, window->w,
window->h));
#else
SDL_DFB_CHECKERR(windata->window->
Resize(windata->window, window->w, window->h));
#endif
SDL_DFB_CHECKERR(windata->window->GetSize(windata->window, &window->w, &window->h)); /* if a window manager should have decided otherwise */
}
error:
return;
868
}
869
870
871
872
873
874
875
876
877
static void
DirectFB_ShowWindow(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
windata->window->SetOpacity(windata->window, windata->opacity);
878
879
880
}
881
static void
882
DirectFB_HideWindow(_THIS, SDL_Window * window)
883
{
884
885
886
887
888
889
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
windata->window->GetOpacity(windata->window, &windata->opacity);
windata->window->SetOpacity(windata->window, 0);
890
891
}
892
893
static void
894
DirectFB_RaiseWindow(_THIS, SDL_Window * window)
895
{
896
897
898
899
900
901
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
windata->window->Raise(windata->window);
902
903
}
904
static void
905
DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
906
{
907
908
909
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
910
911
SDL_Unsupported();
912
913
}
914
915
916
917
918
919
920
static void
DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
921
922
SDL_Unsupported();
923
924
}
925
926
927
928
929
930
931
static void
DirectFB_RestoreWindow(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
932
933
SDL_Unsupported();
934
935
}
936
937
938
939
940
941
942
static void
DirectFB_SetWindowGrab(_THIS, SDL_Window * window)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
943
944
SDL_Unsupported();
945
946
947
}
948
949
static void
DirectFB_DestroyWindow(_THIS, SDL_Window * window)
950
{
951
952
953
954
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
DFB_WindowData *p;
955
956
SDL_DFB_DEBUG("Trace\n");
957
958
959
960
961
SDL_DFB_RELEASE(windata->palette);
SDL_DFB_RELEASE(windata->eventbuffer);
SDL_DFB_RELEASE(windata->surface);
SDL_DFB_RELEASE(windata->window);
962
963
/* Remove from list ... */
964
965
966
967
968
969
970
971
972
973
p = devdata->firstwin;
while (p && p->next != windata)
p = p->next;
if (p)
p->next = windata->next;
else
devdata->firstwin = windata->next;
SDL_free(windata);
}
974
975
976
977
978
979
980
981
static SDL_bool
DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info)
{
SDL_DFB_DEVICEDATA(_this);
SDL_DFB_WINDOWDATA(window);
SDL_DFB_DISPLAYDATA(_this, window);
982
983
984
985
SDL_Unsupported();
return SDL_FALSE;
}
986
987
#if SDL_DIRECTFB_OPENGL
988
989
990
991
992
993
994
995
996
997
998
999
#define OPENGL_REQUIRS_DLOPEN
#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
#include <dlfcn.h>
#define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
#define GL_LoadFunction dlsym
#define GL_UnloadObject dlclose
#else
#define GL_LoadObject SDL_LoadObject
#define GL_LoadFunction SDL_LoadFunction
#define GL_UnloadObject SDL_UnloadObject
#endif
1000