Skip to content

Latest commit

 

History

History
755 lines (631 loc) · 19.9 KB

SDL_DirectFB_video.c

File metadata and controls

755 lines (631 loc) · 19.9 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* DirectFB video driver implementation.
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <directfb.h>
#include "SDL.h"
#include "SDL_error.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_events.h"
/* Initialization/Query functions */
static int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors);
static void DirectFB_VideoQuit(_THIS);
/* Hardware surface functions */
static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface);
static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface);
static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface);
static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst);
static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key);
static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha);
static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface);
/* Various screen update functions available */
static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects);
/* This is the rect EnumModes2 uses */
struct DirectFBEnumRect {
SDL_Rect r;
struct DirectFBEnumRect* next;
};
static struct DirectFBEnumRect *enumlists[NUM_MODELISTS];
/* DirectFB driver bootstrap functions */
static int DirectFB_Available(void)
{
return 1;
}
static void DirectFB_DeleteDevice(SDL_VideoDevice *device)
{
free(device->hidden);
free(device);
}
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
if (device)
{
memset (device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *) malloc (sizeof (*device->hidden));
}
if (device == NULL || device->hidden == NULL)
{
SDL_OutOfMemory();
if (device)
{
free (device);
}
return(0);
}
memset (device->hidden, 0, sizeof (*device->hidden));
/* Set the function pointers */
device->VideoInit = DirectFB_VideoInit;
device->ListModes = DirectFB_ListModes;
device->SetVideoMode = DirectFB_SetVideoMode;
device->SetColors = DirectFB_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = DirectFB_VideoQuit;
device->AllocHWSurface = DirectFB_AllocHWSurface;
device->CheckHWBlit = DirectFB_CheckHWBlit;
device->FillHWRect = DirectFB_FillHWRect;
device->SetHWColorKey = DirectFB_SetHWColorKey;
device->SetHWAlpha = DirectFB_SetHWAlpha;
device->LockHWSurface = DirectFB_LockHWSurface;
device->UnlockHWSurface = DirectFB_UnlockHWSurface;
device->FlipHWSurface = DirectFB_FlipHWSurface;
device->FreeHWSurface = DirectFB_FreeHWSurface;
device->SetCaption = NULL;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->GetWMInfo = NULL;
device->InitOSKeymap = DirectFB_InitOSKeymap;
device->PumpEvents = DirectFB_PumpEvents;
device->free = DirectFB_DeleteDevice;
return device;
}
VideoBootStrap DirectFB_bootstrap = {
"directfb", "DirectFB",
DirectFB_Available, DirectFB_CreateDevice
};
static DFBEnumerationResult EnumModesCallback (unsigned int width,
unsigned int height,
unsigned int bpp,
void *data)
{
SDL_VideoDevice *this = (SDL_VideoDevice *)data;
struct DirectFBEnumRect *enumrect;
switch (bpp)
{
case 8:
case 15:
case 16:
case 24:
case 32:
bpp /= 8; --bpp;
++HIDDEN->SDL_nummodes[bpp];
enumrect = (struct DirectFBEnumRect*)malloc(sizeof(struct DirectFBEnumRect));
if ( !enumrect )
{
SDL_OutOfMemory();
return DFENUM_CANCEL;
}
enumrect->r.x = 0;
enumrect->r.y = 0;
enumrect->r.w = width;
enumrect->r.h = height;
enumrect->next = enumlists[bpp];
enumlists[bpp] = enumrect;
break;
}
return DFENUM_OK;
}
struct private_hwdata {
IDirectFBSurface *surface;
};
void SetDirectFBerror (const char *function, DFBResult code)
{
const char *error = DirectFBErrorString (code);
if (error)
SDL_SetError("%s: %s", function, error);
else
SDL_SetError("Unknown error code from %s", function);
}
static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
{
if (format->Rmask && format->Gmask && format->Bmask)
{
switch (format->BitsPerPixel)
{
case 16:
if (format->Rmask == 0xF800 &&
format->Gmask == 0x07E0 &&
format->Bmask == 0x001F)
return DSPF_RGB16;
/* fall through */
case 15:
if (format->Rmask == 0x7C00 &&
format->Gmask == 0x03E0 &&
format->Bmask == 0x001F)
return DSPF_RGB15;
break;
case 24:
if (format->Rmask == 0xFF0000 &&
format->Gmask == 0x00FF00 &&
format->Bmask == 0x0000FF)
return DSPF_RGB24;
break;
case 32:
if (format->Rmask == 0xFF0000 &&
format->Gmask == 0x00FF00 &&
format->Bmask == 0x0000FF)
{
if (format->Amask == 0xFF000000)
return DSPF_ARGB;
else
return DSPF_RGB32;
}
break;
}
}
else
{
switch (format->BitsPerPixel)
{
case 15:
return DSPF_RGB15;
case 16:
return DSPF_RGB16;
case 24:
return DSPF_RGB24;
case 32:
return DSPF_RGB32;
}
}
return DSPF_UNKNOWN;
}
static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelFormat *format)
{
format->BitsPerPixel = 0;
format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
switch (pixelformat)
{
case DSPF_A8:
format->Amask = 0x000000FF;
break;
case DSPF_RGB15:
format->Rmask = 0x00007C00;
format->Gmask = 0x000003E0;
format->Bmask = 0x0000001F;
break;
case DSPF_RGB16:
format->Rmask = 0x0000F800;
format->Gmask = 0x000007E0;
format->Bmask = 0x0000001F;
break;
case DSPF_ARGB:
format->Amask = 0xFF000000;
/* fall through */
case DSPF_RGB24:
case DSPF_RGB32:
format->Rmask = 0x00FF0000;
format->Gmask = 0x0000FF00;
format->Bmask = 0x000000FF;
break;
default:
return -1;
}
format->BitsPerPixel = BITS_PER_PIXEL(pixelformat);
return 0;
}
int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
int i, j;
DFBResult ret;
IDirectFB *dfb;
DFBCardCapabilities caps;
IDirectFBDisplayLayer *layer;
DFBDisplayLayerConfig dlc;
IDirectFBInputBuffer *inputbuffer;
ret = DirectFBInit (NULL, NULL);
if (ret)
{
SetDirectFBerror ("DirectFBInit", ret);
return -1;
}
ret = DirectFBCreate (&dfb);
if (ret)
{
SetDirectFBerror ("DirectFBCreate", ret);
return -1;
}
ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
if (ret)
{
SetDirectFBerror ("dfb->GetDisplayLayer", ret);
dfb->Release (dfb);
return -1;
}
ret = dfb->CreateInputBuffer (dfb, DICAPS_BUTTONS | DICAPS_AXIS | DICAPS_KEYS,
&inputbuffer);
if (ret)
{
SetDirectFBerror ("dfb->CreateInputBuffer", ret);
layer->Release (layer);
dfb->Release (dfb);
return -1;
}
layer->EnableCursor (layer, 1);
/* Query layer configuration to determine the current mode and pixelformat */
layer->GetConfiguration (layer, &dlc);
if (DFBToSDLPixelFormat (dlc.pixelformat, vformat))
{
SDL_SetError ("Unsupported pixelformat");
layer->Release (layer);
dfb->Release (dfb);
return -1;
}
/* Enumerate the available fullscreen modes */
for ( i=0; i<NUM_MODELISTS; ++i )
enumlists[i] = NULL;
ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
if (ret)
{
SetDirectFBerror ("dfb->EnumVideoModes", ret);
layer->Release (layer);
dfb->Release (dfb);
return(-1);
}
for ( i=0; i<NUM_MODELISTS; ++i )
{
struct DirectFBEnumRect *rect;
HIDDEN->SDL_modelist[i] = (SDL_Rect **) malloc
((HIDDEN->SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
if ( HIDDEN->SDL_modelist[i] == NULL )
{
SDL_OutOfMemory();
return(-1);
}
for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next )
{
HIDDEN->SDL_modelist[i][j]=(SDL_Rect *)rect;
}
HIDDEN->SDL_modelist[i][j] = NULL;
}
/* Query card capabilities to get the video memory size */
dfb->GetCardCapabilities (dfb, &caps);
this->info.wm_available = 1;
this->info.hw_available = 1;
this->info.blit_hw = 1;
this->info.blit_hw_CC = 1;
this->info.blit_hw_A = 1;
this->info.blit_fill = 1;
this->info.video_mem = caps.video_memory / 1024;
HIDDEN->initialized = 1;
HIDDEN->dfb = dfb;
HIDDEN->layer = layer;
HIDDEN->inputbuffer = inputbuffer;
return 0;
}
static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if (flags & SDL_FULLSCREEN)
return HIDDEN->SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
else
if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN)
return (SDL_Rect**) -1;
return NULL;
}
SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
{
DFBResult ret;
DFBSurfaceDescription dsc;
DFBSurfacePixelFormat pixelformat;
fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
width, height, bpp, flags);
flags |= SDL_FULLSCREEN;
/* Release previous primary surface */
if (current->hwdata && current->hwdata->surface)
{
current->hwdata->surface->Release (current->hwdata->surface);
current->hwdata->surface = NULL;
}
else if (!current->hwdata)
{
/* Allocate the hardware acceleration data */
current->hwdata = (struct private_hwdata *) malloc (sizeof(*current->hwdata));
if (!current->hwdata)
{
SDL_OutOfMemory();
return NULL;
}
memset (current->hwdata, 0, sizeof(*current->hwdata));
}
/* Set cooperative level depending on flag SDL_FULLSCREEN */
if (flags & SDL_FULLSCREEN)
{
ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
if (ret)
{
DirectFBError ("dfb->SetCooperativeLevel", ret);
flags &= ~SDL_FULLSCREEN;
}
}
else
HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
/* Set video mode */
ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
if (ret)
{
if (flags & SDL_FULLSCREEN)
{
flags &= ~SDL_FULLSCREEN;
HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL);
ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp);
}
if (ret)
{
SetDirectFBerror ("dfb->SetVideoMode", ret);
return NULL;
}
}
/* Create primary surface */
dsc.flags = DSDESC_CAPS;
dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &current->hwdata->surface);
if (ret && (flags & SDL_DOUBLEBUF))
{
/* Try without double buffering */
dsc.caps &= ~DSCAPS_FLIPPING;
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &current->hwdata->surface);
}
if (ret)
{
SetDirectFBerror ("dfb->CreateSurface", ret);
current->hwdata->surface = NULL;
return NULL;
}
current->w = width;
current->h = height;
current->flags = SDL_HWSURFACE | SDL_PREALLOC;
if (flags & SDL_FULLSCREEN)
{
current->flags |= SDL_FULLSCREEN;
this->UpdateRects = DirectFB_DirectUpdate;
}
else
this->UpdateRects = DirectFB_WindowedUpdate;
if (dsc.caps & DSCAPS_FLIPPING)
current->flags |= SDL_DOUBLEBUF;
current->hwdata->surface->GetPixelFormat (current->hwdata->surface, &pixelformat);
DFBToSDLPixelFormat (pixelformat, current->format);
return current;
}
static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface)
{
DFBResult ret;
DFBSurfaceDescription dsc;
/* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
surface->w, surface->h, surface->format->BitsPerPixel, surface->flags);*/
if (surface->w < 8 || surface->h < 8)
return -1;
/* fill surface description */
dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
dsc.width = surface->w;
dsc.height = surface->h;
dsc.caps = surface->flags & SDL_DOUBLEBUF ? DSCAPS_FLIPPING : 0;
/* find the right pixelformat */
dsc.pixelformat = SDLToDFBPixelFormat (surface->format);
if (dsc.pixelformat == DSPF_UNKNOWN)
return -1;
/* Allocate the hardware acceleration data */
surface->hwdata = (struct private_hwdata *) malloc (sizeof(*surface->hwdata));
if (surface->hwdata == NULL)
{
SDL_OutOfMemory();
return -1;
}
/* Create the surface */
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface->hwdata->surface);
if (ret)
{
SetDirectFBerror ("dfb->CreateSurface", ret);
free (surface->hwdata);
surface->hwdata = NULL;
return -1;
}
surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
return 0;
}
static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface)
{
if (surface->hwdata && HIDDEN->initialized)
{
surface->hwdata->surface->Release (surface->hwdata->surface);
free (surface->hwdata);
surface->hwdata = NULL;
}
}
static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
{
/* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
src->hwdata, dst->hwdata);*/
if (!src->hwdata || !dst->hwdata)
return 0;
src->flags |= SDL_HWACCEL;
src->map->hw_blit = DirectFB_HWAccelBlit;
return 1;
}
static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
{
DFBRectangle sr, dr;
IDirectFBSurface *surface;
DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
sr.x = srcrect->x;
sr.y = srcrect->y;
sr.w = srcrect->w;
sr.h = srcrect->h;
dr.x = dstrect->x;
dr.y = dstrect->y;
dr.w = dstrect->w;
dr.h = dstrect->h;
surface = dst->hwdata->surface;
if (src->flags & SDL_SRCCOLORKEY)
{
flags |= DSBLIT_SRC_COLORKEY;
Nov 1, 2001
Nov 1, 2001
604
DirectFB_SetHWColorKey (NULL, src, src->format->colorkey);
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
}
if (src->flags & SDL_SRCALPHA)
{
flags |= DSBLIT_BLEND_COLORALPHA;
surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha);
}
surface->SetBlittingFlags (surface, flags);
if (sr.w == dr.w && sr.h == dr.h)
surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y);
else
surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr);
return 0;
}
static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
{
SDL_PixelFormat *fmt = dst->format;
IDirectFBSurface *surface = dst->hwdata->surface;
/* ugly */
surface->SetColor (surface,
(color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
(color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
(color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 0xFF);
surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, dstrect->h);
return 0;
}
Nov 1, 2001
Nov 1, 2001
638
static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key)
Nov 1, 2001
Nov 1, 2001
640
641
642
643
644
645
646
647
648
SDL_PixelFormat *fmt = src->format;
IDirectFBSurface *surface = src->hwdata->surface;
/* ugly */
surface->SetSrcColorKey (surface,
(key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
(key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
(key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift));
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
return 0;
}
static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
{
return 0;
}
static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface)
{
return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
}
static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface)
{
DFBResult ret;
void *data;
int pitch;
ret = surface->hwdata->surface->Lock (surface->hwdata->surface,
DSLF_WRITE, &data, &pitch);
if (ret)
{
SetDirectFBerror ("surface->Lock", ret);
return -1;
}
surface->pixels = data;
surface->pitch = pitch;
return 0;
}
static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
surface->hwdata->surface->Unlock (surface->hwdata->surface);
surface->pixels = NULL;
}
static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
{
}
static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
{
IDirectFBSurface *surface = this->screen->hwdata->surface;
DFBRegion region = { rects->x, rects->y,
rects->x + rects->w - 1,
rects->y + rects->h - 1 };
while (--numrects)
{
int x2, y2;
rects++;
if (rects->x < region.x1)
region.x1 = rects->x;
if (rects->y < region.y1)
region.y1 = rects->y;
x2 = rects->x + rects->w - 1;
y2 = rects->y + rects->h - 1;
if (x2 > region.x2)
region.x2 = x2;
if (y2 > region.y2)
region.y2 = y2;
}
surface->Flip (surface, &region, DSFLIP_WAITFORSYNC);
}
int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
fprintf(stderr, "SDL: Unimplemented DirectFB_SetColors!\n");
return 0;
}
void DirectFB_VideoQuit(_THIS)
{
int i, j;
HIDDEN->inputbuffer->Release (HIDDEN->inputbuffer);
HIDDEN->layer->Release (HIDDEN->layer);
HIDDEN->dfb->Release (HIDDEN->dfb);
/* Free video mode lists */
for ( i=0; i<NUM_MODELISTS; ++i )
{
if ( HIDDEN->SDL_modelist[i] != NULL )
{
for ( j=0; HIDDEN->SDL_modelist[i][j]; ++j )
free(HIDDEN->SDL_modelist[i][j]);
free(HIDDEN->SDL_modelist[i]);
HIDDEN->SDL_modelist[i] = NULL;
}
}
HIDDEN->initialized = 0;
}
void DirectFB_FinalQuit(void)
{
}