Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_video.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
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); |
57 static int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, | 58 static SDL_Surface *DirectFB_SetVideoMode (_THIS, SDL_Surface * current, |
58 SDL_Color *colors); | 59 int width, int height, int bpp, |
59 static void DirectFB_VideoQuit(_THIS); | 60 Uint32 flags); |
61 static int DirectFB_SetColors (_THIS, int firstcolor, int ncolors, | |
62 SDL_Color * colors); | |
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, |
618 { | 611 sizeof (*current->hwdata)); |
619 SDL_OutOfMemory(); | 612 if (!current->hwdata) { |
620 return NULL; | 613 SDL_OutOfMemory (); |
621 } | 614 return NULL; |
622 } | 615 } |
623 | 616 } |
624 /* Set cooperative level depending on flag SDL_FULLSCREEN */ | 617 |
625 if (flags & SDL_FULLSCREEN) | 618 /* Set cooperative level depending on flag SDL_FULLSCREEN */ |
626 { | 619 if (flags & SDL_FULLSCREEN) { |
627 ret = HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN); | 620 ret = |
628 if (ret && !HIDDEN->enable_mga_crtc2) | 621 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_FULLSCREEN); |
629 { | 622 if (ret && !HIDDEN->enable_mga_crtc2) { |
630 DirectFBError ("dfb->SetCooperativeLevel", ret); | 623 DirectFBError ("dfb->SetCooperativeLevel", ret); |
631 flags &= ~SDL_FULLSCREEN; | 624 flags &= ~SDL_FULLSCREEN; |
632 } | 625 } |
633 } | 626 } else |
634 else | 627 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); |
635 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); | 628 |
636 | 629 /* Set video mode */ |
637 /* Set video mode */ | 630 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); |
638 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); | 631 if (ret) { |
639 if (ret) | 632 if (flags & SDL_FULLSCREEN) { |
640 { | 633 flags &= ~SDL_FULLSCREEN; |
641 if (flags & SDL_FULLSCREEN) | 634 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); |
642 { | 635 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); |
643 flags &= ~SDL_FULLSCREEN; | 636 } |
644 HIDDEN->dfb->SetCooperativeLevel (HIDDEN->dfb, DFSCL_NORMAL); | 637 |
645 ret = HIDDEN->dfb->SetVideoMode (HIDDEN->dfb, width, height, bpp); | 638 if (ret) { |
646 } | 639 SetDirectFBerror ("dfb->SetVideoMode", ret); |
647 | 640 return NULL; |
648 if (ret) | 641 } |
649 { | 642 } |
650 SetDirectFBerror ("dfb->SetVideoMode", ret); | 643 |
651 return NULL; | 644 /* Create primary surface */ |
652 } | 645 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; |
653 } | 646 dsc.caps = |
654 | 647 DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0); |
655 /* Create primary surface */ | 648 dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer); |
656 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; | 649 |
657 dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0); | 650 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); |
658 dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer); | 651 if (ret && (flags & SDL_DOUBLEBUF)) { |
659 | 652 /* Try without double buffering */ |
660 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); | 653 dsc.caps &= ~DSCAPS_FLIPPING; |
661 if (ret && (flags & SDL_DOUBLEBUF)) | 654 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); |
662 { | 655 } |
663 /* Try without double buffering */ | 656 if (ret) { |
664 dsc.caps &= ~DSCAPS_FLIPPING; | 657 SetDirectFBerror ("dfb->CreateSurface", ret); |
665 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface); | 658 return NULL; |
666 } | 659 } |
667 if (ret) | 660 |
668 { | 661 current->w = width; |
669 SetDirectFBerror ("dfb->CreateSurface", ret); | 662 current->h = height; |
670 return NULL; | 663 current->flags = SDL_HWSURFACE | SDL_PREALLOC; |
671 } | 664 |
672 | 665 if (flags & SDL_FULLSCREEN) { |
673 current->w = width; | 666 current->flags |= SDL_FULLSCREEN; |
674 current->h = height; | 667 this->UpdateRects = DirectFB_DirectUpdate; |
675 current->flags = SDL_HWSURFACE | SDL_PREALLOC; | 668 } else |
676 | 669 this->UpdateRects = DirectFB_WindowedUpdate; |
677 if (flags & SDL_FULLSCREEN) | 670 |
678 { | 671 if (dsc.caps & DSCAPS_FLIPPING) |
679 current->flags |= SDL_FULLSCREEN; | 672 current->flags |= SDL_DOUBLEBUF; |
680 this->UpdateRects = DirectFB_DirectUpdate; | 673 |
681 } | 674 surface->GetPixelFormat (surface, &pixelformat); |
682 else | 675 |
683 this->UpdateRects = DirectFB_WindowedUpdate; | 676 DFBToSDLPixelFormat (pixelformat, current->format); |
684 | 677 |
685 if (dsc.caps & DSCAPS_FLIPPING) | 678 /* Get the surface palette (if supported) */ |
686 current->flags |= SDL_DOUBLEBUF; | 679 if (DFB_PIXELFORMAT_IS_INDEXED (pixelformat)) { |
687 | 680 surface->GetPalette (surface, ¤t->hwdata->palette); |
688 surface->GetPixelFormat (surface, &pixelformat); | 681 |
689 | 682 current->flags |= SDL_HWPALETTE; |
690 DFBToSDLPixelFormat (pixelformat, current->format); | 683 } |
691 | 684 |
692 /* Get the surface palette (if supported) */ | 685 current->hwdata->surface = surface; |
693 if (DFB_PIXELFORMAT_IS_INDEXED( pixelformat )) | 686 |
694 { | 687 /* MGA CRTC2 stuff */ |
695 surface->GetPalette (surface, ¤t->hwdata->palette); | 688 if (HIDDEN->enable_mga_crtc2) { |
696 | 689 /* no stretching if c2ssize == c2framesize */ |
697 current->flags |= SDL_HWPALETTE; | 690 HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0; |
698 } | 691 HIDDEN->c2ssize.w = width; |
699 | 692 HIDDEN->c2ssize.h = height; |
700 current->hwdata->surface = surface; | 693 |
701 | 694 HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0; |
702 /* MGA CRTC2 stuff */ | 695 HIDDEN->c2dsize.w = width; |
703 if (HIDDEN->enable_mga_crtc2) | 696 HIDDEN->c2dsize.h = height; |
704 { | 697 |
705 /* no stretching if c2ssize == c2framesize */ | 698 HIDDEN->mga_crtc2_stretch = 0; |
706 HIDDEN->c2ssize.x = 0, HIDDEN->c2ssize.y = 0; | 699 |
707 HIDDEN->c2ssize.w = width; | 700 if (SDL_getenv ("SDL_DIRECTFB_MGA_STRETCH") != NULL) { |
708 HIDDEN->c2ssize.h = height; | 701 /* Normally assume a picture aspect ratio of 4:3 */ |
709 | 702 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j; |
710 HIDDEN->c2dsize.x = 0, HIDDEN->c2dsize.y = 0; | 703 |
711 HIDDEN->c2dsize.w = width; | 704 for (i = 1; i < 20; i++) { |
712 HIDDEN->c2dsize.h = height; | 705 for (j = 1; j < 10; j++) { |
713 | 706 if ((float) width / (float) i * (float) j == height) { |
714 HIDDEN->mga_crtc2_stretch = 0; | 707 zoom_aspect_x = i; |
715 | 708 zoom_aspect_y = j; |
716 if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL) | 709 |
717 { | 710 /* break the loop */ |
718 /* Normally assume a picture aspect ratio of 4:3 */ | 711 i = 21; |
719 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j; | 712 break; |
720 | 713 } |
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 } | 714 } |
750 | 715 } |
751 /* one step down */ | 716 |
752 HIDDEN->c2dsize.w-=zoom_aspect_x; | 717 #ifdef DIRECTFB_CRTC2_DEBUG |
753 HIDDEN->c2dsize.h-=zoom_aspect_y; | 718 printf |
754 | 719 ("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", |
755 #ifdef DIRECTFB_CRTC2_DEBUG | 720 width, height, zoom_aspect_x, zoom_aspect_y); |
756 printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); | 721 printf ("CRTC2 resolution: X: %d, Y: %d\n", |
757 #endif | 722 HIDDEN->c2framesize.w, HIDDEN->c2framesize.h); |
758 | 723 #endif |
759 HIDDEN->mga_crtc2_stretch = 1; | 724 |
760 } | 725 /* 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) | 726 if ((float) width < (float) HIDDEN->c2framesize.w * 0.95 |
762 { | 727 || (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) | 728 while ((float) HIDDEN->c2dsize.w < |
764 { | 729 (float) HIDDEN->c2framesize.w * |
765 HIDDEN->c2dsize.w-=zoom_aspect_x; | 730 HIDDEN->mga_crtc2_stretch_overscan |
766 HIDDEN->c2dsize.h-=zoom_aspect_y; | 731 && (float) HIDDEN->c2dsize.h < |
732 (float) HIDDEN->c2framesize.h * | |
733 HIDDEN->mga_crtc2_stretch_overscan) { | |
734 HIDDEN->c2dsize.w += zoom_aspect_x; | |
735 HIDDEN->c2dsize.h += zoom_aspect_y; | |
767 } | 736 } |
768 | 737 |
769 #ifdef DIRECTFB_CRTC2_DEBUG | 738 /* one step down */ |
770 printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); | 739 HIDDEN->c2dsize.w -= zoom_aspect_x; |
771 #endif | 740 HIDDEN->c2dsize.h -= zoom_aspect_y; |
772 | 741 |
773 HIDDEN->mga_crtc2_stretch = 1; | 742 #ifdef DIRECTFB_CRTC2_DEBUG |
774 } else { | 743 printf ("Stretched resolution: X: %d, Y: %d\n", |
775 #ifdef DIRECTFB_CRTC2_DEBUG | 744 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); |
776 printf("Not stretching image\n"); | 745 #endif |
777 #endif | 746 |
778 } | 747 HIDDEN->mga_crtc2_stretch = 1; |
779 | 748 } else if ((float) width > (float) HIDDEN->c2framesize.w * 0.95 |
780 /* Panning */ | 749 || (float) height > |
781 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w) | 750 (float) HIDDEN->c2framesize.h * 0.95) { |
782 HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2; | 751 while ((float) HIDDEN->c2dsize.w > |
783 else | 752 (float) HIDDEN->c2framesize.w * |
784 HIDDEN->c2dsize.x = (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2; | 753 HIDDEN->mga_crtc2_stretch_overscan |
785 | 754 || (float) HIDDEN->c2dsize.h > |
786 if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h) | 755 (float) HIDDEN->c2framesize.h * |
787 HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2; | 756 HIDDEN->mga_crtc2_stretch_overscan) { |
788 else | 757 HIDDEN->c2dsize.w -= zoom_aspect_x; |
789 HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2; | 758 HIDDEN->c2dsize.h -= zoom_aspect_y; |
790 | 759 } |
791 #ifdef DIRECTFB_CRTC2_DEBUG | 760 |
792 printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); | 761 #ifdef DIRECTFB_CRTC2_DEBUG |
793 #endif | 762 printf ("Down-Stretched resolution: X: %d, Y: %d\n", |
794 } | 763 HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); |
795 } | 764 #endif |
796 | 765 |
797 return current; | 766 HIDDEN->mga_crtc2_stretch = 1; |
798 } | 767 } else { |
799 | 768 #ifdef DIRECTFB_CRTC2_DEBUG |
800 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface) | 769 printf ("Not stretching image\n"); |
801 { | 770 #endif |
802 DFBResult ret; | 771 } |
803 DFBSurfaceDescription dsc; | 772 |
804 | 773 /* Panning */ |
805 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n", | 774 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w) |
806 surface->w, surface->h, surface->format->BitsPerPixel, surface->flags);*/ | 775 HIDDEN->c2dsize.x = |
807 | 776 (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2; |
808 if (surface->w < 8 || surface->h < 8) | 777 else |
809 return -1; | 778 HIDDEN->c2dsize.x = |
810 | 779 (HIDDEN->c2dsize.w - HIDDEN->c2framesize.w) / 2; |
811 /* fill surface description */ | 780 |
812 dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; | 781 if (HIDDEN->c2framesize.h > HIDDEN->c2dsize.h) |
813 dsc.width = surface->w; | 782 HIDDEN->c2dsize.y = |
814 dsc.height = surface->h; | 783 (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2; |
815 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0; | 784 else |
816 | 785 HIDDEN->c2dsize.y = |
817 /* find the right pixelformat */ | 786 (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2; |
818 dsc.pixelformat = SDLToDFBPixelFormat (surface->format); | 787 |
819 if (dsc.pixelformat == DSPF_UNKNOWN) | 788 #ifdef DIRECTFB_CRTC2_DEBUG |
820 return -1; | 789 printf ("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, |
821 | 790 HIDDEN->c2dsize.y); |
822 /* Allocate the hardware acceleration data */ | 791 #endif |
823 surface->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*surface->hwdata)); | 792 } |
824 if (surface->hwdata == NULL) | 793 } |
825 { | 794 |
826 SDL_OutOfMemory(); | 795 return current; |
827 return -1; | 796 } |
828 } | 797 |
829 | 798 static int |
830 /* Create the surface */ | 799 DirectFB_AllocHWSurface (_THIS, SDL_Surface * surface) |
831 ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface->hwdata->surface); | 800 { |
832 if (ret) | 801 DFBResult ret; |
833 { | 802 DFBSurfaceDescription dsc; |
834 SetDirectFBerror ("dfb->CreateSurface", ret); | 803 |
835 free (surface->hwdata); | 804 /* fprintf(stderr, "SDL: DirectFB_AllocHWSurface (%dx%d@%d, flags: 0x%08x)\n", |
836 surface->hwdata = NULL; | 805 surface->w, surface->h, surface->format->BitsPerPixel, surface->flags); */ |
837 return -1; | 806 |
838 } | 807 if (surface->w < 8 || surface->h < 8) |
839 | 808 return -1; |
840 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC; | 809 |
841 | 810 /* fill surface description */ |
842 return 0; | 811 dsc.flags = |
843 } | 812 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; |
844 | 813 dsc.width = surface->w; |
845 static void DirectFB_FreeHWSurface(_THIS, SDL_Surface *surface) | 814 dsc.height = surface->h; |
846 { | 815 dsc.caps = (surface->flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0; |
847 if (surface->hwdata && HIDDEN->initialized) | 816 |
848 { | 817 /* find the right pixelformat */ |
849 surface->hwdata->surface->Release (surface->hwdata->surface); | 818 dsc.pixelformat = SDLToDFBPixelFormat (surface->format); |
850 free (surface->hwdata); | 819 if (dsc.pixelformat == DSPF_UNKNOWN) |
851 surface->hwdata = NULL; | 820 return -1; |
852 } | 821 |
853 } | 822 /* Allocate the hardware acceleration data */ |
854 | 823 surface->hwdata = |
855 static int DirectFB_CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst) | 824 (struct private_hwdata *) SDL_calloc (1, sizeof (*surface->hwdata)); |
856 { | 825 if (surface->hwdata == NULL) { |
857 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n", | 826 SDL_OutOfMemory (); |
858 src->hwdata, dst->hwdata);*/ | 827 return -1; |
859 | 828 } |
860 if (!src->hwdata || !dst->hwdata) | 829 |
830 /* Create the surface */ | |
831 ret = | |
832 HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, | |
833 &surface->hwdata->surface); | |
834 if (ret) { | |
835 SetDirectFBerror ("dfb->CreateSurface", ret); | |
836 free (surface->hwdata); | |
837 surface->hwdata = NULL; | |
838 return -1; | |
839 } | |
840 | |
841 surface->flags |= SDL_HWSURFACE | SDL_PREALLOC; | |
842 | |
861 return 0; | 843 return 0; |
862 | 844 } |
863 src->flags |= SDL_HWACCEL; | 845 |
864 src->map->hw_blit = DirectFB_HWAccelBlit; | 846 static void |
865 | 847 DirectFB_FreeHWSurface (_THIS, SDL_Surface * surface) |
866 return 1; | 848 { |
867 } | 849 if (surface->hwdata && HIDDEN->initialized) { |
868 | 850 surface->hwdata->surface->Release (surface->hwdata->surface); |
869 static int DirectFB_HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect, | 851 free (surface->hwdata); |
870 SDL_Surface *dst, SDL_Rect *dstrect) | 852 surface->hwdata = NULL; |
871 { | 853 } |
872 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; | 854 } |
873 | 855 |
874 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h }; | 856 static int |
875 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h }; | 857 DirectFB_CheckHWBlit (_THIS, SDL_Surface * src, SDL_Surface * dst) |
876 | 858 { |
877 IDirectFBSurface *surface = dst->hwdata->surface; | 859 /* fprintf(stderr, "SDL: DirectFB_CheckHWBlit (src->hwdata: %p, dst->hwdata: %p)\n", |
878 | 860 src->hwdata, dst->hwdata); */ |
879 if (src->flags & SDL_SRCCOLORKEY) | 861 |
880 { | 862 if (!src->hwdata || !dst->hwdata) |
881 flags |= DSBLIT_SRC_COLORKEY; | 863 return 0; |
882 DirectFB_SetHWColorKey (NULL, src, src->format->colorkey); | 864 |
883 } | 865 src->flags |= SDL_HWACCEL; |
884 | 866 src->map->hw_blit = DirectFB_HWAccelBlit; |
885 if (src->flags & SDL_SRCALPHA) | 867 |
886 { | 868 return 1; |
887 flags |= DSBLIT_BLEND_COLORALPHA; | 869 } |
888 surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha); | 870 |
889 } | 871 static int |
890 | 872 DirectFB_HWAccelBlit (SDL_Surface * src, SDL_Rect * srcrect, |
891 surface->SetBlittingFlags (surface, flags); | 873 SDL_Surface * dst, SDL_Rect * dstrect) |
892 | 874 { |
893 if (sr.w == dr.w && sr.h == dr.h) | 875 DFBSurfaceBlittingFlags flags = DSBLIT_NOFX; |
894 surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y); | 876 |
895 else | 877 DFBRectangle sr = { srcrect->x, srcrect->y, srcrect->w, srcrect->h }; |
896 surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr); | 878 DFBRectangle dr = { dstrect->x, dstrect->y, dstrect->w, dstrect->h }; |
897 | 879 |
898 return 0; | 880 IDirectFBSurface *surface = dst->hwdata->surface; |
899 } | 881 |
900 | 882 if (src->flags & SDL_SRCCOLORKEY) { |
901 static int DirectFB_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) | 883 flags |= DSBLIT_SRC_COLORKEY; |
902 { | 884 DirectFB_SetHWColorKey (NULL, src, src->format->colorkey); |
903 SDL_PixelFormat *fmt = dst->format; | 885 } |
904 IDirectFBSurface *surface = dst->hwdata->surface; | 886 |
905 | 887 if (src->flags & SDL_SRCALPHA) { |
906 /* ugly */ | 888 flags |= DSBLIT_BLEND_COLORALPHA; |
907 surface->SetColor (surface, | 889 surface->SetColor (surface, 0xff, 0xff, 0xff, src->format->alpha); |
908 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss), | 890 } |
909 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss), | 891 |
910 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), 0xFF); | 892 surface->SetBlittingFlags (surface, flags); |
911 surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, dstrect->h); | 893 |
912 | 894 if (sr.w == dr.w && sr.h == dr.h) |
913 return 0; | 895 surface->Blit (surface, src->hwdata->surface, &sr, dr.x, dr.y); |
914 } | 896 else |
915 | 897 surface->StretchBlit (surface, src->hwdata->surface, &sr, &dr); |
916 static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key) | 898 |
917 { | 899 return 0; |
918 SDL_PixelFormat *fmt = src->format; | 900 } |
919 IDirectFBSurface *surface = src->hwdata->surface; | 901 |
920 | 902 static int |
921 if (fmt->BitsPerPixel == 8) | 903 DirectFB_FillHWRect (_THIS, SDL_Surface * dst, SDL_Rect * dstrect, |
922 surface->SetSrcColorKeyIndex (surface, key); | 904 Uint32 color) |
923 else | 905 { |
906 SDL_PixelFormat *fmt = dst->format; | |
907 IDirectFBSurface *surface = dst->hwdata->surface; | |
908 | |
924 /* ugly */ | 909 /* ugly */ |
925 surface->SetSrcColorKey (surface, | 910 surface->SetColor (surface, |
926 (key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss), | 911 (color & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss), |
927 (key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss), | 912 (color & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss), |
928 (key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift)); | 913 (color & fmt->Bmask) << (fmt->Bloss - fmt->Bshift), |
929 | 914 0xFF); |
930 return 0; | 915 surface->FillRectangle (surface, dstrect->x, dstrect->y, dstrect->w, |
931 } | 916 dstrect->h); |
932 | 917 |
933 static int DirectFB_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha) | 918 return 0; |
934 { | 919 } |
935 return 0; | 920 |
936 } | 921 static int |
937 | 922 DirectFB_SetHWColorKey (_THIS, SDL_Surface * src, Uint32 key) |
938 static int DirectFB_FlipHWSurface(_THIS, SDL_Surface *surface) | 923 { |
939 { | 924 SDL_PixelFormat *fmt = src->format; |
940 if (HIDDEN->enable_mga_crtc2) | 925 IDirectFBSurface *surface = src->hwdata->surface; |
941 { | 926 |
942 int rtn = surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, 0); | 927 if (fmt->BitsPerPixel == 8) |
943 if (HIDDEN->mga_crtc2_stretch) | 928 surface->SetSrcColorKeyIndex (surface, key); |
944 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); | 929 else |
945 else | 930 /* ugly */ |
946 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); | 931 surface->SetSrcColorKey (surface, |
947 | 932 (key & fmt->Rmask) >> (fmt->Rshift - |
948 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); | 933 fmt->Rloss), |
949 return rtn; | 934 (key & fmt->Gmask) >> (fmt->Gshift - |
950 } | 935 fmt->Gloss), |
951 else | 936 (key & fmt->Bmask) << (fmt->Bloss - |
952 return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, DSFLIP_WAITFORSYNC); | 937 fmt->Bshift)); |
953 } | 938 |
954 | 939 return 0; |
955 static int DirectFB_LockHWSurface(_THIS, SDL_Surface *surface) | 940 } |
956 { | 941 |
957 DFBResult ret; | 942 static int |
958 void *data; | 943 DirectFB_SetHWAlpha (_THIS, SDL_Surface * surface, Uint8 alpha) |
959 int pitch; | 944 { |
960 | 945 return 0; |
961 ret = surface->hwdata->surface->Lock (surface->hwdata->surface, | 946 } |
962 DSLF_WRITE, &data, &pitch); | 947 |
963 if (ret) | 948 static int |
964 { | 949 DirectFB_FlipHWSurface (_THIS, SDL_Surface * surface) |
965 SetDirectFBerror ("surface->Lock", ret); | 950 { |
966 return -1; | 951 if (HIDDEN->enable_mga_crtc2) { |
967 } | 952 int rtn = |
968 | 953 surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, |
969 surface->pixels = data; | 954 0); |
970 surface->pitch = pitch; | 955 if (HIDDEN->mga_crtc2_stretch) |
971 | 956 HIDDEN->c2frame->StretchBlit (HIDDEN->c2frame, |
972 return 0; | 957 surface->hwdata->surface, |
973 } | 958 &HIDDEN->c2ssize, &HIDDEN->c2dsize); |
974 | 959 else |
975 static void DirectFB_UnlockHWSurface(_THIS, SDL_Surface *surface) | 960 HIDDEN->c2frame->Blit (HIDDEN->c2frame, |
976 { | 961 surface->hwdata->surface, NULL, |
977 surface->hwdata->surface->Unlock (surface->hwdata->surface); | 962 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); |
978 surface->pixels = NULL; | 963 |
979 } | 964 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); |
980 | 965 return rtn; |
981 static void DirectFB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | 966 } else |
982 { | 967 return surface->hwdata->surface->Flip (surface->hwdata->surface, NULL, |
983 if (HIDDEN->enable_mga_crtc2) | 968 DSFLIP_WAITFORSYNC); |
984 { | 969 } |
985 if (HIDDEN->mga_crtc2_stretch) | 970 |
986 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, this->screen->hwdata->surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); | 971 static int |
987 else | 972 DirectFB_LockHWSurface (_THIS, SDL_Surface * surface) |
988 HIDDEN->c2frame->Blit(HIDDEN->c2frame, this->screen->hwdata->surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); | 973 { |
989 | 974 DFBResult ret; |
990 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); | 975 void *data; |
991 } | 976 int pitch; |
992 } | 977 |
993 | 978 ret = surface->hwdata->surface->Lock (surface->hwdata->surface, |
994 static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects) | 979 DSLF_WRITE, &data, &pitch); |
995 { | 980 if (ret) { |
996 DFBRegion region; | 981 SetDirectFBerror ("surface->Lock", ret); |
997 int i; | 982 return -1; |
998 int region_valid = 0; | 983 } |
999 IDirectFBSurface *surface = this->screen->hwdata->surface; | 984 |
1000 | 985 surface->pixels = data; |
1001 for (i=0; i<numrects; ++i) | 986 surface->pitch = pitch; |
1002 { | 987 |
1003 int x2, y2; | 988 return 0; |
1004 | 989 } |
1005 if ( ! rects[i].w ) /* Clipped? */ | 990 |
1006 continue; | 991 static void |
1007 | 992 DirectFB_UnlockHWSurface (_THIS, SDL_Surface * surface) |
1008 x2 = rects[i].x + rects[i].w - 1; | 993 { |
1009 y2 = rects[i].y + rects[i].h - 1; | 994 surface->hwdata->surface->Unlock (surface->hwdata->surface); |
1010 | 995 surface->pixels = NULL; |
1011 if (region_valid) | 996 } |
1012 { | 997 |
1013 if (rects[i].x < region.x1) | 998 static void |
1014 region.x1 = rects[i].x; | 999 DirectFB_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) |
1015 | 1000 { |
1016 if (rects[i].y < region.y1) | 1001 if (HIDDEN->enable_mga_crtc2) { |
1017 region.y1 = rects[i].y; | 1002 if (HIDDEN->mga_crtc2_stretch) |
1018 | 1003 HIDDEN->c2frame->StretchBlit (HIDDEN->c2frame, |
1019 if (x2 > region.x2) | 1004 this->screen->hwdata->surface, |
1020 region.x2 = x2; | 1005 &HIDDEN->c2ssize, &HIDDEN->c2dsize); |
1021 | 1006 else |
1022 if (y2 > region.y2) | 1007 HIDDEN->c2frame->Blit (HIDDEN->c2frame, |
1023 region.y2 = y2; | 1008 this->screen->hwdata->surface, NULL, |
1024 } | 1009 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); |
1025 else | 1010 |
1026 { | 1011 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); |
1012 } | |
1013 } | |
1014 | |
1015 static void | |
1016 DirectFB_WindowedUpdate (_THIS, int numrects, SDL_Rect * rects) | |
1017 { | |
1018 DFBRegion region; | |
1019 int i; | |
1020 int region_valid = 0; | |
1021 IDirectFBSurface *surface = this->screen->hwdata->surface; | |
1022 | |
1023 for (i = 0; i < numrects; ++i) { | |
1024 int x2, y2; | |
1025 | |
1026 if (!rects[i].w) /* Clipped? */ | |
1027 continue; | |
1028 | |
1029 x2 = rects[i].x + rects[i].w - 1; | |
1030 y2 = rects[i].y + rects[i].h - 1; | |
1031 | |
1032 if (region_valid) { | |
1033 if (rects[i].x < region.x1) | |
1034 region.x1 = rects[i].x; | |
1035 | |
1036 if (rects[i].y < region.y1) | |
1037 region.y1 = rects[i].y; | |
1038 | |
1039 if (x2 > region.x2) | |
1040 region.x2 = x2; | |
1041 | |
1042 if (y2 > region.y2) | |
1043 region.y2 = y2; | |
1044 } else { | |
1027 region.x1 = rects[i].x; | 1045 region.x1 = rects[i].x; |
1028 region.y1 = rects[i].y; | 1046 region.y1 = rects[i].y; |
1029 region.x2 = x2; | 1047 region.x2 = x2; |
1030 region.y2 = y2; | 1048 region.y2 = y2; |
1031 | 1049 |
1032 region_valid = 1; | 1050 region_valid = 1; |
1033 } | 1051 } |
1034 } | 1052 } |
1035 | 1053 |
1036 if (region_valid) | 1054 if (region_valid) { |
1037 { | 1055 if (HIDDEN->enable_mga_crtc2) { |
1038 if (HIDDEN->enable_mga_crtc2) | 1056 if (HIDDEN->mga_crtc2_stretch) |
1039 { | 1057 HIDDEN->c2frame->StretchBlit (HIDDEN->c2frame, surface, |
1040 if (HIDDEN->mga_crtc2_stretch) | 1058 &HIDDEN->c2ssize, |
1041 HIDDEN->c2frame->StretchBlit(HIDDEN->c2frame, surface, &HIDDEN->c2ssize, &HIDDEN->c2dsize); | 1059 &HIDDEN->c2dsize); |
1042 else | 1060 else |
1043 HIDDEN->c2frame->Blit(HIDDEN->c2frame, surface, NULL, HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); | 1061 HIDDEN->c2frame->Blit (HIDDEN->c2frame, surface, NULL, |
1044 | 1062 HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); |
1045 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); | 1063 |
1046 } | 1064 HIDDEN->c2frame->Flip (HIDDEN->c2frame, NULL, DSFLIP_WAITFORSYNC); |
1047 else | 1065 } else |
1048 surface->Flip (surface, ®ion, DSFLIP_WAITFORSYNC); | 1066 surface->Flip (surface, ®ion, DSFLIP_WAITFORSYNC); |
1049 } | 1067 } |
1050 } | 1068 } |
1051 | 1069 |
1052 int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | 1070 int |
1053 { | 1071 DirectFB_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
1054 IDirectFBPalette *palette = this->screen->hwdata->palette; | 1072 { |
1055 | 1073 IDirectFBPalette *palette = this->screen->hwdata->palette; |
1056 if (!palette) | 1074 |
1057 return 0; | 1075 if (!palette) |
1058 | 1076 return 0; |
1059 if (firstcolor > 255) | 1077 |
1060 return 0; | 1078 if (firstcolor > 255) |
1061 | 1079 return 0; |
1062 if (firstcolor + ncolors > 256) | 1080 |
1063 ncolors = 256 - firstcolor; | 1081 if (firstcolor + ncolors > 256) |
1064 | 1082 ncolors = 256 - firstcolor; |
1065 if (ncolors > 0) | 1083 |
1066 { | 1084 if (ncolors > 0) { |
1067 int i; | 1085 int i; |
1068 DFBColor entries[ncolors]; | 1086 DFBColor entries[ncolors]; |
1069 | 1087 |
1070 for (i=0; i<ncolors; i++) | 1088 for (i = 0; i < ncolors; i++) { |
1071 { | 1089 entries[i].a = 0xff; |
1072 entries[i].a = 0xff; | 1090 entries[i].r = colors[i].r; |
1073 entries[i].r = colors[i].r; | 1091 entries[i].g = colors[i].g; |
1074 entries[i].g = colors[i].g; | 1092 entries[i].b = colors[i].b; |
1075 entries[i].b = colors[i].b; | 1093 } |
1076 } | 1094 |
1077 | 1095 palette->SetEntries (palette, entries, ncolors, firstcolor); |
1078 palette->SetEntries (palette, entries, ncolors, firstcolor); | 1096 } |
1079 } | 1097 |
1080 | 1098 return 1; |
1081 return 1; | 1099 } |
1082 } | 1100 |
1083 | 1101 void |
1084 void DirectFB_VideoQuit(_THIS) | 1102 DirectFB_VideoQuit (_THIS) |
1085 { | 1103 { |
1086 struct DirectFBEnumRect *rect = enumlist; | 1104 struct DirectFBEnumRect *rect = enumlist; |
1087 | 1105 |
1088 if (this->screen && this->screen->hwdata) | 1106 if (this->screen && this->screen->hwdata) { |
1089 { | 1107 IDirectFBSurface *surface = this->screen->hwdata->surface; |
1090 IDirectFBSurface *surface = this->screen->hwdata->surface; | 1108 IDirectFBPalette *palette = this->screen->hwdata->palette; |
1091 IDirectFBPalette *palette = this->screen->hwdata->palette; | 1109 |
1092 | 1110 if (palette) |
1093 if (palette) | 1111 palette->Release (palette); |
1094 palette->Release (palette); | 1112 |
1095 | 1113 if (surface) |
1096 if (surface) | 1114 surface->Release (surface); |
1097 surface->Release (surface); | 1115 |
1098 | 1116 this->screen->hwdata->surface = NULL; |
1099 this->screen->hwdata->surface = NULL; | 1117 this->screen->hwdata->palette = NULL; |
1100 this->screen->hwdata->palette = NULL; | 1118 } |
1101 } | 1119 |
1102 | 1120 if (HIDDEN->c2frame) { |
1103 if (HIDDEN->c2frame) | 1121 HIDDEN->c2frame->Release (HIDDEN->c2frame); |
1104 { | 1122 HIDDEN->c2frame = NULL; |
1105 HIDDEN->c2frame->Release (HIDDEN->c2frame); | 1123 } |
1106 HIDDEN->c2frame = NULL; | 1124 |
1107 } | 1125 if (HIDDEN->eventbuffer) { |
1108 | 1126 HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer); |
1109 if (HIDDEN->eventbuffer) | 1127 HIDDEN->eventbuffer = NULL; |
1110 { | 1128 } |
1111 HIDDEN->eventbuffer->Release (HIDDEN->eventbuffer); | 1129 |
1112 HIDDEN->eventbuffer = NULL; | 1130 if (HIDDEN->c2layer) { |
1113 } | 1131 HIDDEN->c2layer->Release (HIDDEN->c2layer); |
1114 | 1132 HIDDEN->c2layer = NULL; |
1115 if (HIDDEN->c2layer) | 1133 } |
1116 { | 1134 |
1117 HIDDEN->c2layer->Release (HIDDEN->c2layer); | 1135 if (HIDDEN->layer) { |
1118 HIDDEN->c2layer = NULL; | 1136 HIDDEN->layer->Release (HIDDEN->layer); |
1119 } | 1137 HIDDEN->layer = NULL; |
1120 | 1138 } |
1121 if (HIDDEN->layer) | 1139 |
1122 { | 1140 if (HIDDEN->dfb) { |
1123 HIDDEN->layer->Release (HIDDEN->layer); | 1141 HIDDEN->dfb->Release (HIDDEN->dfb); |
1124 HIDDEN->layer = NULL; | 1142 HIDDEN->dfb = NULL; |
1125 } | 1143 } |
1126 | 1144 |
1127 if (HIDDEN->dfb) | 1145 /* Free video mode list */ |
1128 { | 1146 if (HIDDEN->modelist) { |
1129 HIDDEN->dfb->Release (HIDDEN->dfb); | 1147 free (HIDDEN->modelist); |
1130 HIDDEN->dfb = NULL; | 1148 HIDDEN->modelist = NULL; |
1131 } | 1149 } |
1132 | 1150 |
1133 /* Free video mode list */ | 1151 /* Free mode enumeration list */ |
1134 if (HIDDEN->modelist) | 1152 while (rect) { |
1135 { | 1153 struct DirectFBEnumRect *next = rect->next; |
1136 free (HIDDEN->modelist); | 1154 free (rect); |
1137 HIDDEN->modelist = NULL; | 1155 rect = next; |
1138 } | 1156 } |
1139 | 1157 enumlist = NULL; |
1140 /* Free mode enumeration list */ | 1158 |
1141 while (rect) | 1159 HIDDEN->initialized = 0; |
1142 { | 1160 } |
1143 struct DirectFBEnumRect *next = rect->next; | 1161 |
1144 free (rect); | 1162 |
1145 rect = next; | 1163 int |
1146 } | 1164 DirectFB_ShowWMCursor (_THIS, WMcursor * cursor) |
1147 enumlist = NULL; | 1165 { |
1148 | 1166 /* We can only hide or show the default cursor */ |
1149 HIDDEN->initialized = 0; | 1167 if (cursor == NULL) { |
1150 } | 1168 HIDDEN->layer->SetCursorOpacity (HIDDEN->layer, 0x00); |
1151 | 1169 } else { |
1152 | 1170 HIDDEN->layer->SetCursorOpacity (HIDDEN->layer, 0xFF); |
1153 int DirectFB_ShowWMCursor(_THIS, WMcursor *cursor) | 1171 } |
1154 { | 1172 return 1; |
1155 /* We can only hide or show the default cursor */ | 1173 } |
1156 if ( cursor == NULL ) | 1174 |
1157 { | 1175 void |
1158 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0x00); | 1176 DirectFB_FinalQuit (void) |
1159 } | 1177 { |
1160 else | 1178 } |
1161 { | 1179 |
1162 HIDDEN->layer->SetCursorOpacity(HIDDEN->layer, 0xFF); | 1180 /* vi: set ts=4 sw=4 expandtab: */ |
1163 } | |
1164 return 1; | |
1165 } | |
1166 | |
1167 void DirectFB_FinalQuit(void) | |
1168 { | |
1169 } |