comparison src/video/directfb/SDL_DirectFB_video.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 402d5ff1cf88
children 6264c973814a
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
43 #include "SDL_DirectFB_video.h" 43 #include "SDL_DirectFB_video.h"
44 #include "SDL_DirectFB_events.h" 44 #include "SDL_DirectFB_events.h"
45 #include "SDL_DirectFB_yuv.h" 45 #include "SDL_DirectFB_yuv.h"
46 46
47 /* The implementation dependent data for the window manager cursor */ 47 /* The implementation dependent data for the window manager cursor */
48 struct WMcursor { 48 struct WMcursor
49 int unused; 49 {
50 int unused;
50 }; 51 };
51 52
52 53
53 /* Initialization/Query functions */ 54 /* Initialization/Query functions */
54 static int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat); 55 static int DirectFB_VideoInit(_THIS, SDL_PixelFormat * vformat);
55 static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 56 static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat * format,
56 static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 57 Uint32 flags);
58 static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface * current,
59 int width, int height, int bpp,
60 Uint32 flags);
57 static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, 61 static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors,
58 SDL_Color *colors); 62 SDL_Color * colors);
59 static void DirectFB_VideoQuit(_THIS); 63 static void DirectFB_VideoQuit(_THIS);
60 64
61 /* Hardware surface functions */ 65 /* Hardware surface functions */
62 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface); 66 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface * surface);
63 static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); 67 static int DirectFB_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
64 static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface); 68 Uint32 color);
65 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface); 69 static int DirectFB_LockHWSurface(_THIS, SDL_Surface * surface);
66 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface); 70 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface * surface);
67 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst); 71 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface * surface);
68 static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, 72 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
69 SDL_Surface *dst, SDL_Rect *dstrect); 73 static int DirectFB_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
70 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key); 74 SDL_Surface * dst, SDL_Rect * dstrect);
71 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha); 75 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface * surface, Uint32 key);
72 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface); 76 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha);
73 static int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor); 77 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface * surface);
78 static int DirectFB_ShowWMCursor(_THIS, WMcursor * cursor);
74 79
75 /* Various screen update functions available */ 80 /* Various screen update functions available */
76 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); 81 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
77 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects); 82 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect * rects);
78 83
79 /* This is the rect EnumModes2 uses */ 84 /* This is the rect EnumModes2 uses */
80 struct DirectFBEnumRect { 85 struct DirectFBEnumRect
81 SDL_Rect r; 86 {
82 struct DirectFBEnumRect* next; 87 SDL_Rect r;
88 struct DirectFBEnumRect *next;
83 }; 89 };
84 90
85 static struct DirectFBEnumRect *enumlist = NULL; 91 static struct DirectFBEnumRect *enumlist = NULL;
86 92
87 93
88 /* DirectFB driver bootstrap functions */ 94 /* DirectFB driver bootstrap functions */
89 95
90 static int DirectFB_Available(void) 96 static int
91 { 97 DirectFB_Available(void)
92 return 1; 98 {
93 } 99 return 1;
94 100 }
95 static void DirectFB_DeleteDevice(SDL_VideoDevice *device) 101
96 { 102 static void
97 SDL_free(device->hidden); 103 DirectFB_DeleteDevice(SDL_VideoDevice * device)
98 SDL_free(device); 104 {
99 } 105 SDL_free(device->hidden);
100 106 SDL_free(device);
101 static SDL_VideoDevice *DirectFB_CreateDevice(int devindex) 107 }
102 { 108
103 SDL_VideoDevice *device; 109 static SDL_VideoDevice *
104 110 DirectFB_CreateDevice(int devindex)
105 /* Initialize all variables that we clean on shutdown */ 111 {
106 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 112 SDL_VideoDevice *device;
107 if (device) 113
108 { 114 /* Initialize all variables that we clean on shutdown */
109 SDL_memset (device, 0, (sizeof *device)); 115 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
110 device->hidden = (struct SDL_PrivateVideoData *) malloc (sizeof (*device->hidden)); 116 if (device) {
111 } 117 SDL_memset(device, 0, (sizeof *device));
112 if (device == NULL || device->hidden == NULL) 118 device->hidden = (struct SDL_PrivateVideoData *)
113 { 119 malloc(sizeof(*device->hidden));
114 SDL_OutOfMemory(); 120 }
115 if (device) 121 if (device == NULL || device->hidden == NULL) {
116 { 122 SDL_OutOfMemory();
117 free (device); 123 if (device) {
118 } 124 free(device);
119 return(0); 125 }
120 } 126 return (0);
121 SDL_memset (device->hidden, 0, sizeof (*device->hidden)); 127 }
122 128 SDL_memset(device->hidden, 0, sizeof(*device->hidden));
123 /* Set the function pointers */ 129
124 device->VideoInit = DirectFB_VideoInit; 130 /* Set the function pointers */
125 device->ListModes = DirectFB_ListModes; 131 device->VideoInit = DirectFB_VideoInit;
126 device->SetVideoMode = DirectFB_SetVideoMode; 132 device->ListModes = DirectFB_ListModes;
127 device->SetColors = DirectFB_SetColors; 133 device->SetVideoMode = DirectFB_SetVideoMode;
128 device->UpdateRects = NULL; 134 device->SetColors = DirectFB_SetColors;
129 device->CreateYUVOverlay = DirectFB_CreateYUVOverlay; 135 device->UpdateRects = NULL;
130 device->VideoQuit = DirectFB_VideoQuit; 136 device->CreateYUVOverlay = DirectFB_CreateYUVOverlay;
131 device->AllocHWSurface = DirectFB_AllocHWSurface; 137 device->VideoQuit = DirectFB_VideoQuit;
132 device->CheckHWBlit = DirectFB_CheckHWBlit; 138 device->AllocHWSurface = DirectFB_AllocHWSurface;
133 device->FillHWRect = DirectFB_FillHWRect; 139 device->CheckHWBlit = DirectFB_CheckHWBlit;
134 device->SetHWColorKey = DirectFB_SetHWColorKey; 140 device->FillHWRect = DirectFB_FillHWRect;
135 device->SetHWAlpha = DirectFB_SetHWAlpha; 141 device->SetHWColorKey = DirectFB_SetHWColorKey;
136 device->LockHWSurface = DirectFB_LockHWSurface; 142 device->SetHWAlpha = DirectFB_SetHWAlpha;
137 device->UnlockHWSurface = DirectFB_UnlockHWSurface; 143 device->LockHWSurface = DirectFB_LockHWSurface;
138 device->FlipHWSurface = DirectFB_FlipHWSurface; 144 device->UnlockHWSurface = DirectFB_UnlockHWSurface;
139 device->FreeHWSurface = DirectFB_FreeHWSurface; 145 device->FlipHWSurface = DirectFB_FlipHWSurface;
140 device->ShowWMCursor = DirectFB_ShowWMCursor; 146 device->FreeHWSurface = DirectFB_FreeHWSurface;
141 device->SetCaption = NULL; 147 device->ShowWMCursor = DirectFB_ShowWMCursor;
142 device->SetIcon = NULL; 148 device->SetCaption = NULL;
143 device->IconifyWindow = NULL; 149 device->SetIcon = NULL;
144 device->GrabInput = NULL; 150 device->IconifyWindow = NULL;
145 device->GetWMInfo = NULL; 151 device->GrabInput = NULL;
146 device->InitOSKeymap = DirectFB_InitOSKeymap; 152 device->GetWMInfo = NULL;
147 device->PumpEvents = DirectFB_PumpEvents; 153 device->InitOSKeymap = DirectFB_InitOSKeymap;
148 154 device->PumpEvents = DirectFB_PumpEvents;
149 device->free = DirectFB_DeleteDevice; 155
150 156 device->free = DirectFB_DeleteDevice;
151 return device; 157
158 return device;
152 } 159 }
153 160
154 VideoBootStrap DirectFB_bootstrap = { 161 VideoBootStrap DirectFB_bootstrap = {
155 "directfb", "DirectFB", 162 "directfb", "DirectFB",
156 DirectFB_Available, DirectFB_CreateDevice 163 DirectFB_Available, DirectFB_CreateDevice
157 }; 164 };
158 165
159 static DFBSurfacePixelFormat GetFormatForBpp (int bpp, IDirectFBDisplayLayer *layer) 166 static DFBSurfacePixelFormat
160 { 167 GetFormatForBpp(int bpp, IDirectFBDisplayLayer * layer)
161 DFBDisplayLayerConfig dlc; 168 {
162 int bytes = (bpp + 7) / 8; 169 DFBDisplayLayerConfig dlc;
163 170 int bytes = (bpp + 7) / 8;
164 layer->GetConfiguration (layer, &dlc); 171
165 172 layer->GetConfiguration(layer, &dlc);
166 if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1) 173
167 return dlc.pixelformat; 174 if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1)
168 175 return dlc.pixelformat;
169 switch (bytes) 176
170 { 177 switch (bytes) {
171 case 1: 178 case 1:
172 return DSPF_LUT8; 179 return DSPF_LUT8;
173 case 2: 180 case 2:
174 return DSPF_RGB16; 181 return DSPF_RGB16;
175 case 3: 182 case 3:
176 return DSPF_RGB24; 183 return DSPF_RGB24;
177 case 4: 184 case 4:
178 return DSPF_RGB32; 185 return DSPF_RGB32;
179 } 186 }
180 187
181 return DSPF_UNKNOWN; 188 return DSPF_UNKNOWN;
182 } 189 }
183 190
184 static DFBEnumerationResult EnumModesCallback (int width, 191 static DFBEnumerationResult
185 int height, 192 EnumModesCallback(int width, int height, int bpp, void *data)
186 int bpp, 193 {
187 void *data) 194 SDL_VideoDevice *this = (SDL_VideoDevice *) data;
188 { 195 struct DirectFBEnumRect *enumrect;
189 SDL_VideoDevice *this = (SDL_VideoDevice *)data; 196
190 struct DirectFBEnumRect *enumrect; 197 HIDDEN->nummodes++;
191 198
192 HIDDEN->nummodes++; 199 if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
193 200 return DFENUM_OK;
194 if (enumlist && enumlist->r.w == width && enumlist->r.h == height) 201
202 enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
203 if (!enumrect) {
204 SDL_OutOfMemory();
205 return DFENUM_CANCEL;
206 }
207
208 enumrect->r.w = (Uint16) width;
209 enumrect->r.h = (Uint16) height;
210 enumrect->next = enumlist;
211
212 enumlist = enumrect;
213
195 return DFENUM_OK; 214 return DFENUM_OK;
196 215 }
197 enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect)); 216
198 if (!enumrect) 217 struct private_hwdata
199 { 218 {
200 SDL_OutOfMemory(); 219 IDirectFBSurface *surface;
201 return DFENUM_CANCEL; 220 IDirectFBPalette *palette;
202 }
203
204 enumrect->r.w = (Uint16)width;
205 enumrect->r.h = (Uint16)height;
206 enumrect->next = enumlist;
207
208 enumlist = enumrect;
209
210 return DFENUM_OK;
211 }
212
213 struct private_hwdata {
214 IDirectFBSurface *surface;
215 IDirectFBPalette *palette;
216 }; 221 };
217 222
218 void SetDirectFBerror (const char *function, DFBResult code) 223 void
219 { 224 SetDirectFBerror(const char *function, DFBResult code)
220 const char *error = DirectFBErrorString (code); 225 {
221 226 const char *error = DirectFBErrorString(code);
222 if (error) 227
223 SDL_SetError("%s: %s", function, error); 228 if (error)
224 else 229 SDL_SetError("%s: %s", function, error);
225 SDL_SetError("Unknown error code from %s", function); 230 else
226 } 231 SDL_SetError("Unknown error code from %s", function);
227 232 }
228 static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format) 233
229 { 234 static DFBSurfacePixelFormat
230 if (format->Rmask && format->Gmask && format->Bmask) 235 SDLToDFBPixelFormat(SDL_PixelFormat * format)
231 { 236 {
232 switch (format->BitsPerPixel) 237 if (format->Rmask && format->Gmask && format->Bmask) {
233 { 238 switch (format->BitsPerPixel) {
234 case 8: 239 case 8:
235 return DSPF_LUT8; 240 return DSPF_LUT8;
236 241
237 case 16: 242 case 16:
238 if (format->Rmask == 0xF800 && 243 if (format->Rmask == 0xF800 &&
239 format->Gmask == 0x07E0 && 244 format->Gmask == 0x07E0 && format->Bmask == 0x001F)
240 format->Bmask == 0x001F) 245 return DSPF_RGB16;
246 /* fall through */
247
248 case 15:
249 if (format->Rmask == 0x7C00 &&
250 format->Gmask == 0x03E0 && format->Bmask == 0x001F)
251 return DSPF_ARGB1555;
252 break;
253
254 case 24:
255 if (format->Rmask == 0xFF0000 &&
256 format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF)
257 return DSPF_RGB24;
258 break;
259
260 case 32:
261 if (format->Rmask == 0xFF0000 &&
262 format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) {
263 if (format->Amask == 0xFF000000)
264 return DSPF_ARGB;
265 else
266 return DSPF_RGB32;
267 }
268 break;
269 }
270 } else {
271 switch (format->BitsPerPixel) {
272 case 8:
273 return DSPF_LUT8;
274 case 15:
275 return DSPF_ARGB1555;
276 case 16:
241 return DSPF_RGB16; 277 return DSPF_RGB16;
242 /* fall through */
243
244 case 15:
245 if (format->Rmask == 0x7C00 &&
246 format->Gmask == 0x03E0 &&
247 format->Bmask == 0x001F)
248 return DSPF_ARGB1555;
249 break;
250
251 case 24: 278 case 24:
252 if (format->Rmask == 0xFF0000 &&
253 format->Gmask == 0x00FF00 &&
254 format->Bmask == 0x0000FF)
255 return DSPF_RGB24; 279 return DSPF_RGB24;
256 break;
257
258 case 32: 280 case 32:
259 if (format->Rmask == 0xFF0000 && 281 return DSPF_RGB32;
260 format->Gmask == 0x00FF00 && 282 }
261 format->Bmask == 0x0000FF) 283 }
262 { 284
263 if (format->Amask == 0xFF000000) 285 return DSPF_UNKNOWN;
264 return DSPF_ARGB; 286 }
265 else 287
266 return DSPF_RGB32; 288 static SDL_Palette *
267 } 289 AllocatePalette(int size)
268 break; 290 {
269 } 291 SDL_Palette *palette;
270 } 292 SDL_Color *colors;
271 else 293
272 { 294 palette = SDL_calloc(1, sizeof(SDL_Palette));
273 switch (format->BitsPerPixel) 295 if (!palette) {
274 { 296 SDL_OutOfMemory();
275 case 8: 297 return NULL;
276 return DSPF_LUT8; 298 }
277 case 15: 299
278 return DSPF_ARGB1555; 300 colors = SDL_calloc(size, sizeof(SDL_Color));
279 case 16: 301 if (!colors) {
280 return DSPF_RGB16; 302 SDL_OutOfMemory();
281 case 24: 303 return NULL;
282 return DSPF_RGB24; 304 }
283 case 32: 305
284 return DSPF_RGB32; 306 palette->ncolors = size;
285 } 307 palette->colors = colors;
286 } 308
287 309 return palette;
288 return DSPF_UNKNOWN; 310 }
289 } 311
290 312 static int
291 static SDL_Palette *AllocatePalette(int size) 313 DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat,
292 { 314 SDL_PixelFormat * format)
293 SDL_Palette *palette; 315 {
294 SDL_Color *colors; 316 format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
295 317 format->BitsPerPixel = format->BytesPerPixel = 0;
296 palette = SDL_calloc (1, sizeof(SDL_Palette)); 318
297 if (!palette) 319 switch (pixelformat) {
298 {
299 SDL_OutOfMemory();
300 return NULL;
301 }
302
303 colors = SDL_calloc (size, sizeof(SDL_Color));
304 if (!colors)
305 {
306 SDL_OutOfMemory();
307 return NULL;
308 }
309
310 palette->ncolors = size;
311 palette->colors = colors;
312
313 return palette;
314 }
315
316 static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelFormat *format)
317 {
318 format->Amask = format->Rmask = format->Gmask = format->Bmask = 0;
319 format->BitsPerPixel = format->BytesPerPixel = 0;
320
321 switch (pixelformat)
322 {
323 case DSPF_A8: 320 case DSPF_A8:
324 format->Amask = 0x000000FF; 321 format->Amask = 0x000000FF;
325 break; 322 break;
326 323
327 case DSPF_ARGB1555: 324 case DSPF_ARGB1555:
328 format->Rmask = 0x00007C00; 325 format->Rmask = 0x00007C00;
329 format->Gmask = 0x000003E0; 326 format->Gmask = 0x000003E0;
330 format->Bmask = 0x0000001F; 327 format->Bmask = 0x0000001F;
331 break; 328 break;
332 329
333 case DSPF_RGB16: 330 case DSPF_RGB16:
334 format->Rmask = 0x0000F800; 331 format->Rmask = 0x0000F800;
335 format->Gmask = 0x000007E0; 332 format->Gmask = 0x000007E0;
336 format->Bmask = 0x0000001F; 333 format->Bmask = 0x0000001F;
337 break; 334 break;
338 335
339 case DSPF_ARGB: 336 case DSPF_ARGB:
340 format->Amask = 0; /* apps don't seem to like that: 0xFF000000; */ 337 format->Amask = 0; /* apps don't seem to like that: 0xFF000000; */
341 /* fall through */ 338 /* fall through */
342 case DSPF_RGB24: 339 case DSPF_RGB24:
343 case DSPF_RGB32: 340 case DSPF_RGB32:
344 format->Rmask = 0x00FF0000; 341 format->Rmask = 0x00FF0000;
345 format->Gmask = 0x0000FF00; 342 format->Gmask = 0x0000FF00;
346 format->Bmask = 0x000000FF; 343 format->Bmask = 0x000000FF;
347 break; 344 break;
348 345
349 case DSPF_LUT8: 346 case DSPF_LUT8:
350 format->Rmask = 0x000000FF; 347 format->Rmask = 0x000000FF;
351 format->Gmask = 0x000000FF; 348 format->Gmask = 0x000000FF;
352 format->Bmask = 0x000000FF; 349 format->Bmask = 0x000000FF;
353 350
354 if (!format->palette) 351 if (!format->palette)
355 format->palette = AllocatePalette(256); 352 format->palette = AllocatePalette(256);
356 break; 353 break;
357 354
358 default: 355 default:
359 fprintf (stderr, "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n", pixelformat); 356 fprintf(stderr,
360 return -1; 357 "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n",
361 } 358 pixelformat);
362 359 return -1;
363 format->BitsPerPixel = DFB_BYTES_PER_PIXEL(pixelformat) * 8; 360 }
364 format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat); 361
365 362 format->BitsPerPixel = DFB_BYTES_PER_PIXEL(pixelformat) * 8;
366 return 0; 363 format->BytesPerPixel = DFB_BYTES_PER_PIXEL(pixelformat);
367 } 364
368 365 return 0;
369 366 }
370 int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat) 367
371 { 368
372 int i; 369 int
373 DFBResult ret; 370 DirectFB_VideoInit(_THIS, SDL_PixelFormat * vformat)
371 {
372 int i;
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;
376 #else 376 #else
377 DFBGraphicsDeviceDescription caps; 377 DFBGraphicsDeviceDescription caps;
378 #endif 378 #endif
379 DFBDisplayLayerConfig dlc; 379 DFBDisplayLayerConfig dlc;
380 struct DirectFBEnumRect *rect; 380 struct DirectFBEnumRect *rect;
381 IDirectFB *dfb = NULL; 381 IDirectFB *dfb = NULL;
382 IDirectFBDisplayLayer *layer = NULL; 382 IDirectFBDisplayLayer *layer = NULL;
383 IDirectFBEventBuffer *events = NULL; 383 IDirectFBEventBuffer *events = NULL;
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 { 391 SetDirectFBerror("DirectFBInit", ret);
392 SetDirectFBerror ("DirectFBInit", ret); 392 goto error;
393 goto error; 393 }
394 } 394
395 395 ret = DirectFBCreate(&dfb);
396 ret = DirectFBCreate (&dfb); 396 if (ret) {
397 if (ret) 397 SetDirectFBerror("DirectFBCreate", ret);
398 { 398 goto error;
399 SetDirectFBerror ("DirectFBCreate", ret); 399 }
400 goto error; 400
401 } 401 ret = dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer);
402 402 if (ret) {
403 ret = dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer); 403 SetDirectFBerror("dfb->GetDisplayLayer", ret);
404 if (ret) 404 goto error;
405 { 405 }
406 SetDirectFBerror ("dfb->GetDisplayLayer", ret); 406
407 goto error; 407 ret = dfb->CreateInputEventBuffer(dfb, DICAPS_ALL, DFB_FALSE, &events);
408 } 408 if (ret) {
409 409 SetDirectFBerror("dfb->CreateEventBuffer", ret);
410 ret = dfb->CreateInputEventBuffer (dfb, DICAPS_ALL, DFB_FALSE, &events); 410 goto error;
411 if (ret) 411 }
412 { 412
413 SetDirectFBerror ("dfb->CreateEventBuffer", ret); 413 layer->EnableCursor(layer, 1);
414 goto error; 414
415 } 415 /* Query layer configuration to determine the current mode and pixelformat */
416 416 layer->GetConfiguration(layer, &dlc);
417 layer->EnableCursor (layer, 1); 417
418 418 /* If current format is not supported use LUT8 as the default */
419 /* Query layer configuration to determine the current mode and pixelformat */ 419 if (DFBToSDLPixelFormat(dlc.pixelformat, vformat))
420 layer->GetConfiguration (layer, &dlc); 420 DFBToSDLPixelFormat(DSPF_LUT8, vformat);
421 421
422 /* If current format is not supported use LUT8 as the default */ 422 /* Enumerate the available fullscreen modes */
423 if (DFBToSDLPixelFormat (dlc.pixelformat, vformat)) 423 ret = dfb->EnumVideoModes(dfb, EnumModesCallback, this);
424 DFBToSDLPixelFormat (DSPF_LUT8, vformat); 424 if (ret) {
425 425 SetDirectFBerror("dfb->EnumVideoModes", ret);
426 /* Enumerate the available fullscreen modes */ 426 goto error;
427 ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this); 427 }
428 if (ret) 428
429 { 429 HIDDEN->modelist = SDL_calloc(HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
430 SetDirectFBerror ("dfb->EnumVideoModes", ret); 430 if (!HIDDEN->modelist) {
431 goto error; 431 SDL_OutOfMemory();
432 } 432 goto error;
433 433 }
434 HIDDEN->modelist = SDL_calloc (HIDDEN->nummodes + 1, sizeof(SDL_Rect *)); 434
435 if (!HIDDEN->modelist) 435 for (i = 0, rect = enumlist; rect; ++i, rect = rect->next) {
436 { 436 HIDDEN->modelist[i] = &rect->r;
437 SDL_OutOfMemory(); 437 }
438 goto error; 438
439 } 439 HIDDEN->modelist[i] = NULL;
440 440
441 for (i = 0, rect = enumlist; rect; ++i, rect = rect->next ) 441
442 { 442 /* Query card capabilities to get the video memory size */
443 HIDDEN->modelist[i] = &rect->r;
444 }
445
446 HIDDEN->modelist[i] = NULL;
447
448
449 /* Query card capabilities to get the video memory size */
450 #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)
451 dfb->GetCardCapabilities (dfb, &caps); 444 dfb->GetCardCapabilities(dfb, &caps);
452 #else 445 #else
453 dfb->GetDeviceDescription (dfb, &caps); 446 dfb->GetDeviceDescription(dfb, &caps);
454 #endif 447 #endif
455 448
456 this->info.wm_available = 1; 449 this->info.wm_available = 1;
457 this->info.hw_available = 1; 450 this->info.hw_available = 1;
458 this->info.blit_hw = 1; 451 this->info.blit_hw = 1;
459 this->info.blit_hw_CC = 1; 452 this->info.blit_hw_CC = 1;
460 this->info.blit_hw_A = 1; 453 this->info.blit_hw_A = 1;
461 this->info.blit_fill = 1; 454 this->info.blit_fill = 1;
462 this->info.video_mem = caps.video_memory / 1024; 455 this->info.video_mem = caps.video_memory / 1024;
463 456
464 HIDDEN->initialized = 1; 457 HIDDEN->initialized = 1;
465 HIDDEN->dfb = dfb; 458 HIDDEN->dfb = dfb;
466 HIDDEN->layer = layer; 459 HIDDEN->layer = layer;
467 HIDDEN->eventbuffer = events; 460 HIDDEN->eventbuffer = events;
468 461
469 if (SDL_getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL) 462 if (SDL_getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
470 HIDDEN->enable_mga_crtc2 = 1; 463 HIDDEN->enable_mga_crtc2 = 1;
471 464
472 if (HIDDEN->enable_mga_crtc2) 465 if (HIDDEN->enable_mga_crtc2) {
473 { 466 DFBDisplayLayerConfig dlc;
474 DFBDisplayLayerConfig dlc; 467 DFBDisplayLayerConfigFlags failed;
475 DFBDisplayLayerConfigFlags failed; 468
476 469 ret = dfb->GetDisplayLayer(dfb, 2, &HIDDEN->c2layer);
477 ret = dfb->GetDisplayLayer (dfb, 2, &HIDDEN->c2layer); 470 if (ret) {
478 if (ret) 471 SetDirectFBerror("dfb->GetDisplayLayer(CRTC2)", ret);
479 { 472 goto error;
480 SetDirectFBerror ("dfb->GetDisplayLayer(CRTC2)", ret); 473 }
481 goto error; 474
482 } 475 ret =
483 476 HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer,
484 ret = HIDDEN->layer->SetCooperativeLevel(HIDDEN->layer, DLSCL_EXCLUSIVE); 477 DLSCL_EXCLUSIVE);
485 if (ret) 478 if (ret) {
486 { 479 SetDirectFBerror
487 SetDirectFBerror ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret); 480 ("layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
488 goto error; 481 goto error;
489 } 482 }
490 483
491 ret = HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer, DLSCL_EXCLUSIVE); 484 ret =
492 if (ret) 485 HIDDEN->c2layer->SetCooperativeLevel(HIDDEN->c2layer,
493 { 486 DLSCL_EXCLUSIVE);
494 SetDirectFBerror ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret); 487 if (ret) {
495 goto error; 488 SetDirectFBerror
496 } 489 ("c2layer->SetCooperativeLevel(CRTC2, EXCLUSIVE)", ret);
497 490 goto error;
498 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0); 491 }
499 492
500 /* Init the surface here as it got a fixed size */ 493 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0x0);
501 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE; 494
502 dlc.buffermode = DLBM_BACKVIDEO; 495 /* Init the surface here as it got a fixed size */
503 dlc.pixelformat = DSPF_RGB32; 496 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE;
504 497 dlc.buffermode = DLBM_BACKVIDEO;
505 ret = HIDDEN->c2layer->TestConfiguration( HIDDEN->c2layer, &dlc, &failed ); 498 dlc.pixelformat = DSPF_RGB32;
506 if (ret) 499
507 { 500 ret =
508 SetDirectFBerror ("c2layer->TestConfiguration", ret); 501 HIDDEN->c2layer->TestConfiguration(HIDDEN->c2layer, &dlc,
509 goto error; 502 &failed);
510 } 503 if (ret) {
511 504 SetDirectFBerror("c2layer->TestConfiguration", ret);
512 ret = HIDDEN->c2layer->SetConfiguration( HIDDEN->c2layer, &dlc ); 505 goto error;
513 if (ret) 506 }
514 { 507
515 SetDirectFBerror ("c2layer->SetConfiguration", ret); 508 ret = HIDDEN->c2layer->SetConfiguration(HIDDEN->c2layer, &dlc);
516 goto error; 509 if (ret) {
517 } 510 SetDirectFBerror("c2layer->SetConfiguration", ret);
518 511 goto error;
519 ret = HIDDEN->c2layer->GetSurface( HIDDEN->c2layer, &HIDDEN->c2frame ); 512 }
520 if (ret) 513
521 { 514 ret = HIDDEN->c2layer->GetSurface(HIDDEN->c2layer, &HIDDEN->c2frame);
522 SetDirectFBerror ("c2layer->GetSurface", ret); 515 if (ret) {
523 goto error; 516 SetDirectFBerror("c2layer->GetSurface", ret);
524 } 517 goto error;
525 518 }
526 HIDDEN->c2framesize.x = 0; 519
527 HIDDEN->c2framesize.y = 0; 520 HIDDEN->c2framesize.x = 0;
528 HIDDEN->c2frame->GetSize( HIDDEN->c2frame, &HIDDEN->c2framesize.w, &HIDDEN->c2framesize.h); 521 HIDDEN->c2framesize.y = 0;
529 522 HIDDEN->c2frame->GetSize(HIDDEN->c2frame, &HIDDEN->c2framesize.w,
530 HIDDEN->c2frame->SetBlittingFlags( HIDDEN->c2frame, DSBLIT_NOFX ); 523 &HIDDEN->c2framesize.h);
531 HIDDEN->c2frame->SetColor( HIDDEN->c2frame, 0, 0, 0, 0xff ); 524
532 525 HIDDEN->c2frame->SetBlittingFlags(HIDDEN->c2frame, DSBLIT_NOFX);
533 /* Clear CRTC2 */ 526 HIDDEN->c2frame->SetColor(HIDDEN->c2frame, 0, 0, 0, 0xff);
534 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff ); 527
535 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 ); 528 /* Clear CRTC2 */
536 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff ); 529 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
537 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 ); 530 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0);
538 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff ); 531 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
539 532 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0);
540 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF ); 533 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff);
541 534
542 /* Check if overscan is possibly set */ 535 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF);
543 if (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL) 536
544 { 537 /* Check if overscan is possibly set */
545 float overscan = 0; 538 if (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL) {
546 if (SDL_sscanf(SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1) 539 float overscan = 0;
547 if (overscan > 0 && overscan < 2) 540 if (SDL_sscanf
548 HIDDEN->mga_crtc2_stretch_overscan = overscan; 541 (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f",
549 } 542 &overscan) == 1)
550 543 if (overscan > 0 && overscan < 2)
551 #ifdef DIRECTFB_CRTC2_DEBUG 544 HIDDEN->mga_crtc2_stretch_overscan = overscan;
552 printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan); 545 }
553 #endif 546 #ifdef DIRECTFB_CRTC2_DEBUG
554 } 547 printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
555 548 #endif
556 return 0; 549 }
557 550
558 error: 551 return 0;
559 if (events) 552
560 events->Release (events); 553 error:
561 554 if (events)
562 if (HIDDEN->c2frame) 555 events->Release(events);
563 HIDDEN->c2frame->Release (HIDDEN->c2frame); 556
564 557 if (HIDDEN->c2frame)
565 if (HIDDEN->c2layer) 558 HIDDEN->c2frame->Release(HIDDEN->c2frame);
566 HIDDEN->c2layer->Release (HIDDEN->c2layer); 559
567 560 if (HIDDEN->c2layer)
568 if (layer) 561 HIDDEN->c2layer->Release(HIDDEN->c2layer);
569 layer->Release (layer); 562
570 563 if (layer)
571 if (dfb) 564 layer->Release(layer);
572 dfb->Release (dfb); 565
573 566 if (dfb)
574 return -1; 567 dfb->Release(dfb);
575 } 568
576 569 return -1;
577 static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 570 }
578 { 571
579 if (flags & SDL_FULLSCREEN) 572 static SDL_Rect **
580 return HIDDEN->modelist; 573 DirectFB_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
581 else 574 {
582 if (SDLToDFBPixelFormat (format) != DSPF_UNKNOWN) 575 if (flags & SDL_FULLSCREEN)
583 return (SDL_Rect**) -1; 576 return HIDDEN->modelist;
584 577 else if (SDLToDFBPixelFormat(format) != DSPF_UNKNOWN)
585 return NULL; 578 return (SDL_Rect **) - 1;
586 } 579
587 580 return NULL;
588 static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) 581 }
589 { 582
590 DFBResult ret; 583 static SDL_Surface *
591 DFBSurfaceDescription dsc; 584 DirectFB_SetVideoMode(_THIS, SDL_Surface * current, int width, int height,
592 DFBSurfacePixelFormat pixelformat; 585 int bpp, Uint32 flags)
593 IDirectFBSurface *surface; 586 {
594 587 DFBResult ret;
595 fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n", 588 DFBSurfaceDescription dsc;
596 width, height, bpp, flags); 589 DFBSurfacePixelFormat pixelformat;
597 590 IDirectFBSurface *surface;
598 flags |= SDL_FULLSCREEN; 591
599 592 fprintf(stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
600 /* Release previous primary surface */ 593 width, height, bpp, flags);
601 if (current->hwdata && current->hwdata->surface) 594
602 { 595 flags |= SDL_FULLSCREEN;
603 current->hwdata->surface->Release (current->hwdata->surface); 596
604 current->hwdata->surface = NULL; 597 /* Release previous primary surface */
605 598 if (current->hwdata && current->hwdata->surface) {
606 /* And its palette if present */ 599 current->hwdata->surface->Release(current->hwdata->surface);
607 if (current->hwdata->palette) 600 current->hwdata->surface = NULL;
608 { 601
609 current->hwdata->palette->Release (current->hwdata->palette); 602 /* And its palette if present */
610 current->hwdata->palette = NULL; 603 if (current->hwdata->palette) {
611 } 604 current->hwdata->palette->Release(current->hwdata->palette);
612 } 605 current->hwdata->palette = NULL;
613 else if (!current->hwdata) 606 }
614 { 607 } else if (!current->hwdata) {
615 /* Allocate the hardware acceleration data */ 608 /* Allocate the hardware acceleration data */
616 current->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*current->hwdata)); 609 current->hwdata =
617 if (!current->hwdata) 610 (struct private_hwdata *) SDL_calloc(1, sizeof(*current->hwdata));
618 { 611 if (!current->hwdata) {
619 SDL_OutOfMemory(); 612 SDL_OutOfMemory();
620 return NULL; 613 return NULL;
621 } 614 }
622 } 615 }
623 616
624 /* Set cooperative level depending on flag SDL_FULLSCREEN */ 617 /* Set cooperative level depending on flag SDL_FULLSCREEN */
625 if (flags & SDL_FULLSCREEN) 618 if (flags & SDL_FULLSCREEN) {
626 { 619 ret = HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_FULLSCREEN);
627 ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN); 620 if (ret && !HIDDEN->enable_mga_crtc2) {
628 if (ret && !HIDDEN->enable_mga_crtc2) 621 DirectFBError("dfb->SetCooperativeLevel", ret);
629 { 622 flags &= ~SDL_FULLSCREEN;
630 DirectFBError ("dfb->SetCooperativeLevel", ret); 623 }
631 flags &= ~SDL_FULLSCREEN; 624 } else
632 } 625 HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_NORMAL);
633 } 626
634 else 627 /* Set video mode */
635 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); 628 ret = HIDDEN->dfb->SetVideoMode(HIDDEN->dfb, width, height, bpp);
636 629 if (ret) {
637 /* Set video mode */ 630 if (flags & SDL_FULLSCREEN) {
638 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); 631 flags &= ~SDL_FULLSCREEN;
639 if (ret) 632 HIDDEN->dfb->SetCooperativeLevel(HIDDEN->dfb, DFSCL_NORMAL);
640 { 633 ret = HIDDEN->dfb->SetVideoMode(HIDDEN->dfb, width, height, bpp);
641 if (flags & SDL_FULLSCREEN) 634 }
642 { 635
643 flags &= ~SDL_FULLSCREEN; 636 if (ret) {
644 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); 637 SetDirectFBerror("dfb->SetVideoMode", ret);
645 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); 638 return NULL;
646 } 639 }
647 640 }
648 if (ret) 641
649 { 642 /* Create primary surface */
650 SetDirectFBerror ("dfb->SetVideoMode", ret); 643 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
651 return NULL; 644 dsc.caps =
652 } 645 DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
653 } 646 dsc.pixelformat = GetFormatForBpp(bpp, HIDDEN->layer);
654 647
655 /* Create primary surface */ 648 ret = HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc, &surface);
656 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; 649 if (ret && (flags & SDL_DOUBLEBUF)) {
657 dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0); 650 /* Try without double buffering */
658 dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer); 651 dsc.caps &= ~DSCAPS_FLIPPING;
659 652 ret = HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc, &surface);
660 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); 653 }
661 if (ret && (flags & SDL_DOUBLEBUF)) 654 if (ret) {
662 { 655 SetDirectFBerror("dfb->CreateSurface", ret);
663 /* Try without double buffering */ 656 return NULL;
664 dsc.caps &= ~DSCAPS_FLIPPING; 657 }
665 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); 658
666 } 659 current->w = width;
667 if (ret) 660 current->h = height;
668 { 661 current->flags = SDL_HWSURFACE | SDL_PREALLOC;
669 SetDirectFBerror ("dfb->CreateSurface", ret); 662
670 return NULL; 663 if (flags & SDL_FULLSCREEN) {
671 } 664 current->flags |= SDL_FULLSCREEN;
672 665 this->UpdateRects = DirectFB_DirectUpdate;
673 current->w = width; 666 } else
674 current->h = height; 667 this->UpdateRects = DirectFB_WindowedUpdate;
675 current->flags = SDL_HWSURFACE | SDL_PREALLOC; 668
676 669 if (dsc.caps & DSCAPS_FLIPPING)
677 if (flags & SDL_FULLSCREEN) 670 current->flags |= SDL_DOUBLEBUF;
678 { 671
679 current->flags |= SDL_FULLSCREEN; 672 surface->GetPixelFormat(surface, &pixelformat);
680 this->UpdateRects = DirectFB_DirectUpdate; 673
681 } 674 DFBToSDLPixelFormat(pixelformat, current->format);
682 else 675
683 this->UpdateRects = DirectFB_WindowedUpdate; 676 /* Get the surface palette (if supported) */
684 677 if (DFB_PIXELFORMAT_IS_INDEXED(pixelformat)) {
685 if (dsc.caps & DSCAPS_FLIPPING) 678 surface->GetPalette(surface, &current->hwdata->palette);
686 current->flags |= SDL_DOUBLEBUF; 679
687 680 current->flags |= SDL_HWPALETTE;
688 surface->GetPixelFormat (surface, &pixelformat); 681 }
689 682
690 DFBToSDLPixelFormat (pixelformat, current->format); 683 current->hwdata->surface = surface;
691 684
692 /* Get the surface palette (if supported) */ 685 /* MGA CRTC2 stuff */
693 if (DFB_PIXELFORMAT_IS_INDEXED( pixelformat )) 686 if (HIDDEN->enable_mga_crtc2) {
694 { 687 /* no stretching if c2ssize == c2framesize */
695 surface->GetPalette (surface, &current->hwdata->palette); 688 HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0;
696 689 HIDDEN->c2ssize.w = width;
697 current->flags |= SDL_HWPALETTE; 690 HIDDEN->c2ssize.h = height;
698 } 691
699 692 HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0;
700 current->hwdata->surface = surface; 693 HIDDEN->c2dsize.w = width;
701 694 HIDDEN->c2dsize.h = height;
702 /* MGA CRTC2 stuff */ 695
703 if (HIDDEN->enable_mga_crtc2) 696 HIDDEN->mga_crtc2_stretch = 0;
704 { 697
705 /* no stretching if c2ssize == c2framesize */ 698 if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL) {
706 HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0; 699 /* Normally assume a picture aspect ratio of 4:3 */
707 HIDDEN->c2ssize.w = width; 700 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
708 HIDDEN->c2ssize.h = height; 701
709 702 for (i = 1; i < 20; i++) {
710 HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0; 703 for (j = 1; j < 10; j++) {
711 HIDDEN->c2dsize.w = width; 704 if ((float) width / (float) i * (float) j == height) {
712 HIDDEN->c2dsize.h = height; 705 zoom_aspect_x = i;
713 706 zoom_aspect_y = j;
714 HIDDEN->mga_crtc2_stretch = 0; 707
715 708 /* break the loop */
716 if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL) 709 i = 21;
717 { 710 break;
718 /* Normally assume a picture aspect ratio of 4:3 */ 711 }
719 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
720
721 for (i = 1; i < 20; i++)
722 {
723 for (j = 1; j < 10; j++)
724 {
725 if ((float)width/(float)i*(float)j == height)
726 {
727 zoom_aspect_x = i;
728 zoom_aspect_y = j;
729
730 /* break the loop */
731 i = 21;
732 break;
733 }
734 }
735 }
736
737 #ifdef DIRECTFB_CRTC2_DEBUG
738 printf("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", width, height, zoom_aspect_x, zoom_aspect_y);
739 printf("CRTC2 resolution: X: %d, Y: %d\n", HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
740 #endif
741
742 /* don't stretch only slightly smaller/larger images */
743 if ((float)width < (float)HIDDEN->c2framesize.w*0.95 || (float)height < (float)HIDDEN->c2framesize.h*0.95)
744 {
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)
746 {
747 HIDDEN->c2dsize.w+=zoom_aspect_x;
748 HIDDEN->c2dsize.h+=zoom_aspect_y;
749 } 712 }
750 713 }
751 /* one step down */ 714
752 HIDDEN->c2dsize.w-=zoom_aspect_x; 715 #ifdef DIRECTFB_CRTC2_DEBUG
753 HIDDEN->c2dsize.h-=zoom_aspect_y; 716 printf
754 717 ("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n",
755 #ifdef DIRECTFB_CRTC2_DEBUG 718 width, height, zoom_aspect_x, zoom_aspect_y);
756 printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); 719 printf("CRTC2 resolution: X: %d, Y: %d\n",
757 #endif 720 HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
758 721 #endif
759 HIDDEN->mga_crtc2_stretch = 1; 722
760 } 723 /* don't stretch only slightly smaller/larger images */
761 else if ((float)width > (float)HIDDEN->c2framesize.w*0.95 || (float)height > (float)HIDDEN->c2framesize.h*0.95) 724 if ((float) width < (float) HIDDEN->c2framesize.w * 0.95
762 { 725 || (float) height < (float) HIDDEN->c2framesize.h * 0.95) {
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) 726 while ((float) HIDDEN->c2dsize.w <
764 { 727 (float) HIDDEN->c2framesize.w *
765 HIDDEN->c2dsize.w-=zoom_aspect_x; 728 HIDDEN->mga_crtc2_stretch_overscan
766 HIDDEN->c2dsize.h-=zoom_aspect_y; 729 && (float) HIDDEN->c2dsize.h <
730 (float) HIDDEN->c2framesize.h *
731 HIDDEN->mga_crtc2_stretch_overscan) {
732 HIDDEN->c2dsize.w += zoom_aspect_x;
733 HIDDEN->c2dsize.h += zoom_aspect_y;
767 } 734 }
768 735
769 #ifdef DIRECTFB_CRTC2_DEBUG 736 /* one step down */
770 printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); 737 HIDDEN->c2dsize.w -= zoom_aspect_x;
771 #endif 738 HIDDEN->c2dsize.h -= zoom_aspect_y;
772 739
773 HIDDEN->mga_crtc2_stretch = 1; 740 #ifdef DIRECTFB_CRTC2_DEBUG
774 } else { 741 printf("Stretched resolution: X: %d, Y: %d\n",
775 #ifdef DIRECTFB_CRTC2_DEBUG 742 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
776 printf("Not stretching image\n"); 743 #endif
777 #endif 744
778 } 745 HIDDEN->mga_crtc2_stretch = 1;
779 746 } else if ((float) width > (float) HIDDEN->c2framesize.w * 0.95
780 /* Panning */ 747 || (float) height >
781 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w) 748 (float) HIDDEN->c2framesize.h * 0.95) {
782 HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2; 749 while ((float) HIDDEN->c2dsize.w >
783 else 750 (float) HIDDEN->c2framesize.w *
784 HIDDEN->c2dsize.x = (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2; 751 HIDDEN->mga_crtc2_stretch_overscan
785 752 || (float) HIDDEN->c2dsize.h >
786 if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h) 753 (float) HIDDEN->c2framesize.h *
787 HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2; 754 HIDDEN->mga_crtc2_stretch_overscan) {
788 else 755 HIDDEN->c2dsize.w -= zoom_aspect_x;
789 HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2; 756 HIDDEN->c2dsize.h -= zoom_aspect_y;
790 757 }
791 #ifdef DIRECTFB_CRTC2_DEBUG 758
792 printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 759 #ifdef DIRECTFB_CRTC2_DEBUG
793 #endif 760 printf("Down-Stretched resolution: X: %d, Y: %d\n",
794 } 761 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
795 } 762 #endif
796 763
797 return current; 764 HIDDEN->mga_crtc2_stretch = 1;
798 } 765 } else {
799 766 #ifdef DIRECTFB_CRTC2_DEBUG
800 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface) 767 printf("Not stretching image\n");
801 { 768 #endif
802 DFBResult ret; 769 }
803 DFBSurfaceDescription dsc; 770
804 771 /* Panning */
805 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n", 772 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
806 surface->w, surface->h, surface->format->BitsPerPixel, surface->flags);*/ 773 HIDDEN->c2dsize.x =
807 774 (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2;
808 if (surface->w < 8 || surface->h < 8) 775 else
809 return -1; 776 HIDDEN->c2dsize.x =
810 777 (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2;
811 /* fill surface description */ 778
812 dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; 779 if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h)
813 dsc.width = surface->w; 780 HIDDEN->c2dsize.y =
814 dsc.height = surface->h; 781 (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2;
815 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0; 782 else
816 783 HIDDEN->c2dsize.y =
817 /* find the right pixelformat */ 784 (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;
818 dsc.pixelformat = SDLToDFBPixelFormat (surface->format); 785
819 if (dsc.pixelformat == DSPF_UNKNOWN) 786 #ifdef DIRECTFB_CRTC2_DEBUG
820 return -1; 787 printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x,
821 788 HIDDEN->c2dsize.y);
822 /* Allocate the hardware acceleration data */ 789 #endif
823 surface->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*surface->hwdata)); 790 }
824 if (surface->hwdata == NULL) 791 }
825 { 792
826 SDL_OutOfMemory(); 793 return current;
827 return -1; 794 }
828 } 795
829 796 static int
830 /* Create the surface */ 797 DirectFB_AllocHWSurface(_THIS, SDL_Surface * surface)
831 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface->hwdata->surface); 798 {
832 if (ret) 799 DFBResult ret;
833 { 800 DFBSurfaceDescription dsc;
834 SetDirectFBerror ("dfb->CreateSurface", ret); 801
835 free (surface->hwdata); 802 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n",
836 surface->hwdata = NULL; 803 surface->w, surface->h, surface->format->BitsPerPixel, surface->flags); */
837 return -1; 804
838 } 805 if (surface->w < 8 || surface->h < 8)
839 806 return -1;
840 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC; 807
841 808 /* fill surface description */
842 return 0; 809 dsc.flags =
843 } 810 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
844 811 dsc.width = surface->w;
845 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface) 812 dsc.height = surface->h;
846 { 813 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0;
847 if (surface->hwdata && HIDDEN->initialized) 814
848 { 815 /* find the right pixelformat */
849 surface->hwdata->surface->Release (surface->hwdata->surface); 816 dsc.pixelformat = SDLToDFBPixelFormat(surface->format);
850 free (surface->hwdata); 817 if (dsc.pixelformat == DSPF_UNKNOWN)
851 surface->hwdata = NULL; 818 return -1;
852 } 819
853 } 820 /* Allocate the hardware acceleration data */
854 821 surface->hwdata =
855 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) 822 (struct private_hwdata *) SDL_calloc(1, sizeof(*surface->hwdata));
856 { 823 if (surface->hwdata == NULL) {
857 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n", 824 SDL_OutOfMemory();
858 src->hwdata, dst->hwdata);*/ 825 return -1;
859 826 }
860 if (!src->hwdata || !dst->hwdata) 827
828 /* Create the surface */
829 ret =
830 HIDDEN->dfb->CreateSurface(HIDDEN->dfb, &dsc,
831 &surface->hwdata->surface);
832 if (ret) {
833 SetDirectFBerror("dfb->CreateSurface", ret);
834 free(surface->hwdata);
835 surface->hwdata = NULL;
836 return -1;
837 }
838
839 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC;
840
861 return 0; 841 return 0;
862 842 }
863 src->flags |= SDL_HWACCEL; 843
864 src->map->hw_blit = DirectFB_HWAccelBlit; 844 static void
865 845 DirectFB_FreeHWSurface(_THIS, SDL_Surface * surface)
866 return 1; 846 {
867 } 847 if (surface->hwdata && HIDDEN->initialized) {
868 848 surface->hwdata->surface->Release(surface->hwdata->surface);
869 static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, 849 free(surface->hwdata);
870 SDL_Surface *dst, SDL_Rect *dstrect) 850 surface->hwdata = NULL;
871 { 851 }
872 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; 852 }
873 853
874 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h }; 854 static int
875 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h }; 855 DirectFB_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
876 856 {
877 IDirectFBSurface *surface = dst->hwdata->surface; 857 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n",
878 858 src->hwdata, dst->hwdata); */
879 if (src->flags & SDL_SRCCOLORKEY) 859
880 { 860 if (!src->hwdata || !dst->hwdata)
881 flags |= DSBLIT_SRC_COLORKEY; 861 return 0;
882 DirectFB_SetHWColorKey (NULL, src, src->format->colorkey); 862
883 } 863 src->flags |= SDL_HWACCEL;
884 864 src->map->hw_blit = DirectFB_HWAccelBlit;
885 if (src->flags & SDL_SRCALPHA) 865
886 { 866 return 1;
887 flags |= DSBLIT_BLEND_COLORALPHA; 867 }
888 surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha); 868
889 } 869 static int
890 870 DirectFB_HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
891 surface->SetBlittingFlags (surface, flags); 871 SDL_Surface * dst, SDL_Rect * dstrect)
892 872 {
893 if (sr.w == dr.w && sr.h == dr.h) 873 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX;
894 surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y); 874
895 else 875 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h };
896 surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr); 876 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h };
897 877
898 return 0; 878 IDirectFBSurface *surface = dst->hwdata->surface;
899 } 879
900 880 if (src->flags & SDL_SRCCOLORKEY) {
901 static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) 881 flags |= DSBLIT_SRC_COLORKEY;
902 { 882 DirectFB_SetHWColorKey(NULL, src, src->format->colorkey);
903 SDL_PixelFormat *fmt = dst->format; 883 }
904 IDirectFBSurface *surface = dst->hwdata->surface; 884
905 885 if (src->flags & SDL_SRCALPHA) {
906 /* ugly */ 886 flags |= DSBLIT_BLEND_COLORALPHA;
907 surface->SetColor (surface, 887 surface->SetColor(surface, 0xff, 0xff, 0xff, src->format->alpha);
908 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss), 888 }
909 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss), 889
910 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 0xFF); 890 surface->SetBlittingFlags(surface, flags);
911 surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, dstrect->h); 891
912 892 if (sr.w == dr.w && sr.h == dr.h)
913 return 0; 893 surface->Blit(surface, src->hwdata->surface, &sr, dr.x, dr.y);
914 } 894 else
915 895 surface->StretchBlit(surface, src->hwdata->surface, &sr, &dr);
916 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key) 896
917 { 897 return 0;
918 SDL_PixelFormat *fmt = src->format; 898 }
919 IDirectFBSurface *surface = src->hwdata->surface; 899
920 900 static int
921 if (fmt->BitsPerPixel == 8) 901 DirectFB_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * dstrect,
922 surface->SetSrcColorKeyIndex (surface, key); 902 Uint32 color)
923 else 903 {
904 SDL_PixelFormat *fmt = dst->format;
905 IDirectFBSurface *surface = dst->hwdata->surface;
906
924 /* ugly */ 907 /* ugly */
925 surface->SetSrcColorKey (surface, 908 surface->SetColor(surface,
926 (key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss), 909 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
927 (key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss), 910 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
928 (key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift)); 911 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift),
929 912 0xFF);
930 return 0; 913 surface->FillRectangle(surface, dstrect->x, dstrect->y, dstrect->w,
931 } 914 dstrect->h);
932 915
933 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha) 916 return 0;
934 { 917 }
935 return 0; 918
936 } 919 static int
937 920 DirectFB_SetHWColorKey(_THIS, SDL_Surface * src, Uint32 key)
938 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface) 921 {
939 { 922 SDL_PixelFormat *fmt = src->format;
940 if (HIDDEN->enable_mga_crtc2) 923 IDirectFBSurface *surface = src->hwdata->surface;
941 { 924
942 int rtn = surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 0); 925 if (fmt->BitsPerPixel == 8)
943 if (HIDDEN->mga_crtc2_stretch) 926 surface->SetSrcColorKeyIndex(surface, key);
944 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); 927 else
945 else 928 /* ugly */
946 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 929 surface->SetSrcColorKey(surface,
947 930 (key & fmt->Rmask) >> (fmt->Rshift -
948 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); 931 fmt->Rloss),
949 return rtn; 932 (key & fmt->Gmask) >> (fmt->Gshift -
950 } 933 fmt->Gloss),
951 else 934 (key & fmt->Bmask) << (fmt->Bloss -
952 return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC); 935 fmt->Bshift));
953 } 936
954 937 return 0;
955 static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface) 938 }
956 { 939
957 DFBResult ret; 940 static int
958 void *data; 941 DirectFB_SetHWAlpha(_THIS, SDL_Surface * surface, Uint8 alpha)
959 int pitch; 942 {
960 943 return 0;
961 ret = surface->hwdata->surface->Lock (surface->hwdata->surface, 944 }
962 DSLF_WRITE, &data, &pitch); 945
963 if (ret) 946 static int
964 { 947 DirectFB_FlipHWSurface(_THIS, SDL_Surface * surface)
965 SetDirectFBerror ("surface->Lock", ret); 948 {
966 return -1; 949 if (HIDDEN->enable_mga_crtc2) {
967 } 950 int rtn =
968 951 surface->hwdata->surface->Flip(surface->hwdata->surface, NULL,
969 surface->pixels = data; 952 0);
970 surface->pitch = pitch; 953 if (HIDDEN->mga_crtc2_stretch)
971 954 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame,
972 return 0; 955 surface->hwdata->surface,
973 } 956 &HIDDEN->c2ssize, &HIDDEN->c2dsize);
974 957 else
975 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface) 958 HIDDEN->c2frame->Blit(HIDDEN->c2frame,
976 { 959 surface->hwdata->surface, NULL,
977 surface->hwdata->surface->Unlock (surface->hwdata->surface); 960 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
978 surface->pixels = NULL; 961
979 } 962 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
980 963 return rtn;
981 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) 964 } else
982 { 965 return surface->hwdata->surface->Flip(surface->hwdata->surface, NULL,
983 if (HIDDEN->enable_mga_crtc2) 966 DSFLIP_WAITFORSYNC);
984 { 967 }
985 if (HIDDEN->mga_crtc2_stretch) 968
986 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, this->screen->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); 969 static int
987 else 970 DirectFB_LockHWSurface(_THIS, SDL_Surface * surface)
988 HIDDEN->c2frame->Blit(HIDDEN->c2frame, this->screen->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 971 {
989 972 DFBResult ret;
990 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); 973 void *data;
991 } 974 int pitch;
992 } 975
993 976 ret = surface->hwdata->surface->Lock(surface->hwdata->surface,
994 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects) 977 DSLF_WRITE, &data, &pitch);
995 { 978 if (ret) {
996 DFBRegion region; 979 SetDirectFBerror("surface->Lock", ret);
997 int i; 980 return -1;
998 int region_valid = 0; 981 }
999 IDirectFBSurface *surface = this->screen->hwdata->surface; 982
1000 983 surface->pixels = data;
1001 for (i=0; i<numrects; ++i) 984 surface->pitch = pitch;
1002 { 985
1003 int x2, y2; 986 return 0;
1004 987 }
1005 if ( ! rects[i].w ) /* Clipped? */ 988
1006 continue; 989 static void
1007 990 DirectFB_UnlockHWSurface(_THIS, SDL_Surface * surface)
1008 x2 = rects[i].x + rects[i].w - 1; 991 {
1009 y2 = rects[i].y + rects[i].h - 1; 992 surface->hwdata->surface->Unlock(surface->hwdata->surface);
1010 993 surface->pixels = NULL;
1011 if (region_valid) 994 }
1012 { 995
1013 if (rects[i].x < region.x1) 996 static void
1014 region.x1 = rects[i].x; 997 DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
1015 998 {
1016 if (rects[i].y < region.y1) 999 if (HIDDEN->enable_mga_crtc2) {
1017 region.y1 = rects[i].y; 1000 if (HIDDEN->mga_crtc2_stretch)
1018 1001 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame,
1019 if (x2 > region.x2) 1002 this->screen->hwdata->surface,
1020 region.x2 = x2; 1003 &HIDDEN->c2ssize, &HIDDEN->c2dsize);
1021 1004 else
1022 if (y2 > region.y2) 1005 HIDDEN->c2frame->Blit(HIDDEN->c2frame,
1023 region.y2 = y2; 1006 this->screen->hwdata->surface, NULL,
1024 } 1007 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
1025 else 1008
1026 { 1009 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
1010 }
1011 }
1012
1013 static void
1014 DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect * rects)
1015 {
1016 DFBRegion region;
1017 int i;
1018 int region_valid = 0;
1019 IDirectFBSurface *surface = this->screen->hwdata->surface;
1020
1021 for (i = 0; i < numrects; ++i) {
1022 int x2, y2;
1023
1024 if (!rects[i].w) /* Clipped? */
1025 continue;
1026
1027 x2 = rects[i].x + rects[i].w - 1;
1028 y2 = rects[i].y + rects[i].h - 1;
1029
1030 if (region_valid) {
1031 if (rects[i].x < region.x1)
1032 region.x1 = rects[i].x;
1033
1034 if (rects[i].y < region.y1)
1035 region.y1 = rects[i].y;
1036
1037 if (x2 > region.x2)
1038 region.x2 = x2;
1039
1040 if (y2 > region.y2)
1041 region.y2 = y2;
1042 } else {
1027 region.x1 = rects[i].x; 1043 region.x1 = rects[i].x;
1028 region.y1 = rects[i].y; 1044 region.y1 = rects[i].y;
1029 region.x2 = x2; 1045 region.x2 = x2;
1030 region.y2 = y2; 1046 region.y2 = y2;
1031 1047
1032 region_valid = 1; 1048 region_valid = 1;
1033 } 1049 }
1034 } 1050 }
1035 1051
1036 if (region_valid) 1052 if (region_valid) {
1037 { 1053 if (HIDDEN->enable_mga_crtc2) {
1038 if (HIDDEN->enable_mga_crtc2) 1054 if (HIDDEN->mga_crtc2_stretch)
1039 { 1055 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface,
1040 if (HIDDEN->mga_crtc2_stretch) 1056 &HIDDEN->c2ssize,
1041 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); 1057 &HIDDEN->c2dsize);
1042 else 1058 else
1043 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 1059 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL,
1044 1060 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
1045 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); 1061
1046 } 1062 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC);
1047 else 1063 } else
1048 surface->Flip (surface, &region, DSFLIP_WAITFORSYNC); 1064 surface->Flip(surface, &region, DSFLIP_WAITFORSYNC);
1049 } 1065 }
1050 } 1066 }
1051 1067
1052 int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 1068 int
1053 { 1069 DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1054 IDirectFBPalette *palette = this->screen->hwdata->palette; 1070 {
1055 1071 IDirectFBPalette *palette = this->screen->hwdata->palette;
1056 if (!palette) 1072
1057 return 0; 1073 if (!palette)
1058 1074 return 0;
1059 if (firstcolor > 255) 1075
1060 return 0; 1076 if (firstcolor > 255)
1061 1077 return 0;
1062 if (firstcolor + ncolors > 256) 1078
1063 ncolors = 256 - firstcolor; 1079 if (firstcolor + ncolors > 256)
1064 1080 ncolors = 256 - firstcolor;
1065 if (ncolors > 0) 1081
1066 { 1082 if (ncolors > 0) {
1067 int i; 1083 int i;
1068 DFBColor entries[ncolors]; 1084 DFBColor entries[ncolors];
1069 1085
1070 for (i=0; i<ncolors; i++) 1086 for (i = 0; i < ncolors; i++) {
1071 { 1087 entries[i].a = 0xff;
1072 entries[i].a = 0xff; 1088 entries[i].r = colors[i].r;
1073 entries[i].r = colors[i].r; 1089 entries[i].g = colors[i].g;
1074 entries[i].g = colors[i].g; 1090 entries[i].b = colors[i].b;
1075 entries[i].b = colors[i].b; 1091 }
1076 } 1092
1077 1093 palette->SetEntries(palette, entries, ncolors, firstcolor);
1078 palette->SetEntries (palette, entries, ncolors, firstcolor); 1094 }
1079 } 1095
1080 1096 return 1;
1081 return 1; 1097 }
1082 } 1098
1083 1099 void
1084 void DirectFB_VideoQuit(_THIS) 1100 DirectFB_VideoQuit(_THIS)
1085 { 1101 {
1086 struct DirectFBEnumRect *rect = enumlist; 1102 struct DirectFBEnumRect *rect = enumlist;
1087 1103
1088 if (this->screen && this->screen->hwdata) 1104 if (this->screen && this->screen->hwdata) {
1089 { 1105 IDirectFBSurface *surface = this->screen->hwdata->surface;
1090 IDirectFBSurface *surface = this->screen->hwdata->surface; 1106 IDirectFBPalette *palette = this->screen->hwdata->palette;
1091 IDirectFBPalette *palette = this->screen->hwdata->palette; 1107
1092 1108 if (palette)
1093 if (palette) 1109 palette->Release(palette);
1094 palette->Release (palette); 1110
1095 1111 if (surface)
1096 if (surface) 1112 surface->Release(surface);
1097 surface->Release (surface); 1113
1098 1114 this->screen->hwdata->surface = NULL;
1099 this->screen->hwdata->surface = NULL; 1115 this->screen->hwdata->palette = NULL;
1100 this->screen->hwdata->palette = NULL; 1116 }
1101 } 1117
1102 1118 if (HIDDEN->c2frame) {
1103 if (HIDDEN->c2frame) 1119 HIDDEN->c2frame->Release(HIDDEN->c2frame);
1104 { 1120 HIDDEN->c2frame = NULL;
1105 HIDDEN->c2frame->Release (HIDDEN->c2frame); 1121 }
1106 HIDDEN->c2frame = NULL; 1122
1107 } 1123 if (HIDDEN->eventbuffer) {
1108 1124 HIDDEN->eventbuffer->Release(HIDDEN->eventbuffer);
1109 if (HIDDEN->eventbuffer) 1125 HIDDEN->eventbuffer = NULL;
1110 { 1126 }
1111 HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer); 1127
1112 HIDDEN->eventbuffer = NULL; 1128 if (HIDDEN->c2layer) {
1113 } 1129 HIDDEN->c2layer->Release(HIDDEN->c2layer);
1114 1130 HIDDEN->c2layer = NULL;
1115 if (HIDDEN->c2layer) 1131 }
1116 { 1132
1117 HIDDEN->c2layer->Release (HIDDEN->c2layer); 1133 if (HIDDEN->layer) {
1118 HIDDEN->c2layer = NULL; 1134 HIDDEN->layer->Release(HIDDEN->layer);
1119 } 1135 HIDDEN->layer = NULL;
1120 1136 }
1121 if (HIDDEN->layer) 1137
1122 { 1138 if (HIDDEN->dfb) {
1123 HIDDEN->layer->Release (HIDDEN->layer); 1139 HIDDEN->dfb->Release(HIDDEN->dfb);
1124 HIDDEN->layer = NULL; 1140 HIDDEN->dfb = NULL;
1125 } 1141 }
1126 1142
1127 if (HIDDEN->dfb) 1143 /* Free video mode list */
1128 { 1144 if (HIDDEN->modelist) {
1129 HIDDEN->dfb->Release (HIDDEN->dfb); 1145 free(HIDDEN->modelist);
1130 HIDDEN->dfb = NULL; 1146 HIDDEN->modelist = NULL;
1131 } 1147 }
1132 1148
1133 /* Free video mode list */ 1149 /* Free mode enumeration list */
1134 if (HIDDEN->modelist) 1150 while (rect) {
1135 { 1151 struct DirectFBEnumRect *next = rect->next;
1136 free (HIDDEN->modelist); 1152 free(rect);
1137 HIDDEN->modelist = NULL; 1153 rect = next;
1138 } 1154 }
1139 1155 enumlist = NULL;
1140 /* Free mode enumeration list */ 1156
1141 while (rect) 1157 HIDDEN->initialized = 0;
1142 { 1158 }
1143 struct DirectFBEnumRect *next = rect->next; 1159
1144 free (rect); 1160
1145 rect = next; 1161 int
1146 } 1162 DirectFB_ShowWMCursor(_THIS, WMcursor * cursor)
1147 enumlist = NULL; 1163 {
1148 1164 /* We can only hide or show the default cursor */
1149 HIDDEN->initialized = 0; 1165 if (cursor == NULL) {
1150 } 1166 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00);
1151 1167 } else {
1152 1168 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF);
1153 int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor) 1169 }
1154 { 1170 return 1;
1155 /* We can only hide or show the default cursor */ 1171 }
1156 if ( cursor == NULL ) 1172
1157 { 1173 void
1158 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00); 1174 DirectFB_FinalQuit(void)
1159 } 1175 {
1160 else 1176 }
1161 { 1177
1162 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF); 1178 /* vi: set ts=4 sw=4 expandtab: */
1163 }
1164 return 1;
1165 }
1166
1167 void DirectFB_FinalQuit(void)
1168 {
1169 }