OSDN Git Service

Move driver context allocation to common code
[android-x86/hardware-intel-common-libva.git] / va / android / va_android.cpp
index ebbfbd3..4a8fe9f 100644 (file)
@@ -26,6 +26,7 @@
 #include "sysdeps.h"
 #include "va.h"
 #include "va_backend.h"
+#include "va_internal.h"
 #include "va_trace.h"
 #include "va_fool.h"
 #include "va_android.h"
@@ -41,7 +42,7 @@
 
 
 #define CHECK_SYMBOL(func) { if (!func) printf("func %s not found\n", #func); return VA_STATUS_ERROR_UNKNOWN; }
-#define DEVICE_NAME "/dev/dri/card0"
+#define DEVICE_NAME "/dev/dri/renderD128"
 
 static int open_device (char *dev_name)
 {
@@ -124,54 +125,46 @@ 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 = (VADisplayContextP)calloc(1, sizeof(*pDisplayContext));
-        pDriverContext  = (VADriverContextP)calloc(1, sizeof(*pDriverContext));
-        drm_state       = (struct drm_state*)calloc(1, sizeof(*drm_state));
-        if (pDisplayContext && pDriverContext && drm_state)
-        {
-            pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;          
-
-            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;
-}
 
-#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
-#define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
+    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;
+}
 
 
 extern "C"  {
-    extern int fool_postp; /* do nothing for vaPutSurface if set */
-    extern int trace_flag; /* trace vaPutSurface parameters */
+    extern int va_fool_postp; /* do nothing for vaPutSurface if set */
+    extern int va_trace_flag; /* trace vaPutSurface parameters */
 
     void va_TracePutSurface (
         VADisplay dpy,
@@ -194,7 +187,7 @@ extern "C"  {
 VAStatus vaPutSurface (
     VADisplay dpy,
     VASurfaceID surface,
-    sp<ISurface> draw, /* Android Surface/Window */
+    sp<ANativeWindow> draw, /* Android Native Window */
     short srcx,
     short srcy,
     unsigned short srcw,
@@ -210,7 +203,7 @@ VAStatus vaPutSurface (
 {
     VADriverContextP ctx;
 
-    if (fool_postp)
+    if (va_fool_postp)
         return VA_STATUS_SUCCESS;
 
     if (draw == NULL)