This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_DirectFB_render.c
1200 lines (1030 loc) · 39.5 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2011 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
22
23
24
SDL1.3 DirectFB driver by couriersud@arcor.de
*/
25
#include "SDL_DirectFB_video.h"
26
27
28
29
30
31
32
33
34
#include "SDL_DirectFB_window.h"
#include "SDL_DirectFB_modes.h"
#include "SDL_DirectFB_shape.h"
#include "../SDL_sysvideo.h"
#include "../../render/SDL_sysrender.h"
//#include "../SDL_rect_c.h"
//#include "../SDL_yuv_sw_c.h"
35
36
37
38
/* the following is not yet tested ... */
#define USE_DISPLAY_PALETTE (0)
39
40
41
42
#define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL)
43
44
45
46
/* GDI renderer implementation */
static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
Uint32 flags);
47
static void DirectFB_ActivateRenderer(SDL_Renderer * renderer);
48
49
50
static int DirectFB_CreateTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
51
52
SDL_Texture * texture,
void **pixels, int *pitch);
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors,
int firstcolor, int ncolors);
static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
SDL_Color * colors,
int firstcolor, int ncolors);
static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
SDL_Texture * texture);
static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);
static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer,
SDL_Texture * texture);
69
70
static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
SDL_Texture * texture,
71
72
const SDL_Rect * rect,
const void *pixels, int pitch);
73
static int DirectFB_LockTexture(SDL_Renderer * renderer,
74
SDL_Texture * texture,
75
const SDL_Rect * rect,
76
void **pixels, int *pitch);
77
78
79
80
81
static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
SDL_Texture * texture, int numrects,
const SDL_Rect * rects);
82
static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
83
84
85
86
static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count);
87
88
static int DirectFB_RenderDrawRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
89
90
static int DirectFB_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
91
92
static int DirectFB_RenderCopy(SDL_Renderer * renderer,
SDL_Texture * texture,
93
94
95
96
97
98
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);
static void DirectFB_RenderPresent(SDL_Renderer * renderer);
static void DirectFB_DestroyTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void DirectFB_DestroyRenderer(SDL_Renderer * renderer);
99
100
101
102
103
static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch);
104
105
106
#define SDL_DFB_WINDOWSURFACE(win) IDirectFBSurface *destsurf = ((DFB_WindowData *) ((win)->driverdata))->surface;
107
108
109
110
SDL_RenderDriver DirectFB_RenderDriver = {
DirectFB_CreateRenderer,
{
"directfb",
111
(SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
112
113
114
115
116
117
118
/* (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
SDL_TEXTUREMODULATE_ALPHA),
(SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
(SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST |
SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST),*/
0,
119
{
120
121
/* formats filled in later */
},
122
123
124
125
126
127
0,
0}
};
typedef struct
{
128
SDL_Window *window;
129
DFBSurfaceFlipFlags flipflags;
130
int size_changed;
131
132
133
int lastBlendMode;
DFBSurfaceBlittingFlags blitFlags;
DFBSurfaceDrawingFlags drawFlags;
134
135
136
137
138
139
140
141
} DirectFB_RenderData;
typedef struct
{
IDirectFBSurface *surface;
Uint32 format;
void *pixels;
int pitch;
142
143
144
145
146
IDirectFBPalette *palette;
int isDirty;
SDL_VideoDisplay *display; /* only for yuv textures */
147
#if (DFB_VERSION_ATLEAST(1,2,0))
148
149
DFBSurfaceRenderOptions render_options;
#endif
150
151
} DirectFB_TextureData;
152
153
154
155
156
157
158
159
160
static __inline__ void
SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
{
dr->x = sr->x;
dr->y = sr->y;
dr->h = sr->h;
dr->w = sr->w;
}
161
162
163
164
165
166
167
static int
TextureHasAlpha(DirectFB_TextureData * data)
{
/* Drawing primitive ? */
if (!data)
return 0;
168
169
170
return (DFB_PIXELFORMAT_HAS_ALPHA(DirectFB_SDLToDFBPixelFormat(data->format)) ? 1 : 0);
#if 0
171
switch (data->format) {
172
173
case SDL_PIXELFORMAT_INDEX4LSB:
case SDL_PIXELFORMAT_INDEX4MSB:
174
175
176
177
178
179
180
case SDL_PIXELFORMAT_ARGB4444:
case SDL_PIXELFORMAT_ARGB1555:
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_RGBA8888:
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGRA8888:
case SDL_PIXELFORMAT_ARGB2101010:
181
return 1;
182
183
184
default:
return 0;
}
185
#endif
186
187
188
189
190
191
}
static void
SetBlendMode(DirectFB_RenderData * data, int blendMode,
DirectFB_TextureData * source)
{
192
193
194
SDL_DFB_WINDOWSURFACE(data->window);
//FIXME: check for format change
195
196
197
198
199
200
if (1 || data->lastBlendMode != blendMode) {
switch (blendMode) {
case SDL_BLENDMODE_NONE:
/**< No blending */
data->blitFlags = DSBLIT_NOFX;
data->drawFlags = DSDRAW_NOFX;
201
202
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
203
break;
204
205
206
207
208
209
210
211
#if 0
case SDL_BLENDMODE_MASK:
data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
data->drawFlags = DSDRAW_BLEND;
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
break;
#endif
212
213
214
case SDL_BLENDMODE_BLEND:
data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
data->drawFlags = DSDRAW_BLEND;
215
216
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
217
218
219
220
break;
case SDL_BLENDMODE_ADD:
data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
data->drawFlags = DSDRAW_BLEND;
221
222
223
224
// FIXME: SRCALPHA kills performance on radeon ...
// It will be cheaper to copy the surface to
// a temporay surface and premultiply
if (source && TextureHasAlpha(source))
225
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
226
else
227
228
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE));
229
230
231
232
233
234
235
236
237
238
break;
case SDL_BLENDMODE_MOD:
data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
data->drawFlags = DSDRAW_BLEND;
//SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_DESTCOLOR));
//SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
//data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ZERO));
SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_SRCCOLOR));
239
240
241
242
243
244
break;
}
data->lastBlendMode = blendMode;
}
}
245
246
static int
DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
247
{
248
249
250
251
252
#if USE_DISPLAY_PALETTE
DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
SDL_DFB_WINDOWSURFACE(data->window);
IDirectFBPalette *surfpal;
253
int i;
254
255
256
257
int ncolors;
DFBColor entries[256];
SDL_DFB_CHECKERR(destsurf->GetPalette(destsurf, &surfpal));
258
259
260
261
262
263
264
265
266
/* FIXME: number of colors */
ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
for (i = 0; i < ncolors; ++i) {
entries[i].r = palette->colors[i].r;
entries[i].g = palette->colors[i].g;
entries[i].b = palette->colors[i].b;
entries[i].a = palette->colors[i].unused;
267
}
268
269
270
271
272
273
274
275
276
277
278
279
280
281
SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
return 0;
error:
#else
SDL_Unsupported();
#endif
return -1;
}
static void
DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
SDL_DFB_RENDERERDATA(renderer);
282
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* Rebind the context to the window area and update matrices */
//SDL_CurrentContext = NULL;
//data->updateSize = SDL_TRUE;
renddata->size_changed = SDL_TRUE;
}
}
int
DirectFB_RenderClear(SDL_Renderer * renderer)
{
SDL_DFB_RENDERERDATA(renderer);
DirectFB_ActivateRenderer(renderer);
return 0;
298
299
300
301
302
303
}
SDL_Renderer *
DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_DFB_WINDOWDATA(window);
304
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
305
306
SDL_Renderer *renderer = NULL;
DirectFB_RenderData *data = NULL;
307
308
DFBSurfaceCapabilities scaps;
//char *p;
309
310
311
SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer));
SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
312
313
renderer->WindowEvent = DirectFB_WindowEvent;
314
renderer->CreateTexture = DirectFB_CreateTexture;
315
316
317
renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
318
319
renderer->UpdateTexture = DirectFB_UpdateTexture;
renderer->LockTexture = DirectFB_LockTexture;
320
renderer->RenderClear = DirectFB_RenderClear;
321
renderer->UnlockTexture = DirectFB_UnlockTexture;
322
323
renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
renderer->RenderDrawLines = DirectFB_RenderDrawLines;
324
/* SetDrawColor - no needed */
325
renderer->RenderFillRects = DirectFB_RenderFillRects;
326
327
/* RenderDrawEllipse - no reference implementation yet */
/* RenderFillEllipse - no reference implementation yet */
328
329
renderer->RenderCopy = DirectFB_RenderCopy;
renderer->RenderPresent = DirectFB_RenderPresent;
330
331
332
333
334
/* FIXME: Yet to be tested */
renderer->RenderReadPixels = DirectFB_RenderReadPixels;
//renderer->RenderWritePixels = DirectFB_RenderWritePixels;
335
336
renderer->DestroyTexture = DirectFB_DestroyTexture;
renderer->DestroyRenderer = DirectFB_DestroyRenderer;
337
338
339
340
341
342
343
344
345
346
347
#if 0
renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
renderer->SetTexturePalette = DirectFB_SetTexturePalette;
renderer->GetTexturePalette = DirectFB_GetTexturePalette;
renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode;
renderer->DirtyTexture = DirectFB_DirtyTexture;
renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
renderer->RenderDrawRects = DirectFB_RenderDrawRects;
#endif
348
renderer->info = DirectFB_RenderDriver.info;
349
renderer->window = window; /* SDL window */
350
351
renderer->driverdata = data;
352
353
renderer->info.flags =
SDL_RENDERER_ACCELERATED;
354
355
data->window = window;
356
357
data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
358
359
if (flags & SDL_RENDERER_PRESENTVSYNC) {
360
data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC;
361
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
362
363
} else
data->flipflags |= DSFLIP_ONSYNC;
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
SDL_DFB_CHECKERR(windata->surface->
GetCapabilities(windata->surface, &scaps));
#if 0
if (scaps & DSCAPS_DOUBLE)
renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
else if (scaps & DSCAPS_TRIPLE)
renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
else
renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
#endif
DirectFB_SetSupportedPixelFormats(&renderer->info);
#if 0
/* Set up a palette watch on the display palette */
if (display->palette) {
SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
}
#endif
385
386
387
388
389
390
391
392
393
return renderer;
error:
SDL_DFB_FREE(renderer);
SDL_DFB_FREE(data);
return NULL;
}
394
static void
395
DirectFB_ActivateRenderer(SDL_Renderer * renderer)
396
397
{
SDL_DFB_RENDERERDATA(renderer);
398
SDL_Window *window = renderer->window;
399
400
SDL_DFB_WINDOWDATA(window);
401
if (renddata->size_changed || windata->wm_needs_redraw) {
402
DirectFB_AdjustWindowSurface(window);
403
}
404
405
}
406
407
static int
408
DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
409
{
410
//SDL_DFB_RENDERERDATA(renderer);
411
SDL_Window *window = renderer->window;
412
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
413
414
SDL_DFB_DEVICEDATA(display->device);
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
415
DirectFB_TextureData *data = texture->driverdata;
416
DFBDisplayLayerConfig layconf;
417
DFBResult ret;
418
419
if (devdata->use_yuv_direct && (dispdata->vidID >= 0)
420
&& (!dispdata->vidIDinuse)
421
&& SDL_ISPIXELFORMAT_FOURCC(data->format)) {
422
423
424
layconf.flags =
DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
DLCONF_SURFACE_CAPS;
425
426
layconf.width = texture->w;
layconf.height = texture->h;
427
layconf.pixelformat = DirectFB_SDLToDFBPixelFormat(data->format);
428
layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
429
430
431
432
433
434
435
SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
dispdata->vidID,
&dispdata->vidlayer));
SDL_DFB_CHECKERR(dispdata->
vidlayer->SetCooperativeLevel(dispdata->vidlayer,
DLSCL_EXCLUSIVE));
436
437
if (devdata->use_yuv_underlays) {
438
ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
439
440
441
if (ret != DFB_OK)
SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
}
442
443
444
445
446
447
SDL_DFB_CHECKERR(dispdata->
vidlayer->SetConfiguration(dispdata->vidlayer,
&layconf));
SDL_DFB_CHECKERR(dispdata->
vidlayer->GetSurface(dispdata->vidlayer,
&data->surface));
448
449
dispdata->vidIDinuse = 1;
data->display = display;
450
return 0;
451
}
452
453
return 1;
error:
454
if (dispdata->vidlayer) {
455
SDL_DFB_RELEASE(data->surface);
456
457
458
SDL_DFB_CHECKERR(dispdata->
vidlayer->SetCooperativeLevel(dispdata->vidlayer,
DLSCL_ADMINISTRATIVE));
459
SDL_DFB_RELEASE(dispdata->vidlayer);
460
461
462
463
464
465
466
}
return 1;
}
static int
DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
467
SDL_Window *window = renderer->window;
468
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
469
470
471
SDL_DFB_DEVICEDATA(display->device);
DirectFB_TextureData *data;
DFBSurfaceDescription dsc;
472
DFBSurfacePixelFormat pixelformat;
473
474
475
476
DirectFB_ActivateRenderer(renderer);
SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
477
478
texture->driverdata = data;
479
/* find the right pixelformat */
480
pixelformat = DirectFB_SDLToDFBPixelFormat(texture->format);
481
482
483
484
485
if (pixelformat == DSPF_UNKNOWN) {
SDL_SetError("Unknown pixel format %d\n", data->format);
goto error;
}
486
data->format = texture->format;
487
data->pitch = texture->w * DFB_BYTES_PER_PIXEL(pixelformat);
488
489
if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
490
491
492
493
494
/* fill surface description */
dsc.flags =
DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
dsc.width = texture->w;
dsc.height = texture->h;
495
496
497
498
499
500
if(texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
/* dfb has problems with odd sizes -make them even internally */
dsc.width += (dsc.width % 2);
dsc.height += (dsc.height % 2);
}
501
/* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
502
* No DSCAPS_SYSTEMONLY either - let dfb decide
503
* 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
504
* Depends on other settings as well. Let dfb decide.
505
*/
506
dsc.caps = DSCAPS_PREMULTIPLIED;
507
#if 0
508
509
510
511
if (texture->access == SDL_TEXTUREACCESS_STREAMING)
dsc.caps |= DSCAPS_SYSTEMONLY;
else
dsc.caps |= DSCAPS_VIDEOONLY;
512
#endif
513
514
dsc.pixelformat = pixelformat;
515
516
517
data->pixels = NULL;
/* Create the surface */
518
519
SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
&data->surface));
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
if (SDL_ISPIXELFORMAT_INDEXED(data->format)
&& !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
#if 1
SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette));
#else
/* DFB has issues with blitting LUT8 surfaces.
* Creating a new palette does not help.
*/
DFBPaletteDescription pal_desc;
pal_desc.flags = DPDESC_SIZE; // | DPDESC_ENTRIES
pal_desc.size = 256;
SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette));
SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette));
#endif
}
536
}
537
#if (DFB_VERSION_ATLEAST(1,2,0))
538
539
540
data->render_options = DSRO_NONE;
#endif
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
541
542
543
/* 3 plane YUVs return 1 bpp, but we need more space for other planes */
if(texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
544
SDL_DFB_ALLOC_CLEAR(data->pixels, (texture->h * data->pitch + ((texture->h + texture->h % 2) * (data->pitch + data->pitch % 2) * 2) / 4));
545
} else {
546
SDL_DFB_ALLOC_CLEAR(data->pixels, texture->h * data->pitch);
547
}
548
549
}
550
551
552
553
554
555
556
557
558
559
return 0;
error:
SDL_DFB_RELEASE(data->palette);
SDL_DFB_RELEASE(data->surface);
SDL_DFB_FREE(texture->driverdata);
return -1;
}
static int
560
561
DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels, int *pitch)
562
{
563
564
DirectFB_TextureData *texturedata =
(DirectFB_TextureData *) texture->driverdata;
565
566
567
568
569
570
571
572
if (texturedata->display) {
return -1;
} else {
*pixels = texturedata->pixels;
*pitch = texturedata->pitch;
}
return 0;
573
574
}
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
static int
DirectFB_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors)
{
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
if (SDL_ISPIXELFORMAT_INDEXED(data->format)
&& !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
DFBColor entries[256];
int i;
if (ncolors > 256)
ncolors = 256;
for (i = 0; i < ncolors; ++i) {
entries[i].r = colors[i].r;
entries[i].g = colors[i].g;
entries[i].b = colors[i].b;
entries[i].a = 0xff;
}
SDL_DFB_CHECKERR(data->
palette->SetEntries(data->palette, entries, ncolors, firstcolor));
return 0;
} else {
SDL_SetError("YUV textures don't have a palette");
return -1;
}
error:
return -1;
}
static int
DirectFB_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors)
{
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
if (SDL_ISPIXELFORMAT_INDEXED(data->format)
&& !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
DFBColor entries[256];
int i;
SDL_DFB_CHECKERR(data->
palette->GetEntries(data->palette, entries, ncolors,
firstcolor));
for (i = 0; i < ncolors; ++i) {
colors[i].r = entries[i].r;
colors[i].g = entries[i].g;
colors[i].b = entries[i].b;
colors->unused = SDL_ALPHA_OPAQUE;
}
return 0;
} else {
SDL_SetError("YUV textures don't have a palette");
return -1;
}
error:
return -1;
}
static int
DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
return 0;
}
static int
DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
{
return 0;
}
static int
DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
switch (texture->blendMode) {
case SDL_BLENDMODE_NONE:
//case SDL_BLENDMODE_MASK:
case SDL_BLENDMODE_BLEND:
case SDL_BLENDMODE_ADD:
case SDL_BLENDMODE_MOD:
return 0;
default:
SDL_Unsupported();
texture->blendMode = SDL_BLENDMODE_NONE;
return -1;
}
}
static int
DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
{
switch (renderer->blendMode) {
case SDL_BLENDMODE_NONE:
//case SDL_BLENDMODE_MASK:
case SDL_BLENDMODE_BLEND:
case SDL_BLENDMODE_ADD:
case SDL_BLENDMODE_MOD:
return 0;
default:
SDL_Unsupported();
renderer->blendMode = SDL_BLENDMODE_NONE;
return -1;
}
}
#if 0
685
686
687
static int
DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
688
#if (DFB_VERSION_ATLEAST(1,2,0))
689
690
691
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
692
switch (texture->scaleMode) {
693
694
case SDL_SCALEMODE_NONE:
case SDL_SCALEMODE_FAST:
695
696
data->render_options = DSRO_NONE;
break;
697
case SDL_SCALEMODE_SLOW:
698
699
data->render_options = DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE;
break;
700
case SDL_SCALEMODE_BEST:
701
702
703
data->render_options =
DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS;
break;
704
705
default:
SDL_Unsupported();
706
data->render_options = DSRO_NONE;
707
texture->scaleMode = SDL_SCALEMODE_NONE;
708
709
return -1;
}
710
#endif
711
712
return 0;
}
713
#endif
714
715
716
717
718
719
static int
DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
720
Uint8 *dpixels;
721
int dpitch;
722
723
724
Uint8 *src, *dst;
int row;
size_t length;
725
int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
726
// FIXME: SDL_BYTESPERPIXEL(texture->format) broken for yuv yv12 3 planes
727
728
729
730
731
732
733
734
DirectFB_ActivateRenderer(renderer);
if ((texture->format == SDL_PIXELFORMAT_YV12) ||
(texture->format == SDL_PIXELFORMAT_IYUV)) {
bpp = 1;
}
735
SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
736
737
DSLF_WRITE | DSLF_READ,
((void **) &dpixels), &dpitch));
738
src = (Uint8 *) pixels;
739
740
dst = (Uint8 *) dpixels + rect->y * dpitch + rect->x * bpp;
length = rect->w * bpp;
741
742
743
744
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += pitch;
dst += dpitch;
745
}
746
/* copy other planes for 3 plane formats */
747
748
if ((texture->format == SDL_PIXELFORMAT_YV12) ||
(texture->format == SDL_PIXELFORMAT_IYUV)) {
749
750
src = (Uint8 *) pixels + texture->h * pitch;
dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2;
751
for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) {
752
753
754
755
756
757
SDL_memcpy(dst, src, length / 2);
src += pitch / 2;
dst += dpitch / 2;
}
src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4;
dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2;
758
for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) {
759
760
761
762
763
SDL_memcpy(dst, src, length / 2);
src += pitch / 2;
dst += dpitch / 2;
}
}
764
SDL_DFB_CHECKERR(data->surface->Unlock(data->surface));
765
data->isDirty = 0;
766
return 0;
767
768
error:
return 1;
769
770
771
772
773
}
static int
DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
774
const SDL_Rect * rect, void **pixels, int *pitch)
775
{
776
777
DirectFB_TextureData *texturedata =
(DirectFB_TextureData *) texture->driverdata;
778
779
780
781
DirectFB_ActivateRenderer(renderer);
#if 0
782
783
if (markDirty) {
SDL_AddDirtyRect(&texturedata->dirty, rect);
784
}
785
#endif
786
787
788
789
if (texturedata->display) {
void *fdata;
int fpitch;
790
791
792
793
794
795
796
797
798
799
SDL_DFB_CHECKERR(texturedata->surface->Lock(texturedata->surface,
DSLF_WRITE | DSLF_READ,
&fdata, &fpitch));
*pitch = fpitch;
*pixels = fdata;
} else {
*pixels =
(void *) ((Uint8 *) texturedata->pixels +
rect->y * texturedata->pitch +
800
rect->x * DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format)));
801
*pitch = texturedata->pitch;
802
texturedata->isDirty = 1;
803
}
804
return 0;
805
806
807
808
809
810
811
812
error:
return -1;
}
static void
DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
813
814
DirectFB_TextureData *texturedata =
(DirectFB_TextureData *) texture->driverdata;
815
816
817
DirectFB_ActivateRenderer(renderer);
818
if (texturedata->display) {
819
SDL_DFB_CHECK(texturedata->surface->Unlock(texturedata->surface));
820
821
texturedata->pixels = NULL;
}
822
823
}
824
#if 0
825
826
827
828
static void
DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects)
{
829
830
831
832
833
834
DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
int i;
for (i = 0; i < numrects; ++i) {
SDL_AddDirtyRect(&data->dirty, &rects[i]);
}
835
}
836
#endif
837
838
839
static int
PrepareDraw(SDL_Renderer * renderer)
840
841
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
842
SDL_DFB_WINDOWSURFACE(data->window);
843
844
845
846
847
848
849
850
851
Uint8 r, g, b, a;
r = renderer->r;
g = renderer->g;
b = renderer->b;
a = renderer->a;
SetBlendMode(data, renderer->blendMode, NULL);
852
SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags));
853
854
855
switch (renderer->blendMode) {
case SDL_BLENDMODE_NONE:
856
//case SDL_BLENDMODE_MASK:
857
858
859
case SDL_BLENDMODE_BLEND:
break;
case SDL_BLENDMODE_ADD:
860
case SDL_BLENDMODE_MOD:
861
862
863
864
865
866
r = ((int) r * (int) a) / 255;
g = ((int) g * (int) a) / 255;
b = ((int) b * (int) a) / 255;
a = 255;
break;
}
867
868
SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, r, g, b, a));
869
870
871
872
873
return 0;
error:
return -1;
}
874
875
static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count)
876
877
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
878
SDL_DFB_WINDOWSURFACE(data->window);
879
int i;
880
881
882
DirectFB_ActivateRenderer(renderer);
883
PrepareDraw(renderer);
884
885
for (i=0; i < count; i++)
SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i].x, points[i].y));
886
887
888
889
890
return 0;
error:
return -1;
}
891
892
static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count)
893
894
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
895
SDL_DFB_WINDOWSURFACE(data->window);
896
int i;
897
898
899
DirectFB_ActivateRenderer(renderer);
900
PrepareDraw(renderer);
901
/* Use antialiasing when available */
902
#if (DFB_VERSION_ATLEAST(1,2,0))
903
SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS));
904
#endif
905
906
907
908
for (i=0; i < count - 1; i++)
SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, points[i].x, points[i].y, points[i+1].x, points[i+1].y));
909
910
911
912
913
return 0;
error:
return -1;
}
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
static int
DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
SDL_DFB_WINDOWSURFACE(data->window);
int i;
DirectFB_ActivateRenderer(renderer);
PrepareDraw(renderer);
for (i=0; i<count; i++)
SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y,
rects[i]->w, rects[i]->h));
return 0;
error:
return -1;
}
934
935
936
937
938
939
940
static int
DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
SDL_DFB_WINDOWSURFACE(data->window);
int i;
941
942
DirectFB_ActivateRenderer(renderer);
943
944
945
946
947
PrepareDraw(renderer);
for (i=0; i<count; i++)
SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, rects[i]->x, rects[i]->y,
rects[i]->w, rects[i]->h));
948
949
950
951
952
953
954
955
956
957
958
return 0;
error:
return -1;
}
static int
DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
{
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
959
SDL_DFB_WINDOWSURFACE(data->window);
960
961
DirectFB_TextureData *texturedata =
(DirectFB_TextureData *) texture->driverdata;
962
963
964
Uint8 alpha, r, g, b;
DirectFB_ActivateRenderer(renderer);
965
966
if (texturedata->display) {
967
int px, py;
968
SDL_Window *window = renderer->window;
969
SDL_DFB_WINDOWDATA(window);
970
971
SDL_VideoDisplay *display = texturedata->display;
DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
972
973
974
975
976
977
SDL_DFB_CHECKERR(dispdata->
vidlayer->SetSourceRectangle(dispdata->vidlayer,
srcrect->x, srcrect->y,
srcrect->w,
srcrect->h));
978
SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin, &px, &py));
979
980
981
982
983
984
985
986
px += windata->client.x;
py += windata->client.y;
SDL_DFB_CHECKERR(dispdata->
vidlayer->SetScreenRectangle(dispdata->vidlayer,
px + dstrect->x,
py + dstrect->y,
dstrect->w,
dstrect->h));
987
988
989
990
} else {
DFBRectangle sr, dr;
DFBSurfaceBlittingFlags flags = 0;
991
#if 0
992
993
994
if (texturedata->dirty.list) {
SDL_DirtyRect *dirty;
void *pixels;
995
int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
996
997
998
999
1000
int pitch = texturedata->pitch;
for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
SDL_Rect *rect = &dirty->rect;
pixels =