annotate src/video/x11/SDL_x11yuv.c @ 1361:19418e4422cb

New configure-based build system. Still work in progress, but much improved
author Sam Lantinga <slouken@libsdl.org>
date Thu, 16 Feb 2006 10:11:48 +0000
parents c71e05b4dc2e
children d910939febfa
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 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 /* This is the XFree86 Xv extension implementation of YUV video overlays */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
25 #include "SDL_config.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
26
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
27 #if SDL_VIDEO_DRIVER_X11_XV
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <X11/Xlib.h>
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
30 #ifndef NO_SHARED_MEMORY
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <sys/ipc.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <sys/shm.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <X11/extensions/XShm.h>
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
34 #endif
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
35 #include "../Xext/extensions/Xvlib.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #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
38 #include "../SDL_yuvfuncs.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #define XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #ifdef XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #include "SDL_x11image_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 /* Workaround when pitch != width */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #define PITCH_WORKAROUND
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
48 /* 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
49 /*#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
50
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 /* The functions used to manipulate software video overlays */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 static struct private_yuvhwfuncs x11_yuvfuncs = {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 X11_LockYUVOverlay,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 X11_UnlockYUVOverlay,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 X11_DisplayYUVOverlay,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 X11_FreeYUVOverlay
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 struct private_yuvhwdata {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 int port;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
61 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
62 int yuv_use_mitshm;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 XShmSegmentInfo yuvshm;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
64 #endif
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
65 SDL_NAME(XvImage) *image;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
69 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
70
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
71 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
72 /* Shared memory error handler routine */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
73 static int shm_error;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
74 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
75 {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
76 if ( e->error_code == BadAccess ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
77 shm_error = True;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
78 return(0);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
79 } else
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
80 return(X_handler(d,e));
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
81 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
82 #endif /* !NO_SHARED_MEMORY */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
83
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
84 static int xv_error;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
85 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
86 {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
87 if ( e->error_code == BadMatch ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
88 xv_error = True;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
89 return(0);
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
90 } else
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
91 return(X_handler(d,e));
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
92 }
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
93
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 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
95 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 SDL_Overlay *overlay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 struct private_yuvhwdata *hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 int xv_port;
1196
b81f54c3963f Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents: 1168
diff changeset
99 unsigned int i, j, k;
b81f54c3963f Fixed compile warnings with gcc 4
Sam Lantinga <slouken@libsdl.org>
parents: 1168
diff changeset
100 unsigned int adaptors;
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
101 SDL_NAME(XvAdaptorInfo) *ainfo;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
102 int bpp;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
103 #ifndef NO_SHARED_MEMORY
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 XShmSegmentInfo *yuvshm;
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
105 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 /* Look for the XVideo extension with a valid port for this format */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 xv_port = -1;
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
109 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
110 (Success == SDL_NAME(XvQueryAdaptors)(GFX_Display,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 RootWindow(GFX_Display, SDL_Screen),
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 &adaptors, &ainfo)) ) {
182
d4ebd1bbea9a Fix XVideo on GeForce by using last available adaptor
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
113 #ifdef USE_LAST_ADAPTOR
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
114 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
115 #else
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
116 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
117 #endif /* USE_LAST_ADAPTOR */
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
118 {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 /* Check to see if the visual can be used */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 if ( BUGGY_XFREE86(<=, 4001) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 int visual_ok = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 for ( j=0; j<ainfo[i].num_formats; ++j ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 if ( ainfo[i].formats[j].visual_id ==
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 SDL_Visual->visualid ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 visual_ok = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 if ( ! visual_ok ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 if ( (ainfo[i].type & XvInputMask) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 (ainfo[i].type & XvImageMask) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 int num_formats;
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
136 SDL_NAME(XvImageFormatValues) *formats;
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
137 formats = SDL_NAME(XvListImageFormats)(GFX_Display,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 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
139 #ifdef USE_LAST_ADAPTOR
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
140 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
141 #else
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
142 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
143 #endif /* USE_LAST_ADAPTOR */
659
e3d0517bf67e *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 494
diff changeset
144 {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 if ( (Uint32)formats[j].id == format ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 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
147 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
148 xv_port = ainfo[i].base_id+k;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 break;
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 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 }
410
365f57b7c4ac *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 409
diff changeset
154 if ( formats ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
155 pXFree(formats);
410
365f57b7c4ac *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 409
diff changeset
156 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 }
409
1c3cf7231cd4 Fixed memory leaks in YUV code
Sam Lantinga <slouken@libsdl.org>
parents: 341
diff changeset
159 SDL_NAME(XvFreeAdaptorInfo)(ainfo);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 }
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
161
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
162 /* 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
163 switch (format) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
164 /* 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
165 case SDL_YUY2_OVERLAY:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
166 case SDL_UYVY_OVERLAY:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
167 case SDL_YVYU_OVERLAY:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
168 bpp = 2;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
169 break;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
170 default:
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
171 bpp = 1;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
172 break;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
173 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
174
434
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
175 #if 0
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
176 /*
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
177 * !!! FIXME:
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
178 * "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
179 * 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
180 * 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
181 *
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
182 * 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
183 * 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
184 * more closely... --ryan.
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
185 */
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
186 for ( i=0; i < adaptors; ++i ) {
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
187 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
188 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
189 }
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
190 Xfree(ainfo);
434
ed58b98c0d9d Commented double-free buggy code. Will examine more closely later.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
191 #endif
429
c1666427297c Memory leak fixes by Bill May.
Ryan C. Gordon <icculus@icculus.org>
parents: 410
diff changeset
192
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 if ( xv_port == -1 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 SDL_SetError("No available video ports for requested format");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
198 /* 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
199 {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
200 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
201 unsigned int i;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
202
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
203 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True);
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
204 X_handler = pXSetErrorHandler(xv_errhandler);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
205 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
206 Atom a;
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
207
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
208 xv_error = False;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
209 a = pXInternAtom(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
210 if ( a != None ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
211 SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1);
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
212 pXSync(GFX_Display, True);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
213 if ( ! xv_error ) {
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
214 break;
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 }
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
217 }
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
218 pXSetErrorHandler(X_handler);
950
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
219 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
220 }
b7a5c1b64829 Date: Tue, 24 Aug 2004 06:16:32 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 813
diff changeset
221
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 /* Create the overlay structure */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
223 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 if ( overlay == NULL ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
225 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
229 SDL_memset(overlay, 0, (sizeof *overlay));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 /* Fill in the basic members */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 overlay->format = format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 overlay->w = width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 overlay->h = height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 /* Set up the YUV surface function structure */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 overlay->hwfuncs = &x11_yuvfuncs;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 overlay->hw_overlay = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 /* 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
241 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 overlay->hwdata = hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 if ( hwdata == NULL ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
244 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 SDL_FreeYUVOverlay(overlay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 }
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
249 hwdata->port = xv_port;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
250 #ifndef NO_SHARED_MEMORY
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 yuvshm = &hwdata->yuvshm;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
252 SDL_memset(yuvshm, 0, sizeof(*yuvshm));
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
253 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
254 0, width, height, yuvshm);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
255 #ifdef PITCH_WORKAROUND
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
256 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
257 /* Ajust overlay width according to pitch */
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
258 pXFree(hwdata->image);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
259 width = hwdata->image->pitches[0] / bpp;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
260 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
261 0, width, height, yuvshm);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
262 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
263 #endif /* PITCH_WORKAROUND */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
264 hwdata->yuv_use_mitshm = (hwdata->image != NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
265 if ( hwdata->yuv_use_mitshm ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
266 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
267 IPC_CREAT | 0777);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
268 if ( yuvshm->shmid >= 0 ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
269 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
270 yuvshm->readOnly = False;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
271 if ( yuvshm->shmaddr != (char *)-1 ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
272 shm_error = False;
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
273 X_handler = pXSetErrorHandler(shm_errhandler);
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
274 pXShmAttach(GFX_Display, yuvshm);
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
275 pXSync(GFX_Display, True);
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
276 pXSetErrorHandler(X_handler);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
277 if ( shm_error )
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
278 shmdt(yuvshm->shmaddr);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
279 } else {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
280 shm_error = True;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
281 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
282 shmctl(yuvshm->shmid, IPC_RMID, NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
283 } else {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
284 shm_error = True;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
285 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
286 if ( shm_error ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
287 pXFree(hwdata->image);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
288 hwdata->yuv_use_mitshm = 0;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
289 } else {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
290 hwdata->image->data = yuvshm->shmaddr;
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 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
293 if ( !hwdata->yuv_use_mitshm )
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
294 #endif /* NO_SHARED_MEMORY */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
295 {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
296 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
297 0, width, height);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 #ifdef PITCH_WORKAROUND
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
300 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
301 /* Ajust overlay width according to pitch */
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
302 pXFree(hwdata->image);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
303 width = hwdata->image->pitches[0] / bpp;
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
304 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
305 0, width, height);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
306 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
307 #endif /* PITCH_WORKAROUND */
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
308 if ( hwdata->image == NULL ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
309 SDL_SetError("Couldn't create XVideo image");
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
310 SDL_FreeYUVOverlay(overlay);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
311 return(NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
312 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
313 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
314 if ( hwdata->image->data == NULL ) {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
315 SDL_OutOfMemory();
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
316 SDL_FreeYUVOverlay(overlay);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
317 return(NULL);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
318 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 /* Find the pitch and offset values for the overlay */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 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
323 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
324 overlay->pixels = (Uint8 **)SDL_malloc(overlay->planes * sizeof(Uint8 *));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 if ( !overlay->pitches || !overlay->pixels ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 SDL_FreeYUVOverlay(overlay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 for ( i=0; i<overlay->planes; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 overlay->pitches[i] = hwdata->image->pitches[i];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 overlay->pixels[i] = (Uint8 *)hwdata->image->data +
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 hwdata->image->offsets[i];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 #ifdef XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 /* Work around an XFree86 X server bug (?)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 We can't perform normal updates in windows that have video
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 being output to them. See SDL_x11image.c for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 X11_DisableAutoRefresh(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 /* We're all done.. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 return(overlay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 int X11_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 struct private_yuvhwdata *hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 hwdata = overlay->hwdata;
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,
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 hwdata->image, 0, 0, overlay->w, overlay->h,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
368 }
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
369 else
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
370 #endif
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
371 {
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
372 SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
373 hwdata->image, 0, 0, overlay->w, overlay->h,
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
374 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
375 }
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
376 pXSync(GFX_Display, False);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 struct private_yuvhwdata *hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 hwdata = overlay->hwdata;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 if ( hwdata ) {
292
eadc0746dfaf Added SDL_LockRect() and SDL_UnlockRect()
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
386 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
387 #ifndef NO_SHARED_MEMORY
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
388 if ( hwdata->yuv_use_mitshm ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
389 pXShmDetach(GFX_Display, &hwdata->yuvshm);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 shmdt(hwdata->yuvshm.shmaddr);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 }
813
6a2c6717b386 Added support for remote XVideo (thanks Frederic!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
392 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 if ( hwdata->image ) {
1168
045f186426e1 Dynamically load X11 libraries like we currently do for alsa, esd, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 950
diff changeset
394 pXFree(hwdata->image);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
396 SDL_free(hwdata);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 if ( overlay->pitches ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
399 SDL_free(overlay->pitches);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 overlay->pitches = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 if ( overlay->pixels ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
403 SDL_free(overlay->pixels);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 overlay->pixels = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 #ifdef XFREE86_REFRESH_HACK
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 X11_EnableAutoRefresh(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
411 #endif /* SDL_VIDEO_DRIVER_X11_XV */