Mercurial > sdl-ios-xcode
comparison src/video/directfb/SDL_DirectFB_render.c @ 5202:164f20ba08eb
Updated the DirectFB support, from Couriersud
attached is a working directfb driver diff which works with the current
changes. There are a number of changes around it as well, e.g.
configure.in.
The directfb renderdriver right now still depends on a some "includes"
from src/video/directfb. That's why it is not yet moved to the new
render folder.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Feb 2011 16:07:10 -0800 |
parents | fb424691cfc7 |
children | 58265e606e4e |
comparison
equal
deleted
inserted
replaced
5201:7c3422025c35 | 5202:164f20ba08eb |
---|---|
16 License along with this library; if not, write to the Free Software | 16 License along with this library; if not, write to the Free Software |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 | 21 |
22 SDL1.3 implementation by couriersud@arcor.de | 22 SDL1.3 DirectFB driver by couriersud@arcor.de |
23 | 23 |
24 */ | 24 */ |
25 #include "SDL_config.h" | |
26 | |
27 #include "SDL_DirectFB_video.h" | 25 #include "SDL_DirectFB_video.h" |
28 #include "SDL_DirectFB_render.h" | 26 #include "SDL_DirectFB_window.h" |
29 #include "../SDL_yuv_sw_c.h" | 27 #include "SDL_DirectFB_modes.h" |
28 | |
29 #include "SDL_DirectFB_shape.h" | |
30 | |
31 #include "../SDL_sysvideo.h" | |
32 #include "../../render/SDL_sysrender.h" | |
33 //#include "../SDL_rect_c.h" | |
34 //#include "../SDL_yuv_sw_c.h" | |
30 | 35 |
31 /* the following is not yet tested ... */ | 36 /* the following is not yet tested ... */ |
32 #define USE_DISPLAY_PALETTE (0) | 37 #define USE_DISPLAY_PALETTE (0) |
33 | 38 |
39 | |
40 #define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL) | |
41 | |
42 | |
34 /* GDI renderer implementation */ | 43 /* GDI renderer implementation */ |
35 | 44 |
36 static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window, | 45 static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window, |
37 Uint32 flags); | 46 Uint32 flags); |
38 static int DirectFB_DisplayModeChanged(SDL_Renderer * renderer); | 47 static void DirectFB_ActivateRenderer(SDL_Renderer * renderer); |
39 static int DirectFB_ActivateRenderer(SDL_Renderer * renderer); | |
40 static int DirectFB_CreateTexture(SDL_Renderer * renderer, | 48 static int DirectFB_CreateTexture(SDL_Renderer * renderer, |
41 SDL_Texture * texture); | 49 SDL_Texture * texture); |
42 static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer, | 50 static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer, |
43 SDL_Texture * texture, | 51 SDL_Texture * texture, |
44 void **pixels, int *pitch); | 52 void **pixels, int *pitch); |
53 static int DirectFB_SetTexturePalette(SDL_Renderer * renderer, | |
54 SDL_Texture * texture, | |
55 const SDL_Color * colors, | |
56 int firstcolor, int ncolors); | |
57 static int DirectFB_GetTexturePalette(SDL_Renderer * renderer, | |
58 SDL_Texture * texture, | |
59 SDL_Color * colors, | |
60 int firstcolor, int ncolors); | |
61 static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, | |
62 SDL_Texture * texture); | |
63 static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer, | |
64 SDL_Texture * texture); | |
65 static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, | |
66 SDL_Texture * texture); | |
67 static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, | |
68 SDL_Texture * texture); | |
45 static int DirectFB_UpdateTexture(SDL_Renderer * renderer, | 69 static int DirectFB_UpdateTexture(SDL_Renderer * renderer, |
46 SDL_Texture * texture, | 70 SDL_Texture * texture, |
47 const SDL_Rect * rect, | 71 const SDL_Rect * rect, |
48 const void *pixels, int pitch); | 72 const void *pixels, int pitch); |
49 static int DirectFB_LockTexture(SDL_Renderer * renderer, | 73 static int DirectFB_LockTexture(SDL_Renderer * renderer, |
50 SDL_Texture * texture, | 74 SDL_Texture * texture, |
51 const SDL_Rect * rect, int markDirty, | 75 const SDL_Rect * rect, |
52 void **pixels, int *pitch); | 76 void **pixels, int *pitch); |
53 static void DirectFB_UnlockTexture(SDL_Renderer * renderer, | 77 static void DirectFB_UnlockTexture(SDL_Renderer * renderer, |
54 SDL_Texture * texture); | 78 SDL_Texture * texture); |
55 static void DirectFB_DirtyTexture(SDL_Renderer * renderer, | 79 static void DirectFB_DirtyTexture(SDL_Renderer * renderer, |
56 SDL_Texture * texture, int numrects, | 80 SDL_Texture * texture, int numrects, |
57 const SDL_Rect * rects); | 81 const SDL_Rect * rects); |
82 static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer); | |
58 static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, | 83 static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer, |
59 const SDL_Point * points, int count); | 84 const SDL_Point * points, int count); |
60 static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, | 85 static int DirectFB_RenderDrawLines(SDL_Renderer * renderer, |
61 const SDL_Point * points, int count); | 86 const SDL_Point * points, int count); |
87 static int DirectFB_RenderDrawRects(SDL_Renderer * renderer, | |
88 const SDL_Rect ** rects, int count); | |
62 static int DirectFB_RenderFillRects(SDL_Renderer * renderer, | 89 static int DirectFB_RenderFillRects(SDL_Renderer * renderer, |
63 const SDL_Rect ** rects, int count); | 90 const SDL_Rect ** rects, int count); |
64 static int DirectFB_RenderCopy(SDL_Renderer * renderer, | 91 static int DirectFB_RenderCopy(SDL_Renderer * renderer, |
65 SDL_Texture * texture, | 92 SDL_Texture * texture, |
66 const SDL_Rect * srcrect, | 93 const SDL_Rect * srcrect, |
67 const SDL_Rect * dstrect); | 94 const SDL_Rect * dstrect); |
68 static void DirectFB_RenderPresent(SDL_Renderer * renderer); | 95 static void DirectFB_RenderPresent(SDL_Renderer * renderer); |
69 static void DirectFB_DestroyTexture(SDL_Renderer * renderer, | 96 static void DirectFB_DestroyTexture(SDL_Renderer * renderer, |
70 SDL_Texture * texture); | 97 SDL_Texture * texture); |
71 static void DirectFB_DestroyRenderer(SDL_Renderer * renderer); | 98 static void DirectFB_DestroyRenderer(SDL_Renderer * renderer); |
99 static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, | |
100 Uint32 format, void * pixels, int pitch); | |
101 static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, | |
102 Uint32 format, const void * pixels, int pitch); | |
103 | |
72 | 104 |
73 #define SDL_DFB_WINDOWSURFACE(win) IDirectFBSurface *destsurf = ((DFB_WindowData *) ((win)->driverdata))->surface; | 105 #define SDL_DFB_WINDOWSURFACE(win) IDirectFBSurface *destsurf = ((DFB_WindowData *) ((win)->driverdata))->surface; |
74 | 106 |
75 SDL_RenderDriver DirectFB_RenderDriver = { | 107 SDL_RenderDriver DirectFB_RenderDriver = { |
76 DirectFB_CreateRenderer, | 108 DirectFB_CreateRenderer, |
77 { | 109 { |
78 "directfb", | 110 "directfb", |
79 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), | 111 (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), |
80 12, | 112 /* (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | |
113 SDL_TEXTUREMODULATE_ALPHA), | |
114 (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND | | |
115 SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), | |
116 (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST | | |
117 SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST),*/ | |
118 0, | |
81 { | 119 { |
82 SDL_PIXELFORMAT_RGB332, | 120 /* formats filled in later */ |
83 SDL_PIXELFORMAT_RGB555, | 121 }, |
84 SDL_PIXELFORMAT_RGB565, | |
85 SDL_PIXELFORMAT_RGB888, | |
86 SDL_PIXELFORMAT_ARGB8888, | |
87 SDL_PIXELFORMAT_ARGB4444, | |
88 SDL_PIXELFORMAT_ARGB1555, | |
89 SDL_PIXELFORMAT_RGB24, | |
90 SDL_PIXELFORMAT_YV12, | |
91 SDL_PIXELFORMAT_IYUV, | |
92 SDL_PIXELFORMAT_YUY2, | |
93 SDL_PIXELFORMAT_UYVY}, | |
94 0, | 122 0, |
95 0} | 123 0} |
96 }; | 124 }; |
97 | 125 |
98 typedef struct | 126 typedef struct |
99 { | 127 { |
100 SDL_Window *window; | 128 SDL_Window *window; |
101 DFBSurfaceFlipFlags flipflags; | 129 DFBSurfaceFlipFlags flipflags; |
102 int isyuvdirect; | |
103 int size_changed; | 130 int size_changed; |
104 int lastBlendMode; | 131 int lastBlendMode; |
105 DFBSurfaceBlittingFlags blitFlags; | 132 DFBSurfaceBlittingFlags blitFlags; |
106 DFBSurfaceDrawingFlags drawFlags; | 133 DFBSurfaceDrawingFlags drawFlags; |
107 } DirectFB_RenderData; | 134 } DirectFB_RenderData; |
110 { | 137 { |
111 IDirectFBSurface *surface; | 138 IDirectFBSurface *surface; |
112 Uint32 format; | 139 Uint32 format; |
113 void *pixels; | 140 void *pixels; |
114 int pitch; | 141 int pitch; |
115 SDL_VideoDisplay *display; | 142 IDirectFBPalette *palette; |
116 SDL_DirtyRectList dirty; | 143 int isDirty; |
144 | |
145 SDL_VideoDisplay *display; /* only for yuv textures */ | |
146 | |
117 #if (DFB_VERSION_ATLEAST(1,2,0)) | 147 #if (DFB_VERSION_ATLEAST(1,2,0)) |
118 DFBSurfaceRenderOptions render_options; | 148 DFBSurfaceRenderOptions render_options; |
119 #endif | 149 #endif |
120 } DirectFB_TextureData; | 150 } DirectFB_TextureData; |
121 | 151 |
133 TextureHasAlpha(DirectFB_TextureData * data) | 163 TextureHasAlpha(DirectFB_TextureData * data) |
134 { | 164 { |
135 /* Drawing primitive ? */ | 165 /* Drawing primitive ? */ |
136 if (!data) | 166 if (!data) |
137 return 0; | 167 return 0; |
168 | |
169 return (DFB_PIXELFORMAT_HAS_ALPHA(DirectFB_SDLToDFBPixelFormat(data->format)) ? 1 : 0); | |
170 #if 0 | |
138 switch (data->format) { | 171 switch (data->format) { |
172 case SDL_PIXELFORMAT_INDEX4LSB: | |
173 case SDL_PIXELFORMAT_INDEX4MSB: | |
139 case SDL_PIXELFORMAT_ARGB4444: | 174 case SDL_PIXELFORMAT_ARGB4444: |
140 case SDL_PIXELFORMAT_ARGB1555: | 175 case SDL_PIXELFORMAT_ARGB1555: |
141 case SDL_PIXELFORMAT_ARGB8888: | 176 case SDL_PIXELFORMAT_ARGB8888: |
142 case SDL_PIXELFORMAT_RGBA8888: | 177 case SDL_PIXELFORMAT_RGBA8888: |
143 case SDL_PIXELFORMAT_ABGR8888: | 178 case SDL_PIXELFORMAT_ABGR8888: |
144 case SDL_PIXELFORMAT_BGRA8888: | 179 case SDL_PIXELFORMAT_BGRA8888: |
145 case SDL_PIXELFORMAT_ARGB2101010: | 180 case SDL_PIXELFORMAT_ARGB2101010: |
146 return 1; | 181 return 1; |
147 default: | 182 default: |
148 return 0; | 183 return 0; |
149 } | 184 } |
185 #endif | |
150 } | 186 } |
151 | 187 |
152 static void | 188 static void |
153 SetBlendMode(DirectFB_RenderData * data, int blendMode, | 189 SetBlendMode(DirectFB_RenderData * data, int blendMode, |
154 DirectFB_TextureData * source) | 190 DirectFB_TextureData * source) |
163 data->blitFlags = DSBLIT_NOFX; | 199 data->blitFlags = DSBLIT_NOFX; |
164 data->drawFlags = DSDRAW_NOFX; | 200 data->drawFlags = DSDRAW_NOFX; |
165 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE)); | 201 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE)); |
166 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO)); | 202 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO)); |
167 break; | 203 break; |
204 #if 0 | |
205 case SDL_BLENDMODE_MASK: | |
206 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL; | |
207 data->drawFlags = DSDRAW_BLEND; | |
208 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); | |
209 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA)); | |
210 break; | |
211 #endif | |
168 case SDL_BLENDMODE_BLEND: | 212 case SDL_BLENDMODE_BLEND: |
169 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL; | 213 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL; |
170 data->drawFlags = DSDRAW_BLEND; | 214 data->drawFlags = DSDRAW_BLEND; |
171 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); | 215 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); |
172 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA)); | 216 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA)); |
181 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); | 225 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA)); |
182 else | 226 else |
183 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE)); | 227 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE)); |
184 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE)); | 228 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE)); |
185 break; | 229 break; |
230 case SDL_BLENDMODE_MOD: | |
231 data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL; | |
232 data->drawFlags = DSDRAW_BLEND; | |
233 //SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR)); | |
234 //SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO)); | |
235 //data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); | |
236 SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ZERO)); | |
237 SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_SRCCOLOR)); | |
238 | |
239 break; | |
186 } | 240 } |
187 data->lastBlendMode = blendMode; | 241 data->lastBlendMode = blendMode; |
188 } | 242 } |
189 } | 243 } |
190 | 244 |
191 void | 245 static int |
192 DirectFB_AddRenderDriver(_THIS) | 246 DisplayPaletteChanged(void *userdata, SDL_Palette * palette) |
193 { | 247 { |
248 #if USE_DISPLAY_PALETTE | |
249 DirectFB_RenderData *data = (DirectFB_RenderData *) userdata; | |
250 SDL_DFB_WINDOWSURFACE(data->window); | |
251 IDirectFBPalette *surfpal; | |
252 | |
194 int i; | 253 int i; |
195 | 254 int ncolors; |
196 for (i = 0; i < _this->num_displays; ++i) { | 255 DFBColor entries[256]; |
197 SDL_AddRenderDriver(&_this->displays[i], &DirectFB_RenderDriver); | 256 |
198 } | 257 SDL_DFB_CHECKERR(destsurf->GetPalette(destsurf, &surfpal)); |
258 | |
259 /* FIXME: number of colors */ | |
260 ncolors = (palette->ncolors < 256 ? palette->ncolors : 256); | |
261 | |
262 for (i = 0; i < ncolors; ++i) { | |
263 entries[i].r = palette->colors[i].r; | |
264 entries[i].g = palette->colors[i].g; | |
265 entries[i].b = palette->colors[i].b; | |
266 entries[i].a = palette->colors[i].unused; | |
267 } | |
268 SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0)); | |
269 return 0; | |
270 error: | |
271 #else | |
272 SDL_Unsupported(); | |
273 #endif | |
274 return -1; | |
275 } | |
276 | |
277 static void | |
278 DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) | |
279 { | |
280 SDL_DFB_RENDERERDATA(renderer); | |
281 | |
282 if (event->event == SDL_WINDOWEVENT_RESIZED) { | |
283 /* Rebind the context to the window area and update matrices */ | |
284 //SDL_CurrentContext = NULL; | |
285 //data->updateSize = SDL_TRUE; | |
286 renddata->size_changed = SDL_TRUE; | |
287 } | |
288 } | |
289 | |
290 int | |
291 DirectFB_RenderClear(SDL_Renderer * renderer) | |
292 { | |
293 SDL_DFB_RENDERERDATA(renderer); | |
294 | |
295 DirectFB_ActivateRenderer(renderer); | |
296 | |
297 return 0; | |
199 } | 298 } |
200 | 299 |
201 SDL_Renderer * | 300 SDL_Renderer * |
202 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) | 301 DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags) |
203 { | 302 { |
204 SDL_DFB_WINDOWDATA(window); | 303 SDL_DFB_WINDOWDATA(window); |
205 SDL_VideoDisplay *display = window->display; | 304 SDL_VideoDisplay *display = window->display; |
206 SDL_Renderer *renderer = NULL; | 305 SDL_Renderer *renderer = NULL; |
207 DirectFB_RenderData *data = NULL; | 306 DirectFB_RenderData *data = NULL; |
208 char *p; | 307 DFBSurfaceCapabilities scaps; |
209 | 308 //char *p; |
210 SDL_DFB_CALLOC(renderer, 1, sizeof(*renderer)); | 309 |
211 SDL_DFB_CALLOC(data, 1, sizeof(*data)); | 310 SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer)); |
212 | 311 SDL_DFB_ALLOC_CLEAR(data, sizeof(*data)); |
213 renderer->DisplayModeChanged = DirectFB_DisplayModeChanged; | 312 |
214 renderer->ActivateRenderer = DirectFB_ActivateRenderer; | 313 renderer->WindowEvent = DirectFB_WindowEvent; |
215 renderer->CreateTexture = DirectFB_CreateTexture; | 314 renderer->CreateTexture = DirectFB_CreateTexture; |
216 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; | 315 renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod; |
316 renderer->SetTextureColorMod = DirectFB_SetTextureColorMod; | |
317 renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode; | |
217 renderer->UpdateTexture = DirectFB_UpdateTexture; | 318 renderer->UpdateTexture = DirectFB_UpdateTexture; |
218 renderer->LockTexture = DirectFB_LockTexture; | 319 renderer->LockTexture = DirectFB_LockTexture; |
320 renderer->RenderClear = DirectFB_RenderClear; | |
219 renderer->UnlockTexture = DirectFB_UnlockTexture; | 321 renderer->UnlockTexture = DirectFB_UnlockTexture; |
220 renderer->DirtyTexture = DirectFB_DirtyTexture; | |
221 renderer->RenderDrawPoints = DirectFB_RenderDrawPoints; | 322 renderer->RenderDrawPoints = DirectFB_RenderDrawPoints; |
222 renderer->RenderDrawLines = DirectFB_RenderDrawLines; | 323 renderer->RenderDrawLines = DirectFB_RenderDrawLines; |
324 /* SetDrawColor - no needed */ | |
223 renderer->RenderFillRects = DirectFB_RenderFillRects; | 325 renderer->RenderFillRects = DirectFB_RenderFillRects; |
224 /* RenderDrawEllipse - no reference implementation yet */ | 326 /* RenderDrawEllipse - no reference implementation yet */ |
225 /* RenderFillEllipse - no reference implementation yet */ | 327 /* RenderFillEllipse - no reference implementation yet */ |
226 renderer->RenderCopy = DirectFB_RenderCopy; | 328 renderer->RenderCopy = DirectFB_RenderCopy; |
227 renderer->RenderPresent = DirectFB_RenderPresent; | 329 renderer->RenderPresent = DirectFB_RenderPresent; |
228 /* RenderReadPixels is difficult to implement */ | 330 |
229 /* RenderWritePixels is difficult to implement */ | 331 /* FIXME: Yet to be tested */ |
332 renderer->RenderReadPixels = DirectFB_RenderReadPixels; | |
333 //renderer->RenderWritePixels = DirectFB_RenderWritePixels; | |
334 | |
230 renderer->DestroyTexture = DirectFB_DestroyTexture; | 335 renderer->DestroyTexture = DirectFB_DestroyTexture; |
231 renderer->DestroyRenderer = DirectFB_DestroyRenderer; | 336 renderer->DestroyRenderer = DirectFB_DestroyRenderer; |
337 | |
338 #if 0 | |
339 renderer->QueryTexturePixels = DirectFB_QueryTexturePixels; | |
340 renderer->SetTexturePalette = DirectFB_SetTexturePalette; | |
341 renderer->GetTexturePalette = DirectFB_GetTexturePalette; | |
342 renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode; | |
343 renderer->DirtyTexture = DirectFB_DirtyTexture; | |
344 renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode; | |
345 renderer->RenderDrawRects = DirectFB_RenderDrawRects; | |
346 #endif | |
347 | |
232 renderer->info = DirectFB_RenderDriver.info; | 348 renderer->info = DirectFB_RenderDriver.info; |
233 renderer->window = window; /* SDL window */ | 349 renderer->window = window; /* SDL window */ |
234 renderer->driverdata = data; | 350 renderer->driverdata = data; |
235 | 351 |
236 renderer->info.flags = SDL_RENDERER_ACCELERATED; | 352 renderer->info.flags = |
353 SDL_RENDERER_ACCELERATED; | |
237 | 354 |
238 data->window = window; | 355 data->window = window; |
239 | 356 |
240 data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT; | 357 data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT; |
241 | 358 |
243 data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC; | 360 data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC; |
244 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; | 361 renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; |
245 } else | 362 } else |
246 data->flipflags |= DSFLIP_ONSYNC; | 363 data->flipflags |= DSFLIP_ONSYNC; |
247 | 364 |
248 data->isyuvdirect = 0; /* default is off! */ | 365 SDL_DFB_CHECKERR(windata->surface-> |
249 p = SDL_getenv(DFBENV_USE_YUV_DIRECT); | 366 GetCapabilities(windata->surface, &scaps)); |
250 if (p) | 367 |
251 data->isyuvdirect = atoi(p); | 368 #if 0 |
369 if (scaps & DSCAPS_DOUBLE) | |
370 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; | |
371 else if (scaps & DSCAPS_TRIPLE) | |
372 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3; | |
373 else | |
374 renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; | |
375 #endif | |
376 | |
377 DirectFB_SetSupportedPixelFormats(&renderer->info); | |
378 | |
379 #if 0 | |
380 /* Set up a palette watch on the display palette */ | |
381 if (display->palette) { | |
382 SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data); | |
383 } | |
384 #endif | |
252 | 385 |
253 return renderer; | 386 return renderer; |
254 | 387 |
255 error: | 388 error: |
256 SDL_DFB_FREE(renderer); | 389 SDL_DFB_FREE(renderer); |
257 SDL_DFB_FREE(data); | 390 SDL_DFB_FREE(data); |
258 return NULL; | 391 return NULL; |
259 } | 392 } |
260 | 393 |
261 static DFBSurfacePixelFormat | 394 static void |
262 SDLToDFBPixelFormat(Uint32 format) | |
263 { | |
264 switch (format) { | |
265 case SDL_PIXELFORMAT_RGB332: | |
266 return DSPF_RGB332; | |
267 case SDL_PIXELFORMAT_RGB555: | |
268 return DSPF_ARGB1555; | |
269 case SDL_PIXELFORMAT_ARGB4444: | |
270 return DSPF_ARGB4444; | |
271 case SDL_PIXELFORMAT_ARGB1555: | |
272 return DSPF_ARGB1555; | |
273 case SDL_PIXELFORMAT_RGB565: | |
274 return DSPF_RGB16; | |
275 case SDL_PIXELFORMAT_RGB24: | |
276 return DSPF_RGB24; | |
277 case SDL_PIXELFORMAT_RGB888: | |
278 return DSPF_RGB32; | |
279 case SDL_PIXELFORMAT_ARGB8888: | |
280 return DSPF_ARGB; | |
281 case SDL_PIXELFORMAT_YV12: | |
282 return DSPF_YV12; /* Planar mode: Y + V + U (3 planes) */ | |
283 case SDL_PIXELFORMAT_IYUV: | |
284 return DSPF_I420; /* Planar mode: Y + U + V (3 planes) */ | |
285 case SDL_PIXELFORMAT_YUY2: | |
286 return DSPF_YUY2; /* Packed mode: Y0+U0+Y1+V0 (1 plane) */ | |
287 case SDL_PIXELFORMAT_UYVY: | |
288 return DSPF_UYVY; /* Packed mode: U0+Y0+V0+Y1 (1 plane) */ | |
289 case SDL_PIXELFORMAT_YVYU: | |
290 return DSPF_UNKNOWN; /* Packed mode: Y0+V0+Y1+U0 (1 plane) */ | |
291 #if (DFB_VERSION_ATLEAST(1,2,0)) | |
292 case SDL_PIXELFORMAT_RGB444: | |
293 return DSPF_RGB444; | |
294 #endif | |
295 case SDL_PIXELFORMAT_BGR24: | |
296 return DSPF_UNKNOWN; | |
297 case SDL_PIXELFORMAT_BGR888: | |
298 return DSPF_UNKNOWN; | |
299 case SDL_PIXELFORMAT_RGBA8888: | |
300 return DSPF_UNKNOWN; | |
301 case SDL_PIXELFORMAT_ABGR8888: | |
302 return DSPF_UNKNOWN; | |
303 case SDL_PIXELFORMAT_BGRA8888: | |
304 return DSPF_UNKNOWN; | |
305 case SDL_PIXELFORMAT_ARGB2101010: | |
306 return DSPF_UNKNOWN; | |
307 default: | |
308 return DSPF_UNKNOWN; | |
309 } | |
310 } | |
311 | |
312 static int | |
313 DirectFB_ActivateRenderer(SDL_Renderer * renderer) | 395 DirectFB_ActivateRenderer(SDL_Renderer * renderer) |
314 { | 396 { |
315 SDL_DFB_RENDERERDATA(renderer); | 397 SDL_DFB_RENDERERDATA(renderer); |
316 SDL_Window *window = renderer->window; | 398 SDL_Window *window = renderer->window; |
317 SDL_DFB_WINDOWDATA(window); | 399 SDL_DFB_WINDOWDATA(window); |
318 | 400 |
319 if (renddata->size_changed || windata->wm_needs_redraw) { | 401 if (renddata->size_changed || windata->wm_needs_redraw) { |
320 // DirectFB_AdjustWindowSurface(window); | 402 DirectFB_AdjustWindowSurface(window); |
321 } | 403 } |
322 return 0; | 404 } |
323 } | 405 |
324 | |
325 static int | |
326 DirectFB_DisplayModeChanged(SDL_Renderer * renderer) | |
327 { | |
328 SDL_DFB_RENDERERDATA(renderer); | |
329 | |
330 renddata->size_changed = SDL_TRUE; | |
331 return 0; | |
332 } | |
333 | 406 |
334 static int | 407 static int |
335 DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture) | 408 DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture) |
336 { | 409 { |
337 SDL_DFB_RENDERERDATA(renderer); | 410 //SDL_DFB_RENDERERDATA(renderer); |
338 SDL_Window *window = renderer->window; | 411 SDL_Window *window = renderer->window; |
339 SDL_VideoDisplay *display = window->display; | 412 SDL_VideoDisplay *display = window->display; |
340 SDL_DFB_DEVICEDATA(display->device); | 413 SDL_DFB_DEVICEDATA(display->device); |
341 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; | 414 DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata; |
342 DirectFB_TextureData *data = texture->driverdata; | 415 DirectFB_TextureData *data = texture->driverdata; |
343 DFBDisplayLayerConfig layconf; | 416 DFBDisplayLayerConfig layconf; |
344 DFBResult ret; | 417 DFBResult ret; |
345 | 418 |
346 if (renddata->isyuvdirect && (dispdata->vidID >= 0) | 419 if (devdata->use_yuv_direct && (dispdata->vidID >= 0) |
347 && (!dispdata->vidIDinuse) | 420 && (!dispdata->vidIDinuse) |
348 && SDL_ISPIXELFORMAT_FOURCC(data->format)) { | 421 && SDL_ISPIXELFORMAT_FOURCC(data->format)) { |
349 layconf.flags = | 422 layconf.flags = |
350 DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | | 423 DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | |
351 DLCONF_SURFACE_CAPS; | 424 DLCONF_SURFACE_CAPS; |
352 layconf.width = texture->w; | 425 layconf.width = texture->w; |
353 layconf.height = texture->h; | 426 layconf.height = texture->h; |
354 layconf.pixelformat = SDLToDFBPixelFormat(data->format); | 427 layconf.pixelformat = DirectFB_SDLToDFBPixelFormat(data->format); |
355 layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE; | 428 layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE; |
356 | 429 |
357 SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb, | 430 SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb, |
358 dispdata->vidID, | 431 dispdata->vidID, |
359 &dispdata->vidlayer)); | 432 &dispdata->vidlayer)); |
360 SDL_DFB_CHECKERR(dispdata-> | 433 SDL_DFB_CHECKERR(dispdata-> |
361 vidlayer->SetCooperativeLevel(dispdata->vidlayer, | 434 vidlayer->SetCooperativeLevel(dispdata->vidlayer, |
362 DLSCL_EXCLUSIVE)); | 435 DLSCL_EXCLUSIVE)); |
363 | 436 |
364 if (devdata->use_yuv_underlays) { | 437 if (devdata->use_yuv_underlays) { |
365 ret = SDL_DFB_CHECK(dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1)); | 438 ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1); |
366 if (ret != DFB_OK) | 439 if (ret != DFB_OK) |
367 SDL_DFB_DEBUG("Underlay Setlevel not supported\n"); | 440 SDL_DFB_DEBUG("Underlay Setlevel not supported\n"); |
368 } | 441 } |
369 SDL_DFB_CHECKERR(dispdata-> | 442 SDL_DFB_CHECKERR(dispdata-> |
370 vidlayer->SetConfiguration(dispdata->vidlayer, | 443 vidlayer->SetConfiguration(dispdata->vidlayer, |
396 SDL_DFB_DEVICEDATA(display->device); | 469 SDL_DFB_DEVICEDATA(display->device); |
397 DirectFB_TextureData *data; | 470 DirectFB_TextureData *data; |
398 DFBSurfaceDescription dsc; | 471 DFBSurfaceDescription dsc; |
399 DFBSurfacePixelFormat pixelformat; | 472 DFBSurfacePixelFormat pixelformat; |
400 | 473 |
401 SDL_DFB_CALLOC(data, 1, sizeof(*data)); | 474 DirectFB_ActivateRenderer(renderer); |
475 | |
476 SDL_DFB_ALLOC_CLEAR(data, sizeof(*data)); | |
402 texture->driverdata = data; | 477 texture->driverdata = data; |
403 | 478 |
404 /* find the right pixelformat */ | 479 /* find the right pixelformat */ |
405 pixelformat = SDLToDFBPixelFormat(texture->format); | 480 pixelformat = DirectFB_SDLToDFBPixelFormat(texture->format); |
406 if (pixelformat == DSPF_UNKNOWN) { | 481 if (pixelformat == DSPF_UNKNOWN) { |
407 SDL_SetError("Unknown pixel format %d\n", data->format); | 482 SDL_SetError("Unknown pixel format %d\n", data->format); |
408 goto error; | 483 goto error; |
409 } | 484 } |
410 | 485 |
415 /* fill surface description */ | 490 /* fill surface description */ |
416 dsc.flags = | 491 dsc.flags = |
417 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; | 492 DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS; |
418 dsc.width = texture->w; | 493 dsc.width = texture->w; |
419 dsc.height = texture->h; | 494 dsc.height = texture->h; |
495 if(texture->format == SDL_PIXELFORMAT_YV12 || | |
496 texture->format == SDL_PIXELFORMAT_IYUV) { | |
497 /* dfb has problems with odd sizes -make them even internally */ | |
498 dsc.width += (dsc.width % 2); | |
499 dsc.height += (dsc.height % 2); | |
500 } | |
420 /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance | 501 /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance |
421 * No DSCAPS_SYSTEMONLY either - let dfb decide | 502 * No DSCAPS_SYSTEMONLY either - let dfb decide |
422 * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8 | 503 * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8 |
423 * Depends on other settings as well. Let dfb decide. | 504 * Depends on other settings as well. Let dfb decide. |
424 */ | 505 */ |
434 data->pixels = NULL; | 515 data->pixels = NULL; |
435 | 516 |
436 /* Create the surface */ | 517 /* Create the surface */ |
437 SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, | 518 SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, |
438 &data->surface)); | 519 &data->surface)); |
520 if (SDL_ISPIXELFORMAT_INDEXED(data->format) | |
521 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { | |
522 #if 1 | |
523 SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette)); | |
524 #else | |
525 /* DFB has issues with blitting LUT8 surfaces. | |
526 * Creating a new palette does not help. | |
527 */ | |
528 DFBPaletteDescription pal_desc; | |
529 pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES | |
530 pal_desc.size = 256; | |
531 SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette)); | |
532 SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette)); | |
533 #endif | |
534 } | |
535 | |
439 } | 536 } |
440 #if (DFB_VERSION_ATLEAST(1,2,0)) | 537 #if (DFB_VERSION_ATLEAST(1,2,0)) |
441 data->render_options = DSRO_NONE; | 538 data->render_options = DSRO_NONE; |
442 #endif | 539 #endif |
443 | |
444 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { | 540 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
445 /* 3 plane YUVs return 1 bpp, but we need more space for other planes */ | 541 /* 3 plane YUVs return 1 bpp, but we need more space for other planes */ |
446 if(texture->format == SDL_PIXELFORMAT_YV12 || | 542 if(texture->format == SDL_PIXELFORMAT_YV12 || |
447 texture->format == SDL_PIXELFORMAT_IYUV) { | 543 texture->format == SDL_PIXELFORMAT_IYUV) { |
448 SDL_DFB_CALLOC(data->pixels, 1, (texture->h * data->pitch * 3 + texture->h * data->pitch * 3 % 2) / 2); | 544 SDL_DFB_ALLOC_CLEAR(data->pixels, (texture->h * data->pitch + ((texture->h + texture->h % 2) * (data->pitch + data->pitch % 2) * 2) / 4)); |
449 } else { | 545 } else { |
450 SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch); | 546 SDL_DFB_ALLOC_CLEAR(data->pixels, texture->h * data->pitch); |
451 } | 547 } |
452 } | 548 } |
453 | 549 |
454 return 0; | 550 return 0; |
455 | 551 |
474 *pitch = texturedata->pitch; | 570 *pitch = texturedata->pitch; |
475 } | 571 } |
476 return 0; | 572 return 0; |
477 } | 573 } |
478 | 574 |
575 static int | |
576 DirectFB_SetTexturePalette(SDL_Renderer * renderer, | |
577 SDL_Texture * texture, | |
578 const SDL_Color * colors, int firstcolor, | |
579 int ncolors) | |
580 { | |
581 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; | |
582 if (SDL_ISPIXELFORMAT_INDEXED(data->format) | |
583 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { | |
584 DFBColor entries[256]; | |
585 int i; | |
586 | |
587 if (ncolors > 256) | |
588 ncolors = 256; | |
589 | |
590 for (i = 0; i < ncolors; ++i) { | |
591 entries[i].r = colors[i].r; | |
592 entries[i].g = colors[i].g; | |
593 entries[i].b = colors[i].b; | |
594 entries[i].a = 0xff; | |
595 } | |
596 SDL_DFB_CHECKERR(data-> | |
597 palette->SetEntries(data->palette, entries, ncolors, firstcolor)); | |
598 return 0; | |
599 } else { | |
600 SDL_SetError("YUV textures don't have a palette"); | |
601 return -1; | |
602 } | |
603 error: | |
604 return -1; | |
605 } | |
606 | |
607 static int | |
608 DirectFB_GetTexturePalette(SDL_Renderer * renderer, | |
609 SDL_Texture * texture, SDL_Color * colors, | |
610 int firstcolor, int ncolors) | |
611 { | |
612 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; | |
613 | |
614 if (SDL_ISPIXELFORMAT_INDEXED(data->format) | |
615 && !SDL_ISPIXELFORMAT_FOURCC(data->format)) { | |
616 DFBColor entries[256]; | |
617 int i; | |
618 | |
619 SDL_DFB_CHECKERR(data-> | |
620 palette->GetEntries(data->palette, entries, ncolors, | |
621 firstcolor)); | |
622 | |
623 for (i = 0; i < ncolors; ++i) { | |
624 colors[i].r = entries[i].r; | |
625 colors[i].g = entries[i].g; | |
626 colors[i].b = entries[i].b; | |
627 colors->unused = SDL_ALPHA_OPAQUE; | |
628 } | |
629 return 0; | |
630 } else { | |
631 SDL_SetError("YUV textures don't have a palette"); | |
632 return -1; | |
633 } | |
634 error: | |
635 return -1; | |
636 } | |
637 | |
638 static int | |
639 DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
640 { | |
641 return 0; | |
642 } | |
643 | |
644 static int | |
645 DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) | |
646 { | |
647 return 0; | |
648 } | |
649 | |
650 static int | |
651 DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) | |
652 { | |
653 switch (texture->blendMode) { | |
654 case SDL_BLENDMODE_NONE: | |
655 //case SDL_BLENDMODE_MASK: | |
656 case SDL_BLENDMODE_BLEND: | |
657 case SDL_BLENDMODE_ADD: | |
658 case SDL_BLENDMODE_MOD: | |
659 return 0; | |
660 default: | |
661 SDL_Unsupported(); | |
662 texture->blendMode = SDL_BLENDMODE_NONE; | |
663 return -1; | |
664 } | |
665 } | |
666 | |
667 static int | |
668 DirectFB_SetDrawBlendMode(SDL_Renderer * renderer) | |
669 { | |
670 switch (renderer->blendMode) { | |
671 case SDL_BLENDMODE_NONE: | |
672 //case SDL_BLENDMODE_MASK: | |
673 case SDL_BLENDMODE_BLEND: | |
674 case SDL_BLENDMODE_ADD: | |
675 case SDL_BLENDMODE_MOD: | |
676 return 0; | |
677 default: | |
678 SDL_Unsupported(); | |
679 renderer->blendMode = SDL_BLENDMODE_NONE; | |
680 return -1; | |
681 } | |
682 } | |
683 | |
684 #if 0 | |
479 static int | 685 static int |
480 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) | 686 DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) |
481 { | 687 { |
482 #if (DFB_VERSION_ATLEAST(1,2,0)) | 688 #if (DFB_VERSION_ATLEAST(1,2,0)) |
483 | 689 |
502 return -1; | 708 return -1; |
503 } | 709 } |
504 #endif | 710 #endif |
505 return 0; | 711 return 0; |
506 } | 712 } |
713 #endif | |
507 | 714 |
508 static int | 715 static int |
509 DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 716 DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
510 const SDL_Rect * rect, const void *pixels, int pitch) | 717 const SDL_Rect * rect, const void *pixels, int pitch) |
511 { | 718 { |
513 Uint8 *dpixels; | 720 Uint8 *dpixels; |
514 int dpitch; | 721 int dpitch; |
515 Uint8 *src, *dst; | 722 Uint8 *src, *dst; |
516 int row; | 723 int row; |
517 size_t length; | 724 size_t length; |
518 int bpp = DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format)); | 725 int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format)); |
519 // FIXME: SDL_BYTESPERPIXEL(texture->format) broken for yuv yv12 3 planes | 726 // FIXME: SDL_BYTESPERPIXEL(texture->format) broken for yuv yv12 3 planes |
520 | 727 |
728 DirectFB_ActivateRenderer(renderer); | |
729 | |
730 if ((texture->format == SDL_PIXELFORMAT_YV12) || | |
731 (texture->format == SDL_PIXELFORMAT_IYUV)) { | |
732 bpp = 1; | |
733 } | |
734 | |
521 SDL_DFB_CHECKERR(data->surface->Lock(data->surface, | 735 SDL_DFB_CHECKERR(data->surface->Lock(data->surface, |
522 DSLF_WRITE | DSLF_READ, | 736 DSLF_WRITE | DSLF_READ, |
523 ((void **) &dpixels), &dpitch)); | 737 ((void **) &dpixels), &dpitch)); |
524 src = (Uint8 *) pixels; | 738 src = (Uint8 *) pixels; |
525 dst = (Uint8 *) dpixels + rect->y * dpitch + rect->x * bpp; | 739 dst = (Uint8 *) dpixels + rect->y * dpitch + rect->x * bpp; |
528 SDL_memcpy(dst, src, length); | 742 SDL_memcpy(dst, src, length); |
529 src += pitch; | 743 src += pitch; |
530 dst += dpitch; | 744 dst += dpitch; |
531 } | 745 } |
532 /* copy other planes for 3 plane formats */ | 746 /* copy other planes for 3 plane formats */ |
533 if (texture->format == SDL_PIXELFORMAT_YV12 || | 747 if ((texture->format == SDL_PIXELFORMAT_YV12) || |
534 texture->format == SDL_PIXELFORMAT_IYUV) { | 748 (texture->format == SDL_PIXELFORMAT_IYUV)) { |
535 src = (Uint8 *) pixels + texture->h * pitch; | 749 src = (Uint8 *) pixels + texture->h * pitch; |
536 dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2; | 750 dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2; |
537 for (row = 0; row < rect->h / 2; ++row) { | 751 for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) { |
538 SDL_memcpy(dst, src, length / 2); | 752 SDL_memcpy(dst, src, length / 2); |
539 src += pitch / 2; | 753 src += pitch / 2; |
540 dst += dpitch / 2; | 754 dst += dpitch / 2; |
541 } | 755 } |
542 src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4; | 756 src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4; |
543 dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2; | 757 dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2; |
544 for (row = 0; row < rect->h / 2; ++row) { | 758 for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) { |
545 SDL_memcpy(dst, src, length / 2); | 759 SDL_memcpy(dst, src, length / 2); |
546 src += pitch / 2; | 760 src += pitch / 2; |
547 dst += dpitch / 2; | 761 dst += dpitch / 2; |
548 } | 762 } |
549 } | 763 } |
550 SDL_DFB_CHECKERR(data->surface->Unlock(data->surface)); | 764 SDL_DFB_CHECKERR(data->surface->Unlock(data->surface)); |
765 data->isDirty = 0; | |
551 return 0; | 766 return 0; |
552 error: | 767 error: |
553 return 1; | 768 return 1; |
554 | 769 |
555 } | 770 } |
556 | 771 |
557 static int | 772 static int |
558 DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 773 DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
559 const SDL_Rect * rect, int markDirty, | 774 const SDL_Rect * rect, void **pixels, int *pitch) |
560 void **pixels, int *pitch) | |
561 { | 775 { |
562 DirectFB_TextureData *texturedata = | 776 DirectFB_TextureData *texturedata = |
563 (DirectFB_TextureData *) texture->driverdata; | 777 (DirectFB_TextureData *) texture->driverdata; |
564 | 778 |
779 DirectFB_ActivateRenderer(renderer); | |
780 | |
781 #if 0 | |
565 if (markDirty) { | 782 if (markDirty) { |
566 SDL_AddDirtyRect(&texturedata->dirty, rect); | 783 SDL_AddDirtyRect(&texturedata->dirty, rect); |
567 } | 784 } |
785 #endif | |
568 | 786 |
569 if (texturedata->display) { | 787 if (texturedata->display) { |
570 void *fdata; | 788 void *fdata; |
571 int fpitch; | 789 int fpitch; |
572 | 790 |
577 *pixels = fdata; | 795 *pixels = fdata; |
578 } else { | 796 } else { |
579 *pixels = | 797 *pixels = |
580 (void *) ((Uint8 *) texturedata->pixels + | 798 (void *) ((Uint8 *) texturedata->pixels + |
581 rect->y * texturedata->pitch + | 799 rect->y * texturedata->pitch + |
582 rect->x * DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format))); | 800 rect->x * DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format))); |
583 *pitch = texturedata->pitch; | 801 *pitch = texturedata->pitch; |
802 texturedata->isDirty = 1; | |
584 } | 803 } |
585 return 0; | 804 return 0; |
586 | 805 |
587 error: | 806 error: |
588 return -1; | 807 return -1; |
591 static void | 810 static void |
592 DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 811 DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
593 { | 812 { |
594 DirectFB_TextureData *texturedata = | 813 DirectFB_TextureData *texturedata = |
595 (DirectFB_TextureData *) texture->driverdata; | 814 (DirectFB_TextureData *) texture->driverdata; |
815 | |
816 DirectFB_ActivateRenderer(renderer); | |
596 | 817 |
597 if (texturedata->display) { | 818 if (texturedata->display) { |
598 SDL_DFB_CHECK(texturedata->surface->Unlock(texturedata->surface)); | 819 SDL_DFB_CHECK(texturedata->surface->Unlock(texturedata->surface)); |
599 texturedata->pixels = NULL; | 820 texturedata->pixels = NULL; |
600 } | 821 } |
601 } | 822 } |
602 | 823 |
824 #if 0 | |
603 static void | 825 static void |
604 DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 826 DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
605 int numrects, const SDL_Rect * rects) | 827 int numrects, const SDL_Rect * rects) |
606 { | 828 { |
607 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; | 829 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; |
609 | 831 |
610 for (i = 0; i < numrects; ++i) { | 832 for (i = 0; i < numrects; ++i) { |
611 SDL_AddDirtyRect(&data->dirty, &rects[i]); | 833 SDL_AddDirtyRect(&data->dirty, &rects[i]); |
612 } | 834 } |
613 } | 835 } |
836 #endif | |
614 | 837 |
615 static int | 838 static int |
616 PrepareDraw(SDL_Renderer * renderer) | 839 PrepareDraw(SDL_Renderer * renderer) |
617 { | 840 { |
618 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 841 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
628 SetBlendMode(data, renderer->blendMode, NULL); | 851 SetBlendMode(data, renderer->blendMode, NULL); |
629 SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags)); | 852 SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags)); |
630 | 853 |
631 switch (renderer->blendMode) { | 854 switch (renderer->blendMode) { |
632 case SDL_BLENDMODE_NONE: | 855 case SDL_BLENDMODE_NONE: |
856 //case SDL_BLENDMODE_MASK: | |
633 case SDL_BLENDMODE_BLEND: | 857 case SDL_BLENDMODE_BLEND: |
634 break; | 858 break; |
635 case SDL_BLENDMODE_ADD: | 859 case SDL_BLENDMODE_ADD: |
860 case SDL_BLENDMODE_MOD: | |
636 r = ((int) r * (int) a) / 255; | 861 r = ((int) r * (int) a) / 255; |
637 g = ((int) g * (int) a) / 255; | 862 g = ((int) g * (int) a) / 255; |
638 b = ((int) b * (int) a) / 255; | 863 b = ((int) b * (int) a) / 255; |
639 a = 255; | 864 a = 255; |
640 break; | 865 break; |
651 { | 876 { |
652 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 877 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
653 SDL_DFB_WINDOWSURFACE(data->window); | 878 SDL_DFB_WINDOWSURFACE(data->window); |
654 int i; | 879 int i; |
655 | 880 |
881 DirectFB_ActivateRenderer(renderer); | |
882 | |
656 PrepareDraw(renderer); | 883 PrepareDraw(renderer); |
657 for (i=0; i < count; i++) | 884 for (i=0; i < count; i++) |
658 SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y)); | 885 SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y)); |
659 return 0; | 886 return 0; |
660 error: | 887 error: |
665 const SDL_Point * points, int count) | 892 const SDL_Point * points, int count) |
666 { | 893 { |
667 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 894 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
668 SDL_DFB_WINDOWSURFACE(data->window); | 895 SDL_DFB_WINDOWSURFACE(data->window); |
669 int i; | 896 int i; |
897 | |
898 DirectFB_ActivateRenderer(renderer); | |
670 | 899 |
671 PrepareDraw(renderer); | 900 PrepareDraw(renderer); |
672 /* Use antialiasing when available */ | 901 /* Use antialiasing when available */ |
673 #if (DFB_VERSION_ATLEAST(1,2,0)) | 902 #if (DFB_VERSION_ATLEAST(1,2,0)) |
674 SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS)); | 903 SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS)); |
681 error: | 910 error: |
682 return -1; | 911 return -1; |
683 } | 912 } |
684 | 913 |
685 static int | 914 static int |
686 DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) | 915 DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) |
687 { | 916 { |
688 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 917 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
689 SDL_DFB_WINDOWSURFACE(data->window); | 918 SDL_DFB_WINDOWSURFACE(data->window); |
690 int i; | 919 int i; |
920 | |
921 DirectFB_ActivateRenderer(renderer); | |
922 | |
923 PrepareDraw(renderer); | |
924 | |
925 for (i=0; i<count; i++) | |
926 SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y, | |
927 rects[i]->w, rects[i]->h)); | |
928 | |
929 return 0; | |
930 error: | |
931 return -1; | |
932 } | |
933 | |
934 static int | |
935 DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) | |
936 { | |
937 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | |
938 SDL_DFB_WINDOWSURFACE(data->window); | |
939 int i; | |
940 | |
941 DirectFB_ActivateRenderer(renderer); | |
691 | 942 |
692 PrepareDraw(renderer); | 943 PrepareDraw(renderer); |
693 | 944 |
694 for (i=0; i<count; i++) | 945 for (i=0; i<count; i++) |
695 SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i]->x, rects[i]->y, | 946 SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i]->x, rects[i]->y, |
706 { | 957 { |
707 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 958 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
708 SDL_DFB_WINDOWSURFACE(data->window); | 959 SDL_DFB_WINDOWSURFACE(data->window); |
709 DirectFB_TextureData *texturedata = | 960 DirectFB_TextureData *texturedata = |
710 (DirectFB_TextureData *) texture->driverdata; | 961 (DirectFB_TextureData *) texture->driverdata; |
711 Uint8 alpha = 0xFF; | 962 Uint8 alpha, r, g, b; |
963 | |
964 DirectFB_ActivateRenderer(renderer); | |
712 | 965 |
713 if (texturedata->display) { | 966 if (texturedata->display) { |
714 int px, py; | 967 int px, py; |
715 SDL_Window *window = renderer->window; | 968 SDL_Window *window = renderer->window; |
716 SDL_DFB_WINDOWDATA(window); | 969 SDL_DFB_WINDOWDATA(window); |
720 SDL_DFB_CHECKERR(dispdata-> | 973 SDL_DFB_CHECKERR(dispdata-> |
721 vidlayer->SetSourceRectangle(dispdata->vidlayer, | 974 vidlayer->SetSourceRectangle(dispdata->vidlayer, |
722 srcrect->x, srcrect->y, | 975 srcrect->x, srcrect->y, |
723 srcrect->w, | 976 srcrect->w, |
724 srcrect->h)); | 977 srcrect->h)); |
725 SDL_DFB_CHECK(windata->window->GetPosition(windata->window, &px, &py)); | 978 SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin, &px, &py)); |
726 px += windata->client.x; | 979 px += windata->client.x; |
727 py += windata->client.y; | 980 py += windata->client.y; |
728 SDL_DFB_CHECKERR(dispdata-> | 981 SDL_DFB_CHECKERR(dispdata-> |
729 vidlayer->SetScreenRectangle(dispdata->vidlayer, | 982 vidlayer->SetScreenRectangle(dispdata->vidlayer, |
730 px + dstrect->x, | 983 px + dstrect->x, |
733 dstrect->h)); | 986 dstrect->h)); |
734 } else { | 987 } else { |
735 DFBRectangle sr, dr; | 988 DFBRectangle sr, dr; |
736 DFBSurfaceBlittingFlags flags = 0; | 989 DFBSurfaceBlittingFlags flags = 0; |
737 | 990 |
991 #if 0 | |
738 if (texturedata->dirty.list) { | 992 if (texturedata->dirty.list) { |
739 SDL_DirtyRect *dirty; | 993 SDL_DirtyRect *dirty; |
740 void *pixels; | 994 void *pixels; |
741 int bpp = DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format)); | 995 int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format)); |
742 int pitch = texturedata->pitch; | 996 int pitch = texturedata->pitch; |
743 | 997 |
744 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { | 998 for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { |
745 SDL_Rect *rect = &dirty->rect; | 999 SDL_Rect *rect = &dirty->rect; |
746 pixels = | 1000 pixels = |
747 (void *) ((Uint8 *) texturedata->pixels + | 1001 (void *) ((Uint8 *) texturedata->pixels + |
748 rect->y * pitch + rect->x * bpp); | 1002 rect->y * pitch + rect->x * bpp); |
749 DirectFB_UpdateTexture(renderer, texture, rect, | 1003 DirectFB_UpdateTexture(renderer, texture, rect, |
750 texturedata->pixels, | 1004 pixels, |
751 texturedata->pitch); | 1005 texturedata->pitch); |
752 } | 1006 } |
753 SDL_ClearDirtyRects(&texturedata->dirty); | 1007 SDL_ClearDirtyRects(&texturedata->dirty); |
754 } | 1008 } |
1009 #endif | |
1010 if (texturedata->isDirty) | |
1011 { | |
1012 SDL_Rect rect; | |
1013 | |
1014 rect.x = 0; | |
1015 rect.y = 0; | |
1016 rect.w = texture->w; | |
1017 rect.h = texture->h; | |
1018 | |
1019 DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch); | |
1020 } | |
755 | 1021 |
756 SDLtoDFBRect(srcrect, &sr); | 1022 SDLtoDFBRect(srcrect, &sr); |
757 SDLtoDFBRect(dstrect, &dr); | 1023 SDLtoDFBRect(dstrect, &dr); |
758 | 1024 |
1025 alpha = r = g = b = 0xff; | |
1026 if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){ | |
1027 alpha = texture->a; | |
1028 flags |= DSBLIT_BLEND_COLORALPHA; | |
1029 } | |
1030 | |
1031 if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { | |
1032 r = texture->r; | |
1033 g = texture->g; | |
1034 b = texture->b; | |
1035 flags |= DSBLIT_COLORIZE; | |
1036 } | |
759 SDL_DFB_CHECKERR(destsurf-> | 1037 SDL_DFB_CHECKERR(destsurf-> |
760 SetColor(destsurf, 0xFF, 0xFF, 0xFF, 0xFF)); | 1038 SetColor(destsurf, r, g, b, alpha)); |
761 if (texture-> | 1039 |
762 modMode & (SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA)) | 1040 // ???? flags |= DSBLIT_SRC_PREMULTCOLOR; |
763 { | |
764 if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) { | |
765 alpha = texture->a; | |
766 SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, 0xFF, 0xFF, | |
767 0xFF, alpha)); | |
768 } | |
769 if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) { | |
770 | |
771 SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, | |
772 texture->r, | |
773 texture->g, | |
774 texture->b, alpha)); | |
775 flags |= DSBLIT_COLORIZE; | |
776 } | |
777 if (alpha < 0xFF) | |
778 flags |= DSBLIT_SRC_PREMULTCOLOR; | |
779 } else | |
780 SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, 0xFF, 0xFF, | |
781 0xFF, 0xFF)); | |
782 | 1041 |
783 SetBlendMode(data, texture->blendMode, texturedata); | 1042 SetBlendMode(data, texture->blendMode, texturedata); |
784 | 1043 |
785 SDL_DFB_CHECKERR(destsurf->SetBlittingFlags(destsurf, | 1044 SDL_DFB_CHECKERR(destsurf->SetBlittingFlags(destsurf, |
786 data->blitFlags | flags)); | 1045 data->blitFlags | flags)); |
810 DirectFB_RenderPresent(SDL_Renderer * renderer) | 1069 DirectFB_RenderPresent(SDL_Renderer * renderer) |
811 { | 1070 { |
812 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 1071 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
813 SDL_Window *window = renderer->window; | 1072 SDL_Window *window = renderer->window; |
814 SDL_DFB_WINDOWDATA(window); | 1073 SDL_DFB_WINDOWDATA(window); |
815 | 1074 SDL_ShapeData *shape_data = (window->shaper ? window->shaper->driverdata : NULL); |
816 DFBRectangle sr; | 1075 |
817 | 1076 DirectFB_ActivateRenderer(renderer); |
818 sr.x = 0; | 1077 |
819 sr.y = 0; | 1078 if (shape_data && shape_data->surface) { |
820 sr.w = window->w; | 1079 /* saturate the window surface alpha channel */ |
821 sr.h = window->h; | 1080 SDL_DFB_CHECK(windata->window_surface->SetSrcBlendFunction(windata->window_surface, DSBF_ONE)); |
1081 SDL_DFB_CHECK(windata->window_surface->SetDstBlendFunction(windata->window_surface, DSBF_ONE)); | |
1082 SDL_DFB_CHECK(windata->window_surface->SetDrawingFlags(windata->window_surface, DSDRAW_BLEND)); | |
1083 SDL_DFB_CHECK(windata->window_surface->SetColor(windata->window_surface, 0, 0, 0, 0xff)); | |
1084 SDL_DFB_CHECK(windata->window_surface->FillRectangle(windata->window_surface, 0,0, windata->size.w, windata->size.h)); | |
1085 | |
1086 /* blit the mask */ | |
1087 SDL_DFB_CHECK(windata->surface->SetSrcBlendFunction(windata->surface, DSBF_DESTCOLOR)); | |
1088 SDL_DFB_CHECK(windata->surface->SetDstBlendFunction(windata->surface, DSBF_ZERO)); | |
1089 SDL_DFB_CHECK(windata->surface->SetBlittingFlags(windata->surface, DSBLIT_BLEND_ALPHACHANNEL)); | |
1090 #if (DFB_VERSION_ATLEAST(1,2,0)) | |
1091 SDL_DFB_CHECK(windata->surface->SetRenderOptions(windata->surface, DSRO_NONE)); | |
1092 #endif | |
1093 SDL_DFB_CHECK(windata->surface->Blit(windata->surface, shape_data->surface, NULL, 0, 0)); | |
1094 } | |
822 | 1095 |
823 /* Send the data to the display */ | 1096 /* Send the data to the display */ |
824 SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL, | 1097 SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL, |
825 data->flipflags)); | 1098 data->flipflags)); |
826 } | 1099 } |
828 static void | 1101 static void |
829 DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) | 1102 DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) |
830 { | 1103 { |
831 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; | 1104 DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata; |
832 | 1105 |
1106 DirectFB_ActivateRenderer(renderer); | |
1107 | |
833 if (!data) { | 1108 if (!data) { |
834 return; | 1109 return; |
835 } | 1110 } |
1111 //SDL_FreeDirtyRects(&data->dirty); | |
836 SDL_DFB_RELEASE(data->palette); | 1112 SDL_DFB_RELEASE(data->palette); |
837 SDL_DFB_RELEASE(data->surface); | 1113 SDL_DFB_RELEASE(data->surface); |
838 if (data->display) { | 1114 if (data->display) { |
839 DFB_DisplayData *dispdata = | 1115 DFB_DisplayData *dispdata = |
840 (DFB_DisplayData *) data->display->driverdata; | 1116 (DFB_DisplayData *) data->display->driverdata; |
842 /* FIXME: Shouldn't we reset the cooperative level */ | 1118 /* FIXME: Shouldn't we reset the cooperative level */ |
843 SDL_DFB_CHECK(dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer, | 1119 SDL_DFB_CHECK(dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer, |
844 DLSCL_ADMINISTRATIVE)); | 1120 DLSCL_ADMINISTRATIVE)); |
845 SDL_DFB_RELEASE(dispdata->vidlayer); | 1121 SDL_DFB_RELEASE(dispdata->vidlayer); |
846 } | 1122 } |
847 SDL_FreeDirtyRects(&data->dirty); | |
848 SDL_DFB_FREE(data->pixels); | 1123 SDL_DFB_FREE(data->pixels); |
849 SDL_free(data); | 1124 SDL_free(data); |
850 texture->driverdata = NULL; | 1125 texture->driverdata = NULL; |
851 } | 1126 } |
852 | 1127 |
853 static void | 1128 static void |
854 DirectFB_DestroyRenderer(SDL_Renderer * renderer) | 1129 DirectFB_DestroyRenderer(SDL_Renderer * renderer) |
855 { | 1130 { |
856 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; | 1131 DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata; |
1132 SDL_VideoDisplay *display = renderer->window->display; | |
1133 | |
1134 #if 0 | |
1135 if (display->palette) { | |
1136 SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data); | |
1137 } | |
1138 #endif | |
857 | 1139 |
858 if (data) { | 1140 if (data) { |
859 SDL_free(data); | 1141 SDL_free(data); |
860 } | 1142 } |
861 SDL_free(renderer); | 1143 SDL_free(renderer); |
862 } | 1144 } |
863 | 1145 |
1146 static int | |
1147 DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, | |
1148 Uint32 format, void * pixels, int pitch) | |
1149 { | |
1150 SDL_Window *window = renderer->window; | |
1151 SDL_DFB_WINDOWDATA(window); | |
1152 Uint32 sdl_format; | |
1153 void * laypixels; | |
1154 int laypitch; | |
1155 DFBSurfacePixelFormat dfb_format; | |
1156 | |
1157 DirectFB_ActivateRenderer(renderer); | |
1158 | |
1159 SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format)); | |
1160 sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); | |
1161 SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_READ, (void **) &laypixels, &laypitch)); | |
1162 | |
1163 laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); | |
1164 SDL_ConvertPixels(rect->w, rect->h, | |
1165 sdl_format, laypixels, laypitch, | |
1166 format, pixels, pitch); | |
1167 | |
1168 SDL_DFB_CHECK(windata->surface->Unlock(windata->surface)); | |
1169 | |
1170 return 0; | |
1171 } | |
1172 | |
1173 static int | |
1174 DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, | |
1175 Uint32 format, const void * pixels, int pitch) | |
1176 { | |
1177 SDL_Window *window = renderer->window; | |
1178 SDL_DFB_WINDOWDATA(window); | |
1179 Uint32 sdl_format; | |
1180 void * laypixels; | |
1181 int laypitch; | |
1182 DFBSurfacePixelFormat dfb_format; | |
1183 | |
1184 SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format)); | |
1185 sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format); | |
1186 | |
1187 SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_WRITE, (void **) &laypixels, &laypitch)); | |
1188 | |
1189 laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) ); | |
1190 SDL_ConvertPixels(rect->w, rect->h, | |
1191 format, pixels, pitch, | |
1192 sdl_format, laypixels, laypitch); | |
1193 | |
1194 SDL_DFB_CHECK(windata->surface->Unlock(windata->surface)); | |
1195 | |
1196 return 0; | |
1197 } | |
1198 | |
1199 | |
864 /* vi: set ts=4 sw=4 expandtab: */ | 1200 /* vi: set ts=4 sw=4 expandtab: */ |