Skip to content

Latest commit

 

History

History
538 lines (487 loc) · 14.3 KB

SDL_x11yuv.c

File metadata and controls

538 lines (487 loc) · 14.3 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Dec 8, 2008
Dec 8, 2008
3
Copyright (C) 1997-2009 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
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
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
/* This is the XFree86 Xv extension implementation of YUV video overlays */
Feb 16, 2006
Feb 16, 2006
26
#if SDL_VIDEO_DRIVER_X11_XV
Apr 26, 2001
Apr 26, 2001
27
28
#include <X11/Xlib.h>
Feb 12, 2004
Feb 12, 2004
29
#ifndef NO_SHARED_MEMORY
Apr 26, 2001
Apr 26, 2001
30
31
32
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
Feb 12, 2004
Feb 12, 2004
33
#endif
Feb 16, 2006
Feb 16, 2006
34
#include "../Xext/extensions/Xvlib.h"
Apr 26, 2001
Apr 26, 2001
35
36
#include "SDL_x11yuv_c.h"
Feb 16, 2006
Feb 16, 2006
37
#include "../SDL_yuvfuncs.h"
Apr 26, 2001
Apr 26, 2001
38
39
40
41
42
43
44
45
46
#define XFREE86_REFRESH_HACK
#ifdef XFREE86_REFRESH_HACK
#include "SDL_x11image_c.h"
#endif
/* Workaround when pitch != width */
#define PITCH_WORKAROUND
Dec 29, 2007
Dec 29, 2007
47
48
49
50
/* Workaround intel i810 video overlay waiting with failing until the
first Xv[Shm]PutImage call <sigh> */
#define INTEL_XV_BADALLOC_WORKAROUND
Sep 14, 2001
Sep 14, 2001
51
/* Fix for the NVidia GeForce 2 - use the last available adaptor */
Apr 11, 2002
Apr 11, 2002
52
/*#define USE_LAST_ADAPTOR*/ /* Apparently the NVidia drivers are fixed */
Sep 14, 2001
Sep 14, 2001
53
Apr 26, 2001
Apr 26, 2001
54
55
56
57
58
59
60
61
62
63
/* The functions used to manipulate software video overlays */
static struct private_yuvhwfuncs x11_yuvfuncs = {
X11_LockYUVOverlay,
X11_UnlockYUVOverlay,
X11_DisplayYUVOverlay,
X11_FreeYUVOverlay
};
struct private_yuvhwdata {
int port;
Feb 12, 2004
Feb 12, 2004
64
65
#ifndef NO_SHARED_MEMORY
int yuv_use_mitshm;
Apr 26, 2001
Apr 26, 2001
66
XShmSegmentInfo yuvshm;
Feb 12, 2004
Feb 12, 2004
67
#endif
Mar 5, 2002
Mar 5, 2002
68
SDL_NAME(XvImage) *image;
Apr 26, 2001
Apr 26, 2001
69
70
71
};
Aug 25, 2004
Aug 25, 2004
72
73
static int (*X_handler)(Display *, XErrorEvent *) = NULL;
Feb 12, 2004
Feb 12, 2004
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef NO_SHARED_MEMORY
/* Shared memory error handler routine */
static int shm_error;
static int shm_errhandler(Display *d, XErrorEvent *e)
{
if ( e->error_code == BadAccess ) {
shm_error = True;
return(0);
} else
return(X_handler(d,e));
}
#endif /* !NO_SHARED_MEMORY */
Aug 25, 2004
Aug 25, 2004
87
88
89
90
91
92
93
94
95
static int xv_error;
static int xv_errhandler(Display *d, XErrorEvent *e)
{
if ( e->error_code == BadMatch ) {
xv_error = True;
return(0);
} else
return(X_handler(d,e));
}
Feb 12, 2004
Feb 12, 2004
96
Dec 29, 2007
Dec 29, 2007
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifdef INTEL_XV_BADALLOC_WORKAROUND
static int intel_errhandler(Display *d, XErrorEvent *e)
{
if ( e->error_code == BadAlloc ) {
xv_error = True;
return(0);
} else
return(X_handler(d,e));
}
static void X11_ClearYUVOverlay(SDL_Overlay *overlay)
{
int x,y;
switch (overlay->format)
{
case SDL_YV12_OVERLAY:
case SDL_IYUV_OVERLAY:
for (y = 0; y < overlay->h; y++)
memset(overlay->pixels[0] + y * overlay->pitches[0],
0, overlay->w);
for (y = 0; y < (overlay->h / 2); y++)
{
memset(overlay->pixels[1] + y * overlay->pitches[1],
-128, overlay->w / 2);
memset(overlay->pixels[2] + y * overlay->pitches[2],
-128, overlay->w / 2);
}
break;
case SDL_YUY2_OVERLAY:
case SDL_YVYU_OVERLAY:
for (y = 0; y < overlay->h; y++)
{
for (x = 0; x < overlay->w; x += 2)
{
Uint8 *pixel_pair = overlay->pixels[0] +
y * overlay->pitches[0] + x * 2;
pixel_pair[0] = 0;
pixel_pair[1] = -128;
pixel_pair[2] = 0;
pixel_pair[3] = -128;
}
}
break;
case SDL_UYVY_OVERLAY:
for (y = 0; y < overlay->h; y++)
{
for (x = 0; x < overlay->w; x += 2)
{
Uint8 *pixel_pair = overlay->pixels[0] +
y * overlay->pitches[0] + x * 2;
pixel_pair[0] = -128;
pixel_pair[1] = 0;
pixel_pair[2] = -128;
pixel_pair[3] = 0;
}
}
break;
}
}
#endif
Apr 26, 2001
Apr 26, 2001
160
161
162
163
164
SDL_Overlay *X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
{
SDL_Overlay *overlay;
struct private_yuvhwdata *hwdata;
int xv_port;
Dec 8, 2005
Dec 8, 2005
165
166
unsigned int i, j, k;
unsigned int adaptors;
Mar 5, 2002
Mar 5, 2002
167
SDL_NAME(XvAdaptorInfo) *ainfo;
Feb 12, 2004
Feb 12, 2004
168
169
int bpp;
#ifndef NO_SHARED_MEMORY
Apr 26, 2001
Apr 26, 2001
170
XShmSegmentInfo *yuvshm;
Feb 12, 2004
Feb 12, 2004
171
#endif
Dec 29, 2007
Dec 29, 2007
172
173
174
#ifdef INTEL_XV_BADALLOC_WORKAROUND
int intel_adapter = False;
#endif
Apr 26, 2001
Apr 26, 2001
175
176
177
/* Look for the XVideo extension with a valid port for this format */
xv_port = -1;
Mar 5, 2002
Mar 5, 2002
178
179
if ( (Success == SDL_NAME(XvQueryExtension)(GFX_Display, &j, &j, &j, &j, &j)) &&
(Success == SDL_NAME(XvQueryAdaptors)(GFX_Display,
Apr 26, 2001
Apr 26, 2001
180
181
RootWindow(GFX_Display, SDL_Screen),
&adaptors, &ainfo)) ) {
Sep 14, 2001
Sep 14, 2001
182
#ifdef USE_LAST_ADAPTOR
Jul 26, 2003
Jul 26, 2003
183
for ( i=0; i < adaptors; ++i )
Sep 14, 2001
Sep 14, 2001
184
#else
Jul 26, 2003
Jul 26, 2003
185
for ( i=0; (i < adaptors) && (xv_port == -1); ++i )
Sep 14, 2001
Sep 14, 2001
186
#endif /* USE_LAST_ADAPTOR */
Jul 26, 2003
Jul 26, 2003
187
{
Apr 26, 2001
Apr 26, 2001
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* Check to see if the visual can be used */
if ( BUGGY_XFREE86(<=, 4001) ) {
int visual_ok = 0;
for ( j=0; j<ainfo[i].num_formats; ++j ) {
if ( ainfo[i].formats[j].visual_id ==
SDL_Visual->visualid ) {
visual_ok = 1;
break;
}
}
if ( ! visual_ok ) {
continue;
}
}
Dec 29, 2007
Dec 29, 2007
202
203
204
205
206
207
#ifdef INTEL_XV_BADALLOC_WORKAROUND
if ( !strcmp(ainfo[i].name, "Intel(R) Video Overla"))
intel_adapter = True;
else
intel_adapter = False;
#endif
Apr 26, 2001
Apr 26, 2001
208
209
210
if ( (ainfo[i].type & XvInputMask) &&
(ainfo[i].type & XvImageMask) ) {
int num_formats;
Mar 5, 2002
Mar 5, 2002
211
212
SDL_NAME(XvImageFormatValues) *formats;
formats = SDL_NAME(XvListImageFormats)(GFX_Display,
Apr 26, 2001
Apr 26, 2001
213
ainfo[i].base_id, &num_formats);
Sep 14, 2001
Sep 14, 2001
214
#ifdef USE_LAST_ADAPTOR
Jul 26, 2003
Jul 26, 2003
215
for ( j=0; j < num_formats; ++j )
Sep 14, 2001
Sep 14, 2001
216
#else
Jul 26, 2003
Jul 26, 2003
217
for ( j=0; (j < num_formats) && (xv_port == -1); ++j )
Sep 14, 2001
Sep 14, 2001
218
#endif /* USE_LAST_ADAPTOR */
Jul 26, 2003
Jul 26, 2003
219
{
Apr 26, 2001
Apr 26, 2001
220
221
if ( (Uint32)formats[j].id == format ) {
for ( k=0; k < ainfo[i].num_ports; ++k ) {
Mar 5, 2002
Mar 5, 2002
222
if ( Success == SDL_NAME(XvGrabPort)(GFX_Display, ainfo[i].base_id+k, CurrentTime) ) {
Apr 26, 2001
Apr 26, 2001
223
224
225
226
227
228
xv_port = ainfo[i].base_id+k;
break;
}
}
}
}
Jun 13, 2002
Jun 13, 2002
229
if ( formats ) {
Mar 22, 2006
Mar 22, 2006
230
XFree(formats);
Jun 13, 2002
Jun 13, 2002
231
}
Apr 26, 2001
Apr 26, 2001
232
233
}
}
Jun 13, 2002
Jun 13, 2002
234
SDL_NAME(XvFreeAdaptorInfo)(ainfo);
Apr 26, 2001
Apr 26, 2001
235
}
Jul 30, 2002
Jul 30, 2002
236
Feb 12, 2004
Feb 12, 2004
237
238
239
240
241
242
243
244
245
246
247
248
249
/* Precalculate the bpp for the pitch workaround below */
switch (format) {
/* Add any other cases we need to support... */
case SDL_YUY2_OVERLAY:
case SDL_UYVY_OVERLAY:
case SDL_YVYU_OVERLAY:
bpp = 2;
break;
default:
bpp = 1;
break;
}
Aug 12, 2002
Aug 12, 2002
250
#if 0
Jul 30, 2002
Jul 30, 2002
251
252
253
254
255
/*
* !!! FIXME:
* "Here are some diffs for X11 and yuv. Note that the last part 2nd
* diff should probably be a new call to XvQueryAdaptorFree with ainfo
* and the number of adaptors, instead of the loop through like I did."
Aug 12, 2002
Aug 12, 2002
256
257
258
259
*
* ACHTUNG: This is broken! It looks like XvFreeAdaptorInfo does this
* for you, so we end up with a double-free. I need to look at this
* more closely... --ryan.
Jul 30, 2002
Jul 30, 2002
260
261
262
263
264
265
*/
for ( i=0; i < adaptors; ++i ) {
if (ainfo[i].name != NULL) Xfree(ainfo[i].name);
if (ainfo[i].formats != NULL) Xfree(ainfo[i].formats);
}
Xfree(ainfo);
Aug 12, 2002
Aug 12, 2002
266
#endif
Jul 30, 2002
Jul 30, 2002
267
Apr 26, 2001
Apr 26, 2001
268
269
270
271
272
if ( xv_port == -1 ) {
SDL_SetError("No available video ports for requested format");
return(NULL);
}
Aug 25, 2004
Aug 25, 2004
273
274
275
276
277
278
/* Enable auto-painting of the overlay colorkey */
{
static const char *attr[] = { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" };
unsigned int i;
SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True);
Mar 22, 2006
Mar 22, 2006
279
X_handler = XSetErrorHandler(xv_errhandler);
Aug 25, 2004
Aug 25, 2004
280
281
282
283
for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) {
Atom a;
xv_error = False;
Mar 22, 2006
Mar 22, 2006
284
a = XInternAtom(GFX_Display, attr[i], True);
Aug 25, 2004
Aug 25, 2004
285
286
if ( a != None ) {
SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1);
Mar 22, 2006
Mar 22, 2006
287
XSync(GFX_Display, True);
Aug 25, 2004
Aug 25, 2004
288
289
290
291
292
if ( ! xv_error ) {
break;
}
}
}
Mar 22, 2006
Mar 22, 2006
293
XSetErrorHandler(X_handler);
Aug 25, 2004
Aug 25, 2004
294
295
296
SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False);
}
Apr 26, 2001
Apr 26, 2001
297
/* Create the overlay structure */
Feb 7, 2006
Feb 7, 2006
298
overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
Apr 26, 2001
Apr 26, 2001
299
if ( overlay == NULL ) {
Mar 5, 2002
Mar 5, 2002
300
SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
Apr 26, 2001
Apr 26, 2001
301
302
303
SDL_OutOfMemory();
return(NULL);
}
Feb 7, 2006
Feb 7, 2006
304
SDL_memset(overlay, 0, (sizeof *overlay));
Apr 26, 2001
Apr 26, 2001
305
306
307
308
309
310
311
312
313
314
315
/* Fill in the basic members */
overlay->format = format;
overlay->w = width;
overlay->h = height;
/* Set up the YUV surface function structure */
overlay->hwfuncs = &x11_yuvfuncs;
overlay->hw_overlay = 1;
/* Create the pixel data and lookup tables */
Feb 7, 2006
Feb 7, 2006
316
hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
Apr 26, 2001
Apr 26, 2001
317
318
overlay->hwdata = hwdata;
if ( hwdata == NULL ) {
Mar 5, 2002
Mar 5, 2002
319
SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
Apr 26, 2001
Apr 26, 2001
320
321
322
323
SDL_OutOfMemory();
SDL_FreeYUVOverlay(overlay);
return(NULL);
}
Feb 12, 2004
Feb 12, 2004
324
325
hwdata->port = xv_port;
#ifndef NO_SHARED_MEMORY
Apr 26, 2001
Apr 26, 2001
326
yuvshm = &hwdata->yuvshm;
Feb 7, 2006
Feb 7, 2006
327
SDL_memset(yuvshm, 0, sizeof(*yuvshm));
Mar 5, 2002
Mar 5, 2002
328
hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
Feb 12, 2004
Feb 12, 2004
329
0, width, height, yuvshm);
Apr 26, 2001
Apr 26, 2001
330
#ifdef PITCH_WORKAROUND
Feb 12, 2004
Feb 12, 2004
331
332
if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
/* Ajust overlay width according to pitch */
Mar 22, 2006
Mar 22, 2006
333
XFree(hwdata->image);
Feb 12, 2004
Feb 12, 2004
334
335
336
width = hwdata->image->pitches[0] / bpp;
hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
0, width, height, yuvshm);
Apr 26, 2001
Apr 26, 2001
337
}
Feb 12, 2004
Feb 12, 2004
338
339
340
341
342
343
344
345
346
347
#endif /* PITCH_WORKAROUND */
hwdata->yuv_use_mitshm = (hwdata->image != NULL);
if ( hwdata->yuv_use_mitshm ) {
yuvshm->shmid = shmget(IPC_PRIVATE, hwdata->image->data_size,
IPC_CREAT | 0777);
if ( yuvshm->shmid >= 0 ) {
yuvshm->shmaddr = (char *)shmat(yuvshm->shmid, 0, 0);
yuvshm->readOnly = False;
if ( yuvshm->shmaddr != (char *)-1 ) {
shm_error = False;
Mar 22, 2006
Mar 22, 2006
348
349
350
351
X_handler = XSetErrorHandler(shm_errhandler);
XShmAttach(GFX_Display, yuvshm);
XSync(GFX_Display, True);
XSetErrorHandler(X_handler);
Feb 12, 2004
Feb 12, 2004
352
353
354
355
356
357
358
359
360
361
if ( shm_error )
shmdt(yuvshm->shmaddr);
} else {
shm_error = True;
}
shmctl(yuvshm->shmid, IPC_RMID, NULL);
} else {
shm_error = True;
}
if ( shm_error ) {
Mar 22, 2006
Mar 22, 2006
362
XFree(hwdata->image);
Feb 12, 2004
Feb 12, 2004
363
364
365
366
hwdata->yuv_use_mitshm = 0;
} else {
hwdata->image->data = yuvshm->shmaddr;
}
Apr 26, 2001
Apr 26, 2001
367
}
Feb 12, 2004
Feb 12, 2004
368
369
370
371
372
if ( !hwdata->yuv_use_mitshm )
#endif /* NO_SHARED_MEMORY */
{
hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format,
0, width, height);
Apr 26, 2001
Apr 26, 2001
373
Feb 12, 2004
Feb 12, 2004
374
375
376
#ifdef PITCH_WORKAROUND
if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
/* Ajust overlay width according to pitch */
Mar 22, 2006
Mar 22, 2006
377
XFree(hwdata->image);
Feb 12, 2004
Feb 12, 2004
378
379
380
381
382
383
384
385
386
387
width = hwdata->image->pitches[0] / bpp;
hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format,
0, width, height);
}
#endif /* PITCH_WORKAROUND */
if ( hwdata->image == NULL ) {
SDL_SetError("Couldn't create XVideo image");
SDL_FreeYUVOverlay(overlay);
return(NULL);
}
Feb 7, 2006
Feb 7, 2006
388
hwdata->image->data = SDL_malloc(hwdata->image->data_size);
Feb 12, 2004
Feb 12, 2004
389
390
391
392
393
394
if ( hwdata->image->data == NULL ) {
SDL_OutOfMemory();
SDL_FreeYUVOverlay(overlay);
return(NULL);
}
}
Apr 26, 2001
Apr 26, 2001
395
396
397
/* Find the pitch and offset values for the overlay */
overlay->planes = hwdata->image->num_planes;
Feb 7, 2006
Feb 7, 2006
398
399
overlay->pitches = (Uint16 *)SDL_malloc(overlay->planes * sizeof(Uint16));
overlay->pixels = (Uint8 **)SDL_malloc(overlay->planes * sizeof(Uint8 *));
Apr 26, 2001
Apr 26, 2001
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
if ( !overlay->pitches || !overlay->pixels ) {
SDL_OutOfMemory();
SDL_FreeYUVOverlay(overlay);
return(NULL);
}
for ( i=0; i<overlay->planes; ++i ) {
overlay->pitches[i] = hwdata->image->pitches[i];
overlay->pixels[i] = (Uint8 *)hwdata->image->data +
hwdata->image->offsets[i];
}
#ifdef XFREE86_REFRESH_HACK
/* Work around an XFree86 X server bug (?)
We can't perform normal updates in windows that have video
being output to them. See SDL_x11image.c for more details.
*/
X11_DisableAutoRefresh(this);
#endif
Dec 29, 2007
Dec 29, 2007
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#ifdef INTEL_XV_BADALLOC_WORKAROUND
/* HACK, GRRR sometimes (i810) creating the overlay succeeds, but the
first call to XvShm[Put]Image to a mapped window fails with:
"BadAlloc (insufficient resources for operation)". This happens with
certain formats when the XvImage is too large to the i810's liking.
We work around this by doing a test XvShm[Put]Image with a black
Xv image, this may cause some flashing, so only do this check if we
are running on an intel Xv-adapter. */
if (intel_adapter)
{
xv_error = False;
X_handler = XSetErrorHandler(intel_errhandler);
X11_ClearYUVOverlay(overlay);
/* We set the destination height and width to 1 pixel to avoid
putting a large black rectangle over the screen, thus
strongly reducing possible flashing. */
#ifndef NO_SHARED_MEMORY
if ( hwdata->yuv_use_mitshm ) {
SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port,
SDL_Window, SDL_GC,
hwdata->image,
0, 0, overlay->w, overlay->h,
0, 0, 1, 1, False);
}
else
#endif
{
SDL_NAME(XvPutImage)(GFX_Display, hwdata->port,
SDL_Window, SDL_GC,
hwdata->image,
0, 0, overlay->w, overlay->h,
0, 0, 1, 1);
}
XSync(GFX_Display, False);
XSetErrorHandler(X_handler);
if (xv_error)
{
X11_FreeYUVOverlay(this, overlay);
return NULL;
}
/* Repair the (1 pixel worth of) damage we've just done */
X11_RefreshDisplay(this);
}
#endif
Apr 26, 2001
Apr 26, 2001
468
469
470
471
472
473
474
475
476
477
478
479
480
481
/* We're all done.. */
return(overlay);
}
int X11_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
{
return(0);
}
void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
{
return;
}
Apr 17, 2006
Apr 17, 2006
482
int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
Apr 26, 2001
Apr 26, 2001
483
484
485
486
{
struct private_yuvhwdata *hwdata;
hwdata = overlay->hwdata;
Apr 17, 2006
Apr 17, 2006
487
Feb 12, 2004
Feb 12, 2004
488
489
490
#ifndef NO_SHARED_MEMORY
if ( hwdata->yuv_use_mitshm ) {
SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
Apr 17, 2006
Apr 17, 2006
491
hwdata->image,
Apr 17, 2006
Apr 17, 2006
492
493
src->x, src->y, src->w, src->h,
dst->x, dst->y, dst->w, dst->h, False);
Feb 12, 2004
Feb 12, 2004
494
495
496
497
498
}
else
#endif
{
SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
Apr 17, 2006
Apr 17, 2006
499
hwdata->image,
Apr 17, 2006
Apr 17, 2006
500
501
src->x, src->y, src->w, src->h,
dst->x, dst->y, dst->w, dst->h);
Feb 12, 2004
Feb 12, 2004
502
}
Mar 22, 2006
Mar 22, 2006
503
XSync(GFX_Display, False);
Apr 26, 2001
Apr 26, 2001
504
505
506
507
508
509
510
511
512
return(0);
}
void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
{
struct private_yuvhwdata *hwdata;
hwdata = overlay->hwdata;
if ( hwdata ) {
Mar 5, 2002
Mar 5, 2002
513
SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime);
Feb 12, 2004
Feb 12, 2004
514
515
#ifndef NO_SHARED_MEMORY
if ( hwdata->yuv_use_mitshm ) {
Mar 22, 2006
Mar 22, 2006
516
XShmDetach(GFX_Display, &hwdata->yuvshm);
Apr 26, 2001
Apr 26, 2001
517
518
shmdt(hwdata->yuvshm.shmaddr);
}
Feb 12, 2004
Feb 12, 2004
519
#endif
Apr 26, 2001
Apr 26, 2001
520
if ( hwdata->image ) {
Mar 22, 2006
Mar 22, 2006
521
XFree(hwdata->image);
Apr 26, 2001
Apr 26, 2001
522
}
Feb 7, 2006
Feb 7, 2006
523
SDL_free(hwdata);
Apr 26, 2001
Apr 26, 2001
524
525
}
if ( overlay->pitches ) {
Feb 7, 2006
Feb 7, 2006
526
SDL_free(overlay->pitches);
Apr 26, 2001
Apr 26, 2001
527
528
529
overlay->pitches = NULL;
}
if ( overlay->pixels ) {
Feb 7, 2006
Feb 7, 2006
530
SDL_free(overlay->pixels);
Apr 26, 2001
Apr 26, 2001
531
532
533
534
535
536
537
overlay->pixels = NULL;
}
#ifdef XFREE86_REFRESH_HACK
X11_EnableAutoRefresh(this);
#endif
}
Feb 16, 2006
Feb 16, 2006
538
#endif /* SDL_VIDEO_DRIVER_X11_XV */