annotate src/video/x11/SDL_x11yuv.c @ 1643:51038e80ae59

More general fix for bug #189 The clipping is done at a higher level, and the low level functions are passed clipped rectangles. Drivers which don't support source clipping have not been changed, so the image will be squished instead of clipped, but at least they will no longer crash when the destination rect was out of bounds.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 17 Apr 2006 06:47:23 +0000
parents f1211a4b7380
children 782fd950bd46 c121d94672cb 12bb6311fd5d
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1306
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 182
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* This is the XFree86 Xv extension implementation of YUV video overlays */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
26 #if SDL_VIDEO_DRIVER_X11_XV
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <X11/Xlib.h>
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
29 #ifndef NO_SHARED_MEMORY
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <sys/ipc.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <sys/shm.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <X11/extensions/XShm.h>
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
33 #endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
34 #include "../Xext/extensions/Xvlib.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include "SDL_x11yuv_c.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
37 #include "../SDL_yuvfuncs.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #define XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #ifdef XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #include "SDL_x11image_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 /* Workaround when pitch != width */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #define PITCH_WORKAROUND
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
47 /* Fix for the NVidia GeForce 2 - use the last available adaptor */
341
6ca967a46bf1 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
48 /*#define USE_LAST_ADAPTOR*/ /* Apparently the NVidia drivers are fixed */
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
49
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 /* The functions used to manipulate software video overlays */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 static struct private_yuvhwfuncs x11_yuvfuncs = {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 X11_LockYUVOverlay,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 X11_UnlockYUVOverlay,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 X11_DisplayYUVOverlay,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 X11_FreeYUVOverlay
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 struct private_yuvhwdata {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 int port;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
60 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
61 int yuv_use_mitshm;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 XShmSegmentInfo yuvshm;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
63 #endif
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
64 SDL_NAME(XvImage) *image;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
68 static int (*X_handler)(Display *, XErrorEvent *) = NULL;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
69
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
70 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
71 /* Shared memory error handler routine */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
72 static int shm_error;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
73 static int shm_errhandler(Display *d, XErrorEvent *e)
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
74 {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
75 if ( e->error_code == BadAccess ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
76 shm_error = True;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
77 return(0);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
78 } else
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
79 return(X_handler(d,e));
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
80 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
81 #endif /* !NO_SHARED_MEMORY */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
82
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
83 static int xv_error;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
84 static int xv_errhandler(Display *d, XErrorEvent *e)
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
85 {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
86 if ( e->error_code == BadMatch ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
87 xv_error = True;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
88 return(0);
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
89 } else
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
90 return(X_handler(d,e));
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
91 }
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
92
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 SDL_Overlay *X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 SDL_Overlay *overlay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 struct private_yuvhwdata *hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 int xv_port;
1196
b81f54c3963f Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents: 1168
diff changeset
98 unsigned int i, j, k;
b81f54c3963f Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents: 1168
diff changeset
99 unsigned int adaptors;
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
100 SDL_NAME(XvAdaptorInfo) *ainfo;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
101 int bpp;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
102 #ifndef NO_SHARED_MEMORY
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 XShmSegmentInfo *yuvshm;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
104 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 /* Look for the XVideo extension with a valid port for this format */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 xv_port = -1;
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
108 if ( (Success == SDL_NAME(XvQueryExtension)(GFX_Display, &j, &j, &j, &j, &j)) &&
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
109 (Success == SDL_NAME(XvQueryAdaptors)(GFX_Display,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 RootWindow(GFX_Display, SDL_Screen),
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 &adaptors, &ainfo)) ) {
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
112 #ifdef USE_LAST_ADAPTOR
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
113 for ( i=0; i < adaptors; ++i )
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
114 #else
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
115 for ( i=0; (i < adaptors) && (xv_port == -1); ++i )
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
116 #endif /* USE_LAST_ADAPTOR */
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
117 {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 /* Check to see if the visual can be used */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 if ( BUGGY_XFREE86(<=, 4001) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 int visual_ok = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 for ( j=0; j<ainfo[i].num_formats; ++j ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 if ( ainfo[i].formats[j].visual_id ==
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 SDL_Visual->visualid ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 visual_ok = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 if ( ! visual_ok ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 if ( (ainfo[i].type & XvInputMask) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 (ainfo[i].type & XvImageMask) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 int num_formats;
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
135 SDL_NAME(XvImageFormatValues) *formats;
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
136 formats = SDL_NAME(XvListImageFormats)(GFX_Display,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 ainfo[i].base_id, &num_formats);
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
138 #ifdef USE_LAST_ADAPTOR
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
139 for ( j=0; j < num_formats; ++j )
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
140 #else
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
141 for ( j=0; (j < num_formats) && (xv_port == -1); ++j )
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
142 #endif /* USE_LAST_ADAPTOR */
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
143 {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 if ( (Uint32)formats[j].id == format ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 for ( k=0; k < ainfo[i].num_ports; ++k ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
146 if ( Success == SDL_NAME(XvGrabPort)(GFX_Display, ainfo[i].base_id+k, CurrentTime) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 xv_port = ainfo[i].base_id+k;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 }
410
365f57b7c4ac *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 409
diff changeset
153 if ( formats ) {
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
154 XFree(formats);
410
365f57b7c4ac *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 409
diff changeset
155 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 }
409
1c3cf7231cd4 Fixed memory leaks in YUV code
Sam Lantinga <slouken@libsdl.org>
parents: 341
diff changeset
158 SDL_NAME(XvFreeAdaptorInfo)(ainfo);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 }
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
160
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
161 /* Precalculate the bpp for the pitch workaround below */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
162 switch (format) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
163 /* Add any other cases we need to support... */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
164 case SDL_YUY2_OVERLAY:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
165 case SDL_UYVY_OVERLAY:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
166 case SDL_YVYU_OVERLAY:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
167 bpp = 2;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
168 break;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
169 default:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
170 bpp = 1;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
171 break;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
172 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
173
434
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
174 #if 0
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
175 /*
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
176 * !!! FIXME:
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
177 * "Here are some diffs for X11 and yuv. Note that the last part 2nd
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
178 * diff should probably be a new call to XvQueryAdaptorFree with ainfo
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
179 * and the number of adaptors, instead of the loop through like I did."
434
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
180 *
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
181 * ACHTUNG: This is broken! It looks like XvFreeAdaptorInfo does this
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
182 * for you, so we end up with a double-free. I need to look at this
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
183 * more closely... --ryan.
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
184 */
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
185 for ( i=0; i < adaptors; ++i ) {
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
186 if (ainfo[i].name != NULL) Xfree(ainfo[i].name);
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
187 if (ainfo[i].formats != NULL) Xfree(ainfo[i].formats);
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
188 }
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
189 Xfree(ainfo);
434
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
190 #endif
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
191
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 if ( xv_port == -1 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 SDL_SetError("No available video ports for requested format");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
197 /* Enable auto-painting of the overlay colorkey */
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
198 {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
199 static const char *attr[] = { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" };
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
200 unsigned int i;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
201
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
202 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True);
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
203 X_handler = XSetErrorHandler(xv_errhandler);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
204 for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
205 Atom a;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
206
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
207 xv_error = False;
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
208 a = XInternAtom(GFX_Display, attr[i], True);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
209 if ( a != None ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
210 SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1);
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
211 XSync(GFX_Display, True);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
212 if ( ! xv_error ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
213 break;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
214 }
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
215 }
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
216 }
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
217 XSetErrorHandler(X_handler);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
218 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False);
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
219 }
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
220
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 /* Create the overlay structure */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
222 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 if ( overlay == NULL ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
224 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
228 SDL_memset(overlay, 0, (sizeof *overlay));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 /* Fill in the basic members */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 overlay->format = format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 overlay->w = width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 overlay->h = height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 /* Set up the YUV surface function structure */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 overlay->hwfuncs = &x11_yuvfuncs;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 overlay->hw_overlay = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 /* Create the pixel data and lookup tables */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
240 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 overlay->hwdata = hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 if ( hwdata == NULL ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
243 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 SDL_FreeYUVOverlay(overlay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 }
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
248 hwdata->port = xv_port;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
249 #ifndef NO_SHARED_MEMORY
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 yuvshm = &hwdata->yuvshm;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
251 SDL_memset(yuvshm, 0, sizeof(*yuvshm));
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
252 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
253 0, width, height, yuvshm);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
254 #ifdef PITCH_WORKAROUND
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
255 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
256 /* Ajust overlay width according to pitch */
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
257 XFree(hwdata->image);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
258 width = hwdata->image->pitches[0] / bpp;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
259 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
260 0, width, height, yuvshm);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
261 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
262 #endif /* PITCH_WORKAROUND */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
263 hwdata->yuv_use_mitshm = (hwdata->image != NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
264 if ( hwdata->yuv_use_mitshm ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
265 yuvshm->shmid = shmget(IPC_PRIVATE, hwdata->image->data_size,
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
266 IPC_CREAT | 0777);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
267 if ( yuvshm->shmid >= 0 ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
268 yuvshm->shmaddr = (char *)shmat(yuvshm->shmid, 0, 0);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
269 yuvshm->readOnly = False;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
270 if ( yuvshm->shmaddr != (char *)-1 ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
271 shm_error = False;
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
272 X_handler = XSetErrorHandler(shm_errhandler);
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
273 XShmAttach(GFX_Display, yuvshm);
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
274 XSync(GFX_Display, True);
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
275 XSetErrorHandler(X_handler);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
276 if ( shm_error )
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
277 shmdt(yuvshm->shmaddr);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
278 } else {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
279 shm_error = True;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
280 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
281 shmctl(yuvshm->shmid, IPC_RMID, NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
282 } else {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
283 shm_error = True;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
284 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
285 if ( shm_error ) {
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
286 XFree(hwdata->image);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
287 hwdata->yuv_use_mitshm = 0;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
288 } else {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
289 hwdata->image->data = yuvshm->shmaddr;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
290 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
291 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
292 if ( !hwdata->yuv_use_mitshm )
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
293 #endif /* NO_SHARED_MEMORY */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
294 {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
295 hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format,
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
296 0, width, height);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 #ifdef PITCH_WORKAROUND
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
299 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
300 /* Ajust overlay width according to pitch */
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
301 XFree(hwdata->image);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
302 width = hwdata->image->pitches[0] / bpp;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
303 hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format,
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
304 0, width, height);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
305 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
306 #endif /* PITCH_WORKAROUND */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
307 if ( hwdata->image == NULL ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
308 SDL_SetError("Couldn't create XVideo image");
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
309 SDL_FreeYUVOverlay(overlay);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
310 return(NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
311 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
312 hwdata->image->data = SDL_malloc(hwdata->image->data_size);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
313 if ( hwdata->image->data == NULL ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
314 SDL_OutOfMemory();
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
315 SDL_FreeYUVOverlay(overlay);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
316 return(NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
317 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 /* Find the pitch and offset values for the overlay */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 overlay->planes = hwdata->image->num_planes;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
322 overlay->pitches = (Uint16 *)SDL_malloc(overlay->planes * sizeof(Uint16));
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
323 overlay->pixels = (Uint8 **)SDL_malloc(overlay->planes * sizeof(Uint8 *));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 if ( !overlay->pitches || !overlay->pixels ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 SDL_FreeYUVOverlay(overlay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 for ( i=0; i<overlay->planes; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 overlay->pitches[i] = hwdata->image->pitches[i];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 overlay->pixels[i] = (Uint8 *)hwdata->image->data +
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 hwdata->image->offsets[i];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 #ifdef XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 /* Work around an XFree86 X server bug (?)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 We can't perform normal updates in windows that have video
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 being output to them. See SDL_x11image.c for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 X11_DisableAutoRefresh(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 /* We're all done.. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 return(overlay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 int X11_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356
1643
51038e80ae59 More general fix for bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1642
diff changeset
357 int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 struct private_yuvhwdata *hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 hwdata = overlay->hwdata;
1642
f1211a4b7380 Fixed bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1575
diff changeset
362
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
363 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
364 if ( hwdata->yuv_use_mitshm ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
365 SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
1642
f1211a4b7380 Fixed bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1575
diff changeset
366 hwdata->image,
1643
51038e80ae59 More general fix for bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1642
diff changeset
367 src->x, src->y, src->w, src->h,
51038e80ae59 More general fix for bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1642
diff changeset
368 dst->x, dst->y, dst->w, dst->h, False);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
369 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
370 else
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
371 #endif
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
372 {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
373 SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
1642
f1211a4b7380 Fixed bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1575
diff changeset
374 hwdata->image,
1643
51038e80ae59 More general fix for bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1642
diff changeset
375 src->x, src->y, src->w, src->h,
51038e80ae59 More general fix for bug #189
Sam Lantinga <slouken@libsdl.org>
parents: 1642
diff changeset
376 dst->x, dst->y, dst->w, dst->h);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
377 }
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
378 XSync(GFX_Display, False);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 struct private_yuvhwdata *hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 hwdata = overlay->hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 if ( hwdata ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
388 SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
389 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
390 if ( hwdata->yuv_use_mitshm ) {
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
391 XShmDetach(GFX_Display, &hwdata->yuvshm);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 shmdt(hwdata->yuvshm.shmaddr);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 }
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
394 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 if ( hwdata->image ) {
1575
3ba88cb7eb1b Updated dynamic X11 code. See details in Bugzilla #170.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
396 XFree(hwdata->image);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
398 SDL_free(hwdata);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 if ( overlay->pitches ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
401 SDL_free(overlay->pitches);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 overlay->pitches = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 if ( overlay->pixels ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
405 SDL_free(overlay->pixels);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 overlay->pixels = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 #ifdef XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 X11_EnableAutoRefresh(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
413 #endif /* SDL_VIDEO_DRIVER_X11_XV */