comparison src/video/directfb/SDL_DirectFB_modes.c @ 4636:b196d2758026

Couriersud to Sam Hi Sam, 20100815_1.diff contains updates for the directfb driver: - more documentation, mainly on software OpenGL in README.directfb - Revised error handling leading to leaner code - Improved/fixed OpenGL handling of multiple contexts. - Made the built-in simple window manager handle OpenGL windows. - Rewrote pixelformat mapping - this was quite ugly before. Well, all software GL, but working :-)
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Aug 2010 09:04:55 -0700
parents f7b03b6838cb
children 164f20ba08eb
comparison
equal deleted inserted replaced
4635:0a07d002f10b 4636:b196d2758026
38 { 38 {
39 int nummodes; 39 int nummodes;
40 SDL_DisplayMode *modelist; 40 SDL_DisplayMode *modelist;
41 }; 41 };
42 42
43 static int 43 static const struct {
44 DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat, Uint32 * fmt) 44 DFBSurfacePixelFormat dfb;
45 { 45 Uint32 sdl;
46 switch (pixelformat) { 46 } pixelformat_tab[] =
47 case DSPF_ALUT44: 47 {
48 *fmt = SDL_PIXELFORMAT_INDEX4LSB; 48 { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 }, /* 8 bit LUT (8 bit color and alpha lookup from palette) */
49 break; 49 { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 }, /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
50 case DSPF_LUT8: 50 { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 }, /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
51 *fmt = SDL_PIXELFORMAT_INDEX8; 51 { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 }, /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
52 break; 52 { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 }, /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
53 case DSPF_RGB332: 53 { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 }, /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
54 *fmt = SDL_PIXELFORMAT_RGB332; 54 { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 }, /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
55 break; 55 { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 }, /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
56 case DSPF_ARGB4444: 56 { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 }, /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
57 *fmt = SDL_PIXELFORMAT_ARGB4444; 57 { DSPF_YV12, SDL_PIXELFORMAT_YV12 }, /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
58 break; 58 { DSPF_I420,SDL_PIXELFORMAT_IYUV }, /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
59 case SDL_PIXELFORMAT_ARGB1555: 59 { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
60 *fmt = SDL_PIXELFORMAT_ARGB1555; 60 { DSPF_UYVY, SDL_PIXELFORMAT_UYVY }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
61 break; 61 { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 }, /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
62 case DSPF_RGB16: 62
63 *fmt = SDL_PIXELFORMAT_RGB565; 63 #if (DFB_VERSION_ATLEAST(1,2,0))
64 break; 64 { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 }, /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
65 case DSPF_RGB24: 65 #else
66 *fmt = SDL_PIXELFORMAT_RGB24; 66 { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
67 break; 67 #endif
68 case DSPF_RGB32: 68
69 *fmt = SDL_PIXELFORMAT_RGB888; 69 /* Pfff ... nonmatching formats follow */
70 break; 70
71 case DSPF_ARGB: 71 { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN }, /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
72 *fmt = SDL_PIXELFORMAT_ARGB8888; 72 { DSPF_A8, SDL_PIXELFORMAT_UNKNOWN }, /* 8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
73 break; 73 { DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN }, /* 32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
74 case DSPF_YV12: 74 { DSPF_A1, SDL_PIXELFORMAT_UNKNOWN }, /* 1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
75 *fmt = SDL_PIXELFORMAT_YV12; 75 { DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN }, /* 12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
76 break; /* Planar mode: Y + V + U (3 planes) */ 76 { DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
77 case DSPF_I420: 77 { DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
78 *fmt = SDL_PIXELFORMAT_IYUV; 78 { DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN }, /* 12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
79 break; /* Planar mode: Y + U + V (3 planes) */ 79 { DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN }, /* 32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
80 case DSPF_YUY2: 80 { DSPF_A4, SDL_PIXELFORMAT_UNKNOWN }, /* 4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
81 *fmt = SDL_PIXELFORMAT_YUY2; 81 { DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN }, /* 1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
82 break; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ 82 { DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN }, /* 6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
83 case DSPF_UYVY: 83 { DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN }, /* 6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
84 *fmt = SDL_PIXELFORMAT_UYVY; 84 { DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN }, /* 2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
85 break; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ 85
86 default: 86 #if (DFB_VERSION_ATLEAST(1,3,0))
87 return -1; 87 { DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
88 } 88 #endif
89 return 0; 89
90 #if (DFB_VERSION_ATLEAST(1,4,0))
91 { DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
92 { DSPF_YUV444P, SDL_PIXELFORMAT_UNKNOWN }, /* 24 bit full YUV planar (8 bit Y plane followed by an 8 bit Cb and an 8 bit Cr plane) */
93 { DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN }, /* 24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
94 { DSPF_AVYU, SDL_PIXELFORMAT_UNKNOWN }, /* 32 bit AVYU 4:4:4 (4 byte, alpha 8@24, Cr 8@16, Y 8@8, Cb 8@0) */
95 { DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN }, /* 24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0) */
96 #endif
97
98 { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
99 { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
100 { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB },
101 { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
102 { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
103 { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
104 { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
105 { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
106 { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
107 { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
108 { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
109 { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
110 { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
111 { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU }, /**< Packed mode: Y0+V0+Y1+U0 (1 pla */
112 };
113
114 static Uint32
115 DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
116 {
117 int i;
118
119 for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
120 if (pixelformat_tab[i].dfb == pixelformat)
121 {
122 return pixelformat_tab[i].sdl;
123 }
124 return SDL_PIXELFORMAT_UNKNOWN;
90 } 125 }
91 126
92 static DFBSurfacePixelFormat 127 static DFBSurfacePixelFormat
93 SDLToDFBPixelFormat(Uint32 format) 128 SDLToDFBPixelFormat(Uint32 format)
94 { 129 {
95 switch (format) { 130 int i;
96 case SDL_PIXELFORMAT_INDEX4LSB: 131
97 return DSPF_ALUT44; 132 for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
98 case SDL_PIXELFORMAT_INDEX8: 133 if (pixelformat_tab[i].sdl == format)
99 return DSPF_LUT8; 134 {
100 case SDL_PIXELFORMAT_RGB332: 135 return pixelformat_tab[i].dfb;
101 return DSPF_RGB332; 136 }
102 case SDL_PIXELFORMAT_RGB555: 137 return DSPF_UNKNOWN;
103 return DSPF_ARGB1555;
104 case SDL_PIXELFORMAT_ARGB4444:
105 return DSPF_ARGB4444;
106 case SDL_PIXELFORMAT_ARGB1555:
107 return DSPF_ARGB1555;
108 case SDL_PIXELFORMAT_RGB565:
109 return DSPF_RGB16;
110 case SDL_PIXELFORMAT_RGB24:
111 return DSPF_RGB24;
112 case SDL_PIXELFORMAT_RGB888:
113 return DSPF_RGB32;
114 case SDL_PIXELFORMAT_ARGB8888:
115 return DSPF_ARGB;
116 case SDL_PIXELFORMAT_YV12:
117 return DSPF_YV12; /* Planar mode: Y + V + U (3 planes) */
118 case SDL_PIXELFORMAT_IYUV:
119 return DSPF_I420; /* Planar mode: Y + U + V (3 planes) */
120 case SDL_PIXELFORMAT_YUY2:
121 return DSPF_YUY2; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
122 case SDL_PIXELFORMAT_UYVY:
123 return DSPF_UYVY; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
124 case SDL_PIXELFORMAT_YVYU:
125 return DSPF_UNKNOWN; /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
126 case SDL_PIXELFORMAT_INDEX1LSB:
127 return DSPF_UNKNOWN;
128 case SDL_PIXELFORMAT_INDEX1MSB:
129 return DSPF_UNKNOWN;
130 case SDL_PIXELFORMAT_INDEX4MSB:
131 return DSPF_UNKNOWN;
132 case SDL_PIXELFORMAT_RGB444:
133 return DSPF_UNKNOWN;
134 case SDL_PIXELFORMAT_BGR24:
135 return DSPF_UNKNOWN;
136 case SDL_PIXELFORMAT_BGR888:
137 return DSPF_UNKNOWN;
138 case SDL_PIXELFORMAT_RGBA8888:
139 return DSPF_UNKNOWN;
140 case SDL_PIXELFORMAT_ABGR8888:
141 return DSPF_UNKNOWN;
142 case SDL_PIXELFORMAT_BGRA8888:
143 return DSPF_UNKNOWN;
144 case SDL_PIXELFORMAT_ARGB2101010:
145 return DSPF_UNKNOWN;
146 default:
147 return DSPF_UNKNOWN;
148 }
149 } 138 }
150 139
151 static DFBEnumerationResult 140 static DFBEnumerationResult
152 EnumModesCallback(int width, int height, int bpp, void *data) 141 EnumModesCallback(int width, int height, int bpp, void *data)
153 { 142 {
162 151
163 if (modedata->nummodes < DFB_MAX_MODES) { 152 if (modedata->nummodes < DFB_MAX_MODES) {
164 modedata->modelist[modedata->nummodes++] = mode; 153 modedata->modelist[modedata->nummodes++] = mode;
165 } 154 }
166 155
167 SDL_DFB_DEBUG("w %d h %d bpp %d\n", width, height, bpp);
168 return DFENUM_OK; 156 return DFENUM_OK;
169 } 157 }
170 158
171 static DFBEnumerationResult 159 static DFBEnumerationResult
172 cbScreens(DFBScreenID screen_id, DFBScreenDescription desc, 160 cbScreens(DFBScreenID screen_id, DFBScreenDescription desc,
200 CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode) 188 CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
201 { 189 {
202 SDL_DFB_DEVICEDATA(_this); 190 SDL_DFB_DEVICEDATA(_this);
203 DFBDisplayLayerConfig config; 191 DFBDisplayLayerConfig config;
204 DFBDisplayLayerConfigFlags failed; 192 DFBDisplayLayerConfigFlags failed;
205 int ret;
206 193
207 SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, 194 SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
208 DLSCL_ADMINISTRATIVE)); 195 DLSCL_ADMINISTRATIVE));
209 config.width = mode->w; 196 config.width = mode->w;
210 config.height = mode->h; 197 config.height = mode->h;
219 SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, 206 SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
220 DLSCL_SHARED)); 207 DLSCL_SHARED));
221 if (failed == 0) 208 if (failed == 0)
222 SDL_AddDisplayMode(display, mode); 209 SDL_AddDisplayMode(display, mode);
223 else 210 else
224 SDL_DFB_DEBUG("Mode %d x %d not available: %x\n", mode->w, 211 SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
225 mode->h, failed); 212 mode->h, failed);
226 213
227 return; 214 return;
228 error: 215 error:
229 return; 216 return;
293 if (devdata->use_yuv_underlays) { 280 if (devdata->use_yuv_underlays) {
294 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_OPTIONS; 281 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_OPTIONS;
295 dlc.pixelformat = DSPF_ARGB; 282 dlc.pixelformat = DSPF_ARGB;
296 dlc.options = DLOP_ALPHACHANNEL; 283 dlc.options = DLOP_ALPHACHANNEL;
297 284
298 ret = layer->SetConfiguration(layer, &dlc); 285 ret = SDL_DFB_CHECK(layer->SetConfiguration(layer, &dlc));
299 if (ret) { 286 if (ret != DFB_OK) {
300 /* try AiRGB if the previous failed */ 287 /* try AiRGB if the previous failed */
301 dlc.pixelformat = DSPF_AiRGB; 288 dlc.pixelformat = DSPF_AiRGB;
302 ret = layer->SetConfiguration(layer, &dlc); 289 SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
303 } 290 }
304 } 291 }
305 292
306 /* Query layer configuration to determine the current mode and pixelformat */ 293 /* Query layer configuration to determine the current mode and pixelformat */
307 dlc.flags = DLCONF_ALL; 294 dlc.flags = DLCONF_ALL;
308 layer->GetConfiguration(layer, &dlc); 295 SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
309 296
310 if (DFBToSDLPixelFormat(dlc.pixelformat, &mode.format) != 0) { 297 mode.format = DFBToSDLPixelFormat(dlc.pixelformat);
298
299 if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
311 SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat); 300 SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
312 goto error; 301 goto error;
313 } 302 }
314 303
315 mode.w = dlc.width; 304 mode.w = dlc.width;
361 SDL_DFB_DEVICEDATA(_this); 350 SDL_DFB_DEVICEDATA(_this);
362 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; 351 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
363 SDL_DisplayMode mode; 352 SDL_DisplayMode mode;
364 struct modes_callback_t data; 353 struct modes_callback_t data;
365 int i; 354 int i;
366 int ret;
367 355
368 data.nummodes = 0; 356 data.nummodes = 0;
369 /* Enumerate the available fullscreen modes */ 357 /* Enumerate the available fullscreen modes */
370 SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode)); 358 SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode));
371 SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb, 359 SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb,
401 389
402 SDL_DFB_DEVICEDATA(_this); 390 SDL_DFB_DEVICEDATA(_this);
403 DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata; 391 DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
404 DFBDisplayLayerConfig config, rconfig; 392 DFBDisplayLayerConfig config, rconfig;
405 DFBDisplayLayerConfigFlags fail = 0; 393 DFBDisplayLayerConfigFlags fail = 0;
406 DFBResult ret;
407 394
408 SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer, 395 SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
409 DLSCL_ADMINISTRATIVE)); 396 DLSCL_ADMINISTRATIVE));
410 397
411 SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config)); 398 SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
467 void 454 void
468 DirectFB_QuitModes(_THIS) 455 DirectFB_QuitModes(_THIS)
469 { 456 {
470 //DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata; 457 //DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
471 SDL_DisplayMode tmode; 458 SDL_DisplayMode tmode;
472 DFBResult ret;
473 int i; 459 int i;
474 460
475 for (i = 0; i < _this->num_displays; ++i) { 461 for (i = 0; i < _this->num_displays; ++i) {
476 SDL_VideoDisplay *display = &_this->displays[i]; 462 SDL_VideoDisplay *display = &_this->displays[i];
477 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; 463 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;