Skip to content

Latest commit

 

History

History
1169 lines (956 loc) · 31.7 KB

SDL_DirectFB_video.c

File metadata and controls

1169 lines (956 loc) · 31.7 KB
 
Feb 1, 2006
Feb 1, 2006
2
3
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
Feb 1, 2006
Feb 1, 2006
5
6
7
8
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Feb 1, 2006
Feb 1, 2006
10
11
12
13
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Feb 1, 2006
Feb 1, 2006
19
20
Sam Lantinga
slouken@libsdl.org
Oct 3, 2003
Oct 3, 2003
21
22
23
24
MGA CRTC2 support by Thomas Jarosch - tomj@simonv.com
CRTC2 support is inspired by mplayer's dfbmga driver
written by Ville Syrj��<syrjala@sci.fi>
Feb 21, 2006
Feb 21, 2006
26
#include "SDL_config.h"
27
28
29
30
31
32
33
34
35
/* DirectFB video driver implementation.
*/
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <directfb.h>
Nov 1, 2005
Nov 1, 2005
36
#include <directfb_version.h>
37
38
39
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
40
41
42
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
43
44
#include "SDL_DirectFB_video.h"
#include "SDL_DirectFB_events.h"
Aug 31, 2002
Aug 31, 2002
45
#include "SDL_DirectFB_yuv.h"
Jan 4, 2004
Jan 4, 2004
47
48
49
50
51
/* The implementation dependent data for the window manager cursor */
struct WMcursor {
int unused;
};
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* 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);
Jan 4, 2004
Jan 4, 2004
73
static int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor);
74
75
76
77
78
79
80
81
82
83
84
/* 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;
};
Aug 24, 2002
Aug 24, 2002
85
static struct DirectFBEnumRect *enumlist = NULL;
86
87
88
89
90
91
92
93
94
95
96
/* DirectFB driver bootstrap functions */
static int DirectFB_Available(void)
{
return 1;
}
static void DirectFB_DeleteDevice(SDL_VideoDevice *device)
{
Feb 7, 2006
Feb 7, 2006
97
98
SDL_free(device->hidden);
SDL_free(device);
99
100
101
102
103
104
105
}
static SDL_VideoDevice *DirectFB_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
106
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
107
108
if (device)
{
Feb 7, 2006
Feb 7, 2006
109
SDL_memset (device, 0, (sizeof *device));
110
111
112
113
114
115
116
117
118
119
120
device->hidden = (struct SDL_PrivateVideoData *) malloc (sizeof (*device->hidden));
}
if (device == NULL || device->hidden == NULL)
{
SDL_OutOfMemory();
if (device)
{
free (device);
}
return(0);
}
Feb 7, 2006
Feb 7, 2006
121
SDL_memset (device->hidden, 0, sizeof (*device->hidden));
122
123
124
125
126
127
128
/* Set the function pointers */
device->VideoInit = DirectFB_VideoInit;
device->ListModes = DirectFB_ListModes;
device->SetVideoMode = DirectFB_SetVideoMode;
device->SetColors = DirectFB_SetColors;
device->UpdateRects = NULL;
Aug 31, 2002
Aug 31, 2002
129
device->CreateYUVOverlay = DirectFB_CreateYUVOverlay;
130
131
132
133
134
135
136
137
138
139
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;
Jan 4, 2004
Jan 4, 2004
140
device->ShowWMCursor = DirectFB_ShowWMCursor;
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
};
Aug 24, 2002
Aug 24, 2002
159
160
161
162
163
164
165
static DFBSurfacePixelFormat GetFormatForBpp (int bpp, IDirectFBDisplayLayer *layer)
{
DFBDisplayLayerConfig dlc;
int bytes = (bpp + 7) / 8;
layer->GetConfiguration (layer, &dlc);
Aug 31, 2002
Aug 31, 2002
166
if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1)
Aug 24, 2002
Aug 24, 2002
167
168
169
170
171
return dlc.pixelformat;
switch (bytes)
{
case 1:
Aug 31, 2002
Aug 31, 2002
172
return DSPF_LUT8;
Aug 24, 2002
Aug 24, 2002
173
174
175
176
177
178
179
180
181
182
183
case 2:
return DSPF_RGB16;
case 3:
return DSPF_RGB24;
case 4:
return DSPF_RGB32;
}
return DSPF_UNKNOWN;
}
Feb 13, 2004
Feb 13, 2004
184
185
186
187
static DFBEnumerationResult EnumModesCallback (int width,
int height,
int bpp,
void *data)
188
189
190
191
{
SDL_VideoDevice *this = (SDL_VideoDevice *)data;
struct DirectFBEnumRect *enumrect;
Aug 24, 2002
Aug 24, 2002
192
193
HIDDEN->nummodes++;
May 8, 2006
May 8, 2006
194
195
196
if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
return DFENUM_OK;
Feb 7, 2006
Feb 7, 2006
197
enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
Aug 24, 2002
Aug 24, 2002
198
199
200
201
if (!enumrect)
{
SDL_OutOfMemory();
return DFENUM_CANCEL;
Feb 13, 2004
Feb 13, 2004
204
205
enumrect->r.w = (Uint16)width;
enumrect->r.h = (Uint16)height;
Aug 24, 2002
Aug 24, 2002
206
207
208
209
enumrect->next = enumlist;
enumlist = enumrect;
210
211
212
213
214
return DFENUM_OK;
}
struct private_hwdata {
IDirectFBSurface *surface;
Aug 31, 2002
Aug 31, 2002
215
IDirectFBPalette *palette;
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
};
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)
{
Aug 31, 2002
Aug 31, 2002
234
235
236
case 8:
return DSPF_LUT8;
237
238
239
240
241
242
243
244
245
246
247
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)
Jan 28, 2004
Jan 28, 2004
248
return DSPF_ARGB1555;
249
250
251
252
253
254
255
256
break;
case 24:
if (format->Rmask == 0xFF0000 &&
format->Gmask == 0x00FF00 &&
format->Bmask == 0x0000FF)
return DSPF_RGB24;
break;
Aug 24, 2002
Aug 24, 2002
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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)
{
Aug 24, 2002
Aug 24, 2002
275
case 8:
Aug 31, 2002
Aug 31, 2002
276
return DSPF_LUT8;
Jan 28, 2004
Jan 28, 2004
278
return DSPF_ARGB1555;
279
280
281
282
283
284
285
286
287
288
289
290
case 16:
return DSPF_RGB16;
case 24:
return DSPF_RGB24;
case 32:
return DSPF_RGB32;
}
}
return DSPF_UNKNOWN;
}
Aug 31, 2002
Aug 31, 2002
291
static SDL_Palette *AllocatePalette(int size)
Aug 24, 2002
Aug 24, 2002
292
293
294
295
{
SDL_Palette *palette;
SDL_Color *colors;
Feb 7, 2006
Feb 7, 2006
296
palette = SDL_calloc (1, sizeof(SDL_Palette));
Aug 24, 2002
Aug 24, 2002
297
298
299
300
301
302
if (!palette)
{
SDL_OutOfMemory();
return NULL;
}
Feb 7, 2006
Feb 7, 2006
303
colors = SDL_calloc (size, sizeof(SDL_Color));
Aug 24, 2002
Aug 24, 2002
304
305
306
307
308
309
if (!colors)
{
SDL_OutOfMemory();
return NULL;
}
Aug 31, 2002
Aug 31, 2002
310
palette->ncolors = size;
Aug 24, 2002
Aug 24, 2002
311
312
313
314
315
palette->colors = colors;
return palette;
}
316
317
318
static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelFormat *format)
{
format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
Aug 24, 2002
Aug 24, 2002
319
format->BitsPerPixel = format->BytesPerPixel = 0;
320
321
322
323
324
325
switch (pixelformat)
{
case DSPF_A8:
format->Amask = 0x000000FF;
break;
Aug 24, 2002
Aug 24, 2002
326
Jan 28, 2004
Jan 28, 2004
327
case DSPF_ARGB1555:
328
329
330
331
format->Rmask = 0x00007C00;
format->Gmask = 0x000003E0;
format->Bmask = 0x0000001F;
break;
Aug 24, 2002
Aug 24, 2002
332
333
334
335
336
337
case DSPF_RGB16:
format->Rmask = 0x0000F800;
format->Gmask = 0x000007E0;
format->Bmask = 0x0000001F;
break;
Aug 24, 2002
Aug 24, 2002
338
339
case DSPF_ARGB:
Aug 24, 2002
Aug 24, 2002
340
format->Amask = 0; /* apps don't seem to like that: 0xFF000000; */
341
342
343
344
345
346
347
/* fall through */
case DSPF_RGB24:
case DSPF_RGB32:
format->Rmask = 0x00FF0000;
format->Gmask = 0x0000FF00;
format->Bmask = 0x000000FF;
break;
Aug 24, 2002
Aug 24, 2002
348
Aug 31, 2002
Aug 31, 2002
349
350
351
352
case DSPF_LUT8:
format->Rmask = 0x000000FF;
format->Gmask = 0x000000FF;
format->Bmask = 0x000000FF;
Aug 24, 2002
Aug 24, 2002
353
Aug 31, 2002
Aug 31, 2002
354
355
if (!format->palette)
format->palette = AllocatePalette(256);
Aug 24, 2002
Aug 24, 2002
356
357
break;
Aug 31, 2002
Aug 31, 2002
359
fprintf (stderr, "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n", pixelformat);
360
361
362
return -1;
}
Aug 24, 2002
Aug 24, 2002
363
364
format->BitsPerPixel = DFB_BYTES_PER_PIXEL(pixelformat) * 8;
format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat);
365
366
367
368
369
370
371
return 0;
}
int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
Aug 24, 2002
Aug 24, 2002
372
373
int i;
DFBResult ret;
Nov 1, 2005
Nov 1, 2005
374
#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
Aug 24, 2002
Aug 24, 2002
375
DFBCardCapabilities caps;
Nov 1, 2005
Nov 1, 2005
376
377
378
#else
DFBGraphicsDeviceDescription caps;
#endif
Aug 24, 2002
Aug 24, 2002
379
380
381
382
383
DFBDisplayLayerConfig dlc;
struct DirectFBEnumRect *rect;
IDirectFB *dfb = NULL;
IDirectFBDisplayLayer *layer = NULL;
IDirectFBEventBuffer *events = NULL;
Oct 3, 2003
Oct 3, 2003
385
386
387
HIDDEN->c2layer = NULL, HIDDEN->c2frame = NULL;
HIDDEN->enable_mga_crtc2 = 0;
HIDDEN->mga_crtc2_stretch_overscan = 1;
388
389
390
391
392
ret = DirectFBInit (NULL, NULL);
if (ret)
{
SetDirectFBerror ("DirectFBInit", ret);
Aug 24, 2002
Aug 24, 2002
393
goto error;
394
395
396
397
398
399
}
ret = DirectFBCreate (&dfb);
if (ret)
{
SetDirectFBerror ("DirectFBCreate", ret);
Aug 24, 2002
Aug 24, 2002
400
goto error;
401
402
403
404
405
406
}
ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
if (ret)
{
SetDirectFBerror ("dfb->GetDisplayLayer", ret);
Aug 24, 2002
Aug 24, 2002
407
goto error;
Nov 17, 2002
Nov 17, 2002
410
ret = dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events);
411
412
if (ret)
{
Feb 26, 2002
Feb 26, 2002
413
SetDirectFBerror ("dfb->CreateEventBuffer", ret);
Aug 24, 2002
Aug 24, 2002
414
goto error;
415
416
417
418
419
420
421
}
layer->EnableCursor (layer, 1);
/* Query layer configuration to determine the current mode and pixelformat */
layer->GetConfiguration (layer, &dlc);
Aug 31, 2002
Aug 31, 2002
422
423
424
/* If current format is not supported use LUT8 as the default */
if (DFBToSDLPixelFormat (dlc.pixelformat, vformat))
DFBToSDLPixelFormat (DSPF_LUT8, vformat);
425
426
427
428
429
430
/* Enumerate the available fullscreen modes */
ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
if (ret)
{
SetDirectFBerror ("dfb->EnumVideoModes", ret);
Aug 24, 2002
Aug 24, 2002
431
goto error;
Aug 24, 2002
Aug 24, 2002
433
Feb 7, 2006
Feb 7, 2006
434
HIDDEN->modelist = SDL_calloc (HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
Aug 24, 2002
Aug 24, 2002
435
if (!HIDDEN->modelist)
Aug 24, 2002
Aug 24, 2002
437
438
439
440
441
442
443
SDL_OutOfMemory();
goto error;
}
for (i = 0, rect = enumlist; rect; ++i, rect = rect->next )
{
HIDDEN->modelist[i] = &rect->r;
Aug 24, 2002
Aug 24, 2002
446
447
448
HIDDEN->modelist[i] = NULL;
449
/* Query card capabilities to get the video memory size */
Nov 1, 2005
Nov 1, 2005
450
#if (DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23)
451
dfb->GetCardCapabilities (dfb, &caps);
Nov 1, 2005
Nov 1, 2005
452
453
454
#else
dfb->GetDeviceDescription (dfb, &caps);
#endif
455
456
457
458
459
460
461
462
463
464
465
466
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;
Aug 24, 2002
Aug 24, 2002
467
HIDDEN->eventbuffer = events;
Feb 7, 2006
Feb 7, 2006
469
if (SDL_getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
Oct 3, 2003
Oct 3, 2003
470
471
472
473
HIDDEN->enable_mga_crtc2 = 1;
if (HIDDEN->enable_mga_crtc2)
{
Dec 27, 2004
Dec 27, 2004
474
475
476
DFBDisplayLayerConfig dlc;
DFBDisplayLayerConfigFlags failed;
Oct 3, 2003
Oct 3, 2003
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
ret = dfb->GetDisplayLayer (dfb, 2, &HIDDEN->c2layer);
if (ret)
{
SetDirectFBerror ("dfb->GetDisplayLayer(CRTC2)", ret);
goto error;
}
ret = HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer, DLSCL_EXCLUSIVE);
if (ret)
{
SetDirectFBerror ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
goto error;
}
ret = HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer, DLSCL_EXCLUSIVE);
if (ret)
{
SetDirectFBerror ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
goto error;
}
HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0);
/* Init the surface here as it got a fixed size */
Jan 17, 2005
Jan 17, 2005
501
dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE;
Oct 3, 2003
Oct 3, 2003
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
dlc.buffermode = DLBM_BACKVIDEO;
dlc.pixelformat = DSPF_RGB32;
ret = HIDDEN->c2layer->TestConfiguration( HIDDEN->c2layer, &dlc, &failed );
if (ret)
{
SetDirectFBerror ("c2layer->TestConfiguration", ret);
goto error;
}
ret = HIDDEN->c2layer->SetConfiguration( HIDDEN->c2layer, &dlc );
if (ret)
{
SetDirectFBerror ("c2layer->SetConfiguration", ret);
goto error;
}
ret = HIDDEN->c2layer->GetSurface( HIDDEN->c2layer, &HIDDEN->c2frame );
if (ret)
{
SetDirectFBerror ("c2layer->GetSurface", ret);
goto error;
}
HIDDEN->c2framesize.x = 0;
HIDDEN->c2framesize.y = 0;
HIDDEN->c2frame->GetSize( HIDDEN->c2frame, &HIDDEN->c2framesize.w, &HIDDEN->c2framesize.h);
HIDDEN->c2frame->SetBlittingFlags( HIDDEN->c2frame, DSBLIT_NOFX );
HIDDEN->c2frame->SetColor( HIDDEN->c2frame, 0, 0, 0, 0xff );
/* Clear CRTC2 */
HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );
Nov 5, 2003
Nov 5, 2003
541
542
/* Check if overscan is possibly set */
Feb 7, 2006
Feb 7, 2006
543
if (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
Nov 5, 2003
Nov 5, 2003
544
545
{
float overscan = 0;
Feb 7, 2006
Feb 7, 2006
546
if (SDL_sscanf(SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
Nov 5, 2003
Nov 5, 2003
547
548
549
550
551
552
553
if (overscan > 0 && overscan < 2)
HIDDEN->mga_crtc2_stretch_overscan = overscan;
}
#ifdef DIRECTFB_CRTC2_DEBUG
printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
#endif
Oct 3, 2003
Oct 3, 2003
554
555
}
Aug 24, 2002
Aug 24, 2002
557
558
559
560
561
error:
if (events)
events->Release (events);
Oct 3, 2003
Oct 3, 2003
562
563
564
565
566
567
if (HIDDEN->c2frame)
HIDDEN->c2frame->Release (HIDDEN->c2frame);
if (HIDDEN->c2layer)
HIDDEN->c2layer->Release (HIDDEN->c2layer);
Aug 24, 2002
Aug 24, 2002
568
569
570
571
572
573
574
if (layer)
layer->Release (layer);
if (dfb)
dfb->Release (dfb);
return -1;
575
576
577
578
579
}
static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if (flags & SDL_FULLSCREEN)
Aug 24, 2002
Aug 24, 2002
580
return HIDDEN->modelist;
581
582
583
584
585
586
587
else
if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN)
return (SDL_Rect**) -1;
return NULL;
}
Aug 24, 2002
Aug 24, 2002
588
static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
Aug 31, 2002
Aug 31, 2002
590
591
592
593
DFBResult ret;
DFBSurfaceDescription dsc;
DFBSurfacePixelFormat pixelformat;
IDirectFBSurface *surface;
594
595
596
597
598
599
600
601
602
603
604
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;
Aug 31, 2002
Aug 31, 2002
605
606
607
608
609
610
611
/* And its palette if present */
if (current->hwdata->palette)
{
current->hwdata->palette->Release (current->hwdata->palette);
current->hwdata->palette = NULL;
}
612
613
614
615
}
else if (!current->hwdata)
{
/* Allocate the hardware acceleration data */
Feb 7, 2006
Feb 7, 2006
616
current->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*current->hwdata));
617
618
619
620
621
622
623
624
625
626
627
if (!current->hwdata)
{
SDL_OutOfMemory();
return NULL;
}
}
/* Set cooperative level depending on flag SDL_FULLSCREEN */
if (flags & SDL_FULLSCREEN)
{
ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN);
Oct 3, 2003
Oct 3, 2003
628
if (ret && !HIDDEN->enable_mga_crtc2)
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
{
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 */
Aug 24, 2002
Aug 24, 2002
656
657
658
dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
Aug 31, 2002
Aug 31, 2002
660
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface);
661
662
663
664
if (ret && (flags & SDL_DOUBLEBUF))
{
/* Try without double buffering */
dsc.caps &= ~DSCAPS_FLIPPING;
Aug 31, 2002
Aug 31, 2002
665
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface);
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
}
if (ret)
{
SetDirectFBerror ("dfb->CreateSurface", ret);
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;
Aug 31, 2002
Aug 31, 2002
688
689
surface->GetPixelFormat (surface, &pixelformat);
690
691
DFBToSDLPixelFormat (pixelformat, current->format);
Aug 31, 2002
Aug 31, 2002
692
693
694
695
696
697
698
699
700
701
/* Get the surface palette (if supported) */
if (DFB_PIXELFORMAT_IS_INDEXED( pixelformat ))
{
surface->GetPalette (surface, &current->hwdata->palette);
current->flags |= SDL_HWPALETTE;
}
current->hwdata->surface = surface;
Oct 3, 2003
Oct 3, 2003
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/* MGA CRTC2 stuff */
if (HIDDEN->enable_mga_crtc2)
{
/* no stretching if c2ssize == c2framesize */
HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0;
HIDDEN->c2ssize.w = width;
HIDDEN->c2ssize.h = height;
HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0;
HIDDEN->c2dsize.w = width;
HIDDEN->c2dsize.h = height;
HIDDEN->mga_crtc2_stretch = 0;
Feb 7, 2006
Feb 7, 2006
716
if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
Oct 3, 2003
Oct 3, 2003
717
{
Nov 5, 2003
Nov 5, 2003
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
/* Normally assume a picture aspect ratio of 4:3 */
int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
for (i = 1; i < 20; i++)
{
for (j = 1; j < 10; j++)
{
if ((float)width/(float)i*(float)j == height)
{
zoom_aspect_x = i;
zoom_aspect_y = j;
/* break the loop */
i = 21;
break;
}
}
}
#ifdef DIRECTFB_CRTC2_DEBUG
printf("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", width, height, zoom_aspect_x, zoom_aspect_y);
printf("CRTC2 resolution: X: %d, Y: %d\n", HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
#endif
/* don't stretch only slightly smaller/larger images */
if ((float)width < (float)HIDDEN->c2framesize.w*0.95 || (float)height < (float)HIDDEN->c2framesize.h*0.95)
Oct 3, 2003
Oct 3, 2003
744
{
Nov 5, 2003
Nov 5, 2003
745
while ((float)HIDDEN->c2dsize.w < (float)HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && (float)HIDDEN->c2dsize.h < (float)HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
Oct 3, 2003
Oct 3, 2003
746
{
Nov 5, 2003
Nov 5, 2003
747
748
HIDDEN->c2dsize.w+=zoom_aspect_x;
HIDDEN->c2dsize.h+=zoom_aspect_y;
Oct 3, 2003
Oct 3, 2003
749
750
751
}
/* one step down */
Nov 5, 2003
Nov 5, 2003
752
753
HIDDEN->c2dsize.w-=zoom_aspect_x;
HIDDEN->c2dsize.h-=zoom_aspect_y;
Oct 3, 2003
Oct 3, 2003
754
755
756
757
758
759
760
#ifdef DIRECTFB_CRTC2_DEBUG
printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
#endif
HIDDEN->mga_crtc2_stretch = 1;
}
Nov 5, 2003
Nov 5, 2003
761
else if ((float)width > (float)HIDDEN->c2framesize.w*0.95 || (float)height > (float)HIDDEN->c2framesize.h*0.95)
Oct 3, 2003
Oct 3, 2003
762
{
Nov 5, 2003
Nov 5, 2003
763
while ((float)HIDDEN->c2dsize.w > (float)HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || (float)HIDDEN->c2dsize.h > (float)HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
Oct 3, 2003
Oct 3, 2003
764
{
Nov 5, 2003
Nov 5, 2003
765
766
HIDDEN->c2dsize.w-=zoom_aspect_x;
HIDDEN->c2dsize.h-=zoom_aspect_y;
Oct 3, 2003
Oct 3, 2003
767
768
769
770
771
772
773
}
#ifdef DIRECTFB_CRTC2_DEBUG
printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
#endif
HIDDEN->mga_crtc2_stretch = 1;
Nov 5, 2003
Nov 5, 2003
774
775
776
777
} else {
#ifdef DIRECTFB_CRTC2_DEBUG
printf("Not stretching image\n");
#endif
Oct 3, 2003
Oct 3, 2003
778
779
780
781
782
783
784
785
786
787
788
789
790
791
}
/* Panning */
if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2;
else
HIDDEN->c2dsize.x = (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2;
if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h)
HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2;
else
HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;
#ifdef DIRECTFB_CRTC2_DEBUG
Nov 5, 2003
Nov 5, 2003
792
printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
Oct 3, 2003
Oct 3, 2003
793
794
#endif
}
Nov 5, 2003
Nov 5, 2003
795
}
Oct 3, 2003
Oct 3, 2003
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
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;
Aug 24, 2002
Aug 24, 2002
815
dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0;
816
817
818
819
820
821
822
/* find the right pixelformat */
dsc.pixelformat = SDLToDFBPixelFormat (surface->format);
if (dsc.pixelformat == DSPF_UNKNOWN)
return -1;
/* Allocate the hardware acceleration data */
Feb 7, 2006
Feb 7, 2006
823
surface->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*surface->hwdata));
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
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)
{
Aug 24, 2002
Aug 24, 2002
872
DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
Aug 24, 2002
Aug 24, 2002
874
875
DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h };
DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h };
Aug 24, 2002
Aug 24, 2002
877
IDirectFBSurface *surface = dst->hwdata->surface;
878
879
880
881
if (src->flags & SDL_SRCCOLORKEY)
{
flags |= DSBLIT_SRC_COLORKEY;
Nov 1, 2001
Nov 1, 2001
882
DirectFB_SetHWColorKey (NULL, src, src->format->colorkey);
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
}
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
916
static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key)
Nov 1, 2001
Nov 1, 2001
918
919
920
SDL_PixelFormat *fmt = src->format;
IDirectFBSurface *surface = src->hwdata->surface;
Aug 31, 2002
Aug 31, 2002
921
922
923
924
925
926
927
928
if (fmt->BitsPerPixel == 8)
surface->SetSrcColorKeyIndex (surface, key);
else
/* 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));
Nov 1, 2001
Nov 1, 2001
929
930
931
932
933
934
935
936
937
938
939
return 0;
}
static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha)
{
return 0;
}
static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface)
{
Oct 3, 2003
Oct 3, 2003
940
941
942
943
944
945
946
947
948
949
950
951
952
if (HIDDEN->enable_mga_crtc2)
{
int rtn = surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 0);
if (HIDDEN->mga_crtc2_stretch)
HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
else
HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
return rtn;
}
else
return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC);
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
}
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)
{
Oct 3, 2003
Oct 3, 2003
983
984
985
986
987
988
989
990
991
if (HIDDEN->enable_mga_crtc2)
{
if (HIDDEN->mga_crtc2_stretch)
HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, this->screen->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize);
else
HIDDEN->c2frame->Blit(HIDDEN->c2frame, this->screen->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
}
992
993
994
995
}
static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
{
Feb 26, 2002
Feb 26, 2002
996
997
998
DFBRegion region;
int i;
int region_valid = 0;
999
1000
IDirectFBSurface *surface = this->screen->hwdata->surface;