comparison src/video/directfb/SDL_DirectFB_render.c @ 2737:140a7edcf2bd

Date: Sun, 31 Aug 2008 17:53:59 +0200 From: Couriersud Subject: Re: Updated DirectFB driver for SDL1.3 attached is a patch which brings the directfb driver in line with current svn. In addition: * driver now is in line with the structure of the X11 driver. This adds a couple of files. * driver now supports relative mouse movements
author Sam Lantinga <slouken@libsdl.org>
date Sun, 31 Aug 2008 16:04:32 +0000
parents 91f1706b27be
children 8133d1d278da
comparison
equal deleted inserted replaced
2736:ae653575d4af 2737:140a7edcf2bd
27 #include "SDL_DirectFB_video.h" 27 #include "SDL_DirectFB_video.h"
28 #include "SDL_DirectFB_render.h" 28 #include "SDL_DirectFB_render.h"
29 #include "../SDL_rect_c.h" 29 #include "../SDL_rect_c.h"
30 #include "../SDL_yuv_sw_c.h" 30 #include "../SDL_yuv_sw_c.h"
31 31
32 /* the following is not yet tested ... */
33 #define USE_DISPLAY_PALETTE (0)
34
32 /* GDI renderer implementation */ 35 /* GDI renderer implementation */
33 36
34 static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window, 37 static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
35 Uint32 flags); 38 Uint32 flags);
36 static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer); 39 static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer);
40 static int DirectFB_ActivateRenderer(SDL_Renderer * renderer);
37 static int DirectFB_CreateTexture(SDL_Renderer * renderer, 41 static int DirectFB_CreateTexture(SDL_Renderer * renderer,
38 SDL_Texture * texture); 42 SDL_Texture * texture);
39 static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer, 43 static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
40 SDL_Texture * texture, void **pixels, 44 SDL_Texture * texture, void **pixels,
41 int *pitch); 45 int *pitch);
87 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | 91 (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
88 SDL_TEXTUREMODULATE_ALPHA), 92 SDL_TEXTUREMODULATE_ALPHA),
89 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK | 93 (SDL_TEXTUREBLENDMODE_NONE | SDL_TEXTUREBLENDMODE_MASK |
90 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | 94 SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD |
91 SDL_TEXTUREBLENDMODE_MOD), 95 SDL_TEXTUREBLENDMODE_MOD),
92 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST), 96 (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
97 SDL_TEXTURESCALEMODE_SLOW | SDL_TEXTURESCALEMODE_BEST),
93 14, 98 14,
94 { 99 {
100 SDL_PIXELFORMAT_INDEX4LSB,
95 SDL_PIXELFORMAT_INDEX8, 101 SDL_PIXELFORMAT_INDEX8,
96 SDL_PIXELFORMAT_INDEX4LSB,
97 SDL_PIXELFORMAT_RGB332, 102 SDL_PIXELFORMAT_RGB332,
98 SDL_PIXELFORMAT_RGB555, 103 SDL_PIXELFORMAT_RGB555,
99 SDL_PIXELFORMAT_RGB565, 104 SDL_PIXELFORMAT_RGB565,
100 SDL_PIXELFORMAT_RGB888, 105 SDL_PIXELFORMAT_RGB888,
101 SDL_PIXELFORMAT_ARGB8888, 106 SDL_PIXELFORMAT_ARGB8888,
113 typedef struct 118 typedef struct
114 { 119 {
115 IDirectFBSurface *surface; 120 IDirectFBSurface *surface;
116 DFBSurfaceFlipFlags flipflags; 121 DFBSurfaceFlipFlags flipflags;
117 int isyuvdirect; 122 int isyuvdirect;
123 int size_changed;
118 } DirectFB_RenderData; 124 } DirectFB_RenderData;
119 125
120 typedef struct 126 typedef struct
121 { 127 {
122 IDirectFBDisplayLayer *vidlayer;
123 IDirectFBSurface *surface; 128 IDirectFBSurface *surface;
124 Uint32 format; 129 Uint32 format;
125 void *pixels; 130 void *pixels;
126 int pitch; 131 int pitch;
127 IDirectFBPalette *palette; 132 IDirectFBPalette *palette;
128 DFB_DisplayData *display; 133 SDL_VideoDisplay *display;
134 SDL_DirtyRectList dirty;
135 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
136 DFBSurfaceRenderOptions render_options;
137 #endif
129 } DirectFB_TextureData; 138 } DirectFB_TextureData;
139
140 static __inline__ void
141 SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
142 {
143 dr->x = sr->x;
144 dr->y = sr->y;
145 dr->h = sr->h;
146 dr->w = sr->w;
147 }
130 148
131 void 149 void
132 DirectFB_AddRenderDriver(_THIS) 150 DirectFB_AddRenderDriver(_THIS)
133 { 151 {
134 int i; 152 int i;
135 for (i = 0; i < _this->num_displays; i++) 153 for (i = 0; i < _this->num_displays; i++)
136 SDL_AddRenderDriver(i, &DirectFB_RenderDriver); 154 SDL_AddRenderDriver(i, &DirectFB_RenderDriver);
137 } 155 }
138 156
157 static int
158 DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
159 {
160 #if USE_DISPLAY_PALETTE
161 DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
162 IDirectFBPalette *surfpal;
163
164 int ret;
165 int i;
166 int ncolors;
167 DFBColor entries[256];
168
169 SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &surfpal));
170
171 /* FIXME: number of colors */
172 ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
173
174 for (i = 0; i < ncolors; ++i) {
175 entries[i].r = palette->colors[i].r;
176 entries[i].g = palette->colors[i].g;
177 entries[i].b = palette->colors[i].b;
178 entries[i].a = palette->colors[i].unused;
179 }
180 SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
181 return 0;
182 error:
183 #endif
184 return -1;
185 }
186
187
139 SDL_Renderer * 188 SDL_Renderer *
140 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) 189 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
141 { 190 {
142 SDL_DFB_WINDOWDATA(window); 191 SDL_DFB_WINDOWDATA(window);
143 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 192 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
144 SDL_DFB_DEVICEDATA(display->device);
145 SDL_Renderer *renderer = NULL; 193 SDL_Renderer *renderer = NULL;
146 DirectFB_RenderData *data = NULL; 194 DirectFB_RenderData *data = NULL;
147 DFBResult ret; 195 DFBResult ret;
148 DFBSurfaceDescription dsc;
149 DFBSurfaceCapabilities scaps; 196 DFBSurfaceCapabilities scaps;
150 char *p; 197 char *p;
151 int i, n;
152 198
153 SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer)); 199 SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer));
154 SDL_DFB_CALLOC(data, 1, sizeof(*data)); 200 SDL_DFB_CALLOC(data, 1, sizeof(*data));
155 201
156 renderer->DisplayModeChanged = DirectFB_DisplayModeChanged; 202 renderer->DisplayModeChanged = DirectFB_DisplayModeChanged;
203 renderer->ActivateRenderer = DirectFB_ActivateRenderer;
157 renderer->CreateTexture = DirectFB_CreateTexture; 204 renderer->CreateTexture = DirectFB_CreateTexture;
158 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; 205 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
159 renderer->SetTexturePalette = DirectFB_SetTexturePalette; 206 renderer->SetTexturePalette = DirectFB_SetTexturePalette;
160 renderer->GetTexturePalette = DirectFB_GetTexturePalette; 207 renderer->GetTexturePalette = DirectFB_GetTexturePalette;
161 renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod; 208 renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
177 224
178 renderer->info.flags = 225 renderer->info.flags =
179 SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD; 226 SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTDISCARD;
180 227
181 data->surface = windata->surface; 228 data->surface = windata->surface;
182 data->flipflags = 0; 229 data->surface->AddRef(data->surface);
230
231 data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
183 232
184 if (flags & SDL_RENDERER_PRESENTVSYNC) { 233 if (flags & SDL_RENDERER_PRESENTVSYNC) {
185 data->flipflags = DSFLIP_ONSYNC; 234 data->flipflags = DSFLIP_ONSYNC;
186 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; 235 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
187 } 236 }
188 237
189 data->surface->GetCapabilities(data->surface, &scaps); 238 SDL_DFB_CHECKERR(data->surface->GetCapabilities(data->surface, &scaps));
190 if (scaps & DSCAPS_DOUBLE) 239 if (scaps & DSCAPS_DOUBLE)
191 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; 240 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
192 else if (scaps & DSCAPS_TRIPLE) 241 else if (scaps & DSCAPS_TRIPLE)
193 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; 242 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
194 else 243 else
195 renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; 244 renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
196 245
197 data->isyuvdirect = 1; /* default is on! */ 246 data->isyuvdirect = 0; /* default is off! */
198 p = getenv("SDL_DIRECTFB_YUV_DIRECT"); 247 p = getenv(DFBENV_USE_YUV_DIRECT);
199 if (p) 248 if (p)
200 data->isyuvdirect = atoi(p); 249 data->isyuvdirect = atoi(p);
250
251 /* Set up a palette watch on the display palette */
252 if (display->palette) {
253 SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
254 }
201 255
202 return renderer; 256 return renderer;
203 257
204 error: 258 error:
205 SDL_DFB_FREE(renderer); 259 SDL_DFB_FREE(renderer);
265 return DSPF_UNKNOWN; 319 return DSPF_UNKNOWN;
266 } 320 }
267 } 321 }
268 322
269 static int 323 static int
270 DirectFB_DisplayModeChanged(SDL_Renderer * renderer) 324 DirectFB_ActivateRenderer(SDL_Renderer * renderer)
271 { 325 {
272 SDL_DFB_RENDERERDATA(renderer); 326 SDL_DFB_RENDERERDATA(renderer);
273 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 327 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
274 SDL_DFB_WINDOWDATA(window); 328 SDL_DFB_WINDOWDATA(window);
275 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 329
276 SDL_DFB_DEVICEDATA(display->device); 330 if (renddata->size_changed) {
277 DFBResult ret; 331 int cw, ch;
278 DFBSurfaceDescription dsc; 332 int ret;
279 int i, n; 333
280 334 SDL_DFB_CHECKERR(windata->surface->
281 /* 335 GetSize(windata->surface, &cw, &ch));
282 * Nothing to do here 336 if (cw != window->w || ch != window->h)
283 */ 337 SDL_DFB_CHECKERR(windata->window->
338 ResizeSurface(windata->window, window->w,
339 window->h));
340 }
284 return 0; 341 return 0;
285 error: 342 error:
286 return -1; 343 return -1;
344 }
345
346 static int
347 DirectFB_DisplayModeChanged(SDL_Renderer * renderer)
348 {
349 SDL_DFB_RENDERERDATA(renderer);
350
351 renddata->size_changed = SDL_TRUE;
352 return 0;
287 } 353 }
288 354
289 static int 355 static int
290 DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture) 356 DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
291 { 357 {
299 int ret; 365 int ret;
300 366
301 if (renddata->isyuvdirect && (dispdata->vidID >= 0) 367 if (renddata->isyuvdirect && (dispdata->vidID >= 0)
302 && (!dispdata->vidIDinuse) 368 && (!dispdata->vidIDinuse)
303 && SDL_ISPIXELFORMAT_FOURCC(data->format)) { 369 && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
304 layconf.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT; 370 layconf.flags =
371 DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
372 DLCONF_SURFACE_CAPS;
305 layconf.width = texture->w; 373 layconf.width = texture->w;
306 layconf.height = texture->h; 374 layconf.height = texture->h;
307 layconf.pixelformat = SDLToDFBPixelFormat(data->format); 375 layconf.pixelformat = SDLToDFBPixelFormat(data->format);
376 layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
308 377
309 SDL_DFB_CHECKERR(devdata->dfb-> 378 SDL_DFB_CHECKERR(devdata->dfb->
310 GetDisplayLayer(devdata->dfb, dispdata->vidID, 379 GetDisplayLayer(devdata->dfb, dispdata->vidID,
311 &data->vidlayer)); 380 &dispdata->vidlayer));
312 SDL_DFB_CHECKERR(data->vidlayer-> 381 SDL_DFB_CHECKERR(dispdata->vidlayer->
313 SetCooperativeLevel(data->vidlayer, 382 SetCooperativeLevel(dispdata->vidlayer,
314 DLSCL_EXCLUSIVE)); 383 DLSCL_EXCLUSIVE));
315 SDL_DFB_CHECKERR(data->vidlayer-> 384
316 SetConfiguration(data->vidlayer, &layconf)); 385 if (devdata->use_yuv_underlays) {
317 SDL_DFB_CHECKERR(data->vidlayer-> 386 ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
318 GetSurface(data->vidlayer, &data->surface)); 387 if (ret != DFB_OK)
319 //SDL_DFB_CHECKERR(data->vidlayer->GetDescription(data->vidlayer, laydsc)); 388 SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
389 }
390 SDL_DFB_CHECKERR(dispdata->vidlayer->
391 SetConfiguration(dispdata->vidlayer, &layconf));
392 SDL_DFB_CHECKERR(dispdata->vidlayer->
393 GetSurface(dispdata->vidlayer, &data->surface));
320 dispdata->vidIDinuse = 1; 394 dispdata->vidIDinuse = 1;
321 data->display = dispdata; 395 data->display = display;
322 SDL_DFB_DEBUG("Created HW YUV surface\n");
323
324 return 0; 396 return 0;
325 } 397 }
326 return 1; 398 return 1;
327 error: 399 error:
328 if (data->vidlayer) { 400 if (dispdata->vidlayer) {
329 SDL_DFB_RELEASE(data->surface); 401 SDL_DFB_RELEASE(data->surface);
330 SDL_DFB_CHECKERR(data->vidlayer-> 402 SDL_DFB_CHECKERR(dispdata->vidlayer->
331 SetCooperativeLevel(data->vidlayer, 403 SetCooperativeLevel(dispdata->vidlayer,
332 DLSCL_ADMINISTRATIVE)); 404 DLSCL_ADMINISTRATIVE));
333 SDL_DFB_RELEASE(data->vidlayer); 405 SDL_DFB_RELEASE(dispdata->vidlayer);
334 } 406 }
335 return 1; 407 return 1;
336 } 408 }
337 409
338 static int 410 static int
339 DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) 411 DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
340 { 412 {
341 SDL_DFB_RENDERERDATA(renderer);
342 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 413 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
343 SDL_DFB_WINDOWDATA(window);
344 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 414 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
345 SDL_DFB_DEVICEDATA(display->device); 415 SDL_DFB_DEVICEDATA(display->device);
346 DirectFB_TextureData *data; 416 DirectFB_TextureData *data;
347 DFBResult ret; 417 DFBResult ret;
348 DFBSurfaceDescription dsc; 418 DFBSurfaceDescription dsc;
349 DFBDisplayLayerDescription laydsc;
350 DFBDisplayLayerConfig layconf;
351 419
352 SDL_DFB_CALLOC(data, 1, sizeof(*data)); 420 SDL_DFB_CALLOC(data, 1, sizeof(*data));
353 texture->driverdata = data; 421 texture->driverdata = data;
354 422
355 data->format = texture->format; 423 data->format = texture->format;
356 data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format)); 424 data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format));
357 data->vidlayer = NULL;
358 425
359 if (DirectFB_AcquireVidLayer(renderer, texture) != 0) { 426 if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
360 /* fill surface description */ 427 /* fill surface description */
361 dsc.flags = 428 dsc.flags =
362 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; 429 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
363 dsc.width = texture->w; 430 dsc.width = texture->w;
364 dsc.height = texture->h; 431 dsc.height = texture->h;
365 /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance 432 /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
366 * No DSCAPS_SYSTEMONLY either - let dfb decide 433 * No DSCAPS_SYSTEMONLY either - let dfb decide
367 * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8 434 * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
435 * Depends on other settings as well. Let dfb decide.
368 */ 436 */
369 dsc.caps = DSCAPS_PREMULTIPLIED; 437 dsc.caps = DSCAPS_PREMULTIPLIED;
370 438 #if 0
371 if (texture->access == SDL_TEXTUREACCESS_STREAMING) 439 if (texture->access == SDL_TEXTUREACCESS_STREAMING)
372 dsc.caps |= DSCAPS_SYSTEMONLY; 440 dsc.caps |= DSCAPS_SYSTEMONLY;
373 else 441 else
374 dsc.caps |= DSCAPS_VIDEOONLY; 442 dsc.caps |= DSCAPS_VIDEOONLY;
443 #endif
375 444
376 /* find the right pixelformat */ 445 /* find the right pixelformat */
377 446
378 dsc.pixelformat = SDLToDFBPixelFormat(data->format); 447 dsc.pixelformat = SDLToDFBPixelFormat(data->format);
379 if (dsc.pixelformat == DSPF_UNKNOWN) { 448 if (dsc.pixelformat == DSPF_UNKNOWN) {
391 SDL_DFB_CHECKERR(data->surface-> 460 SDL_DFB_CHECKERR(data->surface->
392 GetPalette(data->surface, &data->palette)); 461 GetPalette(data->surface, &data->palette));
393 } 462 }
394 463
395 } 464 }
465 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
466 data->render_options = DSRO_NONE;
467 #endif
468
469 if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
470 data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
471 SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
472 }
473
396 return 0; 474 return 0;
397 475
398 error: 476 error:
399 SDL_DFB_RELEASE(data->palette); 477 SDL_DFB_RELEASE(data->palette);
400 SDL_DFB_RELEASE(data->surface); 478 SDL_DFB_RELEASE(data->surface);
404 482
405 static int 483 static int
406 DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, 484 DirectFB_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
407 void **pixels, int *pitch) 485 void **pixels, int *pitch)
408 { 486 {
409 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; 487 DirectFB_TextureData *texturedata =
410 488 (DirectFB_TextureData *) texture->driverdata;
411 /* 489
412 * Always fail here so in compat mode SDL_HWSURFACE is set ! 490 if (texturedata->display) {
413 */ 491 return -1;
414 492 } else {
415 return -1; 493 *pixels = texturedata->pixels;
494 *pitch = texturedata->pitch;
495 }
496 return 0;
416 } 497 }
417 498
418 static int 499 static int
419 DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 500 DirectFB_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
420 const SDL_Color * colors, int firstcolor, 501 const SDL_Color * colors, int firstcolor,
421 int ncolors) 502 int ncolors)
422 { 503 {
423 DirectFB_RenderData *renderdata =
424 (DirectFB_RenderData *) renderer->driverdata;
425 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; 504 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
426 DFBResult ret; 505 DFBResult ret;
427 506
428 if (SDL_ISPIXELFORMAT_INDEXED(data->format) 507 if (SDL_ISPIXELFORMAT_INDEXED(data->format)
429 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { 508 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
466 545
467 for (i = 0; i < ncolors; ++i) { 546 for (i = 0; i < ncolors; ++i) {
468 colors[i].r = entries[i].r; 547 colors[i].r = entries[i].r;
469 colors[i].g = entries[i].g; 548 colors[i].g = entries[i].g;
470 colors[i].b = entries[i].b; 549 colors[i].b = entries[i].b;
550 colors->unused = SDL_ALPHA_OPAQUE;
471 } 551 }
472 return 0; 552 return 0;
473 } else { 553 } else {
474 SDL_SetError("YUV textures don't have a palette"); 554 SDL_SetError("YUV textures don't have a palette");
475 return -1; 555 return -1;
508 } 588 }
509 589
510 static int 590 static int
511 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) 591 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
512 { 592 {
593 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
594
595 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
596
513 switch (texture->scaleMode) { 597 switch (texture->scaleMode) {
514 case SDL_TEXTURESCALEMODE_NONE: 598 case SDL_TEXTURESCALEMODE_NONE:
515 case SDL_TEXTURESCALEMODE_FAST: 599 case SDL_TEXTURESCALEMODE_FAST:
516 return 0; 600 data->render_options = DSRO_NONE;
601 break;
517 case SDL_TEXTURESCALEMODE_SLOW: 602 case SDL_TEXTURESCALEMODE_SLOW:
603 data->render_options = DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE;
604 break;
518 case SDL_TEXTURESCALEMODE_BEST: 605 case SDL_TEXTURESCALEMODE_BEST:
519 SDL_Unsupported(); 606 data->render_options =
520 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST; 607 DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS;
521 return -1; 608 break;
522 default: 609 default:
523 SDL_Unsupported(); 610 SDL_Unsupported();
611 data->render_options = DSRO_NONE;
524 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; 612 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
525 return -1; 613 return -1;
526 } 614 }
615 #endif
527 return 0; 616 return 0;
528 } 617 }
529 618
530 static int 619 static int
531 DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 620 DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
532 const SDL_Rect * rect, const void *pixels, int pitch) 621 const SDL_Rect * rect, const void *pixels, int pitch)
533 { 622 {
534 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; 623 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
535 DirectFB_RenderData *renderdata =
536 (DirectFB_RenderData *) renderer->driverdata;
537 DFBResult ret; 624 DFBResult ret;
538 Uint8 *dpixels; 625 Uint8 *dpixels;
539 int dpitch; 626 int dpitch;
540 Uint8 *src, *dst; 627 Uint8 *src, *dst;
541 int row; 628 int row;
564 static int 651 static int
565 DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 652 DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
566 const SDL_Rect * rect, int markDirty, void **pixels, 653 const SDL_Rect * rect, int markDirty, void **pixels,
567 int *pitch) 654 int *pitch)
568 { 655 {
569 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; 656 DirectFB_TextureData *texturedata =
657 (DirectFB_TextureData *) texture->driverdata;
570 DFBResult ret; 658 DFBResult ret;
571 void *fdata; 659
572 int fpitch; 660 if (markDirty) {
573 661 SDL_AddDirtyRect(&texturedata->dirty, rect);
574 SDL_DFB_CHECKERR(data->surface->Lock(data->surface, 662 }
575 DSLF_WRITE | DSLF_READ, &fdata, 663
576 &fpitch)); 664 if (texturedata->display) {
577 data->pixels = fdata; 665 void *fdata;
578 data->pitch = fpitch; 666 int fpitch;
579 667
580 switch (texture->format) { 668 SDL_DFB_CHECKERR(texturedata->surface->Lock(texturedata->surface,
581 case SDL_PIXELFORMAT_YV12: 669 DSLF_WRITE | DSLF_READ,
582 case SDL_PIXELFORMAT_IYUV: 670 &fdata, &fpitch));
583 if (rect 671 *pitch = fpitch;
584 && (rect->x != 0 || rect->y != 0 || rect->w != texture->w 672 *pixels = fdata;
585 || rect->h != texture->h)) { 673 } else {
586 SDL_SetError 674 *pixels =
587 ("YV12 and IYUV textures only support full surface locks"); 675 (void *) ((Uint8 *) texturedata->pixels +
588 return -1; 676 rect->y * texturedata->pitch +
589 } 677 rect->x * SDL_BYTESPERPIXEL(texture->format));
590 break; 678 *pitch = texturedata->pitch;
591 default: 679 }
592 /* Only one plane, no worries */ 680 return 0;
593 break; 681
594 }
595
596 *pitch = data->pitch;
597 *pixels = data->pixels;
598
599 return 0;
600 error: 682 error:
601 return -1; 683 return -1;
602 } 684 }
603 685
604 static void 686 static void
605 DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) 687 DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
606 { 688 {
607 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; 689 DirectFB_TextureData *texturedata =
608 690 (DirectFB_TextureData *) texture->driverdata;
609 data->surface->Unlock(data->surface); 691
610 data->pixels = NULL; 692 if (texturedata->display) {
693 texturedata->surface->Unlock(texturedata->surface);
694 texturedata->pixels = NULL;
695 }
611 } 696 }
612 697
613 static void 698 static void
614 DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 699 DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
615 int numrects, const SDL_Rect * rects) 700 int numrects, const SDL_Rect * rects)
616 { 701 {
617 //TODO: DirtyTexture 702 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
703 int i;
704
705 for (i = 0; i < numrects; ++i) {
706 SDL_AddDirtyRect(&data->dirty, &rects[i]);
707 }
618 } 708 }
619 709
620 static int 710 static int
621 DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, 711 DirectFB_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
622 Uint8 a, const SDL_Rect * rect) 712 Uint8 a, const SDL_Rect * rect)
641 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; 731 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
642 DirectFB_TextureData *texturedata = 732 DirectFB_TextureData *texturedata =
643 (DirectFB_TextureData *) texture->driverdata; 733 (DirectFB_TextureData *) texture->driverdata;
644 DFBResult ret; 734 DFBResult ret;
645 735
646 if (texturedata->vidlayer) { 736 if (texturedata->display) {
647 int px, py; 737 int px, py;
648 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 738 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
649 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 739 SDL_DFB_WINDOWDATA(window);
650 SDL_DFB_DEVICEDATA(display->device); 740 SDL_VideoDisplay *display = texturedata->display;
651 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; 741 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
652 SDL_DFB_WINDOWDATA(window); 742
653 743 SDL_DFB_CHECKERR(dispdata->vidlayer->
654 SDL_DFB_CHECKERR(texturedata->vidlayer-> 744 SetSourceRectangle(dispdata->vidlayer, srcrect->x,
655 SetSourceRectangle(texturedata->vidlayer, srcrect->x,
656 srcrect->y, srcrect->w, 745 srcrect->y, srcrect->w,
657 srcrect->h)); 746 srcrect->h));
658 windata->window->GetPosition(windata->window, &px, &py); 747 windata->window->GetPosition(windata->window, &px, &py);
659 SDL_DFB_CHECKERR(texturedata->vidlayer-> 748 SDL_DFB_CHECKERR(dispdata->vidlayer->
660 SetScreenRectangle(texturedata->vidlayer, 749 SetScreenRectangle(dispdata->vidlayer,
661 px + dstrect->x, py + dstrect->y, 750 px + dstrect->x, py + dstrect->y,
662 dstrect->w, dstrect->h)); 751 dstrect->w, dstrect->h));
663 } else { 752 } else {
664 DFBRectangle sr, dr; 753 DFBRectangle sr, dr;
665 DFBSurfaceBlittingFlags flags = 0; 754 DFBSurfaceBlittingFlags flags = 0;
666 755
667 sr.x = srcrect->x; 756 if (texturedata->dirty.list) {
668 sr.y = srcrect->y; 757 SDL_DirtyRect *dirty;
669 sr.w = srcrect->w; 758 void *pixels;
670 sr.h = srcrect->h; 759 int bpp = SDL_BYTESPERPIXEL(texture->format);
671 760 int pitch = texturedata->pitch;
672 dr.x = dstrect->x; 761
673 dr.y = dstrect->y; 762 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
674 dr.w = dstrect->w; 763 SDL_Rect *rect = &dirty->rect;
675 dr.h = dstrect->h; 764 pixels =
765 (void *) ((Uint8 *) texturedata->pixels +
766 rect->y * pitch + rect->x * bpp);
767 DirectFB_UpdateTexture(renderer, texture, rect,
768 texturedata->pixels,
769 texturedata->pitch);
770 }
771 SDL_ClearDirtyRects(&texturedata->dirty);
772 }
773 #if (DIRECTFB_MAJOR_VERSION == 1) && (DIRECTFB_MINOR_VERSION >= 2)
774 SDL_DFB_CHECKERR(data->surface->SetRenderOptions(data->surface,
775 texturedata->
776 render_options));
777 #endif
778
779 SDLtoDFBRect(srcrect, &sr);
780 SDLtoDFBRect(dstrect, &dr);
676 781
677 if (texture-> 782 if (texture->
678 modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA)) 783 modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA))
679 { 784 {
680 Uint8 alpha = 0xFF; 785 Uint8 alpha = 0xFF;
693 } 798 }
694 } 799 }
695 800
696 switch (texture->blendMode) { 801 switch (texture->blendMode) {
697 case SDL_TEXTUREBLENDMODE_NONE: 802 case SDL_TEXTUREBLENDMODE_NONE:
803 /**< No blending */
698 flags |= DSBLIT_NOFX; 804 flags |= DSBLIT_NOFX;
699 data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE); 805 data->surface->SetSrcBlendFunction(data->surface, DSBF_ONE);
700 data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO); 806 data->surface->SetDstBlendFunction(data->surface, DSBF_ZERO);
701 break; 807 break;
702 case SDL_TEXTUREBLENDMODE_MASK: 808 case SDL_TEXTUREBLENDMODE_MASK:
723 break; 829 break;
724 } 830 }
725 831
726 SDL_DFB_CHECKERR(data->surface-> 832 SDL_DFB_CHECKERR(data->surface->
727 SetBlittingFlags(data->surface, flags)); 833 SetBlittingFlags(data->surface, flags));
834
728 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { 835 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
729 SDL_DFB_CHECKERR(data->surface-> 836 SDL_DFB_CHECKERR(data->surface->
730 Blit(data->surface, texturedata->surface, &sr, 837 Blit(data->surface, texturedata->surface,
731 dr.x, dr.y)); 838 &sr, dr.x, dr.y));
732 } else { 839 } else {
733 SDL_DFB_CHECKERR(data->surface-> 840 SDL_DFB_CHECKERR(data->surface->
734 StretchBlit(data->surface, texturedata->surface, 841 StretchBlit(data->surface, texturedata->surface,
735 &sr, &dr)); 842 &sr, &dr));
736 } 843 }
744 DirectFB_RenderPresent(SDL_Renderer * renderer) 851 DirectFB_RenderPresent(SDL_Renderer * renderer)
745 { 852 {
746 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; 853 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
747 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 854 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
748 855
749 SDL_DirtyRect *dirty;
750 DFBRectangle sr; 856 DFBRectangle sr;
751 DFBResult ret; 857 DFBResult ret;
752 858
753 sr.x = 0; 859 sr.x = 0;
754 sr.y = 0; 860 sr.y = 0;
755 sr.w = window->w; 861 sr.w = window->w;
756 sr.h = window->h; 862 sr.h = window->h;
757 863
758 /* Send the data to the display */ 864 /* Send the data to the display */
759 SDL_DFB_CHECKERR(data->surface-> 865 SDL_DFB_CHECKERR(data->surface->
760 Flip(data->surface, NULL, data->flipflags)); 866 Flip(data->surface, NULL, 0 * data->flipflags));
761 867
762 return; 868 return;
763 error: 869 error:
764 return; 870 return;
765 } 871 }
773 return; 879 return;
774 } 880 }
775 SDL_DFB_RELEASE(data->palette); 881 SDL_DFB_RELEASE(data->palette);
776 SDL_DFB_RELEASE(data->surface); 882 SDL_DFB_RELEASE(data->surface);
777 if (data->display) { 883 if (data->display) {
778 data->display->vidIDinuse = 0; 884 DFB_DisplayData *dispdata =
779 data->vidlayer->SetCooperativeLevel(data->vidlayer, 885 (DFB_DisplayData *) data->display->driverdata;
780 DLSCL_ADMINISTRATIVE); 886 dispdata->vidIDinuse = 0;
781 } 887 dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer,
782 SDL_DFB_RELEASE(data->vidlayer); 888 DLSCL_ADMINISTRATIVE);
889 SDL_DFB_RELEASE(dispdata->vidlayer);
890 }
891 SDL_FreeDirtyRects(&data->dirty);
892 SDL_DFB_FREE(data->pixels);
783 SDL_free(data); 893 SDL_free(data);
784 texture->driverdata = NULL; 894 texture->driverdata = NULL;
785 } 895 }
786 896
787 static void 897 static void
788 DirectFB_DestroyRenderer(SDL_Renderer * renderer) 898 DirectFB_DestroyRenderer(SDL_Renderer * renderer)
789 { 899 {
790 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; 900 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
791 int i;
792 901
793 if (data) { 902 if (data) {
794 data->surface = NULL; 903 SDL_DFB_RELEASE(data->surface);
795 SDL_free(data); 904 SDL_free(data);
796 } 905 }
797 SDL_free(renderer); 906 SDL_free(renderer);
798 } 907 }
799 908