vl: initial implementation of vlVaQueryImageFormats(), vlVaCreateImage(), vlVaQuerySu...
authorThomas Balling Sørensen <tball@tball-laptop.(none)>
Thu, 28 Oct 2010 20:46:28 +0000 (22:46 +0200)
committerThomas Balling Sørensen <tball@tball-laptop.(none)>
Thu, 28 Oct 2010 20:46:28 +0000 (22:46 +0200)
src/gallium/state_trackers/va/ftab.c
src/gallium/state_trackers/va/htab.c
src/gallium/state_trackers/va/va_config.c
src/gallium/state_trackers/va/va_context.c
src/gallium/state_trackers/va/va_display.c
src/gallium/state_trackers/va/va_image.c
src/gallium/state_trackers/va/va_picture.c
src/gallium/state_trackers/va/va_private.h
src/gallium/state_trackers/va/va_subpicture.c
src/gallium/state_trackers/va/va_surface.c

index a567eee9dd1b60582cb1605086b9106faa88e72b..999287e7a7ef5e5264dfd769d1f01b510c92801e 100644 (file)
@@ -30,6 +30,8 @@
 #include <va/va_backend.h>
 #include "va_private.h"
 
+struct VADriverVTable vlVaGetVtable();
+
 static struct VADriverVTable vtable =
 {
        &vlVaTerminate, /* VAStatus (*vaTerminate) ( VADriverContextP ctx ); */
@@ -125,7 +127,7 @@ static struct VADriverVTable vtable =
                 unsigned int *buffer_name,
                 void **buffer); */
        &vlVaUnlockSurface, /* VAStatus (*vaUnlockSurface) (VADriverContextP ctx,VASurfaceID surface); */
-       0x44 /* struct VADriverVTableGLX *glx; "Optional" */
+       NULL /* struct VADriverVTableGLX *glx; "Optional" */
 };
 
 struct VADriverVTable vlVaGetVtable()
index 069c793092723aeae0f443d139b6e7772f977748..2187507c6a4c613bc285318ee44e524fd24030c5 100644 (file)
 #include <os/os_thread.h>
 #include "va_private.h"
 
-#define VL_HANDLES
-
-typedef uint32_t vlHandle;
+boolean vlCreateHTAB(void);
+void vlDestroyHTAB(void);
+vlHandle vlAddDataHTAB(void *data);
+void* vlGetDataHTAB(vlHandle handle);
 
 #ifdef VL_HANDLES
 static struct handle_table *htab = NULL;
index 591d113a916526a463364b3661e65201eb73b938..1589abf7cfa2b1e2798df4ea638031f29633b57e 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <va/va.h>
 #include <va/va_backend.h>
+#include <util/u_debug.h>
 #include "va_private.h"
 
 VAStatus vlVaQueryConfigProfiles(       VADriverContextP ctx,
@@ -36,19 +37,48 @@ VAStatus vlVaQueryConfigProfiles(       VADriverContextP ctx,
        if (!ctx)
                return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-       return VA_STATUS_ERROR_UNIMPLEMENTED;
+       int i = 0;
+
+    profile_list[i++] = VAProfileMPEG2Simple;
+       *num_profiles = i;
+
+       return VA_STATUS_SUCCESS;
 }
 
 
 VAStatus vlVaQueryConfigEntrypoints(       VADriverContextP ctx,
                                       VAProfile profile,
-                                      VAEntrypoint *entypoint_list,
+                                      VAEntrypoint *entrypoint_list,
                                       int *num_entrypoints)
 {
        if (!ctx)
                return VA_STATUS_ERROR_INVALID_CONTEXT;
-
-       return VA_STATUS_ERROR_UNIMPLEMENTED;
+               
+       VAStatus vaStatus = VA_STATUS_SUCCESS;
+
+    switch (profile) {
+    case VAProfileMPEG2Simple:
+    case VAProfileMPEG2Main:
+               VA_INFO("Using profile %08x\n",profile);
+        *num_entrypoints = 1;
+        entrypoint_list[0] = VAEntrypointMoComp;
+        break;
+
+    case VAProfileH264Baseline:
+    case VAProfileH264Main:
+    case VAProfileH264High:
+        vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
+        *num_entrypoints = 0;
+        break;
+
+    default:
+               VA_ERROR("Unsupported profile %08x\n",profile);
+        vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
+        *num_entrypoints = 0;
+        break;
+    }
+
+    return vaStatus;
 }
 
 
index 1e3ab9cb22e964c34d7228033fc32d3bd159665a..cdb20cc0eb2dbb0f5580963fa0d9e64ff929f8b3 100644 (file)
 
 #include <pipe/p_compiler.h>
 #include <pipe/p_video_context.h>
+#include <pipe/p_screen.h>
+#include <vl_winsys.h>
 #include <util/u_debug.h>
+#include <util/u_memory.h>
 #include <va/va.h>
 #include <va/va_backend.h>
 #include "va_private.h"
 PUBLIC
 VAStatus __vaDriverInit_0_31 (VADriverContextP ctx)
 {
+       vlVaDriverContextPriv *driver_context = NULL;
+       
        if (!ctx)
                return VA_STATUS_ERROR_INVALID_CONTEXT;
-
+               
+               
+       /* Create private driver context */
+       driver_context = CALLOC(1,sizeof(vlVaDriverContextPriv));
+       if (!driver_context)
+               return VA_STATUS_ERROR_ALLOCATION_FAILED;
+               
+    driver_context->vscreen = vl_screen_create(ctx->native_dpy, ctx->x11_screen);
+       if (!driver_context->vscreen)
+       {
+               FREE(driver_context);
+               return VA_STATUS_ERROR_ALLOCATION_FAILED;
+       }
+               
        ctx->str_vendor = "mesa gallium vaapi";
        ctx->vtable = vlVaGetVtable();
        ctx->max_attributes = 1;
        ctx->max_display_attributes = 1;
-       ctx->max_entrypoints = 1;
-       ctx->max_image_formats = 1;
+       ctx->max_entrypoints = VA_MAX_ENTRYPOINTS;
+       ctx->max_image_formats = VA_MAX_IMAGE_FORMATS_SUPPORTED;
        ctx->max_profiles = 1;
-       ctx->max_subpic_formats = 1;
+       ctx->max_subpic_formats = VA_MAX_SUBPIC_FORMATS_SUPPORTED;
        ctx->version_major = 3;
        ctx->version_minor = 1;
+       ctx->pDriverData = (void *)driver_context;
 
        VA_INFO("vl_screen_pointer %p\n",ctx->native_dpy);
 
index d50d712d4e0993816f34f8ea2038d5d6e1262d29..1aaaf7ccc5332b49df0f1e25032ed26c9638bfd5 100644 (file)
@@ -37,8 +37,12 @@ VAStatus  vlVaQueryDisplayAttributes(                VADriverContextP ctx,
         if (!ctx)
                 return VA_STATUS_ERROR_INVALID_CONTEXT;
 
+               if (!(attr_list && num_attributes))
+                       return VA_STATUS_ERROR_UNKNOWN;
 
-        return VA_STATUS_ERROR_UNIMPLEMENTED;
+        *num_attributes = 0;
+
+               return VA_STATUS_SUCCESS;
 }
 
 VAStatus  vlVaGetDisplayAttributes(            VADriverContextP ctx,
index 40a96d3ea48f483cb22ca04aa2fc4fe71b2ff5dc..8d20bfa9174ace706dd003397cefe4b72810d8d5 100644 (file)
 
 #include <util/u_memory.h>
 #include <util/u_format.h>
+#include <util/u_debug.h>
+#include <pipe/p_format.h>
 #include <va/va.h>
 #include <va/va_backend.h>
 #include "va_private.h"
 
+typedef struct  {
+       enum pipe_format pipe_format;
+       VAImageFormat       va_format;
+} va_image_formats_supported_t;
+
+static const va_image_formats_supported_t va_image_formats_supported[VA_MAX_IMAGE_FORMATS_SUPPORTED] = 
+{
+       { PIPE_FORMAT_B8G8R8A8_UNORM,
+      { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }},
+    { PIPE_FORMAT_R8G8B8A8_UNORM, 
+         { VA_FOURCC_RGBA, VA_LSB_FIRST, 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 }}
+};
+
+boolean vlCreateHTAB(void);
+void vlDestroyHTAB(void);
+vlHandle vlAddDataHTAB(void *data);
+void* vlGetDataHTAB(vlHandle handle);
+
 VAStatus
 vlVaQueryImageFormats (        VADriverContextP ctx,
                             VAImageFormat *format_list,
@@ -39,8 +59,20 @@ vlVaQueryImageFormats (      VADriverContextP ctx,
        if (!ctx)
                return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-
-       return VA_STATUS_ERROR_UNIMPLEMENTED;
+       if (!(format_list && num_formats))
+               return VA_STATUS_ERROR_UNKNOWN;
+               
+       int n = 0;
+       
+       num_formats[0] = VA_MAX_IMAGE_FORMATS_SUPPORTED;
+       
+       /* Query supported formats */
+       for (n = 0; n < VA_MAX_IMAGE_FORMATS_SUPPORTED; n++)
+       {
+               format_list[n] = va_image_formats_supported[n].va_format;
+       }
+
+       return VA_STATUS_SUCCESS;
 }
 
 VAStatus vlVaCreateImage(      VADriverContextP ctx,
@@ -52,7 +84,31 @@ VAStatus vlVaCreateImage(    VADriverContextP ctx,
        if (!ctx)
                return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-       return VA_STATUS_ERROR_UNIMPLEMENTED;
+       if(!format)
+               return VA_STATUS_ERROR_UNKNOWN;
+               
+       if (!(width && height))
+               return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
+               
+       if (!vlCreateHTAB())
+               return VA_STATUS_ERROR_UNKNOWN; 
+               
+       switch (format->fourcc) {
+       case VA_FOURCC('B','G','R','A'):
+               VA_INFO("Creating BGRA image of size %dx%d\n",width,height);
+       break;
+       case VA_FOURCC_RGBA:
+               VA_INFO("Creating RGBA image of size %dx%d\n",width,height);
+       break;
+       default:
+               VA_ERROR("Couldn't create image of type %0x08\n",format->fourcc);
+               return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
+       break;
+       }
+               
+       VA_INFO("Image %p created successfully\n",format);
+       
+       return VA_STATUS_SUCCESS;
 }
 
 VAStatus vlVaDeriveImage(      VADriverContextP ctx,
index cf7d844a780dcb17d7edccb1e0a32d6a3ff8313e..3603dfb6fedd225f3673f23843683b516e1b3b4c 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <va/va.h>
 #include <va/va_backend.h>
+#include <util/u_debug.h>
 #include "va_private.h"
 
 VAStatus vlVaBeginPicture(       VADriverContextP ctx,
index bd037c89606e0b7514e8b2604cd42e97ada19087..625c6cdbe1b6367ede1cb2e0ef116fe18aff80b0 100644 (file)
 
 #include <va/va.h>
 #include <va/va_backend.h>
+#include <pipe/p_format.h>
+#include <pipe/p_state.h>
+
 #define VA_DEBUG(_str,...) debug_printf("[Gallium VA backend]: " _str,__VA_ARGS__)
 #define VA_INFO(_str,...) VA_DEBUG("INFO: " _str,__VA_ARGS__)
 #define VA_WARNING(_str,...) VA_DEBUG("WARNING: " _str,__VA_ARGS__)
 #define VA_ERROR(_str,...) VA_DEBUG("ERROR: " _str,__VA_ARGS__)
 
+#define VA_MAX_IMAGE_FORMATS_SUPPORTED 2
+#define VA_MAX_SUBPIC_FORMATS_SUPPORTED 2
+#define VA_MAX_ENTRYPOINTS 1
+
+#define VL_HANDLES
+
+typedef unsigned int vlHandle;
+
+typedef struct {
+       struct vl_screen *vscreen;
+       struct pipe_surface *backbuffer;
+} vlVaDriverContextPriv;
+
+typedef struct {
+       unsigned int width;
+       unsigned int height;
+       enum pipe_video_chroma_format format;
+       VADriverContextP ctx;
+} vlVaSurfacePriv;
+
 // Public functions:
 VAStatus __vaDriverInit_0_31 (VADriverContextP ctx);
 
 // Private functions:
 struct VADriverVTable vlVaGetVtable();
 
+
 // Vtable functions:
 VAStatus vlVaTerminate (VADriverContextP ctx);
 VAStatus vlVaQueryConfigProfiles (VADriverContextP ctx, VAProfile *profile_list,int *num_profiles);
index a6d2960e7e55cd1eaf99d74be58f5aa0755c8809..910e5bd7b7087aaba49fb6473872c75e6ba47891 100644 (file)
 #include <pipe/p_format.h>
 #include "va_private.h"
 
-#define NUM_FORMATS_SUPPORTED 2
 
 typedef struct  {
-       enum pipe_format;
+       enum pipe_format        pipe_format;
        VAImageFormat       va_format;
     unsigned int        va_flags;
 } va_subpicture_formats_supported_t;
 
-static const va_subpicture_formats_supported_t va_subpicture_formats_supported[NUM_FORMATS_SUPPORTED] = 
+static const va_subpicture_formats_supported_t va_subpicture_formats_supported[VA_MAX_SUBPIC_FORMATS_SUPPORTED + 1] = 
 {
        { PIPE_FORMAT_B8G8R8A8_UNORM,
-      { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
-        32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
+      { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
       0 },
     { PIPE_FORMAT_R8G8B8A8_UNORM, 
-         { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
-        32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
+         { VA_FOURCC_RGBA, VA_LSB_FIRST, 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
       0 }
 };
 
@@ -62,12 +59,15 @@ vlVaQuerySubpictureFormats(         VADriverContextP ctx,
        if (!(format_list && flags && num_formats))
                return VA_STATUS_ERROR_UNKNOWN;
                
+       num_formats[0] = VA_MAX_SUBPIC_FORMATS_SUPPORTED;
+               
        int n = 0;
        /* Query supported formats */
-       for (n = 0; n < NUM_FORMATS_SUPPORTED; n++)
+       for (n = 0; n < VA_MAX_SUBPIC_FORMATS_SUPPORTED ; n++)
        {
-               flags[n] = va_subpicture_formats_supported[n].va_flags;
-               format_list[n] = va_subpicture_formats_supported[n].va_format;
+               const va_subpicture_formats_supported_t * const format_map = &va_subpicture_formats_supported[n];
+               flags[n] = format_map->va_flags;
+               format_list[n] = format_map->va_format;
        }
 
        return VA_STATUS_SUCCESS;
index ad241adaf41f5708f1dfc0e91fc376330108b2c9..a86c806248ac1ca4163874245dd380b8cb2c32f4 100644 (file)
 
 #include <va/va.h>
 #include <va/va_backend.h>
+#include <util/u_debug.h>
+#include <util/u_memory.h>
 #include "va_private.h"
 
+boolean vlCreateHTAB(void);
+void vlDestroyHTAB(void);
+vlHandle vlAddDataHTAB(void *data);
+void* vlGetDataHTAB(vlHandle handle);
+
+static enum pipe_video_chroma_format VaRTFormatToPipe(unsigned int va_type)
+{
+   switch (va_type) {
+      case VA_RT_FORMAT_YUV420:
+         return PIPE_VIDEO_CHROMA_FORMAT_420;
+      case VA_RT_FORMAT_YUV422:
+         return PIPE_VIDEO_CHROMA_FORMAT_422;
+      case VA_RT_FORMAT_YUV444:
+         return PIPE_VIDEO_CHROMA_FORMAT_444;
+      default:
+         assert(0);
+   }
+
+   return -1;
+}
+
 VAStatus vlVaCreateSurfaces(       VADriverContextP ctx,
                                    int width,
                                    int height,
@@ -39,7 +62,31 @@ VAStatus vlVaCreateSurfaces(       VADriverContextP ctx,
        if (!ctx)
                return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-       return VA_STATUS_ERROR_UNIMPLEMENTED;
+    /* We only support one format */
+    if (VA_RT_FORMAT_YUV420 != format)
+        return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
+               
+       if (!(width && height))
+               return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
+               
+       if (!vlCreateHTAB())
+               return VA_STATUS_ERROR_UNKNOWN; 
+               
+       vlVaSurfacePriv *va_surface = (vlVaSurfacePriv *)CALLOC(num_surfaces,sizeof(vlVaSurfacePriv));
+       if (!va_surface)
+               return VA_STATUS_ERROR_ALLOCATION_FAILED;
+               
+       int n = 0;
+       for (n = 0; n < num_surfaces; n++)
+       {
+               va_surface[n].width = width;
+               va_surface[n].height = height;
+               va_surface[n].format = VaRTFormatToPipe(format);
+               va_surface[n].ctx = ctx;
+               surfaces[n] = (VASurfaceID *)vlAddDataHTAB((void *)(va_surface + n));
+       }
+
+       return VA_STATUS_SUCCESS;
 }
 
 VAStatus vlVaDestroySurfaces(       VADriverContextP ctx,