Mercurial > mplayer.hg
annotate libvo/vo_gl.c @ 8240:5a9cac1cbbf1
10l
author | diego |
---|---|
date | Wed, 20 Nov 2002 21:28:08 +0000 |
parents | 5b39e79af5fe |
children | 2c4cebb8637d |
rev | line source |
---|---|
1 | 1 #define DISP |
2 | |
3 // this can be 3 or 4 (regarding 24bpp and 32bpp) | |
4 #define BYTES_PP 3 | |
5 | |
6 #define TEXTUREFORMAT_32BPP | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <math.h> | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
12 #include <errno.h> |
1 | 13 |
14 #include "config.h" | |
15 #include "video_out.h" | |
16 #include "video_out_internal.h" | |
17 | |
18 #include <X11/Xlib.h> | |
19 #include <X11/Xutil.h> | |
20 //#include <X11/keysym.h> | |
21 #include <GL/glx.h> | |
22 #include <errno.h> | |
2732 | 23 #include "../postproc/rgb2rgb.h" |
1 | 24 |
25 #include <GL/gl.h> | |
26 | |
31 | 27 #include "x11_common.h" |
2057 | 28 #include "aspect.h" |
31 | 29 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
30 static vo_info_t info = |
1 | 31 { |
32 "X11 (OpenGL)", | |
33 "gl", | |
34 "Arpad Gereoffy <arpi@esp-team.scene.hu>", | |
35 "" | |
36 }; | |
37 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
38 LIBVO_EXTERN(gl) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7931
diff
changeset
|
39 |
1 | 40 /* local data */ |
41 static unsigned char *ImageData=NULL; | |
42 | |
43 static GLXContext wsGLXContext; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
44 static int wsGLXAttrib[] = { GLX_RGBA, |
1 | 45 GLX_RED_SIZE,1, |
46 GLX_GREEN_SIZE,1, | |
47 GLX_BLUE_SIZE,1, | |
48 GLX_DOUBLEBUFFER, | |
49 None }; | |
50 | |
51 | |
52 static uint32_t image_width; | |
53 static uint32_t image_height; | |
54 static uint32_t image_format; | |
55 static uint32_t image_bpp; | |
56 static uint32_t image_bytes; | |
57 | |
58 static uint32_t texture_width; | |
59 static uint32_t texture_height; | |
60 | |
612 | 61 static void resize(int x,int y){ |
1290 | 62 printf("[gl] Resize: %dx%d\n",x,y); |
1 | 63 glViewport( 0, 0, x, y ); |
64 | |
65 glMatrixMode(GL_PROJECTION); | |
66 glLoadIdentity(); | |
67 glOrtho(0, image_width, image_height, 0, -1,1); | |
68 | |
69 glMatrixMode(GL_MODELVIEW); | |
70 glLoadIdentity(); | |
71 } | |
72 | |
73 /* connect to server, create and map window, | |
74 * allocate colors and (shared) memory | |
75 */ | |
76 static uint32_t | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
7111
diff
changeset
|
77 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
1 | 78 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
79 // int screen; |
1 | 80 unsigned int fg, bg; |
81 char *hello = (title == NULL) ? "OpenGL rulez" : title; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
82 // char *name = ":0.0"; |
1 | 83 XSizeHints hint; |
84 XVisualInfo *vinfo; | |
85 XEvent xev; | |
86 | |
1109 | 87 // XGCValues xgcv; |
1 | 88 XSetWindowAttributes xswa; |
89 unsigned long xswamask; | |
90 | |
91 image_height = height; | |
92 image_width = width; | |
93 image_format = format; | |
94 | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
95 aspect_save_orig(width,height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
96 aspect_save_prescale(d_width,d_height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
97 aspect_save_screenres(vo_screenwidth,vo_screenheight); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
98 |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
99 aspect(&d_width,&d_height,A_NOZOOM); |
2040 | 100 #ifdef X11_FULLSCREEN |
6095 | 101 // if( flags&0x01 ){ // (-fs) |
102 // aspect(&d_width,&d_height,A_ZOOM); | |
103 // } | |
2040 | 104 #endif |
1 | 105 hint.x = 0; |
106 hint.y = 0; | |
107 hint.width = d_width; | |
108 hint.height = d_height; | |
109 hint.flags = PPosition | PSize; | |
110 | |
111 /* Get some colors */ | |
112 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
113 bg = WhitePixel(mDisplay, mScreen); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
114 fg = BlackPixel(mDisplay, mScreen); |
1 | 115 |
116 /* Make the window */ | |
117 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
118 vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib ); |
1290 | 119 if (vinfo == NULL) |
120 { | |
121 printf("[gl] no GLX support present\n"); | |
122 return -1; | |
123 } | |
1 | 124 |
125 xswa.background_pixel = 0; | |
126 xswa.border_pixel = 1; | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
127 xswa.colormap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone); |
1 | 128 xswamask = CWBackPixel | CWBorderPixel | CWColormap; |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
1109
diff
changeset
|
129 |
7777 | 130 if ( vo_window == None ) |
131 { | |
132 vo_window = XCreateWindow(mDisplay, mRootWin, | |
133 hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa); | |
1 | 134 |
7777 | 135 vo_x11_classhint( mDisplay,vo_window,"gl" ); |
136 vo_hidecursor(mDisplay,vo_window); | |
1 | 137 |
7777 | 138 // if ( flags&0x01 ) vo_x11_decoration( mDisplay,vo_window,0 ); |
139 XSelectInput(mDisplay, vo_window, StructureNotifyMask); | |
140 /* Tell other applications about this window */ | |
141 XSetStandardProperties(mDisplay, vo_window, hello, hello, None, NULL, 0, &hint); | |
142 /* Map window. */ | |
143 XMapWindow(mDisplay, vo_window); | |
144 if ( flags&1 ) vo_x11_fullscreen(); | |
4017 | 145 #ifdef HAVE_XINERAMA |
7777 | 146 vo_x11_xinerama_move(mDisplay,vo_window); |
4017 | 147 #endif |
1 | 148 |
7777 | 149 /* Wait for map. */ |
150 do | |
151 { | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
152 XNextEvent(mDisplay, &xev); |
7777 | 153 } |
154 while (xev.type != MapNotify || xev.xmap.event != vo_window); | |
1 | 155 |
7777 | 156 XSelectInput(mDisplay, vo_window, NoEventMask); |
157 } | |
1 | 158 |
7777 | 159 if ( vo_config_count ) glXDestroyContext( mDisplay,wsGLXContext ); |
160 wsGLXContext=glXCreateContext( mDisplay,vinfo,NULL,True ); | |
161 glXMakeCurrent( mDisplay,vo_window,wsGLXContext ); | |
1 | 162 |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
163 XFlush(mDisplay); |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
164 XSync(mDisplay, False); |
1 | 165 |
6953
ce67cc1f0beb
ignore BadAccess error at XSelectInput() (grabbing mouse etc) with warning
arpi
parents:
6212
diff
changeset
|
166 vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask |
4658 | 167 | ButtonPressMask | ButtonReleaseMask |
168 ); | |
1 | 169 |
170 #if 0 | |
171 // If we have blue in the lowest bit then obviously RGB | |
172 mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR; | |
173 #ifdef WORDS_BIGENDIAN | |
174 if (myximage->byte_order != MSBFirst) | |
175 #else | |
176 if (myximage->byte_order != LSBFirst) | |
177 #endif | |
178 { | |
1302 | 179 printf("[gl] no support for non-native XImage byte order!\n"); |
1 | 180 return -1; |
181 } | |
182 | |
183 printf("DEPTH=%d BPP=%d\n",depth,bpp); | |
184 #endif | |
185 | |
186 /* | |
187 * If depth is 24 then it may either be a 3 or 4 byte per pixel | |
188 * format. We can't use bpp because then we would lose the | |
189 * distinction between 15/16bit depth (2 byte formate assumed). | |
190 * | |
191 * FIXME - change yuv2rgb_init to take both depth and bpp | |
192 * parameters | |
193 */ | |
194 | |
195 texture_width=32; | |
196 while(texture_width<image_width) texture_width*=2; | |
197 while(texture_width<image_height) texture_width*=2; | |
198 texture_height=texture_width; | |
199 | |
200 if(format==IMGFMT_YV12){ | |
201 yuv2rgb_init(8*BYTES_PP, MODE_BGR); | |
1290 | 202 printf("[gl] YUV init OK!\n"); |
1 | 203 image_bpp=8*BYTES_PP; |
204 image_bytes=BYTES_PP; | |
205 } else { | |
206 image_bpp=format&0xFF; | |
207 image_bytes=(image_bpp+7)/8; | |
208 } | |
209 | |
7777 | 210 if ( ImageData ) free( ImageData ); |
1 | 211 ImageData=malloc(texture_width*texture_height*image_bytes); |
212 memset(ImageData,128,texture_width*texture_height*image_bytes); | |
213 | |
214 glDisable(GL_BLEND); | |
215 glDisable(GL_DEPTH_TEST); | |
216 glDepthMask(GL_FALSE); | |
217 glDisable(GL_CULL_FACE); | |
218 | |
219 glEnable(GL_TEXTURE_2D); | |
220 | |
1290 | 221 printf("[gl] Creating %dx%d texture...\n",texture_width,texture_height); |
1 | 222 |
223 #if 1 | |
224 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
225 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
226 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
227 #ifdef TEXTUREFORMAT_32BPP | |
228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0, | |
229 #else | |
230 glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0, | |
231 #endif | |
232 (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData); | |
233 #endif | |
234 | |
235 resize(d_width,d_height); | |
236 | |
237 glClearColor( 1.0f,0.0f,1.0f,0.0f ); | |
238 glClear( GL_COLOR_BUFFER_BIT ); | |
239 | |
240 // printf("OpenGL setup OK!\n"); | |
241 | |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
242 saver_off(mDisplay); // turning off screen saver |
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
243 |
1 | 244 return 0; |
245 } | |
246 | |
31 | 247 static void check_events(void) |
1 | 248 { |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
249 int e=vo_x11_check_events(mDisplay); |
31 | 250 if(e&VO_EVENT_RESIZE) resize(vo_dwidth,vo_dheight); |
251 } | |
1 | 252 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
253 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
254 { |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1302
diff
changeset
|
255 } |
31 | 256 |
257 static void | |
258 flip_page(void) | |
259 { | |
260 | |
1 | 261 // glEnable(GL_TEXTURE_2D); |
262 // glBindTexture(GL_TEXTURE_2D, texture_id); | |
263 | |
264 glColor3f(1,1,1); | |
265 glBegin(GL_QUADS); | |
266 glTexCoord2f(0,0);glVertex2i(0,0); | |
267 glTexCoord2f(0,1);glVertex2i(0,texture_height); | |
268 glTexCoord2f(1,1);glVertex2i(texture_width,texture_height); | |
269 glTexCoord2f(1,0);glVertex2i(texture_width,0); | |
270 glEnd(); | |
271 | |
272 // glFlush(); | |
273 glFinish(); | |
6095 | 274 glXSwapBuffers( mDisplay,vo_window ); |
275 | |
1 | 276 } |
277 | |
278 //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num) | |
279 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
280 { | |
281 int i; | |
282 int dstride=w*BYTES_PP; | |
283 | |
284 // dstride=(dstride+15)&(~15); | |
285 | |
286 yuv2rgb(ImageData, src[0], src[1], src[2], | |
287 w,h, dstride, stride[0],stride[1]); | |
288 | |
289 for(i=0;i<h;i++){ | |
290 glTexSubImage2D( GL_TEXTURE_2D, // target | |
291 0, // level | |
292 x, // x offset | |
293 y+i, // y offset | |
294 w, // width | |
295 1, // height | |
296 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
297 GL_UNSIGNED_BYTE, // type | |
298 ImageData+i*dstride ); // *pixels | |
299 } | |
300 | |
301 return 0; | |
302 } | |
303 | |
304 static inline uint32_t | |
305 draw_frame_x11_yv12(uint8_t *src[]) | |
306 { | |
307 int i; | |
308 // printf("Converting YUV->RGB...\n"); | |
309 yuv2rgb(ImageData, src[0], src[1], src[2], | |
310 image_width, image_height, | |
311 image_width*BYTES_PP, image_width, image_width/2 ); | |
312 | |
313 for(i=0;i<image_height;i++){ | |
314 glTexSubImage2D( GL_TEXTURE_2D, // target | |
315 0, // level | |
316 0, // x offset | |
317 i, // y offset | |
318 image_width, // width | |
319 1, // height | |
320 (BYTES_PP==4)?GL_RGBA:GL_RGB, // format | |
321 GL_UNSIGNED_BYTE, // type | |
322 ImageData+i*BYTES_PP*image_width ); // *pixels | |
323 } | |
324 | |
325 return 0; | |
326 } | |
327 | |
328 | |
329 static inline uint32_t | |
330 draw_frame_x11_bgr(uint8_t *src[]) | |
331 { | |
332 int i; | |
333 uint8_t *s=src[0]; | |
334 uint8_t *de=&ImageData[3*image_width]; | |
335 | |
336 for(i=0;i<image_height;i++){ | |
337 uint8_t *d=ImageData; | |
338 while(d<de){ | |
339 d[0]=s[2]; | |
340 d[1]=s[1]; | |
341 d[2]=s[0]; | |
342 s+=3;d+=3; | |
343 } | |
344 glTexSubImage2D( GL_TEXTURE_2D, // target | |
345 0, // level | |
346 0, // x offset | |
347 // image_height-1-i, // y offset | |
348 i, // y offset | |
349 image_width, // width | |
350 1, // height | |
351 (image_bytes==4)?GL_RGBA:GL_RGB, // format | |
352 GL_UNSIGNED_BYTE, // type | |
353 ImageData); // *pixels | |
354 } | |
355 | |
356 return 0; | |
357 } | |
358 | |
359 static inline uint32_t | |
360 draw_frame_x11_rgb(uint8_t *src[]) | |
361 { | |
362 int i; | |
363 uint8_t *ImageData=src[0]; | |
364 | |
365 for(i=0;i<image_height;i++){ | |
366 glTexSubImage2D( GL_TEXTURE_2D, // target | |
367 0, // level | |
368 0, // x offset | |
369 // image_height-1-i, // y offset | |
370 i, // y offset | |
371 image_width, // width | |
372 1, // height | |
373 (image_bytes==4)?GL_RGBA:GL_RGB, // format | |
374 GL_UNSIGNED_BYTE, // type | |
375 ImageData+i*image_bytes*image_width ); // *pixels | |
376 } | |
377 | |
378 return 0; | |
379 } | |
380 | |
381 | |
382 static uint32_t | |
383 draw_frame(uint8_t *src[]) | |
384 { | |
385 if(image_format==IMGFMT_YV12) | |
386 return draw_frame_x11_yv12(src); | |
387 else | |
388 if((image_format&IMGFMT_RGB_MASK)==IMGFMT_RGB) | |
389 return draw_frame_x11_rgb(src); | |
390 else | |
391 return draw_frame_x11_bgr(src); | |
392 } | |
393 | |
394 static uint32_t | |
395 query_format(uint32_t format) | |
396 { | |
397 switch(format){ | |
398 case IMGFMT_YV12: | |
6212 | 399 return VFCAP_CSP_SUPPORTED; |
1 | 400 case IMGFMT_RGB|24: |
401 case IMGFMT_BGR|24: | |
6212 | 402 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; |
1 | 403 } |
404 return 0; | |
405 } | |
406 | |
407 | |
408 static void | |
409 uninit(void) | |
410 { | |
6095 | 411 if ( !vo_config_count ) return; |
2041
ba8a225d1a18
now using x11_common stuff for X11 opening and w/h/bpp query
arpi
parents:
2040
diff
changeset
|
412 saver_on(mDisplay); // screen saver back on |
6095 | 413 vo_x11_uninit(); |
1 | 414 } |
4352 | 415 |
416 static uint32_t preinit(const char *arg) | |
417 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
418 if(arg) |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
419 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
420 printf("[gl] Unknown subdevice: %s\n",arg); |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
421 return ENOSYS; |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
422 } |
7777 | 423 |
7931 | 424 if( !vo_init() ) return -1; // Can't open X11 |
7777 | 425 |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4658
diff
changeset
|
426 return 0; |
4352 | 427 } |
428 | |
4596 | 429 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 430 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
431 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
432 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
433 return query_format(*((uint32_t*)data)); |
6095 | 434 case VOCTRL_FULLSCREEN: |
435 vo_x11_fullscreen(); | |
436 return VO_TRUE; | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
437 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4448
diff
changeset
|
438 return VO_NOTIMPL; |
4352 | 439 } |