comparison src/video/x11/SDL_x11yuv.c @ 292:eadc0746dfaf

Added SDL_LockRect() and SDL_UnlockRect() Incorporated XFree86 extension libraries into the source
author Sam Lantinga <slouken@libsdl.org>
date Tue, 05 Mar 2002 19:55:32 +0000
parents e8157fcb3114
children f6ffac90895c
comparison
equal deleted inserted replaced
291:68a8a8237c09 292:eadc0746dfaf
33 #include <string.h> 33 #include <string.h>
34 #include <X11/Xlib.h> 34 #include <X11/Xlib.h>
35 #include <sys/ipc.h> 35 #include <sys/ipc.h>
36 #include <sys/shm.h> 36 #include <sys/shm.h>
37 #include <X11/extensions/XShm.h> 37 #include <X11/extensions/XShm.h>
38 #include <X11/extensions/Xvlib.h> 38 #include <XFree86/extensions/Xvlib.h>
39 39
40 #include "SDL_error.h" 40 #include "SDL_error.h"
41 #include "SDL_video.h" 41 #include "SDL_video.h"
42 #include "SDL_x11yuv_c.h" 42 #include "SDL_x11yuv_c.h"
43 #include "SDL_yuvfuncs.h" 43 #include "SDL_yuvfuncs.h"
62 }; 62 };
63 63
64 struct private_yuvhwdata { 64 struct private_yuvhwdata {
65 int port; 65 int port;
66 XShmSegmentInfo yuvshm; 66 XShmSegmentInfo yuvshm;
67 XvImage *image; 67 SDL_NAME(XvImage) *image;
68 }; 68 };
69 69
70 70
71 SDL_Overlay *X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) 71 SDL_Overlay *X11_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
72 { 72 {
73 SDL_Overlay *overlay; 73 SDL_Overlay *overlay;
74 struct private_yuvhwdata *hwdata; 74 struct private_yuvhwdata *hwdata;
75 int xv_port; 75 int xv_port;
76 int i, j, k; 76 int i, j, k;
77 int adaptors; 77 int adaptors;
78 XvAdaptorInfo *ainfo; 78 SDL_NAME(XvAdaptorInfo) *ainfo;
79 XShmSegmentInfo *yuvshm; 79 XShmSegmentInfo *yuvshm;
80 80
81 /* Look for the XVideo extension with a valid port for this format */ 81 /* Look for the XVideo extension with a valid port for this format */
82 xv_port = -1; 82 xv_port = -1;
83 if ( (Success == XvQueryExtension(GFX_Display, &j, &j, &j, &j, &j)) && 83 if ( (Success == SDL_NAME(XvQueryExtension)(GFX_Display, &j, &j, &j, &j, &j)) &&
84 (Success == XvQueryAdaptors(GFX_Display, 84 (Success == SDL_NAME(XvQueryAdaptors)(GFX_Display,
85 RootWindow(GFX_Display, SDL_Screen), 85 RootWindow(GFX_Display, SDL_Screen),
86 &adaptors, &ainfo)) ) { 86 &adaptors, &ainfo)) ) {
87 #ifdef USE_LAST_ADAPTOR 87 #ifdef USE_LAST_ADAPTOR
88 for ( i=0; i < adaptors; ++i ) { 88 for ( i=0; i < adaptors; ++i ) {
89 #else 89 #else
104 } 104 }
105 } 105 }
106 if ( (ainfo[i].type & XvInputMask) && 106 if ( (ainfo[i].type & XvInputMask) &&
107 (ainfo[i].type & XvImageMask) ) { 107 (ainfo[i].type & XvImageMask) ) {
108 int num_formats; 108 int num_formats;
109 XvImageFormatValues *formats; 109 SDL_NAME(XvImageFormatValues) *formats;
110 formats = XvListImageFormats(GFX_Display, 110 formats = SDL_NAME(XvListImageFormats)(GFX_Display,
111 ainfo[i].base_id, &num_formats); 111 ainfo[i].base_id, &num_formats);
112 #ifdef USE_LAST_ADAPTOR 112 #ifdef USE_LAST_ADAPTOR
113 for ( j=0; j < num_formats; ++j ) { 113 for ( j=0; j < num_formats; ++j ) {
114 #else 114 #else
115 for ( j=0; (j < num_formats) && (xv_port == -1); ++j ) { 115 for ( j=0; (j < num_formats) && (xv_port == -1); ++j ) {
116 #endif /* USE_LAST_ADAPTOR */ 116 #endif /* USE_LAST_ADAPTOR */
117 if ( (Uint32)formats[j].id == format ) { 117 if ( (Uint32)formats[j].id == format ) {
118 for ( k=0; k < ainfo[i].num_ports; ++k ) { 118 for ( k=0; k < ainfo[i].num_ports; ++k ) {
119 if ( Success == XvGrabPort(GFX_Display, ainfo[i].base_id+k, CurrentTime) ) { 119 if ( Success == SDL_NAME(XvGrabPort)(GFX_Display, ainfo[i].base_id+k, CurrentTime) ) {
120 xv_port = ainfo[i].base_id+k; 120 xv_port = ainfo[i].base_id+k;
121 break; 121 break;
122 } 122 }
123 } 123 }
124 } 124 }
132 } 132 }
133 133
134 /* Create the overlay structure */ 134 /* Create the overlay structure */
135 overlay = (SDL_Overlay *)malloc(sizeof *overlay); 135 overlay = (SDL_Overlay *)malloc(sizeof *overlay);
136 if ( overlay == NULL ) { 136 if ( overlay == NULL ) {
137 XvUngrabPort(GFX_Display, xv_port, CurrentTime); 137 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
138 SDL_OutOfMemory(); 138 SDL_OutOfMemory();
139 return(NULL); 139 return(NULL);
140 } 140 }
141 memset(overlay, 0, (sizeof *overlay)); 141 memset(overlay, 0, (sizeof *overlay));
142 142
151 151
152 /* Create the pixel data and lookup tables */ 152 /* Create the pixel data and lookup tables */
153 hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata); 153 hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata);
154 overlay->hwdata = hwdata; 154 overlay->hwdata = hwdata;
155 if ( hwdata == NULL ) { 155 if ( hwdata == NULL ) {
156 XvUngrabPort(GFX_Display, xv_port, CurrentTime); 156 SDL_NAME(XvUngrabPort)(GFX_Display, xv_port, CurrentTime);
157 SDL_OutOfMemory(); 157 SDL_OutOfMemory();
158 SDL_FreeYUVOverlay(overlay); 158 SDL_FreeYUVOverlay(overlay);
159 return(NULL); 159 return(NULL);
160 } 160 }
161 yuvshm = &hwdata->yuvshm; 161 yuvshm = &hwdata->yuvshm;
162 memset(yuvshm, 0, sizeof(*yuvshm)); 162 memset(yuvshm, 0, sizeof(*yuvshm));
163 hwdata->port = xv_port; 163 hwdata->port = xv_port;
164 hwdata->image = XvShmCreateImage(GFX_Display, xv_port, format, 164 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
165 0, width, height, yuvshm); 165 0, width, height, yuvshm);
166 166
167 #ifdef PITCH_WORKAROUND 167 #ifdef PITCH_WORKAROUND
168 if ( hwdata->image != NULL && hwdata->image->pitches[0] != width ) 168 if ( hwdata->image != NULL && hwdata->image->pitches[0] != width )
169 { 169 {
182 /* We should never get here (caught above) */ 182 /* We should never get here (caught above) */
183 return(NULL); 183 return(NULL);
184 } 184 }
185 185
186 XFree(hwdata->image); 186 XFree(hwdata->image);
187 hwdata->image = XvShmCreateImage(GFX_Display, xv_port, format, 187 hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
188 0, width, height, yuvshm); 188 0, width, height, yuvshm);
189 } 189 }
190 #endif 190 #endif
191 191
192 if ( hwdata->image == NULL ) { 192 if ( hwdata->image == NULL ) {
250 int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) 250 int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
251 { 251 {
252 struct private_yuvhwdata *hwdata; 252 struct private_yuvhwdata *hwdata;
253 253
254 hwdata = overlay->hwdata; 254 hwdata = overlay->hwdata;
255 XvShmPutImage(GFX_Display, hwdata->port, SDL_Window, SDL_GC, 255 SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
256 hwdata->image, 0, 0, overlay->w, overlay->h, 256 hwdata->image, 0, 0, overlay->w, overlay->h,
257 dstrect->x, dstrect->y, dstrect->w, dstrect->h, False); 257 dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);
258 XSync(GFX_Display, False); 258 XSync(GFX_Display, False);
259 return(0); 259 return(0);
260 } 260 }
263 { 263 {
264 struct private_yuvhwdata *hwdata; 264 struct private_yuvhwdata *hwdata;
265 265
266 hwdata = overlay->hwdata; 266 hwdata = overlay->hwdata;
267 if ( hwdata ) { 267 if ( hwdata ) {
268 XvUngrabPort(GFX_Display, hwdata->port, CurrentTime); 268 SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime);
269 if ( hwdata->yuvshm.shmaddr ) { 269 if ( hwdata->yuvshm.shmaddr ) {
270 XShmDetach(GFX_Display, &hwdata->yuvshm); 270 XShmDetach(GFX_Display, &hwdata->yuvshm);
271 shmdt(hwdata->yuvshm.shmaddr); 271 shmdt(hwdata->yuvshm.shmaddr);
272 } 272 }
273 if ( hwdata->image ) { 273 if ( hwdata->image ) {