Hash :
3f1fd5ab
Author :
Date :
2023-05-23T10:59:03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_DIRECTFB
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_modes.h"
#define DFB_MAX_MODES 200
struct screen_callback_t
{
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 EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc, void *callbackdata)
{
struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
devdata->screenid[devdata->numscreens++] = screen_id;
return DFENUM_OK;
}
static DFBEnumerationResult EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc, void *callbackdata)
{
struct screen_callback_t *devdata = (struct screen_callback_t *) 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;
}
static void CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
{
SDL_DFB_DEVICEDATA(_this);
DFBDisplayLayerConfig config;
DFBDisplayLayerConfigFlags failed;
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
config.width = mode->w;
config.height = mode->h;
config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
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);
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_SHARED));
if (failed == 0)
{
SDL_AddDisplayMode(display, mode);
SDL_DFB_LOG("Mode %d x %d Added\n", mode->w, mode->h);
}
else
SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
mode->h, failed);
return;
error:
return;
}
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 = SDL_GetDisplayForWindow(window);
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
}
void DirectFB_InitModes(_THIS)
{
SDL_DFB_DEVICEDATA(_this);
IDirectFBDisplayLayer *layer = NULL;
SDL_VideoDisplay display;
DFB_DisplayData *dispdata = NULL;
SDL_DisplayMode mode;
DFBGraphicsDeviceDescription caps;
DFBDisplayLayerConfig dlc;
struct screen_callback_t *screencbdata;
int tcw[DFB_MAX_SCREENS];
int tch[DFB_MAX_SCREENS];
int i;
DFBResult ret;
SDL_DFB_ALLOC_CLEAR(screencbdata, sizeof(*screencbdata));
screencbdata->numscreens = 0;
for (i = 0; i < DFB_MAX_SCREENS; i++) {
screencbdata->gralayer[i] = -1;
screencbdata->vidlayer[i] = -1;
}
SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &EnumScreensCallback,
screencbdata));
for (i = 0; i < screencbdata->numscreens; i++) {
IDirectFBScreen *screen;
SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb,
screencbdata->screenid
[i], &screen));
screencbdata->aux = i;
SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &EnumLayersCallback,
screencbdata));
screen->GetSize(screen, &tcw[i], &tch[i]);
screen->Release(screen);
}
/* Query card capabilities */
devdata->dfb->GetDeviceDescription(devdata->dfb, &caps);
for (i = 0; i < screencbdata->numscreens; i++) {
SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
screencbdata->gralayer
[i], &layer));
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer,
DLSCL_ADMINISTRATIVE));
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;
ret = layer->SetConfiguration(layer, &dlc);
if (ret != DFB_OK) {
/* try AiRGB if the previous failed */
dlc.pixelformat = DSPF_AiRGB;
SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
}
}
/* Query layer configuration to determine the current mode and pixelformat */
dlc.flags = DLCONF_ALL;
SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
mode.format = DirectFB_DFBToSDLPixelFormat(dlc.pixelformat);
if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
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;
SDL_DFB_ALLOC_CLEAR(dispdata, sizeof(*dispdata));
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;
#if (DFB_VERSION_ATLEAST(1,2,0))
dlc.flags =
DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS;
ret = layer->SetConfiguration(layer, &dlc);
#endif
SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
SDL_AddVideoDisplay(&display, SDL_FALSE);
}
SDL_DFB_FREE(screencbdata);
return;
error:
/* FIXME: Cleanup not complete, Free existing displays */
SDL_DFB_FREE(dispdata);
SDL_DFB_RELEASE(layer);
return;
}
void DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
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));
SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb,
EnumModesCallback, &data));
for (i = 0; i < data.nummodes; ++i) {
mode = data.modelist[i];
mode.format = SDL_PIXELFORMAT_ARGB8888;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_RGB888;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_RGB24;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_RGB565;
CheckSetDisplayMode(_this, display, dispdata, &mode);
mode.format = SDL_PIXELFORMAT_INDEX8;
CheckSetDisplayMode(_this, display, dispdata, &mode);
}
SDL_DFB_FREE(data.modelist);
error:
return;
}
int DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
/*
* FIXME: video mode switch is currently broken for 1.2.0
*
*/
SDL_DFB_DEVICEDATA(_this);
DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
DFBDisplayLayerConfig config, rconfig;
DFBDisplayLayerConfigFlags fail = 0;
SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
DLSCL_ADMINISTRATIVE));
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;
config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
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 &
(DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_OPTIONS)) {
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));
#if (DFB_VERSION_ATLEAST(1,2,0))
/* Need to call this twice ! */
SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
#endif
/* Double check */
SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
SDL_DFB_CHECKERR(data->
layer->SetCooperativeLevel(data->layer, DLSCL_SHARED));
if ((config.width != rconfig.width) || (config.height != rconfig.height)
|| ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
&& (config.pixelformat != rconfig.pixelformat))) {
SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
mode->format);
return -1;
}
data->pixelformat = rconfig.pixelformat;
data->cw = config.width;
data->ch = config.height;
display->current_mode = *mode;
return 0;
error:
return -1;
}
void DirectFB_QuitModes(_THIS)
{
SDL_DisplayMode tmode;
int i;
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
SDL_GetDesktopDisplayMode(i, &tmode);
tmode.format = SDL_PIXELFORMAT_UNKNOWN;
DirectFB_SetDisplayMode(_this, display, &tmode);
SDL_GetDesktopDisplayMode(i, &tmode);
DirectFB_SetDisplayMode(_this, display, &tmode);
if (dispdata->layer) {
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));
}
SDL_DFB_RELEASE(dispdata->layer);
SDL_DFB_RELEASE(dispdata->vidlayer);
}
}
#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
/* vi: set ts=4 sw=4 expandtab: */