This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_DirectFB_modes.c
413 lines (334 loc) · 12.9 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2010 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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.
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.
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
Sam Lantinga
slouken@libsdl.org
21
22
23
SDL1.3 DirectFB driver by couriersud@arcor.de
24
25
26
*/
#include "SDL_DirectFB_video.h"
27
#include "SDL_DirectFB_modes.h"
28
29
30
#define DFB_MAX_MODES 200
31
struct screen_callback_t
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
int numscreens;
DFBScreenID screenid[DFB_MAX_SCREENS];
DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
int aux; /* auxiliary integer for callbacks */
};
struct modes_callback_t
{
int nummodes;
SDL_DisplayMode *modelist;
};
static DFBEnumerationResult
EnumModesCallback(int width, int height, int bpp, void *data)
{
struct modes_callback_t *modedata = (struct modes_callback_t *) data;
SDL_DisplayMode mode;
mode.w = width;
mode.h = height;
mode.refresh_rate = 0;
mode.driverdata = NULL;
mode.format = SDL_PIXELFORMAT_UNKNOWN;
if (modedata->nummodes < DFB_MAX_MODES) {
modedata->modelist[modedata->nummodes++] = mode;
}
return DFENUM_OK;
}
static DFBEnumerationResult
66
EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
67
68
void *callbackdata)
{
69
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
70
71
72
73
74
devdata->screenid[devdata->numscreens++] = screen_id;
return DFENUM_OK;
}
75
76
static DFBEnumerationResult
EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
77
78
void *callbackdata)
{
79
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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;
}
static void
94
CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
95
96
97
98
99
{
SDL_DFB_DEVICEDATA(_this);
DFBDisplayLayerConfig config;
DFBDisplayLayerConfigFlags failed;
100
101
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
102
103
config.width = mode->w;
config.height = mode->h;
104
config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
105
106
107
108
109
110
111
config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
if (devdata->use_yuv_underlays) {
config.flags |= DLCONF_OPTIONS;
config.options = DLOP_ALPHACHANNEL;
}
failed = 0;
data->layer->TestConfiguration(data->layer, &config, &failed);
112
113
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_SHARED));
114
if (failed == 0)
115
{
116
SDL_AddDisplayMode(display, mode);
117
118
SDL_DFB_LOG("Mode %d x %d Added\n", mode->w, mode->h);
}
119
else
120
SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
121
mode->h, failed);
122
123
124
125
126
127
return;
error:
return;
}
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
void
DirectFB_SetContext(_THIS, SDL_Window *window)
{
#if (DFB_VERSION_ATLEAST(1,0,0))
/* FIXME: does not work on 1.0/1.2 with radeon driver
* the approach did work with the matrox driver
* This has simply no effect.
*/
SDL_VideoDisplay *display = window->display;
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
/* FIXME: should we handle the error */
if (dispdata->vidIDinuse)
SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
DFB_TRUE));
#endif
}
148
149
150
151
152
153
void
DirectFB_InitModes(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
IDirectFBDisplayLayer *layer = NULL;
SDL_VideoDisplay display;
154
DFB_DisplayData *dispdata = NULL;
155
156
157
SDL_DisplayMode mode;
DFBGraphicsDeviceDescription caps;
DFBDisplayLayerConfig dlc;
158
struct screen_callback_t *screencbdata;
159
160
161
162
163
164
int tcw[DFB_MAX_SCREENS];
int tch[DFB_MAX_SCREENS];
int i;
DFBResult ret;
165
SDL_DFB_ALLOC_CLEAR(screencbdata, sizeof(*screencbdata));
166
167
168
169
170
171
172
173
screencbdata->numscreens = 0;
for (i = 0; i < DFB_MAX_SCREENS; i++) {
screencbdata->gralayer[i] = -1;
screencbdata->vidlayer[i] = -1;
}
174
SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &EnumScreensCallback,
175
screencbdata));
176
177
178
179
for (i = 0; i < screencbdata->numscreens; i++) {
IDirectFBScreen *screen;
180
181
182
SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb,
screencbdata->screenid
[i], &screen));
183
184
screencbdata->aux = i;
185
SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &EnumLayersCallback,
186
screencbdata));
187
screen->GetSize(screen, &tcw[i], &tch[i]);
188
189
190
191
192
193
194
195
196
screen->Release(screen);
}
/* Query card capabilities */
devdata->dfb->GetDeviceDescription(devdata->dfb, &caps);
for (i = 0; i < screencbdata->numscreens; i++) {
197
198
199
SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
screencbdata->gralayer
[i], &layer));
200
201
202
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer,
DLSCL_ADMINISTRATIVE));
203
204
205
206
207
208
209
210
layer->EnableCursor(layer, 1);
SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
if (devdata->use_yuv_underlays) {
dlc.flags = DLCONF_PIXELFORMAT | DLCONF_OPTIONS;
dlc.pixelformat = DSPF_ARGB;
dlc.options = DLOP_ALPHACHANNEL;
211
ret = layer->SetConfiguration(layer, &dlc);
212
if (ret != DFB_OK) {
213
214
/* try AiRGB if the previous failed */
dlc.pixelformat = DSPF_AiRGB;
215
SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
216
217
218
219
}
}
/* Query layer configuration to determine the current mode and pixelformat */
220
dlc.flags = DLCONF_ALL;
221
SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
222
223
mode.format = DirectFB_DFBToSDLPixelFormat(dlc.pixelformat);
224
225
if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
226
227
228
229
230
231
232
233
234
SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
goto error;
}
mode.w = dlc.width;
mode.h = dlc.height;
mode.refresh_rate = 0;
mode.driverdata = NULL;
235
SDL_DFB_ALLOC_CLEAR(dispdata, sizeof(*dispdata));
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
dispdata->layer = layer;
dispdata->pixelformat = dlc.pixelformat;
dispdata->cw = tcw[i];
dispdata->ch = tch[i];
/* YUV - Video layer */
dispdata->vidID = screencbdata->vidlayer[i];
dispdata->vidIDinuse = 0;
SDL_zero(display);
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = dispdata;
253
#if (DFB_VERSION_ATLEAST(1,2,0))
254
255
256
257
258
dlc.flags =
DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS;
ret = layer->SetConfiguration(layer, &dlc);
#endif
259
260
261
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
262
263
264
265
266
267
268
269
270
271
272
273
SDL_AddVideoDisplay(&display);
}
SDL_DFB_FREE(screencbdata);
return;
error:
/* FIXME: Cleanup not complete, Free existing displays */
SDL_DFB_FREE(dispdata);
SDL_DFB_RELEASE(layer);
return;
}
void
274
DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
275
276
{
SDL_DFB_DEVICEDATA(_this);
277
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
278
279
280
281
282
283
284
SDL_DisplayMode mode;
struct modes_callback_t data;
int i;
data.nummodes = 0;
/* Enumerate the available fullscreen modes */
SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode));
285
286
SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb,
EnumModesCallback, &data));
287
288
289
290
291
for (i = 0; i < data.nummodes; ++i) {
mode = data.modelist[i];
mode.format = SDL_PIXELFORMAT_ARGB8888;
292
CheckSetDisplayMode(_this, display, dispdata, &mode);
293
mode.format = SDL_PIXELFORMAT_RGB888;
294
CheckSetDisplayMode(_this, display, dispdata, &mode);
295
mode.format = SDL_PIXELFORMAT_RGB24;
296
CheckSetDisplayMode(_this, display, dispdata, &mode);
297
mode.format = SDL_PIXELFORMAT_RGB565;
298
CheckSetDisplayMode(_this, display, dispdata, &mode);
299
mode.format = SDL_PIXELFORMAT_INDEX8;
300
CheckSetDisplayMode(_this, display, dispdata, &mode);
301
}
302
303
SDL_DFB_FREE(data.modelist);
304
error:
305
306
307
308
return;
}
int
309
DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
310
311
312
313
314
315
316
{
/*
* FIXME: video mode switch is currently broken for 1.2.0
*
*/
SDL_DFB_DEVICEDATA(_this);
317
DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
318
319
320
DFBDisplayLayerConfig config, rconfig;
DFBDisplayLayerConfigFlags fail = 0;
321
322
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
323
324
325
326
327
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
config.flags |= DLCONF_PIXELFORMAT;
328
config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
329
330
331
332
333
334
335
336
337
338
339
340
341
data->pixelformat = config.pixelformat;
}
config.width = mode->w;
config.height = mode->h;
if (devdata->use_yuv_underlays) {
config.flags |= DLCONF_OPTIONS;
config.options = DLOP_ALPHACHANNEL;
}
data->layer->TestConfiguration(data->layer, &config, &fail);
if (fail &
342
343
(DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS)) {
344
345
346
347
348
349
350
SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
return -1;
}
config.flags &= ~fail;
SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
351
#if (DFB_VERSION_ATLEAST(1,2,0))
352
353
354
/* Need to call this twice ! */
SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
#endif
355
356
357
/* Double check */
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
358
359
SDL_DFB_CHECKERR(data->
layer->SetCooperativeLevel(data->layer, DLSCL_SHARED));
360
361
362
363
if ((config.width != rconfig.width) || (config.height != rconfig.height)
|| ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
&& (config.pixelformat != rconfig.pixelformat))) {
364
365
366
367
SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
return -1;
}
368
369
370
371
data->pixelformat = rconfig.pixelformat;
data->cw = config.width;
data->ch = config.height;
372
display->current_mode = *mode;
373
374
375
376
377
378
379
380
381
382
383
384
return 0;
error:
return -1;
}
void
DirectFB_QuitModes(_THIS)
{
SDL_DisplayMode tmode;
int i;
385
386
387
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
388
389
390
391
SDL_GetDesktopDisplayModeForDisplay(display, &tmode);
tmode.format = SDL_PIXELFORMAT_UNKNOWN;
DirectFB_SetDisplayMode(_this, display, &tmode);
392
393
394
SDL_GetDesktopDisplayModeForDisplay(display, &tmode);
DirectFB_SetDisplayMode(_this, display, &tmode);
395
396
if (dispdata->layer) {
397
398
399
400
401
402
403
404
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));
405
406
407
408
409
410
411
412
413
}
SDL_DFB_RELEASE(dispdata->layer);
SDL_DFB_RELEASE(dispdata->vidlayer);
}
}
/* vi: set ts=4 sw=4 expandtab: */