comparison src/video/x11/SDL_x11yuv.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 51038e80ae59
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
43 43
44 /* Workaround when pitch != width */ 44 /* Workaround when pitch != width */
45 #define PITCH_WORKAROUND 45 #define PITCH_WORKAROUND
46 46
47 /* Fix for the NVidia GeForce 2 - use the last available adaptor */ 47 /* Fix for the NVidia GeForce 2 - use the last available adaptor */
48 /*#define USE_LAST_ADAPTOR*/ /* Apparently the NVidia drivers are fixed */ 48 #if 0 /* Apparently the NVidia drivers are fixed */
49 #define USE_LAST_ADAPTOR
50 #endif
49 51
50 /* The functions used to manipulate software video overlays */ 52 /* The functions used to manipulate software video overlays */
51 static struct private_yuvhwfuncs x11_yuvfuncs = { 53 static struct private_yuvhwfuncs x11_yuvfuncs = {
52 X11_LockYUVOverlay, 54 X11_LockYUVOverlay,
53 X11_UnlockYUVOverlay, 55 X11_UnlockYUVOverlay,
54 X11_DisplayYUVOverlay, 56 X11_DisplayYUVOverlay,
55 X11_FreeYUVOverlay 57 X11_FreeYUVOverlay
56 }; 58 };
57 59
58 struct private_yuvhwdata { 60 struct private_yuvhwdata
59 int port; 61 {
60 #ifndef NO_SHARED_MEMORY 62 int port;
61 int yuv_use_mitshm; 63 #ifndef NO_SHARED_MEMORY
62 XShmSegmentInfo yuvshm; 64 int yuv_use_mitshm;
63 #endif 65 XShmSegmentInfo yuvshm;
64 SDL_NAME(XvImage) *image; 66 #endif
67 SDL_NAME(XvImage) * image;
65 }; 68 };
66 69
67 70
68 static int (*X_handler)(Display *, XErrorEvent *) = NULL; 71 static int (*X_handler) (Display *, XErrorEvent *) = NULL;
69 72
70 #ifndef NO_SHARED_MEMORY 73 #ifndef NO_SHARED_MEMORY
71 /* Shared memory error handler routine */ 74 /* Shared memory error handler routine */
72 static int shm_error; 75 static int shm_error;
73 static int shm_errhandler(Display *d, XErrorEvent *e) 76 static int
74 { 77 shm_errhandler(Display * d, XErrorEvent * e)
75 if ( e->error_code == BadAccess ) { 78 {
76 shm_error = True; 79 if (e->error_code == BadAccess) {
77 return(0); 80 shm_error = True;
78 } else 81 return (0);
79 return(X_handler(d,e)); 82 } else
83 return (X_handler(d, e));
80 } 84 }
81 #endif /* !NO_SHARED_MEMORY */ 85 #endif /* !NO_SHARED_MEMORY */
82 86
83 static int xv_error; 87 static int xv_error;
84 static int xv_errhandler(Display *d, XErrorEvent *e) 88 static int
85 { 89 xv_errhandler(Display * d, XErrorEvent * e)
86 if ( e->error_code == BadMatch ) { 90 {
87 xv_error = True; 91 if (e->error_code == BadMatch) {
88 return(0); 92 xv_error = True;
89 } else 93 return (0);
90 return(X_handler(d,e)); 94 } else
91 } 95 return (X_handler(d, e));
92 96 }
93 SDL_Overlay *X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) 97
94 { 98 SDL_Overlay *
95 SDL_Overlay *overlay; 99 X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format,
96 struct private_yuvhwdata *hwdata; 100 SDL_Surface * display)
97 int xv_port; 101 {
98 unsigned int i, j, k; 102 SDL_Overlay *overlay;
99 unsigned int adaptors; 103 struct private_yuvhwdata *hwdata;
100 SDL_NAME(XvAdaptorInfo) *ainfo; 104 int xv_port;
101 int bpp; 105 unsigned int i, j, k;
102 #ifndef NO_SHARED_MEMORY 106 unsigned int adaptors;
103 XShmSegmentInfo *yuvshm; 107 SDL_NAME(XvAdaptorInfo) * ainfo;
104 #endif 108 int bpp;
105 109 #ifndef NO_SHARED_MEMORY
106 /* Look for the XVideo extension with a valid port for this format */ 110 XShmSegmentInfo *yuvshm;
107 xv_port = -1; 111 #endif
108 if ( (Success == SDL_NAME(XvQueryExtension)(GFX_Display, &j, &j, &j, &j, &j)) && 112
109 (Success == SDL_NAME(XvQueryAdaptors)(GFX_Display, 113 /* Look for the XVideo extension with a valid port for this format */
110 RootWindow(GFX_Display, SDL_Screen), 114 xv_port = -1;
111 &adaptors, &ainfo)) ) { 115 if ((Success ==
116 SDL_NAME(XvQueryExtension) (GFX_Display, &j, &j, &j, &j, &j))
117 && (Success ==
118 SDL_NAME(XvQueryAdaptors) (GFX_Display,
119 RootWindow(GFX_Display, SDL_Screen),
120 &adaptors, &ainfo))) {
112 #ifdef USE_LAST_ADAPTOR 121 #ifdef USE_LAST_ADAPTOR
113 for ( i=0; i < adaptors; ++i ) 122 for (i = 0; i < adaptors; ++i)
114 #else 123 #else
115 for ( i=0; (i < adaptors) && (xv_port == -1); ++i ) 124 for (i = 0; (i < adaptors) && (xv_port == -1); ++i)
116 #endif /* USE_LAST_ADAPTOR */ 125 #endif /* USE_LAST_ADAPTOR */
117 { 126 {
118 /* Check to see if the visual can be used */ 127 /* Check to see if the visual can be used */
119 if ( BUGGY_XFREE86(<=, 4001) ) { 128 if (BUGGY_XFREE86(<=, 4001)) {
120 int visual_ok = 0; 129 int visual_ok = 0;
121 for ( j=0; j<ainfo[i].num_formats; ++j ) { 130 for (j = 0; j < ainfo[i].num_formats; ++j) {
122 if ( ainfo[i].formats[j].visual_id == 131 if (ainfo[i].formats[j].visual_id == SDL_Visual->visualid) {
123 SDL_Visual->visualid ) { 132 visual_ok = 1;
124 visual_ok = 1; 133 break;
125 break; 134 }
126 } 135 }
127 } 136 if (!visual_ok) {
128 if ( ! visual_ok ) { 137 continue;
129 continue; 138 }
130 } 139 }
131 } 140 if ((ainfo[i].type & XvInputMask) &&
132 if ( (ainfo[i].type & XvInputMask) && 141 (ainfo[i].type & XvImageMask)) {
133 (ainfo[i].type & XvImageMask) ) { 142 int num_formats;
134 int num_formats; 143 SDL_NAME(XvImageFormatValues) * formats;
135 SDL_NAME(XvImageFormatValues) *formats; 144 formats = SDL_NAME(XvListImageFormats) (GFX_Display,
136 formats = SDL_NAME(XvListImageFormats)(GFX_Display, 145 ainfo[i].
137 ainfo[i].base_id, &num_formats); 146 base_id,
147 &num_formats);
138 #ifdef USE_LAST_ADAPTOR 148 #ifdef USE_LAST_ADAPTOR
139 for ( j=0; j < num_formats; ++j ) 149 for (j = 0; j < num_formats; ++j)
140 #else 150 #else
141 for ( j=0; (j < num_formats) && (xv_port == -1); ++j ) 151 for (j = 0; (j < num_formats) && (xv_port == -1); ++j)
142 #endif /* USE_LAST_ADAPTOR */ 152 #endif /* USE_LAST_ADAPTOR */
143 { 153 {
144 if ( (Uint32)formats[j].id == format ) { 154 if ((Uint32) formats[j].id == format) {
145 for ( k=0; k < ainfo[i].num_ports; ++k ) { 155 for (k = 0; k < ainfo[i].num_ports; ++k) {
146 if ( Success == SDL_NAME(XvGrabPort)(GFX_Display, ainfo[i].base_id+k, CurrentTime) ) { 156 if (Success == SDL_NAME(XvGrabPort)
147 xv_port = ainfo[i].base_id+k; 157 (GFX_Display,
148 break; 158 ainfo[i].base_id + k, CurrentTime)) {
149 } 159 xv_port = ainfo[i].base_id + k;
150 } 160 break;
151 } 161 }
152 } 162 }
153 if ( formats ) { 163 }
154 XFree(formats); 164 }
155 } 165 if (formats) {
156 } 166 XFree(formats);
157 } 167 }
158 SDL_NAME(XvFreeAdaptorInfo)(ainfo); 168 }
159 } 169 }
160 170 SDL_NAME(XvFreeAdaptorInfo) (ainfo);
161 /* Precalculate the bpp for the pitch workaround below */ 171 }
162 switch (format) { 172
163 /* Add any other cases we need to support... */ 173 /* Precalculate the bpp for the pitch workaround below */
164 case SDL_YUY2_OVERLAY: 174 switch (format) {
165 case SDL_UYVY_OVERLAY: 175 /* Add any other cases we need to support... */
166 case SDL_YVYU_OVERLAY: 176 case SDL_YUY2_OVERLAY:
167 bpp = 2; 177 case SDL_UYVY_OVERLAY:
168 break; 178 case SDL_YVYU_OVERLAY:
169 default: 179 bpp = 2;
170 bpp = 1; 180 break;
171 break; 181 default:
172 } 182 bpp = 1;
183 break;
184 }
173 185
174 #if 0 186 #if 0
175 /* 187 /*
176 * !!! FIXME: 188 * !!! FIXME:
177 * "Here are some diffs for X11 and yuv. Note that the last part 2nd 189 * "Here are some diffs for X11 and yuv. Note that the last part 2nd
180 * 192 *
181 * ACHTUNG: This is broken! It looks like XvFreeAdaptorInfo does this 193 * ACHTUNG: This is broken! It looks like XvFreeAdaptorInfo does this
182 * for you, so we end up with a double-free. I need to look at this 194 * for you, so we end up with a double-free. I need to look at this
183 * more closely... --ryan. 195 * more closely... --ryan.
184 */ 196 */
185 for ( i=0; i < adaptors; ++i ) { 197 for (i = 0; i < adaptors; ++i) {
186 if (ainfo[i].name != NULL) Xfree(ainfo[i].name); 198 if (ainfo[i].name != NULL)
187 if (ainfo[i].formats != NULL) Xfree(ainfo[i].formats); 199 Xfree(ainfo[i].name);
188 } 200 if (ainfo[i].formats != NULL)
189 Xfree(ainfo); 201 Xfree(ainfo[i].formats);
190 #endif 202 }
191 203 Xfree(ainfo);
192 if ( xv_port == -1 ) { 204 #endif
193 SDL_SetError("No available video ports for requested format"); 205
194 return(NULL); 206 if (xv_port == -1) {
195 } 207 SDL_SetError("No available video ports for requested format");
196 208 return (NULL);
197 /* Enable auto-painting of the overlay colorkey */ 209 }
198 { 210
199 static const char *attr[] = { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" }; 211 /* Enable auto-painting of the overlay colorkey */
200 unsigned int i; 212 {
201 213 static const char *attr[] =
202 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True); 214 { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" };
203 X_handler = XSetErrorHandler(xv_errhandler); 215 unsigned int i;
204 for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) { 216
205 Atom a; 217 SDL_NAME(XvSelectPortNotify) (GFX_Display, xv_port, True);
206 218 X_handler = XSetErrorHandler(xv_errhandler);
207 xv_error = False; 219 for (i = 0; i < sizeof(attr) / (sizeof attr[0]); ++i) {
208 a = XInternAtom(GFX_Display, attr[i], True); 220 Atom a;
209 if ( a != None ) { 221
210 SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1); 222 xv_error = False;
211 XSync(GFX_Display, True); 223 a = XInternAtom(GFX_Display, attr[i], True);
212 if ( ! xv_error ) { 224 if (a != None) {
213 break; 225 SDL_NAME(XvSetPortAttribute) (GFX_Display, xv_port, a, 1);
214 } 226 XSync(GFX_Display, True);
215 } 227 if (!xv_error) {
216 } 228 break;
217 XSetErrorHandler(X_handler); 229 }
218 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False); 230 }
219 } 231 }
220 232 XSetErrorHandler(X_handler);
221 /* Create the overlay structure */ 233 SDL_NAME(XvSelectPortNotify) (GFX_Display, xv_port, False);
222 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay); 234 }
223 if ( overlay == NULL ) { 235
224 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime); 236 /* Create the overlay structure */
225 SDL_OutOfMemory(); 237 overlay = (SDL_Overlay *) SDL_malloc(sizeof *overlay);
226 return(NULL); 238 if (overlay == NULL) {
227 } 239 SDL_NAME(XvUngrabPort) (GFX_Display, xv_port, CurrentTime);
228 SDL_memset(overlay, 0, (sizeof *overlay)); 240 SDL_OutOfMemory();
229 241 return (NULL);
230 /* Fill in the basic members */ 242 }
231 overlay->format = format; 243 SDL_memset(overlay, 0, (sizeof *overlay));
232 overlay->w = width; 244
233 overlay->h = height; 245 /* Fill in the basic members */
234 246 overlay->format = format;
235 /* Set up the YUV surface function structure */ 247 overlay->w = width;
236 overlay->hwfuncs = &x11_yuvfuncs; 248 overlay->h = height;
237 overlay->hw_overlay = 1; 249
238 250 /* Set up the YUV surface function structure */
239 /* Create the pixel data and lookup tables */ 251 overlay->hwfuncs = &x11_yuvfuncs;
240 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata); 252 overlay->hw_overlay = 1;
241 overlay->hwdata = hwdata; 253
242 if ( hwdata == NULL ) { 254 /* Create the pixel data and lookup tables */
243 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime); 255 hwdata = (struct private_yuvhwdata *) SDL_malloc(sizeof *hwdata);
244 SDL_OutOfMemory(); 256 overlay->hwdata = hwdata;
245 SDL_FreeYUVOverlay(overlay); 257 if (hwdata == NULL) {
246 return(NULL); 258 SDL_NAME(XvUngrabPort) (GFX_Display, xv_port, CurrentTime);
247 } 259 SDL_OutOfMemory();
248 hwdata->port = xv_port; 260 SDL_FreeYUVOverlay(overlay);
249 #ifndef NO_SHARED_MEMORY 261 return (NULL);
250 yuvshm = &hwdata->yuvshm; 262 }
251 SDL_memset(yuvshm, 0, sizeof(*yuvshm)); 263 hwdata->port = xv_port;
252 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format, 264 #ifndef NO_SHARED_MEMORY
253 0, width, height, yuvshm); 265 yuvshm = &hwdata->yuvshm;
266 SDL_memset(yuvshm, 0, sizeof(*yuvshm));
267 hwdata->image = SDL_NAME(XvShmCreateImage) (GFX_Display, xv_port, format,
268 0, width, height, yuvshm);
254 #ifdef PITCH_WORKAROUND 269 #ifdef PITCH_WORKAROUND
255 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) { 270 if (hwdata->image != NULL && hwdata->image->pitches[0] != (width * bpp)) {
256 /* Ajust overlay width according to pitch */ 271 /* Ajust overlay width according to pitch */
257 XFree(hwdata->image); 272 XFree(hwdata->image);
258 width = hwdata->image->pitches[0] / bpp; 273 width = hwdata->image->pitches[0] / bpp;
259 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format, 274 hwdata->image =
260 0, width, height, yuvshm); 275 SDL_NAME(XvShmCreateImage) (GFX_Display, xv_port, format, 0,
261 } 276 width, height, yuvshm);
277 }
262 #endif /* PITCH_WORKAROUND */ 278 #endif /* PITCH_WORKAROUND */
263 hwdata->yuv_use_mitshm = (hwdata->image != NULL); 279 hwdata->yuv_use_mitshm = (hwdata->image != NULL);
264 if ( hwdata->yuv_use_mitshm ) { 280 if (hwdata->yuv_use_mitshm) {
265 yuvshm->shmid = shmget(IPC_PRIVATE, hwdata->image->data_size, 281 yuvshm->shmid = shmget(IPC_PRIVATE, hwdata->image->data_size,
266 IPC_CREAT | 0777); 282 IPC_CREAT | 0777);
267 if ( yuvshm->shmid >= 0 ) { 283 if (yuvshm->shmid >= 0) {
268 yuvshm->shmaddr = (char *)shmat(yuvshm->shmid, 0, 0); 284 yuvshm->shmaddr = (char *) shmat(yuvshm->shmid, 0, 0);
269 yuvshm->readOnly = False; 285 yuvshm->readOnly = False;
270 if ( yuvshm->shmaddr != (char *)-1 ) { 286 if (yuvshm->shmaddr != (char *) -1) {
271 shm_error = False; 287 shm_error = False;
272 X_handler = XSetErrorHandler(shm_errhandler); 288 X_handler = XSetErrorHandler(shm_errhandler);
273 XShmAttach(GFX_Display, yuvshm); 289 XShmAttach(GFX_Display, yuvshm);
274 XSync(GFX_Display, True); 290 XSync(GFX_Display, True);
275 XSetErrorHandler(X_handler); 291 XSetErrorHandler(X_handler);
276 if ( shm_error ) 292 if (shm_error)
277 shmdt(yuvshm->shmaddr); 293 shmdt(yuvshm->shmaddr);
278 } else { 294 } else {
279 shm_error = True; 295 shm_error = True;
280 } 296 }
281 shmctl(yuvshm->shmid, IPC_RMID, NULL); 297 shmctl(yuvshm->shmid, IPC_RMID, NULL);
282 } else { 298 } else {
283 shm_error = True; 299 shm_error = True;
284 } 300 }
285 if ( shm_error ) { 301 if (shm_error) {
286 XFree(hwdata->image); 302 XFree(hwdata->image);
287 hwdata->yuv_use_mitshm = 0; 303 hwdata->yuv_use_mitshm = 0;
288 } else { 304 } else {
289 hwdata->image->data = yuvshm->shmaddr; 305 hwdata->image->data = yuvshm->shmaddr;
290 } 306 }
291 } 307 }
292 if ( !hwdata->yuv_use_mitshm ) 308 if (!hwdata->yuv_use_mitshm)
293 #endif /* NO_SHARED_MEMORY */ 309 #endif /* NO_SHARED_MEMORY */
294 { 310 {
295 hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format, 311 hwdata->image =
296 0, width, height); 312 SDL_NAME(XvCreateImage) (GFX_Display, xv_port, format, 0,
313 width, height);
297 314
298 #ifdef PITCH_WORKAROUND 315 #ifdef PITCH_WORKAROUND
299 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) { 316 if (hwdata->image != NULL
300 /* Ajust overlay width according to pitch */ 317 && hwdata->image->pitches[0] != (width * bpp)) {
301 XFree(hwdata->image); 318 /* Ajust overlay width according to pitch */
302 width = hwdata->image->pitches[0] / bpp; 319 XFree(hwdata->image);
303 hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format, 320 width = hwdata->image->pitches[0] / bpp;
304 0, width, height); 321 hwdata->image =
305 } 322 SDL_NAME(XvCreateImage) (GFX_Display, xv_port, format, 0,
323 width, height);
324 }
306 #endif /* PITCH_WORKAROUND */ 325 #endif /* PITCH_WORKAROUND */
307 if ( hwdata->image == NULL ) { 326 if (hwdata->image == NULL) {
308 SDL_SetError("Couldn't create XVideo image"); 327 SDL_SetError("Couldn't create XVideo image");
309 SDL_FreeYUVOverlay(overlay); 328 SDL_FreeYUVOverlay(overlay);
310 return(NULL); 329 return (NULL);
311 } 330 }
312 hwdata->image->data = SDL_malloc(hwdata->image->data_size); 331 hwdata->image->data = SDL_malloc(hwdata->image->data_size);
313 if ( hwdata->image->data == NULL ) { 332 if (hwdata->image->data == NULL) {
314 SDL_OutOfMemory(); 333 SDL_OutOfMemory();
315 SDL_FreeYUVOverlay(overlay); 334 SDL_FreeYUVOverlay(overlay);
316 return(NULL); 335 return (NULL);
317 } 336 }
318 } 337 }
319 338
320 /* Find the pitch and offset values for the overlay */ 339 /* Find the pitch and offset values for the overlay */
321 overlay->planes = hwdata->image->num_planes; 340 overlay->planes = hwdata->image->num_planes;
322 overlay->pitches = (Uint16 *)SDL_malloc(overlay->planes * sizeof(Uint16)); 341 overlay->pitches =
323 overlay->pixels = (Uint8 **)SDL_malloc(overlay->planes * sizeof(Uint8 *)); 342 (Uint16 *) SDL_malloc(overlay->planes * sizeof(Uint16));
324 if ( !overlay->pitches || !overlay->pixels ) { 343 overlay->pixels =
325 SDL_OutOfMemory(); 344 (Uint8 **) SDL_malloc(overlay->planes * sizeof(Uint8 *));
326 SDL_FreeYUVOverlay(overlay); 345 if (!overlay->pitches || !overlay->pixels) {
327 return(NULL); 346 SDL_OutOfMemory();
328 } 347 SDL_FreeYUVOverlay(overlay);
329 for ( i=0; i<overlay->planes; ++i ) { 348 return (NULL);
330 overlay->pitches[i] = hwdata->image->pitches[i]; 349 }
331 overlay->pixels[i] = (Uint8 *)hwdata->image->data + 350 for (i = 0; i < overlay->planes; ++i) {
332 hwdata->image->offsets[i]; 351 overlay->pitches[i] = hwdata->image->pitches[i];
333 } 352 overlay->pixels[i] = (Uint8 *) hwdata->image->data +
353 hwdata->image->offsets[i];
354 }
334 355
335 #ifdef XFREE86_REFRESH_HACK 356 #ifdef XFREE86_REFRESH_HACK
336 /* Work around an XFree86 X server bug (?) 357 /* Work around an XFree86 X server bug (?)
337 We can't perform normal updates in windows that have video 358 We can't perform normal updates in windows that have video
338 being output to them. See SDL_x11image.c for more details. 359 being output to them. See SDL_x11image.c for more details.
339 */ 360 */
340 X11_DisableAutoRefresh(this); 361 X11_DisableAutoRefresh(this);
341 #endif 362 #endif
342 363
343 /* We're all done.. */ 364 /* We're all done.. */
344 return(overlay); 365 return (overlay);
345 } 366 }
346 367
347 int X11_LockYUVOverlay(_THIS, SDL_Overlay *overlay) 368 int
348 { 369 X11_LockYUVOverlay(_THIS, SDL_Overlay * overlay)
349 return(0); 370 {
350 } 371 return (0);
351 372 }
352 void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) 373
353 { 374 void
354 return; 375 X11_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay)
355 } 376 {
356 377 return;
357 int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) 378 }
358 { 379
359 struct private_yuvhwdata *hwdata; 380 int
360 381 X11_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
361 hwdata = overlay->hwdata; 382 SDL_Rect * dst)
362 383 {
363 #ifndef NO_SHARED_MEMORY 384 struct private_yuvhwdata *hwdata;
364 if ( hwdata->yuv_use_mitshm ) { 385
365 SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC, 386 hwdata = overlay->hwdata;
366 hwdata->image, 387
367 src->x, src->y, src->w, src->h, 388 #ifndef NO_SHARED_MEMORY
368 dst->x, dst->y, dst->w, dst->h, False); 389 if (hwdata->yuv_use_mitshm) {
369 } 390 SDL_NAME(XvShmPutImage) (GFX_Display, hwdata->port, SDL_Window,
370 else 391 SDL_GC, hwdata->image, src->x, src->y,
371 #endif 392 src->w, src->h, dst->x, dst->y, dst->w,
372 { 393 dst->h, False);
373 SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC, 394 } else
374 hwdata->image, 395 #endif
375 src->x, src->y, src->w, src->h, 396 {
376 dst->x, dst->y, dst->w, dst->h); 397 SDL_NAME(XvPutImage) (GFX_Display, hwdata->port, SDL_Window,
377 } 398 SDL_GC, hwdata->image, src->x, src->y,
378 XSync(GFX_Display, False); 399 src->w, src->h, dst->x, dst->y, dst->w, dst->h);
379 return(0); 400 }
380 } 401 XSync(GFX_Display, False);
381 402 return (0);
382 void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) 403 }
383 { 404
384 struct private_yuvhwdata *hwdata; 405 void
385 406 X11_FreeYUVOverlay(_THIS, SDL_Overlay * overlay)
386 hwdata = overlay->hwdata; 407 {
387 if ( hwdata ) { 408 struct private_yuvhwdata *hwdata;
388 SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime); 409
389 #ifndef NO_SHARED_MEMORY 410 hwdata = overlay->hwdata;
390 if ( hwdata->yuv_use_mitshm ) { 411 if (hwdata) {
391 XShmDetach(GFX_Display, &hwdata->yuvshm); 412 SDL_NAME(XvUngrabPort) (GFX_Display, hwdata->port, CurrentTime);
392 shmdt(hwdata->yuvshm.shmaddr); 413 #ifndef NO_SHARED_MEMORY
393 } 414 if (hwdata->yuv_use_mitshm) {
394 #endif 415 XShmDetach(GFX_Display, &hwdata->yuvshm);
395 if ( hwdata->image ) { 416 shmdt(hwdata->yuvshm.shmaddr);
396 XFree(hwdata->image); 417 }
397 } 418 #endif
398 SDL_free(hwdata); 419 if (hwdata->image) {
399 } 420 XFree(hwdata->image);
400 if ( overlay->pitches ) { 421 }
401 SDL_free(overlay->pitches); 422 SDL_free(hwdata);
402 overlay->pitches = NULL; 423 }
403 } 424 if (overlay->pitches) {
404 if ( overlay->pixels ) { 425 SDL_free(overlay->pitches);
405 SDL_free(overlay->pixels); 426 overlay->pitches = NULL;
406 overlay->pixels = NULL; 427 }
407 } 428 if (overlay->pixels) {
429 SDL_free(overlay->pixels);
430 overlay->pixels = NULL;
431 }
408 #ifdef XFREE86_REFRESH_HACK 432 #ifdef XFREE86_REFRESH_HACK
409 X11_EnableAutoRefresh(this); 433 X11_EnableAutoRefresh(this);
410 #endif 434 #endif
411 } 435 }
412 436
413 #endif /* SDL_VIDEO_DRIVER_X11_XV */ 437 #endif /* SDL_VIDEO_DRIVER_X11_XV */
438 /* vi: set ts=4 sw=4 expandtab: */