comparison src/video/directfb/SDL_DirectFB_video.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
50 int unused; 50 int unused;
51 }; 51 };
52 52
53 53
54 /* Initialization/Query functions */ 54 /* Initialization/Query functions */
55 static int DirectFB_VideoInit (_THIS, SDL_PixelFormat * vformat); 55 static int DirectFB_VideoInit(_THIS, SDL_PixelFormat * vformat);
56 static SDL_Rect **DirectFB_ListModes (_THIS, SDL_PixelFormat * format, 56 static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat * format,
57 Uint32 flags); 57 Uint32 flags);
58 static SDL_Surface *DirectFB_SetVideoMode (_THIS, SDL_Surface * current, 58 static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface * current,
59 int width, int height, int bpp, 59 int width, int height, int bpp,
60 Uint32 flags); 60 Uint32 flags);
61 static int DirectFB_SetColors (_THIS, int firstcolor, int ncolors, 61 static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors,
62 SDL_Color * colors); 62 SDL_Color * colors);
63 static void DirectFB_VideoQuit (_THIS); 63 static void DirectFB_VideoQuit(_THIS);
64 64
65 /* Hardware surface functions */ 65 /* Hardware surface functions */
66 static int DirectFB_AllocHWSurface (_THIS, SDL_Surface * surface); 66 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface * surface);
67 static int DirectFB_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, 67 static int DirectFB_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
68 Uint32 color); 68 Uint32 color);
69 static int DirectFB_LockHWSurface (_THIS, SDL_Surface * surface); 69 static int DirectFB_LockHWSurface(_THIS, SDL_Surface * surface);
70 static void DirectFB_UnlockHWSurface (_THIS, SDL_Surface * surface); 70 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface * surface);
71 static void DirectFB_FreeHWSurface (_THIS, SDL_Surface * surface); 71 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface * surface);
72 static int DirectFB_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst); 72 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
73 static int DirectFB_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, 73 static int DirectFB_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
74 SDL_Surface * dst, SDL_Rect * dstrect); 74 SDL_Surface * dst, SDL_Rect * dstrect);
75 static int DirectFB_SetHWColorKey (_THIS, SDL_Surface * surface, Uint32 key); 75 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key);
76 static int DirectFB_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha); 76 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha);
77 static int DirectFB_FlipHWSurface (_THIS, SDL_Surface * surface); 77 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface * surface);
78 static int DirectFB_ShowWMCursor (_THIS, WMcursor * cursor); 78 static int DirectFB_ShowWMCursor(_THIS, WMcursor * cursor);
79 79
80 /* Various screen update functions available */ 80 /* Various screen update functions available */
81 static void DirectFB_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); 81 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
82 static void DirectFB_WindowedUpdate (_THIS, int numrects, SDL_Rect * rects); 82 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect * rects);
83 83
84 /* This is the rect EnumModes2 uses */ 84 /* This is the rect EnumModes2 uses */
85 struct DirectFBEnumRect 85 struct DirectFBEnumRect
86 { 86 {
87 SDL_Rect r; 87 SDL_Rect r;
92 92
93 93
94 /* DirectFB driver bootstrap functions */ 94 /* DirectFB driver bootstrap functions */
95 95
96 static int 96 static int
97 DirectFB_Available (void) 97 DirectFB_Available(void)
98 { 98 {
99 return 1; 99 return 1;
100 } 100 }
101 101
102 static void 102 static void
103 DirectFB_DeleteDevice (SDL_VideoDevice * device) 103 DirectFB_DeleteDevice(SDL_VideoDevice * device)
104 { 104 {
105 SDL_free (device->hidden); 105 SDL_free(device->hidden);
106 SDL_free (device); 106 SDL_free(device);
107 } 107 }
108 108
109 static SDL_VideoDevice * 109 static SDL_VideoDevice *
110 DirectFB_CreateDevice (int devindex) 110 DirectFB_CreateDevice(int devindex)
111 { 111 {
112 SDL_VideoDevice *device; 112 SDL_VideoDevice *device;
113 113
114 /* Initialize all variables that we clean on shutdown */ 114 /* Initialize all variables that we clean on shutdown */
115 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 115 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
116 if (device) { 116 if (device) {
117 SDL_memset (device, 0, (sizeof *device)); 117 SDL_memset(device, 0, (sizeof *device));
118 device->hidden = (struct SDL_PrivateVideoData *) 118 device->hidden = (struct SDL_PrivateVideoData *)
119 malloc (sizeof (*device->hidden)); 119 malloc(sizeof(*device->hidden));
120 } 120 }
121 if (device == NULL || device->hidden == NULL) { 121 if (device == NULL || device->hidden == NULL) {
122 SDL_OutOfMemory (); 122 SDL_OutOfMemory();
123 if (device) { 123 if (device) {
124 free (device); 124 free(device);
125 } 125 }
126 return (0); 126 return (0);
127 } 127 }
128 SDL_memset (device->hidden, 0, sizeof (*device->hidden)); 128 SDL_memset(device->hidden, 0, sizeof(*device->hidden));
129 129
130 /* Set the function pointers */ 130 /* Set the function pointers */
131 device->VideoInit = DirectFB_VideoInit; 131 device->VideoInit = DirectFB_VideoInit;
132 device->ListModes = DirectFB_ListModes; 132 device->ListModes = DirectFB_ListModes;
133 device->SetVideoMode = DirectFB_SetVideoMode; 133 device->SetVideoMode = DirectFB_SetVideoMode;
162 "directfb", "DirectFB", 162 "directfb", "DirectFB",
163 DirectFB_Available, DirectFB_CreateDevice 163 DirectFB_Available, DirectFB_CreateDevice
164 }; 164 };
165 165
166 static DFBSurfacePixelFormat 166 static DFBSurfacePixelFormat
167 GetFormatForBpp (int bpp, IDirectFBDisplayLayer * layer) 167 GetFormatForBpp(int bpp, IDirectFBDisplayLayer * layer)
168 { 168 {
169 DFBDisplayLayerConfig dlc; 169 DFBDisplayLayerConfig dlc;
170 int bytes = (bpp + 7) / 8; 170 int bytes = (bpp + 7) / 8;
171 171
172 layer->GetConfiguration (layer, &dlc); 172 layer->GetConfiguration(layer, &dlc);
173 173
174 if (bytes == DFB_BYTES_PER_PIXEL (dlc.pixelformat) && bytes > 1) 174 if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1)
175 return dlc.pixelformat; 175 return dlc.pixelformat;
176 176
177 switch (bytes) { 177 switch (bytes) {
178 case 1: 178 case 1:
179 return DSPF_LUT8; 179 return DSPF_LUT8;
187 187
188 return DSPF_UNKNOWN; 188 return DSPF_UNKNOWN;
189 } 189 }
190 190
191 static DFBEnumerationResult 191 static DFBEnumerationResult
192 EnumModesCallback (int width, int height, int bpp, void *data) 192 EnumModesCallback(int width, int height, int bpp, void *data)
193 { 193 {
194 SDL_VideoDevice *this = (SDL_VideoDevice *) data; 194 SDL_VideoDevice *this = (SDL_VideoDevice *) data;
195 struct DirectFBEnumRect *enumrect; 195 struct DirectFBEnumRect *enumrect;
196 196
197 HIDDEN->nummodes++; 197 HIDDEN->nummodes++;
198 198
199 if (enumlist && enumlist->r.w == width && enumlist->r.h == height) 199 if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
200 return DFENUM_OK; 200 return DFENUM_OK;
201 201
202 enumrect = SDL_calloc (1, sizeof (struct DirectFBEnumRect)); 202 enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
203 if (!enumrect) { 203 if (!enumrect) {
204 SDL_OutOfMemory (); 204 SDL_OutOfMemory();
205 return DFENUM_CANCEL; 205 return DFENUM_CANCEL;
206 } 206 }
207 207
208 enumrect->r.w = (Uint16) width; 208 enumrect->r.w = (Uint16) width;
209 enumrect->r.h = (Uint16) height; 209 enumrect->r.h = (Uint16) height;
219 IDirectFBSurface *surface; 219 IDirectFBSurface *surface;
220 IDirectFBPalette *palette; 220 IDirectFBPalette *palette;
221 }; 221 };
222 222
223 void 223 void
224 SetDirectFBerror (const char *function, DFBResult code) 224 SetDirectFBerror(const char *function, DFBResult code)
225 { 225 {
226 const char *error = DirectFBErrorString (code); 226 const char *error = DirectFBErrorString(code);
227 227
228 if (error) 228 if (error)
229 SDL_SetError ("%s: %s", function, error); 229 SDL_SetError("%s: %s", function, error);
230 else 230 else
231 SDL_SetError ("Unknown error code from %s", function); 231 SDL_SetError("Unknown error code from %s", function);
232 } 232 }
233 233
234 static DFBSurfacePixelFormat 234 static DFBSurfacePixelFormat
235 SDLToDFBPixelFormat (SDL_PixelFormat * format) 235 SDLToDFBPixelFormat(SDL_PixelFormat * format)
236 { 236 {
237 if (format->Rmask && format->Gmask && format->Bmask) { 237 if (format->Rmask && format->Gmask && format->Bmask) {
238 switch (format->BitsPerPixel) { 238 switch (format->BitsPerPixel) {
239 case 8: 239 case 8:
240 return DSPF_LUT8; 240 return DSPF_LUT8;
284 284
285 return DSPF_UNKNOWN; 285 return DSPF_UNKNOWN;
286 } 286 }
287 287
288 static SDL_Palette * 288 static SDL_Palette *
289 AllocatePalette (int size) 289 AllocatePalette(int size)
290 { 290 {
291 SDL_Palette *palette; 291 SDL_Palette *palette;
292 SDL_Color *colors; 292 SDL_Color *colors;
293 293
294 palette = SDL_calloc (1, sizeof (SDL_Palette)); 294 palette = SDL_calloc(1, sizeof(SDL_Palette));
295 if (!palette) { 295 if (!palette) {
296 SDL_OutOfMemory (); 296 SDL_OutOfMemory();
297 return NULL; 297 return NULL;
298 } 298 }
299 299
300 colors = SDL_calloc (size, sizeof (SDL_Color)); 300 colors = SDL_calloc(size, sizeof(SDL_Color));
301 if (!colors) { 301 if (!colors) {
302 SDL_OutOfMemory (); 302 SDL_OutOfMemory();
303 return NULL; 303 return NULL;
304 } 304 }
305 305
306 palette->ncolors = size; 306 palette->ncolors = size;
307 palette->colors = colors; 307 palette->colors = colors;
308 308
309 return palette; 309 return palette;
310 } 310 }
311 311
312 static int 312 static int
313 DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, 313 DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat,
314 SDL_PixelFormat * format) 314 SDL_PixelFormat * format)
315 { 315 {
316 format->Amask = format->Rmask = format->Gmask = format->Bmask = 0; 316 format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
317 format->BitsPerPixel = format->BytesPerPixel = 0; 317 format->BitsPerPixel = format->BytesPerPixel = 0;
318 318
319 switch (pixelformat) { 319 switch (pixelformat) {
347 format->Rmask = 0x000000FF; 347 format->Rmask = 0x000000FF;
348 format->Gmask = 0x000000FF; 348 format->Gmask = 0x000000FF;
349 format->Bmask = 0x000000FF; 349 format->Bmask = 0x000000FF;
350 350
351 if (!format->palette) 351 if (!format->palette)
352 format->palette = AllocatePalette (256); 352 format->palette = AllocatePalette(256);
353 break; 353 break;
354 354
355 default: 355 default:
356 fprintf (stderr, 356 fprintf(stderr,
357 "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n", 357 "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n",
358 pixelformat); 358 pixelformat);
359 return -1; 359 return -1;
360 } 360 }
361 361
362 format->BitsPerPixel = DFB_BYTES_PER_PIXEL (pixelformat) * 8; 362 format->BitsPerPixel = DFB_BYTES_PER_PIXEL(pixelformat) * 8;
363 format->BytesPerPixel = DFB_BYTES_PER_PIXEL (pixelformat); 363 format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat);
364 364
365 return 0; 365 return 0;
366 } 366 }
367 367
368 368
369 int 369 int
370 DirectFB_VideoInit (_THIS, SDL_PixelFormat * vformat) 370 DirectFB_VideoInit(_THIS, SDL_PixelFormat * vformat)
371 { 371 {
372 int i; 372 int i;
373 DFBResult ret; 373 DFBResult ret;
374 #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23) 374 #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
375 DFBCardCapabilities caps; 375 DFBCardCapabilities caps;
384 384
385 HIDDEN->c2layer = NULL, HIDDEN->c2frame = NULL; 385 HIDDEN->c2layer = NULL, HIDDEN->c2frame = NULL;
386 HIDDEN->enable_mga_crtc2 = 0; 386 HIDDEN->enable_mga_crtc2 = 0;
387 HIDDEN->mga_crtc2_stretch_overscan = 1; 387 HIDDEN->mga_crtc2_stretch_overscan = 1;
388 388
389 ret = DirectFBInit (NULL, NULL); 389 ret = DirectFBInit(NULL, NULL);
390 if (ret) { 390 if (ret) {
391 SetDirectFBerror ("DirectFBInit", ret); 391 SetDirectFBerror("DirectFBInit", ret);
392 goto error; 392 goto error;
393 } 393 }
394 394
395 ret = DirectFBCreate (&dfb); 395 ret = DirectFBCreate(&dfb);
396 if (ret) { 396 if (ret) {
397 SetDirectFBerror ("DirectFBCreate", ret); 397 SetDirectFBerror("DirectFBCreate", ret);
398 goto error; 398 goto error;
399 } 399 }
400 400
401 ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer); 401 ret = dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer);
402 if (ret) { 402 if (ret) {
403 SetDirectFBerror ("dfb->GetDisplayLayer", ret); 403 SetDirectFBerror("dfb->GetDisplayLayer", ret);
404 goto error; 404 goto error;
405 } 405 }
406 406
407 ret = dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events); 407 ret = dfb->CreateInputEventBuffer(dfb, DICAPS_ALL, DFB_FALSE, &events);
408 if (ret) { 408 if (ret) {
409 SetDirectFBerror ("dfb->CreateEventBuffer", ret); 409 SetDirectFBerror("dfb->CreateEventBuffer", ret);
410 goto error; 410 goto error;
411 } 411 }
412 412
413 layer->EnableCursor (layer, 1); 413 layer->EnableCursor(layer, 1);
414 414
415 /* Query layer configuration to determine the current mode and pixelformat */ 415 /* Query layer configuration to determine the current mode and pixelformat */
416 layer->GetConfiguration (layer, &dlc); 416 layer->GetConfiguration(layer, &dlc);
417 417
418 /* If current format is not supported use LUT8 as the default */ 418 /* If current format is not supported use LUT8 as the default */
419 if (DFBToSDLPixelFormat (dlc.pixelformat, vformat)) 419 if (DFBToSDLPixelFormat(dlc.pixelformat, vformat))
420 DFBToSDLPixelFormat (DSPF_LUT8, vformat); 420 DFBToSDLPixelFormat(DSPF_LUT8, vformat);
421 421
422 /* Enumerate the available fullscreen modes */ 422 /* Enumerate the available fullscreen modes */
423 ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this); 423 ret = dfb->EnumVideoModes(dfb, EnumModesCallback, this);
424 if (ret) { 424 if (ret) {
425 SetDirectFBerror ("dfb->EnumVideoModes", ret); 425 SetDirectFBerror("dfb->EnumVideoModes", ret);
426 goto error; 426 goto error;
427 } 427 }
428 428
429 HIDDEN->modelist = SDL_calloc (HIDDEN->nummodes + 1, sizeof (SDL_Rect *)); 429 HIDDEN->modelist = SDL_calloc(HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
430 if (!HIDDEN->modelist) { 430 if (!HIDDEN->modelist) {
431 SDL_OutOfMemory (); 431 SDL_OutOfMemory();
432 goto error; 432 goto error;
433 } 433 }
434 434
435 for (i = 0, rect = enumlist; rect; ++i, rect = rect->next) { 435 for (i = 0, rect = enumlist; rect; ++i, rect = rect->next) {
436 HIDDEN->modelist[i] = &rect->r; 436 HIDDEN->modelist[i] = &rect->r;
439 HIDDEN->modelist[i] = NULL; 439 HIDDEN->modelist[i] = NULL;
440 440
441 441
442 /* Query card capabilities to get the video memory size */ 442 /* Query card capabilities to get the video memory size */
443 #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23) 443 #if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
444 dfb->GetCardCapabilities (dfb, &caps); 444 dfb->GetCardCapabilities(dfb, &caps);
445 #else 445 #else
446 dfb->GetDeviceDescription (dfb, &caps); 446 dfb->GetDeviceDescription(dfb, &caps);
447 #endif 447 #endif
448 448
449 this->info.wm_available = 1; 449 this->info.wm_available = 1;
450 this->info.hw_available = 1; 450 this->info.hw_available = 1;
451 this->info.blit_hw = 1; 451 this->info.blit_hw = 1;
457 HIDDEN->initialized = 1; 457 HIDDEN->initialized = 1;
458 HIDDEN->dfb = dfb; 458 HIDDEN->dfb = dfb;
459 HIDDEN->layer = layer; 459 HIDDEN->layer = layer;
460 HIDDEN->eventbuffer = events; 460 HIDDEN->eventbuffer = events;
461 461
462 if (SDL_getenv ("SDL_DIRECTFB_MGA_CRTC2") != NULL) 462 if (SDL_getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
463 HIDDEN->enable_mga_crtc2 = 1; 463 HIDDEN->enable_mga_crtc2 = 1;
464 464
465 if (HIDDEN->enable_mga_crtc2) { 465 if (HIDDEN->enable_mga_crtc2) {
466 DFBDisplayLayerConfig dlc; 466 DFBDisplayLayerConfig dlc;
467 DFBDisplayLayerConfigFlags failed; 467 DFBDisplayLayerConfigFlags failed;
468 468
469 ret = dfb->GetDisplayLayer (dfb, 2, &HIDDEN->c2layer); 469 ret = dfb->GetDisplayLayer(dfb, 2, &HIDDEN->c2layer);
470 if (ret) { 470 if (ret) {
471 SetDirectFBerror ("dfb->GetDisplayLayer(CRTC2)", ret); 471 SetDirectFBerror("dfb->GetDisplayLayer(CRTC2)", ret);
472 goto error; 472 goto error;
473 } 473 }
474 474
475 ret = 475 ret =
476 HIDDEN->layer->SetCooperativeLevel (HIDDEN->layer, 476 HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer,
477 DLSCL_EXCLUSIVE); 477 DLSCL_EXCLUSIVE);
478 if (ret) { 478 if (ret) {
479 SetDirectFBerror 479 SetDirectFBerror
480 ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret); 480 ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
481 goto error; 481 goto error;
482 } 482 }
483 483
484 ret = 484 ret =
485 HIDDEN->c2layer->SetCooperativeLevel (HIDDEN->c2layer, 485 HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer,
486 DLSCL_EXCLUSIVE); 486 DLSCL_EXCLUSIVE);
487 if (ret) { 487 if (ret) {
488 SetDirectFBerror 488 SetDirectFBerror
489 ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret); 489 ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
490 goto error; 490 goto error;
491 } 491 }
492 492
493 HIDDEN->c2layer->SetOpacity (HIDDEN->c2layer, 0x0); 493 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0);
494 494
495 /* Init the surface here as it got a fixed size */ 495 /* Init the surface here as it got a fixed size */
496 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE; 496 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE;
497 dlc.buffermode = DLBM_BACKVIDEO; 497 dlc.buffermode = DLBM_BACKVIDEO;
498 dlc.pixelformat = DSPF_RGB32; 498 dlc.pixelformat = DSPF_RGB32;
499 499
500 ret = 500 ret =
501 HIDDEN->c2layer->TestConfiguration (HIDDEN->c2layer, &dlc, 501 HIDDEN->c2layer->TestConfiguration(HIDDEN->c2layer, &dlc,
502 &failed); 502 &failed);
503 if (ret) { 503 if (ret) {
504 SetDirectFBerror ("c2layer->TestConfiguration", ret); 504 SetDirectFBerror("c2layer->TestConfiguration", ret);
505 goto error; 505 goto error;
506 } 506 }
507 507
508 ret = HIDDEN->c2layer->SetConfiguration (HIDDEN->c2layer, &dlc); 508 ret = HIDDEN->c2layer->SetConfiguration(HIDDEN->c2layer, &dlc);
509 if (ret) { 509 if (ret) {
510 SetDirectFBerror ("c2layer->SetConfiguration", ret); 510 SetDirectFBerror("c2layer->SetConfiguration", ret);
511 goto error; 511 goto error;
512 } 512 }
513 513
514 ret = HIDDEN->c2layer->GetSurface (HIDDEN->c2layer, &HIDDEN->c2frame); 514 ret = HIDDEN->c2layer->GetSurface(HIDDEN->c2layer, &HIDDEN->c2frame);
515 if (ret) { 515 if (ret) {
516 SetDirectFBerror ("c2layer->GetSurface", ret); 516 SetDirectFBerror("c2layer->GetSurface", ret);
517 goto error; 517 goto error;
518 } 518 }
519 519
520 HIDDEN->c2framesize.x = 0; 520 HIDDEN->c2framesize.x = 0;
521 HIDDEN->c2framesize.y = 0; 521 HIDDEN->c2framesize.y = 0;
522 HIDDEN->c2frame->GetSize (HIDDEN->c2frame, &HIDDEN->c2framesize.w, 522 HIDDEN->c2frame->GetSize(HIDDEN->c2frame, &HIDDEN->c2framesize.w,
523 &HIDDEN->c2framesize.h); 523 &HIDDEN->c2framesize.h);
524 524
525 HIDDEN->c2frame->SetBlittingFlags (HIDDEN->c2frame, DSBLIT_NOFX); 525 HIDDEN->c2frame->SetBlittingFlags(HIDDEN->c2frame, DSBLIT_NOFX);
526 HIDDEN->c2frame->SetColor (HIDDEN->c2frame, 0, 0, 0, 0xff); 526 HIDDEN->c2frame->SetColor(HIDDEN->c2frame, 0, 0, 0, 0xff);
527 527
528 /* Clear CRTC2 */ 528 /* Clear CRTC2 */
529 HIDDEN->c2frame->Clear (HIDDEN->c2frame, 0, 0, 0, 0xff); 529 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
530 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, 0); 530 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0);
531 HIDDEN->c2frame->Clear (HIDDEN->c2frame, 0, 0, 0, 0xff); 531 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
532 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, 0); 532 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0);
533 HIDDEN->c2frame->Clear (HIDDEN->c2frame, 0, 0, 0, 0xff); 533 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
534 534
535 HIDDEN->c2layer->SetOpacity (HIDDEN->c2layer, 0xFF); 535 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF);
536 536
537 /* Check if overscan is possibly set */ 537 /* Check if overscan is possibly set */
538 if (SDL_getenv ("SDL_DIRECTFB_MGA_OVERSCAN") != NULL) { 538 if (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL) {
539 float overscan = 0; 539 float overscan = 0;
540 if (SDL_sscanf 540 if (SDL_sscanf
541 (SDL_getenv ("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", 541 (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f",
542 &overscan) == 1) 542 &overscan) == 1)
543 if (overscan > 0 && overscan < 2) 543 if (overscan > 0 && overscan < 2)
544 HIDDEN->mga_crtc2_stretch_overscan = overscan; 544 HIDDEN->mga_crtc2_stretch_overscan = overscan;
545 } 545 }
546 #ifdef DIRECTFB_CRTC2_DEBUG 546 #ifdef DIRECTFB_CRTC2_DEBUG
547 printf ("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan); 547 printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
548 #endif 548 #endif
549 } 549 }
550 550
551 return 0; 551 return 0;
552 552
553 error: 553 error:
554 if (events) 554 if (events)
555 events->Release (events); 555 events->Release(events);
556 556
557 if (HIDDEN->c2frame) 557 if (HIDDEN->c2frame)
558 HIDDEN->c2frame->Release (HIDDEN->c2frame); 558 HIDDEN->c2frame->Release(HIDDEN->c2frame);
559 559
560 if (HIDDEN->c2layer) 560 if (HIDDEN->c2layer)
561 HIDDEN->c2layer->Release (HIDDEN->c2layer); 561 HIDDEN->c2layer->Release(HIDDEN->c2layer);
562 562
563 if (layer) 563 if (layer)
564 layer->Release (layer); 564 layer->Release(layer);
565 565
566 if (dfb) 566 if (dfb)
567 dfb->Release (dfb); 567 dfb->Release(dfb);
568 568
569 return -1; 569 return -1;
570 } 570 }
571 571
572 static SDL_Rect ** 572 static SDL_Rect **
573 DirectFB_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 573 DirectFB_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
574 { 574 {
575 if (flags & SDL_FULLSCREEN) 575 if (flags & SDL_FULLSCREEN)
576 return HIDDEN->modelist; 576 return HIDDEN->modelist;
577 else if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN) 577 else if (SDLToDFBPixelFormat(format) != DSPF_UNKNOWN)
578 return (SDL_Rect **) - 1; 578 return (SDL_Rect **) - 1;
579 579
580 return NULL; 580 return NULL;
581 } 581 }
582 582
583 static SDL_Surface * 583 static SDL_Surface *
584 DirectFB_SetVideoMode (_THIS, SDL_Surface * current, int width, int height, 584 DirectFB_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
585 int bpp, Uint32 flags) 585 int bpp, Uint32 flags)
586 { 586 {
587 DFBResult ret; 587 DFBResult ret;
588 DFBSurfaceDescription dsc; 588 DFBSurfaceDescription dsc;
589 DFBSurfacePixelFormat pixelformat; 589 DFBSurfacePixelFormat pixelformat;
590 IDirectFBSurface *surface; 590 IDirectFBSurface *surface;
591 591
592 fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n", 592 fprintf(stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
593 width, height, bpp, flags); 593 width, height, bpp, flags);
594 594
595 flags |= SDL_FULLSCREEN; 595 flags |= SDL_FULLSCREEN;
596 596
597 /* Release previous primary surface */ 597 /* Release previous primary surface */
598 if (current->hwdata && current->hwdata->surface) { 598 if (current->hwdata && current->hwdata->surface) {
599 current->hwdata->surface->Release (current->hwdata->surface); 599 current->hwdata->surface->Release(current->hwdata->surface);
600 current->hwdata->surface = NULL; 600 current->hwdata->surface = NULL;
601 601
602 /* And its palette if present */ 602 /* And its palette if present */
603 if (current->hwdata->palette) { 603 if (current->hwdata->palette) {
604 current->hwdata->palette->Release (current->hwdata->palette); 604 current->hwdata->palette->Release(current->hwdata->palette);
605 current->hwdata->palette = NULL; 605 current->hwdata->palette = NULL;
606 } 606 }
607 } else if (!current->hwdata) { 607 } else if (!current->hwdata) {
608 /* Allocate the hardware acceleration data */ 608 /* Allocate the hardware acceleration data */
609 current->hwdata = 609 current->hwdata =
610 (struct private_hwdata *) SDL_calloc (1, 610 (struct private_hwdata *) SDL_calloc(1, sizeof(*current->hwdata));
611 sizeof (*current->hwdata));
612 if (!current->hwdata) { 611 if (!current->hwdata) {
613 SDL_OutOfMemory (); 612 SDL_OutOfMemory();
614 return NULL; 613 return NULL;
615 } 614 }
616 } 615 }
617 616
618 /* Set cooperative level depending on flag SDL_FULLSCREEN */ 617 /* Set cooperative level depending on flag SDL_FULLSCREEN */
619 if (flags & SDL_FULLSCREEN) { 618 if (flags & SDL_FULLSCREEN) {
620 ret = 619 ret = HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_FULLSCREEN);
621 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
622 if (ret && !HIDDEN->enable_mga_crtc2) { 620 if (ret && !HIDDEN->enable_mga_crtc2) {
623 DirectFBError ("dfb->SetCooperativeLevel", ret); 621 DirectFBError("dfb->SetCooperativeLevel", ret);
624 flags &= ~SDL_FULLSCREEN; 622 flags &= ~SDL_FULLSCREEN;
625 } 623 }
626 } else 624 } else
627 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); 625 HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_NORMAL);
628 626
629 /* Set video mode */ 627 /* Set video mode */
630 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); 628 ret = HIDDEN->dfb->SetVideoMode(HIDDEN->dfb, width, height, bpp);
631 if (ret) { 629 if (ret) {
632 if (flags & SDL_FULLSCREEN) { 630 if (flags & SDL_FULLSCREEN) {
633 flags &= ~SDL_FULLSCREEN; 631 flags &= ~SDL_FULLSCREEN;
634 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); 632 HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_NORMAL);
635 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); 633 ret = HIDDEN->dfb->SetVideoMode(HIDDEN->dfb, width, height, bpp);
636 } 634 }
637 635
638 if (ret) { 636 if (ret) {
639 SetDirectFBerror ("dfb->SetVideoMode", ret); 637 SetDirectFBerror("dfb->SetVideoMode", ret);
640 return NULL; 638 return NULL;
641 } 639 }
642 } 640 }
643 641
644 /* Create primary surface */ 642 /* Create primary surface */
645 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; 643 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
646 dsc.caps = 644 dsc.caps =
647 DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0); 645 DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
648 dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer); 646 dsc.pixelformat = GetFormatForBpp(bpp, HIDDEN->layer);
649 647
650 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); 648 ret = HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc, &surface);
651 if (ret && (flags & SDL_DOUBLEBUF)) { 649 if (ret && (flags & SDL_DOUBLEBUF)) {
652 /* Try without double buffering */ 650 /* Try without double buffering */
653 dsc.caps &= ~DSCAPS_FLIPPING; 651 dsc.caps &= ~DSCAPS_FLIPPING;
654 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); 652 ret = HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc, &surface);
655 } 653 }
656 if (ret) { 654 if (ret) {
657 SetDirectFBerror ("dfb->CreateSurface", ret); 655 SetDirectFBerror("dfb->CreateSurface", ret);
658 return NULL; 656 return NULL;
659 } 657 }
660 658
661 current->w = width; 659 current->w = width;
662 current->h = height; 660 current->h = height;
669 this->UpdateRects = DirectFB_WindowedUpdate; 667 this->UpdateRects = DirectFB_WindowedUpdate;
670 668
671 if (dsc.caps & DSCAPS_FLIPPING) 669 if (dsc.caps & DSCAPS_FLIPPING)
672 current->flags |= SDL_DOUBLEBUF; 670 current->flags |= SDL_DOUBLEBUF;
673 671
674 surface->GetPixelFormat (surface, &pixelformat); 672 surface->GetPixelFormat(surface, &pixelformat);
675 673
676 DFBToSDLPixelFormat (pixelformat, current->format); 674 DFBToSDLPixelFormat(pixelformat, current->format);
677 675
678 /* Get the surface palette (if supported) */ 676 /* Get the surface palette (if supported) */
679 if (DFB_PIXELFORMAT_IS_INDEXED (pixelformat)) { 677 if (DFB_PIXELFORMAT_IS_INDEXED(pixelformat)) {
680 surface->GetPalette (surface, &current->hwdata->palette); 678 surface->GetPalette(surface, &current->hwdata->palette);
681 679
682 current->flags |= SDL_HWPALETTE; 680 current->flags |= SDL_HWPALETTE;
683 } 681 }
684 682
685 current->hwdata->surface = surface; 683 current->hwdata->surface = surface;
695 HIDDEN->c2dsize.w = width; 693 HIDDEN->c2dsize.w = width;
696 HIDDEN->c2dsize.h = height; 694 HIDDEN->c2dsize.h = height;
697 695
698 HIDDEN->mga_crtc2_stretch = 0; 696 HIDDEN->mga_crtc2_stretch = 0;
699 697
700 if (SDL_getenv ("SDL_DIRECTFB_MGA_STRETCH") != NULL) { 698 if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL) {
701 /* Normally assume a picture aspect ratio of 4:3 */ 699 /* Normally assume a picture aspect ratio of 4:3 */
702 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j; 700 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
703 701
704 for (i = 1; i < 20; i++) { 702 for (i = 1; i < 20; i++) {
705 for (j = 1; j < 10; j++) { 703 for (j = 1; j < 10; j++) {
716 714
717 #ifdef DIRECTFB_CRTC2_DEBUG 715 #ifdef DIRECTFB_CRTC2_DEBUG
718 printf 716 printf
719 ("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", 717 ("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n",
720 width, height, zoom_aspect_x, zoom_aspect_y); 718 width, height, zoom_aspect_x, zoom_aspect_y);
721 printf ("CRTC2 resolution: X: %d, Y: %d\n", 719 printf("CRTC2 resolution: X: %d, Y: %d\n",
722 HIDDEN->c2framesize.w, HIDDEN->c2framesize.h); 720 HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
723 #endif 721 #endif
724 722
725 /* don't stretch only slightly smaller/larger images */ 723 /* don't stretch only slightly smaller/larger images */
726 if ((float) width < (float) HIDDEN->c2framesize.w * 0.95 724 if ((float) width < (float) HIDDEN->c2framesize.w * 0.95
727 || (float) height < (float) HIDDEN->c2framesize.h * 0.95) { 725 || (float) height < (float) HIDDEN->c2framesize.h * 0.95) {
738 /* one step down */ 736 /* one step down */
739 HIDDEN->c2dsize.w -= zoom_aspect_x; 737 HIDDEN->c2dsize.w -= zoom_aspect_x;
740 HIDDEN->c2dsize.h -= zoom_aspect_y; 738 HIDDEN->c2dsize.h -= zoom_aspect_y;
741 739
742 #ifdef DIRECTFB_CRTC2_DEBUG 740 #ifdef DIRECTFB_CRTC2_DEBUG
743 printf ("Stretched resolution: X: %d, Y: %d\n", 741 printf("Stretched resolution: X: %d, Y: %d\n",
744 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); 742 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
745 #endif 743 #endif
746 744
747 HIDDEN->mga_crtc2_stretch = 1; 745 HIDDEN->mga_crtc2_stretch = 1;
748 } else if ((float) width > (float) HIDDEN->c2framesize.w * 0.95 746 } else if ((float) width > (float) HIDDEN->c2framesize.w * 0.95
749 || (float) height > 747 || (float) height >
757 HIDDEN->c2dsize.w -= zoom_aspect_x; 755 HIDDEN->c2dsize.w -= zoom_aspect_x;
758 HIDDEN->c2dsize.h -= zoom_aspect_y; 756 HIDDEN->c2dsize.h -= zoom_aspect_y;
759 } 757 }
760 758
761 #ifdef DIRECTFB_CRTC2_DEBUG 759 #ifdef DIRECTFB_CRTC2_DEBUG
762 printf ("Down-Stretched resolution: X: %d, Y: %d\n", 760 printf("Down-Stretched resolution: X: %d, Y: %d\n",
763 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); 761 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
764 #endif 762 #endif
765 763
766 HIDDEN->mga_crtc2_stretch = 1; 764 HIDDEN->mga_crtc2_stretch = 1;
767 } else { 765 } else {
768 #ifdef DIRECTFB_CRTC2_DEBUG 766 #ifdef DIRECTFB_CRTC2_DEBUG
769 printf ("Not stretching image\n"); 767 printf("Not stretching image\n");
770 #endif 768 #endif
771 } 769 }
772 770
773 /* Panning */ 771 /* Panning */
774 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w) 772 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
784 else 782 else
785 HIDDEN->c2dsize.y = 783 HIDDEN->c2dsize.y =
786 (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2; 784 (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;
787 785
788 #ifdef DIRECTFB_CRTC2_DEBUG 786 #ifdef DIRECTFB_CRTC2_DEBUG
789 printf ("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, 787 printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x,
790 HIDDEN->c2dsize.y); 788 HIDDEN->c2dsize.y);
791 #endif 789 #endif
792 } 790 }
793 } 791 }
794 792
795 return current; 793 return current;
796 } 794 }
797 795
798 static int 796 static int
799 DirectFB_AllocHWSurface (_THIS, SDL_Surface * surface) 797 DirectFB_AllocHWSurface(_THIS, SDL_Surface * surface)
800 { 798 {
801 DFBResult ret; 799 DFBResult ret;
802 DFBSurfaceDescription dsc; 800 DFBSurfaceDescription dsc;
803 801
804 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n", 802 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
813 dsc.width = surface->w; 811 dsc.width = surface->w;
814 dsc.height = surface->h; 812 dsc.height = surface->h;
815 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0; 813 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0;
816 814
817 /* find the right pixelformat */ 815 /* find the right pixelformat */
818 dsc.pixelformat = SDLToDFBPixelFormat (surface->format); 816 dsc.pixelformat = SDLToDFBPixelFormat(surface->format);
819 if (dsc.pixelformat == DSPF_UNKNOWN) 817 if (dsc.pixelformat == DSPF_UNKNOWN)
820 return -1; 818 return -1;
821 819
822 /* Allocate the hardware acceleration data */ 820 /* Allocate the hardware acceleration data */
823 surface->hwdata = 821 surface->hwdata =
824 (struct private_hwdata *) SDL_calloc (1, sizeof (*surface->hwdata)); 822 (struct private_hwdata *) SDL_calloc(1, sizeof(*surface->hwdata));
825 if (surface->hwdata == NULL) { 823 if (surface->hwdata == NULL) {
826 SDL_OutOfMemory (); 824 SDL_OutOfMemory();
827 return -1; 825 return -1;
828 } 826 }
829 827
830 /* Create the surface */ 828 /* Create the surface */
831 ret = 829 ret =
832 HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, 830 HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc,
833 &surface->hwdata->surface); 831 &surface->hwdata->surface);
834 if (ret) { 832 if (ret) {
835 SetDirectFBerror ("dfb->CreateSurface", ret); 833 SetDirectFBerror("dfb->CreateSurface", ret);
836 free (surface->hwdata); 834 free(surface->hwdata);
837 surface->hwdata = NULL; 835 surface->hwdata = NULL;
838 return -1; 836 return -1;
839 } 837 }
840 838
841 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC; 839 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
842 840
843 return 0; 841 return 0;
844 } 842 }
845 843
846 static void 844 static void
847 DirectFB_FreeHWSurface (_THIS, SDL_Surface * surface) 845 DirectFB_FreeHWSurface(_THIS, SDL_Surface * surface)
848 { 846 {
849 if (surface->hwdata && HIDDEN->initialized) { 847 if (surface->hwdata && HIDDEN->initialized) {
850 surface->hwdata->surface->Release (surface->hwdata->surface); 848 surface->hwdata->surface->Release(surface->hwdata->surface);
851 free (surface->hwdata); 849 free(surface->hwdata);
852 surface->hwdata = NULL; 850 surface->hwdata = NULL;
853 } 851 }
854 } 852 }
855 853
856 static int 854 static int
857 DirectFB_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst) 855 DirectFB_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
858 { 856 {
859 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n", 857 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
860 src->hwdata, dst->hwdata); */ 858 src->hwdata, dst->hwdata); */
861 859
862 if (!src->hwdata || !dst->hwdata) 860 if (!src->hwdata || !dst->hwdata)
867 865
868 return 1; 866 return 1;
869 } 867 }
870 868
871 static int 869 static int
872 DirectFB_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, 870 DirectFB_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
873 SDL_Surface * dst, SDL_Rect * dstrect) 871 SDL_Surface * dst, SDL_Rect * dstrect)
874 { 872 {
875 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; 873 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
876 874
877 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h }; 875 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h };
878 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h }; 876 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h };
879 877
880 IDirectFBSurface *surface = dst->hwdata->surface; 878 IDirectFBSurface *surface = dst->hwdata->surface;
881 879
882 if (src->flags & SDL_SRCCOLORKEY) { 880 if (src->flags & SDL_SRCCOLORKEY) {
883 flags |= DSBLIT_SRC_COLORKEY; 881 flags |= DSBLIT_SRC_COLORKEY;
884 DirectFB_SetHWColorKey (NULL, src, src->format->colorkey); 882 DirectFB_SetHWColorKey(NULL, src, src->format->colorkey);
885 } 883 }
886 884
887 if (src->flags & SDL_SRCALPHA) { 885 if (src->flags & SDL_SRCALPHA) {
888 flags |= DSBLIT_BLEND_COLORALPHA; 886 flags |= DSBLIT_BLEND_COLORALPHA;
889 surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha); 887 surface->SetColor(surface, 0xff, 0xff, 0xff, src->format->alpha);
890 } 888 }
891 889
892 surface->SetBlittingFlags (surface, flags); 890 surface->SetBlittingFlags(surface, flags);
893 891
894 if (sr.w == dr.w && sr.h == dr.h) 892 if (sr.w == dr.w && sr.h == dr.h)
895 surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y); 893 surface->Blit(surface, src->hwdata->surface, &sr, dr.x, dr.y);
896 else 894 else
897 surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr); 895 surface->StretchBlit(surface, src->hwdata->surface, &sr, &dr);
898 896
899 return 0; 897 return 0;
900 } 898 }
901 899
902 static int 900 static int
903 DirectFB_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, 901 DirectFB_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
904 Uint32 color) 902 Uint32 color)
905 { 903 {
906 SDL_PixelFormat *fmt = dst->format; 904 SDL_PixelFormat *fmt = dst->format;
907 IDirectFBSurface *surface = dst->hwdata->surface; 905 IDirectFBSurface *surface = dst->hwdata->surface;
908 906
909 /* ugly */ 907 /* ugly */
910 surface->SetColor (surface, 908 surface->SetColor(surface,
911 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss), 909 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
912 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss), 910 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
913 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 911 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift),
914 0xFF); 912 0xFF);
915 surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, 913 surface->FillRectangle(surface, dstrect->x, dstrect->y, dstrect->w,
916 dstrect->h); 914 dstrect->h);
917 915
918 return 0; 916 return 0;
919 } 917 }
920 918
921 static int 919 static int
922 DirectFB_SetHWColorKey (_THIS, SDL_Surface * src, Uint32 key) 920 DirectFB_SetHWColorKey(_THIS, SDL_Surface * src, Uint32 key)
923 { 921 {
924 SDL_PixelFormat *fmt = src->format; 922 SDL_PixelFormat *fmt = src->format;
925 IDirectFBSurface *surface = src->hwdata->surface; 923 IDirectFBSurface *surface = src->hwdata->surface;
926 924
927 if (fmt->BitsPerPixel == 8) 925 if (fmt->BitsPerPixel == 8)
928 surface->SetSrcColorKeyIndex (surface, key); 926 surface->SetSrcColorKeyIndex(surface, key);
929 else 927 else
930 /* ugly */ 928 /* ugly */
931 surface->SetSrcColorKey (surface, 929 surface->SetSrcColorKey(surface,
932 (key & fmt->Rmask) >> (fmt->Rshift - 930 (key & fmt->Rmask) >> (fmt->Rshift -
933 fmt->Rloss), 931 fmt->Rloss),
934 (key & fmt->Gmask) >> (fmt->Gshift - 932 (key & fmt->Gmask) >> (fmt->Gshift -
935 fmt->Gloss), 933 fmt->Gloss),
936 (key & fmt->Bmask) << (fmt->Bloss - 934 (key & fmt->Bmask) << (fmt->Bloss -
937 fmt->Bshift)); 935 fmt->Bshift));
938 936
939 return 0; 937 return 0;
940 } 938 }
941 939
942 static int 940 static int
943 DirectFB_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha) 941 DirectFB_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha)
944 { 942 {
945 return 0; 943 return 0;
946 } 944 }
947 945
948 static int 946 static int
949 DirectFB_FlipHWSurface (_THIS, SDL_Surface * surface) 947 DirectFB_FlipHWSurface(_THIS, SDL_Surface * surface)
950 { 948 {
951 if (HIDDEN->enable_mga_crtc2) { 949 if (HIDDEN->enable_mga_crtc2) {
952 int rtn = 950 int rtn =
953 surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 951 surface->hwdata->surface->Flip(surface->hwdata->surface, NULL,
954 0); 952 0);
955 if (HIDDEN->mga_crtc2_stretch) 953 if (HIDDEN->mga_crtc2_stretch)
956 HIDDEN->c2frame->StretchBlit (HIDDEN->c2frame, 954 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame,
957 surface->hwdata->surface, 955 surface->hwdata->surface,
958 &HIDDEN->c2ssize, &HIDDEN->c2dsize); 956 &HIDDEN->c2ssize, &HIDDEN->c2dsize);
959 else 957 else
960 HIDDEN->c2frame->Blit (HIDDEN->c2frame, 958 HIDDEN->c2frame->Blit(HIDDEN->c2frame,
961 surface->hwdata->surface, NULL, 959 surface->hwdata->surface, NULL,
962 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 960 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
963 961
964 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); 962 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
965 return rtn; 963 return rtn;
966 } else 964 } else
967 return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 965 return surface->hwdata->surface->Flip(surface->hwdata->surface, NULL,
968 DSFLIP_WAITFORSYNC); 966 DSFLIP_WAITFORSYNC);
969 } 967 }
970 968
971 static int 969 static int
972 DirectFB_LockHWSurface (_THIS, SDL_Surface * surface) 970 DirectFB_LockHWSurface(_THIS, SDL_Surface * surface)
973 { 971 {
974 DFBResult ret; 972 DFBResult ret;
975 void *data; 973 void *data;
976 int pitch; 974 int pitch;
977 975
978 ret = surface->hwdata->surface->Lock (surface->hwdata->surface, 976 ret = surface->hwdata->surface->Lock(surface->hwdata->surface,
979 DSLF_WRITE, &data, &pitch); 977 DSLF_WRITE, &data, &pitch);
980 if (ret) { 978 if (ret) {
981 SetDirectFBerror ("surface->Lock", ret); 979 SetDirectFBerror("surface->Lock", ret);
982 return -1; 980 return -1;
983 } 981 }
984 982
985 surface->pixels = data; 983 surface->pixels = data;
986 surface->pitch = pitch; 984 surface->pitch = pitch;
987 985
988 return 0; 986 return 0;
989 } 987 }
990 988
991 static void 989 static void
992 DirectFB_UnlockHWSurface (_THIS, SDL_Surface * surface) 990 DirectFB_UnlockHWSurface(_THIS, SDL_Surface * surface)
993 { 991 {
994 surface->hwdata->surface->Unlock (surface->hwdata->surface); 992 surface->hwdata->surface->Unlock(surface->hwdata->surface);
995 surface->pixels = NULL; 993 surface->pixels = NULL;
996 } 994 }
997 995
998 static void 996 static void
999 DirectFB_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) 997 DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
1000 { 998 {
1001 if (HIDDEN->enable_mga_crtc2) { 999 if (HIDDEN->enable_mga_crtc2) {
1002 if (HIDDEN->mga_crtc2_stretch) 1000 if (HIDDEN->mga_crtc2_stretch)
1003 HIDDEN->c2frame->StretchBlit (HIDDEN->c2frame, 1001 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame,
1004 this->screen->hwdata->surface, 1002 this->screen->hwdata->surface,
1005 &HIDDEN->c2ssize, &HIDDEN->c2dsize); 1003 &HIDDEN->c2ssize, &HIDDEN->c2dsize);
1006 else 1004 else
1007 HIDDEN->c2frame->Blit (HIDDEN->c2frame, 1005 HIDDEN->c2frame->Blit(HIDDEN->c2frame,
1008 this->screen->hwdata->surface, NULL, 1006 this->screen->hwdata->surface, NULL,
1009 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 1007 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
1010 1008
1011 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); 1009 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
1012 } 1010 }
1013 } 1011 }
1014 1012
1015 static void 1013 static void
1016 DirectFB_WindowedUpdate (_THIS, int numrects, SDL_Rect * rects) 1014 DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect * rects)
1017 { 1015 {
1018 DFBRegion region; 1016 DFBRegion region;
1019 int i; 1017 int i;
1020 int region_valid = 0; 1018 int region_valid = 0;
1021 IDirectFBSurface *surface = this->screen->hwdata->surface; 1019 IDirectFBSurface *surface = this->screen->hwdata->surface;
1052 } 1050 }
1053 1051
1054 if (region_valid) { 1052 if (region_valid) {
1055 if (HIDDEN->enable_mga_crtc2) { 1053 if (HIDDEN->enable_mga_crtc2) {
1056 if (HIDDEN->mga_crtc2_stretch) 1054 if (HIDDEN->mga_crtc2_stretch)
1057 HIDDEN->c2frame->StretchBlit (HIDDEN->c2frame, surface, 1055 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface,
1058 &HIDDEN->c2ssize, 1056 &HIDDEN->c2ssize,
1059 &HIDDEN->c2dsize); 1057 &HIDDEN->c2dsize);
1060 else 1058 else
1061 HIDDEN->c2frame->Blit (HIDDEN->c2frame, surface, NULL, 1059 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL,
1062 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 1060 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
1063 1061
1064 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); 1062 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
1065 } else 1063 } else
1066 surface->Flip (surface, &region, DSFLIP_WAITFORSYNC); 1064 surface->Flip(surface, &region, DSFLIP_WAITFORSYNC);
1067 } 1065 }
1068 } 1066 }
1069 1067
1070 int 1068 int
1071 DirectFB_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 1069 DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1072 { 1070 {
1073 IDirectFBPalette *palette = this->screen->hwdata->palette; 1071 IDirectFBPalette *palette = this->screen->hwdata->palette;
1074 1072
1075 if (!palette) 1073 if (!palette)
1076 return 0; 1074 return 0;
1090 entries[i].r = colors[i].r; 1088 entries[i].r = colors[i].r;
1091 entries[i].g = colors[i].g; 1089 entries[i].g = colors[i].g;
1092 entries[i].b = colors[i].b; 1090 entries[i].b = colors[i].b;
1093 } 1091 }
1094 1092
1095 palette->SetEntries (palette, entries, ncolors, firstcolor); 1093 palette->SetEntries(palette, entries, ncolors, firstcolor);
1096 } 1094 }
1097 1095
1098 return 1; 1096 return 1;
1099 } 1097 }
1100 1098
1101 void 1099 void
1102 DirectFB_VideoQuit (_THIS) 1100 DirectFB_VideoQuit(_THIS)
1103 { 1101 {
1104 struct DirectFBEnumRect *rect = enumlist; 1102 struct DirectFBEnumRect *rect = enumlist;
1105 1103
1106 if (this->screen && this->screen->hwdata) { 1104 if (this->screen && this->screen->hwdata) {
1107 IDirectFBSurface *surface = this->screen->hwdata->surface; 1105 IDirectFBSurface *surface = this->screen->hwdata->surface;
1108 IDirectFBPalette *palette = this->screen->hwdata->palette; 1106 IDirectFBPalette *palette = this->screen->hwdata->palette;
1109 1107
1110 if (palette) 1108 if (palette)
1111 palette->Release (palette); 1109 palette->Release(palette);
1112 1110
1113 if (surface) 1111 if (surface)
1114 surface->Release (surface); 1112 surface->Release(surface);
1115 1113
1116 this->screen->hwdata->surface = NULL; 1114 this->screen->hwdata->surface = NULL;
1117 this->screen->hwdata->palette = NULL; 1115 this->screen->hwdata->palette = NULL;
1118 } 1116 }
1119 1117
1120 if (HIDDEN->c2frame) { 1118 if (HIDDEN->c2frame) {
1121 HIDDEN->c2frame->Release (HIDDEN->c2frame); 1119 HIDDEN->c2frame->Release(HIDDEN->c2frame);
1122 HIDDEN->c2frame = NULL; 1120 HIDDEN->c2frame = NULL;
1123 } 1121 }
1124 1122
1125 if (HIDDEN->eventbuffer) { 1123 if (HIDDEN->eventbuffer) {
1126 HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer); 1124 HIDDEN->eventbuffer->Release(HIDDEN->eventbuffer);
1127 HIDDEN->eventbuffer = NULL; 1125 HIDDEN->eventbuffer = NULL;
1128 } 1126 }
1129 1127
1130 if (HIDDEN->c2layer) { 1128 if (HIDDEN->c2layer) {
1131 HIDDEN->c2layer->Release (HIDDEN->c2layer); 1129 HIDDEN->c2layer->Release(HIDDEN->c2layer);
1132 HIDDEN->c2layer = NULL; 1130 HIDDEN->c2layer = NULL;
1133 } 1131 }
1134 1132
1135 if (HIDDEN->layer) { 1133 if (HIDDEN->layer) {
1136 HIDDEN->layer->Release (HIDDEN->layer); 1134 HIDDEN->layer->Release(HIDDEN->layer);
1137 HIDDEN->layer = NULL; 1135 HIDDEN->layer = NULL;
1138 } 1136 }
1139 1137
1140 if (HIDDEN->dfb) { 1138 if (HIDDEN->dfb) {
1141 HIDDEN->dfb->Release (HIDDEN->dfb); 1139 HIDDEN->dfb->Release(HIDDEN->dfb);
1142 HIDDEN->dfb = NULL; 1140 HIDDEN->dfb = NULL;
1143 } 1141 }
1144 1142
1145 /* Free video mode list */ 1143 /* Free video mode list */
1146 if (HIDDEN->modelist) { 1144 if (HIDDEN->modelist) {
1147 free (HIDDEN->modelist); 1145 free(HIDDEN->modelist);
1148 HIDDEN->modelist = NULL; 1146 HIDDEN->modelist = NULL;
1149 } 1147 }
1150 1148
1151 /* Free mode enumeration list */ 1149 /* Free mode enumeration list */
1152 while (rect) { 1150 while (rect) {
1153 struct DirectFBEnumRect *next = rect->next; 1151 struct DirectFBEnumRect *next = rect->next;
1154 free (rect); 1152 free(rect);
1155 rect = next; 1153 rect = next;
1156 } 1154 }
1157 enumlist = NULL; 1155 enumlist = NULL;
1158 1156
1159 HIDDEN->initialized = 0; 1157 HIDDEN->initialized = 0;
1160 } 1158 }
1161 1159
1162 1160
1163 int 1161 int
1164 DirectFB_ShowWMCursor (_THIS, WMcursor * cursor) 1162 DirectFB_ShowWMCursor(_THIS, WMcursor * cursor)
1165 { 1163 {
1166 /* We can only hide or show the default cursor */ 1164 /* We can only hide or show the default cursor */
1167 if (cursor == NULL) { 1165 if (cursor == NULL) {
1168 HIDDEN->layer->SetCursorOpacity (HIDDEN->layer, 0x00); 1166 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00);
1169 } else { 1167 } else {
1170 HIDDEN->layer->SetCursorOpacity (HIDDEN->layer, 0xFF); 1168 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF);
1171 } 1169 }
1172 return 1; 1170 return 1;
1173 } 1171 }
1174 1172
1175 void 1173 void
1176 DirectFB_FinalQuit (void) 1174 DirectFB_FinalQuit(void)
1177 { 1175 {
1178 } 1176 }
1179 1177
1180 /* vi: set ts=4 sw=4 expandtab: */ 1178 /* vi: set ts=4 sw=4 expandtab: */