annotate src/video/x11/SDL_x11yuv.c @ 1314:2b3ebc327017

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