OSDN Git Service

Move driver context allocation to common code
authorMark Thompson <sw@jkqxz.net>
Mon, 2 Oct 2017 22:49:33 +0000 (23:49 +0100)
committerXiang, Haihao <haihao.xiang@intel.com>
Wed, 22 Nov 2017 05:38:52 +0000 (21:38 -0800)
This will be required to set common options on a newly-created driver
context.

Signed-off-by: Mark Thompson <sw@jkqxz.net>
va/android/va_android.cpp
va/drm/va_drm.c
va/va.c
va/va_internal.h
va/wayland/va_wayland.c
va/x11/va_x11.c

index ae96236..4a8fe9f 100644 (file)
@@ -125,43 +125,40 @@ VADisplay vaGetDisplay (
     void *native_dpy /* implementation specific */
 )
 {
-    VADisplay dpy = NULL;
     VADisplayContextP pDisplayContext;
+    VADriverContextP  pDriverContext;
+    struct drm_state *drm_state;
 
     if (!native_dpy)
         return NULL;
 
-    if (!dpy)
-    {
-        /* create new entry */
-        VADriverContextP pDriverContext = 0;
-        struct drm_state *drm_state = 0;
-        pDisplayContext = va_newDisplayContext();
-        pDriverContext  = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
-        drm_state       = (struct drm_state*)calloc(1, sizeof(*drm_state));
-        if (pDisplayContext && pDriverContext && drm_state)
-        {
-            pDriverContext->native_dpy       = (void *)native_dpy;
-            pDriverContext->display_type     = VA_DISPLAY_ANDROID;
-            pDisplayContext->pDriverContext  = pDriverContext;
-            pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
-            pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
-            pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
-            pDriverContext->drm_state       = drm_state;
-            dpy                              = (VADisplay)pDisplayContext;
-        }
-        else
-        {
-            if (pDisplayContext)
-                free(pDisplayContext);
-            if (pDriverContext)
-                free(pDriverContext);
-            if (drm_state)
-                free(drm_state);
-        }
+    pDisplayContext = va_newDisplayContext();
+    if (!pDisplayContext)
+        return NULL;
+
+    pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
+    pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
+    pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
+
+    pDriverContext = va_newDriverContext(pDisplayContext);
+    if (!pDriverContext) {
+        free(pDisplayContext);
+        return NULL;
     }
-  
-    return dpy;
+
+    pDriverContext->native_dpy   = (void *)native_dpy;
+    pDriverContext->display_type = VA_DISPLAY_ANDROID
+
+    drm_state = calloc(1, sizeof(*drm_state));
+    if (!drm_state) {
+        free(pDisplayContext);
+        free(pDriverContext);
+        return NULL;
+    }
+
+    pDriverContext->drm_state = drm_state;
+
+    return (VADisplay)pDisplayContext;
 }
 
 
index bccd108..b406e68 100644 (file)
@@ -102,22 +102,23 @@ vaGetDisplayDRM(int fd)
         goto error;
     drm_state->fd = fd;
 
-    pDriverContext = calloc(1, sizeof(*pDriverContext));
-    if (!pDriverContext)
-        goto error;
-    pDriverContext->native_dpy   = NULL;
-    pDriverContext->display_type = is_render_nodes ?
-        VA_DISPLAY_DRM_RENDERNODES : VA_DISPLAY_DRM;
-    pDriverContext->drm_state    = drm_state;
-
     pDisplayContext = va_newDisplayContext();
     if (!pDisplayContext)
         goto error;
 
-    pDisplayContext->pDriverContext  = pDriverContext;
     pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
     pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
     pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
+
+    pDriverContext = va_newDriverContext(pDisplayContext);
+    if (!pDriverContext)
+        goto error;
+
+    pDriverContext->native_dpy   = NULL;
+    pDriverContext->display_type = is_render_nodes ?
+        VA_DISPLAY_DRM_RENDERNODES : VA_DISPLAY_DRM;
+    pDriverContext->drm_state    = drm_state;
+
     return pDisplayContext;
 
 error:
diff --git a/va/va.c b/va/va.c
index 819bef1..257b241 100644 (file)
--- a/va/va.c
+++ b/va/va.c
@@ -275,6 +275,17 @@ VADisplayContextP va_newDisplayContext(void)
     return dctx;
 }
 
+VADriverContextP va_newDriverContext(VADisplayContextP dctx)
+{
+    VADriverContextP ctx = calloc(1, sizeof(*ctx));
+    if (!ctx)
+        return NULL;
+
+    dctx->pDriverContext = ctx;
+
+    return ctx;
+}
+
 static bool va_checkVtable(VADisplay dpy, void *ptr, char *function)
 {
     if (!ptr) {
index 7b8da55..cc909c1 100644 (file)
@@ -39,6 +39,8 @@ int  va_parseConfig(char *env, char *env_value);
 
 VADisplayContextP va_newDisplayContext(void);
 
+VADriverContextP va_newDriverContext(VADisplayContextP dctx);
+
 #ifdef __cplusplus
 }
 #endif
index f7ddfe8..86ae6ac 100644 (file)
@@ -129,10 +129,9 @@ vaGetDisplayWl(struct wl_display *display)
     pDisplayContext->vaDestroy          = va_DisplayContextDestroy;
     pDisplayContext->vaGetDriverName    = va_DisplayContextGetDriverName;
 
-    pDriverContext = calloc(1, sizeof(*pDriverContext));
+    pDriverContext = va_newDriverContext(pDisplayContext);
     if (!pDriverContext)
         goto error;
-    pDisplayContext->pDriverContext     = pDriverContext;
 
     pDriverContext->native_dpy          = display;
     pDriverContext->display_type        = VA_DISPLAY_WAYLAND;
index ed06826..c40c8c4 100644 (file)
@@ -153,45 +153,41 @@ VADisplay vaGetDisplay (
     Display *native_dpy /* implementation specific */
 )
 {
-  VADisplay dpy = NULL;
-  VADisplayContextP pDisplayContext;
-
-  if (!native_dpy)
-      return NULL;
-
-  if (!dpy)
-  {
-      /* create new entry */
-      VADriverContextP pDriverContext;
-      struct dri_state *dri_state;
-      pDisplayContext = va_newDisplayContext();
-      pDriverContext  = calloc(1, sizeof(*pDriverContext));
-      dri_state       = calloc(1, sizeof(*dri_state));
-      if (pDisplayContext && pDriverContext && dri_state)
-      {
-         pDriverContext->native_dpy       = (void *)native_dpy;
-         pDriverContext->x11_screen       = XDefaultScreen(native_dpy);
-          pDriverContext->display_type     = VA_DISPLAY_X11;
-         pDisplayContext->pDriverContext  = pDriverContext;
-         pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
-         pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
-         pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
-          pDisplayContext->opaque          = NULL;
-         pDriverContext->drm_state        = dri_state;
-         dpy                              = (VADisplay)pDisplayContext;
-      }
-      else
-      {
-         if (pDisplayContext)
-             free(pDisplayContext);
-         if (pDriverContext)
-             free(pDriverContext);
-          if (dri_state)
-              free(dri_state);
-      }
-  }
-  
-  return dpy;
+    VADisplayContextP pDisplayContext;
+    VADriverContextP  pDriverContext;
+    struct dri_state *dri_state;
+
+    if (!native_dpy)
+        return NULL;
+
+    pDisplayContext = va_newDisplayContext();
+    if (!pDisplayContext)
+        return NULL;
+
+    pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
+    pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
+    pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
+
+    pDriverContext = va_newDriverContext(pDisplayContext);
+    if (!pDriverContext) {
+        free(pDisplayContext);
+        return NULL;
+    }
+
+    pDriverContext->native_dpy   = (void *)native_dpy;
+    pDriverContext->x11_screen   = XDefaultScreen(native_dpy);
+    pDriverContext->display_type = VA_DISPLAY_X11;
+
+    dri_state = calloc(1, sizeof(*dri_state));
+    if (!dri_state) {
+        free(pDisplayContext);
+        free(pDriverContext);
+        return NULL;
+    }
+
+    pDriverContext->drm_state = dri_state;
+
+    return (VADisplay)pDisplayContext;
 }