comparison src/video/x11/SDL_x11yuv.c @ 1168:045f186426e1

Dynamically load X11 libraries like we currently do for alsa, esd, etc. This allows you to run an SDL program on a system without Xlib, since it'll just report the x11 target unavailable at runtime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 05 Nov 2005 19:53:37 +0000
parents b7a5c1b64829
children b81f54c3963f
comparison
equal deleted inserted replaced
1167:435c2e481299 1168:045f186426e1
157 } 157 }
158 } 158 }
159 } 159 }
160 } 160 }
161 if ( formats ) { 161 if ( formats ) {
162 XFree(formats); 162 pXFree(formats);
163 } 163 }
164 } 164 }
165 } 165 }
166 SDL_NAME(XvFreeAdaptorInfo)(ainfo); 166 SDL_NAME(XvFreeAdaptorInfo)(ainfo);
167 } 167 }
206 { 206 {
207 static const char *attr[] = { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" }; 207 static const char *attr[] = { "XV_AUTOPAINT_COLORKEY", "XV_AUTOPAINT_COLOURKEY" };
208 unsigned int i; 208 unsigned int i;
209 209
210 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True); 210 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True);
211 X_handler = XSetErrorHandler(xv_errhandler); 211 X_handler = pXSetErrorHandler(xv_errhandler);
212 for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) { 212 for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) {
213 Atom a; 213 Atom a;
214 214
215 xv_error = False; 215 xv_error = False;
216 a = XInternAtom(GFX_Display, attr[i], True); 216 a = pXInternAtom(GFX_Display, attr[i], True);
217 if ( a != None ) { 217 if ( a != None ) {
218 SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1); 218 SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1);
219 XSync(GFX_Display, True); 219 pXSync(GFX_Display, True);
220 if ( ! xv_error ) { 220 if ( ! xv_error ) {
221 break; 221 break;
222 } 222 }
223 } 223 }
224 } 224 }
225 XSetErrorHandler(X_handler); 225 pXSetErrorHandler(X_handler);
226 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False); 226 SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False);
227 } 227 }
228 228
229 /* Create the overlay structure */ 229 /* Create the overlay structure */
230 overlay = (SDL_Overlay *)malloc(sizeof *overlay); 230 overlay = (SDL_Overlay *)malloc(sizeof *overlay);
260 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format, 260 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
261 0, width, height, yuvshm); 261 0, width, height, yuvshm);
262 #ifdef PITCH_WORKAROUND 262 #ifdef PITCH_WORKAROUND
263 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) { 263 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
264 /* Ajust overlay width according to pitch */ 264 /* Ajust overlay width according to pitch */
265 XFree(hwdata->image); 265 pXFree(hwdata->image);
266 width = hwdata->image->pitches[0] / bpp; 266 width = hwdata->image->pitches[0] / bpp;
267 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format, 267 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
268 0, width, height, yuvshm); 268 0, width, height, yuvshm);
269 } 269 }
270 #endif /* PITCH_WORKAROUND */ 270 #endif /* PITCH_WORKAROUND */
275 if ( yuvshm->shmid >= 0 ) { 275 if ( yuvshm->shmid >= 0 ) {
276 yuvshm->shmaddr = (char *)shmat(yuvshm->shmid, 0, 0); 276 yuvshm->shmaddr = (char *)shmat(yuvshm->shmid, 0, 0);
277 yuvshm->readOnly = False; 277 yuvshm->readOnly = False;
278 if ( yuvshm->shmaddr != (char *)-1 ) { 278 if ( yuvshm->shmaddr != (char *)-1 ) {
279 shm_error = False; 279 shm_error = False;
280 X_handler = XSetErrorHandler(shm_errhandler); 280 X_handler = pXSetErrorHandler(shm_errhandler);
281 XShmAttach(GFX_Display, yuvshm); 281 pXShmAttach(GFX_Display, yuvshm);
282 XSync(GFX_Display, True); 282 pXSync(GFX_Display, True);
283 XSetErrorHandler(X_handler); 283 pXSetErrorHandler(X_handler);
284 if ( shm_error ) 284 if ( shm_error )
285 shmdt(yuvshm->shmaddr); 285 shmdt(yuvshm->shmaddr);
286 } else { 286 } else {
287 shm_error = True; 287 shm_error = True;
288 } 288 }
289 shmctl(yuvshm->shmid, IPC_RMID, NULL); 289 shmctl(yuvshm->shmid, IPC_RMID, NULL);
290 } else { 290 } else {
291 shm_error = True; 291 shm_error = True;
292 } 292 }
293 if ( shm_error ) { 293 if ( shm_error ) {
294 XFree(hwdata->image); 294 pXFree(hwdata->image);
295 hwdata->yuv_use_mitshm = 0; 295 hwdata->yuv_use_mitshm = 0;
296 } else { 296 } else {
297 hwdata->image->data = yuvshm->shmaddr; 297 hwdata->image->data = yuvshm->shmaddr;
298 } 298 }
299 } 299 }
304 0, width, height); 304 0, width, height);
305 305
306 #ifdef PITCH_WORKAROUND 306 #ifdef PITCH_WORKAROUND
307 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) { 307 if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
308 /* Ajust overlay width according to pitch */ 308 /* Ajust overlay width according to pitch */
309 XFree(hwdata->image); 309 pXFree(hwdata->image);
310 width = hwdata->image->pitches[0] / bpp; 310 width = hwdata->image->pitches[0] / bpp;
311 hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format, 311 hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format,
312 0, width, height); 312 0, width, height);
313 } 313 }
314 #endif /* PITCH_WORKAROUND */ 314 #endif /* PITCH_WORKAROUND */
378 { 378 {
379 SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC, 379 SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
380 hwdata->image, 0, 0, overlay->w, overlay->h, 380 hwdata->image, 0, 0, overlay->w, overlay->h,
381 dstrect->x, dstrect->y, dstrect->w, dstrect->h); 381 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
382 } 382 }
383 XSync(GFX_Display, False); 383 pXSync(GFX_Display, False);
384 return(0); 384 return(0);
385 } 385 }
386 386
387 void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) 387 void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
388 { 388 {
391 hwdata = overlay->hwdata; 391 hwdata = overlay->hwdata;
392 if ( hwdata ) { 392 if ( hwdata ) {
393 SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime); 393 SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime);
394 #ifndef NO_SHARED_MEMORY 394 #ifndef NO_SHARED_MEMORY
395 if ( hwdata->yuv_use_mitshm ) { 395 if ( hwdata->yuv_use_mitshm ) {
396 XShmDetach(GFX_Display, &hwdata->yuvshm); 396 pXShmDetach(GFX_Display, &hwdata->yuvshm);
397 shmdt(hwdata->yuvshm.shmaddr); 397 shmdt(hwdata->yuvshm.shmaddr);
398 } 398 }
399 #endif 399 #endif
400 if ( hwdata->image ) { 400 if ( hwdata->image ) {
401 XFree(hwdata->image); 401 pXFree(hwdata->image);
402 } 402 }
403 free(hwdata); 403 free(hwdata);
404 } 404 }
405 if ( overlay->pitches ) { 405 if ( overlay->pitches ) {
406 free(overlay->pitches); 406 free(overlay->pitches);