[Libva] [PATCH 4/4] Drop explicit dependency on libva-x11.

Gwenole Beauchesne gb.devel at gmail.com
Tue Jul 3 07:43:36 PDT 2012


Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/Makefile.am       |    3 +--
 src/i965_drv_video.h  |    3 +++
 src/i965_render_dri.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 829e83b..ea3eab9 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,7 +40,7 @@ driver_ldflags = \
 	$(NULL)
 
 driver_libs = \
-	-lpthread -lm		\
+	-lpthread -lm -ldl	\
 	$(DRM_LIBS) -ldrm_intel	\
 	$(LIBVA_DEPS_LIBS)	\
 	$(NULL)
@@ -112,7 +112,6 @@ noinst_HEADERS			= $(source_h)
 if USE_X11
 source_c			+= i965_render_dri.c
 source_h			+= i965_render_dri.h
-driver_libs			+= $(LIBVA_X11_DEPS_LIBS)
 endif
 
 # Extra clean files so that maintainer-clean removes *everything*
diff --git a/src/i965_drv_video.h b/src/i965_drv_video.h
index e40e9b4..ebd8f9b 100644
--- a/src/i965_drv_video.h
+++ b/src/i965_drv_video.h
@@ -275,6 +275,9 @@ struct i965_driver_data
     char va_vendor[256];
     
     VAContextID current_context_id;
+
+    /* dri_*() function hooks to libva-x11.so.* */
+    void *dri_vtable;
 };
 
 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
diff --git a/src/i965_render_dri.c b/src/i965_render_dri.c
index f700173..40bf024 100644
--- a/src/i965_render_dri.c
+++ b/src/i965_render_dri.c
@@ -22,22 +22,81 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#define _GNU_SOURCE 1
 #include "config.h"
+#include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <dlfcn.h>
 #include <va/va_dricommon.h>
 #include "i965_drv_video.h"
 #include "i965_render_dri.h"
 
+typedef void (*dri_generic_func)(void);
+typedef struct dri_drawable *(*dri_get_drawable_func)(
+    VADriverContextP ctx, XID drawable);
+typedef union dri_buffer *(*dri_get_rendering_buffer_func)(
+    VADriverContextP ctx, struct dri_drawable *d);
+typedef void (*dri_swap_buffer_func)(
+    VADriverContextP ctx, struct dri_drawable *d);
+
+struct dri_vtable {
+    dri_get_drawable_func               get_drawable;
+    dri_get_rendering_buffer_func       get_rendering_buffer;
+    dri_swap_buffer_func                swap_buffer;
+};
+
+static bool
+get_symbol(void *func_vptr, const char *name)
+{
+    dri_generic_func func, *func_ptr = func_vptr;
+    const char *error;
+
+    dlerror();
+    func = (dri_generic_func)dlsym(RTLD_DEFAULT, name);
+    error = dlerror();
+
+    if (error) {
+        fprintf(stderr, "error: failed to resolved %s() function: %s\n", name, error);
+        return false;
+    }
+
+    *func_ptr = func;
+    return true;
+}
+
 bool
 i965_render_dri_init(VADriverContextP ctx)
 {
+    struct i965_driver_data * const i965 = i965_driver_data(ctx); 
+    struct dri_vtable *vtable = NULL;
+
+    vtable = calloc(1, sizeof(*vtable));
+    if (!vtable)
+        return false;
+
+    if (!get_symbol(&vtable->get_drawable, "dri_get_drawable"))
+        goto error;
+    if (!get_symbol(&vtable->get_rendering_buffer, "dri_get_rendering_buffer"))
+        goto error;
+    if (!get_symbol(&vtable->swap_buffer, "dri_swap_buffer"))
+        goto error;
+
+    i965->dri_vtable = vtable;
     return true;
+
+error:
+    free(vtable);
+    return false;
 }
 
 void
 i965_render_dri_terminate(VADriverContextP ctx)
 {
+    struct i965_driver_data * const i965 = i965_driver_data(ctx); 
+
+    free(i965->dri_vtable);
+    i965->dri_vtable = NULL;
 }
 
 VAStatus
@@ -53,6 +112,7 @@ i965_put_surface_dri(
 )
 {
     struct i965_driver_data * const i965 = i965_driver_data(ctx); 
+    struct dri_vtable * const dri_vtable = i965->dri_vtable;
     struct dri_state * const dri_state = (struct dri_state *)ctx->drm_state;
     struct i965_render_state * const render_state = &i965->render_state;
     struct dri_drawable *dri_drawable;
@@ -77,10 +137,10 @@ i965_put_surface_dri(
 
     _i965LockMutex(&i965->render_mutex);
 
-    dri_drawable = dri_get_drawable(ctx, (Drawable)draw);
+    dri_drawable = dri_vtable->get_drawable(ctx, (Drawable)draw);
     assert(dri_drawable);
 
-    buffer = dri_get_rendering_buffer(ctx, dri_drawable);
+    buffer = dri_vtable->get_rendering_buffer(ctx, dri_drawable);
     assert(buffer);
     
     dest_region = render_state->draw_region;
@@ -129,7 +189,7 @@ i965_put_surface_dri(
         intel_render_put_subpicture(ctx, surface, src_rect, dst_rect);
     }
 
-    dri_swap_buffer(ctx, dri_drawable);
+    dri_vtable->swap_buffer(ctx, dri_drawable);
     obj_surface->flags |= SURFACE_DISPLAYED;
 
     if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
-- 
1.7.9.5



More information about the Libva mailing list