[Libva] [PATCH 3/4] Allow build without VA/X11 API.

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


From: Dmitry Ermilov <dmitry.ermilov at intel.com>

Signed-off-by: Dmitry Ermilov <dmitry.ermilov at intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 configure.ac          |   18 +++++-
 src/Makefile.am       |    7 ++-
 src/i965_drv_video.c  |  142 +++++++++++------------------------------------
 src/i965_render_dri.c |  147 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/i965_render_dri.h |   49 +++++++++++++++++
 5 files changed, 250 insertions(+), 113 deletions(-)
 create mode 100644 src/i965_render_dri.c
 create mode 100644 src/i965_render_dri.h

diff --git a/configure.ac b/configure.ac
index 3c084a0..bfee374 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,6 +46,11 @@ AC_ARG_ENABLE(drm,
                     [build with VA/DRM API support @<:@default=yes@:>@])],
     [], [enable_drm="yes"])
 
+AC_ARG_ENABLE(x11,
+    [AC_HELP_STRING([--enable-x11],
+                    [build with VA/X11 API support @<:@default=yes@:>@])],
+    [], [enable_x11="yes"])
+
 AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
 AC_PROG_CC
@@ -70,7 +75,6 @@ AC_PATH_PROG([GEN4ASM], [intel-gen4asm])
 
 dnl Check for VA-API
 PKG_CHECK_MODULES(LIBVA_DEPS,	  [libva >= libva_version])
-PKG_CHECK_MODULES(LIBVA_X11_DEPS, [libva-x11])
 
 dnl Check for VA/DRM API
 USE_DRM="$enable_drm"
@@ -94,6 +98,15 @@ VA_DRIVER_INIT_FUNC="__vaDriverInit_${VA_MAJOR_VERSION}_${VA_MINOR_VERSION}"
 AC_DEFINE_UNQUOTED([VA_DRIVER_INIT_FUNC], [$VA_DRIVER_INIT_FUNC],
     [Define driver entry-point])
 
+dnl Check for VA/DRM API
+USE_X11="$enable_x11"
+if test "$USE_X11" = "yes"; then
+    PKG_CHECK_MODULES(LIBVA_X11_DEPS, [libva-x11],
+      [AC_DEFINE([HAVE_VA_X11], [1], [Defined to 1 if VA/X11 API is enabled])],
+      [USE_X11="no"])
+fi
+AM_CONDITIONAL(USE_X11, test "$USE_X11" = "yes")
+
 dnl Check for VA-API drivers path
 AC_MSG_CHECKING([for VA drivers path])
 LIBVA_DRIVERS_PATH=`$PKG_CONFIG libva --variable driverdir`
@@ -122,8 +135,9 @@ AC_OUTPUT([
 ])
 
 dnl Print summary
-BACKENDS="x11"
+BACKENDS=""
 AS_IF([test "$USE_DRM" = "yes"], [BACKENDS="$BACKENDS drm"])
+AS_IF([test "$USE_X11" = "yes"], [BACKENDS="$BACKENDS x11"])
 
 echo
 echo $PACKAGE configuration summary:
diff --git a/src/Makefile.am b/src/Makefile.am
index b8cc501..829e83b 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,7 +43,6 @@ driver_libs = \
 	-lpthread -lm		\
 	$(DRM_LIBS) -ldrm_intel	\
 	$(LIBVA_DEPS_LIBS)	\
-	$(LIBVA_X11_DEPS_LIBS)	\
 	$(NULL)
 
 source_c = \
@@ -110,5 +109,11 @@ i965_drv_video_la_LIBADD	= $(driver_libs)
 i965_drv_video_la_SOURCES	= $(source_c)
 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*
 MAINTAINERCLEANFILES = Makefile.in config.h.in
diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index 90f41e2..141f53f 100755
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -36,7 +36,9 @@
 #include <string.h>
 #include <assert.h>
 
-#include <va/va_dricommon.h>
+#ifdef HAVE_VA_X11
+# include "i965_render_dri.h"
+#endif
 
 #include "intel_driver.h"
 #include "intel_memman.h"
@@ -86,6 +88,10 @@
 #define HAS_ACCELERATED_PUTIMAGE(ctx)   HAS_VPP(ctx)
 static int get_sampling_from_fourcc(unsigned int fourcc);
 
+/* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
+#define IS_VA_X11(ctx) \
+    (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
+
 enum {
     I965_SURFACETYPE_RGBA = 1,
     I965_SURFACETYPE_YUV,
@@ -1991,6 +1997,11 @@ i965_Init(VADriverContextP ctx)
     if (i965_render_init(ctx) == False)
         return VA_STATUS_ERROR_UNKNOWN;
 
+#if HAVE_VA_X11
+    if (IS_VA_X11(ctx) && !i965_render_dri_init(ctx))
+        return VA_STATUS_ERROR_UNKNOWN;
+#endif
+
     _i965InitMutex(&i965->render_mutex);
     _i965InitMutex(&i965->pp_mutex);
 
@@ -3256,119 +3267,25 @@ i965_PutSurface(VADriverContextP ctx,
                 unsigned int number_cliprects, /* number of clip rects in the clip list */
                 unsigned int flags) /* de-interlacing flags */
 {
-#ifdef ANDROID
-        /*dummy function to keep libva API but android does not use this
-         * method to route information to display*/
-        return VA_STATUS_SUCCESS;
-#endif
-    struct i965_driver_data *i965 = i965_driver_data(ctx); 
-    struct dri_state *dri_state = (struct dri_state *)ctx->drm_state;
-    struct i965_render_state *render_state = &i965->render_state;
-    struct dri_drawable *dri_drawable;
-    union dri_buffer *buffer;
-    struct intel_region *dest_region;
-    struct object_surface *obj_surface; 
-    VARectangle src_rect, dst_rect;
-    int ret;
-    uint32_t name;
-    Bool new_region = False;
-    int pp_flag = 0;
-
-#ifdef HAVE_VA_DRM
-    if (ctx->display_type == VA_DISPLAY_DRM)
-        return VA_STATUS_ERROR_UNIMPLEMENTED;
-#endif
-
-    /* Currently don't support DRI1 */
-    if (dri_state->base.type != VA_DRI2)
-        return VA_STATUS_ERROR_UNKNOWN;
-
-    /* Some broken sources such as H.264 conformance case FM2_SVA_C
-     * will get here
-     */
-    obj_surface = SURFACE(surface);
-    if (!obj_surface || !obj_surface->bo)
-        return VA_STATUS_SUCCESS;
+#ifdef HAVE_VA_X11
+    if (IS_VA_X11(ctx)) {
+        VARectangle src_rect, dst_rect;
 
-    _i965LockMutex(&i965->render_mutex);
+        src_rect.x      = srcx;
+        src_rect.y      = srcy;
+        src_rect.width  = srcw;
+        src_rect.height = srch;
 
-    dri_drawable = dri_get_drawable(ctx, (Drawable)draw);
-    assert(dri_drawable);
+        dst_rect.x      = destx;
+        dst_rect.y      = desty;
+        dst_rect.width  = destw;
+        dst_rect.height = desth;
 
-    buffer = dri_get_rendering_buffer(ctx, dri_drawable);
-    assert(buffer);
-    
-    dest_region = render_state->draw_region;
-
-    if (dest_region) {
-        assert(dest_region->bo);
-        dri_bo_flink(dest_region->bo, &name);
-        
-        if (buffer->dri2.name != name) {
-            new_region = True;
-            dri_bo_unreference(dest_region->bo);
-        }
-    } else {
-        dest_region = (struct intel_region *)calloc(1, sizeof(*dest_region));
-        assert(dest_region);
-        render_state->draw_region = dest_region;
-        new_region = True;
+        return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
+                                    cliprects, number_cliprects, flags);
     }
-
-    if (new_region) {
-        dest_region->x = dri_drawable->x;
-        dest_region->y = dri_drawable->y;
-        dest_region->width = dri_drawable->width;
-        dest_region->height = dri_drawable->height;
-        dest_region->cpp = buffer->dri2.cpp;
-        dest_region->pitch = buffer->dri2.pitch;
-
-        dest_region->bo = intel_bo_gem_create_from_name(i965->intel.bufmgr, "rendering buffer", buffer->dri2.name);
-        assert(dest_region->bo);
-
-        ret = dri_bo_get_tiling(dest_region->bo, &(dest_region->tiling), &(dest_region->swizzle));
-        assert(ret == 0);
-    }
-
-    if ((flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC)
-        pp_flag |= I965_PP_FLAG_AVS;
-
-    if (flags & VA_TOP_FIELD)
-        pp_flag |= I965_PP_FLAG_TOP_FIELD;
-    else if (flags & VA_BOTTOM_FIELD)
-        pp_flag |= I965_PP_FLAG_BOTTOM_FIELD;
-
-    src_rect.x      = srcx;
-    src_rect.y      = srcy;
-    src_rect.width  = srcw;
-    src_rect.height = srch;
-
-    dst_rect.x      = destx;
-    dst_rect.y      = desty;
-    dst_rect.width  = destw;
-    dst_rect.height = desth;
-
-    intel_render_put_surface(ctx, surface, &src_rect, &dst_rect, pp_flag);
-
-    if(obj_surface->subpic != VA_INVALID_ID) {
-        intel_render_put_subpicture(ctx, surface, &src_rect, &dst_rect);
-    }
-
-    dri_swap_buffer(ctx, dri_drawable);
-    obj_surface->flags |= SURFACE_DISPLAYED;
-
-    if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
-        dri_bo_unreference(obj_surface->bo);
-        obj_surface->bo = NULL;
-        obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
-
-        if (obj_surface->free_private_data)
-            obj_surface->free_private_data(&obj_surface->private_data);
-    }
-
-    _i965UnlockMutex(&i965->render_mutex);
-
-    return VA_STATUS_SUCCESS;
+#endif
+    return VA_STATUS_ERROR_UNIMPLEMENTED;
 }
 
 VAStatus 
@@ -3382,6 +3299,11 @@ i965_Terminate(VADriverContextP ctx)
     _i965DestroyMutex(&i965->pp_mutex);
     _i965DestroyMutex(&i965->render_mutex);
 
+#if HAVE_VA_X11
+    if (IS_VA_X11(ctx))
+        i965_render_dri_terminate(ctx);
+#endif
+
     if (i965_render_terminate(ctx) == False)
         return VA_STATUS_ERROR_UNKNOWN;
 
diff --git a/src/i965_render_dri.c b/src/i965_render_dri.c
new file mode 100644
index 0000000..f700173
--- /dev/null
+++ b/src/i965_render_dri.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+#include <string.h>
+#include <assert.h>
+#include <va/va_dricommon.h>
+#include "i965_drv_video.h"
+#include "i965_render_dri.h"
+
+bool
+i965_render_dri_init(VADriverContextP ctx)
+{
+    return true;
+}
+
+void
+i965_render_dri_terminate(VADriverContextP ctx)
+{
+}
+
+VAStatus
+i965_put_surface_dri(
+    VADriverContextP    ctx,
+    VASurfaceID         surface,
+    void               *draw,
+    const VARectangle  *src_rect,
+    const VARectangle  *dst_rect,
+    const VARectangle  *cliprects,
+    unsigned int        num_cliprects,
+    unsigned int        flags
+)
+{
+    struct i965_driver_data * const i965 = i965_driver_data(ctx); 
+    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;
+    union dri_buffer *buffer;
+    struct intel_region *dest_region;
+    struct object_surface *obj_surface; 
+    unsigned int pp_flag = 0;
+    bool new_region = false;
+    uint32_t name;
+    int ret;
+
+    /* Currently don't support DRI1 */
+    if (dri_state->base.type != VA_DRI2)
+        return VA_STATUS_ERROR_UNKNOWN;
+
+    /* Some broken sources such as H.264 conformance case FM2_SVA_C
+     * will get here
+     */
+    obj_surface = SURFACE(surface);
+    if (!obj_surface || !obj_surface->bo)
+        return VA_STATUS_SUCCESS;
+
+    _i965LockMutex(&i965->render_mutex);
+
+    dri_drawable = dri_get_drawable(ctx, (Drawable)draw);
+    assert(dri_drawable);
+
+    buffer = dri_get_rendering_buffer(ctx, dri_drawable);
+    assert(buffer);
+    
+    dest_region = render_state->draw_region;
+
+    if (dest_region) {
+        assert(dest_region->bo);
+        dri_bo_flink(dest_region->bo, &name);
+        
+        if (buffer->dri2.name != name) {
+            new_region = True;
+            dri_bo_unreference(dest_region->bo);
+        }
+    } else {
+        dest_region = (struct intel_region *)calloc(1, sizeof(*dest_region));
+        assert(dest_region);
+        render_state->draw_region = dest_region;
+        new_region = True;
+    }
+
+    if (new_region) {
+        dest_region->x = dri_drawable->x;
+        dest_region->y = dri_drawable->y;
+        dest_region->width = dri_drawable->width;
+        dest_region->height = dri_drawable->height;
+        dest_region->cpp = buffer->dri2.cpp;
+        dest_region->pitch = buffer->dri2.pitch;
+
+        dest_region->bo = intel_bo_gem_create_from_name(i965->intel.bufmgr, "rendering buffer", buffer->dri2.name);
+        assert(dest_region->bo);
+
+        ret = dri_bo_get_tiling(dest_region->bo, &(dest_region->tiling), &(dest_region->swizzle));
+        assert(ret == 0);
+    }
+
+    if ((flags & VA_FILTER_SCALING_MASK) == VA_FILTER_SCALING_NL_ANAMORPHIC)
+        pp_flag |= I965_PP_FLAG_AVS;
+
+    if (flags & VA_TOP_FIELD)
+        pp_flag |= I965_PP_FLAG_TOP_FIELD;
+    else if (flags & VA_BOTTOM_FIELD)
+        pp_flag |= I965_PP_FLAG_BOTTOM_FIELD;
+
+    intel_render_put_surface(ctx, surface, src_rect, dst_rect, pp_flag);
+
+    if(obj_surface->subpic != VA_INVALID_ID) {
+        intel_render_put_subpicture(ctx, surface, src_rect, dst_rect);
+    }
+
+    dri_swap_buffer(ctx, dri_drawable);
+    obj_surface->flags |= SURFACE_DISPLAYED;
+
+    if ((obj_surface->flags & SURFACE_ALL_MASK) == SURFACE_DISPLAYED) {
+        dri_bo_unreference(obj_surface->bo);
+        obj_surface->bo = NULL;
+        obj_surface->flags &= ~SURFACE_REF_DIS_MASK;
+
+        if (obj_surface->free_private_data)
+            obj_surface->free_private_data(&obj_surface->private_data);
+    }
+
+    _i965UnlockMutex(&i965->render_mutex);
+
+    return VA_STATUS_SUCCESS;
+}
diff --git a/src/i965_render_dri.h b/src/i965_render_dri.h
new file mode 100644
index 0000000..bea150a
--- /dev/null
+++ b/src/i965_render_dri.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 Intel Corporation. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef I965_RENDER_DRI_H
+#define I965_RENDER_DRI_H
+
+#include <stdbool.h>
+#include <va/va_backend.h>
+
+bool
+i965_render_dri_init(VADriverContextP ctx);
+
+void
+i965_render_dri_terminate(VADriverContextP ctx);
+
+VAStatus
+i965_put_surface_dri(
+    VADriverContextP    ctx,
+    VASurfaceID         surface,
+    void               *draw,
+    const VARectangle  *src_rect,
+    const VARectangle  *dst_rect,
+    const VARectangle  *cliprects,
+    unsigned int        num_cliprects,
+    unsigned int        flags
+);
+
+#endif /* I965_RENDER_DRI_H */
-- 
1.7.9.5



More information about the Libva mailing list