Mercurial > mplayer.hg
changeset 12582:162c80b2d432
major reindentation of x11 code try #2
note that this is plain ident output, i didnt tweak it by
hand like the last attempt.
if anyone is interested in the indent profile i used, just drop me a mail.
please contact me on irc on how to send me my share of cola,
but be aware that i will only accept swiss or german cola, as the japanese is
way to sweet :)
author | attila |
---|---|
date | Mon, 14 Jun 2004 04:53:03 +0000 |
parents | 602a2796e353 |
children | 2b39ce9b0ffe |
files | libvo/vo_dga.c libvo/vo_x11.c libvo/vo_xmga.c libvo/vo_xv.c libvo/vo_xvidix.c libvo/x11_common.c |
diffstat | 6 files changed, 4152 insertions(+), 3225 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/vo_dga.c Sun Jun 13 21:34:29 2004 +0000 +++ b/libvo/vo_dga.c Mon Jun 14 04:53:03 2004 +0000 @@ -30,168 +30,181 @@ #include <X11/extensions/xf86vmode.h> #endif -static vo_info_t info = -{ +static vo_info_t info = { #ifdef HAVE_DGA2 - "DGA ( Direct Graphic Access V2.0 )", + "DGA ( Direct Graphic Access V2.0 )", #else #ifdef HAVE_XF86VM - "DGA ( Direct Graphic Access V1.0+XF86VidModeExt. )", + "DGA ( Direct Graphic Access V1.0+XF86VidModeExt. )", #else - "DGA ( Direct Graphic Access V1.0 )", + "DGA ( Direct Graphic Access V1.0 )", #endif #endif - "dga", - "Andreas Ackermann <acki@acki-netz.de>", - "" + "dga", + "Andreas Ackermann <acki@acki-netz.de>", + "" }; -LIBVO_EXTERN( dga ) - - +LIBVO_EXTERN(dga) //------------------------------------------------------------------ - - //#define BITSPP (vo_dga_modes[vo_dga_active_mode].vdm_bitspp) //#define BYTESPP (vo_dga_modes[vo_dga_active_mode].vdm_bytespp) - #define VO_DGA_INVALID_RES 100000 - #define HW_MODE (vo_dga_modes[vo_dga_hw_mode]) -#define SRC_MODE (vo_dga_modes[vo_dga_src_mode]) - -struct vd_modes { - int vdm_mplayer_depth; - int vdm_supported; - int vdm_depth; - int vdm_bitspp; - int vdm_bytespp; - int vdm_rmask; - int vdm_gmask; - int vdm_bmask; - int vdm_hw_mode; +#define SRC_MODE (vo_dga_modes[vo_dga_src_mode]) +struct vd_modes +{ + int vdm_mplayer_depth; + int vdm_supported; + int vdm_depth; + int vdm_bitspp; + int vdm_bytespp; + int vdm_rmask; + int vdm_gmask; + int vdm_bmask; + int vdm_hw_mode; }; //------------------------------------------------------------------ static struct vd_modes vo_dga_modes[] = { - // these entries describe HW modes - // however, we use the same entries to tell mplayer what we support - // so the last two values describe, which HW mode to use and which conversion - // function to use for a mode that is not supported by HW + // these entries describe HW modes + // however, we use the same entries to tell mplayer what we support + // so the last two values describe, which HW mode to use and which conversion + // function to use for a mode that is not supported by HW - { 0, 0, 0, 0, 0, 0, 0, 0, 0, }, - { 15, 0, 15, 16, 2, 0x7c00, 0x03e0, 0x001f, 2, }, - { 16, 0, 16, 16, 2, 0xf800, 0x07e0, 0x001f, 2, }, - { 24, 0, 24, 24, 3, 0xff0000, 0x00ff00, 0x0000ff, 4}, - { 32, 0, 24, 32, 4, 0x00ff0000, 0x0000ff00, 0x000000ff, 4} + {0, 0, 0, 0, 0, 0, 0, 0, 0,}, + {15, 0, 15, 16, 2, 0x7c00, 0x03e0, 0x001f, 2,}, + {16, 0, 16, 16, 2, 0xf800, 0x07e0, 0x001f, 2,}, + {24, 0, 24, 24, 3, 0xff0000, 0x00ff00, 0x0000ff, 4}, + {32, 0, 24, 32, 4, 0x00ff0000, 0x0000ff00, 0x000000ff, 4} }; -static int vo_dga_mode_num = sizeof(vo_dga_modes)/sizeof(struct vd_modes); +static int vo_dga_mode_num = + sizeof(vo_dga_modes) / sizeof(struct vd_modes); // enable a HW mode (by description) -static int vd_EnableMode( int depth, int bitspp, - int rmask, int gmask, int bmask){ - int i; - for(i=1; i<vo_dga_mode_num; i++){ - if(vo_dga_modes[i].vdm_depth == depth && - vo_dga_modes[i].vdm_bitspp == bitspp && - vo_dga_modes[i].vdm_rmask == rmask && - vo_dga_modes[i].vdm_gmask == gmask && - vo_dga_modes[i].vdm_bmask == bmask){ - vo_dga_modes[i].vdm_supported = 1; - vo_dga_modes[i].vdm_hw_mode = i; - return i; +static int vd_EnableMode(int depth, int bitspp, + int rmask, int gmask, int bmask) +{ + int i; + + for (i = 1; i < vo_dga_mode_num; i++) + { + if (vo_dga_modes[i].vdm_depth == depth && + vo_dga_modes[i].vdm_bitspp == bitspp && + vo_dga_modes[i].vdm_rmask == rmask && + vo_dga_modes[i].vdm_gmask == gmask && + vo_dga_modes[i].vdm_bmask == bmask) + { + vo_dga_modes[i].vdm_supported = 1; + vo_dga_modes[i].vdm_hw_mode = i; + return i; + } } - } - return 0; + return 0; } -static int vd_ModeEqual(int depth, int bitspp, - int rmask, int gmask, int bmask, int index){ - return ( - (vo_dga_modes[index].vdm_depth == depth && - vo_dga_modes[index].vdm_bitspp == bitspp && - vo_dga_modes[index].vdm_rmask == rmask && - vo_dga_modes[index].vdm_gmask == gmask && - vo_dga_modes[index].vdm_bmask == bmask) - ? 1 : 0); +static int vd_ModeEqual(int depth, int bitspp, + int rmask, int gmask, int bmask, int index) +{ + return ((vo_dga_modes[index].vdm_depth == depth && + vo_dga_modes[index].vdm_bitspp == bitspp && + vo_dga_modes[index].vdm_rmask == rmask && + vo_dga_modes[index].vdm_gmask == gmask && + vo_dga_modes[index].vdm_bmask == bmask) ? 1 : 0); } // enable a HW mode (mplayer_depth decides which) -static int vd_ValidateMode( int mplayer_depth){ - int i; - if(mplayer_depth == 0)return 0; - for(i=1; i<vo_dga_mode_num; i++){ - if(vo_dga_modes[i].vdm_mplayer_depth == mplayer_depth ){ - vo_dga_modes[i].vdm_supported = 1; - vo_dga_modes[i].vdm_hw_mode = i; - return i; +static int vd_ValidateMode(int mplayer_depth) +{ + int i; + + if (mplayer_depth == 0) + return 0; + for (i = 1; i < vo_dga_mode_num; i++) + { + if (vo_dga_modes[i].vdm_mplayer_depth == mplayer_depth) + { + vo_dga_modes[i].vdm_supported = 1; + vo_dga_modes[i].vdm_hw_mode = i; + return i; + } } - } - return 0; + return 0; } // do we support this mode? (not important whether native or conversion) -static int vd_ModeValid( int mplayer_depth){ - int i; - if(mplayer_depth == 0)return 0; - for(i=1; i<vo_dga_mode_num; i++){ - if(vo_dga_modes[i].vdm_mplayer_depth == mplayer_depth && - vo_dga_modes[i].vdm_supported != 0){ - return i; +static int vd_ModeValid(int mplayer_depth) +{ + int i; + + if (mplayer_depth == 0) + return 0; + for (i = 1; i < vo_dga_mode_num; i++) + { + if (vo_dga_modes[i].vdm_mplayer_depth == mplayer_depth && + vo_dga_modes[i].vdm_supported != 0) + { + return i; + } } - } - return 0; + return 0; } -static char *vd_GetModeString(int index){ +static char *vd_GetModeString(int index) +{ #define VO_DGA_MAX_STRING_LEN 100 - static char stringbuf[VO_DGA_MAX_STRING_LEN]; - stringbuf[VO_DGA_MAX_STRING_LEN-1]=0; - snprintf(stringbuf, VO_DGA_MAX_STRING_LEN-2, - "depth=%d, bpp=%d, r=%06x, g=%06x, b=%06x, %s (-bpp %d)", - vo_dga_modes[index].vdm_depth, - vo_dga_modes[index].vdm_bitspp, - vo_dga_modes[index].vdm_rmask, - vo_dga_modes[index].vdm_gmask, - vo_dga_modes[index].vdm_bmask, - vo_dga_modes[index].vdm_supported ? "native" : "not supported", - vo_dga_modes[index].vdm_mplayer_depth); - return stringbuf; + static char stringbuf[VO_DGA_MAX_STRING_LEN]; + + stringbuf[VO_DGA_MAX_STRING_LEN - 1] = 0; + snprintf(stringbuf, VO_DGA_MAX_STRING_LEN - 2, + "depth=%d, bpp=%d, r=%06x, g=%06x, b=%06x, %s (-bpp %d)", + vo_dga_modes[index].vdm_depth, + vo_dga_modes[index].vdm_bitspp, + vo_dga_modes[index].vdm_rmask, + vo_dga_modes[index].vdm_gmask, + vo_dga_modes[index].vdm_bmask, + vo_dga_modes[index]. + vdm_supported ? "native" : "not supported", + vo_dga_modes[index].vdm_mplayer_depth); + return stringbuf; } //----------------------------------------------------------------- #if defined(HAVE_XF86VM) && !defined(HAVE_DGA2) -static XF86VidModeModeInfo **vo_dga_vidmodes=NULL; +static XF86VidModeModeInfo **vo_dga_vidmodes = NULL; #endif -static int vo_dga_src_format; -static int vo_dga_width; // bytes per line in framebuffer -static int vo_dga_vp_width; // visible pixels per line in +static int vo_dga_src_format; +static int vo_dga_width; // bytes per line in framebuffer +static int vo_dga_vp_width; // visible pixels per line in + // framebuffer -static int vo_dga_vp_height; // visible lines in framebuffer -static int vo_dga_is_running = 0; -static int vo_dga_src_width; // width of video in pixels -static int vo_dga_src_height; // height of video in pixels -static int vo_dga_src_offset=0; // offset in src -static int vo_dga_vp_offset=0; // offset in dest -static int vo_dga_bytes_per_line; // bytes per line to copy -static int vo_dga_vp_skip; // dto. for dest -static int vo_dga_lines; // num of lines to copy -static int vo_dga_hw_mode = 0; // index in mode list that is actually +static int vo_dga_vp_height; // visible lines in framebuffer +static int vo_dga_is_running = 0; +static int vo_dga_src_width; // width of video in pixels +static int vo_dga_src_height; // height of video in pixels +static int vo_dga_src_offset = 0; // offset in src +static int vo_dga_vp_offset = 0; // offset in dest +static int vo_dga_bytes_per_line; // bytes per line to copy +static int vo_dga_vp_skip; // dto. for dest +static int vo_dga_lines; // num of lines to copy +static int vo_dga_hw_mode = 0; // index in mode list that is actually + // used by framebuffer -static int vo_dga_src_mode = 0; // index in mode list that is used by +static int vo_dga_src_mode = 0; // index in mode list that is used by + // codec -static int vo_dga_XServer_mode = 0;// index in mode list for resolution +static int vo_dga_XServer_mode = 0; // index in mode list for resolution #ifdef HAVE_DGA2 - static XDGAMode * vo_modelines; - static int vo_modecount; +static XDGAMode *vo_modelines; +static int vo_modecount; #endif #define MAX_NR_VIDEO_BUFFERS 3 @@ -199,48 +212,53 @@ #define CURRENT_VIDEO_BUFFER \ (vo_dga_video_buffer[vo_dga_current_video_buffer]) -static int vo_dga_nr_video_buffers; // Total number of frame buffers. -static int vo_dga_current_video_buffer; // Buffer available for rendering. +static int vo_dga_nr_video_buffers; // Total number of frame buffers. +static int vo_dga_current_video_buffer; // Buffer available for rendering. static struct video_buffer { - int y; - uint8_t *data; + int y; + uint8_t *data; } vo_dga_video_buffer[MAX_NR_VIDEO_BUFFERS]; /* saved src and dst dimensions for SwScaler */ static unsigned int scale_srcW = 0, - scale_dstW = 0, - scale_srcH = 0, - scale_dstH = 0; + scale_dstW = 0, scale_srcH = 0, scale_dstH = 0; //--------------------------------------------------------- -static void draw_alpha( int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride ){ - - char *d; - unsigned int offset; - unsigned int buffer_stride; +static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ - offset = vo_dga_width * y0 +x0; - buffer_stride = vo_dga_width; - d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; - - switch( HW_MODE.vdm_mplayer_depth ){ + char *d; + unsigned int offset; + unsigned int buffer_stride; + + offset = vo_dga_width * y0 + x0; + buffer_stride = vo_dga_width; + d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; + + switch (HW_MODE.vdm_mplayer_depth) + { - case 32: - vo_draw_alpha_rgb32(w,h,src,srca,stride, d+4*offset , 4*buffer_stride); - break; - case 24: - vo_draw_alpha_rgb24(w,h,src,srca,stride, d+3*offset , 3*buffer_stride); - break; - case 15: - vo_draw_alpha_rgb15(w,h,src,srca,stride, d+2*offset , 2*buffer_stride); - break; - case 16: - vo_draw_alpha_rgb16(w,h,src,srca,stride, d+2*offset , 2*buffer_stride); - break; - } + case 32: + vo_draw_alpha_rgb32(w, h, src, srca, stride, d + 4 * offset, + 4 * buffer_stride); + break; + case 24: + vo_draw_alpha_rgb24(w, h, src, srca, stride, d + 3 * offset, + 3 * buffer_stride); + break; + case 15: + vo_draw_alpha_rgb15(w, h, src, srca, stride, d + 2 * offset, + 2 * buffer_stride); + break; + case 16: + vo_draw_alpha_rgb16(w, h, src, srca, stride, d + 2 * offset, + 2 * buffer_stride); + break; + } } @@ -251,53 +269,56 @@ // quick & dirty - for debugging only #if 0 -static void fillblock(char *strt, int yoff, int lines, int val){ - char *i; - for(i = strt + yoff * vo_dga_width *HW_MODE.vdm_bytespp; - i< strt + (lines+yoff) * vo_dga_width *HW_MODE.vdm_bytespp; ){ - *i++ = val; - } +static void fillblock(char *strt, int yoff, int lines, int val) +{ + char *i; + + for (i = strt + yoff * vo_dga_width * HW_MODE.vdm_bytespp; + i < strt + (lines + yoff) * vo_dga_width * HW_MODE.vdm_bytespp;) + { + *i++ = val; + } } #endif //--------------------------------------------------------- -static uint32_t draw_frame( uint8_t *src[] ){ +static uint32_t draw_frame(uint8_t * src[]) +{ - int vp_skip = vo_dga_vp_skip; - int numlines = vo_dga_lines; + int vp_skip = vo_dga_vp_skip; + int numlines = vo_dga_lines; - char *s, *d; + char *s, *d; - s = *src; - d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; - - mem2agpcpy_pic( - d, s, - vo_dga_bytes_per_line, - numlines, - vo_dga_bytes_per_line+vo_dga_vp_skip, - vo_dga_bytes_per_line); - - // DBG-COde + s = *src; + d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; + + mem2agpcpy_pic(d, s, + vo_dga_bytes_per_line, + numlines, + vo_dga_bytes_per_line + vo_dga_vp_skip, + vo_dga_bytes_per_line); + + // DBG-COde #if 0 - d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; - fillblock(d, 0, 10, 0x800000ff); - fillblock(d, 10, 10, 0x8000ff00); - fillblock(d, 20, 10, 0x80ff0000); - fillblock(d, 30, 10, 0xff0000ff); - fillblock(d, 40, 10, 0x800000ff); - fillblock(d, 50, 10, 0x0f0000ff); + d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; + fillblock(d, 0, 10, 0x800000ff); + fillblock(d, 10, 10, 0x8000ff00); + fillblock(d, 20, 10, 0x80ff0000); + fillblock(d, 30, 10, 0xff0000ff); + fillblock(d, 40, 10, 0x800000ff); + fillblock(d, 50, 10, 0x0f0000ff); #endif - return 0; + return 0; } //--------------------------------------------------------- static void check_events(void) { - vo_x11_check_events(mDisplay); + vo_x11_check_events(mDisplay); } //--------------------------------------------------------- @@ -305,96 +326,100 @@ #include "sub.h" static void draw_osd(void) -{ vo_draw_text(vo_dga_src_width,vo_dga_src_height,draw_alpha); } +{ + vo_draw_text(vo_dga_src_width, vo_dga_src_height, draw_alpha); +} static void switch_video_buffers(void) { - vo_dga_current_video_buffer = - (vo_dga_current_video_buffer + 1) % vo_dga_nr_video_buffers; + vo_dga_current_video_buffer = + (vo_dga_current_video_buffer + 1) % vo_dga_nr_video_buffers; } -static void flip_page( void ) +static void flip_page(void) { - if(1 < vo_dga_nr_video_buffers) - { + if (1 < vo_dga_nr_video_buffers) + { #ifdef HAVE_DGA2 - XDGASetViewport(mDisplay, mScreen, - 0, - CURRENT_VIDEO_BUFFER.y, - XDGAFlipRetrace); + XDGASetViewport(mDisplay, mScreen, + 0, CURRENT_VIDEO_BUFFER.y, XDGAFlipRetrace); #else - XF86DGASetViewPort(mDisplay, mScreen, - 0, - CURRENT_VIDEO_BUFFER.y); + XF86DGASetViewPort(mDisplay, mScreen, 0, CURRENT_VIDEO_BUFFER.y); #endif - switch_video_buffers(); - } + switch_video_buffers(); + } } //--------------------------------------------------------- -static uint32_t draw_slice( uint8_t *src[],int stride[], - int w,int h,int x,int y ) +static uint32_t draw_slice(uint8_t * src[], int stride[], + int w, int h, int x, int y) { - return 0; + return 0; }; //--------------------------------------------------------- -static uint32_t query_format( uint32_t format ) +static uint32_t query_format(uint32_t format) { - if( (format&IMGFMT_BGR_MASK) == IMGFMT_BGR && - vd_ModeValid(format&0xff)) - { - return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD; - } - - return 0; + if ((format & IMGFMT_BGR_MASK) == IMGFMT_BGR && + vd_ModeValid(format & 0xff)) + { + return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD; + } + + return 0; } //--------------------------------------------------------- -static void -uninit(void) +static void uninit(void) { #ifdef HAVE_DGA2 - XDGADevice *dgadevice; + XDGADevice *dgadevice; #endif - if ( !vo_config_count ) return; + if (!vo_config_count) + return; - if(vo_dga_is_running){ - vo_dga_is_running = 0; - mp_msg(MSGT_VO, MSGL_V, "vo_dga: in uninit\n"); - if(vo_grabpointer) - XUngrabPointer (mDisplay, CurrentTime); - XUngrabKeyboard (mDisplay, CurrentTime); + if (vo_dga_is_running) + { + vo_dga_is_running = 0; + mp_msg(MSGT_VO, MSGL_V, "vo_dga: in uninit\n"); + if (vo_grabpointer) + XUngrabPointer(mDisplay, CurrentTime); + XUngrabKeyboard(mDisplay, CurrentTime); #ifdef HAVE_DGA2 - XDGACloseFramebuffer(mDisplay, mScreen); - dgadevice = XDGASetMode(mDisplay, mScreen, 0); - if(dgadevice != NULL){ - XFree(dgadevice); - } + XDGACloseFramebuffer(mDisplay, mScreen); + dgadevice = XDGASetMode(mDisplay, mScreen, 0); + if (dgadevice != NULL) + { + XFree(dgadevice); + } #else - XF86DGADirectVideo (mDisplay, mScreen, 0); - // first disable DirectVideo and then switch mode back! + XF86DGADirectVideo(mDisplay, mScreen, 0); + // first disable DirectVideo and then switch mode back! #ifdef HAVE_XF86VM - if (vo_dga_vidmodes != NULL ){ - int screen; screen=XDefaultScreen( mDisplay ); - mp_msg(MSGT_VO, MSGL_V, "vo_dga: VidModeExt: Switching back..\n"); - // seems some graphics adaptors need this more than once ... - XF86VidModeSwitchToMode(mDisplay,screen,vo_dga_vidmodes[0]); - XF86VidModeSwitchToMode(mDisplay,screen,vo_dga_vidmodes[0]); - XF86VidModeSwitchToMode(mDisplay,screen,vo_dga_vidmodes[0]); - XF86VidModeSwitchToMode(mDisplay,screen,vo_dga_vidmodes[0]); - XFree(vo_dga_vidmodes); - } + if (vo_dga_vidmodes != NULL) + { + int screen; + + screen = XDefaultScreen(mDisplay); + mp_msg(MSGT_VO, MSGL_V, + "vo_dga: VidModeExt: Switching back..\n"); + // seems some graphics adaptors need this more than once ... + XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); + XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); + XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); + XF86VidModeSwitchToMode(mDisplay, screen, vo_dga_vidmodes[0]); + XFree(vo_dga_vidmodes); + } #endif #endif - } - vo_x11_uninit(); + } + vo_x11_uninit(); } @@ -402,75 +427,57 @@ // TODO: check for larger maxy value // (useful for double buffering!!!) -static int check_res( int num, int x, int y, int bpp, - int new_x, int new_y, int new_vbi, int new_maxy, - int *old_x, int *old_y, int *old_vbi, int *old_maxy){ +static int check_res(int num, int x, int y, int bpp, + int new_x, int new_y, int new_vbi, int new_maxy, + int *old_x, int *old_y, int *old_vbi, int *old_maxy) +{ - mp_msg(MSGT_VO, MSGL_V, "vo_dga: (%3d) Trying %4d x %4d @ %3d Hz @ depth %2d ..", - num, new_x, new_y, new_vbi, bpp ); - mp_msg(MSGT_VO, MSGL_V, "(old: %dx%d@%d).", *old_x, *old_y, *old_vbi); - if ( - (new_x >= x) && - (new_y >= y) && - ( - // prefer a better resolution either in X or in Y - // as long as the other dimension is at least the same - // - // hmm ... MAYBE it would be more clever to focus on the - // x-resolution; I had 712x400 and 640x480 and the movie - // was 640x360; 640x480 would be the 'right thing' here - // but since 712x400 was queried first I got this one. - // I think there should be a cmd-line switch to let the - // user choose the mode he likes ... (acki2) - - ( - ((new_x < *old_x) && - !(new_y > *old_y)) || - ((new_y < *old_y) && - !(new_x > *old_x)) - ) - // but if we get an identical resolution choose - // the one with the lower refreshrate (saves bandwidth !!!) - // as long as it's above 50 Hz (acki2 on 30/3/2001) - || - ( - ( - (new_x == *old_x) && - (new_y == *old_y) && - ( - ( - new_vbi >= *old_vbi && *old_vbi < 50 - ) - || - ( - *old_vbi >= 50 && - new_vbi < *old_vbi && - new_vbi >= 50 - ) - ) - ) - || - // if everything is equal, then use the mode with the lower - // stride - ( - (new_x == *old_x) && - (new_y == *old_y) && - (new_vbi == *old_vbi) && - (new_maxy > *old_maxy) - ) - ) - ) - ) + mp_msg(MSGT_VO, MSGL_V, + "vo_dga: (%3d) Trying %4d x %4d @ %3d Hz @ depth %2d ..", num, + new_x, new_y, new_vbi, bpp); + mp_msg(MSGT_VO, MSGL_V, "(old: %dx%d@%d).", *old_x, *old_y, *old_vbi); + if ((new_x >= x) && (new_y >= y) && ( + // prefer a better resolution either in X or in Y + // as long as the other dimension is at least the same + // + // hmm ... MAYBE it would be more clever to focus on the + // x-resolution; I had 712x400 and 640x480 and the movie + // was 640x360; 640x480 would be the 'right thing' here + // but since 712x400 was queried first I got this one. + // I think there should be a cmd-line switch to let the + // user choose the mode he likes ... (acki2) + (((new_x < *old_x) && + !(new_y > *old_y)) || + ((new_y < *old_y) && + !(new_x > *old_x))) + // but if we get an identical resolution choose + // the one with the lower refreshrate (saves bandwidth !!!) + // as long as it's above 50 Hz (acki2 on 30/3/2001) + || + (((new_x == *old_x) && + (new_y == *old_y) && + ((new_vbi >= *old_vbi + && *old_vbi < 50) + || (*old_vbi >= 50 + && new_vbi < *old_vbi + && new_vbi >= 50))) || + // if everything is equal, then use the mode with the lower + // stride + ((new_x == *old_x) && + (new_y == *old_y) && + (new_vbi == *old_vbi) && + (new_maxy > *old_maxy))))) { - *old_x = new_x; - *old_y = new_y; - *old_maxy = new_maxy; - *old_vbi = new_vbi; - mp_msg(MSGT_VO, MSGL_V, ".ok!!\n"); - return 1; - }else{ - mp_msg(MSGT_VO, MSGL_V, ".no\n"); - return 0; + *old_x = new_x; + *old_y = new_y; + *old_maxy = new_maxy; + *old_vbi = new_vbi; + mp_msg(MSGT_VO, MSGL_V, ".ok!!\n"); + return 1; + } else + { + mp_msg(MSGT_VO, MSGL_V, ".no\n"); + return 0; } } @@ -478,460 +485,505 @@ //--------------------------------------------------------- -static void init_video_buffers(uint8_t *buffer_base, - int view_port_height, - int bytes_per_scanline, - int max_view_port_y, - int use_multiple_buffers) +static void init_video_buffers(uint8_t * buffer_base, + int view_port_height, + int bytes_per_scanline, + int max_view_port_y, + int use_multiple_buffers) { - int bytes_per_buffer = view_port_height * bytes_per_scanline; - int i; + int bytes_per_buffer = view_port_height * bytes_per_scanline; + int i; - if(use_multiple_buffers) - vo_dga_nr_video_buffers = max_view_port_y / view_port_height; - else - vo_dga_nr_video_buffers = 1; + if (use_multiple_buffers) + vo_dga_nr_video_buffers = max_view_port_y / view_port_height; + else + vo_dga_nr_video_buffers = 1; - if (vo_dga_nr_video_buffers > MAX_NR_VIDEO_BUFFERS) - vo_dga_nr_video_buffers = MAX_NR_VIDEO_BUFFERS; - if (vo_dga_nr_video_buffers <= 0) - vo_dga_nr_video_buffers = 1; + if (vo_dga_nr_video_buffers > MAX_NR_VIDEO_BUFFERS) + vo_dga_nr_video_buffers = MAX_NR_VIDEO_BUFFERS; + if (vo_dga_nr_video_buffers <= 0) + vo_dga_nr_video_buffers = 1; + + vo_dga_current_video_buffer = 0; - vo_dga_current_video_buffer = 0; - - for(i = 0; i < vo_dga_nr_video_buffers; i++) - { - vo_dga_video_buffer[i].y = i * view_port_height; - vo_dga_video_buffer[i].data = - buffer_base + i * bytes_per_buffer; - - // Clear video buffer. - memset(vo_dga_video_buffer[i].data, 0, bytes_per_buffer); - } + for (i = 0; i < vo_dga_nr_video_buffers; i++) + { + vo_dga_video_buffer[i].y = i * view_port_height; + vo_dga_video_buffer[i].data = buffer_base + i * bytes_per_buffer; + + // Clear video buffer. + memset(vo_dga_video_buffer[i].data, 0, bytes_per_buffer); + } } -static uint32_t config( uint32_t width, uint32_t height, - uint32_t d_width,uint32_t d_height, - uint32_t flags,char *title,uint32_t format) +static uint32_t config(uint32_t width, uint32_t height, + uint32_t d_width, uint32_t d_height, + uint32_t flags, char *title, uint32_t format) { - int x_off, y_off; - int wanted_width, wanted_height; + int x_off, y_off; + int wanted_width, wanted_height; - static unsigned char *vo_dga_base; - static int prev_width, prev_height; + static unsigned char *vo_dga_base; + static int prev_width, prev_height; + #ifdef HAVE_DGA2 - // needed to change DGA video mode - int mX=VO_DGA_INVALID_RES, mY=VO_DGA_INVALID_RES , mVBI=100000, mMaxY=0, i,j=0; - int dga_modenum; - XDGAMode *modeline; - XDGADevice *dgadevice; + // needed to change DGA video mode + int mX = VO_DGA_INVALID_RES, mY = VO_DGA_INVALID_RES, mVBI = + 100000, mMaxY = 0, i, j = 0; + int dga_modenum; + XDGAMode *modeline; + XDGADevice *dgadevice; #else #ifdef HAVE_XF86VM - unsigned int vm_event, vm_error; - unsigned int vm_ver, vm_rev; - int i, j=0, have_vm=0; - int mX=VO_DGA_INVALID_RES, mY=VO_DGA_INVALID_RES, mVBI=100000, mMaxY=0, dga_modenum; + unsigned int vm_event, vm_error; + unsigned int vm_ver, vm_rev; + int i, j = 0, have_vm = 0; + int mX = VO_DGA_INVALID_RES, mY = VO_DGA_INVALID_RES, mVBI = + 100000, mMaxY = 0, dga_modenum; #endif - int bank, ram; + int bank, ram; #endif - vo_dga_src_format = format; + vo_dga_src_format = format; + + wanted_width = d_width; + wanted_height = d_height; - wanted_width = d_width; - wanted_height = d_height; + if (!wanted_height) + wanted_height = height; + if (!wanted_width) + wanted_width = width; - if(!wanted_height) wanted_height = height; - if(!wanted_width) wanted_width = width; - - if( !vo_dbpp ){ - if((format & IMGFMT_BGR_MASK) == IMGFMT_BGR){ - vo_dga_src_mode = vd_ModeValid( format & 0xff ); + if (!vo_dbpp) + { + if ((format & IMGFMT_BGR_MASK) == IMGFMT_BGR) + { + vo_dga_src_mode = vd_ModeValid(format & 0xff); + } + } else + { + vo_dga_src_mode = vd_ModeValid(vo_dbpp); } - }else{ - vo_dga_src_mode = vd_ModeValid(vo_dbpp); - } - vo_dga_hw_mode = SRC_MODE.vdm_hw_mode; + vo_dga_hw_mode = SRC_MODE.vdm_hw_mode; - if(!vo_dga_src_mode){ - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: unsupported video format!\n"); - return 1; - } - - vo_dga_vp_width = vo_screenwidth; - vo_dga_vp_height = vo_screenheight; + if (!vo_dga_src_mode) + { + mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: unsupported video format!\n"); + return 1; + } - mp_msg(MSGT_VO, MSGL_V, "vo_dga: XServer res: %dx%d\n", - vo_dga_vp_width, vo_dga_vp_height); + vo_dga_vp_width = vo_screenwidth; + vo_dga_vp_height = vo_screenheight; + + mp_msg(MSGT_VO, MSGL_V, "vo_dga: XServer res: %dx%d\n", + vo_dga_vp_width, vo_dga_vp_height); // choose a suitable mode ... - + #ifdef HAVE_DGA2 // Code to change the video mode added by Michael Graffam // mgraffam@idsi.net - mp_msg(MSGT_VO, MSGL_V, "vo_dga: vo_modelines=%p, vo_modecount=%d\n", vo_modelines, vo_modecount); + mp_msg(MSGT_VO, MSGL_V, "vo_dga: vo_modelines=%p, vo_modecount=%d\n", + vo_modelines, vo_modecount); + + if (vo_modelines == NULL) + { + mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: can't get modelines\n"); + return 1; + } - if (vo_modelines == NULL) - { - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: can't get modelines\n"); - return 1; - } - - mp_msg(MSGT_VO, MSGL_INFO, - "vo_dga: DGA 2.0 available :-) Can switch resolution AND depth!\n"); - for (i=0; i<vo_modecount; i++) - { - if(vd_ModeEqual( vo_modelines[i].depth, - vo_modelines[i].bitsPerPixel, - vo_modelines[i].redMask, - vo_modelines[i].greenMask, - vo_modelines[i].blueMask, - vo_dga_hw_mode)){ + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: DGA 2.0 available :-) Can switch resolution AND depth!\n"); + for (i = 0; i < vo_modecount; i++) + { + if (vd_ModeEqual(vo_modelines[i].depth, + vo_modelines[i].bitsPerPixel, + vo_modelines[i].redMask, + vo_modelines[i].greenMask, + vo_modelines[i].blueMask, vo_dga_hw_mode)) + { - mp_msg(MSGT_VO, MSGL_V, "maxy: %4d, depth: %2d, %4dx%4d, ", - vo_modelines[i].maxViewportY, vo_modelines[i].depth, - vo_modelines[i].imageWidth, vo_modelines[i].imageHeight ); - if ( check_res(i, wanted_width, wanted_height, vo_modelines[i].depth, - vo_modelines[i].viewportWidth, - vo_modelines[i].viewportHeight, - (unsigned) vo_modelines[i].verticalRefresh, - vo_modelines[i].maxViewportY, - &mX, &mY, &mVBI, &mMaxY )) j = i; - } - } - mp_msg(MSGT_VO, MSGL_INFO, - "vo_dga: Selected hardware mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d.\n", - mX, mY, mVBI, - HW_MODE.vdm_depth, - HW_MODE.vdm_bitspp); - mp_msg(MSGT_VO, MSGL_INFO, - "vo_dga: Video parameters by codec: %3d x %3d, depth %2d, bitspp %2d.\n", - width, height, - SRC_MODE.vdm_depth, - SRC_MODE.vdm_bitspp); - vo_dga_vp_width = mX; - vo_dga_vp_height = mY; + mp_msg(MSGT_VO, MSGL_V, "maxy: %4d, depth: %2d, %4dx%4d, ", + vo_modelines[i].maxViewportY, vo_modelines[i].depth, + vo_modelines[i].imageWidth, + vo_modelines[i].imageHeight); + if (check_res + (i, wanted_width, wanted_height, vo_modelines[i].depth, + vo_modelines[i].viewportWidth, + vo_modelines[i].viewportHeight, + (unsigned) vo_modelines[i].verticalRefresh, + vo_modelines[i].maxViewportY, &mX, &mY, &mVBI, &mMaxY)) + j = i; + } + } + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: Selected hardware mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d.\n", + mX, mY, mVBI, HW_MODE.vdm_depth, HW_MODE.vdm_bitspp); + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: Video parameters by codec: %3d x %3d, depth %2d, bitspp %2d.\n", + width, height, SRC_MODE.vdm_depth, SRC_MODE.vdm_bitspp); + vo_dga_vp_width = mX; + vo_dga_vp_height = mY; - if((flags&0x04)||(flags&0x01)) { /* -zoom or -fs */ - scale_dstW = (d_width + 7) & ~7; - scale_dstH = d_height; - scale_srcW = width; - scale_srcH = height; - aspect_save_screenres(mX,mY); - aspect_save_orig(scale_srcW,scale_srcH); - aspect_save_prescale(scale_dstW,scale_dstH); - if(flags&0x01) /* -fs */ - aspect(&scale_dstW,&scale_dstH,A_ZOOM); - else if(flags&0x04) /* -fs */ - aspect(&scale_dstW,&scale_dstH,A_NOZOOM); - mp_msg(MSGT_VO, MSGL_INFO, - "vo_dga: Aspect corrected size for SwScaler: %4d x %4d.\n", - scale_dstW, scale_dstH); - /* XXX this is a hack, but I'm lazy ;-) :: atmos */ - width = scale_dstW; - height = scale_dstH; - } + if ((flags & 0x04) || (flags & 0x01)) + { /* -zoom or -fs */ + scale_dstW = (d_width + 7) & ~7; + scale_dstH = d_height; + scale_srcW = width; + scale_srcH = height; + aspect_save_screenres(mX, mY); + aspect_save_orig(scale_srcW, scale_srcH); + aspect_save_prescale(scale_dstW, scale_dstH); + if (flags & 0x01) /* -fs */ + aspect(&scale_dstW, &scale_dstH, A_ZOOM); + else if (flags & 0x04) /* -fs */ + aspect(&scale_dstW, &scale_dstH, A_NOZOOM); + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: Aspect corrected size for SwScaler: %4d x %4d.\n", + scale_dstW, scale_dstH); + /* XXX this is a hack, but I'm lazy ;-) :: atmos */ + width = scale_dstW; + height = scale_dstH; + } - vo_dga_width = vo_modelines[j].bytesPerScanline / HW_MODE.vdm_bytespp ; - dga_modenum = vo_modelines[j].num; - modeline = vo_modelines + j; - + vo_dga_width = vo_modelines[j].bytesPerScanline / HW_MODE.vdm_bytespp; + dga_modenum = vo_modelines[j].num; + modeline = vo_modelines + j; + #else #ifdef HAVE_XF86VM - mp_msg(MSGT_VO, MSGL_INFO, - "vo_dga: DGA 1.0 compatibility code: Using XF86VidMode for mode switching!\n"); + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: DGA 1.0 compatibility code: Using XF86VidMode for mode switching!\n"); - if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error)) { - XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev); - mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: XF86VidMode Extension v%i.%i\n", vm_ver, vm_rev); - have_vm=1; - } else { - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: XF86VidMode Extension not available.\n"); - } + if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error)) + { + XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev); + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: XF86VidMode Extension v%i.%i\n", vm_ver, vm_rev); + have_vm = 1; + } else + { + mp_msg(MSGT_VO, MSGL_ERR, + "vo_dga: XF86VidMode Extension not available.\n"); + } #define GET_VREFRESH(dotclk, x, y)( (((dotclk)/(x))*1000)/(y) ) - - if (have_vm) { - int modecount; - XF86VidModeGetAllModeLines(mDisplay,mScreen,&modecount,&vo_dga_vidmodes); + + if (have_vm) + { + int modecount; + + XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount, + &vo_dga_vidmodes); - if(vo_dga_vidmodes != NULL ){ - for (i=0; i<modecount; i++){ - if ( check_res(i, wanted_width, wanted_height, - vo_dga_modes[vo_dga_hw_mode].vdm_depth, - vo_dga_vidmodes[i]->hdisplay, - vo_dga_vidmodes[i]->vdisplay, - GET_VREFRESH(vo_dga_vidmodes[i]->dotclock, - vo_dga_vidmodes[i]->htotal, - vo_dga_vidmodes[i]->vtotal), - 0, - &mX, &mY, &mVBI, &mMaxY )) j = i; - } - - mp_msg(MSGT_VO, MSGL_INFO, - "vo_dga: Selected video mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d, video %3d x %3d.\n", - mX, mY, mVBI, - vo_dga_modes[vo_dga_hw_mode].vdm_depth, - vo_dga_modes[vo_dga_hw_mode].vdm_bitspp, - width, height); - }else{ - mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: XF86VidMode returned no screens - using current resolution.\n"); + if (vo_dga_vidmodes != NULL) + { + for (i = 0; i < modecount; i++) + { + if (check_res(i, wanted_width, wanted_height, + vo_dga_modes[vo_dga_hw_mode].vdm_depth, + vo_dga_vidmodes[i]->hdisplay, + vo_dga_vidmodes[i]->vdisplay, + GET_VREFRESH(vo_dga_vidmodes[i]->dotclock, + vo_dga_vidmodes[i]->htotal, + vo_dga_vidmodes[i]->vtotal), + 0, &mX, &mY, &mVBI, &mMaxY)) + j = i; + } + + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: Selected video mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d, video %3d x %3d.\n", + mX, mY, mVBI, + vo_dga_modes[vo_dga_hw_mode].vdm_depth, + vo_dga_modes[vo_dga_hw_mode].vdm_bitspp, width, height); + } else + { + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: XF86VidMode returned no screens - using current resolution.\n"); + } + dga_modenum = j; + vo_dga_vp_width = mX; + vo_dga_vp_height = mY; } - dga_modenum = j; - vo_dga_vp_width = mX; - vo_dga_vp_height = mY; - } - #else - mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: Only have DGA 1.0 extension and no XF86VidMode :-(\n"); - mp_msg(MSGT_VO, MSGL_INFO, " Thus, resolution switching is NOT possible.\n"); + mp_msg(MSGT_VO, MSGL_INFO, + "vo_dga: Only have DGA 1.0 extension and no XF86VidMode :-(\n"); + mp_msg(MSGT_VO, MSGL_INFO, + " Thus, resolution switching is NOT possible.\n"); #endif #endif - vo_dga_src_width = width; - vo_dga_src_height = height; - - if(vo_dga_src_width > vo_dga_vp_width || - vo_dga_src_height > vo_dga_vp_height) - { - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: Sorry, video larger than viewport is not yet supported!\n"); - // ugly, do something nicer in the future ... + vo_dga_src_width = width; + vo_dga_src_height = height; + + if (vo_dga_src_width > vo_dga_vp_width || + vo_dga_src_height > vo_dga_vp_height) + { + mp_msg(MSGT_VO, MSGL_ERR, + "vo_dga: Sorry, video larger than viewport is not yet supported!\n"); + // ugly, do something nicer in the future ... #ifndef HAVE_DGA2 #ifdef HAVE_XF86VM - if(vo_dga_vidmodes){ - XFree(vo_dga_vidmodes); - vo_dga_vidmodes = NULL; - } + if (vo_dga_vidmodes) + { + XFree(vo_dga_vidmodes); + vo_dga_vidmodes = NULL; + } #endif #endif - return 1; - } + return 1; + } - if(vo_dga_vp_width == VO_DGA_INVALID_RES){ - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: Something is wrong with your DGA. There doesn't seem to be a\n" - " single suitable mode!\n" - " Please file a bug report (see DOCS/HTML/en/bugreports.html)\n"); + if (vo_dga_vp_width == VO_DGA_INVALID_RES) + { + mp_msg(MSGT_VO, MSGL_ERR, + "vo_dga: Something is wrong with your DGA. There doesn't seem to be a\n" + " single suitable mode!\n" + " Please file a bug report (see DOCS/HTML/en/bugreports.html)\n"); #ifndef HAVE_DGA2 #ifdef HAVE_XF86VM - if(vo_dga_vidmodes){ - XFree(vo_dga_vidmodes); - vo_dga_vidmodes = NULL; - } + if (vo_dga_vidmodes) + { + XFree(vo_dga_vidmodes); + vo_dga_vidmodes = NULL; + } #endif #endif - return 1; - } - + return 1; + } // now let's start the DGA thing - if ( !vo_config_count || width != prev_width || height != prev_height ) - { + if (!vo_config_count || width != prev_width || height != prev_height) + { #ifdef HAVE_DGA2 - if (!XDGAOpenFramebuffer(mDisplay, mScreen)){ - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: Framebuffer mapping failed!!!\n"); - return 1; - } + if (!XDGAOpenFramebuffer(mDisplay, mScreen)) + { + mp_msg(MSGT_VO, MSGL_ERR, + "vo_dga: Framebuffer mapping failed!!!\n"); + return 1; + } - dgadevice=XDGASetMode(mDisplay, mScreen, dga_modenum); - XDGASync(mDisplay, mScreen); + dgadevice = XDGASetMode(mDisplay, mScreen, dga_modenum); + XDGASync(mDisplay, mScreen); - vo_dga_base = dgadevice->data; - XFree(dgadevice); + vo_dga_base = dgadevice->data; + XFree(dgadevice); - XDGASetViewport (mDisplay, mScreen, 0, 0, XDGAFlipRetrace); - + XDGASetViewport(mDisplay, mScreen, 0, 0, XDGAFlipRetrace); + #else #ifdef HAVE_XF86VM - if (have_vm) - { - XF86VidModeLockModeSwitch(mDisplay,mScreen,0); - // Two calls are needed to switch modes on my ATI Rage 128. Why? - // for riva128 one call is enough! - XF86VidModeSwitchToMode(mDisplay,mScreen,vo_dga_vidmodes[dga_modenum]); - XF86VidModeSwitchToMode(mDisplay,mScreen,vo_dga_vidmodes[dga_modenum]); - } + if (have_vm) + { + XF86VidModeLockModeSwitch(mDisplay, mScreen, 0); + // Two calls are needed to switch modes on my ATI Rage 128. Why? + // for riva128 one call is enough! + XF86VidModeSwitchToMode(mDisplay, mScreen, + vo_dga_vidmodes[dga_modenum]); + XF86VidModeSwitchToMode(mDisplay, mScreen, + vo_dga_vidmodes[dga_modenum]); + } #endif - - XF86DGAGetViewPortSize(mDisplay,mScreen, - &vo_dga_vp_width, - &vo_dga_vp_height); + + XF86DGAGetViewPortSize(mDisplay, mScreen, + &vo_dga_vp_width, &vo_dga_vp_height); - XF86DGAGetVideo (mDisplay, mScreen, - (char **)&vo_dga_base, &vo_dga_width, &bank, &ram); + XF86DGAGetVideo(mDisplay, mScreen, + (char **) &vo_dga_base, &vo_dga_width, &bank, + &ram); - XF86DGADirectVideo (mDisplay, mScreen, - XF86DGADirectGraphics | XF86DGADirectMouse | - XF86DGADirectKeyb); - - XF86DGASetViewPort (mDisplay, mScreen, 0, 0); + XF86DGADirectVideo(mDisplay, mScreen, + XF86DGADirectGraphics | XF86DGADirectMouse | + XF86DGADirectKeyb); + + XF86DGASetViewPort(mDisplay, mScreen, 0, 0); #endif - } - - // do some more checkings here ... + } + // do some more checkings here ... - mp_msg(MSGT_VO, MSGL_V, "vo_dga: bytes/line: %d, screen res: %dx%d, depth: %d, base: %08x, bpp: %d\n", - vo_dga_width, vo_dga_vp_width, - vo_dga_vp_height, HW_MODE.vdm_bytespp, vo_dga_base, - HW_MODE.vdm_bitspp); + mp_msg(MSGT_VO, MSGL_V, + "vo_dga: bytes/line: %d, screen res: %dx%d, depth: %d, base: %08x, bpp: %d\n", + vo_dga_width, vo_dga_vp_width, vo_dga_vp_height, + HW_MODE.vdm_bytespp, vo_dga_base, HW_MODE.vdm_bitspp); + + x_off = (vo_dga_vp_width - vo_dga_src_width) >> 1; + y_off = (vo_dga_vp_height - vo_dga_src_height) >> 1; - x_off = (vo_dga_vp_width - vo_dga_src_width)>>1; - y_off = (vo_dga_vp_height - vo_dga_src_height)>>1; - - vo_dga_bytes_per_line = vo_dga_src_width * HW_MODE.vdm_bytespp; - vo_dga_lines = vo_dga_src_height; + vo_dga_bytes_per_line = vo_dga_src_width * HW_MODE.vdm_bytespp; + vo_dga_lines = vo_dga_src_height; - vo_dga_src_offset = 0; - vo_dga_vp_offset = (y_off * vo_dga_width + x_off ) * HW_MODE.vdm_bytespp; + vo_dga_src_offset = 0; + vo_dga_vp_offset = + (y_off * vo_dga_width + x_off) * HW_MODE.vdm_bytespp; - vo_dga_vp_skip = (vo_dga_width - vo_dga_src_width) * HW_MODE.vdm_bytespp; // todo - - mp_msg(MSGT_VO, MSGL_V, "vo_dga: vp_off=%d, vp_skip=%d, bpl=%d\n", - vo_dga_vp_offset, vo_dga_vp_skip, vo_dga_bytes_per_line); + vo_dga_vp_skip = (vo_dga_width - vo_dga_src_width) * HW_MODE.vdm_bytespp; // todo + + mp_msg(MSGT_VO, MSGL_V, "vo_dga: vp_off=%d, vp_skip=%d, bpl=%d\n", + vo_dga_vp_offset, vo_dga_vp_skip, vo_dga_bytes_per_line); + - - XGrabKeyboard (mDisplay, DefaultRootWindow(mDisplay), True, - GrabModeAsync,GrabModeAsync, CurrentTime); - if(vo_grabpointer) - XGrabPointer (mDisplay, DefaultRootWindow(mDisplay), True, - ButtonPressMask,GrabModeAsync, GrabModeAsync, - None, None, CurrentTime); + XGrabKeyboard(mDisplay, DefaultRootWindow(mDisplay), True, + GrabModeAsync, GrabModeAsync, CurrentTime); + if (vo_grabpointer) + XGrabPointer(mDisplay, DefaultRootWindow(mDisplay), True, + ButtonPressMask, GrabModeAsync, GrabModeAsync, + None, None, CurrentTime); - if ( !vo_config_count || width != prev_width || height != prev_height ) - { - init_video_buffers(vo_dga_base, - vo_dga_vp_height, - vo_dga_width * HW_MODE.vdm_bytespp, + if (!vo_config_count || width != prev_width || height != prev_height) + { + init_video_buffers(vo_dga_base, + vo_dga_vp_height, + vo_dga_width * HW_MODE.vdm_bytespp, #ifdef HAVE_DGA2 - modeline->maxViewportY, + modeline->maxViewportY, #else - vo_dga_vp_height, + vo_dga_vp_height, #endif - vo_doublebuffering); - prev_width=width; prev_height=height; - } + vo_doublebuffering); + prev_width = width; + prev_height = height; + } - mp_msg(MSGT_VO, MSGL_V, "vo_dga: Using %d frame buffer%s.\n", - vo_dga_nr_video_buffers, vo_dga_nr_video_buffers == 1 ? "" : "s"); - - vo_dga_is_running = 1; - return 0; + mp_msg(MSGT_VO, MSGL_V, "vo_dga: Using %d frame buffer%s.\n", + vo_dga_nr_video_buffers, + vo_dga_nr_video_buffers == 1 ? "" : "s"); + + vo_dga_is_running = 1; + return 0; } static int dga_depths_init = 0; static uint32_t preinit(const char *arg) { - if(arg) + if (arg) { - mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: Unknown subdevice: %s\n",arg); - return ENOSYS; + mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: Unknown subdevice: %s\n", arg); + return ENOSYS; } - if( !vo_init() ) return -1; // Can't open X11 + if (!vo_init()) + return -1; // Can't open X11 - if(dga_depths_init == 0){ // FIXME!? - int i; + if (dga_depths_init == 0) + { // FIXME!? + int i; - vo_dga_XServer_mode = vd_ValidateMode(vo_depthonscreen); + vo_dga_XServer_mode = vd_ValidateMode(vo_depthonscreen); - if(vo_dga_XServer_mode ==0){ + if (vo_dga_XServer_mode == 0) + { #ifndef HAVE_DGA2 - mp_msg(MSGT_VO, MSGL_ERR, "vo_dga: Your X-Server is not running in a "); - mp_msg(MSGT_VO, MSGL_ERR, "resolution supported by DGA driver!\n"); -#endif - }//else{ - // mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: X running at: %s\n", - // vd_GetModeString(vo_dga_XServer_mode)); - //} - + mp_msg(MSGT_VO, MSGL_ERR, + "vo_dga: Your X-Server is not running in a "); + mp_msg(MSGT_VO, MSGL_ERR, + "resolution supported by DGA driver!\n"); +#endif + } //else{ + // mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: X running at: %s\n", + // vd_GetModeString(vo_dga_XServer_mode)); + //} + #ifdef HAVE_DGA2 - vo_modelines=XDGAQueryModes(mDisplay, mScreen, &vo_modecount); - if(vo_modelines){ - for(i=0; i< vo_modecount; i++){ - mp_msg(MSGT_VO, MSGL_V, "vo_dga: (%03d) depth=%d, bpp=%d, r=%08x, g=%08x, b=%08x, %d x %d\n", - i, - vo_modelines[i].depth, - vo_modelines[i].bitsPerPixel, - vo_modelines[i].redMask, - vo_modelines[i].greenMask, - vo_modelines[i].blueMask, - vo_modelines[i].viewportWidth, - vo_modelines[i].viewportHeight); - vd_EnableMode( - vo_modelines[i].depth, - vo_modelines[i].bitsPerPixel, - vo_modelines[i].redMask, - vo_modelines[i].greenMask, - vo_modelines[i].blueMask); - } - } + vo_modelines = XDGAQueryModes(mDisplay, mScreen, &vo_modecount); + if (vo_modelines) + { + for (i = 0; i < vo_modecount; i++) + { + mp_msg(MSGT_VO, MSGL_V, + "vo_dga: (%03d) depth=%d, bpp=%d, r=%08x, g=%08x, b=%08x, %d x %d\n", + i, vo_modelines[i].depth, + vo_modelines[i].bitsPerPixel, + vo_modelines[i].redMask, vo_modelines[i].greenMask, + vo_modelines[i].blueMask, + vo_modelines[i].viewportWidth, + vo_modelines[i].viewportHeight); + vd_EnableMode(vo_modelines[i].depth, + vo_modelines[i].bitsPerPixel, + vo_modelines[i].redMask, + vo_modelines[i].greenMask, + vo_modelines[i].blueMask); + } + } #endif - dga_depths_init = 1; + dga_depths_init = 1; - if( !vo_dga_modes[1].vdm_supported && vo_dga_modes[2].vdm_supported ){ - vo_dga_modes[1].vdm_supported = 1; - } + if (!vo_dga_modes[1].vdm_supported + && vo_dga_modes[2].vdm_supported) + { + vo_dga_modes[1].vdm_supported = 1; + } - if( !vo_dga_modes[3].vdm_supported && vo_dga_modes[4].vdm_supported ){ - vo_dga_modes[3].vdm_supported = 1; - } + if (!vo_dga_modes[3].vdm_supported + && vo_dga_modes[4].vdm_supported) + { + vo_dga_modes[3].vdm_supported = 1; + } - for(i=1; i<vo_dga_mode_num; i++){ - mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: Mode: %s", vd_GetModeString(i)); - if(vo_dbpp && vo_dbpp != vo_dga_modes[i].vdm_mplayer_depth){ - vo_dga_modes[i].vdm_supported = 0; - mp_msg(MSGT_VO, MSGL_INFO, " ...disabled by -bpp %d", vo_dbpp ); - } - mp_msg(MSGT_VO, MSGL_INFO, "\n"); - } - } + for (i = 1; i < vo_dga_mode_num; i++) + { + mp_msg(MSGT_VO, MSGL_INFO, "vo_dga: Mode: %s", + vd_GetModeString(i)); + if (vo_dbpp && vo_dbpp != vo_dga_modes[i].vdm_mplayer_depth) + { + vo_dga_modes[i].vdm_supported = 0; + mp_msg(MSGT_VO, MSGL_INFO, " ...disabled by -bpp %d", + vo_dbpp); + } + mp_msg(MSGT_VO, MSGL_INFO, "\n"); + } + } return 0; } -static uint32_t get_image(mp_image_t *mpi) +static uint32_t get_image(mp_image_t * mpi) { - if ( - !IMGFMT_IS_BGR(mpi->imgfmt) || - (IMGFMT_BGR_DEPTH(mpi->imgfmt) != vo_dga_modes[vo_dga_hw_mode].vdm_mplayer_depth) || - (mpi->type==MP_IMGTYPE_STATIC && vo_dga_nr_video_buffers>1) || - (mpi->type==MP_IMGTYPE_IP && vo_dga_nr_video_buffers<2) || - (mpi->type==MP_IMGTYPE_IPB) - ) - return(VO_FALSE); - - if( (mpi->flags&MP_IMGFLAG_ACCEPT_STRIDE) || - (mpi->flags&MP_IMGFLAG_ACCEPT_WIDTH && - ((vo_dga_bytes_per_line+vo_dga_vp_skip)%(mpi->bpp/8))==0 ) || - (mpi->width*(mpi->bpp/8)==(vo_dga_bytes_per_line+vo_dga_vp_skip)) ){ - - mpi->planes[0] = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; - mpi->stride[0] = vo_dga_bytes_per_line + vo_dga_vp_skip; - mpi->width=(vo_dga_bytes_per_line+vo_dga_vp_skip)/(mpi->bpp/8); - mpi->flags |= MP_IMGFLAG_DIRECT; - return(VO_TRUE); + if (!IMGFMT_IS_BGR(mpi->imgfmt) || + (IMGFMT_BGR_DEPTH(mpi->imgfmt) != + vo_dga_modes[vo_dga_hw_mode].vdm_mplayer_depth) + || (mpi->type == MP_IMGTYPE_STATIC && vo_dga_nr_video_buffers > 1) + || (mpi->type == MP_IMGTYPE_IP && vo_dga_nr_video_buffers < 2) + || (mpi->type == MP_IMGTYPE_IPB)) + return (VO_FALSE); + + if ((mpi->flags & MP_IMGFLAG_ACCEPT_STRIDE) || + (mpi->flags & MP_IMGFLAG_ACCEPT_WIDTH && + ((vo_dga_bytes_per_line + vo_dga_vp_skip) % (mpi->bpp / 8)) == 0) + || (mpi->width * (mpi->bpp / 8) == + (vo_dga_bytes_per_line + vo_dga_vp_skip))) + { + + mpi->planes[0] = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; + mpi->stride[0] = vo_dga_bytes_per_line + vo_dga_vp_skip; + mpi->width = + (vo_dga_bytes_per_line + vo_dga_vp_skip) / (mpi->bpp / 8); + mpi->flags |= MP_IMGFLAG_DIRECT; + return (VO_TRUE); } - return(VO_FALSE); + return (VO_FALSE); } static uint32_t control(uint32_t request, void *data, ...) { - switch (request) { - case VOCTRL_GET_IMAGE: - return get_image(data); - case VOCTRL_QUERY_FORMAT: - return query_format(*((uint32_t*)data)); - } - return VO_NOTIMPL; + switch (request) + { + case VOCTRL_GET_IMAGE: + return get_image(data); + case VOCTRL_QUERY_FORMAT: + return query_format(*((uint32_t *) data)); + } + return VO_NOTIMPL; } //---------------------------------------------------------
--- a/libvo/vo_x11.c Sun Jun 13 21:34:29 2004 +0000 +++ b/libvo/vo_x11.c Mon Jun 14 04:53:03 2004 +0000 @@ -25,20 +25,21 @@ #include <X11/extensions/XShm.h> static int Shmem_Flag; + //static int Quiet_Flag; Here also what is this for. It's used but isn't inited ? static XShmSegmentInfo Shminfo[1]; static int gXErrorFlag; -static int CompletionType=-1; +static int CompletionType = -1; /* since it doesn't seem to be defined on some platforms */ -int XShmGetEventBase( Display* ); +int XShmGetEventBase(Display *); #endif #include "fastmemcpy.h" #include "sub.h" #include "../postproc/swscale.h" -#include "../postproc/swscale_internal.h" //FIXME +#include "../postproc/swscale_internal.h" //FIXME #include "../postproc/rgb2rgb.h" #include "../libmpcodecs/vf_scale.h" @@ -49,26 +50,26 @@ #include "../mplayer.h" #endif -static vo_info_t info = -{ - "X11 ( XImage/Shm )", - "x11", - "Aaron Holtzman <aholtzma@ess.engr.uvic.ca>", - "" +static vo_info_t info = { + "X11 ( XImage/Shm )", + "x11", + "Aaron Holtzman <aholtzma@ess.engr.uvic.ca>", + "" }; -LIBVO_EXTERN( x11 ) - +LIBVO_EXTERN(x11) /* private prototypes */ -static void Display_Image ( XImage * myximage,unsigned char *ImageData ); -static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); +static void Display_Image(XImage * myximage, unsigned char *ImageData); +static void (*draw_alpha_fnc) (int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride); /* local data */ static unsigned char *ImageData; /* X11 related variables */ static XImage *myximage = NULL; -static int depth,bpp,mode; +static int depth, bpp, mode; static XWindowAttributes attribs; static int int_pause; @@ -80,48 +81,69 @@ static uint32_t image_width; static uint32_t image_height; static uint32_t in_format; -static uint32_t out_format=0; -static int srcW=-1; -static int srcH=-1; -static int aspect; // 1<<16 based fixed point aspect, so that the aspect stays correct during resizing +static uint32_t out_format = 0; +static int srcW = -1; +static int srcH = -1; +static int aspect; // 1<<16 based fixed point aspect, so that the aspect stays correct during resizing -static int old_vo_dwidth=-1; -static int old_vo_dheight=-1; +static int old_vo_dwidth = -1; +static int old_vo_dheight = -1; + +static void check_events() +{ + int ret = vo_x11_check_events(mDisplay); -static void check_events(){ - int ret = vo_x11_check_events(mDisplay); - - /* clear left over borders and redraw frame if we are paused */ - if ( ret & VO_EVENT_EXPOSE && int_pause) - { - vo_x11_clearwindow_part(mDisplay, vo_window, myximage->width, myximage->height, 0); - flip_page(); - } else - if ( (ret & VO_EVENT_RESIZE)||(ret & VO_EVENT_EXPOSE) ) - vo_x11_clearwindow_part(mDisplay, vo_window, myximage->width, myximage->height, 0); - + /* clear left over borders and redraw frame if we are paused */ + if (ret & VO_EVENT_EXPOSE && int_pause) + { + vo_x11_clearwindow_part(mDisplay, vo_window, myximage->width, + myximage->height, 0); + flip_page(); + } else if ((ret & VO_EVENT_RESIZE) || (ret & VO_EVENT_EXPOSE)) + vo_x11_clearwindow_part(mDisplay, vo_window, myximage->width, + myximage->height, 0); + +} + +static void draw_alpha_32(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ + vo_draw_alpha_rgb32(w, h, src, srca, stride, + ImageData + 4 * (y0 * image_width + x0), + 4 * image_width); } -static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb32(w,h,src,srca,stride,ImageData+4*(y0*image_width+x0),4*image_width); +static void draw_alpha_24(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ + vo_draw_alpha_rgb24(w, h, src, srca, stride, + ImageData + 3 * (y0 * image_width + x0), + 3 * image_width); } -static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb24(w,h,src,srca,stride,ImageData+3*(y0*image_width+x0),3*image_width); +static void draw_alpha_16(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ + vo_draw_alpha_rgb16(w, h, src, srca, stride, + ImageData + 2 * (y0 * image_width + x0), + 2 * image_width); } -static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb16(w,h,src,srca,stride,ImageData+2*(y0*image_width+x0),2*image_width); +static void draw_alpha_15(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) +{ + vo_draw_alpha_rgb15(w, h, src, srca, stride, + ImageData + 2 * (y0 * image_width + x0), + 2 * image_width); } -static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb15(w,h,src,srca,stride,ImageData+2*(y0*image_width+x0),2*image_width); +static void draw_alpha_null(int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride) +{ } -static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ -} - -static SwsContext *swsContext=NULL; +static SwsContext *swsContext = NULL; extern int sws_flags; static XVisualInfo vinfo; @@ -129,464 +151,557 @@ static void getMyXImage() { #ifdef HAVE_SHM - if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag=1; - else - { - Shmem_Flag=0; - mp_msg(MSGT_VO,MSGL_WARN, "Shared memory not supported\nReverting to normal Xlib\n" ); - } - if ( Shmem_Flag ) CompletionType=XShmGetEventBase( mDisplay ) + ShmCompletion; + if (mLocalDisplay && XShmQueryExtension(mDisplay)) + Shmem_Flag = 1; + else + { + Shmem_Flag = 0; + mp_msg(MSGT_VO, MSGL_WARN, + "Shared memory not supported\nReverting to normal Xlib\n"); + } + if (Shmem_Flag) + CompletionType = XShmGetEventBase(mDisplay) + ShmCompletion; - if ( Shmem_Flag ) - { - myximage=XShmCreateImage( mDisplay,vinfo.visual,depth,ZPixmap,NULL,&Shminfo[0],image_width,image_height ); - if ( myximage == NULL ) + if (Shmem_Flag) { - if ( myximage != NULL ) XDestroyImage( myximage ); - mp_msg(MSGT_VO,MSGL_WARN,"Shared memory error,disabling ( Ximage error )\n" ); - goto shmemerror; - } - Shminfo[0].shmid=shmget( IPC_PRIVATE, - myximage->bytes_per_line * myximage->height , - IPC_CREAT | 0777 ); - if ( Shminfo[0].shmid < 0 ) - { - XDestroyImage( myximage ); - mp_msg(MSGT_VO,MSGL_V, "%s\n",strerror( errno ) ); - //perror( strerror( errno ) ); - mp_msg(MSGT_VO,MSGL_WARN,"Shared memory error,disabling ( seg id error )\n" ); - goto shmemerror; - } - Shminfo[0].shmaddr=( char * ) shmat( Shminfo[0].shmid,0,0 ); + myximage = + XShmCreateImage(mDisplay, vinfo.visual, depth, ZPixmap, NULL, + &Shminfo[0], image_width, image_height); + if (myximage == NULL) + { + if (myximage != NULL) + XDestroyImage(myximage); + mp_msg(MSGT_VO, MSGL_WARN, + "Shared memory error,disabling ( Ximage error )\n"); + goto shmemerror; + } + Shminfo[0].shmid = shmget(IPC_PRIVATE, + myximage->bytes_per_line * + myximage->height, IPC_CREAT | 0777); + if (Shminfo[0].shmid < 0) + { + XDestroyImage(myximage); + mp_msg(MSGT_VO, MSGL_V, "%s\n", strerror(errno)); + //perror( strerror( errno ) ); + mp_msg(MSGT_VO, MSGL_WARN, + "Shared memory error,disabling ( seg id error )\n"); + goto shmemerror; + } + Shminfo[0].shmaddr = (char *) shmat(Shminfo[0].shmid, 0, 0); - if ( Shminfo[0].shmaddr == ( ( char * ) -1 ) ) - { - XDestroyImage( myximage ); - if ( Shminfo[0].shmaddr != ( ( char * ) -1 ) ) shmdt( Shminfo[0].shmaddr ); - mp_msg(MSGT_VO,MSGL_WARN, "Shared memory error,disabling ( address error )\n" ); - goto shmemerror; - } - myximage->data=Shminfo[0].shmaddr; - ImageData=( unsigned char * ) myximage->data; - Shminfo[0].readOnly=False; - XShmAttach( mDisplay,&Shminfo[0] ); + if (Shminfo[0].shmaddr == ((char *) -1)) + { + XDestroyImage(myximage); + if (Shminfo[0].shmaddr != ((char *) -1)) + shmdt(Shminfo[0].shmaddr); + mp_msg(MSGT_VO, MSGL_WARN, + "Shared memory error,disabling ( address error )\n"); + goto shmemerror; + } + myximage->data = Shminfo[0].shmaddr; + ImageData = (unsigned char *) myximage->data; + Shminfo[0].readOnly = False; + XShmAttach(mDisplay, &Shminfo[0]); - XSync( mDisplay,False ); + XSync(mDisplay, False); - if ( gXErrorFlag ) - { - XDestroyImage( myximage ); - shmdt( Shminfo[0].shmaddr ); - mp_msg(MSGT_VO,MSGL_WARN, "Shared memory error,disabling.\n" ); - gXErrorFlag=0; - goto shmemerror; - } - else - shmctl( Shminfo[0].shmid,IPC_RMID,0 ); + if (gXErrorFlag) + { + XDestroyImage(myximage); + shmdt(Shminfo[0].shmaddr); + mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling.\n"); + gXErrorFlag = 0; + goto shmemerror; + } else + shmctl(Shminfo[0].shmid, IPC_RMID, 0); + + { + static int firstTime = 1; - { - static int firstTime=1; - if ( firstTime){ - mp_msg(MSGT_VO,MSGL_V, "Sharing memory.\n" ); - firstTime=0; - } - } - } - else - { - shmemerror: - Shmem_Flag=0; + if (firstTime) + { + mp_msg(MSGT_VO, MSGL_V, "Sharing memory.\n"); + firstTime = 0; + } + } + } else + { + shmemerror: + Shmem_Flag = 0; #endif - myximage=XGetImage( mDisplay,vo_window,0,0, - image_width,image_height,AllPlanes,ZPixmap ); - ImageData=myximage->data; + myximage = XGetImage(mDisplay, vo_window, 0, 0, + image_width, image_height, AllPlanes, + ZPixmap); + ImageData = myximage->data; #ifdef HAVE_SHM - } + } #endif } static void freeMyXImage() { #ifdef HAVE_SHM - if ( Shmem_Flag ) - { - XShmDetach( mDisplay,&Shminfo[0] ); - XDestroyImage( myximage ); - shmdt( Shminfo[0].shmaddr ); - } - else + if (Shmem_Flag) + { + XShmDetach(mDisplay, &Shminfo[0]); + XDestroyImage(myximage); + shmdt(Shminfo[0].shmaddr); + } else #endif - { - XDestroyImage( myximage ); - } - myximage=NULL; + { + XDestroyImage(myximage); + } + myximage = NULL; } -static uint32_t config( uint32_t width,uint32_t height,uint32_t d_width,uint32_t d_height,uint32_t flags,char *title,uint32_t format) +static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, + uint32_t d_height, uint32_t flags, char *title, + uint32_t format) { // int screen; - int fullscreen=0; - int vm=0; + int fullscreen = 0; + int vm = 0; + // int interval, prefer_blank, allow_exp, nothing; - unsigned int fg,bg; - XEvent xev; - XGCValues xgcv; - Colormap theCmap; - XSetWindowAttributes xswa; - unsigned long xswamask; + unsigned int fg, bg; + XEvent xev; + XGCValues xgcv; + Colormap theCmap; + XSetWindowAttributes xswa; + unsigned long xswamask; + #ifdef HAVE_XF86VM - unsigned int modeline_width, modeline_height; - static uint32_t vm_width; - static uint32_t vm_height; + unsigned int modeline_width, modeline_height; + static uint32_t vm_width; + static uint32_t vm_height; #endif - vo_mouse_autohide=1; - old_vo_dwidth=-1; - old_vo_dheight=-1; + vo_mouse_autohide = 1; + old_vo_dwidth = -1; + old_vo_dheight = -1; - if (!title) - title = strdup("MPlayer X11 (XImage/Shm) render"); + if (!title) + title = strdup("MPlayer X11 (XImage/Shm) render"); - in_format=format; - srcW= width; - srcH= height; - vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; - geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); - vo_dwidth=d_width; vo_dheight=d_height; - - if( flags&0x03 ) fullscreen = 1; - if( flags&0x02 ) vm = 1; - if( flags&0x08 ) Flip_Flag = 1; - zoomFlag = flags&0x04; + in_format = format; + srcW = width; + srcH = height; + vo_dx = (vo_screenwidth - d_width) / 2; + vo_dy = (vo_screenheight - d_height) / 2; + geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, + vo_screenheight); + vo_dwidth = d_width; + vo_dheight = d_height; - int_pause = 0; + if (flags & 0x03) + fullscreen = 1; + if (flags & 0x02) + vm = 1; + if (flags & 0x08) + Flip_Flag = 1; + zoomFlag = flags & 0x04; + + int_pause = 0; // if(!fullscreen) zoomFlag=1; //it makes no sense to avoid zooming on windowd mode - + //printf( "w: %d h: %d\n\n",vo_dwidth,vo_dheight ); - XGetWindowAttributes( mDisplay,mRootWin,&attribs ); - depth=attribs.depth; + XGetWindowAttributes(mDisplay, mRootWin, &attribs); + depth = attribs.depth; + + if (depth != 15 && depth != 16 && depth != 24 && depth != 32) + { + Visual *visual; - if ( depth != 15 && depth != 16 && depth != 24 && depth != 32 ) { - Visual *visual; - depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual); - } - if ( !XMatchVisualInfo( mDisplay,mScreen,depth,DirectColor,&vinfo ) || - (WinID > 0 && vinfo.visualid != XVisualIDFromVisual(attribs.visual))) - XMatchVisualInfo( mDisplay,mScreen,depth,TrueColor,&vinfo ); + depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual); + } + if (!XMatchVisualInfo(mDisplay, mScreen, depth, DirectColor, &vinfo) || + (WinID > 0 + && vinfo.visualid != XVisualIDFromVisual(attribs.visual))) + XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); - /* set image size (which is indeed neither the input nor output size), - if zoom is on it will be changed during draw_slice anyway so we don't duplicate the aspect code here - */ - image_width=(width + 7) & (~7); - image_height=height; + /* set image size (which is indeed neither the input nor output size), + if zoom is on it will be changed during draw_slice anyway so we don't duplicate the aspect code here + */ + image_width = (width + 7) & (~7); + image_height = height; - aspect= ((1<<16)*d_width + d_height/2)/d_height; + aspect = ((1 << 16) * d_width + d_height / 2) / d_height; #ifdef HAVE_NEW_GUI - if(use_gui) guiGetEvent( guiSetShVideo,0 ); // the GUI will set up / resize the window - else -#endif - { + if (use_gui) + guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize the window + else +#endif + { #ifdef HAVE_XF86VM - if ( vm ) - { - if ((d_width==0) && (d_height==0)) - { vm_width=image_width; vm_height=image_height; } - else - { vm_width=d_width; vm_height=d_height; } - vo_vm_switch(vm_width, vm_height,&modeline_width, &modeline_height); - vo_dx=(vo_screenwidth-modeline_width)/2; - vo_dy=(vo_screenheight-modeline_height)/2; - vo_dwidth=modeline_width; - vo_dheight=modeline_height; - } + if (vm) + { + if ((d_width == 0) && (d_height == 0)) + { + vm_width = image_width; + vm_height = image_height; + } else + { + vm_width = d_width; + vm_height = d_height; + } + vo_vm_switch(vm_width, vm_height, &modeline_width, + &modeline_height); + vo_dx = (vo_screenwidth - modeline_width) / 2; + vo_dy = (vo_screenheight - modeline_height) / 2; + vo_dwidth = modeline_width; + vo_dheight = modeline_height; + } #endif - bg=WhitePixel( mDisplay,mScreen ); - fg=BlackPixel( mDisplay,mScreen ); + bg = WhitePixel(mDisplay, mScreen); + fg = BlackPixel(mDisplay, mScreen); - theCmap=vo_x11_create_colormap(&vinfo); + theCmap = vo_x11_create_colormap(&vinfo); - xswa.background_pixel=0; - xswa.border_pixel=0; - xswa.colormap=theCmap; - xswamask=CWBackPixel | CWBorderPixel | CWColormap; + xswa.background_pixel = 0; + xswa.border_pixel = 0; + xswa.colormap = theCmap; + xswamask = CWBackPixel | CWBorderPixel | CWColormap; #ifdef HAVE_XF86VM - if ( vm ) - { - xswa.override_redirect=True; - xswamask|=CWOverrideRedirect; - } + if (vm) + { + xswa.override_redirect = True; + xswamask |= CWOverrideRedirect; + } #endif - - if ( WinID>=0 ){ - vo_window = WinID ? ((Window)WinID) : mRootWin; - if ( WinID ) - { - XUnmapWindow( mDisplay,vo_window ); - XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xswa ); - vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask ); - XMapWindow( mDisplay,vo_window ); - } else XSelectInput( mDisplay,vo_window,ExposureMask ); - } - else - { - if ( vo_window == None ) - { - vo_window=vo_x11_create_smooth_window( mDisplay,mRootWin,vinfo.visual, vo_dx, vo_dy, vo_dwidth, vo_dheight, depth, theCmap ); + + if (WinID >= 0) + { + vo_window = WinID ? ((Window) WinID) : mRootWin; + if (WinID) + { + XUnmapWindow(mDisplay, vo_window); + XChangeWindowAttributes(mDisplay, vo_window, xswamask, + &xswa); + vo_x11_selectinput_witherr(mDisplay, vo_window, + StructureNotifyMask | + KeyPressMask | + PropertyChangeMask | + PointerMotionMask | + ButtonPressMask | + ButtonReleaseMask | + ExposureMask); + XMapWindow(mDisplay, vo_window); + } else + XSelectInput(mDisplay, vo_window, ExposureMask); + } else + { + if (vo_window == None) + { + vo_window = + vo_x11_create_smooth_window(mDisplay, mRootWin, + vinfo.visual, vo_dx, vo_dy, + vo_dwidth, vo_dheight, + depth, theCmap); - vo_x11_classhint( mDisplay,vo_window,"x11" ); - vo_hidecursor(mDisplay,vo_window); - vo_x11_sizehint( vo_dx,vo_dy,vo_dwidth,vo_dheight,0 ); - XSelectInput( mDisplay,vo_window,StructureNotifyMask ); - XStoreName( mDisplay,vo_window,title ); - XMapWindow( mDisplay,vo_window ); + vo_x11_classhint(mDisplay, vo_window, "x11"); + vo_hidecursor(mDisplay, vo_window); + vo_x11_sizehint(vo_dx, vo_dy, vo_dwidth, vo_dheight, 0); + XSelectInput(mDisplay, vo_window, StructureNotifyMask); + XStoreName(mDisplay, vo_window, title); + XMapWindow(mDisplay, vo_window); // if(WinID!=0) - do { XNextEvent( mDisplay,&xev ); } while ( xev.type != MapNotify || xev.xmap.event != vo_window ); - - if ( fullscreen ) vo_x11_fullscreen(); + do + { + XNextEvent(mDisplay, &xev); + } + while (xev.type != MapNotify + || xev.xmap.event != vo_window); + + if (fullscreen) + vo_x11_fullscreen(); #ifdef HAVE_XINERAMA - vo_x11_xinerama_move(mDisplay,vo_window); + vo_x11_xinerama_move(mDisplay, vo_window); #endif - } else if ( !fullscreen ) XMoveResizeWindow( mDisplay,vo_window,vo_dx,vo_dy,vo_dwidth,vo_dheight ); - } + } else if (!fullscreen) + XMoveResizeWindow(mDisplay, vo_window, vo_dx, vo_dy, + vo_dwidth, vo_dheight); + } - XFlush( mDisplay ); - XSync( mDisplay,False ); + XFlush(mDisplay); + XSync(mDisplay, False); - // we cannot grab mouse events on root window :( - vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | ExposureMask | - ((WinID==0)?0:(ButtonPressMask | ButtonReleaseMask | PointerMotionMask)) ); + // we cannot grab mouse events on root window :( + vo_x11_selectinput_witherr(mDisplay, vo_window, + StructureNotifyMask | KeyPressMask | + PropertyChangeMask | ExposureMask | + ((WinID == + 0) ? 0 : (ButtonPressMask | + ButtonReleaseMask | + PointerMotionMask))); #ifdef HAVE_XF86VM - if ( vm ) - { - /* Grab the mouse pointer in our window */ - if(vo_grabpointer) - XGrabPointer(mDisplay, vo_window, True, 0, - GrabModeAsync, GrabModeAsync, - vo_window, None, CurrentTime); - XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); - } + if (vm) + { + /* Grab the mouse pointer in our window */ + if (vo_grabpointer) + XGrabPointer(mDisplay, vo_window, True, 0, + GrabModeAsync, GrabModeAsync, + vo_window, None, CurrentTime); + XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); + } #endif - } + } - if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc ); - vo_gc=XCreateGC( mDisplay,vo_window,0L,&xgcv ); - - if ( myximage ) - { - freeMyXImage(); - sws_freeContext(swsContext); - } - getMyXImage(); - - if ( !WinID ) - { vo_dwidth=vo_screenwidth; vo_dheight=vo_screenheight; } + if (vo_gc != None) + XFreeGC(mDisplay, vo_gc); + vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv); + + if (myximage) + { + freeMyXImage(); + sws_freeContext(swsContext); + } + getMyXImage(); + + if (!WinID) + { + vo_dwidth = vo_screenwidth; + vo_dheight = vo_screenheight; + } - switch ((bpp=myximage->bits_per_pixel)){ - case 24: draw_alpha_fnc=draw_alpha_24; - out_format= IMGFMT_BGR24; break; - case 32: draw_alpha_fnc=draw_alpha_32; - out_format= IMGFMT_BGR32; break; - case 15: - case 16: if (depth==15){ - draw_alpha_fnc=draw_alpha_15; - out_format= IMGFMT_BGR15; - }else{ - draw_alpha_fnc=draw_alpha_16; - out_format= IMGFMT_BGR16; - }break; - case 8: draw_alpha_fnc=draw_alpha_null; - out_format= IMGFMT_BGR8; break; - default: draw_alpha_fnc=draw_alpha_null; - } + switch ((bpp = myximage->bits_per_pixel)) + { + case 24: + draw_alpha_fnc = draw_alpha_24; + out_format = IMGFMT_BGR24; + break; + case 32: + draw_alpha_fnc = draw_alpha_32; + out_format = IMGFMT_BGR32; + break; + case 15: + case 16: + if (depth == 15) + { + draw_alpha_fnc = draw_alpha_15; + out_format = IMGFMT_BGR15; + } else + { + draw_alpha_fnc = draw_alpha_16; + out_format = IMGFMT_BGR16; + } + break; + case 8: + draw_alpha_fnc = draw_alpha_null; + out_format = IMGFMT_BGR8; + break; + default: + draw_alpha_fnc = draw_alpha_null; + } - /* always allocate swsContext as size could change between frames */ - swsContext= sws_getContextFromCmdLine(width, height, in_format, width, height, out_format ); - if (!swsContext) - return -1; + /* always allocate swsContext as size could change between frames */ + swsContext = + sws_getContextFromCmdLine(width, height, in_format, width, height, + out_format); + if (!swsContext) + return -1; - //printf( "X11 bpp: %d color mask: R:%lX G:%lX B:%lX\n",bpp,myximage->red_mask,myximage->green_mask,myximage->blue_mask ); + //printf( "X11 bpp: %d color mask: R:%lX G:%lX B:%lX\n",bpp,myximage->red_mask,myximage->green_mask,myximage->blue_mask ); - // If we have blue in the lowest bit then obviously RGB - mode=( ( myximage->blue_mask & 0x01 ) != 0 ) ? MODE_RGB : MODE_BGR; + // If we have blue in the lowest bit then obviously RGB + mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR; #ifdef WORDS_BIGENDIAN - if ( myximage->byte_order != MSBFirst ) + if (myximage->byte_order != MSBFirst) #else - if ( myximage->byte_order != LSBFirst ) + if (myximage->byte_order != LSBFirst) #endif - { - mode=( ( myximage->blue_mask & 0x01 ) != 0 ) ? MODE_BGR : MODE_RGB; + { + mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_BGR : MODE_RGB; // printf( "No support for non-native XImage byte order!\n" ); // return -1; - } - + } #ifdef WORDS_BIGENDIAN - if(mode==MODE_BGR && bpp!=32){ - mp_msg(MSGT_VO,MSGL_ERR,"BGR%d not supported, please contact the developers\n", bpp); - return -1; - } + if (mode == MODE_BGR && bpp != 32) + { + mp_msg(MSGT_VO, MSGL_ERR, + "BGR%d not supported, please contact the developers\n", + bpp); + return -1; + } #else - if(mode==MODE_BGR){ - mp_msg(MSGT_VO,MSGL_ERR,"BGR not supported, please contact the developers\n"); - return -1; - } -#endif + if (mode == MODE_BGR) + { + mp_msg(MSGT_VO, MSGL_ERR, + "BGR not supported, please contact the developers\n"); + return -1; + } +#endif - saver_off(mDisplay); + saver_off(mDisplay); - if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); + if (vo_ontop) + vo_x11_setlayer(mDisplay, vo_window, vo_ontop); - return 0; + return 0; } -static void Display_Image( XImage *myximage,uint8_t *ImageData ) +static void Display_Image(XImage * myximage, uint8_t * ImageData) { #ifdef HAVE_SHM - if ( Shmem_Flag ) - { - XShmPutImage( mDisplay,vo_window,vo_gc,myximage, - 0,0, - ( vo_dwidth - swsContext->dstW ) / 2,( vo_dheight - myximage->height ) / 2, - swsContext->dstW,myximage->height,True ); - } - else + if (Shmem_Flag) + { + XShmPutImage(mDisplay, vo_window, vo_gc, myximage, + 0, 0, + (vo_dwidth - swsContext->dstW) / 2, + (vo_dheight - myximage->height) / 2, swsContext->dstW, + myximage->height, True); + } else #endif - { - XPutImage( mDisplay,vo_window,vo_gc,myximage, - 0,0, - ( vo_dwidth - swsContext->dstW ) / 2,( vo_dheight - myximage->height ) / 2, - swsContext->dstW,myximage->height); - } + { + XPutImage(mDisplay, vo_window, vo_gc, myximage, + 0, 0, + (vo_dwidth - swsContext->dstW) / 2, + (vo_dheight - myximage->height) / 2, swsContext->dstW, + myximage->height); + } } static void draw_osd(void) -{ vo_draw_text(image_width,image_height,draw_alpha_fnc); } +{ + vo_draw_text(image_width, image_height, draw_alpha_fnc); +} -static void flip_page( void ){ - Display_Image( myximage,ImageData ); +static void flip_page(void) +{ + Display_Image(myximage, ImageData); XSync(mDisplay, False); } -static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) +static uint32_t draw_slice(uint8_t * src[], int stride[], int w, int h, + int x, int y) { - uint8_t *dst[3]; - int dstStride[3]; + uint8_t *dst[3]; + int dstStride[3]; - if((old_vo_dwidth != vo_dwidth || old_vo_dheight != vo_dheight) /*&& y==0*/ && zoomFlag) - { - int newW= vo_dwidth; - int newH= vo_dheight; - int newAspect= (newW*(1<<16) + (newH>>1))/newH; - SwsContext *oldContext= swsContext; - - if(newAspect>aspect) newW= (newH*aspect + (1<<15))>>16; - else newH= ((newW<<16) + (aspect>>1)) /aspect; + if ((old_vo_dwidth != vo_dwidth + || old_vo_dheight != vo_dheight) /*&& y==0 */ && zoomFlag) + { + int newW = vo_dwidth; + int newH = vo_dheight; + int newAspect = (newW * (1 << 16) + (newH >> 1)) / newH; + SwsContext *oldContext = swsContext; - old_vo_dwidth= vo_dwidth; - old_vo_dheight= vo_dheight; - - if(sws_flags==0) newW&= (~31); // not needed but, if the user wants the FAST_BILINEAR SCALER, then its needed + if (newAspect > aspect) + newW = (newH * aspect + (1 << 15)) >> 16; + else + newH = ((newW << 16) + (aspect >> 1)) / aspect; - swsContext= sws_getContextFromCmdLine(srcW, srcH, in_format, - newW, newH, out_format); - if(swsContext) - { - image_width= (newW+7)&(~7); - image_height= newH; + old_vo_dwidth = vo_dwidth; + old_vo_dheight = vo_dheight; + + if (sws_flags == 0) + newW &= (~31); // not needed but, if the user wants the FAST_BILINEAR SCALER, then its needed - freeMyXImage(); - getMyXImage(); - sws_freeContext(oldContext); - } - else - { - swsContext= oldContext; - } - } - dstStride[1]= - dstStride[2]=0; - dst[1]= - dst[2]=NULL; + swsContext = sws_getContextFromCmdLine(srcW, srcH, in_format, + newW, newH, out_format); + if (swsContext) + { + image_width = (newW + 7) & (~7); + image_height = newH; - if(Flip_Flag) - { - dstStride[0]= -image_width*((bpp+7)/8); - dst[0]=ImageData - dstStride[0]*(image_height-1); - sws_scale_ordered(swsContext,src,stride,y,h,dst, dstStride); - } - else - { - dstStride[0]=image_width*((bpp+7)/8); - dst[0]=ImageData; - sws_scale_ordered(swsContext,src,stride,y,h,dst, dstStride); - } - return 0; + freeMyXImage(); + getMyXImage(); + sws_freeContext(oldContext); + } else + { + swsContext = oldContext; + } + } + dstStride[1] = dstStride[2] = 0; + dst[1] = dst[2] = NULL; + + if (Flip_Flag) + { + dstStride[0] = -image_width * ((bpp + 7) / 8); + dst[0] = ImageData - dstStride[0] * (image_height - 1); + sws_scale_ordered(swsContext, src, stride, y, h, dst, dstStride); + } else + { + dstStride[0] = image_width * ((bpp + 7) / 8); + dst[0] = ImageData; + sws_scale_ordered(swsContext, src, stride, y, h, dst, dstStride); + } + return 0; } -static uint32_t draw_frame( uint8_t *src[] ){ +static uint32_t draw_frame(uint8_t * src[]) +{ #if 0 - int stride[3]= {0,0,0}; - - if (in_format==IMGFMT_YUY2) stride[0]=srcW*2; - else if(in_format==IMGFMT_BGR8) stride[0]=srcW; - else if(in_format==IMGFMT_BGR15) stride[0]=srcW*2; - else if(in_format==IMGFMT_BGR16) stride[0]=srcW*2; - else if(in_format==IMGFMT_BGR24) stride[0]=srcW*3; - else if(in_format==IMGFMT_BGR32) stride[0]=srcW*4; - - return draw_slice(src, stride, srcW, srcH, 0, 0); + int stride[3] = { 0, 0, 0 }; + + if (in_format == IMGFMT_YUY2) + stride[0] = srcW * 2; + else if (in_format == IMGFMT_BGR8) + stride[0] = srcW; + else if (in_format == IMGFMT_BGR15) + stride[0] = srcW * 2; + else if (in_format == IMGFMT_BGR16) + stride[0] = srcW * 2; + else if (in_format == IMGFMT_BGR24) + stride[0] = srcW * 3; + else if (in_format == IMGFMT_BGR32) + stride[0] = srcW * 4; + + return draw_slice(src, stride, srcW, srcH, 0, 0); #else printf("draw_frame() called!!!!!!\n"); return -1; #endif } -static uint32_t get_image(mp_image_t *mpi) +static uint32_t get_image(mp_image_t * mpi) { if (zoomFlag || - !IMGFMT_IS_BGR(mpi->imgfmt) || - (IMGFMT_BGR_DEPTH(mpi->imgfmt) != vo_depthonscreen) || - ((mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) || - (mpi->flags & MP_IMGFLAG_PLANAR) || - (mpi->flags & MP_IMGFLAG_YUV) || - (mpi->width != image_width) || - (mpi->height != image_height) - ) - return(VO_FALSE); + !IMGFMT_IS_BGR(mpi->imgfmt) || + (IMGFMT_BGR_DEPTH(mpi->imgfmt) != vo_depthonscreen) || + ((mpi->type != MP_IMGTYPE_STATIC) + && (mpi->type != MP_IMGTYPE_TEMP)) + || (mpi->flags & MP_IMGFLAG_PLANAR) + || (mpi->flags & MP_IMGFLAG_YUV) || (mpi->width != image_width) + || (mpi->height != image_height)) + return (VO_FALSE); if (Flip_Flag) { - mpi->stride[0] = -image_width*((bpp+7)/8); - mpi->planes[0] = ImageData - mpi->stride[0]*(image_height-1); - } - else + mpi->stride[0] = -image_width * ((bpp + 7) / 8); + mpi->planes[0] = ImageData - mpi->stride[0] * (image_height - 1); + } else { - mpi->stride[0] = image_width*((bpp+7)/8); - mpi->planes[0] = ImageData; + mpi->stride[0] = image_width * ((bpp + 7) / 8); + mpi->planes[0] = ImageData; } mpi->flags |= MP_IMGFLAG_DIRECT; - - return(VO_TRUE); + + return (VO_TRUE); } -static uint32_t query_format( uint32_t format ) +static uint32_t query_format(uint32_t format) { - mp_msg(MSGT_VO,MSGL_DBG2,"vo_x11: query_format was called: %x (%s)\n",format,vo_format_name(format)); + mp_msg(MSGT_VO, MSGL_DBG2, + "vo_x11: query_format was called: %x (%s)\n", format, + vo_format_name(format)); if (IMGFMT_IS_BGR(format)) { - if (IMGFMT_BGR_DEPTH(format) <= 8) - return 0; // TODO 8bpp not yet fully implemented - if (IMGFMT_BGR_DEPTH(format) == vo_depthonscreen) - return 3|VFCAP_OSD|VFCAP_SWSCALE|VFCAP_FLIP|VFCAP_ACCEPT_STRIDE; - else - return 1|VFCAP_OSD|VFCAP_SWSCALE|VFCAP_FLIP|VFCAP_ACCEPT_STRIDE; + if (IMGFMT_BGR_DEPTH(format) <= 8) + return 0; // TODO 8bpp not yet fully implemented + if (IMGFMT_BGR_DEPTH(format) == vo_depthonscreen) + return 3 | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_FLIP | + VFCAP_ACCEPT_STRIDE; + else + return 1 | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_FLIP | + VFCAP_ACCEPT_STRIDE; } - switch( format ) - { + switch (format) + { // case IMGFMT_BGR8: // case IMGFMT_BGR15: // case IMGFMT_BGR16: @@ -594,82 +709,91 @@ // case IMGFMT_BGR32: // return 0x2; // case IMGFMT_YUY2: - case IMGFMT_I420: - case IMGFMT_IYUV: - case IMGFMT_YV12: - return 1|VFCAP_OSD|VFCAP_SWSCALE|VFCAP_ACCEPT_STRIDE; - } - return 0; + case IMGFMT_I420: + case IMGFMT_IYUV: + case IMGFMT_YV12: + return 1 | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_ACCEPT_STRIDE; + } + return 0; } static void uninit(void) { - if(!myximage) return; - - freeMyXImage(); - saver_on(mDisplay); // screen saver back on + if (!myximage) + return; + + freeMyXImage(); + saver_on(mDisplay); // screen saver back on #ifdef HAVE_XF86VM - vo_vm_close(mDisplay); + vo_vm_close(mDisplay); #endif - zoomFlag=0; - vo_x11_uninit(); + zoomFlag = 0; + vo_x11_uninit(); - sws_freeContext(swsContext); + sws_freeContext(swsContext); } static uint32_t preinit(const char *arg) { - if(arg) + if (arg) { - mp_msg(MSGT_VO,MSGL_ERR,"vo_x11: Unknown subdevice: %s\n",arg); - return ENOSYS; + mp_msg(MSGT_VO, MSGL_ERR, "vo_x11: Unknown subdevice: %s\n", arg); + return ENOSYS; } - if( !vo_init() ) return -1; // Can't open X11 + if (!vo_init()) + return -1; // Can't open X11 return 0; } static uint32_t control(uint32_t request, void *data, ...) { - switch (request) { - case VOCTRL_PAUSE: return (int_pause=1); - case VOCTRL_RESUME: return (int_pause=0); - case VOCTRL_QUERY_FORMAT: - return query_format(*((uint32_t*)data)); - case VOCTRL_GUISUPPORT: - return VO_TRUE; - case VOCTRL_GET_IMAGE: - return get_image(data); - case VOCTRL_SET_EQUALIZER: - { - va_list ap; - int value; - va_start(ap, data); - value = va_arg(ap, int); - va_end(ap); - return vo_x11_set_equalizer(data, value); - } - case VOCTRL_GET_EQUALIZER: + switch (request) { - va_list ap; - int *value; - va_start(ap, data); - value = va_arg(ap, int *); - va_end(ap); - return vo_x11_get_equalizer(data, value); + case VOCTRL_PAUSE: + return (int_pause = 1); + case VOCTRL_RESUME: + return (int_pause = 0); + case VOCTRL_QUERY_FORMAT: + return query_format(*((uint32_t *) data)); + case VOCTRL_GUISUPPORT: + return VO_TRUE; + case VOCTRL_GET_IMAGE: + return get_image(data); + case VOCTRL_SET_EQUALIZER: + { + va_list ap; + int value; + + va_start(ap, data); + value = va_arg(ap, int); + + va_end(ap); + return vo_x11_set_equalizer(data, value); + } + case VOCTRL_GET_EQUALIZER: + { + va_list ap; + int *value; + + va_start(ap, data); + value = va_arg(ap, int *); + + va_end(ap); + return vo_x11_get_equalizer(data, value); + } + case VOCTRL_ONTOP: + vo_x11_ontop(); + return VO_TRUE; + case VOCTRL_FULLSCREEN: + { + vo_x11_fullscreen(); + vo_x11_clearwindow(mDisplay, vo_window); + } + return VO_TRUE; } - case VOCTRL_ONTOP: - vo_x11_ontop(); - return VO_TRUE; - case VOCTRL_FULLSCREEN: - { - vo_x11_fullscreen(); - vo_x11_clearwindow(mDisplay, vo_window); - } - return VO_TRUE; - } - return VO_NOTIMPL; + return VO_NOTIMPL; }
--- a/libvo/vo_xmga.c Sun Jun 13 21:34:29 2004 +0000 +++ b/libvo/vo_xmga.c Mon Jun 14 04:53:03 2004 +0000 @@ -39,204 +39,259 @@ #ifdef SHOW_TIME #include "../osdep/timer.h" -static unsigned int timer=0; -static unsigned int timerd=0; +static unsigned int timer = 0; +static unsigned int timerd = 0; #endif #ifdef HAVE_NEW_GUI #include "../Gui/interface.h" #endif -static vo_info_t info = -{ - "Matrox G200/G4x0/G550 overlay in X11 window (using /dev/mga_vid)", - "xmga", - "Zoltan Ponekker <pontscho@makacs.poliod.hu>", - "" +static vo_info_t info = { + "Matrox G200/G4x0/G550 overlay in X11 window (using /dev/mga_vid)", + "xmga", + "Zoltan Ponekker <pontscho@makacs.poliod.hu>", + "" }; -LIBVO_EXTERN( xmga ) - +LIBVO_EXTERN(xmga) +static XGCValues wGCV; -static XGCValues wGCV; - -static uint32_t mDepth; -static XWindowAttributes attribs; +static uint32_t mDepth; +static XWindowAttributes attribs; static int colorkey; -static uint32_t mvHeight; -static uint32_t mvWidth; +static uint32_t mvHeight; +static uint32_t mvWidth; -static Window mRoot; +static Window mRoot; -static XSetWindowAttributes xWAttribs; +static XSetWindowAttributes xWAttribs; -static int inited=0; +static int inited = 0; #define VO_XMGA #include "mga_common.c" #undef VO_XMGA -static void mDrawColorKey( void ) +static void mDrawColorKey(void) { - XSetBackground( mDisplay,vo_gc,0 ); - XClearWindow( mDisplay,vo_window ); - XSetForeground( mDisplay,vo_gc,colorkey ); - XFillRectangle( mDisplay,vo_window,vo_gc,drwX,drwY,drwWidth,(vo_fs?drwHeight - 1:drwHeight) ); - XFlush( mDisplay ); + XSetBackground(mDisplay, vo_gc, 0); + XClearWindow(mDisplay, vo_window); + XSetForeground(mDisplay, vo_gc, colorkey); + XFillRectangle(mDisplay, vo_window, vo_gc, drwX, drwY, drwWidth, + (vo_fs ? drwHeight - 1 : drwHeight)); + XFlush(mDisplay); } static void check_events(void) { - int e=vo_x11_check_events(mDisplay); - if ( !(e&VO_EVENT_RESIZE) && !(e&VO_EVENT_EXPOSE) ) return; - set_window(); - mDrawColorKey(); - if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) mp_msg(MSGT_VO,MSGL_WARN,"Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); + int e = vo_x11_check_events(mDisplay); + + if (!(e & VO_EVENT_RESIZE) && !(e & VO_EVENT_EXPOSE)) + return; + set_window(); + mDrawColorKey(); + if (ioctl(f, MGA_VID_CONFIG, &mga_vid_config)) + mp_msg(MSGT_VO, MSGL_WARN, + "Error in mga_vid_config ioctl (wrong mga_vid.o version?)"); } -static void flip_page(void){ +static void flip_page(void) +{ #ifdef SHOW_TIME unsigned int t; - t=GetTimer(); - mp_msg(MSGT_VO,MSGL_STATUS," [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd); - timerd=t-timer; - timer=t; + + t = GetTimer(); + mp_msg(MSGT_VO, MSGL_STATUS, + " [timer: %08X diff: %6d dd: %6d ] \n", t, t - timer, + (t - timer) - timerd); + timerd = t - timer; + timer = t; #endif - vo_mga_flip_page(); + vo_mga_flip_page(); } -static uint32_t config( uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) +static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, + uint32_t d_height, uint32_t flags, char *title, + uint32_t format) { - char * mTitle=(title == NULL) ? "XMGA render" : title; - XVisualInfo vinfo; - unsigned long xswamask; - int r, g, b; + char *mTitle = (title == NULL) ? "XMGA render" : title; + XVisualInfo vinfo; + unsigned long xswamask; + int r, g, b; + + if (mga_init(width, height, format)) + return -1; // ioctl errors? - if(mga_init(width,height,format)) return -1; // ioctl errors? + aspect_save_orig(width, height); + aspect_save_prescale(d_width, d_height); + aspect_save_screenres(vo_screenwidth, vo_screenheight); + + mvWidth = width; + mvHeight = height; - aspect_save_orig(width,height); - aspect_save_prescale(d_width,d_height); - aspect_save_screenres(vo_screenwidth,vo_screenheight); + vo_panscan_x = vo_panscan_y = vo_panscan_amount = 0; - mvWidth=width; mvHeight=height; - - vo_panscan_x=vo_panscan_y=vo_panscan_amount=0; + vo_dx = (vo_screenwidth - d_width) / 2; + vo_dy = (vo_screenheight - d_height) / 2; + geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, + vo_screenheight); + vo_dwidth = d_width; + vo_dheight = d_height; + vo_mouse_autohide = 1; - vo_dx=( vo_screenwidth - d_width ) / 2; - vo_dy=( vo_screenheight - d_height ) / 2; - geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); - vo_dwidth=d_width; vo_dheight=d_height; - vo_mouse_autohide=1; + r = (vo_colorkey & 0x00ff0000) >> 16; + g = (vo_colorkey & 0x0000ff00) >> 8; + b = vo_colorkey & 0x000000ff; + switch (vo_depthonscreen) + { + case 32: + colorkey = vo_colorkey; + break; + case 24: + colorkey = vo_colorkey & 0x00ffffff; + break; + case 16: + colorkey = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); + break; + case 15: + colorkey = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); + break; + default: + mp_msg(MSGT_VO, MSGL_ERR, + "Sorry, this (%d) color depth not supported.\n", + vo_depthonscreen); + return -1; + } + mp_msg(MSGT_VO, MSGL_INFO, "Using colorkey: %x\n", colorkey); - r = (vo_colorkey & 0x00ff0000) >> 16; - g = (vo_colorkey & 0x0000ff00) >> 8; - b = vo_colorkey & 0x000000ff; - switch ( vo_depthonscreen ) - { - case 32: colorkey = vo_colorkey; break; - case 24: colorkey = vo_colorkey & 0x00ffffff; break; - case 16: colorkey = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); break; - case 15: colorkey = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); break; - default: mp_msg(MSGT_VO,MSGL_ERR,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; - } - mp_msg(MSGT_VO, MSGL_INFO, "Using colorkey: %x\n", colorkey); + inited = 1; - inited=1; - - aspect(&d_width,&d_height,A_NOZOOM); + aspect(&d_width, &d_height, A_NOZOOM); #ifdef HAVE_NEW_GUI - if(use_gui) - guiGetEvent( guiSetShVideo,0 ); // the GUI will set up / resize the window - else + if (use_gui) + guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize the window + else #endif - { - if ( flags&1 ) aspect(&dwidth,&dheight,A_ZOOM); + { + if (flags & 1) + aspect(&dwidth, &dheight, A_ZOOM); - XGetWindowAttributes( mDisplay,mRootWin,&attribs ); - mDepth=attribs.depth; - if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; - XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); - xWAttribs.colormap=XCreateColormap( mDisplay,mRootWin,vinfo.visual,AllocNone ); - xWAttribs.background_pixel=0; - xWAttribs.border_pixel=0; - xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask | - ((WinID==0)?0:(ButtonPressMask | ButtonReleaseMask | PointerMotionMask | PropertyChangeMask)); - xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + XGetWindowAttributes(mDisplay, mRootWin, &attribs); + mDepth = attribs.depth; + if (mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32) + mDepth = 24; + XMatchVisualInfo(mDisplay, mScreen, mDepth, TrueColor, &vinfo); + xWAttribs.colormap = + XCreateColormap(mDisplay, mRootWin, vinfo.visual, AllocNone); + xWAttribs.background_pixel = 0; + xWAttribs.border_pixel = 0; + xWAttribs.event_mask = + StructureNotifyMask | ExposureMask | KeyPressMask | + ((WinID == + 0) ? 0 : (ButtonPressMask | ButtonReleaseMask | + PointerMotionMask | PropertyChangeMask)); + xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + if (WinID >= 0) + { - if ( WinID>=0 ){ - - vo_window = WinID ? ((Window)WinID) : mRootWin; - if ( WinID ) - { - XUnmapWindow( mDisplay,vo_window ); - XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xWAttribs); - vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask ); - } else XSelectInput( mDisplay,vo_window,ExposureMask ); - - } else { + vo_window = WinID ? ((Window) WinID) : mRootWin; + if (WinID) + { + XUnmapWindow(mDisplay, vo_window); + XChangeWindowAttributes(mDisplay, vo_window, xswamask, + &xWAttribs); + vo_x11_selectinput_witherr(mDisplay, vo_window, + StructureNotifyMask | + KeyPressMask | + PropertyChangeMask | + PointerMotionMask | + ButtonPressMask | + ButtonReleaseMask | + ExposureMask); + } else + XSelectInput(mDisplay, vo_window, ExposureMask); + + } else + { - if ( vo_window == None ) - { - vo_window=XCreateWindow( mDisplay,mRootWin, - vo_dx,vo_dy, - vo_dwidth,vo_dheight, - xWAttribs.border_pixel, - mDepth, - InputOutput, - vinfo.visual,xswamask,&xWAttribs ); - - vo_x11_classhint( mDisplay,vo_window,"xmga" ); - vo_hidecursor(mDisplay,vo_window); - vo_x11_sizehint( vo_dx,vo_dy,vo_dwidth,vo_dheight,0 ); + if (vo_window == None) + { + vo_window = XCreateWindow(mDisplay, mRootWin, + vo_dx, vo_dy, + vo_dwidth, vo_dheight, + xWAttribs.border_pixel, + mDepth, + InputOutput, + vinfo.visual, xswamask, + &xWAttribs); - XStoreName( mDisplay,vo_window,mTitle ); - XMapWindow( mDisplay,vo_window ); - - if ( flags&1 ) vo_x11_fullscreen(); + vo_x11_classhint(mDisplay, vo_window, "xmga"); + vo_hidecursor(mDisplay, vo_window); + vo_x11_sizehint(vo_dx, vo_dy, vo_dwidth, vo_dheight, 0); + + XStoreName(mDisplay, vo_window, mTitle); + XMapWindow(mDisplay, vo_window); + + if (flags & 1) + vo_x11_fullscreen(); #ifdef HAVE_XINERAMA - vo_x11_xinerama_move(mDisplay,vo_window); + vo_x11_xinerama_move(mDisplay, vo_window); #endif - } else if ( !(flags&1) ) XMoveResizeWindow( mDisplay,vo_window,vo_dx,vo_dy,vo_dwidth,vo_dheight ); - } + } else if (!(flags & 1)) + XMoveResizeWindow(mDisplay, vo_window, vo_dx, vo_dy, + vo_dwidth, vo_dheight); + } - if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc ); - vo_gc=XCreateGC( mDisplay,vo_window,GCForeground,&wGCV ); + if (vo_gc != None) + XFreeGC(mDisplay, vo_gc); + vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &wGCV); - } // !GUI - - if ( ( flags&1 )&&( !WinID ) ) { vo_dx=0; vo_dy=0; vo_dwidth=vo_screenwidth; vo_dheight=vo_screenheight; vo_fs=1; } - - panscan_calc(); + } // !GUI - mga_vid_config.colkey_on=1; - mga_vid_config.colkey_red=r; - mga_vid_config.colkey_green=g; - mga_vid_config.colkey_blue=b; + if ((flags & 1) && (!WinID)) + { + vo_dx = 0; + vo_dy = 0; + vo_dwidth = vo_screenwidth; + vo_dheight = vo_screenheight; + vo_fs = 1; + } - set_window(); // set up mga_vid_config.dest_width etc - - saver_off(mDisplay); + panscan_calc(); - if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); + mga_vid_config.colkey_on = 1; + mga_vid_config.colkey_red = r; + mga_vid_config.colkey_green = g; + mga_vid_config.colkey_blue = b; + + set_window(); // set up mga_vid_config.dest_width etc + + saver_off(mDisplay); - XFlush( mDisplay ); - XSync( mDisplay,False ); - - ioctl(f,MGA_VID_ON,0); + if (vo_ontop) + vo_x11_setlayer(mDisplay, vo_window, vo_ontop); - return 0; + XFlush(mDisplay); + XSync(mDisplay, False); + + ioctl(f, MGA_VID_ON, 0); + + return 0; } -static void uninit(void){ - mp_msg(MSGT_VO,MSGL_V,"vo: uninit!\n"); - mga_uninit(); - if(!inited) return; // no window? - inited=0; - saver_on(mDisplay); - vo_x11_uninit(); // destroy the window +static void uninit(void) +{ + mp_msg(MSGT_VO, MSGL_V, "vo: uninit!\n"); + mga_uninit(); + if (!inited) + return; // no window? + inited = 0; + saver_on(mDisplay); + vo_x11_uninit(); // destroy the window } -
--- a/libvo/vo_xv.c Sun Jun 13 21:34:29 2004 +0000 +++ b/libvo/vo_xv.c Mon Jun 14 04:53:03 2004 +0000 @@ -40,23 +40,20 @@ #include "../Gui/interface.h" #endif -static vo_info_t info = -{ - "X11/Xv", - "xv", - "Gerd Knorr <kraxel@goldbach.in-berlin.de> and others", - "" +static vo_info_t info = { + "X11/Xv", + "xv", + "Gerd Knorr <kraxel@goldbach.in-berlin.de> and others", + "" }; LIBVO_EXTERN(xv) - #ifdef HAVE_SHM #include <sys/ipc.h> #include <sys/shm.h> #include <X11/extensions/XShm.h> - /* since it doesn't seem to be defined on some platforms */ -int XShmGetEventBase(Display*); +int XShmGetEventBase(Display *); static XShmSegmentInfo Shminfo[NUM_BUFFERS]; static int Shmem_Flag; @@ -68,15 +65,15 @@ // FIXME: dynamically allocate this stuff static void allocate_xvimage(int); -static unsigned int ver,rel,req,ev,err; +static unsigned int ver, rel, req, ev, err; static unsigned int formats, adaptors, xv_port, xv_format; -static XvAdaptorInfo *ai = NULL; -static XvImageFormatValues *fo; +static XvAdaptorInfo *ai = NULL; +static XvImageFormatValues *fo; -static int current_buf=0; -static int current_ip_buf=0; -static int num_buffers=1; // default -static XvImage* xvimage[NUM_BUFFERS]; +static int current_buf = 0; +static int current_ip_buf = 0; +static int num_buffers = 1; // default +static XvImage *xvimage[NUM_BUFFERS]; static uint32_t image_width; @@ -86,34 +83,54 @@ static int int_pause; -static Window mRoot; -static uint32_t drwX,drwY,drwBorderWidth,drwDepth; -static uint32_t dwidth,dheight; +static Window mRoot; +static uint32_t drwX, drwY, drwBorderWidth, drwDepth; +static uint32_t dwidth, dheight; -static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); +static void (*draw_alpha_fnc) (int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride); -static void draw_alpha_yv12(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - x0+=image_width*(vo_panscan_x>>1)/(vo_dwidth+vo_panscan_x); - vo_draw_alpha_yv12(w,h,src,srca,stride, - xvimage[current_buf]->data+xvimage[current_buf]->offsets[0]+ - xvimage[current_buf]->pitches[0]*y0+x0,xvimage[current_buf]->pitches[0]); +static void draw_alpha_yv12(int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride) +{ + x0 += image_width * (vo_panscan_x >> 1) / (vo_dwidth + vo_panscan_x); + vo_draw_alpha_yv12(w, h, src, srca, stride, + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[0] + + xvimage[current_buf]->pitches[0] * y0 + x0, + xvimage[current_buf]->pitches[0]); } -static void draw_alpha_yuy2(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - x0+=image_width*(vo_panscan_x>>1)/(vo_dwidth+vo_panscan_x); - vo_draw_alpha_yuy2(w,h,src,srca,stride, - xvimage[current_buf]->data+xvimage[current_buf]->offsets[0]+ - xvimage[current_buf]->pitches[0]*y0+2*x0,xvimage[current_buf]->pitches[0]); +static void draw_alpha_yuy2(int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride) +{ + x0 += image_width * (vo_panscan_x >> 1) / (vo_dwidth + vo_panscan_x); + vo_draw_alpha_yuy2(w, h, src, srca, stride, + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[0] + + xvimage[current_buf]->pitches[0] * y0 + 2 * x0, + xvimage[current_buf]->pitches[0]); } -static void draw_alpha_uyvy(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - x0+=image_width*(vo_panscan_x>>1)/(vo_dwidth+vo_panscan_x); - vo_draw_alpha_yuy2(w,h,src,srca,stride, - xvimage[current_buf]->data+xvimage[current_buf]->offsets[0]+ - xvimage[current_buf]->pitches[0]*y0+2*x0+1,xvimage[current_buf]->pitches[0]); +static void draw_alpha_uyvy(int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride) +{ + x0 += image_width * (vo_panscan_x >> 1) / (vo_dwidth + vo_panscan_x); + vo_draw_alpha_yuy2(w, h, src, srca, stride, + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[0] + + xvimage[current_buf]->pitches[0] * y0 + 2 * x0 + 1, + xvimage[current_buf]->pitches[0]); } -static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ +static void draw_alpha_null(int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, + int stride) +{ } @@ -123,451 +140,605 @@ * connect to server, create and map window, * allocate colors and (shared) memory */ -static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) +static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, + uint32_t d_height, uint32_t flags, char *title, + uint32_t format) { // int screen; - char *hello = (title == NULL) ? "Xv render" : title; + char *hello = (title == NULL) ? "Xv render" : title; + // char *name = ":0.0"; - XSizeHints hint; - XVisualInfo vinfo; - XGCValues xgcv; - XSetWindowAttributes xswa; - XWindowAttributes attribs; - unsigned long xswamask; - int depth; + XSizeHints hint; + XVisualInfo vinfo; + XGCValues xgcv; + XSetWindowAttributes xswa; + XWindowAttributes attribs; + unsigned long xswamask; + int depth; + #ifdef HAVE_XF86VM - int vm=0; - unsigned int modeline_width, modeline_height; - static uint32_t vm_width; - static uint32_t vm_height; + int vm = 0; + unsigned int modeline_width, modeline_height; + static uint32_t vm_width; + static uint32_t vm_height; #endif - panscan_init(); + panscan_init(); - aspect_save_orig(width,height); - aspect_save_prescale(d_width,d_height); + aspect_save_orig(width, height); + aspect_save_prescale(d_width, d_height); + + image_height = height; + image_width = width; + image_format = format; - image_height = height; - image_width = width; - image_format=format; - - vo_mouse_autohide=1; + vo_mouse_autohide = 1; + + int_pause = 0; - int_pause=0; + vo_dx = (vo_screenwidth - d_width) / 2; + vo_dy = (vo_screenheight - d_height) / 2; + geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, + vo_screenheight); + vo_dwidth = d_width; + vo_dheight = d_height; - vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; - geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); - vo_dwidth=d_width; vo_dheight=d_height; - #ifdef HAVE_XF86VM - if( flags&0x02 ) vm = 1; + if (flags & 0x02) + vm = 1; #endif - flip_flag=flags&8; - num_buffers=vo_doublebuffering?(vo_directrendering?NUM_BUFFERS:2):1; + flip_flag = flags & 8; + num_buffers = + vo_doublebuffering ? (vo_directrendering ? NUM_BUFFERS : 2) : 1; - /* check image formats */ - { - unsigned int i; + /* check image formats */ + { + unsigned int i; - xv_format=0; - for(i = 0; i < formats; i++){ - mp_msg(MSGT_VO,MSGL_V,"Xvideo image format: 0x%x (%4.4s) %s\n", fo[i].id,(char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar"); - if (fo[i].id == format) xv_format = fo[i].id; - } - if (!xv_format) return -1; - } - aspect_save_screenres(vo_screenwidth,vo_screenheight); + xv_format = 0; + for (i = 0; i < formats; i++) + { + mp_msg(MSGT_VO, MSGL_V, + "Xvideo image format: 0x%x (%4.4s) %s\n", fo[i].id, + (char *) &fo[i].id, + (fo[i].format == XvPacked) ? "packed" : "planar"); + if (fo[i].id == format) + xv_format = fo[i].id; + } + if (!xv_format) + return -1; + } + aspect_save_screenres(vo_screenwidth, vo_screenheight); #ifdef HAVE_NEW_GUI - if(use_gui) - guiGetEvent( guiSetShVideo,0 ); // let the GUI to setup/resize our window - else -#endif - { - hint.x = vo_dx; - hint.y = vo_dy; - aspect(&d_width,&d_height,A_NOZOOM); - hint.width = d_width; - hint.height = d_height; -#ifdef HAVE_XF86VM - if ( vm ) - { - if ((d_width==0) && (d_height==0)) - { vm_width=image_width; vm_height=image_height; } - else - { vm_width=d_width; vm_height=d_height; } - vo_vm_switch(vm_width, vm_height,&modeline_width, &modeline_height); - hint.x=(vo_screenwidth-modeline_width)/2; - hint.y=(vo_screenheight-modeline_height)/2; - hint.width=modeline_width; - hint.height=modeline_height; - aspect_save_screenres(modeline_width,modeline_height); - } + if (use_gui) + guiGetEvent(guiSetShVideo, 0); // let the GUI to setup/resize our window else #endif - if ( vo_fs ) { + hint.x = vo_dx; + hint.y = vo_dy; + aspect(&d_width, &d_height, A_NOZOOM); + hint.width = d_width; + hint.height = d_height; +#ifdef HAVE_XF86VM + if (vm) + { + if ((d_width == 0) && (d_height == 0)) + { + vm_width = image_width; + vm_height = image_height; + } else + { + vm_width = d_width; + vm_height = d_height; + } + vo_vm_switch(vm_width, vm_height, &modeline_width, + &modeline_height); + hint.x = (vo_screenwidth - modeline_width) / 2; + hint.y = (vo_screenheight - modeline_height) / 2; + hint.width = modeline_width; + hint.height = modeline_height; + aspect_save_screenres(modeline_width, modeline_height); + } else +#endif + if (vo_fs) + { #ifdef X11_FULLSCREEN - /* this code replaces X11_FULLSCREEN hack in mplayer.c - * aspect() is available through aspect.h for all vos. - * besides zooming should only be done with -zoom, - * but I leave the old -fs behaviour so users don't get - * irritated for now (and send lots o' mails ;) ::atmos - */ + /* this code replaces X11_FULLSCREEN hack in mplayer.c + * aspect() is available through aspect.h for all vos. + * besides zooming should only be done with -zoom, + * but I leave the old -fs behaviour so users don't get + * irritated for now (and send lots o' mails ;) ::atmos + */ - aspect(&d_width,&d_height,A_ZOOM); + aspect(&d_width, &d_height, A_ZOOM); #endif - } + } // dwidth=d_width; dheight=d_height; //XXX: what are the copy vars used for? - vo_dwidth=d_width; vo_dheight=d_height; - hint.flags = PPosition | PSize /* | PBaseSize */; - hint.base_width = hint.width; hint.base_height = hint.height; - XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); - depth=attribs.depth; - if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; - XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); + vo_dwidth = d_width; + vo_dheight = d_height; + hint.flags = PPosition | PSize /* | PBaseSize */ ; + hint.base_width = hint.width; + hint.base_height = hint.height; + XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), + &attribs); + depth = attribs.depth; + if (depth != 15 && depth != 16 && depth != 24 && depth != 32) + depth = 24; + XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); - xswa.background_pixel = 0; - xswa.border_pixel = 0; - xswamask = CWBackPixel | CWBorderPixel; + xswa.background_pixel = 0; + xswa.border_pixel = 0; + xswamask = CWBackPixel | CWBorderPixel; - if ( WinID>=0 ){ - vo_window = WinID ? ((Window)WinID) : mRootWin; - if ( WinID ) - { - XUnmapWindow( mDisplay,vo_window ); - XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xswa ); - vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask ); - XMapWindow( mDisplay,vo_window ); - } else { drwX=vo_dx; drwY=vo_dy; } - } else - if ( vo_window == None ){ - vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vinfo.visual, hint.x, hint.y, hint.width, hint.height, depth, CopyFromParent); + if (WinID >= 0) + { + vo_window = WinID ? ((Window) WinID) : mRootWin; + if (WinID) + { + XUnmapWindow(mDisplay, vo_window); + XChangeWindowAttributes(mDisplay, vo_window, xswamask, + &xswa); + vo_x11_selectinput_witherr(mDisplay, vo_window, + StructureNotifyMask | + KeyPressMask | + PropertyChangeMask | + PointerMotionMask | + ButtonPressMask | + ButtonReleaseMask | + ExposureMask); + XMapWindow(mDisplay, vo_window); + } else + { + drwX = vo_dx; + drwY = vo_dy; + } + } else if (vo_window == None) + { + vo_window = + vo_x11_create_smooth_window(mDisplay, mRootWin, + vinfo.visual, hint.x, hint.y, + hint.width, hint.height, depth, + CopyFromParent); - vo_x11_classhint( mDisplay,vo_window,"xv" ); - vo_hidecursor(mDisplay,vo_window); + vo_x11_classhint(mDisplay, vo_window, "xv"); + vo_hidecursor(mDisplay, vo_window); - vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PropertyChangeMask | - ((WinID==0) ? 0 : (PointerMotionMask - | ButtonPressMask | ButtonReleaseMask | ExposureMask - ))); - XSetStandardProperties(mDisplay, vo_window, hello, hello, None, NULL, 0, &hint); - XSetWMNormalHints( mDisplay,vo_window,&hint ); - XMapWindow(mDisplay, vo_window); - if ( flags&1 ) vo_x11_fullscreen(); - else { + vo_x11_selectinput_witherr(mDisplay, vo_window, + StructureNotifyMask | KeyPressMask | + PropertyChangeMask | ((WinID == 0) ? + 0 + : + (PointerMotionMask + | + ButtonPressMask + | + ButtonReleaseMask + | + ExposureMask))); + XSetStandardProperties(mDisplay, vo_window, hello, hello, None, + NULL, 0, &hint); + XSetWMNormalHints(mDisplay, vo_window, &hint); + XMapWindow(mDisplay, vo_window); + if (flags & 1) + vo_x11_fullscreen(); + else + { #ifdef HAVE_XINERAMA - vo_x11_xinerama_move(mDisplay,vo_window); + vo_x11_xinerama_move(mDisplay, vo_window); #endif - vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 ); - } - } else { - // vo_fs set means we were already at fullscreen - vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 ); - if ( !vo_fs ) XMoveResizeWindow( mDisplay,vo_window,hint.x,hint.y,hint.width,hint.height ); - if ( flags&1 && !vo_fs ) vo_x11_fullscreen(); // handle -fs on non-first file - } - + vo_x11_sizehint(hint.x, hint.y, hint.width, hint.height, + 0); + } + } else + { + // vo_fs set means we were already at fullscreen + vo_x11_sizehint(hint.x, hint.y, hint.width, hint.height, 0); + if (!vo_fs) + XMoveResizeWindow(mDisplay, vo_window, hint.x, hint.y, + hint.width, hint.height); + if (flags & 1 && !vo_fs) + vo_x11_fullscreen(); // handle -fs on non-first file + } + // vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 ); - - if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc ); - vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv); - XFlush(mDisplay); - XSync(mDisplay, False); + + if (vo_gc != None) + XFreeGC(mDisplay, vo_gc); + vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv); + XFlush(mDisplay); + XSync(mDisplay, False); #ifdef HAVE_XF86VM - if ( vm ) - { - /* Grab the mouse pointer in our window */ - if(vo_grabpointer) - XGrabPointer(mDisplay, vo_window, True, 0, - GrabModeAsync, GrabModeAsync, - vo_window, None, CurrentTime); - XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); - } + if (vm) + { + /* Grab the mouse pointer in our window */ + if (vo_grabpointer) + XGrabPointer(mDisplay, vo_window, True, 0, + GrabModeAsync, GrabModeAsync, + vo_window, None, CurrentTime); + XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); + } #endif - } + } + + mp_msg(MSGT_VO, MSGL_V, "using Xvideo port %d for hw scaling\n", + xv_port); - mp_msg(MSGT_VO,MSGL_V, "using Xvideo port %d for hw scaling\n",xv_port ); - - switch (xv_format){ - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: draw_alpha_fnc=draw_alpha_yv12; break; - case IMGFMT_YUY2: - case IMGFMT_YVYU: draw_alpha_fnc=draw_alpha_yuy2; break; - case IMGFMT_UYVY: draw_alpha_fnc=draw_alpha_uyvy; break; - default: draw_alpha_fnc=draw_alpha_null; - } + switch (xv_format) + { + case IMGFMT_YV12: + case IMGFMT_I420: + case IMGFMT_IYUV: + draw_alpha_fnc = draw_alpha_yv12; + break; + case IMGFMT_YUY2: + case IMGFMT_YVYU: + draw_alpha_fnc = draw_alpha_yuy2; + break; + case IMGFMT_UYVY: + draw_alpha_fnc = draw_alpha_uyvy; + break; + default: + draw_alpha_fnc = draw_alpha_null; + } - if ( vo_config_count ) - for(current_buf=0;current_buf<num_buffers;++current_buf) - deallocate_xvimage(current_buf); + if (vo_config_count) + for (current_buf = 0; current_buf < num_buffers; ++current_buf) + deallocate_xvimage(current_buf); - for(current_buf=0;current_buf<num_buffers;++current_buf) - allocate_xvimage(current_buf); + for (current_buf = 0; current_buf < num_buffers; ++current_buf) + allocate_xvimage(current_buf); - current_buf=0; - current_ip_buf=0; + current_buf = 0; + current_ip_buf = 0; #if 0 - set_gamma_correction(); + set_gamma_correction(); #endif - aspect(&vo_dwidth,&vo_dheight,A_NOZOOM); - if ( (( flags&1 )&&( WinID <= 0 )) || vo_fs ) - { - aspect(&vo_dwidth,&vo_dheight,A_ZOOM); - drwX=( vo_screenwidth - (vo_dwidth > vo_screenwidth?vo_screenwidth:vo_dwidth) ) / 2; - drwY=( vo_screenheight - (vo_dheight > vo_screenheight?vo_screenheight:vo_dheight) ) / 2; - vo_dwidth=(vo_dwidth > vo_screenwidth?vo_screenwidth:vo_dwidth); - vo_dheight=(vo_dheight > vo_screenheight?vo_screenheight:vo_dheight); - mp_msg(MSGT_VO,MSGL_V, "[xv-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); - } + aspect(&vo_dwidth, &vo_dheight, A_NOZOOM); + if (((flags & 1) && (WinID <= 0)) || vo_fs) + { + aspect(&vo_dwidth, &vo_dheight, A_ZOOM); + drwX = + (vo_screenwidth - + (vo_dwidth > + vo_screenwidth ? vo_screenwidth : vo_dwidth)) / 2; + drwY = + (vo_screenheight - + (vo_dheight > + vo_screenheight ? vo_screenheight : vo_dheight)) / 2; + vo_dwidth = + (vo_dwidth > vo_screenwidth ? vo_screenwidth : vo_dwidth); + vo_dheight = + (vo_dheight > vo_screenheight ? vo_screenheight : vo_dheight); + mp_msg(MSGT_VO, MSGL_V, "[xv-fs] dx: %d dy: %d dw: %d dh: %d\n", + drwX, drwY, vo_dwidth, vo_dheight); + } - panscan_calc(); + panscan_calc(); - XClearWindow(mDisplay, vo_window); + XClearWindow(mDisplay, vo_window); #if 0 #ifdef HAVE_SHM - if ( Shmem_Flag ) - { - XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf], 0, 0, image_width, image_height, drwX, drwY, 1, 1, False); - XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf], 0, 0, image_width, image_height, drwX,drwY,vo_dwidth,(vo_fs?vo_dheight - 1:vo_dheight), False); - } - else + if (Shmem_Flag) + { + XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, + xvimage[current_buf], 0, 0, image_width, + image_height, drwX, drwY, 1, 1, False); + XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, + xvimage[current_buf], 0, 0, image_width, + image_height, drwX, drwY, vo_dwidth, + (vo_fs ? vo_dheight - 1 : vo_dheight), False); + } else #endif - { - XvPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf], 0, 0, image_width, image_height, drwX, drwY, 1, 1); - XvPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf], 0, 0, image_width, image_height, drwX,drwY,vo_dwidth,(vo_fs?vo_dheight - 1:vo_dheight)); - } + { + XvPutImage(mDisplay, xv_port, vo_window, vo_gc, + xvimage[current_buf], 0, 0, image_width, image_height, + drwX, drwY, 1, 1); + XvPutImage(mDisplay, xv_port, vo_window, vo_gc, + xvimage[current_buf], 0, 0, image_width, image_height, + drwX, drwY, vo_dwidth, + (vo_fs ? vo_dheight - 1 : vo_dheight)); + } #endif - - mp_msg(MSGT_VO,MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); + + mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", drwX, + drwY, vo_dwidth, vo_dheight); - saver_off(mDisplay); // turning off screen saver + saver_off(mDisplay); // turning off screen saver - if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); + if (vo_ontop) + vo_x11_setlayer(mDisplay, vo_window, vo_ontop); - return 0; + return 0; } static void allocate_xvimage(int foo) { - /* - * allocate XvImages. FIXME: no error checking, without - * mit-shm this will bomb... trzing to fix ::atmos - */ + /* + * allocate XvImages. FIXME: no error checking, without + * mit-shm this will bomb... trzing to fix ::atmos + */ #ifdef HAVE_SHM - if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag = 1; - else - { - Shmem_Flag = 0; - mp_msg(MSGT_VO,MSGL_INFO, "Shared memory not supported\nReverting to normal Xv\n" ); - } - if ( Shmem_Flag ) - { - xvimage[foo] = (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format, NULL, image_width, image_height, &Shminfo[foo]); + if (mLocalDisplay && XShmQueryExtension(mDisplay)) + Shmem_Flag = 1; + else + { + Shmem_Flag = 0; + mp_msg(MSGT_VO, MSGL_INFO, + "Shared memory not supported\nReverting to normal Xv\n"); + } + if (Shmem_Flag) + { + xvimage[foo] = + (XvImage *) XvShmCreateImage(mDisplay, xv_port, xv_format, + NULL, image_width, image_height, + &Shminfo[foo]); - Shminfo[foo].shmid = shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777); - Shminfo[foo].shmaddr = (char *) shmat(Shminfo[foo].shmid, 0, 0); - Shminfo[foo].readOnly = False; + Shminfo[foo].shmid = + shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777); + Shminfo[foo].shmaddr = (char *) shmat(Shminfo[foo].shmid, 0, 0); + Shminfo[foo].readOnly = False; - xvimage[foo]->data = Shminfo[foo].shmaddr; - XShmAttach(mDisplay, &Shminfo[foo]); - XSync(mDisplay, False); - shmctl(Shminfo[foo].shmid, IPC_RMID, 0); - } - else + xvimage[foo]->data = Shminfo[foo].shmaddr; + XShmAttach(mDisplay, &Shminfo[foo]); + XSync(mDisplay, False); + shmctl(Shminfo[foo].shmid, IPC_RMID, 0); + } else #endif - { - xvimage[foo] = (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, image_width, image_height); - xvimage[foo]->data = malloc(xvimage[foo]->data_size); - XSync(mDisplay,False); - } - memset(xvimage[foo]->data,128,xvimage[foo]->data_size); - return; + { + xvimage[foo] = + (XvImage *) XvCreateImage(mDisplay, xv_port, xv_format, NULL, + image_width, image_height); + xvimage[foo]->data = malloc(xvimage[foo]->data_size); + XSync(mDisplay, False); + } + memset(xvimage[foo]->data, 128, xvimage[foo]->data_size); + return; } static void deallocate_xvimage(int foo) { #ifdef HAVE_SHM - if ( Shmem_Flag ) - { - XShmDetach( mDisplay,&Shminfo[foo] ); - shmdt( Shminfo[foo].shmaddr ); - } - else + if (Shmem_Flag) + { + XShmDetach(mDisplay, &Shminfo[foo]); + shmdt(Shminfo[foo].shmaddr); + } else #endif - { - free(xvimage[foo]->data); - } - XFree(xvimage[foo]); - - XFlush( mDisplay ); - XSync(mDisplay, False); - return; + { + free(xvimage[foo]->data); + } + XFree(xvimage[foo]); + + XFlush(mDisplay); + XSync(mDisplay, False); + return; } static void check_events(void) { - int e=vo_x11_check_events(mDisplay); + int e = vo_x11_check_events(mDisplay); + + if (e & VO_EVENT_EXPOSE && vo_fs) + vo_x11_clearwindow(mDisplay, vo_window); - if (e&VO_EVENT_EXPOSE && vo_fs) - vo_x11_clearwindow(mDisplay, vo_window); + if (e & VO_EVENT_RESIZE) + { + if (vo_fs) + { + e |= VO_EVENT_EXPOSE; + XClearWindow(mDisplay, vo_window); + XFlush(mDisplay); + } + + XGetGeometry(mDisplay, vo_window, &mRoot, &drwX, &drwY, &vo_dwidth, + &vo_dheight, &drwBorderWidth, &drwDepth); + drwX = drwY = 0; + mp_msg(MSGT_VO, MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n", drwX, + drwY, vo_dwidth, vo_dheight); - if(e&VO_EVENT_RESIZE) - { - if (vo_fs) { - e |= VO_EVENT_EXPOSE; - XClearWindow(mDisplay, vo_window); - XFlush(mDisplay); - } - - XGetGeometry( mDisplay,vo_window,&mRoot,&drwX,&drwY,&vo_dwidth,&vo_dheight,&drwBorderWidth,&drwDepth ); - drwX = drwY = 0; - mp_msg(MSGT_VO,MSGL_V, "[xv] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); + aspect(&dwidth, &dheight, A_NOZOOM); + if (vo_fs) + { + aspect(&dwidth, &dheight, A_ZOOM); + drwX = + (vo_screenwidth - + (dwidth > vo_screenwidth ? vo_screenwidth : dwidth)) / 2; + drwY = + (vo_screenheight - + (dheight > + vo_screenheight ? vo_screenheight : dheight)) / 2; + vo_dwidth = + (dwidth > vo_screenwidth ? vo_screenwidth : dwidth); + vo_dheight = + (dheight > vo_screenheight ? vo_screenheight : dheight); + mp_msg(MSGT_VO, MSGL_V, + "[xv-fs] dx: %d dy: %d dw: %d dh: %d\n", drwX, drwY, + vo_dwidth, vo_dheight); + } + } - aspect(&dwidth,&dheight,A_NOZOOM); - if ( vo_fs ) - { - aspect(&dwidth,&dheight,A_ZOOM); - drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; - drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; - vo_dwidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); - vo_dheight=(dheight > vo_screenheight?vo_screenheight:dheight); - mp_msg(MSGT_VO,MSGL_V, "[xv-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); - } - } - - if ( (e&VO_EVENT_EXPOSE || e&VO_EVENT_RESIZE) && int_pause) - flip_page(); + if ((e & VO_EVENT_EXPOSE || e & VO_EVENT_RESIZE) && int_pause) + flip_page(); } static void draw_osd(void) -{ vo_draw_text(image_width-image_width*vo_panscan_x/(vo_dwidth+vo_panscan_x),image_height,draw_alpha_fnc);} +{ + vo_draw_text(image_width - + image_width * vo_panscan_x / (vo_dwidth + vo_panscan_x), + image_height, draw_alpha_fnc); +} static void flip_page(void) { #ifdef HAVE_SHM - if ( Shmem_Flag ) - { - XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf], - 0, 0, image_width, image_height, - drwX-(vo_panscan_x>>1),drwY-(vo_panscan_y>>1),vo_dwidth+vo_panscan_x,(vo_fs?vo_dheight - 1:vo_dheight)+vo_panscan_y, - False); - } - else + if (Shmem_Flag) + { + XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, + xvimage[current_buf], 0, 0, image_width, + image_height, drwX - (vo_panscan_x >> 1), + drwY - (vo_panscan_y >> 1), vo_dwidth + vo_panscan_x, + (vo_fs ? vo_dheight - 1 : vo_dheight) + vo_panscan_y, + False); + } else #endif - { - XvPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf], - 0, 0, image_width, image_height, - drwX-(vo_panscan_x>>1),drwY-(vo_panscan_y>>1),vo_dwidth+vo_panscan_x,(vo_fs?vo_dheight - 1:vo_dheight)+vo_panscan_y); - } - if (num_buffers>1){ - current_buf=vo_directrendering?0:((current_buf+1)%num_buffers); - XFlush(mDisplay); - } else - XSync(mDisplay, False); - return; + { + XvPutImage(mDisplay, xv_port, vo_window, vo_gc, + xvimage[current_buf], 0, 0, image_width, image_height, + drwX - (vo_panscan_x >> 1), drwY - (vo_panscan_y >> 1), + vo_dwidth + vo_panscan_x, + (vo_fs ? vo_dheight - 1 : vo_dheight) + vo_panscan_y); + } + if (num_buffers > 1) + { + current_buf = + vo_directrendering ? 0 : ((current_buf + 1) % num_buffers); + XFlush(mDisplay); + } else + XSync(mDisplay, False); + return; } -static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) +static uint32_t draw_slice(uint8_t * image[], int stride[], int w, int h, + int x, int y) { - uint8_t *dst; + uint8_t *dst; - dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[0] + - xvimage[current_buf]->pitches[0]*y + x; - memcpy_pic(dst, image[0], w, h, xvimage[current_buf]->pitches[0], stride[0]); + dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[0] + + xvimage[current_buf]->pitches[0] * y + x; + memcpy_pic(dst, image[0], w, h, xvimage[current_buf]->pitches[0], + stride[0]); - x/=2;y/=2;w/=2;h/=2; + x /= 2; + y /= 2; + w /= 2; + h /= 2; - dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[1] + - xvimage[current_buf]->pitches[1]*y + x; - if(image_format!=IMGFMT_YV12) - memcpy_pic(dst, image[1], w, h, xvimage[current_buf]->pitches[1], stride[1]); - else - memcpy_pic(dst, image[2], w, h, xvimage[current_buf]->pitches[1], stride[2]); + dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[1] + + xvimage[current_buf]->pitches[1] * y + x; + if (image_format != IMGFMT_YV12) + memcpy_pic(dst, image[1], w, h, xvimage[current_buf]->pitches[1], + stride[1]); + else + memcpy_pic(dst, image[2], w, h, xvimage[current_buf]->pitches[1], + stride[2]); - dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[2] + - xvimage[current_buf]->pitches[2]*y + x; - if(image_format==IMGFMT_YV12) - memcpy_pic(dst, image[1], w, h, xvimage[current_buf]->pitches[1], stride[1]); - else - memcpy_pic(dst, image[2], w, h, xvimage[current_buf]->pitches[1], stride[2]); + dst = xvimage[current_buf]->data + xvimage[current_buf]->offsets[2] + + xvimage[current_buf]->pitches[2] * y + x; + if (image_format == IMGFMT_YV12) + memcpy_pic(dst, image[1], w, h, xvimage[current_buf]->pitches[1], + stride[1]); + else + memcpy_pic(dst, image[2], w, h, xvimage[current_buf]->pitches[1], + stride[2]); - return 0; + return 0; } -static uint32_t draw_frame(uint8_t *src[]){ +static uint32_t draw_frame(uint8_t * src[]) +{ printf("draw_frame() called!!!!!!"); return -1; } -static uint32_t draw_image(mp_image_t *mpi){ - if(mpi->flags&MP_IMGFLAG_DIRECT){ - // direct rendering: - current_buf=(int)(mpi->priv); // hack! - return VO_TRUE; +static uint32_t draw_image(mp_image_t * mpi) +{ + if (mpi->flags & MP_IMGFLAG_DIRECT) + { + // direct rendering: + current_buf = (int) (mpi->priv); // hack! + return VO_TRUE; } - if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK) return VO_TRUE; // done - if(mpi->flags&MP_IMGFLAG_PLANAR){ - draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0); - return VO_TRUE; + if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) + return VO_TRUE; // done + if (mpi->flags & MP_IMGFLAG_PLANAR) + { + draw_slice(mpi->planes, mpi->stride, mpi->w, mpi->h, 0, 0); + return VO_TRUE; } - if(mpi->flags&MP_IMGFLAG_YUV){ - // packed YUV: - memcpy_pic(xvimage[current_buf]->data+xvimage[current_buf]->offsets[0], - mpi->planes[0],mpi->w*(mpi->bpp/8),mpi->h, - xvimage[current_buf]->pitches[0], mpi->stride[0]); - return VO_TRUE; + if (mpi->flags & MP_IMGFLAG_YUV) + { + // packed YUV: + memcpy_pic(xvimage[current_buf]->data + + xvimage[current_buf]->offsets[0], mpi->planes[0], + mpi->w * (mpi->bpp / 8), mpi->h, + xvimage[current_buf]->pitches[0], mpi->stride[0]); + return VO_TRUE; } - return VO_FALSE; // not (yet) supported + return VO_FALSE; // not (yet) supported } -static uint32_t get_image(mp_image_t *mpi){ - int buf=current_buf; // we shouldn't change current_buf unless we do DR! - if(mpi->type==MP_IMGTYPE_STATIC && num_buffers>1) return VO_FALSE; // it is not static - if(mpi->imgfmt!=image_format) return VO_FALSE; // needs conversion :( +static uint32_t get_image(mp_image_t * mpi) +{ + int buf = current_buf; // we shouldn't change current_buf unless we do DR! + + if (mpi->type == MP_IMGTYPE_STATIC && num_buffers > 1) + return VO_FALSE; // it is not static + if (mpi->imgfmt != image_format) + return VO_FALSE; // needs conversion :( // if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram - if(mpi->flags&MP_IMGFLAG_READABLE && - (mpi->type==MP_IMGTYPE_IPB || mpi->type==MP_IMGTYPE_IP)){ - // reference (I/P) frame of IP or IPB: - if(num_buffers<2) return VO_FALSE; // not enough - current_ip_buf^=1; - // for IPB with 2 buffers we can DR only one of the 2 P frames: - if(mpi->type==MP_IMGTYPE_IPB && num_buffers<3 && current_ip_buf) return VO_FALSE; - buf=current_ip_buf; - if(mpi->type==MP_IMGTYPE_IPB) ++buf; // preserve space for B + if (mpi->flags & MP_IMGFLAG_READABLE && + (mpi->type == MP_IMGTYPE_IPB || mpi->type == MP_IMGTYPE_IP)) + { + // reference (I/P) frame of IP or IPB: + if (num_buffers < 2) + return VO_FALSE; // not enough + current_ip_buf ^= 1; + // for IPB with 2 buffers we can DR only one of the 2 P frames: + if (mpi->type == MP_IMGTYPE_IPB && num_buffers < 3 + && current_ip_buf) + return VO_FALSE; + buf = current_ip_buf; + if (mpi->type == MP_IMGTYPE_IPB) + ++buf; // preserve space for B } - if(mpi->height > xvimage[buf]->height) return VO_FALSE; //buffer to small - if(mpi->width*(mpi->bpp/8) > xvimage[buf]->pitches[0]) return VO_FALSE; //buffer to small - if( (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)) || - (mpi->width*(mpi->bpp/8)==xvimage[buf]->pitches[0]) ){ - current_buf=buf; - mpi->planes[0]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[0]; - mpi->stride[0]=xvimage[current_buf]->pitches[0]; - mpi->width=mpi->stride[0]/(mpi->bpp/8); - if(mpi->flags&MP_IMGFLAG_PLANAR){ - if(mpi->flags&MP_IMGFLAG_SWAPPED){ - // I420 - mpi->planes[1]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[1]; - mpi->planes[2]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[2]; - mpi->stride[1]=xvimage[current_buf]->pitches[1]; - mpi->stride[2]=xvimage[current_buf]->pitches[2]; - } else { - // YV12 - mpi->planes[1]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[2]; - mpi->planes[2]=xvimage[current_buf]->data+xvimage[current_buf]->offsets[1]; - mpi->stride[1]=xvimage[current_buf]->pitches[2]; - mpi->stride[2]=xvimage[current_buf]->pitches[1]; - } - } - mpi->flags|=MP_IMGFLAG_DIRECT; - mpi->priv=(void*)current_buf; -// printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); - return VO_TRUE; + if (mpi->height > xvimage[buf]->height) + return VO_FALSE; //buffer to small + if (mpi->width * (mpi->bpp / 8) > xvimage[buf]->pitches[0]) + return VO_FALSE; //buffer to small + if ((mpi->flags & (MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_ACCEPT_WIDTH)) + || (mpi->width * (mpi->bpp / 8) == xvimage[buf]->pitches[0])) + { + current_buf = buf; + mpi->planes[0] = + xvimage[current_buf]->data + xvimage[current_buf]->offsets[0]; + mpi->stride[0] = xvimage[current_buf]->pitches[0]; + mpi->width = mpi->stride[0] / (mpi->bpp / 8); + if (mpi->flags & MP_IMGFLAG_PLANAR) + { + if (mpi->flags & MP_IMGFLAG_SWAPPED) + { + // I420 + mpi->planes[1] = + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[1]; + mpi->planes[2] = + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[2]; + mpi->stride[1] = xvimage[current_buf]->pitches[1]; + mpi->stride[2] = xvimage[current_buf]->pitches[2]; + } else + { + // YV12 + mpi->planes[1] = + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[2]; + mpi->planes[2] = + xvimage[current_buf]->data + + xvimage[current_buf]->offsets[1]; + mpi->stride[1] = xvimage[current_buf]->pitches[2]; + mpi->stride[2] = xvimage[current_buf]->pitches[1]; + } + } + mpi->flags |= MP_IMGFLAG_DIRECT; + mpi->priv = (void *) current_buf; +// printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); + return VO_TRUE; } return VO_FALSE; } @@ -575,186 +746,229 @@ static uint32_t query_format(uint32_t format) { uint32_t i; - int flag=VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW| - VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN|VFCAP_OSD|VFCAP_ACCEPT_STRIDE; // FIXME! check for DOWN - /* check image formats */ - for(i = 0; i < formats; i++){ - if (fo[i].id == format) return flag; //xv_format = fo[i].id; - } - return 0; + int flag = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_ACCEPT_STRIDE; // FIXME! check for DOWN + + /* check image formats */ + for (i = 0; i < formats; i++) + { + if (fo[i].id == format) + return flag; //xv_format = fo[i].id; + } + return 0; } -static void uninit(void) +static void uninit(void) { - int i; - if ( !vo_config_count ) return; - XvFreeAdaptorInfo(ai); - ai = NULL; - saver_on(mDisplay); // screen saver back on - for( i=0;i<num_buffers;i++ ) deallocate_xvimage( i ); + int i; + + if (!vo_config_count) + return; + XvFreeAdaptorInfo(ai); + ai = NULL; + saver_on(mDisplay); // screen saver back on + for (i = 0; i < num_buffers; i++) + deallocate_xvimage(i); #ifdef HAVE_XF86VM - vo_vm_close(mDisplay); + vo_vm_close(mDisplay); #endif - vo_x11_uninit(); + vo_x11_uninit(); } static uint32_t preinit(const char *arg) { XvPortID xv_p; - int busy_ports=0; + int busy_ports = 0; unsigned int i; - + xv_port = 0; - if(arg) + if (arg) { - if ((strlen(arg) >= 6) && !strncmp(arg, "port=", 5)) - { - xv_port = atoi(arg+5); - } - else - { - mp_msg(MSGT_VO,MSGL_ERR,"vo_xv: Unknown subdevice: %s\n",arg); - return ENOSYS; - } + if ((strlen(arg) >= 6) && !strncmp(arg, "port=", 5)) + { + xv_port = atoi(arg + 5); + } else + { + mp_msg(MSGT_VO, MSGL_ERR, "vo_xv: Unknown subdevice: %s\n", + arg); + return ENOSYS; + } } - if (!vo_init()) return -1; + if (!vo_init()) + return -1; - /* check for Xvideo extension */ - if (Success != XvQueryExtension(mDisplay,&ver,&rel,&req,&ev,&err)){ - mp_msg(MSGT_VO,MSGL_ERR,"Sorry, Xv not supported by this X11 version/driver\n"); - mp_msg(MSGT_VO,MSGL_ERR,"******** Try with -vo x11 or -vo sdl *********\n"); - return -1; - } - - /* check for Xvideo support */ - if (Success != XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay), &adaptors,&ai)){ - mp_msg(MSGT_VO,MSGL_ERR,"Xv: XvQueryAdaptors failed\n"); - return -1; + /* check for Xvideo extension */ + if (Success != XvQueryExtension(mDisplay, &ver, &rel, &req, &ev, &err)) + { + mp_msg(MSGT_VO, MSGL_ERR, + "Sorry, Xv not supported by this X11 version/driver\n"); + mp_msg(MSGT_VO, MSGL_ERR, + "******** Try with -vo x11 or -vo sdl *********\n"); + return -1; } - /* check adaptors */ - if (xv_port) { + /* check for Xvideo support */ + if (Success != + XvQueryAdaptors(mDisplay, DefaultRootWindow(mDisplay), &adaptors, + &ai)) + { + mp_msg(MSGT_VO, MSGL_ERR, "Xv: XvQueryAdaptors failed\n"); + return -1; + } + + /* check adaptors */ + if (xv_port) + { int port_found; - - for (port_found = 0, i = 0; !port_found && i < adaptors; i++) { - if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask)) { - for (xv_p = ai[i].base_id; xv_p < ai[i].base_id+ai[i].num_ports; ++xv_p) { - if (xv_p == xv_port) { + + for (port_found = 0, i = 0; !port_found && i < adaptors; i++) + { + if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask)) + { + for (xv_p = ai[i].base_id; + xv_p < ai[i].base_id + ai[i].num_ports; ++xv_p) + { + if (xv_p == xv_port) + { port_found = 1; break; } } } } - if (port_found) { + if (port_found) + { if (XvGrabPort(mDisplay, xv_port, CurrentTime)) xv_port = 0; - } else { - mp_msg(MSGT_VO, MSGL_WARN,"Xv: Invalid port parameter, overriding with port 0\n"); + } else + { + mp_msg(MSGT_VO, MSGL_WARN, + "Xv: Invalid port parameter, overriding with port 0\n"); xv_port = 0; } } - - for (i = 0; i < adaptors && xv_port == 0; i++){ - if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask)) { - for (xv_p = ai[i].base_id; xv_p < ai[i].base_id+ai[i].num_ports; ++xv_p) - if (!XvGrabPort(mDisplay, xv_p, CurrentTime)) { - xv_port = xv_p; - break; - } else { - mp_msg(MSGT_VO,MSGL_WARN,"Xv: could not grab port %i\n", (int)xv_p); - ++busy_ports; - } - } + + for (i = 0; i < adaptors && xv_port == 0; i++) + { + if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask)) + { + for (xv_p = ai[i].base_id; + xv_p < ai[i].base_id + ai[i].num_ports; ++xv_p) + if (!XvGrabPort(mDisplay, xv_p, CurrentTime)) + { + xv_port = xv_p; + break; + } else + { + mp_msg(MSGT_VO, MSGL_WARN, + "Xv: could not grab port %i\n", (int) xv_p); + ++busy_ports; + } + } } - if(!xv_port){ - if(busy_ports) - mp_msg(MSGT_VO,MSGL_ERR,"Could not find free Xvideo port - maybe another process is already using it.\n" - "Close all video applications, and try again. If that does not help,\n" - "see 'mplayer -vo help' for other (non-xv) video out drivers.\n"); - else - mp_msg(MSGT_VO,MSGL_ERR,"It seems there is no Xvideo support for your video card available.\n" - "Run 'xvinfo' to verify its Xv support and read DOCS/HTML/en/devices.html#xv!\n" - "See 'mplayer -vo help' for other (non-xv) video out drivers. Try -vo x11\n"); - return -1; + if (!xv_port) + { + if (busy_ports) + mp_msg(MSGT_VO, MSGL_ERR, + "Could not find free Xvideo port - maybe another process is already using it.\n" + "Close all video applications, and try again. If that does not help,\n" + "see 'mplayer -vo help' for other (non-xv) video out drivers.\n"); + else + mp_msg(MSGT_VO, MSGL_ERR, + "It seems there is no Xvideo support for your video card available.\n" + "Run 'xvinfo' to verify its Xv support and read DOCS/HTML/en/devices.html#xv!\n" + "See 'mplayer -vo help' for other (non-xv) video out drivers. Try -vo x11\n"); + return -1; } { - int howmany, i; - const XvAttribute * const attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany); - - for (i = 0; i < howmany && attributes; i++) - if (!strcmp(attributes[i].name, "XV_AUTOPAINT_COLORKEY")) - { - const Atom autopaint = XInternAtom(mDisplay, "XV_AUTOPAINT_COLORKEY", False); - XvSetPortAttribute(mDisplay, xv_port, autopaint, 1); - break; - } + int howmany, i; + const XvAttribute *const attributes = + XvQueryPortAttributes(mDisplay, xv_port, &howmany); + + for (i = 0; i < howmany && attributes; i++) + if (!strcmp(attributes[i].name, "XV_AUTOPAINT_COLORKEY")) + { + const Atom autopaint = + XInternAtom(mDisplay, "XV_AUTOPAINT_COLORKEY", False); + XvSetPortAttribute(mDisplay, xv_port, autopaint, 1); + break; + } } - fo = XvListImageFormats(mDisplay, xv_port, (int*)&formats); + fo = XvListImageFormats(mDisplay, xv_port, (int *) &formats); return 0; } static uint32_t control(uint32_t request, void *data, ...) { - switch (request) { - case VOCTRL_PAUSE: return (int_pause=1); - case VOCTRL_RESUME: return (int_pause=0); - case VOCTRL_QUERY_FORMAT: - return query_format(*((uint32_t*)data)); - case VOCTRL_GET_IMAGE: - return get_image(data); - case VOCTRL_DRAW_IMAGE: - return draw_image(data); - case VOCTRL_GUISUPPORT: - return VO_TRUE; - case VOCTRL_GET_PANSCAN: - if ( !vo_config_count || !vo_fs ) return VO_FALSE; - return VO_TRUE; - case VOCTRL_FULLSCREEN: - vo_x11_fullscreen(); - /* indended, fallthrough to update panscan on fullscreen/windowed switch */ - case VOCTRL_SET_PANSCAN: - if ( ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) || ( !vo_fs && vo_panscan_amount ) ) - { - int old_y = vo_panscan_y; - panscan_calc(); - - if(old_y != vo_panscan_y) - { - vo_x11_clearwindow_part(mDisplay, vo_window, vo_dwidth+vo_panscan_x-1, vo_dheight+vo_panscan_y-1, 1); - flip_page(); - } - } - return VO_TRUE; - case VOCTRL_SET_EQUALIZER: - { - va_list ap; - int value; - - va_start(ap, data); - value = va_arg(ap, int); - va_end(ap); - - return(vo_xv_set_eq(xv_port, data, value)); - } - case VOCTRL_GET_EQUALIZER: - { - va_list ap; - int *value; - - va_start(ap, data); - value = va_arg(ap, int*); - va_end(ap); - - return(vo_xv_get_eq(xv_port, data, value)); - } - case VOCTRL_ONTOP: - vo_x11_ontop(); - return VO_TRUE; - } - return VO_NOTIMPL; + switch (request) + { + case VOCTRL_PAUSE: + return (int_pause = 1); + case VOCTRL_RESUME: + return (int_pause = 0); + case VOCTRL_QUERY_FORMAT: + return query_format(*((uint32_t *) data)); + case VOCTRL_GET_IMAGE: + return get_image(data); + case VOCTRL_DRAW_IMAGE: + return draw_image(data); + case VOCTRL_GUISUPPORT: + return VO_TRUE; + case VOCTRL_GET_PANSCAN: + if (!vo_config_count || !vo_fs) + return VO_FALSE; + return VO_TRUE; + case VOCTRL_FULLSCREEN: + vo_x11_fullscreen(); + /* indended, fallthrough to update panscan on fullscreen/windowed switch */ + case VOCTRL_SET_PANSCAN: + if ((vo_fs && (vo_panscan != vo_panscan_amount)) + || (!vo_fs && vo_panscan_amount)) + { + int old_y = vo_panscan_y; + + panscan_calc(); + + if (old_y != vo_panscan_y) + { + vo_x11_clearwindow_part(mDisplay, vo_window, + vo_dwidth + vo_panscan_x - 1, + vo_dheight + vo_panscan_y - 1, + 1); + flip_page(); + } + } + return VO_TRUE; + case VOCTRL_SET_EQUALIZER: + { + va_list ap; + int value; + + va_start(ap, data); + value = va_arg(ap, int); + + va_end(ap); + + return (vo_xv_set_eq(xv_port, data, value)); + } + case VOCTRL_GET_EQUALIZER: + { + va_list ap; + int *value; + + va_start(ap, data); + value = va_arg(ap, int *); + + va_end(ap); + + return (vo_xv_get_eq(xv_port, data, value)); + } + case VOCTRL_ONTOP: + vo_x11_ontop(); + return VO_TRUE; + } + return VO_NOTIMPL; }
--- a/libvo/vo_xvidix.c Sun Jun 13 21:34:29 2004 +0000 +++ b/libvo/vo_xvidix.c Mon Jun 14 04:53:03 2004 +0000 @@ -38,8 +38,7 @@ #endif -static vo_info_t info = -{ +static vo_info_t info = { "X11 (VIDIX)", "xvidix", "Alex Beregszaszi", @@ -47,9 +46,7 @@ }; LIBVO_EXTERN(xvidix) - -#define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */ - +#define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */ /* X11 related variables */ /* Colorkey handling */ static XGCValues mGCV; @@ -72,7 +69,7 @@ static uint32_t drwX, drwY, drwWidth, drwHeight, drwBorderWidth, drwDepth, drwcX, drwcY, dwidth, dheight; -extern void set_video_eq( int cap ); +extern void set_video_eq(int cap); #ifdef HAVE_XINERAMA extern int xinerama_screen; @@ -81,129 +78,144 @@ static void set_window(int force_update) { Window mRoot; - if ( WinID ) - { - XGetGeometry(mDisplay, vo_window, &mRoot, &drwX, &drwY, &drwWidth, - &drwHeight, &drwBorderWidth, &drwDepth); - drwX = drwY = 0; + + if (WinID) + { + XGetGeometry(mDisplay, vo_window, &mRoot, &drwX, &drwY, &drwWidth, + &drwHeight, &drwBorderWidth, &drwDepth); + drwX = drwY = 0; - XTranslateCoordinates(mDisplay, vo_window, mRoot, 0, 0, - &drwcX, &drwcY, &mRoot); - aspect(&dwidth,&dheight,A_NOZOOM); - if (!vo_fs) - mp_msg(MSGT_VO, MSGL_V, "[xvidix] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n", - drwcX, drwcY, drwX, drwY, drwWidth, drwHeight); + XTranslateCoordinates(mDisplay, vo_window, mRoot, 0, 0, + &drwcX, &drwcY, &mRoot); + aspect(&dwidth, &dheight, A_NOZOOM); + if (!vo_fs) + mp_msg(MSGT_VO, MSGL_V, + "[xvidix] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n", + drwcX, drwcY, drwX, drwY, drwWidth, drwHeight); - /* following stuff copied from vo_xmga.c */ - } - else - { - aspect(&dwidth,&dheight,A_NOZOOM); - drwcX=drwX=vo_dx; drwcY=drwY=vo_dy; drwWidth=vo_dwidth; drwHeight=vo_dheight; - } + /* following stuff copied from vo_xmga.c */ + } else + { + aspect(&dwidth, &dheight, A_NOZOOM); + drwcX = drwX = vo_dx; + drwcY = drwY = vo_dy; + drwWidth = vo_dwidth; + drwHeight = vo_dheight; + } #if X11_FULLSCREEN if (vo_fs) { - aspect(&dwidth,&dheight,A_ZOOM); - drwX = (vo_screenwidth - (dwidth > vo_screenwidth ? vo_screenwidth : dwidth)) / 2; - drwcX = drwX; - drwY = (vo_screenheight - (dheight > vo_screenheight ? vo_screenheight : dheight)) / 2; - drwcY = drwY; - drwWidth = (dwidth > vo_screenwidth ? vo_screenwidth : dwidth); - drwHeight = (dheight > vo_screenheight ? vo_screenheight : dheight); - mp_msg(MSGT_VO, MSGL_V, "[xvidix-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n", - drwcX, drwcY, drwX, drwY, drwWidth, drwHeight); + aspect(&dwidth, &dheight, A_ZOOM); + drwX = + (vo_screenwidth - + (dwidth > vo_screenwidth ? vo_screenwidth : dwidth)) / 2; + drwcX = drwX; + drwY = + (vo_screenheight - + (dheight > vo_screenheight ? vo_screenheight : dheight)) / 2; + drwcY = drwY; + drwWidth = (dwidth > vo_screenwidth ? vo_screenwidth : dwidth); + drwHeight = + (dheight > vo_screenheight ? vo_screenheight : dheight); + mp_msg(MSGT_VO, MSGL_V, + "[xvidix-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n", + drwcX, drwcY, drwX, drwY, drwWidth, drwHeight); } #endif - vo_dwidth=drwWidth; vo_dheight=drwHeight; + vo_dwidth = drwWidth; + vo_dheight = drwHeight; #ifdef HAVE_XINERAMA if (XineramaIsActive(mDisplay)) { - XineramaScreenInfo *screens; - int num_screens; - int i = 0; - - screens = XineramaQueryScreens(mDisplay, &num_screens); - - /* find the screen we are on */ - while (i<num_screens && - ((screens[i].x_org < drwcX) || (screens[i].y_org < drwcY) || - (screens[i].x_org + screens[i].width >= drwcX) || - (screens[i].y_org + screens[i].height >= drwcY))) - { - i++; - } + XineramaScreenInfo *screens; + int num_screens; + int i = 0; + + screens = XineramaQueryScreens(mDisplay, &num_screens); + + /* find the screen we are on */ + while (i < num_screens && + ((screens[i].x_org < drwcX) || (screens[i].y_org < drwcY) || + (screens[i].x_org + screens[i].width >= drwcX) || + (screens[i].y_org + screens[i].height >= drwcY))) + { + i++; + } - if(i<num_screens) - { - /* save the screen we are on */ - xinerama_screen = i; - } else { - /* oops.. couldnt find the screen we are on - * because the upper left corner left the - * visual range. assume we are still on the - * same screen - */ - i = xinerama_screen; - } + if (i < num_screens) + { + /* save the screen we are on */ + xinerama_screen = i; + } else + { + /* oops.. couldnt find the screen we are on + * because the upper left corner left the + * visual range. assume we are still on the + * same screen + */ + i = xinerama_screen; + } - /* set drwcX and drwcY to the right values */ - drwcX = drwcX - screens[i].x_org; - drwcY = drwcY - screens[i].y_org; - XFree(screens); + /* set drwcX and drwcY to the right values */ + drwcX = drwcX - screens[i].x_org; + drwcY = drwcY - screens[i].y_org; + XFree(screens); } #endif - if ( vo_panscan > 0.0f && vo_fs ) - { - drwcX-=vo_panscan_x >> 1; - drwcY-=vo_panscan_y >> 1; - drwX-=vo_panscan_x >> 1; - drwY-=vo_panscan_y >> 1; - drwWidth+=vo_panscan_x; - drwHeight+=vo_panscan_y; - } + if (vo_panscan > 0.0f && vo_fs) + { + drwcX -= vo_panscan_x >> 1; + drwcY -= vo_panscan_y >> 1; + drwX -= vo_panscan_x >> 1; + drwY -= vo_panscan_y >> 1; + drwWidth += vo_panscan_x; + drwHeight += vo_panscan_y; + } /* set new values in VIDIX */ if (force_update || (window_x != drwcX) || (window_y != drwcY) || - (window_width != drwWidth) || (window_height != drwHeight)) + (window_width != drwWidth) || (window_height != drwHeight)) { - // do a backup of window coordinates - window_x = drwcX; - window_y = drwcY; - vo_dx = drwcX; - vo_dy = drwcY; - window_width = drwWidth; - window_height = drwHeight; + // do a backup of window coordinates + window_x = drwcX; + window_y = drwcY; + vo_dx = drwcX; + vo_dy = drwcY; + window_width = drwWidth; + window_height = drwHeight; - /* FIXME: implement runtime resize/move if possible, this way is very ugly! */ - vidix_stop(); - if (vidix_init(image_width, image_height, vo_dx, vo_dy, - window_width, window_height, image_format, vo_depthonscreen, - vo_screenwidth, vo_screenheight) != 0) + /* FIXME: implement runtime resize/move if possible, this way is very ugly! */ + vidix_stop(); + if (vidix_init(image_width, image_height, vo_dx, vo_dy, + window_width, window_height, image_format, + vo_depthonscreen, vo_screenwidth, + vo_screenheight) != 0) { - mp_msg(MSGT_VO, MSGL_FATAL, "Can't initialize VIDIX driver: %s\n", strerror(errno)); - abort(); - } - vidix_start(); + mp_msg(MSGT_VO, MSGL_FATAL, + "Can't initialize VIDIX driver: %s\n", strerror(errno)); + abort(); + } + vidix_start(); } - - mp_msg(MSGT_VO, MSGL_V, "[xvidix] window properties: pos: %dx%d, size: %dx%d\n", - vo_dx, vo_dy, window_width, window_height); + + mp_msg(MSGT_VO, MSGL_V, + "[xvidix] window properties: pos: %dx%d, size: %dx%d\n", vo_dx, + vo_dy, window_width, window_height); /* mDrawColorKey: */ /* fill drawable with specified color */ if (!(vo_colorkey & 0xff000000)) { - XSetBackground(mDisplay, vo_gc, 0L); - XClearWindow( mDisplay,vo_window ); - XSetForeground(mDisplay, vo_gc, colorkey); - XFillRectangle(mDisplay, vo_window, vo_gc, drwX, drwY, drwWidth, - (vo_fs ? drwHeight - 1 : drwHeight)); + XSetBackground(mDisplay, vo_gc, 0L); + XClearWindow(mDisplay, vo_window); + XSetForeground(mDisplay, vo_gc, colorkey); + XFillRectangle(mDisplay, vo_window, vo_gc, drwX, drwY, drwWidth, + (vo_fs ? drwHeight - 1 : drwHeight)); } /* flush, update drawable */ XFlush(mDisplay); @@ -215,9 +227,11 @@ * allocate colors and (shared) memory */ static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, - uint32_t d_height, uint32_t flags, char *title, uint32_t format) + uint32_t d_height, uint32_t flags, char *title, + uint32_t format) { XVisualInfo vinfo; + // XSizeHints hint; XSetWindowAttributes xswa; unsigned long xswamask; @@ -231,7 +245,7 @@ image_height = height; image_width = width; image_format = format; - vo_mouse_autohide=1; + vo_mouse_autohide = 1; aspect_save_orig(width, height); aspect_save_prescale(d_width, d_height); @@ -239,8 +253,10 @@ vo_dx = 0; vo_dy = 0; - vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; - geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); + vo_dx = (vo_screenwidth - d_width) / 2; + vo_dy = (vo_screenheight - d_height) / 2; + geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, + vo_screenheight); window_width = d_width; window_height = d_height; @@ -251,114 +267,146 @@ r = (vo_colorkey & 0x00ff0000) >> 16; g = (vo_colorkey & 0x0000ff00) >> 8; b = vo_colorkey & 0x000000ff; - switch(vo_depthonscreen) + switch (vo_depthonscreen) { - case 32: - colorkey = vo_colorkey; - break; - case 24: - colorkey = vo_colorkey & 0x00ffffff; - break; - case 16: - colorkey = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); - break; - case 15: - colorkey = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); - break; - default: - mp_msg(MSGT_VO, MSGL_ERR, "Sorry, this (%d) color depth is not supported\n", - vo_depthonscreen); + case 32: + colorkey = vo_colorkey; + break; + case 24: + colorkey = vo_colorkey & 0x00ffffff; + break; + case 16: + colorkey = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); + break; + case 15: + colorkey = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3); + break; + default: + mp_msg(MSGT_VO, MSGL_ERR, + "Sorry, this (%d) color depth is not supported\n", + vo_depthonscreen); } mp_msg(MSGT_VO, MSGL_INFO, "Using colorkey: %x\n", colorkey); aspect(&d_width, &d_height, A_NOZOOM); - vo_dwidth=d_width; vo_dheight=d_height; + vo_dwidth = d_width; + vo_dheight = d_height; #ifdef HAVE_NEW_GUI -if(use_gui) guiGetEvent( guiSetShVideo,0 ); // the GUI will set up / resize the window -else -{ + if (use_gui) + guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize the window + else + { #endif #ifdef X11_FULLSCREEN - if ( ( flags&1 )||(flags & 0x04) ) aspect(&d_width, &d_height, A_ZOOM); + if ((flags & 1) || (flags & 0x04)) + aspect(&d_width, &d_height, A_ZOOM); #endif - dwidth = d_width; - dheight = d_height; - /* Make the window */ - XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); + dwidth = d_width; + dheight = d_height; + /* Make the window */ + XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), + &attribs); - /* from vo_x11 */ - window_depth = attribs.depth; - if ((window_depth != 15) && (window_depth != 16) && (window_depth != 24) - && (window_depth != 32)) - window_depth = 24; - XMatchVisualInfo(mDisplay, mScreen, window_depth, TrueColor, &vinfo); + /* from vo_x11 */ + window_depth = attribs.depth; + if ((window_depth != 15) && (window_depth != 16) + && (window_depth != 24) && (window_depth != 32)) + window_depth = 24; + XMatchVisualInfo(mDisplay, mScreen, window_depth, TrueColor, + &vinfo); - xswa.background_pixel = BlackPixel(mDisplay, mScreen); - xswa.border_pixel = 0; - xswa.colormap = XCreateColormap(mDisplay, RootWindow(mDisplay, mScreen), - vinfo.visual, AllocNone); - xswa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | PropertyChangeMask | - ((WinID==0)?0:(ButtonPressMask | ButtonReleaseMask | PointerMotionMask)); - xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + xswa.background_pixel = BlackPixel(mDisplay, mScreen); + xswa.border_pixel = 0; + xswa.colormap = + XCreateColormap(mDisplay, RootWindow(mDisplay, mScreen), + vinfo.visual, AllocNone); + xswa.event_mask = + StructureNotifyMask | ExposureMask | KeyPressMask | + PropertyChangeMask | ((WinID == 0) ? 0 + : (ButtonPressMask | ButtonReleaseMask | + PointerMotionMask)); + xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - if (WinID >= 0) - { - vo_window = WinID ? ((Window)WinID) : RootWindow(mDisplay, mScreen); - if ( WinID ) - { - XUnmapWindow(mDisplay, vo_window); - XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa); - vo_x11_selectinput_witherr( mDisplay,vo_window,StructureNotifyMask | KeyPressMask | PropertyChangeMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ExposureMask ); - } else XSelectInput( mDisplay,vo_window,ExposureMask ); - } - else - { - if ( vo_window == None ) - { - vo_window = XCreateWindow(mDisplay, RootWindow(mDisplay, mScreen), - vo_dx, vo_dy, window_width, window_height, xswa.border_pixel, - vinfo.depth, InputOutput, vinfo.visual, xswamask, &xswa); + if (WinID >= 0) + { + vo_window = + WinID ? ((Window) WinID) : RootWindow(mDisplay, mScreen); + if (WinID) + { + XUnmapWindow(mDisplay, vo_window); + XChangeWindowAttributes(mDisplay, vo_window, xswamask, + &xswa); + vo_x11_selectinput_witherr(mDisplay, vo_window, + StructureNotifyMask | + KeyPressMask | + PropertyChangeMask | + PointerMotionMask | + ButtonPressMask | + ButtonReleaseMask | + ExposureMask); + } else + XSelectInput(mDisplay, vo_window, ExposureMask); + } else + { + if (vo_window == None) + { + vo_window = + XCreateWindow(mDisplay, RootWindow(mDisplay, mScreen), + vo_dx, vo_dy, window_width, + window_height, xswa.border_pixel, + vinfo.depth, InputOutput, vinfo.visual, + xswamask, &xswa); - vo_x11_classhint(mDisplay, vo_window, "xvidix"); - vo_hidecursor(mDisplay, vo_window); - vo_x11_sizehint( vo_dx,vo_dy,vo_dwidth,vo_dheight,0 ); + vo_x11_classhint(mDisplay, vo_window, "xvidix"); + vo_hidecursor(mDisplay, vo_window); + vo_x11_sizehint(vo_dx, vo_dy, vo_dwidth, vo_dheight, 0); - XStoreName(mDisplay, vo_window, title); - XMapWindow(mDisplay, vo_window); - - if ( flags&1 ) vo_x11_fullscreen(); - + XStoreName(mDisplay, vo_window, title); + XMapWindow(mDisplay, vo_window); + + if (flags & 1) + vo_x11_fullscreen(); + #ifdef HAVE_XINERAMA - vo_x11_xinerama_move(mDisplay, vo_window); + vo_x11_xinerama_move(mDisplay, vo_window); #endif - } else if ( !(flags&1) ) XMoveResizeWindow( mDisplay,vo_window,vo_dx,vo_dy,vo_dwidth,vo_dheight ); - } - - if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc ); - vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &mGCV); + } else if (!(flags & 1)) + XMoveResizeWindow(mDisplay, vo_window, vo_dx, vo_dy, + vo_dwidth, vo_dheight); + } + + if (vo_gc != None) + XFreeGC(mDisplay, vo_gc); + vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &mGCV); #ifdef HAVE_NEW_GUI -} + } #endif - if ( ( !WinID )&&( flags&1 ) ) { vo_dx=0; vo_dy=0; vo_dwidth=vo_screenwidth; vo_dheight=vo_screenheight; vo_fs=1; } + if ((!WinID) && (flags & 1)) + { + vo_dx = 0; + vo_dy = 0; + vo_dwidth = vo_screenwidth; + vo_dheight = vo_screenheight; + vo_fs = 1; + } if (vidix_grkey_support()) { - vidix_grkey_get(&gr_key); - gr_key.key_op = KEYS_PUT; - if (!(vo_colorkey & 0xff000000)) - { - gr_key.ckey.op = CKEY_TRUE; - gr_key.ckey.red = r; - gr_key.ckey.green = g; - gr_key.ckey.blue = b; - } - else - gr_key.ckey.op = CKEY_FALSE; - vidix_grkey_set(&gr_key); + vidix_grkey_get(&gr_key); + gr_key.key_op = KEYS_PUT; + if (!(vo_colorkey & 0xff000000)) + { + gr_key.ckey.op = CKEY_TRUE; + gr_key.ckey.red = r; + gr_key.ckey.green = g; + gr_key.ckey.blue = b; + } else + gr_key.ckey.op = CKEY_FALSE; + vidix_grkey_set(&gr_key); } set_window(1); @@ -368,11 +416,12 @@ panscan_calc(); - if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop); + if (vo_ontop) + vo_x11_setlayer(mDisplay, vo_window, vo_ontop); - saver_off(mDisplay); /* turning off screen saver */ + saver_off(mDisplay); /* turning off screen saver */ - return(0); + return (0); } static void check_events(void) @@ -380,7 +429,7 @@ const int event = vo_x11_check_events(mDisplay); if ((event & VO_EVENT_RESIZE) || (event & VO_EVENT_EXPOSE)) - set_window(0); + set_window(0); return; } @@ -389,18 +438,20 @@ overwritten with vidix functions (vosub_vidix.c) */ static void draw_osd(void) { - mp_msg(MSGT_VO, MSGL_FATAL, "[xvidix] error: didn't used vidix draw_osd!\n"); + mp_msg(MSGT_VO, MSGL_FATAL, + "[xvidix] error: didn't used vidix draw_osd!\n"); return; } static void flip_page(void) { - mp_msg(MSGT_VO, MSGL_FATAL, "[xvidix] error: didn't used vidix flip_page!\n"); + mp_msg(MSGT_VO, MSGL_FATAL, + "[xvidix] error: didn't used vidix flip_page!\n"); return; } -static uint32_t draw_slice(uint8_t *src[], int stride[], - int w, int h, int x, int y) +static uint32_t draw_slice(uint8_t * src[], int stride[], + int w, int h, int x, int y) { UNUSED(src); UNUSED(stride); @@ -408,34 +459,37 @@ UNUSED(h); UNUSED(x); UNUSED(y); - mp_msg(MSGT_VO, MSGL_FATAL, "[xvidix] error: didn't used vidix draw_slice!\n"); - return(-1); + mp_msg(MSGT_VO, MSGL_FATAL, + "[xvidix] error: didn't used vidix draw_slice!\n"); + return (-1); } -static uint32_t draw_frame(uint8_t *src[]) +static uint32_t draw_frame(uint8_t * src[]) { UNUSED(src); - mp_msg(MSGT_VO, MSGL_FATAL, "[xvidix] error: didn't used vidix draw_frame!\n"); - return(-1); + mp_msg(MSGT_VO, MSGL_FATAL, + "[xvidix] error: didn't used vidix draw_frame!\n"); + return (-1); } static uint32_t query_format(uint32_t format) { - return(vidix_query_fourcc(format)); + return (vidix_query_fourcc(format)); } static void uninit(void) { - if ( !vo_config_count ) return; + if (!vo_config_count) + return; vidix_term(); - + if (vidix_name) { - free(vidix_name); - vidix_name = NULL; + free(vidix_name); + vidix_name = NULL; } - saver_on(mDisplay); /* screen saver back on */ + saver_on(mDisplay); /* screen saver back on */ vo_x11_uninit(); } @@ -446,63 +500,69 @@ vidix_name = strdup(arg); else { - mp_msg(MSGT_VO, MSGL_INFO, "No vidix driver name provided, probing available ones (-v option for details)!\n"); - vidix_name = NULL; + mp_msg(MSGT_VO, MSGL_INFO, + "No vidix driver name provided, probing available ones (-v option for details)!\n"); + vidix_name = NULL; } - if (!vo_init()) return(-1); + if (!vo_init()) + return (-1); if (vidix_preinit(vidix_name, &video_out_xvidix) != 0) - return(1); + return (1); - return(0); + return (0); } static uint32_t control(uint32_t request, void *data, ...) { - switch (request) { - case VOCTRL_QUERY_FORMAT: - return query_format(*((uint32_t*)data)); - case VOCTRL_GUISUPPORT: - return VO_TRUE; - case VOCTRL_GET_PANSCAN: - if ( !vo_config_count || !vo_fs ) return VO_FALSE; - return VO_TRUE; - case VOCTRL_ONTOP: - vo_x11_ontop(); - return VO_TRUE; - case VOCTRL_FULLSCREEN: - vo_x11_fullscreen(); - case VOCTRL_SET_PANSCAN: - if ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) - { - panscan_calc(); - set_window(0); - } - return VO_TRUE; - case VOCTRL_SET_EQUALIZER: - { - va_list ap; - int value; - - va_start(ap, data); - value = va_arg(ap, int); - va_end(ap); + switch (request) + { + case VOCTRL_QUERY_FORMAT: + return query_format(*((uint32_t *) data)); + case VOCTRL_GUISUPPORT: + return VO_TRUE; + case VOCTRL_GET_PANSCAN: + if (!vo_config_count || !vo_fs) + return VO_FALSE; + return VO_TRUE; + case VOCTRL_ONTOP: + vo_x11_ontop(); + return VO_TRUE; + case VOCTRL_FULLSCREEN: + vo_x11_fullscreen(); + case VOCTRL_SET_PANSCAN: + if (vo_fs && (vo_panscan != vo_panscan_amount)) + { + panscan_calc(); + set_window(0); + } + return VO_TRUE; + case VOCTRL_SET_EQUALIZER: + { + va_list ap; + int value; - return vidix_control(request, data, (int *)value); - } - case VOCTRL_GET_EQUALIZER: - { - va_list ap; - int *value; - - va_start(ap, data); - value = va_arg(ap, int*); - va_end(ap); + va_start(ap, data); + value = va_arg(ap, int); + + va_end(ap); - return vidix_control(request, data, value); - } - } - return vidix_control(request, data); + return vidix_control(request, data, (int *) value); + } + case VOCTRL_GET_EQUALIZER: + { + va_list ap; + int *value; + + va_start(ap, data); + value = va_arg(ap, int *); + + va_end(ap); + + return vidix_control(request, data, value); + } + } + return vidix_control(request, data); // return VO_NOTIMPL; }
--- a/libvo/x11_common.c Sun Jun 13 21:34:29 2004 +0000 +++ b/libvo/x11_common.c Mon Jun 14 04:53:03 2004 +0000 @@ -57,30 +57,30 @@ #define WIN_LAYER_NORMAL 4 #define WIN_LAYER_ONTOP 6 #define WIN_LAYER_ABOVE_DOCK 10 - -int fs_layer=WIN_LAYER_ABOVE_DOCK; -static int orig_layer=0; + +int fs_layer = WIN_LAYER_ABOVE_DOCK; +static int orig_layer = 0; static int old_gravity = NorthWestGravity; -int stop_xscreensaver=0; +int stop_xscreensaver = 0; -static int dpms_disabled=0; -static int timeout_save=0; -static int kdescreensaver_was_running=0; +static int dpms_disabled = 0; +static int timeout_save = 0; +static int kdescreensaver_was_running = 0; -char* mDisplayName=NULL; -Display* mDisplay=NULL; -Window mRootWin; +char *mDisplayName = NULL; +Display *mDisplay = NULL; +Window mRootWin; int mScreen; int mLocalDisplay; /* output window id */ -int WinID=-1; +int WinID = -1; int vo_mouse_autohide = 0; int vo_wm_type = 0; static int vo_fs_type = 0; static int vo_fs_flip = 0; -char** vo_fstype_list; +char **vo_fstype_list; /* if equal to 1 means that WM is a metacity (broken as hell) */ int metacity_hack = 0; @@ -110,7 +110,7 @@ int xinerama_y = 0; #endif #ifdef HAVE_XF86VM -XF86VidModeModeInfo **vidmodes=NULL; +XF86VidModeModeInfo **vidmodes = NULL; XF86VidModeModeLine modeline; #endif @@ -124,80 +124,85 @@ * _NET_WM_STATE_ADD -- add state * _NET_WM_STATE_TOGGLE -- toggle */ -void vo_x11_ewmh_fullscreen( int action ) +void vo_x11_ewmh_fullscreen(int action) { - assert( action == _NET_WM_STATE_REMOVE || - action == _NET_WM_STATE_ADD || - action == _NET_WM_STATE_TOGGLE ); - - if ( vo_fs_type & vo_wm_FULLSCREEN ) - { - XEvent xev; - - /* init X event structure for _NET_WM_FULLSCREEN client msg */ - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.message_type = XInternAtom( mDisplay, - "_NET_WM_STATE", False ); - xev.xclient.window = vo_window; - xev.xclient.format = 32; - xev.xclient.data.l[0] = action; - xev.xclient.data.l[1] = XInternAtom( mDisplay, - "_NET_WM_STATE_FULLSCREEN", False ); - xev.xclient.data.l[2] = 0; - xev.xclient.data.l[3] = 0; - xev.xclient.data.l[4] = 0; - - /* finally send that damn thing */ - if ( !XSendEvent( mDisplay, DefaultRootWindow( mDisplay ), False, - SubstructureRedirectMask | SubstructureNotifyMask, &xev ) ) + assert(action == _NET_WM_STATE_REMOVE || + action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE); + + if (vo_fs_type & vo_wm_FULLSCREEN) { - mp_msg( MSGT_VO,MSGL_ERR, MSGTR_EwmhFullscreenStateFailed ); + XEvent xev; + + /* init X event structure for _NET_WM_FULLSCREEN client msg */ + xev.xclient.type = ClientMessage; + xev.xclient.serial = 0; + xev.xclient.send_event = True; + xev.xclient.message_type = XInternAtom(mDisplay, + "_NET_WM_STATE", False); + xev.xclient.window = vo_window; + xev.xclient.format = 32; + xev.xclient.data.l[0] = action; + xev.xclient.data.l[1] = XInternAtom(mDisplay, + "_NET_WM_STATE_FULLSCREEN", + False); + xev.xclient.data.l[2] = 0; + xev.xclient.data.l[3] = 0; + xev.xclient.data.l[4] = 0; + + /* finally send that damn thing */ + if (!XSendEvent(mDisplay, DefaultRootWindow(mDisplay), False, + SubstructureRedirectMask | SubstructureNotifyMask, + &xev)) + { + mp_msg(MSGT_VO, MSGL_ERR, MSGTR_EwmhFullscreenStateFailed); + } } - } } -void vo_hidecursor ( Display *disp , Window win ) +void vo_hidecursor(Display * disp, Window win) { - Cursor no_ptr; - Pixmap bm_no; - XColor black,dummy; - Colormap colormap; - static unsigned char bm_no_data[] = { 0,0,0,0, 0,0,0,0 }; + Cursor no_ptr; + Pixmap bm_no; + XColor black, dummy; + Colormap colormap; + static unsigned char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - if(WinID==0) return; // do not hide, if we're playing at rootwin - - colormap = DefaultColormap(disp,DefaultScreen(disp)); - XAllocNamedColor(disp,colormap,"black",&black,&dummy); - bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8,8); - no_ptr=XCreatePixmapCursor(disp, bm_no, bm_no,&black, &black,0, 0); - XDefineCursor(disp,win,no_ptr); - XFreeCursor( disp,no_ptr ); - if (bm_no != None) - XFreePixmap(disp, bm_no); + if (WinID == 0) + return; // do not hide, if we're playing at rootwin + + colormap = DefaultColormap(disp, DefaultScreen(disp)); + XAllocNamedColor(disp, colormap, "black", &black, &dummy); + bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8); + no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0); + XDefineCursor(disp, win, no_ptr); + XFreeCursor(disp, no_ptr); + if (bm_no != None) + XFreePixmap(disp, bm_no); } -void vo_showcursor( Display *disp, Window win ) -{ - if ( WinID==0 ) return; - XDefineCursor( disp,win,0 ); +void vo_showcursor(Display * disp, Window win) +{ + if (WinID == 0) + return; + XDefineCursor(disp, win, 0); } -static int x11_errorhandler(Display *display, XErrorEvent *event) +static int x11_errorhandler(Display * display, XErrorEvent * event) { #define MSGLEN 60 char msg[MSGLEN]; - - XGetErrorText(display, event->error_code, (char *)&msg, MSGLEN); - - mp_msg(MSGT_VO,MSGL_ERR,"X11 error: %s\n", msg); - - mp_msg(MSGT_VO,MSGL_V,"Type: %x, display: %x, resourceid: %x, serial: %x\n", - event->type, event->display, event->resourceid, event->serial); - mp_msg(MSGT_VO,MSGL_V,"Error code: %x, request code: %x, minor code: %x\n", - event->error_code, event->request_code, event->minor_code); - + + XGetErrorText(display, event->error_code, (char *) &msg, MSGLEN); + + mp_msg(MSGT_VO, MSGL_ERR, "X11 error: %s\n", msg); + + mp_msg(MSGT_VO, MSGL_V, + "Type: %x, display: %x, resourceid: %x, serial: %x\n", + event->type, event->display, event->resourceid, event->serial); + mp_msg(MSGT_VO, MSGL_V, + "Error code: %x, request code: %x, minor code: %x\n", + event->error_code, event->request_code, event->minor_code); + abort(); //exit_player("X11 error"); #undef MSGLEN @@ -205,278 +210,314 @@ void fstype_help(void) { - mp_msg(MSGT_VO, MSGL_INFO, MSGTR_AvailableFsType); - - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "none", "don't set fullscreen window layer"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer", "use _WIN_LAYER hint with default layer"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer=<0..15>", "use _WIN_LAYER hint with a given layer number"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "netwm", "force NETWM style"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "above", "use _NETWM_STATE_ABOVE hint if available"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "below", "use _NETWM_STATE_BELOW hint if available"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "fullscreen", "use _NETWM_STATE_FULLSCREEN hint if availale"); - mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "stays_on_top", "use _NETWM_STATE_STAYS_ON_TOP hint if available"); - mp_msg(MSGT_VO, MSGL_INFO, "You can also negate the settings with simply putting '-' in the beginning"); + mp_msg(MSGT_VO, MSGL_INFO, MSGTR_AvailableFsType); + + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "none", + "don't set fullscreen window layer"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer", + "use _WIN_LAYER hint with default layer"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer=<0..15>", + "use _WIN_LAYER hint with a given layer number"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "netwm", + "force NETWM style"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "above", + "use _NETWM_STATE_ABOVE hint if available"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "below", + "use _NETWM_STATE_BELOW hint if available"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "fullscreen", + "use _NETWM_STATE_FULLSCREEN hint if availale"); + mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "stays_on_top", + "use _NETWM_STATE_STAYS_ON_TOP hint if available"); + mp_msg(MSGT_VO, MSGL_INFO, + "You can also negate the settings with simply putting '-' in the beginning"); } static void fstype_dump(int fstype) { if (fstype) { - mp_msg(MSGT_VO, MSGL_V, "[x11] Current fstype setting honours"); - if (fstype & vo_wm_LAYER) - mp_msg(MSGT_VO, MSGL_V, " LAYER"); - if (fstype & vo_wm_FULLSCREEN) - mp_msg(MSGT_VO, MSGL_V, " FULLSCREEN"); - if (fstype & vo_wm_STAYS_ON_TOP) - mp_msg(MSGT_VO, MSGL_V, " STAYS_ON_TOP"); - if (fstype & vo_wm_ABOVE) - mp_msg(MSGT_VO, MSGL_V, " ABOVE"); - if (fstype & vo_wm_BELOW) - mp_msg(MSGT_VO, MSGL_V, " BELOW"); - mp_msg(MSGT_VO, MSGL_V, " X atoms\n"); - } - else - mp_msg(MSGT_VO, MSGL_V, "[x11] Current fstype setting doesn't honour any X atoms\n"); + mp_msg(MSGT_VO, MSGL_V, "[x11] Current fstype setting honours"); + if (fstype & vo_wm_LAYER) + mp_msg(MSGT_VO, MSGL_V, " LAYER"); + if (fstype & vo_wm_FULLSCREEN) + mp_msg(MSGT_VO, MSGL_V, " FULLSCREEN"); + if (fstype & vo_wm_STAYS_ON_TOP) + mp_msg(MSGT_VO, MSGL_V, " STAYS_ON_TOP"); + if (fstype & vo_wm_ABOVE) + mp_msg(MSGT_VO, MSGL_V, " ABOVE"); + if (fstype & vo_wm_BELOW) + mp_msg(MSGT_VO, MSGL_V, " BELOW"); + mp_msg(MSGT_VO, MSGL_V, " X atoms\n"); + } else + mp_msg(MSGT_VO, MSGL_V, + "[x11] Current fstype setting doesn't honour any X atoms\n"); } - + static int net_wm_support_state_test(Atom atom) { #define NET_WM_STATE_TEST(x) { if (atom == XA_NET_WM_STATE_##x) { mp_msg( MSGT_VO,MSGL_V, "[x11] Detected wm supports " #x " state.\n" ); return vo_wm_##x; } } - - NET_WM_STATE_TEST(FULLSCREEN); - NET_WM_STATE_TEST(ABOVE); - NET_WM_STATE_TEST(STAYS_ON_TOP); - NET_WM_STATE_TEST(BELOW); - return 0; + + NET_WM_STATE_TEST(FULLSCREEN); + NET_WM_STATE_TEST(ABOVE); + NET_WM_STATE_TEST(STAYS_ON_TOP); + NET_WM_STATE_TEST(BELOW); + return 0; } -static int x11_get_property(Atom type, Atom **args, unsigned long *nitems) +static int x11_get_property(Atom type, Atom ** args, unsigned long *nitems) { - int format; - unsigned long bytesafter; + int format; + unsigned long bytesafter; - return (Success == XGetWindowProperty( mDisplay,mRootWin,type,0,16384, - False,AnyPropertyType,&type,&format,nitems,&bytesafter, - (unsigned char **) args ) && *nitems > 0 ); + return (Success == + XGetWindowProperty(mDisplay, mRootWin, type, 0, 16384, False, + AnyPropertyType, &type, &format, nitems, + &bytesafter, (unsigned char **) args) + && *nitems > 0); } static int vo_wm_detect(void) { - int i; - int wm = 0; - unsigned long nitems; - Atom * args = NULL; - - if ( WinID >= 0 ) return 0; - + int i; + int wm = 0; + unsigned long nitems; + Atom *args = NULL; + + if (WinID >= 0) + return 0; + // -- supports layers - if (x11_get_property(XA_WIN_PROTOCOLS, &args, &nitems)) - { - mp_msg( MSGT_VO,MSGL_V,"[x11] Detected wm supports layers.\n" ); - for (i = 0; i < nitems; i++) - { - if ( args[i] == XA_WIN_LAYER) { - wm |= vo_wm_LAYER; - metacity_hack |= 1; - } else - // metacity is the only manager I know which reports support only for _WIN_LAYER - // hint in _WIN_PROTOCOLS (what's more support for it is broken) - metacity_hack |= 2; - } - XFree( args ); - if (wm && (metacity_hack == 1)) - { - // metacity reports that it supports layers, but it is not really truth :-) - wm ^= vo_wm_LAYER; - mp_msg( MSGT_VO,MSGL_V,"[x11] Using workaround for Metacity bugs.\n" ); - } - } - + if (x11_get_property(XA_WIN_PROTOCOLS, &args, &nitems)) + { + mp_msg(MSGT_VO, MSGL_V, "[x11] Detected wm supports layers.\n"); + for (i = 0; i < nitems; i++) + { + if (args[i] == XA_WIN_LAYER) + { + wm |= vo_wm_LAYER; + metacity_hack |= 1; + } else + // metacity is the only manager I know which reports support only for _WIN_LAYER + // hint in _WIN_PROTOCOLS (what's more support for it is broken) + metacity_hack |= 2; + } + XFree(args); + if (wm && (metacity_hack == 1)) + { + // metacity reports that it supports layers, but it is not really truth :-) + wm ^= vo_wm_LAYER; + mp_msg(MSGT_VO, MSGL_V, + "[x11] Using workaround for Metacity bugs.\n"); + } + } // --- netwm - if (x11_get_property(XA_NET_SUPPORTED, &args, &nitems)) - { - mp_msg( MSGT_VO,MSGL_V,"[x11] Detected wm supports NetWM.\n" ); - for (i = 0; i < nitems; i++) - wm |= net_wm_support_state_test (args[i]); - XFree( args ); + if (x11_get_property(XA_NET_SUPPORTED, &args, &nitems)) + { + mp_msg(MSGT_VO, MSGL_V, "[x11] Detected wm supports NetWM.\n"); + for (i = 0; i < nitems; i++) + wm |= net_wm_support_state_test(args[i]); + XFree(args); #if 0 - // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support - // (in their implementation it only changes internal state of window, nothing more!!!) - if (wm & vo_wm_FULLSCREEN) - { - if (x11_get_property(XA_BLACKBOX_PID, &args, &nitems)) - { - mp_msg( MSGT_VO,MSGL_V,"[x11] Detected wm is a broken OpenBox.\n" ); - wm ^= vo_wm_FULLSCREEN; - } - XFree (args); - } + // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support + // (in their implementation it only changes internal state of window, nothing more!!!) + if (wm & vo_wm_FULLSCREEN) + { + if (x11_get_property(XA_BLACKBOX_PID, &args, &nitems)) + { + mp_msg(MSGT_VO, MSGL_V, + "[x11] Detected wm is a broken OpenBox.\n"); + wm ^= vo_wm_FULLSCREEN; + } + XFree(args); + } #endif - } + } - if ( wm == 0 ) mp_msg( MSGT_VO,MSGL_V,"[x11] Unknown wm type...\n" ); - return wm; -} + if (wm == 0) + mp_msg(MSGT_VO, MSGL_V, "[x11] Unknown wm type...\n"); + return wm; +} static void init_atoms(void) { - XA_INIT(_NET_SUPPORTED); - XA_INIT(_NET_WM_STATE); - XA_INIT(_NET_WM_STATE_FULLSCREEN); - XA_INIT(_NET_WM_STATE_ABOVE); - XA_INIT(_NET_WM_STATE_STAYS_ON_TOP); - XA_INIT(_NET_WM_STATE_BELOW); - XA_INIT(_NET_WM_PID); - XA_INIT(_WIN_PROTOCOLS); - XA_INIT(_WIN_LAYER); - XA_INIT(_WIN_HINTS); - XA_INIT(_BLACKBOX_PID); + XA_INIT(_NET_SUPPORTED); + XA_INIT(_NET_WM_STATE); + XA_INIT(_NET_WM_STATE_FULLSCREEN); + XA_INIT(_NET_WM_STATE_ABOVE); + XA_INIT(_NET_WM_STATE_STAYS_ON_TOP); + XA_INIT(_NET_WM_STATE_BELOW); + XA_INIT(_NET_WM_PID); + XA_INIT(_WIN_PROTOCOLS); + XA_INIT(_WIN_LAYER); + XA_INIT(_WIN_HINTS); + XA_INIT(_BLACKBOX_PID); } -int vo_init( void ) +int vo_init(void) { // int mScreen; - int depth, bpp; - unsigned int mask; + int depth, bpp; + unsigned int mask; + // char * DisplayName = ":0.0"; // Display * mDisplay; - XImage * mXImage = NULL; + XImage *mXImage = NULL; + // Window mRootWin; - XWindowAttributes attribs; - char* dispName; + XWindowAttributes attribs; + char *dispName; - if(vo_depthonscreen) return 1; // already called + if (vo_depthonscreen) + return 1; // already called - XSetErrorHandler(x11_errorhandler); + XSetErrorHandler(x11_errorhandler); #if 0 - if (!mDisplayName) - if (!(mDisplayName=getenv("DISPLAY"))) - mDisplayName=strdup(":0.0"); + if (!mDisplayName) + if (!(mDisplayName = getenv("DISPLAY"))) + mDisplayName = strdup(":0.0"); #else - dispName = XDisplayName(mDisplayName); + dispName = XDisplayName(mDisplayName); #endif - mp_msg(MSGT_VO,MSGL_V,"X11 opening display: %s\n", dispName); + mp_msg(MSGT_VO, MSGL_V, "X11 opening display: %s\n", dispName); - mDisplay=XOpenDisplay(dispName); - if ( !mDisplay ) - { - mp_msg(MSGT_VO,MSGL_ERR,"vo: couldn't open the X11 display (%s)!\n",dispName ); - return 0; - } - mScreen=DefaultScreen( mDisplay ); // Screen ID. - mRootWin=RootWindow( mDisplay,mScreen );// Root window ID. + mDisplay = XOpenDisplay(dispName); + if (!mDisplay) + { + mp_msg(MSGT_VO, MSGL_ERR, + "vo: couldn't open the X11 display (%s)!\n", dispName); + return 0; + } + mScreen = DefaultScreen(mDisplay); // Screen ID. + mRootWin = RootWindow(mDisplay, mScreen); // Root window ID. - init_atoms(); - + init_atoms(); + #ifdef HAVE_XINERAMA - if(XineramaIsActive(mDisplay)) - { - XineramaScreenInfo *screens; - int num_screens; + if (XineramaIsActive(mDisplay)) + { + XineramaScreenInfo *screens; + int num_screens; - screens = XineramaQueryScreens(mDisplay, &num_screens); - if(xinerama_screen >= num_screens) xinerama_screen = 0; - if (! vo_screenwidth) - vo_screenwidth=screens[xinerama_screen].width; - if (! vo_screenheight) - vo_screenheight=screens[xinerama_screen].height; - xinerama_x = screens[xinerama_screen].x_org; - xinerama_y = screens[xinerama_screen].y_org; + screens = XineramaQueryScreens(mDisplay, &num_screens); + if (xinerama_screen >= num_screens) + xinerama_screen = 0; + if (!vo_screenwidth) + vo_screenwidth = screens[xinerama_screen].width; + if (!vo_screenheight) + vo_screenheight = screens[xinerama_screen].height; + xinerama_x = screens[xinerama_screen].x_org; + xinerama_y = screens[xinerama_screen].y_org; - XFree(screens); - } - else + XFree(screens); + } else #endif #ifdef HAVE_XF86VM - { - int clock; - XF86VidModeGetModeLine( mDisplay,mScreen,&clock ,&modeline ); - if ( !vo_screenwidth ) vo_screenwidth=modeline.hdisplay; - if ( !vo_screenheight ) vo_screenheight=modeline.vdisplay; - } + { + int clock; + + XF86VidModeGetModeLine(mDisplay, mScreen, &clock, &modeline); + if (!vo_screenwidth) + vo_screenwidth = modeline.hdisplay; + if (!vo_screenheight) + vo_screenheight = modeline.vdisplay; + } #endif - { - if (! vo_screenwidth) - vo_screenwidth=DisplayWidth( mDisplay,mScreen ); - if (! vo_screenheight) - vo_screenheight=DisplayHeight( mDisplay,mScreen ); - } - // get color depth (from root window, or the best visual): - XGetWindowAttributes(mDisplay, mRootWin, &attribs); - depth=attribs.depth; + { + if (!vo_screenwidth) + vo_screenwidth = DisplayWidth(mDisplay, mScreen); + if (!vo_screenheight) + vo_screenheight = DisplayHeight(mDisplay, mScreen); + } + // get color depth (from root window, or the best visual): + XGetWindowAttributes(mDisplay, mRootWin, &attribs); + depth = attribs.depth; - if (depth != 15 && depth != 16 && depth != 24 && depth != 32) { - Visual *visual; + if (depth != 15 && depth != 16 && depth != 24 && depth != 32) + { + Visual *visual; + + depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual); + if (depth != -1) + mXImage = XCreateImage(mDisplay, visual, depth, ZPixmap, + 0, NULL, 1, 1, 8, 1); + } else + mXImage = + XGetImage(mDisplay, mRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap); - depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual); - if (depth != -1) - mXImage=XCreateImage(mDisplay, visual, depth, ZPixmap, - 0, NULL, 1, 1, 8, 1); - } else - mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap ); - - vo_depthonscreen = depth; // display depth on screen + vo_depthonscreen = depth; // display depth on screen - // get bits/pixel from XImage structure: - if (mXImage == NULL) { - mask = 0; - } else { - /* - * for the depth==24 case, the XImage structures might use - * 24 or 32 bits of data per pixel. The global variable - * vo_depthonscreen stores the amount of data per pixel in the - * XImage structure! - * - * Maybe we should rename vo_depthonscreen to (or add) vo_bpp? - */ - bpp=mXImage->bits_per_pixel; - if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi - mask=mXImage->red_mask|mXImage->green_mask|mXImage->blue_mask; - mp_msg(MSGT_VO,MSGL_V,"vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", - mask,mXImage->red_mask,mXImage->green_mask,mXImage->blue_mask); - XDestroyImage( mXImage ); - } - if(((vo_depthonscreen+7)/8)==2){ - if(mask==0x7FFF) vo_depthonscreen=15; else - if(mask==0xFFFF) vo_depthonscreen=16; - } + // get bits/pixel from XImage structure: + if (mXImage == NULL) + { + mask = 0; + } else + { + /* + * for the depth==24 case, the XImage structures might use + * 24 or 32 bits of data per pixel. The global variable + * vo_depthonscreen stores the amount of data per pixel in the + * XImage structure! + * + * Maybe we should rename vo_depthonscreen to (or add) vo_bpp? + */ + bpp = mXImage->bits_per_pixel; + if ((vo_depthonscreen + 7) / 8 != (bpp + 7) / 8) + vo_depthonscreen = bpp; // by A'rpi + mask = + mXImage->red_mask | mXImage->green_mask | mXImage->blue_mask; + mp_msg(MSGT_VO, MSGL_V, + "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask, + mXImage->red_mask, mXImage->green_mask, mXImage->blue_mask); + XDestroyImage(mXImage); + } + if (((vo_depthonscreen + 7) / 8) == 2) + { + if (mask == 0x7FFF) + vo_depthonscreen = 15; + else if (mask == 0xFFFF) + vo_depthonscreen = 16; + } // XCloseDisplay( mDisplay ); /* slightly improved local display detection AST */ - if ( strncmp(dispName, "unix:", 5) == 0) - dispName += 4; - else if ( strncmp(dispName, "localhost:", 10) == 0) - dispName += 9; - if (*dispName==':' && atoi(dispName+1)<10) mLocalDisplay=1; else mLocalDisplay=0; - mp_msg(MSGT_VO,MSGL_INFO,"vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n", - vo_screenwidth,vo_screenheight, - depth, vo_depthonscreen, - dispName,mLocalDisplay?"local":"remote"); + if (strncmp(dispName, "unix:", 5) == 0) + dispName += 4; + else if (strncmp(dispName, "localhost:", 10) == 0) + dispName += 9; + if (*dispName == ':' && atoi(dispName + 1) < 10) + mLocalDisplay = 1; + else + mLocalDisplay = 0; + mp_msg(MSGT_VO, MSGL_INFO, + "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n", + vo_screenwidth, vo_screenheight, depth, vo_depthonscreen, + dispName, mLocalDisplay ? "local" : "remote"); - vo_wm_type=vo_wm_detect(); + vo_wm_type = vo_wm_detect(); + + vo_fs_type = vo_x11_get_fs_type(vo_wm_type); - vo_fs_type=vo_x11_get_fs_type(vo_wm_type); - - fstype_dump(vo_fs_type); + fstype_dump(vo_fs_type); - saver_off(mDisplay); - return 1; + saver_off(mDisplay); + return 1; } -void vo_uninit( void ) +void vo_uninit(void) { - if (!mDisplay) - { - mp_msg(MSGT_VO, MSGL_V, "vo: x11 uninit called but X11 not inited..\n"); - return; - } + if (!mDisplay) + { + mp_msg(MSGT_VO, MSGL_V, + "vo: x11 uninit called but X11 not inited..\n"); + return; + } // if( !vo_depthonscreen ) return; - mp_msg(MSGT_VO,MSGL_V,"vo: uninit ...\n" ); - XSetErrorHandler(NULL); - XCloseDisplay( mDisplay ); - vo_depthonscreen = 0; - mDisplay=NULL; + mp_msg(MSGT_VO, MSGL_V, "vo: uninit ...\n"); + XSetErrorHandler(NULL); + XCloseDisplay(mDisplay); + vo_depthonscreen = 0; + mDisplay = NULL; } #include "../osdep/keycodes.h" @@ -485,120 +526,285 @@ extern void mplayer_put_key(int code); #ifdef XF86XK_AudioPause -void vo_x11_putkey_ext(int keysym){ - switch ( keysym ) - { - case XF86XK_AudioPause: mplayer_put_key(KEY_XF86_PAUSE); break; - case XF86XK_AudioStop: mplayer_put_key(KEY_XF86_STOP); break; - case XF86XK_AudioPrev: mplayer_put_key(KEY_XF86_PREV); break; - case XF86XK_AudioNext: mplayer_put_key(KEY_XF86_NEXT); break; - default: break; - } +void vo_x11_putkey_ext(int keysym) +{ + switch (keysym) + { + case XF86XK_AudioPause: + mplayer_put_key(KEY_XF86_PAUSE); + break; + case XF86XK_AudioStop: + mplayer_put_key(KEY_XF86_STOP); + break; + case XF86XK_AudioPrev: + mplayer_put_key(KEY_XF86_PREV); + break; + case XF86XK_AudioNext: + mplayer_put_key(KEY_XF86_NEXT); + break; + default: + break; + } } #endif -void vo_x11_putkey(int key){ - switch ( key ) - { - case wsLeft: mplayer_put_key(KEY_LEFT); break; - case wsRight: mplayer_put_key(KEY_RIGHT); break; - case wsUp: mplayer_put_key(KEY_UP); break; - case wsDown: mplayer_put_key(KEY_DOWN); break; - case wsSpace: mplayer_put_key(' '); break; - case wsEscape: mplayer_put_key(KEY_ESC); break; - case wsEnter: mplayer_put_key(KEY_ENTER); break; - case wsBackSpace: mplayer_put_key(KEY_BS); break; - case wsDelete: mplayer_put_key(KEY_DELETE); break; - case wsInsert: mplayer_put_key(KEY_INSERT); break; - case wsHome: mplayer_put_key(KEY_HOME); break; - case wsEnd: mplayer_put_key(KEY_END); break; - case wsPageUp: mplayer_put_key(KEY_PAGE_UP); break; - case wsPageDown: mplayer_put_key(KEY_PAGE_DOWN); break; - case wsF1: mplayer_put_key(KEY_F+1); break; - case wsF2: mplayer_put_key(KEY_F+2); break; - case wsF3: mplayer_put_key(KEY_F+3); break; - case wsF4: mplayer_put_key(KEY_F+4); break; - case wsF5: mplayer_put_key(KEY_F+5); break; - case wsF6: mplayer_put_key(KEY_F+6); break; - case wsF7: mplayer_put_key(KEY_F+7); break; - case wsF8: mplayer_put_key(KEY_F+8); break; - case wsF9: mplayer_put_key(KEY_F+9); break; - case wsF10: mplayer_put_key(KEY_F+10); break; - case wsF11: mplayer_put_key(KEY_F+11); break; - case wsF12: mplayer_put_key(KEY_F+12); break; - case wsq: - case wsQ: mplayer_put_key('q'); break; - case wsp: - case wsP: mplayer_put_key('p'); break; - case wsMinus: - case wsGrayMinus: mplayer_put_key('-'); break; - case wsPlus: - case wsGrayPlus: mplayer_put_key('+'); break; - case wsGrayMul: - case wsMul: mplayer_put_key('*'); break; - case wsGrayDiv: - case wsDiv: mplayer_put_key('/'); break; - case wsLess: mplayer_put_key('<'); break; - case wsMore: mplayer_put_key('>'); break; - case wsGray0: mplayer_put_key(KEY_KP0); break; - case wsGrayEnd: - case wsGray1: mplayer_put_key(KEY_KP1); break; - case wsGrayDown: - case wsGray2: mplayer_put_key(KEY_KP2); break; - case wsGrayPgDn: - case wsGray3: mplayer_put_key(KEY_KP3); break; - case wsGrayLeft: - case wsGray4: mplayer_put_key(KEY_KP4); break; - case wsGray5Dup: - case wsGray5: mplayer_put_key(KEY_KP5); break; - case wsGrayRight: - case wsGray6: mplayer_put_key(KEY_KP6); break; - case wsGrayHome: - case wsGray7: mplayer_put_key(KEY_KP7); break; - case wsGrayUp: - case wsGray8: mplayer_put_key(KEY_KP8); break; - case wsGrayPgUp: - case wsGray9: mplayer_put_key(KEY_KP9); break; - case wsGrayDecimal: mplayer_put_key(KEY_KPDEC); break; - case wsGrayInsert: mplayer_put_key(KEY_KPINS); break; - case wsGrayDelete: mplayer_put_key(KEY_KPDEL); break; - case wsGrayEnter: mplayer_put_key(KEY_KPENTER); break; - case wsm: - case wsM: mplayer_put_key('m'); break; - case wso: - case wsO: mplayer_put_key('o'); break; +void vo_x11_putkey(int key) +{ + switch (key) + { + case wsLeft: + mplayer_put_key(KEY_LEFT); + break; + case wsRight: + mplayer_put_key(KEY_RIGHT); + break; + case wsUp: + mplayer_put_key(KEY_UP); + break; + case wsDown: + mplayer_put_key(KEY_DOWN); + break; + case wsSpace: + mplayer_put_key(' '); + break; + case wsEscape: + mplayer_put_key(KEY_ESC); + break; + case wsEnter: + mplayer_put_key(KEY_ENTER); + break; + case wsBackSpace: + mplayer_put_key(KEY_BS); + break; + case wsDelete: + mplayer_put_key(KEY_DELETE); + break; + case wsInsert: + mplayer_put_key(KEY_INSERT); + break; + case wsHome: + mplayer_put_key(KEY_HOME); + break; + case wsEnd: + mplayer_put_key(KEY_END); + break; + case wsPageUp: + mplayer_put_key(KEY_PAGE_UP); + break; + case wsPageDown: + mplayer_put_key(KEY_PAGE_DOWN); + break; + case wsF1: + mplayer_put_key(KEY_F + 1); + break; + case wsF2: + mplayer_put_key(KEY_F + 2); + break; + case wsF3: + mplayer_put_key(KEY_F + 3); + break; + case wsF4: + mplayer_put_key(KEY_F + 4); + break; + case wsF5: + mplayer_put_key(KEY_F + 5); + break; + case wsF6: + mplayer_put_key(KEY_F + 6); + break; + case wsF7: + mplayer_put_key(KEY_F + 7); + break; + case wsF8: + mplayer_put_key(KEY_F + 8); + break; + case wsF9: + mplayer_put_key(KEY_F + 9); + break; + case wsF10: + mplayer_put_key(KEY_F + 10); + break; + case wsF11: + mplayer_put_key(KEY_F + 11); + break; + case wsF12: + mplayer_put_key(KEY_F + 12); + break; + case wsq: + case wsQ: + mplayer_put_key('q'); + break; + case wsp: + case wsP: + mplayer_put_key('p'); + break; + case wsMinus: + case wsGrayMinus: + mplayer_put_key('-'); + break; + case wsPlus: + case wsGrayPlus: + mplayer_put_key('+'); + break; + case wsGrayMul: + case wsMul: + mplayer_put_key('*'); + break; + case wsGrayDiv: + case wsDiv: + mplayer_put_key('/'); + break; + case wsLess: + mplayer_put_key('<'); + break; + case wsMore: + mplayer_put_key('>'); + break; + case wsGray0: + mplayer_put_key(KEY_KP0); + break; + case wsGrayEnd: + case wsGray1: + mplayer_put_key(KEY_KP1); + break; + case wsGrayDown: + case wsGray2: + mplayer_put_key(KEY_KP2); + break; + case wsGrayPgDn: + case wsGray3: + mplayer_put_key(KEY_KP3); + break; + case wsGrayLeft: + case wsGray4: + mplayer_put_key(KEY_KP4); + break; + case wsGray5Dup: + case wsGray5: + mplayer_put_key(KEY_KP5); + break; + case wsGrayRight: + case wsGray6: + mplayer_put_key(KEY_KP6); + break; + case wsGrayHome: + case wsGray7: + mplayer_put_key(KEY_KP7); + break; + case wsGrayUp: + case wsGray8: + mplayer_put_key(KEY_KP8); + break; + case wsGrayPgUp: + case wsGray9: + mplayer_put_key(KEY_KP9); + break; + case wsGrayDecimal: + mplayer_put_key(KEY_KPDEC); + break; + case wsGrayInsert: + mplayer_put_key(KEY_KPINS); + break; + case wsGrayDelete: + mplayer_put_key(KEY_KPDEL); + break; + case wsGrayEnter: + mplayer_put_key(KEY_KPENTER); + break; + case wsm: + case wsM: + mplayer_put_key('m'); + break; + case wso: + case wsO: + mplayer_put_key('o'); + break; - case wsGrave: mplayer_put_key('`'); break; - case wsTilde: mplayer_put_key('~'); break; - case wsExclSign: mplayer_put_key('!'); break; - case wsAt: mplayer_put_key('@'); break; - case wsHash: mplayer_put_key('#'); break; - case wsDollar: mplayer_put_key('$'); break; - case wsPercent: mplayer_put_key('%'); break; - case wsCircumflex: mplayer_put_key('^'); break; - case wsAmpersand: mplayer_put_key('&'); break; - case wsobracket: mplayer_put_key('('); break; - case wscbracket: mplayer_put_key(')'); break; - case wsUnder: mplayer_put_key('_'); break; - case wsocbracket: mplayer_put_key('{'); break; - case wsccbracket: mplayer_put_key('}'); break; - case wsColon: mplayer_put_key(':'); break; - case wsSemicolon: mplayer_put_key(';'); break; - case wsDblQuote: mplayer_put_key('\"'); break; - case wsAcute: mplayer_put_key('\''); break; - case wsComma: mplayer_put_key(','); break; - case wsPoint: mplayer_put_key('.'); break; - case wsQuestSign: mplayer_put_key('?'); break; - case wsBSlash: mplayer_put_key('\\'); break; - case wsPipe: mplayer_put_key('|'); break; - case wsEqual: mplayer_put_key('='); break; - case wsosbrackets: mplayer_put_key('['); break; - case wscsbrackets: mplayer_put_key(']'); break; + case wsGrave: + mplayer_put_key('`'); + break; + case wsTilde: + mplayer_put_key('~'); + break; + case wsExclSign: + mplayer_put_key('!'); + break; + case wsAt: + mplayer_put_key('@'); + break; + case wsHash: + mplayer_put_key('#'); + break; + case wsDollar: + mplayer_put_key('$'); + break; + case wsPercent: + mplayer_put_key('%'); + break; + case wsCircumflex: + mplayer_put_key('^'); + break; + case wsAmpersand: + mplayer_put_key('&'); + break; + case wsobracket: + mplayer_put_key('('); + break; + case wscbracket: + mplayer_put_key(')'); + break; + case wsUnder: + mplayer_put_key('_'); + break; + case wsocbracket: + mplayer_put_key('{'); + break; + case wsccbracket: + mplayer_put_key('}'); + break; + case wsColon: + mplayer_put_key(':'); + break; + case wsSemicolon: + mplayer_put_key(';'); + break; + case wsDblQuote: + mplayer_put_key('\"'); + break; + case wsAcute: + mplayer_put_key('\''); + break; + case wsComma: + mplayer_put_key(','); + break; + case wsPoint: + mplayer_put_key('.'); + break; + case wsQuestSign: + mplayer_put_key('?'); + break; + case wsBSlash: + mplayer_put_key('\\'); + break; + case wsPipe: + mplayer_put_key('|'); + break; + case wsEqual: + mplayer_put_key('='); + break; + case wsosbrackets: + mplayer_put_key('['); + break; + case wscsbrackets: + mplayer_put_key(']'); + break; - default: if((key>='a' && key<='z')||(key>='A' && key<='Z')|| - (key>='0' && key<='9')) mplayer_put_key(key); - } + default: + if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') || + (key >= '0' && key <= '9')) + mplayer_put_key(key); + } } @@ -635,525 +841,634 @@ typedef struct { - long flags; - long functions; - long decorations; - long input_mode; - long state; + long flags; + long functions; + long decorations; + long input_mode; + long state; } MotifWmHints; extern MotifWmHints vo_MotifWmHints; -extern Atom vo_MotifHints; -extern int vo_depthonscreen; -extern int vo_screenwidth; -extern int vo_screenheight; +extern Atom vo_MotifHints; +extern int vo_depthonscreen; +extern int vo_screenwidth; +extern int vo_screenheight; -static MotifWmHints vo_MotifWmHints; -static Atom vo_MotifHints = None; +static MotifWmHints vo_MotifWmHints; +static Atom vo_MotifHints = None; -void vo_x11_decoration( Display * vo_Display,Window w,int d ) +void vo_x11_decoration(Display * vo_Display, Window w, int d) { - static unsigned int olddecor = MWM_DECOR_ALL; - static unsigned int oldfuncs = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; - Atom mtype; - int mformat; - unsigned long mn,mb; - if ( !WinID ) return; + static unsigned int olddecor = MWM_DECOR_ALL; + static unsigned int oldfuncs = + MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | + MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; + Atom mtype; + int mformat; + unsigned long mn, mb; + + if (!WinID) + return; - if(vo_fsmode&8){ - XSetTransientForHint (vo_Display, w, RootWindow(vo_Display,mScreen)); - } + if (vo_fsmode & 8) + { + XSetTransientForHint(vo_Display, w, + RootWindow(vo_Display, mScreen)); + } + + vo_MotifHints = XInternAtom(vo_Display, "_MOTIF_WM_HINTS", 0); + if (vo_MotifHints != None) + { + if (!d) + { + MotifWmHints *mhints = NULL; - vo_MotifHints=XInternAtom( vo_Display,"_MOTIF_WM_HINTS",0 ); - if ( vo_MotifHints != None ) - { - if (!d) { - MotifWmHints *mhints=NULL; - XGetWindowProperty(vo_Display,w, vo_MotifHints, 0, 20, False, - vo_MotifHints, &mtype, &mformat, &mn, - &mb, (unsigned char **)&mhints) ; - if (mhints){ - if (mhints->flags & MWM_HINTS_DECORATIONS) - olddecor = mhints->decorations; - if (mhints->flags & MWM_HINTS_FUNCTIONS) - oldfuncs = mhints->functions; - XFree (mhints); - } - } + XGetWindowProperty(vo_Display, w, vo_MotifHints, 0, 20, False, + vo_MotifHints, &mtype, &mformat, &mn, + &mb, (unsigned char **) &mhints); + if (mhints) + { + if (mhints->flags & MWM_HINTS_DECORATIONS) + olddecor = mhints->decorations; + if (mhints->flags & MWM_HINTS_FUNCTIONS) + oldfuncs = mhints->functions; + XFree(mhints); + } + } - memset( &vo_MotifWmHints,0,sizeof( MotifWmHints ) ); - vo_MotifWmHints.flags=MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; - if ( d ) - { - vo_MotifWmHints.functions= oldfuncs; - d=olddecor; - } + memset(&vo_MotifWmHints, 0, sizeof(MotifWmHints)); + vo_MotifWmHints.flags = + MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + if (d) + { + vo_MotifWmHints.functions = oldfuncs; + d = olddecor; + } #if 0 - vo_MotifWmHints.decorations=d|((vo_fsmode&2)?0:MWM_DECOR_MENU); + vo_MotifWmHints.decorations = + d | ((vo_fsmode & 2) ? 0 : MWM_DECOR_MENU); #else - vo_MotifWmHints.decorations=d|((vo_fsmode&2)?MWM_DECOR_MENU:0); + vo_MotifWmHints.decorations = + d | ((vo_fsmode & 2) ? MWM_DECOR_MENU : 0); #endif - XChangeProperty( vo_Display,w,vo_MotifHints,vo_MotifHints,32, - PropModeReplace,(unsigned char *)&vo_MotifWmHints,(vo_fsmode&4)?4:5 ); - } + XChangeProperty(vo_Display, w, vo_MotifHints, vo_MotifHints, 32, + PropModeReplace, + (unsigned char *) &vo_MotifWmHints, + (vo_fsmode & 4) ? 4 : 5); + } } -void vo_x11_classhint( Display * display,Window window,char *name ){ - XClassHint wmClass; - pid_t pid=getpid(); - wmClass.res_name = name; - wmClass.res_class = "MPlayer"; - XSetClassHint(display,window,&wmClass); - XChangeProperty(display,window, XA_NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1); +void vo_x11_classhint(Display * display, Window window, char *name) +{ + XClassHint wmClass; + pid_t pid = getpid(); + + wmClass.res_name = name; + wmClass.res_class = "MPlayer"; + XSetClassHint(display, window, &wmClass); + XChangeProperty(display, window, XA_NET_WM_PID, XA_CARDINAL, 32, + PropModeReplace, (unsigned char *) &pid, 1); } -Window vo_window = None; -GC vo_gc = NULL; -GC f_gc = NULL; +Window vo_window = None; +GC vo_gc = NULL; +GC f_gc = NULL; XSizeHints vo_hint; #ifdef HAVE_NEW_GUI - void vo_setwindow( Window w,GC g ) { - vo_window=w; vo_gc=g; - } +void vo_setwindow(Window w, GC g) +{ + vo_window = w; + vo_gc = g; +} #endif void vo_x11_uninit() { saver_on(mDisplay); - if(vo_window!=None) vo_showcursor( mDisplay,vo_window ); - - if (f_gc) { XFreeGC(mDisplay, f_gc); f_gc = NULL; } + if (vo_window != None) + vo_showcursor(mDisplay, vo_window); + if (f_gc) + { + XFreeGC(mDisplay, f_gc); + f_gc = NULL; + } #ifdef HAVE_NEW_GUI /* destroy window only if it's not controlled by GUI */ - if ( !use_gui ) + if (!use_gui) #endif { - if(vo_gc){ - XSetBackground( mDisplay,vo_gc,0 ); - XFreeGC( mDisplay,vo_gc ); - vo_gc=NULL; - } - if(vo_window!=None){ - XClearWindow( mDisplay,vo_window ); - if (WinID < 0){ - XEvent xev; - XUnmapWindow( mDisplay,vo_window ); - XDestroyWindow(mDisplay, vo_window); - do { XNextEvent( mDisplay,&xev ); } while ( xev.type != DestroyNotify || xev.xdestroywindow.event != vo_window ); - } - vo_window=None; - } - vo_fs=0; - vo_old_width=vo_old_height=0; + if (vo_gc) + { + XSetBackground(mDisplay, vo_gc, 0); + XFreeGC(mDisplay, vo_gc); + vo_gc = NULL; + } + if (vo_window != None) + { + XClearWindow(mDisplay, vo_window); + if (WinID < 0) + { + XEvent xev; + + XUnmapWindow(mDisplay, vo_window); + XDestroyWindow(mDisplay, vo_window); + do + { + XNextEvent(mDisplay, &xev); + } + while (xev.type != DestroyNotify + || xev.xdestroywindow.event != vo_window); + } + vo_window = None; + } + vo_fs = 0; + vo_old_width = vo_old_height = 0; } } - int vo_mouse_timer_const = 30; +int vo_mouse_timer_const = 30; static int vo_mouse_counter = 30; -int vo_x11_check_events(Display *mydisplay){ - int ret=0; - XEvent Event; - char buf[100]; - KeySym keySym; - static XComposeStatus stat; +int vo_x11_check_events(Display * mydisplay) +{ + int ret = 0; + XEvent Event; + char buf[100]; + KeySym keySym; + static XComposeStatus stat; // unsigned long vo_KeyTable[512]; - if ( ( vo_mouse_autohide )&&( --vo_mouse_counter == 0 ) ) vo_hidecursor( mydisplay,vo_window ); + if ((vo_mouse_autohide) && (--vo_mouse_counter == 0)) + vo_hidecursor(mydisplay, vo_window); - while ( XPending( mydisplay ) ) - { - XNextEvent( mydisplay,&Event ); - #ifdef HAVE_NEW_GUI - if ( use_gui ) - { - guiGetEvent( 0,(char*)&Event ); - if ( vo_window != Event.xany.window ) continue; - } - #endif + while (XPending(mydisplay)) + { + XNextEvent(mydisplay, &Event); +#ifdef HAVE_NEW_GUI + if (use_gui) + { + guiGetEvent(0, (char *) &Event); + if (vo_window != Event.xany.window) + continue; + } +#endif // printf("\rEvent.type=%X \n",Event.type); - switch( Event.type ) - { - case Expose: - ret|=VO_EVENT_EXPOSE; - break; - case ConfigureNotify: -// if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break; -// if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break; - if ( vo_window == None ) break; - vo_dwidth=Event.xconfigure.width; - vo_dheight=Event.xconfigure.height; + switch (Event.type) + { + case Expose: + ret |= VO_EVENT_EXPOSE; + break; + case ConfigureNotify: +// if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break; +// if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break; + if (vo_window == None) + break; + vo_dwidth = Event.xconfigure.width; + vo_dheight = Event.xconfigure.height; #if 0 - /* when resizing, x and y are zero :( */ - vo_dx=Event.xconfigure.x; - vo_dy=Event.xconfigure.y; + /* when resizing, x and y are zero :( */ + vo_dx = Event.xconfigure.x; + vo_dy = Event.xconfigure.y; #else - { - Window root; - int foo; - Window win; - XGetGeometry(mydisplay, vo_window, &root, &foo, &foo, - &foo/*width*/, &foo/*height*/, &foo, &foo); - XTranslateCoordinates(mydisplay, vo_window, root, 0, 0, - &vo_dx, &vo_dy, &win); - } + { + Window root; + int foo; + Window win; + + XGetGeometry(mydisplay, vo_window, &root, &foo, &foo, + &foo /*width */ , &foo /*height */ , &foo, + &foo); + XTranslateCoordinates(mydisplay, vo_window, root, 0, 0, + &vo_dx, &vo_dy, &win); + } +#endif + ret |= VO_EVENT_RESIZE; + break; + case KeyPress: + { + int key; + + XLookupString(&Event.xkey, buf, sizeof(buf), &keySym, + &stat); +#ifdef XF86XK_AudioPause + vo_x11_putkey_ext(keySym); +#endif + key = + ((keySym & 0xff00) != + 0 ? ((keySym & 0x00ff) + 256) : (keySym)); +#ifdef HAVE_NEW_GUI + if ((use_gui) && (key == wsEnter)) + break; #endif - ret|=VO_EVENT_RESIZE; - break; - case KeyPress: - { - int key; - XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat ); - #ifdef XF86XK_AudioPause - vo_x11_putkey_ext( keySym ); - #endif - key=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ); - #ifdef HAVE_NEW_GUI - if ( ( use_gui )&&( key == wsEnter ) ) break; - #endif - vo_x11_putkey( key ); - ret|=VO_EVENT_KEYPRESS; - } - break; - case MotionNotify: - if ( vo_mouse_autohide ) { vo_showcursor( mydisplay,vo_window ); vo_mouse_counter=vo_mouse_timer_const; } - break; - case ButtonPress: - if ( vo_mouse_autohide ) { vo_showcursor( mydisplay,vo_window ); vo_mouse_counter=vo_mouse_timer_const; } - // Ignore mouse whell press event - if(Event.xbutton.button > 3) { - mplayer_put_key(MOUSE_BTN0+Event.xbutton.button-1); - break; - } - #ifdef HAVE_NEW_GUI - // Ignor mouse button 1 - 3 under gui - if ( use_gui && ( Event.xbutton.button >= 1 )&&( Event.xbutton.button <= 3 ) ) break; - #endif - mplayer_put_key((MOUSE_BTN0+Event.xbutton.button-1)|MP_KEY_DOWN); - break; - case ButtonRelease: - if ( vo_mouse_autohide ) { vo_showcursor( mydisplay,vo_window ); vo_mouse_counter=vo_mouse_timer_const; } - #ifdef HAVE_NEW_GUI - // Ignor mouse button 1 - 3 under gui - if ( use_gui && ( Event.xbutton.button >= 1 )&&( Event.xbutton.button <= 3 ) ) break; - #endif - mplayer_put_key(MOUSE_BTN0+Event.xbutton.button-1); - break; - case PropertyNotify: - { - char * name = XGetAtomName( mydisplay,Event.xproperty.atom ); - - if ( !name ) break; - + vo_x11_putkey(key); + ret |= VO_EVENT_KEYPRESS; + } + break; + case MotionNotify: + if (vo_mouse_autohide) + { + vo_showcursor(mydisplay, vo_window); + vo_mouse_counter = vo_mouse_timer_const; + } + break; + case ButtonPress: + if (vo_mouse_autohide) + { + vo_showcursor(mydisplay, vo_window); + vo_mouse_counter = vo_mouse_timer_const; + } + // Ignore mouse whell press event + if (Event.xbutton.button > 3) + { + mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1); + break; + } +#ifdef HAVE_NEW_GUI + // Ignor mouse button 1 - 3 under gui + if (use_gui && (Event.xbutton.button >= 1) + && (Event.xbutton.button <= 3)) + break; +#endif + mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button - + 1) | MP_KEY_DOWN); + break; + case ButtonRelease: + if (vo_mouse_autohide) + { + vo_showcursor(mydisplay, vo_window); + vo_mouse_counter = vo_mouse_timer_const; + } +#ifdef HAVE_NEW_GUI + // Ignor mouse button 1 - 3 under gui + if (use_gui && (Event.xbutton.button >= 1) + && (Event.xbutton.button <= 3)) + break; +#endif + mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1); + break; + case PropertyNotify: + { + char *name = + XGetAtomName(mydisplay, Event.xproperty.atom); + + if (!name) + break; + // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom ); - - XFree( name ); - } - break; - case MapNotify: - vo_hint.win_gravity = old_gravity; - XSetWMNormalHints( mDisplay,vo_window,&vo_hint ); - vo_fs_flip = 0; - break; - } - } - return ret; + + XFree(name); + } + break; + case MapNotify: + vo_hint.win_gravity = old_gravity; + XSetWMNormalHints(mDisplay, vo_window, &vo_hint); + vo_fs_flip = 0; + break; + } + } + return ret; } -void vo_x11_sizehint( int x, int y, int width, int height, int max ) +void vo_x11_sizehint(int x, int y, int width, int height, int max) { - vo_hint.flags=PPosition | PSize | PWinGravity; - if(vo_keepaspect) - { - vo_hint.flags |= PAspect; - vo_hint.min_aspect.x = width; - vo_hint.min_aspect.y = height; - vo_hint.max_aspect.x = width; - vo_hint.max_aspect.y = height; - } + vo_hint.flags = PPosition | PSize | PWinGravity; + if (vo_keepaspect) + { + vo_hint.flags |= PAspect; + vo_hint.min_aspect.x = width; + vo_hint.min_aspect.y = height; + vo_hint.max_aspect.x = width; + vo_hint.max_aspect.y = height; + } - vo_hint.x=x; vo_hint.y=y; vo_hint.width=width; vo_hint.height=height; - if ( max ) - { - vo_hint.max_width=width; vo_hint.max_height=height; - vo_hint.flags|=PMaxSize; - } else { vo_hint.max_width=0; vo_hint.max_height=0; } + vo_hint.x = x; + vo_hint.y = y; + vo_hint.width = width; + vo_hint.height = height; + if (max) + { + vo_hint.max_width = width; + vo_hint.max_height = height; + vo_hint.flags |= PMaxSize; + } else + { + vo_hint.max_width = 0; + vo_hint.max_height = 0; + } - // set min height/width to 4 to avoid off by one errors - // and because mga_vid requires a minial size of 4 pixel - vo_hint.min_width = vo_hint.min_height = 4; - vo_hint.flags |= PMinSize; + // set min height/width to 4 to avoid off by one errors + // and because mga_vid requires a minial size of 4 pixel + vo_hint.min_width = vo_hint.min_height = 4; + vo_hint.flags |= PMinSize; - vo_hint.win_gravity=StaticGravity; - XSetWMNormalHints( mDisplay,vo_window,&vo_hint ); + vo_hint.win_gravity = StaticGravity; + XSetWMNormalHints(mDisplay, vo_window, &vo_hint); } static int vo_x11_get_gnome_layer(Display * mDisplay, Window win) { - Atom type; - int format; - unsigned long nitems; - unsigned long bytesafter; - unsigned short *args = NULL; + Atom type; + int format; + unsigned long nitems; + unsigned long bytesafter; + unsigned short *args = NULL; - if (XGetWindowProperty (mDisplay, win, XA_WIN_LAYER, 0, 16384, - False, AnyPropertyType, &type, &format, &nitems, - &bytesafter, (unsigned char **) &args) == Success - && nitems > 0 && args) - { - mp_msg (MSGT_VO, MSGL_V, "[x11] original window layer is %d.\n", *args); - return *args; - } - return WIN_LAYER_NORMAL; + if (XGetWindowProperty(mDisplay, win, XA_WIN_LAYER, 0, 16384, + False, AnyPropertyType, &type, &format, &nitems, + &bytesafter, + (unsigned char **) &args) == Success + && nitems > 0 && args) + { + mp_msg(MSGT_VO, MSGL_V, "[x11] original window layer is %d.\n", + *args); + return *args; + } + return WIN_LAYER_NORMAL; } // -Window vo_x11_create_smooth_window( Display *mDisplay, Window mRoot, Visual *vis, int x, int y, unsigned int width, unsigned int height, int depth, Colormap col_map) +Window vo_x11_create_smooth_window(Display * mDisplay, Window mRoot, + Visual * vis, int x, int y, + unsigned int width, unsigned int height, + int depth, Colormap col_map) { - unsigned long xswamask = CWBackingStore | CWBorderPixel; - XSetWindowAttributes xswa; - Window ret_win; - - if (col_map!=CopyFromParent) - { - xswa.colormap = col_map; - xswamask|=CWColormap; - } - xswa.background_pixel = 0; - xswa.border_pixel = 0; - xswa.backing_store = Always; - xswa.bit_gravity = StaticGravity; - - ret_win = XCreateWindow(mDisplay, mRootWin, x, y, width, height, 0, depth, - CopyFromParent, vis, xswamask , &xswa); - if (!f_gc) f_gc=XCreateGC (mDisplay, ret_win, 0, 0); - XSetForeground (mDisplay, f_gc, 0); + unsigned long xswamask = CWBackingStore | CWBorderPixel; + XSetWindowAttributes xswa; + Window ret_win; - return ret_win; + if (col_map != CopyFromParent) + { + xswa.colormap = col_map; + xswamask |= CWColormap; + } + xswa.background_pixel = 0; + xswa.border_pixel = 0; + xswa.backing_store = Always; + xswa.bit_gravity = StaticGravity; + + ret_win = + XCreateWindow(mDisplay, mRootWin, x, y, width, height, 0, depth, + CopyFromParent, vis, xswamask, &xswa); + if (!f_gc) + f_gc = XCreateGC(mDisplay, ret_win, 0, 0); + XSetForeground(mDisplay, f_gc, 0); + + return ret_win; } - + -void vo_x11_clearwindow_part(Display *mDisplay, Window vo_window, int img_width, int img_height, int use_fs) +void vo_x11_clearwindow_part(Display * mDisplay, Window vo_window, + int img_width, int img_height, int use_fs) { - int u_dheight, u_dwidth, left_ov, left_ov2; + int u_dheight, u_dwidth, left_ov, left_ov2; - if (!f_gc) return; + if (!f_gc) + return; - u_dheight = use_fs?vo_screenheight:vo_dheight; - u_dwidth = use_fs?vo_screenwidth:vo_dwidth; - if ((u_dheight<=img_height) && (u_dwidth<=img_width)) return; + u_dheight = use_fs ? vo_screenheight : vo_dheight; + u_dwidth = use_fs ? vo_screenwidth : vo_dwidth; + if ((u_dheight <= img_height) && (u_dwidth <= img_width)) + return; - left_ov = (u_dheight - img_height)/2; - left_ov2 = (u_dwidth - img_width)/2; - - XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, u_dwidth, left_ov); - XFillRectangle(mDisplay, vo_window, f_gc, 0, u_dheight-left_ov-1, u_dwidth, left_ov+1); - - if (u_dwidth>img_width) - { - XFillRectangle(mDisplay, vo_window, f_gc, 0, left_ov, left_ov2, img_height); - XFillRectangle(mDisplay, vo_window, f_gc, u_dwidth-left_ov2-1, left_ov, left_ov2, img_height); - } + left_ov = (u_dheight - img_height) / 2; + left_ov2 = (u_dwidth - img_width) / 2; + + XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, u_dwidth, left_ov); + XFillRectangle(mDisplay, vo_window, f_gc, 0, u_dheight - left_ov - 1, + u_dwidth, left_ov + 1); - XFlush(mDisplay); + if (u_dwidth > img_width) + { + XFillRectangle(mDisplay, vo_window, f_gc, 0, left_ov, left_ov2, + img_height); + XFillRectangle(mDisplay, vo_window, f_gc, u_dwidth - left_ov2 - 1, + left_ov, left_ov2, img_height); + } + + XFlush(mDisplay); } -void vo_x11_clearwindow( Display *mDisplay, Window vo_window ) +void vo_x11_clearwindow(Display * mDisplay, Window vo_window) { - if (!f_gc) return; - XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, vo_screenwidth, vo_screenheight); - // - XFlush(mDisplay); + if (!f_gc) + return; + XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, vo_screenwidth, + vo_screenheight); + // + XFlush(mDisplay); } - + -void vo_x11_setlayer( Display * mDisplay,Window vo_window,int layer ) +void vo_x11_setlayer(Display * mDisplay, Window vo_window, int layer) { - if (WinID >= 0) return; + if (WinID >= 0) + return; - if ( vo_fs_type & vo_wm_LAYER ) - { - XClientMessageEvent xev; - - if (!orig_layer) orig_layer=vo_x11_get_gnome_layer( mDisplay, vo_window ); + if (vo_fs_type & vo_wm_LAYER) + { + XClientMessageEvent xev; + + if (!orig_layer) + orig_layer = vo_x11_get_gnome_layer(mDisplay, vo_window); - memset(&xev, 0, sizeof(xev)); - xev.type = ClientMessage; - xev.display= mDisplay; - xev.window = vo_window; - xev.message_type = XA_WIN_LAYER; - xev.format = 32; - xev.data.l[0] = layer?fs_layer:orig_layer; // if not fullscreen, stay on default layer - xev.data.l[1] = CurrentTime; - mp_msg( MSGT_VO,MSGL_V,"[x11] Layered style stay on top (layer %d).\n",xev.data.l[0] ); - XSendEvent(mDisplay, mRootWin, False, SubstructureNotifyMask, (XEvent *) &xev); - } else - if ( vo_fs_type & vo_wm_NETWM ) - { - XClientMessageEvent xev; - char *state; + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.display = mDisplay; + xev.window = vo_window; + xev.message_type = XA_WIN_LAYER; + xev.format = 32; + xev.data.l[0] = layer ? fs_layer : orig_layer; // if not fullscreen, stay on default layer + xev.data.l[1] = CurrentTime; + mp_msg(MSGT_VO, MSGL_V, + "[x11] Layered style stay on top (layer %d).\n", + xev.data.l[0]); + XSendEvent(mDisplay, mRootWin, False, SubstructureNotifyMask, + (XEvent *) & xev); + } else if (vo_fs_type & vo_wm_NETWM) + { + XClientMessageEvent xev; + char *state; - memset( &xev,0,sizeof( xev ) ); - xev.type=ClientMessage; - xev.message_type=XA_NET_WM_STATE; - xev.display=mDisplay; - xev.window=vo_window; - xev.format=32; - xev.data.l[0]=layer; - - if ( vo_fs_type & vo_wm_STAYS_ON_TOP ) - xev.data.l[1]=XA_NET_WM_STATE_STAYS_ON_TOP; - else - if ( vo_fs_type & vo_wm_ABOVE ) - xev.data.l[1]=XA_NET_WM_STATE_ABOVE; - else - if ( vo_fs_type & vo_wm_FULLSCREEN ) - xev.data.l[1]=XA_NET_WM_STATE_FULLSCREEN; - else - if ( vo_fs_type & vo_wm_BELOW ) - // This is not fallback. We can safely assume that situation where - // only NETWM_STATE_BELOW is supported and others not, doesn't exist. - xev.data.l[1]=XA_NET_WM_STATE_BELOW; + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.message_type = XA_NET_WM_STATE; + xev.display = mDisplay; + xev.window = vo_window; + xev.format = 32; + xev.data.l[0] = layer; - XSendEvent( mDisplay,mRootWin,False,SubstructureRedirectMask,(XEvent*)&xev ); - state = XGetAtomName (mDisplay, xev.data.l[1]); - mp_msg( MSGT_VO,MSGL_V,"[x11] NET style stay on top (layer %d). Using state %s.\n",layer,state ); - XFree (state); - } + if (vo_fs_type & vo_wm_STAYS_ON_TOP) + xev.data.l[1] = XA_NET_WM_STATE_STAYS_ON_TOP; + else if (vo_fs_type & vo_wm_ABOVE) + xev.data.l[1] = XA_NET_WM_STATE_ABOVE; + else if (vo_fs_type & vo_wm_FULLSCREEN) + xev.data.l[1] = XA_NET_WM_STATE_FULLSCREEN; + else if (vo_fs_type & vo_wm_BELOW) + // This is not fallback. We can safely assume that situation where + // only NETWM_STATE_BELOW is supported and others not, doesn't exist. + xev.data.l[1] = XA_NET_WM_STATE_BELOW; + + XSendEvent(mDisplay, mRootWin, False, SubstructureRedirectMask, + (XEvent *) & xev); + state = XGetAtomName(mDisplay, xev.data.l[1]); + mp_msg(MSGT_VO, MSGL_V, + "[x11] NET style stay on top (layer %d). Using state %s.\n", + layer, state); + XFree(state); + } } static int vo_x11_get_fs_type(int supported) { - int i; - int type = supported; - - if (vo_fstype_list) { - i = 0; - for (i = 0; vo_fstype_list[i]; i++) + int i; + int type = supported; + + if (vo_fstype_list) { - int neg = 0; - char * arg = vo_fstype_list[i]; - - if (vo_fstype_list[i][0] == '-') - { - neg = 1; - arg = vo_fstype_list[i] + 1; - } + i = 0; + for (i = 0; vo_fstype_list[i]; i++) + { + int neg = 0; + char *arg = vo_fstype_list[i]; + + if (vo_fstype_list[i][0] == '-') + { + neg = 1; + arg = vo_fstype_list[i] + 1; + } + + if (!strncmp(arg, "layer", 5)) + { + if (!neg && (arg[5] == '=')) + { + char *endptr = NULL; + int layer = strtol(vo_fstype_list[i] + 6, &endptr, 10); - if (!strncmp(arg, "layer", 5)) - { - if (!neg && (arg[5] == '=')) - { - char *endptr = NULL; - int layer = strtol(vo_fstype_list[i]+6, &endptr, 10); - - if (endptr && *endptr == '\0' && layer >= 0 && layer <= 15) - fs_layer = layer; + if (endptr && *endptr == '\0' && layer >= 0 + && layer <= 15) + fs_layer = layer; + } + if (neg) + type &= ~vo_wm_LAYER; + else + type |= vo_wm_LAYER; + } else if (!strcmp(arg, "above")) + { + if (neg) + type &= ~vo_wm_ABOVE; + else + type |= vo_wm_ABOVE; + } else if (!strcmp(arg, "fullscreen")) + { + if (neg) + type &= ~vo_wm_FULLSCREEN; + else + type |= vo_wm_FULLSCREEN; + } else if (!strcmp(arg, "stays_on_top")) + { + if (neg) + type &= ~vo_wm_STAYS_ON_TOP; + else + type |= vo_wm_STAYS_ON_TOP; + } else if (!strcmp(arg, "below")) + { + if (neg) + type &= ~vo_wm_BELOW; + else + type |= vo_wm_BELOW; + } else if (!strcmp(arg, "netwm")) + { + if (neg) + type &= ~vo_wm_NETWM; + else + type |= vo_wm_NETWM; + } else if (!strcmp(arg, "none")) + return 0; } - if (neg) - type &= ~vo_wm_LAYER; - else - type |= vo_wm_LAYER; - } - else if (!strcmp(arg, "above")) - { - if (neg) - type &= ~vo_wm_ABOVE; - else - type |= vo_wm_ABOVE; - } else if (!strcmp(arg, "fullscreen")) - { - if (neg) - type &= ~vo_wm_FULLSCREEN; - else - type |= vo_wm_FULLSCREEN; - } else if (!strcmp(arg, "stays_on_top")) - { - if (neg) - type &= ~vo_wm_STAYS_ON_TOP; - else - type |= vo_wm_STAYS_ON_TOP; - } else if (!strcmp(arg, "below")) - { - if (neg) - type &= ~vo_wm_BELOW; - else - type |= vo_wm_BELOW; - } else if (!strcmp(arg, "netwm")) - { - if (neg) - type &= ~vo_wm_NETWM; - else - type |= vo_wm_NETWM; - } else if (!strcmp(arg, "none")) return 0; } - } - - return type; -} - -void vo_x11_fullscreen( void ) -{ - int x,y,w,h; - if ( WinID >= 0 || vo_fs_flip) return; - - if ( vo_fs ){ - // fs->win - vo_x11_ewmh_fullscreen( _NET_WM_STATE_REMOVE ); // removes fullscreen state if wm supports EWMH - - if(vo_dwidth != vo_screenwidth && vo_dheight != vo_screenheight) return; - vo_fs=VO_FALSE; - x=vo_old_x; y=vo_old_y; w=vo_old_width; h=vo_old_height; - } else { - // win->fs - vo_x11_ewmh_fullscreen( _NET_WM_STATE_ADD ); // sends fullscreen state to be added if wm supports EWMH - - if(vo_old_width && - (vo_dwidth==vo_screenwidth && vo_dwidth!=vo_old_width) && - (vo_dheight==vo_screenheight && vo_dheight!=vo_old_height) ) return; - vo_fs=VO_TRUE; - vo_old_x=vo_dx; vo_old_y=vo_dy; vo_old_width=vo_dwidth; vo_old_height=vo_dheight; - x=0; y=0; w=vo_screenwidth; h=vo_screenheight; - - } - { - long dummy; - XGetWMNormalHints(mDisplay, vo_window, &vo_hint, &dummy); - if (!(vo_hint.flags & PWinGravity)) - old_gravity = NorthWestGravity; - else - old_gravity = vo_hint.win_gravity; - } - if(vo_wm_type==0 && !(vo_fsmode&16)) { - XUnmapWindow( mDisplay,vo_window ); // required for MWM - XWithdrawWindow(mDisplay,vo_window,mScreen); - vo_fs_flip = 1; - } - - vo_x11_decoration( mDisplay,vo_window,(vo_fs) ? 0 : 1 ); - vo_x11_sizehint( x,y,w,h,0 ); - vo_x11_setlayer( mDisplay,vo_window,vo_fs ); - - if ((!(vo_fs)) & vo_ontop) vo_x11_setlayer(mDisplay, vo_window,vo_ontop); - - XMoveResizeWindow( mDisplay,vo_window,x,y,w,h ); -#ifdef HAVE_XINERAMA - vo_x11_xinerama_move(mDisplay,vo_window); -#endif - XMapRaised( mDisplay,vo_window ); - XRaiseWindow( mDisplay,vo_window ); - XFlush( mDisplay ); + return type; } -void vo_x11_ontop( void ) +void vo_x11_fullscreen(void) { - vo_ontop = (!(vo_ontop)); + int x, y, w, h; + + if (WinID >= 0 || vo_fs_flip) + return; + + if (vo_fs) + { + // fs->win + vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE); // removes fullscreen state if wm supports EWMH + + if (vo_dwidth != vo_screenwidth && vo_dheight != vo_screenheight) + return; + vo_fs = VO_FALSE; + x = vo_old_x; + y = vo_old_y; + w = vo_old_width; + h = vo_old_height; + } else + { + // win->fs + vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD); // sends fullscreen state to be added if wm supports EWMH + + if (vo_old_width && + (vo_dwidth == vo_screenwidth && vo_dwidth != vo_old_width) && + (vo_dheight == vo_screenheight && vo_dheight != vo_old_height)) + return; + vo_fs = VO_TRUE; + vo_old_x = vo_dx; + vo_old_y = vo_dy; + vo_old_width = vo_dwidth; + vo_old_height = vo_dheight; + x = 0; + y = 0; + w = vo_screenwidth; + h = vo_screenheight; - vo_x11_setlayer(mDisplay, vo_window, vo_ontop); + } + { + long dummy; + + XGetWMNormalHints(mDisplay, vo_window, &vo_hint, &dummy); + if (!(vo_hint.flags & PWinGravity)) + old_gravity = NorthWestGravity; + else + old_gravity = vo_hint.win_gravity; + } + if (vo_wm_type == 0 && !(vo_fsmode & 16)) + { + XUnmapWindow(mDisplay, vo_window); // required for MWM + XWithdrawWindow(mDisplay, vo_window, mScreen); + vo_fs_flip = 1; + } + + vo_x11_decoration(mDisplay, vo_window, (vo_fs) ? 0 : 1); + vo_x11_sizehint(x, y, w, h, 0); + vo_x11_setlayer(mDisplay, vo_window, vo_fs); + + if ((!(vo_fs)) & vo_ontop) + vo_x11_setlayer(mDisplay, vo_window, vo_ontop); + + XMoveResizeWindow(mDisplay, vo_window, x, y, w, h); +#ifdef HAVE_XINERAMA + vo_x11_xinerama_move(mDisplay, vo_window); +#endif + XMapRaised(mDisplay, vo_window); + XRaiseWindow(mDisplay, vo_window); + XFlush(mDisplay); +} + +void vo_x11_ontop(void) +{ + vo_ontop = (!(vo_ontop)); + + vo_x11_setlayer(mDisplay, vo_window, vo_ontop); } /* @@ -1163,16 +1478,16 @@ static int got_badwindow; static XErrorHandler old_handler; -static int badwindow_handler(Display *dpy, XErrorEvent *error) +static int badwindow_handler(Display * dpy, XErrorEvent * error) { if (error->error_code != BadWindow) - return (*old_handler)(dpy, error); + return (*old_handler) (dpy, error); got_badwindow = True; return 0; } -static Window find_xscreensaver_window(Display *dpy) +static Window find_xscreensaver_window(Display * dpy) { int i; Window root = RootWindowOfScreen(DefaultScreenOfDisplay(dpy)); @@ -1185,28 +1500,33 @@ if (!(xs_version != None && XQueryTree(dpy, root, &root2, &parent, &kids, &nkids) && - kids && nkids)) return 0; + kids && nkids)) + return 0; old_handler = XSetErrorHandler(badwindow_handler); - for (i = 0; i < nkids; i++) { - Atom type; - int format; - unsigned long nitems, bytesafter; - char *v; - int status; + for (i = 0; i < nkids; i++) + { + Atom type; + int format; + unsigned long nitems, bytesafter; + char *v; + int status; got_badwindow = False; - status = XGetWindowProperty(dpy, kids[i], xs_version, 0, 200, False, - XA_STRING, &type, &format, &nitems, - &bytesafter, (unsigned char**) &v); - XSync(dpy, False); - if (got_badwindow) status = BadWindow; + status = + XGetWindowProperty(dpy, kids[i], xs_version, 0, 200, False, + XA_STRING, &type, &format, &nitems, + &bytesafter, (unsigned char **) &v); + XSync(dpy, False); + if (got_badwindow) + status = BadWindow; - if (status == Success && type != None) { - retval = kids[i]; - break; - } + if (status == Success && type != None) + { + retval = kids[i]; + break; + } } XFree(kids); XSetErrorHandler(old_handler); @@ -1226,35 +1546,36 @@ XEvent ev; if (mDisplay && xs_windowid && - ((time - time_last)>30000 || - (time - time_last)<0)) { - time_last = time; + ((time - time_last) > 30000 || (time - time_last) < 0)) + { + time_last = time; - ev.xany.type = ClientMessage; - ev.xclient.display = mDisplay; - ev.xclient.window = xs_windowid; - ev.xclient.message_type = screensaver; - ev.xclient.format = 32; - memset(&ev.xclient.data, 0, sizeof(ev.xclient.data)); - ev.xclient.data.l[0] = (long) deactivate; + ev.xany.type = ClientMessage; + ev.xclient.display = mDisplay; + ev.xclient.window = xs_windowid; + ev.xclient.message_type = screensaver; + ev.xclient.format = 32; + memset(&ev.xclient.data, 0, sizeof(ev.xclient.data)); + ev.xclient.data.l[0] = (long) deactivate; - mp_msg(MSGT_VO,MSGL_DBG2, "Pinging xscreensaver.\n"); - XSendEvent(mDisplay, xs_windowid, False, 0L, &ev); - XSync(mDisplay, False); + mp_msg(MSGT_VO, MSGL_DBG2, "Pinging xscreensaver.\n"); + XSendEvent(mDisplay, xs_windowid, False, 0L, &ev); + XSync(mDisplay, False); } } -static void xscreensaver_disable(Display *dpy) +static void xscreensaver_disable(Display * dpy) { - mp_msg(MSGT_VO,MSGL_DBG2, "xscreensaver_disable()\n"); + mp_msg(MSGT_VO, MSGL_DBG2, "xscreensaver_disable()\n"); xs_windowid = find_xscreensaver_window(dpy); - if (!xs_windowid) { - mp_msg(MSGT_VO,MSGL_INFO, - "xscreensaver_disable: Could not find xscreensaver window.\n"); - return; + if (!xs_windowid) + { + mp_msg(MSGT_VO, MSGL_INFO, + "xscreensaver_disable: Could not find xscreensaver window.\n"); + return; } - mp_msg(MSGT_VO,MSGL_INFO, + mp_msg(MSGT_VO, MSGL_INFO, "xscreensaver_disable: xscreensaver wid=%d.\n", xs_windowid); deactivate = XInternAtom(dpy, "DEACTIVATE", False); @@ -1270,203 +1591,264 @@ * End of XScreensaver stuff */ -void saver_on(Display *mDisplay) { +void saver_on(Display * mDisplay) +{ #ifdef HAVE_XDPMS int nothing; + if (dpms_disabled) { - if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) - { - if (!DPMSEnable(mDisplay)) { // restoring power saving settings - mp_msg(MSGT_VO,MSGL_WARN,"DPMS not available?\n"); - } else { + if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) + { + if (!DPMSEnable(mDisplay)) + { // restoring power saving settings + mp_msg(MSGT_VO, MSGL_WARN, "DPMS not available?\n"); + } else + { // DPMS does not seem to be enabled unless we call DPMSInfo - BOOL onoff; - CARD16 state; - DPMSForceLevel(mDisplay, DPMSModeOn); - DPMSInfo(mDisplay, &state, &onoff); - if (onoff) { - mp_msg(MSGT_VO,MSGL_INFO,"Successfully enabled DPMS\n"); - } else { - mp_msg(MSGT_VO,MSGL_WARN,"Could not enable DPMS\n"); + BOOL onoff; + CARD16 state; + + DPMSForceLevel(mDisplay, DPMSModeOn); + DPMSInfo(mDisplay, &state, &onoff); + if (onoff) + { + mp_msg(MSGT_VO, MSGL_INFO, + "Successfully enabled DPMS\n"); + } else + { + mp_msg(MSGT_VO, MSGL_WARN, "Could not enable DPMS\n"); } } - } - dpms_disabled=0; + } + dpms_disabled = 0; } #endif if (timeout_save) { - int dummy, interval, prefer_blank, allow_exp; - XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank, &allow_exp); - XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank, allow_exp); - XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); - timeout_save=0; + int dummy, interval, prefer_blank, allow_exp; + + XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank, + &allow_exp); + XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank, + allow_exp); + XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, + &allow_exp); + timeout_save = 0; } - if (stop_xscreensaver) xscreensaver_enable(); - if (kdescreensaver_was_running && stop_xscreensaver) { - system("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null"); - kdescreensaver_was_running = 0; + if (stop_xscreensaver) + xscreensaver_enable(); + if (kdescreensaver_was_running && stop_xscreensaver) + { + system + ("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null"); + kdescreensaver_was_running = 0; } } -void saver_off(Display *mDisplay) { +void saver_off(Display * mDisplay) +{ int interval, prefer_blank, allow_exp; + #ifdef HAVE_XDPMS int nothing; if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing)) { - BOOL onoff; - CARD16 state; - DPMSInfo(mDisplay, &state, &onoff); - if (onoff) - { - Status stat; - mp_msg(MSGT_VO,MSGL_INFO,"Disabling DPMS\n"); - dpms_disabled=1; - stat = DPMSDisable(mDisplay); // monitor powersave off - mp_msg(MSGT_VO,MSGL_V,"DPMSDisable stat: %d\n", stat); - } + BOOL onoff; + CARD16 state; + + DPMSInfo(mDisplay, &state, &onoff); + if (onoff) + { + Status stat; + + mp_msg(MSGT_VO, MSGL_INFO, "Disabling DPMS\n"); + dpms_disabled = 1; + stat = DPMSDisable(mDisplay); // monitor powersave off + mp_msg(MSGT_VO, MSGL_V, "DPMSDisable stat: %d\n", stat); + } } #endif - if (!timeout_save) { - XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp); - if (timeout_save) - XSetScreenSaver(mDisplay, 0, interval, prefer_blank, allow_exp); + if (!timeout_save) + { + XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, + &allow_exp); + if (timeout_save) + XSetScreenSaver(mDisplay, 0, interval, prefer_blank, + allow_exp); } - // turning off screensaver - if (stop_xscreensaver) xscreensaver_disable(mDisplay); + // turning off screensaver + if (stop_xscreensaver) + xscreensaver_disable(mDisplay); if (stop_xscreensaver && !kdescreensaver_was_running) { - kdescreensaver_was_running=(system("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")==0); - if (kdescreensaver_was_running) - system("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null"); + kdescreensaver_was_running = + (system + ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null") + == 0); + if (kdescreensaver_was_running) + system + ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null"); } } static XErrorHandler old_handler = NULL; static int selectinput_err = 0; -static int x11_selectinput_errorhandler(Display *display, XErrorEvent *event) +static int x11_selectinput_errorhandler(Display * display, + XErrorEvent * event) { - if (event->error_code == BadAccess) { - selectinput_err = 1; - mp_msg(MSGT_VO, MSGL_ERR, "X11 error: BadAccess during XSelectInput Call\n"); - mp_msg(MSGT_VO, MSGL_ERR, "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n"); - /* If you think mplayer should shutdown with this error, comments out following line */ - return 0; - } - if (old_handler != NULL) old_handler(display, event); - else x11_errorhandler(display, event); - return 0; + if (event->error_code == BadAccess) + { + selectinput_err = 1; + mp_msg(MSGT_VO, MSGL_ERR, + "X11 error: BadAccess during XSelectInput Call\n"); + mp_msg(MSGT_VO, MSGL_ERR, + "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n"); + /* If you think mplayer should shutdown with this error, comments out following line */ + return 0; + } + if (old_handler != NULL) + old_handler(display, event); + else + x11_errorhandler(display, event); + return 0; } -void vo_x11_selectinput_witherr(Display *display, Window w, long event_mask) +void vo_x11_selectinput_witherr(Display * display, Window w, + long event_mask) { - XSync(display, False); - old_handler = XSetErrorHandler(x11_selectinput_errorhandler); - selectinput_err = 0; - if(vo_nomouse_input){ - XSelectInput(display,w,event_mask & (~(ButtonPressMask | ButtonReleaseMask))); - } else { - XSelectInput(display, w, event_mask); - } - XSync(display, False); - XSetErrorHandler(old_handler); - if (selectinput_err) { - mp_msg(MSGT_VO, MSGL_ERR, "X11 error: MPlayer discards mouse control (reconfiguring)\n"); - XSelectInput(display, w, event_mask & (~(ButtonPressMask | ButtonReleaseMask | PointerMotionMask)) ); - } + XSync(display, False); + old_handler = XSetErrorHandler(x11_selectinput_errorhandler); + selectinput_err = 0; + if (vo_nomouse_input) + { + XSelectInput(display, w, + event_mask & + (~(ButtonPressMask | ButtonReleaseMask))); + } else + { + XSelectInput(display, w, event_mask); + } + XSync(display, False); + XSetErrorHandler(old_handler); + if (selectinput_err) + { + mp_msg(MSGT_VO, MSGL_ERR, + "X11 error: MPlayer discards mouse control (reconfiguring)\n"); + XSelectInput(display, w, + event_mask & + (~ + (ButtonPressMask | ButtonReleaseMask | + PointerMotionMask))); + } } #ifdef HAVE_XINERAMA -void vo_x11_xinerama_move(Display *dsp, Window w) +void vo_x11_xinerama_move(Display * dsp, Window w) { - if(XineramaIsActive(dsp) && ! geometry_xy_changed) - { - /* printf("XXXX Xinerama screen: x: %hd y: %hd\n",xinerama_x,xinerama_y); */ - XMoveWindow(dsp,w,xinerama_x,xinerama_y); - } + if (XineramaIsActive(dsp) && !geometry_xy_changed) + { + /* printf("XXXX Xinerama screen: x: %hd y: %hd\n",xinerama_x,xinerama_y); */ + XMoveWindow(dsp, w, xinerama_x, xinerama_y); + } } #endif #ifdef HAVE_XF86VM -void vo_vm_switch(uint32_t X, uint32_t Y, int* modeline_width, int* modeline_height) +void vo_vm_switch(uint32_t X, uint32_t Y, int *modeline_width, + int *modeline_height) { unsigned int vm_event, vm_error; unsigned int vm_ver, vm_rev; - int i,j,have_vm=0; + int i, j, have_vm = 0; int modecount; - - if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error)) { - XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev); - mp_msg(MSGT_VO,MSGL_V,"XF86VidMode Extension v%i.%i\n", vm_ver, vm_rev); - have_vm=1; + + if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error)) + { + XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev); + mp_msg(MSGT_VO, MSGL_V, "XF86VidMode Extension v%i.%i\n", vm_ver, + vm_rev); + have_vm = 1; } else - mp_msg(MSGT_VO,MSGL_WARN,"XF86VidMode Extenstion not available.\n"); + mp_msg(MSGT_VO, MSGL_WARN, + "XF86VidMode Extenstion not available.\n"); + + if (have_vm) + { + if (vidmodes == NULL) + XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount, + &vidmodes); + j = 0; + *modeline_width = vidmodes[0]->hdisplay; + *modeline_height = vidmodes[0]->vdisplay; - if (have_vm) { - if (vidmodes==NULL) - XF86VidModeGetAllModeLines(mDisplay,mScreen,&modecount,&vidmodes); - j=0; - *modeline_width=vidmodes[0]->hdisplay; - *modeline_height=vidmodes[0]->vdisplay; - - for (i=1; i<modecount; i++) - if ((vidmodes[i]->hdisplay >= X) && (vidmodes[i]->vdisplay >= Y)) - if ( (vidmodes[i]->hdisplay <= *modeline_width ) && (vidmodes[i]->vdisplay <= *modeline_height) ) - { - *modeline_width=vidmodes[i]->hdisplay; - *modeline_height=vidmodes[i]->vdisplay; - j=i; - } - - mp_msg(MSGT_VO,MSGL_INFO,"XF86VM: Selected video mode %dx%d for image size %dx%d.\n",*modeline_width, *modeline_height, X, Y); - XF86VidModeLockModeSwitch(mDisplay,mScreen,0); - XF86VidModeSwitchToMode(mDisplay,mScreen,vidmodes[j]); - XF86VidModeSwitchToMode(mDisplay,mScreen,vidmodes[j]); - X=(vo_screenwidth-*modeline_width)/2; - Y=(vo_screenheight-*modeline_height)/2; - XF86VidModeSetViewPort(mDisplay,mScreen,X,Y); + for (i = 1; i < modecount; i++) + if ((vidmodes[i]->hdisplay >= X) + && (vidmodes[i]->vdisplay >= Y)) + if ((vidmodes[i]->hdisplay <= *modeline_width) + && (vidmodes[i]->vdisplay <= *modeline_height)) + { + *modeline_width = vidmodes[i]->hdisplay; + *modeline_height = vidmodes[i]->vdisplay; + j = i; + } + + mp_msg(MSGT_VO, MSGL_INFO, + "XF86VM: Selected video mode %dx%d for image size %dx%d.\n", + *modeline_width, *modeline_height, X, Y); + XF86VidModeLockModeSwitch(mDisplay, mScreen, 0); + XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]); + XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]); + X = (vo_screenwidth - *modeline_width) / 2; + Y = (vo_screenheight - *modeline_height) / 2; + XF86VidModeSetViewPort(mDisplay, mScreen, X, Y); } } -void vo_vm_close(Display *dpy) +void vo_vm_close(Display * dpy) { - #ifdef HAVE_NEW_GUI - if (vidmodes!=NULL && vo_window != None) - #else - if (vidmodes!=NULL) - #endif - { - int i, modecount; - int screen; screen=DefaultScreen( dpy ); +#ifdef HAVE_NEW_GUI + if (vidmodes != NULL && vo_window != None) +#else + if (vidmodes != NULL) +#endif + { + int i, modecount; + int screen; + + screen = DefaultScreen(dpy); - free(vidmodes); vidmodes=NULL; - XF86VidModeGetAllModeLines(mDisplay,mScreen,&modecount,&vidmodes); - for (i=0; i<modecount; i++) - if ((vidmodes[i]->hdisplay == vo_screenwidth) && (vidmodes[i]->vdisplay == vo_screenheight)) - { - mp_msg(MSGT_VO,MSGL_INFO,"Returning to original mode %dx%d\n", vo_screenwidth, vo_screenheight); - break; - } + free(vidmodes); + vidmodes = NULL; + XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount, + &vidmodes); + for (i = 0; i < modecount; i++) + if ((vidmodes[i]->hdisplay == vo_screenwidth) + && (vidmodes[i]->vdisplay == vo_screenheight)) + { + mp_msg(MSGT_VO, MSGL_INFO, + "Returning to original mode %dx%d\n", + vo_screenwidth, vo_screenheight); + break; + } - XF86VidModeSwitchToMode(dpy,screen,vidmodes[i]); - XF86VidModeSwitchToMode(dpy,screen,vidmodes[i]); - free(vidmodes); - vidmodes = NULL; - } + XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]); + XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]); + free(vidmodes); + vidmodes = NULL; + } } #endif -#endif /* X11_FULLSCREEN */ +#endif /* X11_FULLSCREEN */ /* @@ -1475,45 +1857,50 @@ * depth (at least 15bit). If there are multiple visuals with depth * >= 15bit, we prefer visuals with a smaller color depth. */ -int vo_find_depth_from_visuals(Display *dpy, int screen, Visual **visual_return) +int vo_find_depth_from_visuals(Display * dpy, int screen, + Visual ** visual_return) { - XVisualInfo visual_tmpl; - XVisualInfo *visuals; - int nvisuals, i; - int bestvisual = -1; - int bestvisual_depth = -1; + XVisualInfo visual_tmpl; + XVisualInfo *visuals; + int nvisuals, i; + int bestvisual = -1; + int bestvisual_depth = -1; - visual_tmpl.screen = screen; - visual_tmpl.class = TrueColor; - visuals = XGetVisualInfo(dpy, - VisualScreenMask | VisualClassMask, &visual_tmpl, - &nvisuals); - if (visuals != NULL) { - for (i = 0; i < nvisuals; i++) { - mp_msg(MSGT_VO,MSGL_V,"vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n", - visuals[i].visualid, visuals[i].depth, - visuals[i].red_mask, visuals[i].green_mask, - visuals[i].blue_mask); - /* - * save the visual index and it's depth, if this is the first - * truecolor visul, or a visual that is 'preferred' over the - * previous 'best' visual - */ - if (bestvisual_depth == -1 - || (visuals[i].depth >= 15 - && ( visuals[i].depth < bestvisual_depth - || bestvisual_depth < 15))) { - bestvisual = i; - bestvisual_depth = visuals[i].depth; - } + visual_tmpl.screen = screen; + visual_tmpl.class = TrueColor; + visuals = XGetVisualInfo(dpy, + VisualScreenMask | VisualClassMask, + &visual_tmpl, &nvisuals); + if (visuals != NULL) + { + for (i = 0; i < nvisuals; i++) + { + mp_msg(MSGT_VO, MSGL_V, + "vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n", + visuals[i].visualid, visuals[i].depth, + visuals[i].red_mask, visuals[i].green_mask, + visuals[i].blue_mask); + /* + * save the visual index and it's depth, if this is the first + * truecolor visul, or a visual that is 'preferred' over the + * previous 'best' visual + */ + if (bestvisual_depth == -1 + || (visuals[i].depth >= 15 + && (visuals[i].depth < bestvisual_depth + || bestvisual_depth < 15))) + { + bestvisual = i; + bestvisual_depth = visuals[i].depth; + } + } + + if (bestvisual != -1 && visual_return != NULL) + *visual_return = visuals[bestvisual].visual; + + XFree(visuals); } - - if (bestvisual != -1 && visual_return != NULL) - *visual_return = visuals[bestvisual].visual; - - XFree(visuals); - } - return bestvisual_depth; + return bestvisual_depth; } @@ -1522,45 +1909,58 @@ static int cm_size, red_mask, green_mask, blue_mask; -Colormap vo_x11_create_colormap(XVisualInfo *vinfo) +Colormap vo_x11_create_colormap(XVisualInfo * vinfo) { - unsigned k, r, g, b, ru, gu, bu, m, rv, gv, bv, rvu, gvu, bvu; + unsigned k, r, g, b, ru, gu, bu, m, rv, gv, bv, rvu, gvu, bvu; - if (vinfo->class != DirectColor) - return XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone); + if (vinfo->class != DirectColor) + return XCreateColormap(mDisplay, mRootWin, vinfo->visual, + AllocNone); - /* can this function get called twice or more? */ - if (cmap) return cmap; - cm_size = vinfo->colormap_size; - red_mask = vinfo->red_mask; - green_mask = vinfo->green_mask; - blue_mask = vinfo->blue_mask; - ru = (red_mask&(red_mask-1))^red_mask; - gu = (green_mask&(green_mask-1))^green_mask; - bu = (blue_mask&(blue_mask-1))^blue_mask; - rvu = 65536ull*ru/(red_mask + ru); - gvu = 65536ull*gu/(green_mask + gu); - bvu = 65536ull*bu/(blue_mask + bu); - r = g = b = 0; - rv = gv = bv = 0; - m = DoRed|DoGreen|DoBlue; - for (k = 0; k < cm_size; k++) { - int t; - cols[k].pixel = r|g|b; - cols[k].red = rv; - cols[k].green = gv; - cols[k].blue = bv; - cols[k].flags = m; - t = (r + ru) & red_mask; if (t < r) m &= ~DoRed; r = t; - t = (g + gu) & green_mask; if (t < g) m &= ~DoGreen; g = t; - t = (b + bu) & blue_mask; if (t < b) m &= ~DoBlue; b = t; - rv += rvu; - gv += gvu; - bv += bvu; - } - cmap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocAll); - XStoreColors(mDisplay, cmap, cols, cm_size); - return cmap; + /* can this function get called twice or more? */ + if (cmap) + return cmap; + cm_size = vinfo->colormap_size; + red_mask = vinfo->red_mask; + green_mask = vinfo->green_mask; + blue_mask = vinfo->blue_mask; + ru = (red_mask & (red_mask - 1)) ^ red_mask; + gu = (green_mask & (green_mask - 1)) ^ green_mask; + bu = (blue_mask & (blue_mask - 1)) ^ blue_mask; + rvu = 65536ull * ru / (red_mask + ru); + gvu = 65536ull * gu / (green_mask + gu); + bvu = 65536ull * bu / (blue_mask + bu); + r = g = b = 0; + rv = gv = bv = 0; + m = DoRed | DoGreen | DoBlue; + for (k = 0; k < cm_size; k++) + { + int t; + + cols[k].pixel = r | g | b; + cols[k].red = rv; + cols[k].green = gv; + cols[k].blue = bv; + cols[k].flags = m; + t = (r + ru) & red_mask; + if (t < r) + m &= ~DoRed; + r = t; + t = (g + gu) & green_mask; + if (t < g) + m &= ~DoGreen; + g = t; + t = (b + bu) & blue_mask; + if (t < b) + m &= ~DoBlue; + b = t; + rv += rvu; + gv += gvu; + bv += bvu; + } + cmap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocAll); + XStoreColors(mDisplay, cmap, cols, cm_size); + return cmap; } /* @@ -1577,208 +1977,230 @@ uint32_t vo_x11_set_equalizer(char *name, int value) { - float gamma, brightness, contrast; - float rf, gf, bf; - int k; + float gamma, brightness, contrast; + float rf, gf, bf; + int k; + + /* + * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case + * of TrueColor-ed window but be careful: + * unlike the colormaps, which are private for the X client + * who created them and thus automatically destroyed on client + * disconnect, this gamma ramp is a system-wide (X-server-wide) + * setting and _must_ be restored before the process exit. + * Unforunately when the process crashes (or get killed + * for some reason) it is impossible to restore the setting, + * and such behaviour could be rather annoying for the users. + */ + if (cmap == None) + return VO_NOTAVAIL; - /* - * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case - * of TrueColor-ed window but be careful: - * unlike the colormaps, which are private for the X client - * who created them and thus automatically destroyed on client - * disconnect, this gamma ramp is a system-wide (X-server-wide) - * setting and _must_ be restored before the process exit. - * Unforunately when the process crashes (or get killed - * for some reason) it is impossible to restore the setting, - * and such behaviour could be rather annoying for the users. - */ - if (cmap == None) return VO_NOTAVAIL; + if (!strcasecmp(name, "brightness")) + vo_brightness = value; + else if (!strcasecmp(name, "contrast")) + vo_contrast = value; + else if (!strcasecmp(name, "gamma")) + vo_gamma = value; + else + return VO_NOTIMPL; - if (!strcasecmp(name, "brightness")) vo_brightness = value; - else if (!strcasecmp(name, "contrast")) vo_contrast = value; - else if (!strcasecmp(name, "gamma")) vo_gamma = value; - else return VO_NOTIMPL; - - brightness = 0.01*vo_brightness; - contrast = tan(0.0095*(vo_contrast+100)*M_PI/4); - gamma = pow(2, -0.02*vo_gamma); + brightness = 0.01 * vo_brightness; + contrast = tan(0.0095 * (vo_contrast + 100) * M_PI / 4); + gamma = pow(2, -0.02 * vo_gamma); - rf = (float)((red_mask & (red_mask - 1)) ^ red_mask)/red_mask; - gf = (float)((green_mask & (green_mask - 1)) ^ green_mask)/green_mask; - bf = (float)((blue_mask & (blue_mask - 1)) ^ blue_mask)/blue_mask; + rf = (float) ((red_mask & (red_mask - 1)) ^ red_mask) / red_mask; + gf = (float) ((green_mask & (green_mask - 1)) ^ green_mask) / + green_mask; + bf = (float) ((blue_mask & (blue_mask - 1)) ^ blue_mask) / blue_mask; - /* now recalculate the colormap using the newly set value */ - for (k = 0; k < cm_size; k++) { - float s; + /* now recalculate the colormap using the newly set value */ + for (k = 0; k < cm_size; k++) + { + float s; - s = pow(rf*k, gamma); - s = (s - 0.5)*contrast + 0.5; - s += brightness; - if (s < 0) s = 0; - if (s > 1) s = 1; - cols[k].red = (unsigned short)(s * 65535); + s = pow(rf * k, gamma); + s = (s - 0.5) * contrast + 0.5; + s += brightness; + if (s < 0) + s = 0; + if (s > 1) + s = 1; + cols[k].red = (unsigned short) (s * 65535); - s = pow(gf*k, gamma); - s = (s - 0.5)*contrast + 0.5; - s += brightness; - if (s < 0) s = 0; - if (s > 1) s = 1; - cols[k].green = (unsigned short)(s * 65535); + s = pow(gf * k, gamma); + s = (s - 0.5) * contrast + 0.5; + s += brightness; + if (s < 0) + s = 0; + if (s > 1) + s = 1; + cols[k].green = (unsigned short) (s * 65535); - s = pow(bf*k, gamma); - s = (s - 0.5)*contrast + 0.5; - s += brightness; - if (s < 0) s = 0; - if (s > 1) s = 1; - cols[k].blue = (unsigned short)(s * 65535); - } - - XStoreColors(mDisplay, cmap, cols, cm_size); - XFlush(mDisplay); - return VO_TRUE; + s = pow(bf * k, gamma); + s = (s - 0.5) * contrast + 0.5; + s += brightness; + if (s < 0) + s = 0; + if (s > 1) + s = 1; + cols[k].blue = (unsigned short) (s * 65535); + } + + XStoreColors(mDisplay, cmap, cols, cm_size); + XFlush(mDisplay); + return VO_TRUE; } uint32_t vo_x11_get_equalizer(char *name, int *value) { - if (cmap == None) return VO_NOTAVAIL; - if (!strcasecmp(name, "brightness")) *value = vo_brightness; - else if (!strcasecmp(name, "contrast")) *value = vo_contrast; - else if (!strcasecmp(name, "gamma")) *value = vo_gamma; - else return VO_NOTIMPL; - return VO_TRUE; + if (cmap == None) + return VO_NOTAVAIL; + if (!strcasecmp(name, "brightness")) + *value = vo_brightness; + else if (!strcasecmp(name, "contrast")) + *value = vo_contrast; + else if (!strcasecmp(name, "gamma")) + *value = vo_gamma; + else + return VO_NOTIMPL; + return VO_TRUE; } + #ifdef HAVE_XV int vo_xv_set_eq(uint32_t xv_port, char *name, int value) { XvAttribute *attributes; - int i,howmany, xv_atom; + int i, howmany, xv_atom; mp_dbg(MSGT_VO, MSGL_V, "xv_set_eq called! (%s, %d)\n", name, value); /* get available attributes */ attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany); for (i = 0; i < howmany && attributes; i++) - if (attributes[i].flags & XvSettable) - { - xv_atom = XInternAtom(mDisplay, attributes[i].name, True); + if (attributes[i].flags & XvSettable) + { + xv_atom = XInternAtom(mDisplay, attributes[i].name, True); /* since we have SET_DEFAULTS first in our list, we can check if it's available then trigger it if it's ok so that the other values are at default upon query */ - if (xv_atom != None) - { - int hue = 0,port_value,port_min,port_max; + if (xv_atom != None) + { + int hue = 0, port_value, port_min, port_max; - if(!strcmp(attributes[i].name,"XV_BRIGHTNESS") && - (!strcasecmp(name, "brightness"))) - port_value = value; - else - if(!strcmp(attributes[i].name,"XV_CONTRAST") && - (!strcasecmp(name, "contrast"))) - port_value = value; - else - if(!strcmp(attributes[i].name,"XV_SATURATION") && - (!strcasecmp(name, "saturation"))) - port_value = value; - else - if(!strcmp(attributes[i].name,"XV_HUE") && - (!strcasecmp(name, "hue"))) - { port_value = value; hue=1; } - else + if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") && + (!strcasecmp(name, "brightness"))) + port_value = value; + else if (!strcmp(attributes[i].name, "XV_CONTRAST") && + (!strcasecmp(name, "contrast"))) + port_value = value; + else if (!strcmp(attributes[i].name, "XV_SATURATION") && + (!strcasecmp(name, "saturation"))) + port_value = value; + else if (!strcmp(attributes[i].name, "XV_HUE") && + (!strcasecmp(name, "hue"))) + { + port_value = value; + hue = 1; + } else /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */ - if(!strcmp(attributes[i].name,"XV_RED_INTENSITY") && - (!strcasecmp(name, "red_intensity"))) - port_value = value; - else - if(!strcmp(attributes[i].name,"XV_GREEN_INTENSITY") && - (!strcasecmp(name, "green_intensity"))) - port_value = value; - else - if(!strcmp(attributes[i].name,"XV_BLUE_INTENSITY") && - (!strcasecmp(name, "blue_intensity"))) - port_value = value; - else continue; + if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") && + (!strcasecmp(name, "red_intensity"))) + port_value = value; + else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY") + && (!strcasecmp(name, "green_intensity"))) + port_value = value; + else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY") + && (!strcasecmp(name, "blue_intensity"))) + port_value = value; + else + continue; + + port_min = attributes[i].min_value; + port_max = attributes[i].max_value; - port_min = attributes[i].min_value; - port_max = attributes[i].max_value; - - /* nvidia hue workaround */ - if ( hue && port_min == 0 && port_max == 360 ){ - port_value = (port_value>=0) ? (port_value-100) : (port_value+100); - } - - // -100 -> min - // 0 -> (max+min)/2 - // +100 -> max - port_value = (port_value+100)*(port_max-port_min)/200+port_min; - XvSetPortAttribute(mDisplay, xv_port, xv_atom, port_value); - return(VO_TRUE); + /* nvidia hue workaround */ + if (hue && port_min == 0 && port_max == 360) + { + port_value = + (port_value >= + 0) ? (port_value - 100) : (port_value + 100); } - } - return(VO_FALSE); + // -100 -> min + // 0 -> (max+min)/2 + // +100 -> max + port_value = + (port_value + 100) * (port_max - port_min) / 200 + + port_min; + XvSetPortAttribute(mDisplay, xv_port, xv_atom, port_value); + return (VO_TRUE); + } + } + return (VO_FALSE); } int vo_xv_get_eq(uint32_t xv_port, char *name, int *value) { - + XvAttribute *attributes; - int i,howmany, xv_atom; + int i, howmany, xv_atom; /* get available attributes */ attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany); for (i = 0; i < howmany && attributes; i++) - if (attributes[i].flags & XvGettable) - { - xv_atom = XInternAtom(mDisplay, attributes[i].name, True); + if (attributes[i].flags & XvGettable) + { + xv_atom = XInternAtom(mDisplay, attributes[i].name, True); /* since we have SET_DEFAULTS first in our list, we can check if it's available then trigger it if it's ok so that the other values are at default upon query */ - if (xv_atom != None) - { - int val, port_value=0, port_min, port_max; + if (xv_atom != None) + { + int val, port_value = 0, port_min, port_max; - XvGetPortAttribute(mDisplay, xv_port, xv_atom, &port_value); + XvGetPortAttribute(mDisplay, xv_port, xv_atom, + &port_value); + + port_min = attributes[i].min_value; + port_max = attributes[i].max_value; + val = + (port_value - port_min) * 200 / (port_max - port_min) - + 100; - port_min = attributes[i].min_value; - port_max = attributes[i].max_value; - val=(port_value-port_min)*200/(port_max-port_min)-100; - - if(!strcmp(attributes[i].name,"XV_BRIGHTNESS") && - (!strcasecmp(name, "brightness"))) - *value = val; - else - if(!strcmp(attributes[i].name,"XV_CONTRAST") && - (!strcasecmp(name, "contrast"))) - *value = val; - else - if(!strcmp(attributes[i].name,"XV_SATURATION") && - (!strcasecmp(name, "saturation"))) - *value = val; - else - if(!strcmp(attributes[i].name,"XV_HUE") && - (!strcasecmp(name, "hue"))){ - /* nasty nvidia detect */ - if (port_min == 0 && port_max == 360) - *value = (val>=0) ? (val-100) : (val+100); - else - *value = val; - } else + if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") && + (!strcasecmp(name, "brightness"))) + *value = val; + else if (!strcmp(attributes[i].name, "XV_CONTRAST") && + (!strcasecmp(name, "contrast"))) + *value = val; + else if (!strcmp(attributes[i].name, "XV_SATURATION") && + (!strcasecmp(name, "saturation"))) + *value = val; + else if (!strcmp(attributes[i].name, "XV_HUE") && + (!strcasecmp(name, "hue"))) + { + /* nasty nvidia detect */ + if (port_min == 0 && port_max == 360) + *value = (val >= 0) ? (val - 100) : (val + 100); + else + *value = val; + } else /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */ - if(!strcmp(attributes[i].name,"XV_RED_INTENSITY") && - (!strcasecmp(name, "red_intensity"))) - *value = val; - else - if(!strcmp(attributes[i].name,"XV_GREEN_INTENSITY") && - (!strcasecmp(name, "green_intensity"))) - *value = val; - else - if(!strcmp(attributes[i].name,"XV_BLUE_INTENSITY") && - (!strcasecmp(name, "blue_intensity"))) - *value = val; - else continue; + if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") && + (!strcasecmp(name, "red_intensity"))) + *value = val; + else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY") + && (!strcasecmp(name, "green_intensity"))) + *value = val; + else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY") + && (!strcasecmp(name, "blue_intensity"))) + *value = val; + else + continue; - mp_dbg(MSGT_VO, MSGL_V, "xv_get_eq called! (%s, %d)\n", name, *value); - return(VO_TRUE); - } - } - return(VO_FALSE); + mp_dbg(MSGT_VO, MSGL_V, "xv_get_eq called! (%s, %d)\n", + name, *value); + return (VO_TRUE); + } + } + return (VO_FALSE); } #endif