diff options
author | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-11-01 20:24:37 +0000 |
---|---|---|
committer | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-11-01 20:24:37 +0000 |
commit | 1a7a3f8b389b4febd41dd2d3f7c16fb033d98fe7 (patch) | |
tree | 0619ef71f423acd2f182db83235c2e29dcee1bae /libvo/gl_common.c | |
parent | 0e49449d13c63f3673e6cc5021459bcf30ebe285 (diff) | |
download | mpv-1a7a3f8b389b4febd41dd2d3f7c16fb033d98fe7.tar.bz2 mpv-1a7a3f8b389b4febd41dd2d3f7c16fb033d98fe7.tar.xz |
fullscreen fixes and GUI support for vo_gl
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13844 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo/gl_common.c')
-rw-r--r-- | libvo/gl_common.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/libvo/gl_common.c b/libvo/gl_common.c index 900c8a3ec6..7c82c74076 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -17,3 +17,101 @@ void glAdjustAlignment(int stride) { glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment); } +#ifndef GL_WIN32 +/** + * Returns the XVisualInfo associated with Window win. + * \param win Window whose XVisualInfo is returne. + * \return XVisualInfo of the window. Caller must use XFree to free it. + */ +static XVisualInfo *getWindowVisualInfo(Window win) { + XWindowAttributes xw_attr; + XVisualInfo vinfo_template; + int tmp; + XGetWindowAttributes(mDisplay, win, &xw_attr); + vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual); + return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp); +} + +/** + * \brief Changes the window in which video is displayed. + * If possible only transfers the context to the new window, otherwise + * creates a new one, which must be initialized by the caller. + * \param vinfo Currently used visual. + * \param context Currently used context. + * \param win window that should be used for drawing. + * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT. + * In case of SET_WINDOW_REINIT the context could not be transfered + * and the caller must initialize it correctly. + */ +int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win) +{ + XVisualInfo *new_vinfo; + GLXContext new_context = NULL; + int keep_context = 0; + + // should only be needed when keeping context, but not doing glFinish + // can cause flickering even when we do not keep it. + glFinish(); + new_vinfo = getWindowVisualInfo(win); + if (*context && *vinfo && new_vinfo && + (*vinfo)->visualid == new_vinfo->visualid) { + // we can keep the GLXContext + new_context = *context; + XFree(new_vinfo); + new_vinfo = *vinfo; + keep_context = 1; + } else { + // create a context + new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True); + if (!new_context) { + mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GLX context!\n"); + XFree(new_vinfo); + return SET_WINDOW_FAILED; + } + } + + // set context + if (!glXMakeCurrent(mDisplay, vo_window, new_context)) { + mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GLX context!\n"); + if (!keep_context) { + glXDestroyContext (mDisplay, new_context); + XFree(new_vinfo); + } + return SET_WINDOW_FAILED; + } + + // set new values + vo_window = win; + { + Window root; + int tmp; + XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp, + &vo_dwidth, &vo_dheight, &tmp, &tmp); + } + if (!keep_context) { + if (*context) + glXDestroyContext(mDisplay, *context); + *context = new_context; + if (*vinfo) + XFree(*vinfo); + *vinfo = new_vinfo; + + // and inform that reinit is neccessary + return SET_WINDOW_REINIT; + } + return SET_WINDOW_OK; +} + +/** + * \brief free the VisualInfo and GLXContext of an OpenGL context. + */ +void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) { + if (*vinfo) + XFree(*vinfo); + *vinfo = NULL; + if (*context) + glXDestroyContext(mDisplay, *context); + *context = 0; +} +#endif + |