From patchwork Mon Jul 25 13:56:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 3092 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1071523E54 for ; Mon, 25 Jul 2011 13:58:04 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id CDFB0A1844E for ; Mon, 25 Jul 2011 13:58:03 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so3003702qwb.11 for ; Mon, 25 Jul 2011 06:58:03 -0700 (PDT) Received: by 10.229.1.217 with SMTP id 25mr1001924qcg.38.1311602281987; Mon, 25 Jul 2011 06:58:01 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs77912qcb; Mon, 25 Jul 2011 06:58:01 -0700 (PDT) Received: by 10.204.129.7 with SMTP id m7mr1372354bks.364.1311602281094; Mon, 25 Jul 2011 06:58:01 -0700 (PDT) Received: from mail-fx0-f44.google.com (mail-fx0-f44.google.com [209.85.161.44]) by mx.google.com with ESMTPS id 18si7042659fat.105.2011.07.25.06.58.00 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:58:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.161.44 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) client-ip=209.85.161.44; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.161.44 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) smtp.mail=alexandros.frantzis@linaro.org Received: by mail-fx0-f44.google.com with SMTP id 6so6802455fxe.17 for ; Mon, 25 Jul 2011 06:58:00 -0700 (PDT) Received: by 10.223.14.139 with SMTP id g11mr6905254faa.82.1311602280625; Mon, 25 Jul 2011 06:58:00 -0700 (PDT) Received: from localhost (77.49.93.204.dsl.dyn.forthnet.gr [77.49.93.204]) by mx.google.com with ESMTPS id n18sm2782418fam.31.2011.07.25.06.57.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:58:00 -0700 (PDT) From: alexandros.frantzis@linaro.org To: patches@linaro.org Subject: [PATCH 20/21] gl: Fall back to dlsym() if *GetProcAddress() fails Date: Mon, 25 Jul 2011 16:56:47 +0300 Message-Id: <1311602208-5973-20-git-send-email-alexandros.frantzis@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1311602208-5973-1-git-send-email-alexandros.frantzis@linaro.org> References: <1311602208-5973-1-git-send-email-alexandros.frantzis@linaro.org> From: Alexandros Frantzis In strictly conforming EGL implementations, eglGetProcAddress() can be used only to get extension functions, but some of the functions we want belong to core GL(ES). If the *GetProcAddress function provided by the context fails, try to get the address of the wanted GL function using standard system facilities (eg dlsym() in *nix systems). Signed-off-by: Chris Wilson --- configure.ac | 11 +++++++++ src/cairo-gl-dispatch.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index 9107b3e..72caa0d 100644 --- a/configure.ac +++ b/configure.ac @@ -49,6 +49,9 @@ if test "x$have_dlsym" = "xno"; then fi AC_CHECK_HEADERS(dlfcn.h, [have_dlsym=yes], [have_dlsym=no]) AM_CONDITIONAL(CAIRO_HAS_DL, test "x$have_dl" = "xyes") +if test "x$have_dlsym" = "xyes"; then + AC_DEFINE([CAIRO_HAS_DLSYM], 1, [Define to 1 if dlsym is available]) +fi dnl =========================================================================== @@ -317,6 +320,10 @@ CAIRO_ENABLE_SURFACE_BACKEND(gl, OpenGL, no, [ gl_NONPKGCONFIG_LIBS="-lGL" fi]) + if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then + gl_LIBS="$gl_LIBS -ldl" + fi + need_glx_functions=yes need_wgl_functions=yes need_egl_functions=yes @@ -333,6 +340,10 @@ CAIRO_ENABLE_SURFACE_BACKEND(glesv2, OpenGLESv2, no, [ glesv2_NONPKGCONFIG_LIBS="-lGLESv2" fi]) + if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then + glesv2_LIBS="$glesv2_LIBS -ldl" + fi + need_egl_functions=yes ]) diff --git a/src/cairo-gl-dispatch.c b/src/cairo-gl-dispatch.c index 6277f53..344b0eb 100644 --- a/src/cairo-gl-dispatch.c +++ b/src/cairo-gl-dispatch.c @@ -32,6 +32,48 @@ #include "cairoint.h" #include "cairo-gl-private.h" #include "cairo-gl-dispatch-private.h" +#if CAIRO_HAS_DLSYM +#include +#endif + +#if CAIRO_HAS_DLSYM +static void * +_cairo_gl_dispatch_open_lib (void) +{ + return dlopen (NULL, RTLD_LAZY); +} + +static void +_cairo_gl_dispatch_close_lib (void *handle) +{ + dlclose (handle); +} + +static cairo_gl_generic_func_t +_cairo_gl_dispatch_get_proc_addr (void *handle, const char *name) +{ + return (cairo_gl_generic_func_t) dlsym (handle, name); +} +#else +static void * +_cairo_gl_dispatch_open_lib (void) +{ + return NULL; +} + +static void +_cairo_gl_dispatch_close_lib (void *handle) +{ + return; +} + +static cairo_gl_generic_func_t +_cairo_gl_dispatch_get_proc_addr (void *handle, const char *name) +{ + return NULL; +} +#endif /* CAIRO_HAS_DLSYM */ + static void _cairo_gl_dispatch_init_entries (cairo_gl_dispatch_t *dispatch, @@ -40,18 +82,30 @@ _cairo_gl_dispatch_init_entries (cairo_gl_dispatch_t *dispatch, cairo_gl_dispatch_name_t dispatch_name) { cairo_gl_dispatch_entry_t *entry = entries; + void *handle = _cairo_gl_dispatch_open_lib (); while (entry->name[CAIRO_GL_DISPATCH_NAME_CORE] != NULL) { void *dispatch_ptr = &((char *) dispatch)[entry->offset]; const char *name = entry->name[dispatch_name]; + /* + * In strictly conforming EGL implementations, eglGetProcAddress() can + * be used only to get extension functions, but some of the functions + * we want belong to core GL(ES). If the *GetProcAddress function + * provided by the context fails, try to get the address of the wanted + * GL function using standard system facilities (eg dlsym() in *nix + * systems). + */ cairo_gl_generic_func_t func = get_proc_addr (name); + if (func == NULL) + func = _cairo_gl_dispatch_get_proc_addr (handle, name); *((cairo_gl_generic_func_t *) dispatch_ptr) = func; ++entry; } + _cairo_gl_dispatch_close_lib (handle); } static cairo_status_t