From fea8c85c8595b797fc839b113c1db252fc55c798 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 31 Mar 2012 01:56:57 +0200 Subject: gl_common: minor cleanup/refactor Remove all platform/GUI specific includes from gl_common.h. Get rid of the ugly union in MPGLContext. Use function pointers instead of an ifdef ridden switch statement in uninit_mpglcontext(). Always include glext.h, not only on Windows. None of this should actually change any functionality. --- libvo/gl_common.c | 78 ++++++++++++++++++++++++++++++------------------------- libvo/gl_common.h | 30 ++------------------- 2 files changed, 44 insertions(+), 64 deletions(-) diff --git a/libvo/gl_common.c b/libvo/gl_common.c index b83fecbb6b..c5abc81e15 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -1764,8 +1764,13 @@ static void cocoa_fullscreen(struct vo *vo) #endif #ifdef CONFIG_GL_WIN32 +#include #include "w32_common.h" +struct w32_context { + int vinfo; + HGLRC context; +}; static int create_window_w32(struct MPGLContext *ctx, uint32_t d_width, uint32_t d_height, uint32_t flags) @@ -1797,7 +1802,8 @@ static int create_window_w32_gl3(struct MPGLContext *ctx, int gl_flags, if (!vo_w32_config(d_width, d_height, flags)) return -1; - HGLRC *context = &ctx->context.w32; + struct w32_context *w32_ctx = ctx->priv; + HGLRC *context = &w32_ctx->context; if (*context) // reuse existing context return 0; // not reusing it breaks gl3! @@ -1891,8 +1897,9 @@ out: static int setGlWindow_w32(MPGLContext *ctx) { HWND win = vo_w32_window; - int *vinfo = &ctx->vinfo.w32; - HGLRC *context = &ctx->context.w32; + struct w32_context *w32_ctx = ctx->priv; + int *vinfo = &w32_ctx->vinfo; + HGLRC *context = &w32_ctx->context; int new_vinfo; HDC windc = vo_w32_get_dc(win); HGLRC new_context = 0; @@ -1954,8 +1961,9 @@ out: static void releaseGlContext_w32(MPGLContext *ctx) { - int *vinfo = &ctx->vinfo.w32; - HGLRC *context = &ctx->context.w32; + struct w32_context *w32_ctx = ctx->priv; + int *vinfo = &w32_ctx->vinfo; + HGLRC *context = &w32_ctx->context; *vinfo = 0; if (*context) { wglMakeCurrent(0, 0); @@ -1977,10 +1985,19 @@ static void new_vo_w32_border(struct vo *vo) { vo_w32_border(); } static void new_vo_w32_fullscreen(struct vo *vo) { vo_w32_fullscreen(); } static int new_vo_w32_check_events(struct vo *vo) { return vo_w32_check_events(); } static void new_w32_update_xinerama_info(struct vo *vo) { w32_update_xinerama_info(); } +static void new_vo_w32_uninit(struct vo *vo) { vo_w32_uninit(); } #endif + #ifdef CONFIG_GL_X11 +#include +#include #include "x11_common.h" +struct glx_context { + XVisualInfo *vinfo; + GLXContext context; +}; + static int create_window_x11(struct MPGLContext *ctx, uint32_t d_width, uint32_t d_height, uint32_t flags) { @@ -2071,8 +2088,9 @@ static char *get_glx_exts(MPGLContext *ctx) */ static int setGlWindow_x11(MPGLContext *ctx) { - XVisualInfo **vinfo = &ctx->vinfo.x11; - GLXContext *context = &ctx->context.x11; + struct glx_context *glx_context = ctx->priv; + XVisualInfo **vinfo = &glx_context->vinfo; + GLXContext *context = &glx_context->context; Display *display = ctx->vo->x11->display; Window win = ctx->vo->x11->window; XVisualInfo *new_vinfo; @@ -2174,13 +2192,14 @@ static int create_window_x11_gl3(struct MPGLContext *ctx, int gl_flags, uint32_t d_height, uint32_t flags) { struct vo *vo = ctx->vo; + struct glx_context *glx_ctx = ctx->priv; - if (ctx->context.x11) { + if (glx_ctx->context) { // GL context and window already exist. // Only update window geometry etc. Colormap colormap = XCreateColormap(vo->x11->display, vo->x11->rootwin, - ctx->vinfo.x11->visual, AllocNone); - vo_x11_create_vo_window(vo, ctx->vinfo.x11, vo->dx, vo->dy, d_width, + glx_ctx->vinfo->visual, AllocNone); + vo_x11_create_vo_window(vo, glx_ctx->vinfo, vo->dx, vo->dy, d_width, d_height, flags, colormap, "gl"); XFreeColormap(vo->x11->display, colormap); return SET_WINDOW_OK; @@ -2276,8 +2295,8 @@ static int create_window_x11_gl3(struct MPGLContext *ctx, int gl_flags, return SET_WINDOW_FAILED; } - ctx->vinfo.x11 = vinfo; - ctx->context.x11 = context; + glx_ctx->vinfo = vinfo; + glx_ctx->context = context; getFunctions(ctx->gl, (void *)glXGetProcAddress, glxstr, true); @@ -2292,8 +2311,9 @@ static int create_window_x11_gl3(struct MPGLContext *ctx, int gl_flags, */ static void releaseGlContext_x11(MPGLContext *ctx) { - XVisualInfo **vinfo = &ctx->vinfo.x11; - GLXContext *context = &ctx->context.x11; + struct glx_context *glx_ctx = ctx->priv; + XVisualInfo **vinfo = &glx_ctx->vinfo; + GLXContext *context = &glx_ctx->context; Display *display = ctx->vo->x11->display; GL *gl = ctx->gl; if (*vinfo) @@ -2363,6 +2383,7 @@ static int sdl_check_events(struct vo *vo) static void new_sdl_update_xinerama_info(struct vo *vo) { sdl_update_xinerama_info(); } static void new_vo_sdl_fullscreen(struct vo *vo) { vo_sdl_fullscreen(); } +static void new_vo_sdl_uninit(struct vo *vo) { vo_sdl_uninit(); } #endif @@ -2426,12 +2447,14 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) ctx->check_events = cocoa_check_events; ctx->update_xinerama_info = cocoa_update_xinerama_info; ctx->fullscreen = cocoa_fullscreen; + ctx->vo_uninit = vo_cocoa_uninit; if (vo_cocoa_init(vo)) return ctx; break; #endif #ifdef CONFIG_GL_WIN32 case GLTYPE_W32: + ctx->priv = talloc_zero(ctx, struct w32_context); ctx->create_window = create_window_w32; ctx->create_window_gl3 = create_window_w32_gl3; ctx->setGlWindow = setGlWindow_w32; @@ -2442,6 +2465,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) ctx->check_events = new_vo_w32_check_events; ctx->fullscreen = new_vo_w32_fullscreen; ctx->ontop = new_vo_w32_ontop; + ctx->vo_uninit = new_vo_w32_uninit; //the win32 code is hardcoded to use the deprecated vo API global_vo = vo; if (vo_w32_init()) @@ -2450,6 +2474,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) #endif #ifdef CONFIG_GL_X11 case GLTYPE_X11: + ctx->priv = talloc_zero(ctx, struct glx_context); ctx->create_window = create_window_x11; ctx->setGlWindow = setGlWindow_x11; ctx->create_window_gl3 = create_window_x11_gl3; @@ -2460,6 +2485,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) ctx->check_events = vo_x11_check_events; ctx->fullscreen = vo_x11_fullscreen; ctx->ontop = vo_x11_ontop; + ctx->vo_uninit = vo_x11_uninit; if (vo_init(vo)) return ctx; break; @@ -2473,6 +2499,7 @@ MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo) ctx->update_xinerama_info = new_sdl_update_xinerama_info; ctx->check_events = sdl_check_events; ctx->fullscreen = new_vo_sdl_fullscreen; + ctx->vo_uninit = new_vo_sdl_uninit; //the SDL code is hardcoded to use the deprecated vo API global_vo = vo; if (vo_sdl_init()) @@ -2507,28 +2534,7 @@ void uninit_mpglcontext(MPGLContext *ctx) if (!ctx) return; ctx->releaseGlContext(ctx); - switch (ctx->type) { -#ifdef CONFIG_GL_COCOA - case GLTYPE_COCOA: - vo_cocoa_uninit(ctx->vo); - break; -#endif -#ifdef CONFIG_GL_WIN32 - case GLTYPE_W32: - vo_w32_uninit(); - break; -#endif -#ifdef CONFIG_GL_X11 - case GLTYPE_X11: - vo_x11_uninit(ctx->vo); - break; -#endif -#ifdef CONFIG_GL_SDL - case GLTYPE_SDL: - vo_sdl_uninit(); - break; -#endif - } + ctx->vo_uninit(ctx->vo); talloc_free(ctx); } diff --git a/libvo/gl_common.h b/libvo/gl_common.h index dd420a7ebb..8091886b1f 100644 --- a/libvo/gl_common.h +++ b/libvo/gl_common.h @@ -33,22 +33,8 @@ #include "video_out.h" #include "csputils.h" -#ifdef CONFIG_GL_WIN32 -#include -#include "w32_common.h" -#endif -#ifdef CONFIG_GL_X11 -#include -#include -#include "x11_common.h" -// This old-vo wrapper macro would conflict with the struct member -#undef update_xinerama_info -#endif #include - -#ifdef CONFIG_GL_WIN32 #include -#endif #include "libvo/gl_header_fixes.h" @@ -191,22 +177,9 @@ typedef struct MPGLContext { GL *gl; enum MPGLType type; struct vo *vo; + void *priv; // Bit size of each component in the created framebuffer. 0 if unknown. int depth_r, depth_g, depth_b; - union { - int w32; -#ifdef CONFIG_GL_X11 - XVisualInfo *x11; -#endif - } vinfo; - union { -#ifdef CONFIG_GL_WIN32 - HGLRC w32; -#endif -#ifdef CONFIG_GL_X11 - GLXContext x11; -#endif - } context; int (*create_window)(struct MPGLContext *ctx, uint32_t d_width, uint32_t d_height, uint32_t flags); int (*setGlWindow)(struct MPGLContext *); @@ -214,6 +187,7 @@ typedef struct MPGLContext { void (*swapGlBuffers)(struct MPGLContext *); int (*check_events)(struct vo *vo); void (*fullscreen)(struct vo *vo); + void (*vo_uninit)(struct vo *vo); // only available if GL3 context creation is supported // gl_flags: bitfield of MPGLFLAG_* constants // gl_version: requested OpenGL version number (use MPGL_VER()) -- cgit v1.2.3