From 9b70d5f03f02bb3497eb7291e9858e34388a9aa1 Mon Sep 17 00:00:00 2001 From: Matthias Hopf Date: Fri, 8 Aug 2008 17:18:32 +0200 Subject: video_out_opengl: Activate only if visual is direct rendering capable --- src/video_out/video_out_opengl.c | 60 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/video_out/video_out_opengl.c b/src/video_out/video_out_opengl.c index 4aeaab325..d66e85ae9 100644 --- a/src/video_out/video_out_opengl.c +++ b/src/video_out/video_out_opengl.c @@ -1954,8 +1954,66 @@ static vo_driver_t *opengl_open_plugin (video_driver_class_t *class_gen, const v /* * class functions */ + +static int opengl_verify_direct (x11_visual_t *vis) { + int attribs[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None + }; + Window root, win; + XVisualInfo *visinfo; + GLXContext ctx; + XSetWindowAttributes xattr; + int ret = 0; + + if (!vis || !vis->display || + ! (root = RootWindow (vis->display, vis->screen))) { + fprintf (stderr, "[videoout_opengl]: Don't have a root window to verify\n"); + return 0; + } + if (! (visinfo = glXChooseVisual (vis->display, vis->screen, attribs))) + return 0; + if (! (ctx = glXCreateContext (vis->display, visinfo, NULL, 1))) + return 0; + memset (&xattr, 0, sizeof (xattr)); + xattr.colormap = XCreateColormap(vis->display, root, visinfo->visual, AllocNone); + xattr.event_mask = StructureNotifyMask | ExposureMask; + if ( (win = XCreateWindow (vis->display, root, 0, 0, 1, 1, 0, visinfo->depth, + InputOutput, visinfo->visual, + CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, + &xattr))) { + if (glXMakeCurrent (vis->display, win, ctx)) { + const char *renderer = (const char *) glGetString(GL_RENDERER); + if (glXIsDirect (vis->display, ctx) && + ! strstr (renderer, "Software") && + ! strstr (renderer, "Indirect")) + ret = 1; + glXMakeCurrent (vis->display, None, NULL); + } + XDestroyWindow (vis->display, win); + } + glXDestroyContext (vis->display, ctx); + XFreeColormap (vis->display, xattr.colormap); + + return ret; +} + static void *opengl_init_class (xine_t *xine, void *visual_gen) { - opengl_class_t *this = (opengl_class_t *) calloc(1, sizeof(opengl_class_t)); + + opengl_class_t *this; + + xprintf (xine, XINE_VERBOSITY_LOG, + "video_out_opengl: Testing for hardware accelerated direct rendering visual\n"); + if (! opengl_verify_direct ((x11_visual_t *)visual_gen)) { + xprintf (xine, XINE_VERBOSITY_LOG, + "video_out_opengl: Didn't find any\n"); + return NULL; + } + + this = (opengl_class_t *) calloc (1, sizeof(opengl_class_t)); this->driver_class.open_plugin = opengl_open_plugin; this->driver_class.identifier = "opengl"; -- cgit v1.2.3