OSDN Git Service

Merge branch 'v1.8-branch' into master
authorXiang, Haihao <haihao.xiang@intel.com>
Wed, 16 Aug 2017 05:06:25 +0000 (13:06 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Wed, 16 Aug 2017 05:06:55 +0000 (13:06 +0800)
.gitignore
configure.ac
pkgconfig/libva.pc.in
va/glx/va_glx_impl.c
va/va.h
va/va_trace.c [changed mode: 0644->0755]
va/wayland/Makefile.am
va/wayland/va_wayland_drm.c
va/x11/Makefile.am

index 4906534..1641e78 100644 (file)
@@ -30,3 +30,5 @@ ltmain.sh
 missing
 stamp-h1
 /va/va_version.h
+/va/wayland/wayland-drm-client-protocol-export.c
+/va/wayland/wayland-drm-client-protocol.*
index 635a50d..bd74df8 100644 (file)
@@ -42,8 +42,8 @@ m4_define([va_api_version],
 # - reset micro version to zero when VA-API major or minor version is changed
 m4_define([libva_major_version], [m4_eval(va_api_major_version + 1)])
 m4_define([libva_minor_version], [m4_eval(va_api_minor_version - 32)])
-m4_define([libva_micro_version], [3])
-m4_define([libva_pre_version],   [0])
+m4_define([libva_micro_version], [4])
+m4_define([libva_pre_version],   [1])
 
 m4_define([libva_version],
           [libva_major_version.libva_minor_version.libva_micro_version])
@@ -78,7 +78,8 @@ m4_define([libva_lt_age],
 m4_define([libdrm_version], [2.4])
 
 # Wayland minimum version number
-m4_define([wayland_api_version], [1.0.0])
+# 1.11.0 for wl_proxy_create_wrapper
+m4_define([wayland_api_version], [1.11.0])
 
 AC_PREREQ(2.57)
 AC_INIT([libva],
@@ -135,23 +136,23 @@ AC_ARG_ENABLE(drm,
 
 AC_ARG_ENABLE(x11,
     [AC_HELP_STRING([--enable-x11],
-                    [build with VA/X11 API support @<:@default=yes@:>@])],
-    [], [enable_x11="yes"])
+                    [build with VA/X11 API support @<:@default=auto@:>@])],
+    [], [enable_x11="auto"])
 
 AC_ARG_ENABLE(glx,
     [AC_HELP_STRING([--enable-glx],
-                    [build with VA/GLX API support @<:@default=yes@:>@])],
-    [], [enable_glx="yes"])
+                    [build with VA/GLX API support @<:@default=auto@:>@])],
+    [], [enable_glx="auto"])
 
 AC_ARG_ENABLE(egl,
     [AC_HELP_STRING([--enable-egl],
-                    [build with VA/EGL API support @<:@default=yes@:>@])],
-    [], [enable_egl="yes"])
+                    [build with VA/EGL API support @<:@default=auto@:>@])],
+    [], [enable_egl="auto"])
 
 AC_ARG_ENABLE([wayland],
     [AC_HELP_STRING([--enable-wayland],
-                    [build with VA/Wayland API support @<:@default=yes@:>@])],
-    [], [enable_wayland="yes"])
+                    [build with VA/Wayland API support @<:@default=auto@:>@])],
+    [], [enable_wayland="auto"])
 
 AC_ARG_ENABLE([va-messaging],
     [AC_HELP_STRING([--enable-va-messaging],
@@ -171,6 +172,7 @@ AC_PROG_LIBTOOL
 AC_PROG_CC
 AC_PROG_CXX
 AM_PROG_CC_C_O
+AC_PROG_SED
 PKG_PROG_PKG_CONFIG
 
 AC_HEADER_STDC
@@ -226,11 +228,13 @@ AM_CONDITIONAL(USE_DRM, test "$USE_DRM" = "yes")
 
 # Check for X11
 USE_X11="no"
-if test "$enable_x11" = "yes"; then
-    USE_X11="yes"
-    PKG_CHECK_MODULES([X11],    [x11],    [:], [USE_X11="no"])
-    PKG_CHECK_MODULES([XEXT],   [xext],   [:], [USE_X11="no"])
-    PKG_CHECK_MODULES([XFIXES], [xfixes], [:], [USE_X11="no"])
+if test "x$enable_x11" != "xno"; then
+    PKG_CHECK_MODULES([X11],    [x11 xext xfixes],    [USE_X11="yes"], [:])
+
+    if test "x$USE_X11" = "xno" -a "x$enable_x11" = "xyes"; then
+       AC_MSG_ERROR([VA/X11 explicitly enabled, however $X11_PKG_ERRORS])
+    fi
+
     if test "$USE_X11" = "yes"; then
         AC_DEFINE([HAVE_VA_X11], [1], [Defined to 1 if VA/X11 API is built])
     fi
@@ -239,7 +243,12 @@ AM_CONDITIONAL(USE_X11, test "$USE_X11" = "yes")
 
 # Check for GLX
 USE_GLX="no"
-if test "$USE_X11:$enable_glx" = "yes:yes"; then
+
+if test "$USE_X11:$enable_glx" = "no:yes"; then
+   AC_MSG_ERROR([VA/GLX explicitly enabled, but VA/X11 isn't built])
+fi
+
+if test "$USE_X11:$enable_glx" != "yes:no"; then
     PKG_CHECK_MODULES([GLX], [gl x11], [USE_GLX="yes"], [:])
     saved_CPPFLAGS="$CPPFLAGS"
     saved_LIBS="$LIBS"
@@ -249,6 +258,11 @@ if test "$USE_X11:$enable_glx" = "yes:yes"; then
     AC_CHECK_LIB([GL], [glXCreateContext], [:] [USE_GLX="no"])
     CPPFLAGS="$saved_CPPFLAGS"
     LIBS="$saved_LIBS"
+
+    if test "x$USE_GLX" = "xno" -a "x$enable_glx" = "xyes"; then
+       AC_MSG_ERROR([VA/GLX explicitly enabled, but libGL couldn't be found])
+    fi
+
     if test "$USE_GLX" = "yes"; then
         AC_DEFINE([HAVE_VA_GLX], [1], [Defined to 1 if VA/GLX API is built])
     fi
@@ -257,7 +271,7 @@ AM_CONDITIONAL(USE_GLX, test "$USE_GLX" = "yes")
 
 # Check for EGL
 USE_EGL="no"
-if test "$enable_egl" = "yes"; then
+if test "x$enable_egl" != "xno"; then
     PKG_CHECK_MODULES([EGL], [egl], [USE_EGL="yes"], [:])
     saved_CPPFLAGS="$CPPFLAGS"
     saved_LIBS="$LIBS"
@@ -267,6 +281,11 @@ if test "$enable_egl" = "yes"; then
     AC_CHECK_LIB([EGL], [eglGetDisplay], [:], [USE_EGL="no"])
     CPPFLAGS="$saved_CPPFLAGS"
     LIBS="$saved_LIBS"
+
+    if test "x$USE_EGL" = "xno" -a "x$enable_egl" = "xyes"; then
+       AC_MSG_ERROR([VA/EGL explicitly enabled, but libEGL couldn't be found])
+    fi
+
     if test "$USE_EGL" = "yes"; then
         AC_DEFINE([HAVE_VA_EGL], [1], [Defined to 1 if VA/EGL API is built])
     fi
@@ -278,9 +297,14 @@ WAYLAND_API_VERSION=wayland_api_version
 AC_SUBST(WAYLAND_API_VERSION)
 
 USE_WAYLAND="no"
-if test "$enable_wayland" = "yes"; then
+if test "x$enable_wayland" != "xno"; then
     PKG_CHECK_MODULES([WAYLAND], [wayland-client >= wayland_api_version],
         [USE_WAYLAND="yes"], [:])
+
+    if test "x$USE_WAYLAND" = "xno" -a "x$enable_wayland" = "xyes"; then
+        AC_MSG_ERROR([wayland explicitly enabled, however $WAYLAND_PKG_ERRORS])
+    fi
+
     if test "$USE_WAYLAND" = "yes"; then
 
         WAYLAND_PREFIX=`$PKG_CONFIG --variable=prefix wayland-client`
index 8b03f98..4ede38c 100644 (file)
@@ -3,6 +3,7 @@ exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
 driverdir=@LIBVA_DRIVERS_PATH@
+libva_version=@LIBVA_VERSION@
 
 Name: libva
 Description: Userspace Video Acceleration (VA) core interface
index 621f6c1..23ea270 100644 (file)
@@ -205,7 +205,7 @@ static int check_extension3(const char *name)
     for(i = 0; i < nbExtensions; i++)
     {
         const GLubyte *strExtension = glGetStringi(GL_EXTENSIONS, i);
-        if(strcmp(strExtension, (const GLubyte *)name) == 0)
+        if(strcmp((const char *) strExtension, name) == 0)
             return 1;
     }
 
diff --git a/va/va.h b/va/va.h
index e1382d8..a0eb02f 100644 (file)
--- a/va/va.h
+++ b/va/va.h
@@ -589,7 +589,7 @@ typedef struct _VAConfigAttrib {
 #define VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS           0x00000000
 /** \brief Driver supports a power-of-two number of rows per slice. */
 #define VA_ENC_SLICE_STRUCTURE_POWER_OF_TWO_ROWS        0x00000001
-/** \brief Driver supports an arbitrary number of rows per slice. */
+/** \brief Driver supports an arbitrary number of macroblocks per slice. */
 #define VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS    0x00000002
 /**@}*/
 
old mode 100644 (file)
new mode 100755 (executable)
index ab76377..9162929
@@ -340,7 +340,7 @@ static VAContextID get_ctx_by_buf(
     struct trace_buf_manager *pbuf_mgr = &pva_trace->buf_manager;
     struct trace_buf_info *pbuf_info = pbuf_mgr->pbuf_info[0];
     VAContextID context = VA_INVALID_ID;
-    int i = 0, idx = 0, valid = 0;
+    int i = 0, idx = 0;
 
     LOCK_RESOURCE(pva_trace);
 
@@ -734,8 +734,6 @@ static void refresh_log_file(
 void va_TraceInit(VADisplay dpy)
 {
     char env_value[1024];
-    unsigned short suffix = 0xffff & ((unsigned int)time(NULL));
-    FILE *tmp;
     struct va_trace *pva_trace = calloc(sizeof(struct va_trace), 1);
     struct trace_context *trace_ctx = calloc(sizeof(struct trace_context), 1);
 
@@ -823,7 +821,7 @@ void va_TraceInit(VADisplay dpy)
 void va_TraceEnd(VADisplay dpy)
 {
     struct va_trace *pva_trace = NULL;
-    int i = 0, j = 0;
+    int i = 0;
 
     pva_trace = (struct va_trace *)(((VADisplayContextP)dpy)->vatrace);
     if(!pva_trace)
@@ -3206,6 +3204,14 @@ static void va_TraceVAEncMiscParameterBuffer(
         va_TraceMsg(trace_ctx, "\tmax_frame_size = %d\n", p->max_frame_size);
         break;
     }
+    case VAEncMiscParameterTypeQualityLevel:
+    {
+        VAEncMiscParameterBufferQualityLevel *p = (VAEncMiscParameterBufferQualityLevel *)tmp->data;
+
+        va_TraceMsg(trace_ctx, "\t--VAEncMiscParameterBufferQualityLevel\n");
+        va_TraceMsg(trace_ctx, "\tquality_level = %d\n", p->quality_level);
+        break;
+    }
     default:
         va_TraceMsg(trace_ctx, "Unknown VAEncMiscParameterBuffer(type = %d):\n", tmp->type);
         va_TraceVABuffers(dpy, context, buffer, type, size, num_elements, data);
@@ -3555,7 +3561,6 @@ static void va_TraceVAEncSequenceParameterBufferVP9(
 {
     VAEncSequenceParameterBufferVP9 *p = (VAEncSequenceParameterBufferVP9 *)data;
     DPY2TRACECTX(dpy, context, VA_INVALID_ID);
-    int i;
 
     va_TraceMsg(trace_ctx, "\t--VAEncSequenceParameterBufferVP9\n");
 
index 4ab8d07..1ac8d48 100644 (file)
@@ -46,6 +46,14 @@ source_h_priv = \
        va_wayland_private.h    \
        $(NULL)
 
+protocol_source_export_c = \
+       wayland-drm-client-protocol-export.c    \
+       $(NULL)
+
+protocol_source_c = \
+       wayland-drm-client-protocol.c   \
+       $(NULL)
+
 protocol_source_h = \
        wayland-drm-client-protocol.h   \
        $(NULL)
@@ -53,19 +61,24 @@ protocol_source_h = \
 noinst_LTLIBRARIES             = libva_wayland.la
 libva_waylandincludedir                = ${includedir}/va
 libva_waylandinclude_HEADERS   = $(source_h)
-libva_wayland_la_SOURCES       = $(source_c)
+libva_wayland_la_SOURCES       = $(source_c) $(protocol_source_c)
 noinst_HEADERS                 = $(source_h_priv)
 
 # Wayland protocol
 va_wayland_drm.c: $(protocol_source_h)
 %-client-protocol.h : %.xml
        $(AM_V_GEN)$(WAYLAND_SCANNER) client-header < $< > $@
-
+%-client-protocol-export.c : %.xml
+       $(AM_V_GEN)$(WAYLAND_SCANNER) code < $< > $@
+%-client-protocol.c: %-client-protocol-export.c
+       $(AM_V_GEN)$(SED) -e '1i#include "sysdeps.h"' \
+                          -e 's@WL_EXPORT@DLL_HIDDEN@g' < $< > $@
+       
 EXTRA_DIST = \
        wayland-drm.xml         \
        $(NULL)
 
-BUILT_SOURCES = $(protocol_source_h)
+BUILT_SOURCES = $(protocol_source_h) $(protocol_source_c) $(protocol_source_export_c)
 CLEANFILES = $(BUILT_SOURCES)
 
 # Extra clean files so that maintainer-clean removes *everything*
index 2ff19f5..1c9c09a 100644 (file)
 #include "va_wayland_private.h"
 #include "wayland-drm-client-protocol.h"
 
-/* XXX: Wayland/DRM support currently lives in Mesa libEGL.so.* library */
-/* First try the soname of a glvnd enabled mesa build */
-#define LIBWAYLAND_DRM_NAME "libEGL_mesa.so.0"
-/* Then fallback to plain libEGL.so.1 (which might not be mesa) */
-#define LIBWAYLAND_DRM_NAME_FALLBACK "libEGL.so.1"
-
 typedef struct va_wayland_drm_context {
     struct va_wayland_context   base;
-    void                       *handle;
+    struct wl_event_queue      *queue;
     struct wl_drm              *drm;
     struct wl_registry         *registry;
-    void                       *drm_interface;
     unsigned int                is_authenticated        : 1;
 } VADisplayContextWaylandDRM;
 
@@ -145,9 +138,14 @@ va_wayland_drm_destroy(VADisplayContextP pDisplayContext)
     }
     wl_drm_ctx->is_authenticated = 0;
 
-    if (wl_drm_ctx->handle) {
-        dlclose(wl_drm_ctx->handle);
-        wl_drm_ctx->handle = NULL;
+    if (wl_drm_ctx->registry) {
+        wl_registry_destroy(wl_drm_ctx->registry);
+        wl_drm_ctx->registry = NULL;
+    }
+
+    if (wl_drm_ctx->queue) {
+        wl_event_queue_destroy(wl_drm_ctx->queue);
+        wl_drm_ctx->queue = NULL;
     }
 
     if (drm_state) {
@@ -172,8 +170,12 @@ registry_handle_global(
     struct va_wayland_drm_context *wl_drm_ctx = data;
 
     if (strcmp(interface, "wl_drm") == 0) {
+        /* bind to at most version 2, but also support version 1 if
+         * compositor does not have v2
+         */
         wl_drm_ctx->drm =
-            wl_registry_bind(wl_drm_ctx->registry, id, wl_drm_ctx->drm_interface, 2);
+            wl_registry_bind(wl_drm_ctx->registry, id, &wl_drm_interface,
+                             (version < 2) ? version : 2);
     }
 }
 
@@ -182,6 +184,19 @@ static const struct wl_registry_listener registry_listener = {
     NULL,
 };
 
+static bool
+wayland_roundtrip_queue(struct wl_display *display,
+                         struct wl_event_queue *queue)
+{
+    if (wl_display_roundtrip_queue(display, queue) < 0) {
+        int err = wl_display_get_error(display);
+        va_wayland_error("Wayland roundtrip error: %s (errno %d)", strerror(err), err);
+        return false;
+    } else {
+        return true;
+    }
+}
+
 bool
 va_wayland_drm_create(VADisplayContextP pDisplayContext)
 {
@@ -189,56 +204,81 @@ va_wayland_drm_create(VADisplayContextP pDisplayContext)
     struct va_wayland_drm_context *wl_drm_ctx;
     struct drm_state *drm_state;
     struct VADriverVTableWayland *vtable = ctx->vtable_wayland;
+    struct wl_display *wrapped_display;
 
     wl_drm_ctx = malloc(sizeof(*wl_drm_ctx));
-    if (!wl_drm_ctx)
+    if (!wl_drm_ctx) {
+        va_wayland_error("could not allocate wl_drm_ctx");
         return false;
+    }
     wl_drm_ctx->base.destroy            = va_wayland_drm_destroy;
-    wl_drm_ctx->handle                  = NULL;
+    wl_drm_ctx->queue                   = NULL;
     wl_drm_ctx->drm                     = NULL;
-    wl_drm_ctx->drm_interface           = NULL;
+    wl_drm_ctx->registry                = NULL;
     wl_drm_ctx->is_authenticated        = 0;
     pDisplayContext->opaque             = wl_drm_ctx;
     pDisplayContext->vaGetDriverName    = va_DisplayContextGetDriverName;
 
     drm_state = calloc(1, sizeof(struct drm_state));
-    if (!drm_state)
+    if (!drm_state) {
+        va_wayland_error("could not allocate drm_state");
         return false;
+    }
     drm_state->fd        = -1;
     drm_state->auth_type = 0;
     ctx->drm_state       = drm_state;
     vtable->has_prime_sharing = 0;
 
-    wl_drm_ctx->handle = dlopen(LIBWAYLAND_DRM_NAME, RTLD_LAZY|RTLD_LOCAL);
-    if (!wl_drm_ctx->handle) {
-        wl_drm_ctx->handle = dlopen(LIBWAYLAND_DRM_NAME_FALLBACK, RTLD_LAZY|RTLD_LOCAL);
-        if (!wl_drm_ctx->handle)
-            return false;
+    /* Use wrapped wl_display with private event queue to prevent
+     * thread safety issues with applications that e.g. run an event pump
+     * parallel to libva initialization.
+     * Using the default queue, events might get lost and crashes occur
+     * because wl_display_roundtrip is not thread-safe with respect to the
+     * same queue.
+     */
+    wl_drm_ctx->queue = wl_display_create_queue(ctx->native_dpy);
+    if (!wl_drm_ctx->queue) {
+        va_wayland_error("could not create Wayland event queue");
+        return false;
     }
 
-    wl_drm_ctx->drm_interface =
-        dlsym(wl_drm_ctx->handle, "wl_drm_interface");
-    if (!wl_drm_ctx->drm_interface)
+    wrapped_display = wl_proxy_create_wrapper(ctx->native_dpy);
+    if (!wrapped_display) {
+        va_wayland_error("could not create Wayland proxy wrapper");
         return false;
+    }
 
-    wl_drm_ctx->registry = wl_display_get_registry(ctx->native_dpy);
+    /* All created objects will inherit this queue */
+    wl_proxy_set_queue((struct wl_proxy *) wrapped_display, wl_drm_ctx->queue);
+    wl_drm_ctx->registry = wl_display_get_registry(wrapped_display);
+    wl_proxy_wrapper_destroy(wrapped_display);
     wl_registry_add_listener(wl_drm_ctx->registry, &registry_listener, wl_drm_ctx);
-    wl_display_roundtrip(ctx->native_dpy);
+    if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue))
+        return false;
 
     /* registry_handle_global should have been called by the
-     * wl_display_roundtrip above
+     * wl_display_roundtrip_queue above
      */
 
+    /* Do not print an error, the compositor might just not support wl_drm */
     if (!wl_drm_ctx->drm)
         return false;
 
     wl_drm_add_listener(wl_drm_ctx->drm, &drm_listener, pDisplayContext);
-    wl_display_roundtrip(ctx->native_dpy);
-    if (drm_state->fd < 0)
+    if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue))
+        return false;
+    if (drm_state->fd < 0) {
+        va_wayland_error("did not get DRM device");
+        return false;
+    }
+
+    if (!wayland_roundtrip_queue(ctx->native_dpy, wl_drm_ctx->queue))
         return false;
 
-    wl_display_roundtrip(ctx->native_dpy);
-    if (!wl_drm_ctx->is_authenticated)
+    if (!wl_drm_ctx->is_authenticated) {
+        va_wayland_error("Wayland compositor did not respond to DRM authentication");
         return false;
+    }
+
     return true;
 }
index 0853016..ed4f66a 100644 (file)
@@ -25,8 +25,6 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)         \
        -I$(top_srcdir)/va      \
        $(X11_CFLAGS)           \
-       $(XEXT_CFLAGS)          \
-       $(XFIXES_CFLAGS)        \
        $(DRM_CFLAGS)           \
        $(NULL)