[Libva] [PATCH v2 2/5] API: introduce DRM common utilities and data structures.

Gwenole Beauchesne gb.devel at gmail.com
Fri Jul 6 09:42:03 PDT 2012


From: Benjamin Franzke <benjaminfranzke at googlemail.com>

Add <va/va_drmcommon.h> header for DRM-based drivers to use common
base utilities and data structures. So far, only the DRM state is
shared to that to maintain binary compatibility.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 va/Makefile.am            |    1 +
 va/android/va_android.cpp |   14 ++++++-------
 va/va_drmcommon.h         |   50 +++++++++++++++++++++++++++++++++++++++++++++
 va/x11/dri1_util.c        |   24 +++++++++++-----------
 va/x11/dri2_util.c        |   24 +++++++++++-----------
 va/x11/va_dricommon.h     |   16 +++++++--------
 6 files changed, 90 insertions(+), 39 deletions(-)
 create mode 100644 va/va_drmcommon.h

diff --git a/va/Makefile.am b/va/Makefile.am
index 1d03e9d..47b7ba6 100644
--- a/va/Makefile.am
+++ b/va/Makefile.am
@@ -46,6 +46,7 @@ libva_source_h = \
 	va_compat.h		\
 	va_dec_jpeg.h		\
 	va_dec_vp8.h		\
+	va_drmcommon.h		\
 	va_dummy.h		\
 	va_enc.h		\
 	va_enc_h264.h		\
diff --git a/va/android/va_android.cpp b/va/android/va_android.cpp
index 51f1f51..92f1e60 100644
--- a/va/android/va_android.cpp
+++ b/va/android/va_android.cpp
@@ -96,7 +96,7 @@ static void va_DisplayContextDestroy (
 
     /* close the open-ed DRM fd */
     dri_state = (struct dri_state *)pDisplayContext->pDriverContext->dri_state;
-    close(dri_state->fd);
+    close(dri_state->base.fd);
 
     free(pDisplayContext->pDriverContext->dri_state);
     free(pDisplayContext->pDriverContext);
@@ -126,9 +126,9 @@ static VAStatus va_DisplayContextGetDriverName (
     };
 
     memset(dri_state, 0, sizeof(*dri_state));
-    dri_state->fd = open_device((char *)DEVICE_NAME);
+    dri_state->base.fd = open_device((char *)DEVICE_NAME);
     
-    if (dri_state->fd < 0) {
+    if (dri_state->base.fd < 0) {
         fprintf(stderr,"can't open DRM devices\n");
         return VA_STATUS_ERROR_UNKNOWN;
     }
@@ -138,7 +138,7 @@ static VAStatus va_DisplayContextGetDriverName (
     device_id = devices[0].device_id;
     *driver_name = strdup(devices[0].driver_name);
         
-    dri_state->driConnectedFlag = VA_DUMMY;
+    dri_state->base.auth_type = VA_DUMMY;
 
     return VA_STATUS_SUCCESS;
 }
@@ -166,9 +166,9 @@ static VAStatus va_DisplayContextGetDriverName (
     };
 
     memset(dri_state, 0, sizeof(*dri_state));
-    dri_state->fd = drm_open_any(&vendor_id, &device_id);
+    dri_state->base.fd = drm_open_any(&vendor_id, &device_id);
     
-    if (dri_state->fd < 0) {
+    if (dri_state->base.fd < 0) {
         fprintf(stderr,"can't open DRM devices\n");
         return VA_STATUS_ERROR_UNKNOWN;
     }
@@ -194,7 +194,7 @@ static VAStatus va_DisplayContextGetDriverName (
     printf("DRM device is opened, loading driver %s for device 0x%04x:0x%04x\n",
            driver_name, vendor_id, device_id);
     
-    dri_state->driConnectedFlag = VA_DUMMY;
+    dri_state->base.auth_type = VA_DUMMY;
 
     return VA_STATUS_SUCCESS;
 }
diff --git a/va/va_drmcommon.h b/va/va_drmcommon.h
new file mode 100644
index 0000000..b7435dc
--- /dev/null
+++ b/va/va_drmcommon.h
@@ -0,0 +1,50 @@
+/*
+ * va_drmcommon.h - Common utilities for DRM-based drivers
+ *
+ * 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 INTEL 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 VA_DRM_COMMON_H
+#define VA_DRM_COMMON_H
+
+/** \brief DRM authentication type. */
+enum {
+    /** \brief Disconnected. */
+    VA_DRM_AUTH_NONE    = 0,
+    /** \brief Connected. Authenticated with DRI1 protocol. */
+    VA_DRM_AUTH_DRI1    = 1,
+    /** \brief Connected. Authenticated with DRI2 protocol. */
+    VA_DRM_AUTH_DRI2    = 2,
+    /** \brief Connected. Authenticated with some alternate raw protocol. */
+    VA_DRM_AUTH_CUSTOM  = 3
+};
+
+/** \brief Base DRM state. */
+struct drm_state {
+    /** \brief DRM connection descriptor. */
+    int         fd;
+    /** \brief DRM authentication type. */
+    int         auth_type;
+};
+
+#endif /* VA_DRM_COMMON_H */
diff --git a/va/x11/dri1_util.c b/va/x11/dri1_util.c
index 7e5abf8..0b87e24 100644
--- a/va/x11/dri1_util.c
+++ b/va/x11/dri1_util.c
@@ -65,8 +65,8 @@ dri1Close(VADriverContextP ctx)
     VA_DRIDestroyContext(ctx->native_dpy, ctx->x11_screen, dri_state->hwContextID);
     assert(dri_state->pSAREA != MAP_FAILED);
     drmUnmap(dri_state->pSAREA, SAREA_MAX);
-    assert(dri_state->fd >= 0);
-    drmCloseOnce(dri_state->fd);
+    assert(dri_state->base.fd >= 0);
+    drmCloseOnce(dri_state->base.fd);
     VA_DRICloseConnection(ctx->native_dpy, ctx->x11_screen);
 }
 
@@ -83,9 +83,9 @@ isDRI1Connected(VADriverContextP ctx, char **driver_name)
     drm_magic_t magic;        
 
     *driver_name = NULL;
-    dri_state->fd = -1;
+    dri_state->base.fd = -1;
     dri_state->pSAREA = MAP_FAILED;
-    dri_state->driConnectedFlag = VA_NONE;
+    dri_state->base.auth_type = VA_NONE;
 
     if (!VA_DRIQueryDirectRenderingCapable(ctx->native_dpy, 
                                            ctx->x11_screen, 
@@ -105,20 +105,20 @@ isDRI1Connected(VADriverContextP ctx, char **driver_name)
         goto err_out0;
 
     
-    dri_state->fd = drmOpenOnce(NULL, BusID, &newlyopened);
+    dri_state->base.fd = drmOpenOnce(NULL, BusID, &newlyopened);
     XFree(BusID);
 
-    if (dri_state->fd < 0)
+    if (dri_state->base.fd < 0)
         goto err_out1;
 
 
-    if (drmGetMagic(dri_state->fd, &magic))
+    if (drmGetMagic(dri_state->base.fd, &magic))
         goto err_out1;
 
     if (newlyopened && !VA_DRIAuthConnection(ctx->native_dpy, ctx->x11_screen, magic))
         goto err_out1;
 
-    if (drmMap(dri_state->fd, dri_state->hSAREA, SAREA_MAX, &dri_state->pSAREA))
+    if (drmMap(dri_state->base.fd, dri_state->hSAREA, SAREA_MAX, &dri_state->pSAREA))
         goto err_out1;
 
     if (!VA_DRICreateContext(ctx->native_dpy, ctx->x11_screen,
@@ -126,7 +126,7 @@ isDRI1Connected(VADriverContextP ctx, char **driver_name)
                              &dri_state->hwContextID, &dri_state->hwContext))
         goto err_out1;
 
-    dri_state->driConnectedFlag = VA_DRI1;
+    dri_state->base.auth_type = VA_DRI1;
     dri_state->createDrawable = dri1CreateDrawable;
     dri_state->destroyDrawable = dri1DestroyDrawable;
     dri_state->swapBuffer = dri1SwapBuffer;
@@ -139,8 +139,8 @@ err_out1:
     if (dri_state->pSAREA != MAP_FAILED)
         drmUnmap(dri_state->pSAREA, SAREA_MAX);
 
-    if (dri_state->fd >= 0)
-        drmCloseOnce(dri_state->fd);
+    if (dri_state->base.fd >= 0)
+        drmCloseOnce(dri_state->base.fd);
 
     VA_DRICloseConnection(ctx->native_dpy, ctx->x11_screen);
 
@@ -149,7 +149,7 @@ err_out0:
         XFree(*driver_name);
 
     dri_state->pSAREA = MAP_FAILED;
-    dri_state->fd = -1;
+    dri_state->base.fd = -1;
     *driver_name = NULL;
     
     return False;
diff --git a/va/x11/dri2_util.c b/va/x11/dri2_util.c
index ab3f58a..47f663a 100644
--- a/va/x11/dri2_util.c
+++ b/va/x11/dri2_util.c
@@ -168,8 +168,8 @@ dri2Close(VADriverContextP ctx)
 
     free_drawable_hashtable(ctx);
 
-    if (dri_state->fd >= 0);
-	close(dri_state->fd);
+    if (dri_state->base.fd >= 0);
+	close(dri_state->base.fd);
 }
 
 Bool 
@@ -182,8 +182,8 @@ isDRI2Connected(VADriverContextP ctx, char **driver_name)
     char *device_name = NULL;
     drm_magic_t magic;        
     *driver_name = NULL;
-    dri_state->fd = -1;
-    dri_state->driConnectedFlag = VA_NONE;
+    dri_state->base.fd = -1;
+    dri_state->base.auth_type = VA_NONE;
     if (!VA_DRI2QueryExtension(ctx->native_dpy, &event_base, &error_base))
         goto err_out;
 
@@ -195,20 +195,20 @@ isDRI2Connected(VADriverContextP ctx, char **driver_name)
                      driver_name, &device_name))
         goto err_out;
 
-    dri_state->fd = open(device_name, O_RDWR);
-    assert(dri_state->fd >= 0);
+    dri_state->base.fd = open(device_name, O_RDWR);
+    assert(dri_state->base.fd >= 0);
 
-    if (dri_state->fd < 0)
+    if (dri_state->base.fd < 0)
         goto err_out;
 
-    if (drmGetMagic(dri_state->fd, &magic))
+    if (drmGetMagic(dri_state->base.fd, &magic))
         goto err_out;
 
     if (!VA_DRI2Authenticate(ctx->native_dpy, RootWindow(ctx->native_dpy, ctx->x11_screen),
                           magic))
         goto err_out;
 
-    dri_state->driConnectedFlag = VA_DRI2;
+    dri_state->base.auth_type = VA_DRI2;
     dri_state->createDrawable = dri2CreateDrawable;
     dri_state->destroyDrawable = dri2DestroyDrawable;
     dri_state->swapBuffer = dri2SwapBuffer;
@@ -228,11 +228,11 @@ err_out:
     if (*driver_name)
         Xfree(*driver_name);
 
-    if (dri_state->fd >= 0)
-        close(dri_state->fd);
+    if (dri_state->base.fd >= 0)
+        close(dri_state->base.fd);
 
     *driver_name = NULL;
-    dri_state->fd = -1;
+    dri_state->base.fd = -1;
     
     return False;
 }
diff --git a/va/x11/va_dricommon.h b/va/x11/va_dricommon.h
index ac58735..ca25d2d 100644
--- a/va/x11/va_dricommon.h
+++ b/va/x11/va_dricommon.h
@@ -32,18 +32,19 @@
 #endif
 
 #include <va/va_backend.h>
+#include <va/va_drmcommon.h>
 
 #ifdef ANDROID
 #define XID unsigned int
 #define Bool int
 #endif
 
-enum
-{
-    VA_NONE = 0,
-    VA_DRI1 = 1,
-    VA_DRI2 = 2,
-    VA_DUMMY = 3
+enum {
+    /* Compatibility. Do not use for newly-written code. */
+    VA_NONE     = VA_DRM_AUTH_NONE,
+    VA_DRI1     = VA_DRM_AUTH_DRI1,
+    VA_DRI2     = VA_DRM_AUTH_DRI2,
+    VA_DUMMY    = VA_DRM_AUTH_CUSTOM
 };
 
 union dri_buffer 
@@ -74,8 +75,7 @@ struct dri_drawable
 #define DRAWABLE_HASH_SZ 32
 struct dri_state 
 {
-    int fd;
-    int driConnectedFlag; /* 0: disconnected, 1: DRI, 2: DRI2 */
+    struct drm_state base;
 #ifndef ANDROID
     drm_handle_t hSAREA;
     drm_context_t hwContext;
-- 
1.7.9.5



More information about the Libva mailing list