Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
413 lines (334 loc) · 12.9 KB

SDL_DirectFB_modes.c

File metadata and controls

413 lines (334 loc) · 12.9 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
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
Feb 6, 2011
Feb 6, 2011
21
22
23
SDL1.3 DirectFB driver by couriersud@arcor.de
24
25
26
*/
#include "SDL_DirectFB_video.h"
Feb 6, 2011
Feb 6, 2011
27
#include "SDL_DirectFB_modes.h"
28
29
30
#define DFB_MAX_MODES 200
Feb 6, 2011
Feb 6, 2011
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
Feb 6, 2011
Feb 6, 2011
66
EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
67
68
void *callbackdata)
{
Feb 6, 2011
Feb 6, 2011
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;
}
Feb 6, 2011
Feb 6, 2011
75
76
static DFBEnumerationResult
EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
77
78
void *callbackdata)
{
Feb 6, 2011
Feb 6, 2011
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
Dec 1, 2009
Dec 1, 2009
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;
Jan 11, 2009
Jan 11, 2009
100
101
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
102
103
config.width = mode->w;
config.height = mode->h;
Feb 6, 2011
Feb 6, 2011
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);
Jan 11, 2009
Jan 11, 2009
112
113
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_SHARED));
114
if (failed == 0)
Feb 6, 2011
Feb 6, 2011
115
{
Dec 1, 2009
Dec 1, 2009
116
SDL_AddDisplayMode(display, mode);
Feb 6, 2011
Feb 6, 2011
117
118
SDL_DFB_LOG("Mode %d x %d Added\n", mode->w, mode->h);
}
119
else
Aug 16, 2010
Aug 16, 2010
120
SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
Jan 11, 2009
Jan 11, 2009
121
mode->h, failed);
122
123
124
125
126
127
return;
error:
return;
}
Feb 6, 2011
Feb 6, 2011
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;
Jan 11, 2009
Jan 11, 2009
154
DFB_DisplayData *dispdata = NULL;
155
156
157
SDL_DisplayMode mode;
DFBGraphicsDeviceDescription caps;
DFBDisplayLayerConfig dlc;
Feb 6, 2011
Feb 6, 2011
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;
Feb 6, 2011
Feb 6, 2011
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;
}
Feb 6, 2011
Feb 6, 2011
174
SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &EnumScreensCallback,
Jan 11, 2009
Jan 11, 2009
175
screencbdata));
176
177
178
179
for (i = 0; i < screencbdata->numscreens; i++) {
IDirectFBScreen *screen;
Jan 11, 2009
Jan 11, 2009
180
181
182
SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb,
screencbdata->screenid
[i], &screen));
183
184
screencbdata->aux = i;
Feb 6, 2011
Feb 6, 2011
185
SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &EnumLayersCallback,
Jan 11, 2009
Jan 11, 2009
186
screencbdata));
187
screen->GetSize(screen, &tcw[i], &tch[i]);
Feb 6, 2011
Feb 6, 2011
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++) {
Jan 11, 2009
Jan 11, 2009
197
198
199
SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
screencbdata->gralayer
[i], &layer));
200
Jan 11, 2009
Jan 11, 2009
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;
Feb 6, 2011
Feb 6, 2011
211
ret = layer->SetConfiguration(layer, &dlc);
Aug 16, 2010
Aug 16, 2010
212
if (ret != DFB_OK) {
213
214
/* try AiRGB if the previous failed */
dlc.pixelformat = DSPF_AiRGB;
Aug 16, 2010
Aug 16, 2010
215
SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
216
217
218
219
}
}
/* Query layer configuration to determine the current mode and pixelformat */
Dec 1, 2008
Dec 1, 2008
220
dlc.flags = DLCONF_ALL;
Aug 16, 2010
Aug 16, 2010
221
SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
222
Feb 6, 2011
Feb 6, 2011
223
mode.format = DirectFB_DFBToSDLPixelFormat(dlc.pixelformat);
Aug 16, 2010
Aug 16, 2010
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;
Feb 6, 2011
Feb 6, 2011
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;
Jan 13, 2009
Jan 13, 2009
253
#if (DFB_VERSION_ATLEAST(1,2,0))
Dec 6, 2008
Dec 6, 2008
254
255
256
257
258
dlc.flags =
DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS;
ret = layer->SetConfiguration(layer, &dlc);
#endif
Dec 1, 2008
Dec 1, 2008
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
Dec 1, 2009
Dec 1, 2009
274
DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
275
276
{
SDL_DFB_DEVICEDATA(_this);
Dec 1, 2009
Dec 1, 2009
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));
Jan 11, 2009
Jan 11, 2009
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;
Dec 1, 2009
Dec 1, 2009
292
CheckSetDisplayMode(_this, display, dispdata, &mode);
293
mode.format = SDL_PIXELFORMAT_RGB888;
Dec 1, 2009
Dec 1, 2009
294
CheckSetDisplayMode(_this, display, dispdata, &mode);
295
mode.format = SDL_PIXELFORMAT_RGB24;
Dec 1, 2009
Dec 1, 2009
296
CheckSetDisplayMode(_this, display, dispdata, &mode);
297
mode.format = SDL_PIXELFORMAT_RGB565;
Dec 1, 2009
Dec 1, 2009
298
CheckSetDisplayMode(_this, display, dispdata, &mode);
299
mode.format = SDL_PIXELFORMAT_INDEX8;
Dec 1, 2009
Dec 1, 2009
300
CheckSetDisplayMode(_this, display, dispdata, &mode);
301
}
Dec 1, 2009
Dec 1, 2009
302
303
SDL_DFB_FREE(data.modelist);
Jan 11, 2010
Jan 11, 2010
304
error:
305
306
307
308
return;
}
int
Dec 1, 2009
Dec 1, 2009
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);
Dec 1, 2009
Dec 1, 2009
317
DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
318
319
320
DFBDisplayLayerConfig config, rconfig;
DFBDisplayLayerConfigFlags fail = 0;
Jan 11, 2009
Jan 11, 2009
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;
Feb 6, 2011
Feb 6, 2011
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 &
Jan 11, 2009
Jan 11, 2009
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));
Jan 13, 2009
Jan 13, 2009
351
#if (DFB_VERSION_ATLEAST(1,2,0))
Dec 1, 2008
Dec 1, 2008
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));
Jan 11, 2009
Jan 11, 2009
358
359
SDL_DFB_CHECKERR(data->
layer->SetCooperativeLevel(data->layer, DLSCL_SHARED));
360
Jan 11, 2009
Jan 11, 2009
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;
}
Dec 6, 2008
Dec 6, 2008
368
369
370
371
data->pixelformat = rconfig.pixelformat;
data->cw = config.width;
data->ch = config.height;
Dec 1, 2009
Dec 1, 2009
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;
Dec 1, 2009
Dec 1, 2009
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
Dec 1, 2009
Dec 1, 2009
389
390
391
SDL_GetDesktopDisplayModeForDisplay(display, &tmode);
tmode.format = SDL_PIXELFORMAT_UNKNOWN;
DirectFB_SetDisplayMode(_this, display, &tmode);
392
Dec 1, 2009
Dec 1, 2009
393
394
SDL_GetDesktopDisplayModeForDisplay(display, &tmode);
DirectFB_SetDisplayMode(_this, display, &tmode);
395
396
if (dispdata->layer) {
Jan 11, 2009
Jan 11, 2009
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: */