Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_render.c @ 5152:be02be2ea897
Making the API simpler, removed support for palettized video modes and textures.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 01 Feb 2011 21:23:43 -0800 |
parents | 5429daf5e3f9 |
children | fb424691cfc7 |
comparison
equal
deleted
inserted
replaced
5151:5429daf5e3f9 | 5152:be02be2ea897 |
---|---|
41 static int DirectFB_CreateTexture(SDL_Renderer * renderer, | 41 static int DirectFB_CreateTexture(SDL_Renderer * renderer, |
42 SDL_Texture * texture); | 42 SDL_Texture * texture); |
43 static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer, | 43 static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer, |
44 SDL_Texture * texture, | 44 SDL_Texture * texture, |
45 void **pixels, int *pitch); | 45 void **pixels, int *pitch); |
46 static int DirectFB_SetTexturePalette(SDL_Renderer * renderer, | |
47 SDL_Texture * texture, | |
48 const SDL_Color * colors, | |
49 int firstcolor, int ncolors); | |
50 static int DirectFB_GetTexturePalette(SDL_Renderer * renderer, | |
51 SDL_Texture * texture, | |
52 SDL_Color * colors, | |
53 int firstcolor, int ncolors); | |
54 static int DirectFB_UpdateTexture(SDL_Renderer * renderer, | 46 static int DirectFB_UpdateTexture(SDL_Renderer * renderer, |
55 SDL_Texture * texture, | 47 SDL_Texture * texture, |
56 const SDL_Rect * rect, | 48 const SDL_Rect * rect, |
57 const void *pixels, int pitch); | 49 const void *pixels, int pitch); |
58 static int DirectFB_LockTexture(SDL_Renderer * renderer, | 50 static int DirectFB_LockTexture(SDL_Renderer * renderer, |
84 SDL_RenderDriver DirectFB_RenderDriver = { | 76 SDL_RenderDriver DirectFB_RenderDriver = { |
85 DirectFB_CreateRenderer, | 77 DirectFB_CreateRenderer, |
86 { | 78 { |
87 "directfb", | 79 "directfb", |
88 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), | 80 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
89 14, | 81 12, |
90 { | 82 { |
91 SDL_PIXELFORMAT_INDEX4LSB, | |
92 SDL_PIXELFORMAT_INDEX8, | |
93 SDL_PIXELFORMAT_RGB332, | 83 SDL_PIXELFORMAT_RGB332, |
94 SDL_PIXELFORMAT_RGB555, | 84 SDL_PIXELFORMAT_RGB555, |
95 SDL_PIXELFORMAT_RGB565, | 85 SDL_PIXELFORMAT_RGB565, |
96 SDL_PIXELFORMAT_RGB888, | 86 SDL_PIXELFORMAT_RGB888, |
97 SDL_PIXELFORMAT_ARGB8888, | 87 SDL_PIXELFORMAT_ARGB8888, |
121 { | 111 { |
122 IDirectFBSurface *surface; | 112 IDirectFBSurface *surface; |
123 Uint32 format; | 113 Uint32 format; |
124 void *pixels; | 114 void *pixels; |
125 int pitch; | 115 int pitch; |
126 IDirectFBPalette *palette; | |
127 SDL_VideoDisplay *display; | 116 SDL_VideoDisplay *display; |
128 SDL_DirtyRectList dirty; | 117 SDL_DirtyRectList dirty; |
129 #if (DFB_VERSION_ATLEAST(1,2,0)) | 118 #if (DFB_VERSION_ATLEAST(1,2,0)) |
130 DFBSurfaceRenderOptions render_options; | 119 DFBSurfaceRenderOptions render_options; |
131 #endif | 120 #endif |
146 { | 135 { |
147 /* Drawing primitive ? */ | 136 /* Drawing primitive ? */ |
148 if (!data) | 137 if (!data) |
149 return 0; | 138 return 0; |
150 switch (data->format) { | 139 switch (data->format) { |
151 case SDL_PIXELFORMAT_INDEX4LSB: | |
152 case SDL_PIXELFORMAT_ARGB4444: | 140 case SDL_PIXELFORMAT_ARGB4444: |
153 case SDL_PIXELFORMAT_ARGB1555: | 141 case SDL_PIXELFORMAT_ARGB1555: |
154 case SDL_PIXELFORMAT_ARGB8888: | 142 case SDL_PIXELFORMAT_ARGB8888: |
155 case SDL_PIXELFORMAT_RGBA8888: | 143 case SDL_PIXELFORMAT_RGBA8888: |
156 case SDL_PIXELFORMAT_ABGR8888: | 144 case SDL_PIXELFORMAT_ABGR8888: |
209 for (i = 0; i < _this->num_displays; ++i) { | 197 for (i = 0; i < _this->num_displays; ++i) { |
210 SDL_AddRenderDriver(&_this->displays[i], &DirectFB_RenderDriver); | 198 SDL_AddRenderDriver(&_this->displays[i], &DirectFB_RenderDriver); |
211 } | 199 } |
212 } | 200 } |
213 | 201 |
214 static int | |
215 DisplayPaletteChanged(void *userdata, SDL_Palette * palette) | |
216 { | |
217 #if USE_DISPLAY_PALETTE | |
218 DirectFB_RenderData *data = (DirectFB_RenderData *) userdata; | |
219 SDL_DFB_WINDOWSURFACE(data->window); | |
220 IDirectFBPalette *surfpal; | |
221 | |
222 int i; | |
223 int ncolors; | |
224 DFBColor entries[256]; | |
225 | |
226 SDL_DFB_CHECKERR(destsurf->GetPalette(destsurf, &surfpal)); | |
227 | |
228 /* FIXME: number of colors */ | |
229 ncolors = (palette->ncolors < 256 ? palette->ncolors : 256); | |
230 | |
231 for (i = 0; i < ncolors; ++i) { | |
232 entries[i].r = palette->colors[i].r; | |
233 entries[i].g = palette->colors[i].g; | |
234 entries[i].b = palette->colors[i].b; | |
235 entries[i].a = palette->colors[i].unused; | |
236 } | |
237 SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0)); | |
238 return 0; | |
239 error: | |
240 #else | |
241 SDL_Unsupported(); | |
242 #endif | |
243 return -1; | |
244 } | |
245 | |
246 | |
247 SDL_Renderer * | 202 SDL_Renderer * |
248 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) | 203 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) |
249 { | 204 { |
250 SDL_DFB_WINDOWDATA(window); | 205 SDL_DFB_WINDOWDATA(window); |
251 SDL_VideoDisplay *display = window->display; | 206 SDL_VideoDisplay *display = window->display; |
258 | 213 |
259 renderer->DisplayModeChanged = DirectFB_DisplayModeChanged; | 214 renderer->DisplayModeChanged = DirectFB_DisplayModeChanged; |
260 renderer->ActivateRenderer = DirectFB_ActivateRenderer; | 215 renderer->ActivateRenderer = DirectFB_ActivateRenderer; |
261 renderer->CreateTexture = DirectFB_CreateTexture; | 216 renderer->CreateTexture = DirectFB_CreateTexture; |
262 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; | 217 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; |
263 renderer->SetTexturePalette = DirectFB_SetTexturePalette; | |
264 renderer->GetTexturePalette = DirectFB_GetTexturePalette; | |
265 renderer->UpdateTexture = DirectFB_UpdateTexture; | 218 renderer->UpdateTexture = DirectFB_UpdateTexture; |
266 renderer->LockTexture = DirectFB_LockTexture; | 219 renderer->LockTexture = DirectFB_LockTexture; |
267 renderer->UnlockTexture = DirectFB_UnlockTexture; | 220 renderer->UnlockTexture = DirectFB_UnlockTexture; |
268 renderer->DirtyTexture = DirectFB_DirtyTexture; | 221 renderer->DirtyTexture = DirectFB_DirtyTexture; |
269 renderer->RenderDrawPoints = DirectFB_RenderDrawPoints; | 222 renderer->RenderDrawPoints = DirectFB_RenderDrawPoints; |
296 data->isyuvdirect = 0; /* default is off! */ | 249 data->isyuvdirect = 0; /* default is off! */ |
297 p = SDL_getenv(DFBENV_USE_YUV_DIRECT); | 250 p = SDL_getenv(DFBENV_USE_YUV_DIRECT); |
298 if (p) | 251 if (p) |
299 data->isyuvdirect = atoi(p); | 252 data->isyuvdirect = atoi(p); |
300 | 253 |
301 /* Set up a palette watch on the display palette */ | |
302 if (display->palette) { | |
303 SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data); | |
304 } | |
305 | |
306 return renderer; | 254 return renderer; |
307 | 255 |
308 error: | 256 error: |
309 SDL_DFB_FREE(renderer); | 257 SDL_DFB_FREE(renderer); |
310 SDL_DFB_FREE(data); | 258 SDL_DFB_FREE(data); |
313 | 261 |
314 static DFBSurfacePixelFormat | 262 static DFBSurfacePixelFormat |
315 SDLToDFBPixelFormat(Uint32 format) | 263 SDLToDFBPixelFormat(Uint32 format) |
316 { | 264 { |
317 switch (format) { | 265 switch (format) { |
318 case SDL_PIXELFORMAT_INDEX4LSB: | |
319 return DSPF_ALUT44; | |
320 case SDL_PIXELFORMAT_INDEX8: | |
321 return DSPF_LUT8; | |
322 case SDL_PIXELFORMAT_RGB332: | 266 case SDL_PIXELFORMAT_RGB332: |
323 return DSPF_RGB332; | 267 return DSPF_RGB332; |
324 case SDL_PIXELFORMAT_RGB555: | 268 case SDL_PIXELFORMAT_RGB555: |
325 return DSPF_ARGB1555; | 269 return DSPF_ARGB1555; |
326 case SDL_PIXELFORMAT_ARGB4444: | 270 case SDL_PIXELFORMAT_ARGB4444: |
343 return DSPF_YUY2; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ | 287 return DSPF_YUY2; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ |
344 case SDL_PIXELFORMAT_UYVY: | 288 case SDL_PIXELFORMAT_UYVY: |
345 return DSPF_UYVY; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ | 289 return DSPF_UYVY; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ |
346 case SDL_PIXELFORMAT_YVYU: | 290 case SDL_PIXELFORMAT_YVYU: |
347 return DSPF_UNKNOWN; /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ | 291 return DSPF_UNKNOWN; /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ |
348 case SDL_PIXELFORMAT_INDEX1LSB: | |
349 return DSPF_UNKNOWN; | |
350 case SDL_PIXELFORMAT_INDEX1MSB: | |
351 return DSPF_UNKNOWN; | |
352 case SDL_PIXELFORMAT_INDEX4MSB: | |
353 return DSPF_UNKNOWN; | |
354 #if (DFB_VERSION_ATLEAST(1,2,0)) | 292 #if (DFB_VERSION_ATLEAST(1,2,0)) |
355 case SDL_PIXELFORMAT_RGB444: | 293 case SDL_PIXELFORMAT_RGB444: |
356 return DSPF_RGB444; | 294 return DSPF_RGB444; |
357 #endif | 295 #endif |
358 case SDL_PIXELFORMAT_BGR24: | 296 case SDL_PIXELFORMAT_BGR24: |
497 data->pixels = NULL; | 435 data->pixels = NULL; |
498 | 436 |
499 /* Create the surface */ | 437 /* Create the surface */ |
500 SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, | 438 SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, |
501 &data->surface)); | 439 &data->surface)); |
502 if (SDL_ISPIXELFORMAT_INDEXED(data->format) | |
503 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { | |
504 SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, | |
505 &data->palette)); | |
506 } | |
507 | |
508 } | 440 } |
509 #if (DFB_VERSION_ATLEAST(1,2,0)) | 441 #if (DFB_VERSION_ATLEAST(1,2,0)) |
510 data->render_options = DSRO_NONE; | 442 data->render_options = DSRO_NONE; |
511 #endif | 443 #endif |
512 | 444 |
541 } else { | 473 } else { |
542 *pixels = texturedata->pixels; | 474 *pixels = texturedata->pixels; |
543 *pitch = texturedata->pitch; | 475 *pitch = texturedata->pitch; |
544 } | 476 } |
545 return 0; | 477 return 0; |
546 } | |
547 | |
548 static int | |
549 DirectFB_SetTexturePalette(SDL_Renderer * renderer, | |
550 SDL_Texture * texture, | |
551 const SDL_Color * colors, int firstcolor, | |
552 int ncolors) | |
553 { | |
554 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; | |
555 | |
556 if (SDL_ISPIXELFORMAT_INDEXED(data->format) | |
557 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { | |
558 DFBColor entries[256]; | |
559 int i; | |
560 | |
561 for (i = 0; i < ncolors; ++i) { | |
562 entries[i].r = colors[i].r; | |
563 entries[i].g = colors[i].g; | |
564 entries[i].b = colors[i].b; | |
565 entries[i].a = 0xFF; | |
566 } | |
567 SDL_DFB_CHECKERR(data-> | |
568 palette->SetEntries(data->palette, entries, ncolors, | |
569 firstcolor)); | |
570 return 0; | |
571 } else { | |
572 SDL_SetError("YUV textures don't have a palette"); | |
573 return -1; | |
574 } | |
575 error: | |
576 return -1; | |
577 } | |
578 | |
579 static int | |
580 DirectFB_GetTexturePalette(SDL_Renderer * renderer, | |
581 SDL_Texture * texture, SDL_Color * colors, | |
582 int firstcolor, int ncolors) | |
583 { | |
584 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; | |
585 | |
586 if (SDL_ISPIXELFORMAT_INDEXED(data->format) | |
587 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { | |
588 DFBColor entries[256]; | |
589 int i; | |
590 | |
591 SDL_DFB_CHECKERR(data-> | |
592 palette->GetEntries(data->palette, entries, ncolors, | |
593 firstcolor)); | |
594 | |
595 for (i = 0; i < ncolors; ++i) { | |
596 colors[i].r = entries[i].r; | |
597 colors[i].g = entries[i].g; | |
598 colors[i].b = entries[i].b; | |
599 colors->unused = SDL_ALPHA_OPAQUE; | |
600 } | |
601 return 0; | |
602 } else { | |
603 SDL_SetError("YUV textures don't have a palette"); | |
604 return -1; | |
605 } | |
606 error: | |
607 return -1; | |
608 } | 478 } |
609 | 479 |
610 static int | 480 static int |
611 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | 481 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) |
612 { | 482 { |