summaryrefslogtreecommitdiff
path: root/src/video_out/video_out_opengl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_out/video_out_opengl.c')
-rw-r--r--src/video_out/video_out_opengl.c75
1 files changed, 65 insertions, 10 deletions
diff --git a/src/video_out/video_out_opengl.c b/src/video_out/video_out_opengl.c
index 54696f452..a8f11db2f 100644
--- a/src/video_out/video_out_opengl.c
+++ b/src/video_out/video_out_opengl.c
@@ -669,8 +669,8 @@ static int render_image_envtex (opengl_driver_t *this, opengl_frame_t *frame) {
* Render setup functions
*/
static int render_help_verify_ext (opengl_driver_t *this, char *ext) {
- int ret = 0;
- int l = strlen (ext);
+ int ret = 0;
+ const size_t l = strlen (ext);
const char *e;
for (e = (char *) this->gl_exts; e && *e; e = strchr (e, ' ')) {
while (isspace (*e))
@@ -694,10 +694,9 @@ static void *getdladdr (const GLubyte *_funcName) {
return NULL;
#elif defined(__APPLE__)
- char *temp = xine_xmalloc (strlen (funcName) + 2);
+ char *temp;
+ asprintf(&temp, "_%s", funcName);
void *res = NULL;
- temp[0] = '_'; /* Mac OS X prepends an underscore on function names */
- strcpy (temp+1, funcName);
if (NSIsSymbolNameDefined (temp)) {
NSSymbol symbol = NSLookupAndBindSymbol (temp);
res = NSAddressOfSymbol (symbol);
@@ -1281,7 +1280,7 @@ static vo_frame_t *opengl_alloc_frame (vo_driver_t *this_gen) {
opengl_frame_t *frame;
opengl_driver_t *this = (opengl_driver_t *) this_gen;
- frame = (opengl_frame_t *) xine_xmalloc (sizeof (opengl_frame_t));
+ frame = (opengl_frame_t *) calloc(1, sizeof(opengl_frame_t));
if (!frame)
return NULL;
@@ -1820,7 +1819,7 @@ static vo_driver_t *opengl_open_plugin (video_driver_class_t *class_gen, const v
char **render_fun_names;
int i;
- this = (opengl_driver_t *) xine_xmalloc (sizeof (opengl_driver_t));
+ this = (opengl_driver_t *) calloc(1, sizeof(opengl_driver_t));
if (!this)
return NULL;
@@ -1876,8 +1875,7 @@ static vo_driver_t *opengl_open_plugin (video_driver_class_t *class_gen, const v
this->drawable, X11OSD_SHAPED);
XUnlockDisplay (this->display);
- render_fun_names = xine_xmalloc ((sizeof(opengl_rb)/sizeof(opengl_render_t)+1)
- * sizeof (const char *));
+ render_fun_names = calloc((sizeof(opengl_rb)/sizeof(opengl_render_t)+1), sizeof(const char*));
for (i = 0; i < sizeof (opengl_rb) / sizeof (opengl_render_t); i++)
render_fun_names[i] = opengl_rb[i].name;
render_fun_names[i] = NULL;
@@ -1955,6 +1953,52 @@ 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 char* opengl_get_identifier (video_driver_class_t *this_gen) {
return "opengl";
}
@@ -1970,7 +2014,18 @@ static void opengl_dispose_class (video_driver_class_t *this_gen) {
}
static void *opengl_init_class (xine_t *xine, void *visual_gen) {
- opengl_class_t *this = (opengl_class_t *) xine_xmalloc (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.get_identifier = opengl_get_identifier;