[Mesa-dev] [PATCH 06/15] st/va: implement vlVa(Create|Destroy)Surfaces

Christian König deathsimple at vodafone.de
Tue Jun 18 02:27:36 PDT 2013


From: Christian König <christian.koenig at amd.com>

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 src/gallium/state_trackers/va/context.c    |    9 ++++
 src/gallium/state_trackers/va/surface.c    |   61 +++++++++++++++++++++++++++-
 src/gallium/state_trackers/va/va_private.h |   22 ++++++++++
 3 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/va/context.c b/src/gallium/state_trackers/va/context.c
index 5940422..51eb259 100644
--- a/src/gallium/state_trackers/va/context.c
+++ b/src/gallium/state_trackers/va/context.c
@@ -30,6 +30,7 @@
 #include "pipe/p_video_decoder.h"
 
 #include "util/u_memory.h"
+#include "util/u_handle_table.h"
 #include "vl/vl_winsys.h"
 
 #include "va_private.h"
@@ -100,6 +101,13 @@ __vaDriverInit_0_32(VADriverContextP ctx)
       return VA_STATUS_ERROR_ALLOCATION_FAILED;
    }
 
+   drv->htab = handle_table_create();
+   if (!drv->htab) {
+      vl_screen_destroy(drv->vscreen);
+      FREE(drv);
+      return VA_STATUS_ERROR_ALLOCATION_FAILED;
+   }
+
    ctx->pDriverData = (void *)drv;
    ctx->version_major = 0;
    ctx->version_minor = 1;
@@ -145,6 +153,7 @@ vlVaTerminate(VADriverContextP ctx)
 
    drv = ctx->pDriverData;
    vl_screen_destroy(drv->vscreen);
+   handle_table_destroy(drv->htab);
    FREE(drv);
 
    return VA_STATUS_SUCCESS;
diff --git a/src/gallium/state_trackers/va/surface.c b/src/gallium/state_trackers/va/surface.c
index 56356e4..5b54d7c 100644
--- a/src/gallium/state_trackers/va/surface.c
+++ b/src/gallium/state_trackers/va/surface.c
@@ -26,28 +26,85 @@
  *
  **************************************************************************/
 
+#include "pipe/p_screen.h"
+
+#include "util/u_memory.h"
+#include "util/u_handle_table.h"
+#include "vl/vl_winsys.h"
+
 #include "va_private.h"
 
 VAStatus
 vlVaCreateSurfaces(VADriverContextP ctx, int width, int height, int format,
                    int num_surfaces, VASurfaceID *surfaces)
 {
+   struct pipe_video_buffer templat = {};
+   struct pipe_screen *pscreen;
+   vlVaDriver *drv;
+   int i;
+
    if (!ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
    if (!(width && height))
       return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
 
-   return VA_STATUS_ERROR_UNIMPLEMENTED;
+   drv = VL_VA_DRIVER(ctx);
+   pscreen = VL_VA_PSCREEN(ctx);
+
+   templat.buffer_format = pscreen->get_video_param
+   (
+      pscreen,
+      PIPE_VIDEO_PROFILE_UNKNOWN,
+      PIPE_VIDEO_CAP_PREFERED_FORMAT
+   );
+   templat.chroma_format = ChromaToPipe(format);
+   templat.width = width;
+   templat.height = height;
+   templat.interlaced = pscreen->get_video_param
+   (
+      pscreen,
+      PIPE_VIDEO_PROFILE_UNKNOWN,
+      PIPE_VIDEO_CAP_PREFERS_INTERLACED
+   );
+
+   for (i = 0; i < num_surfaces; ++i) {
+      vlVaSurface *surf = CALLOC(1, sizeof(vlVaSurface));
+      if (!surf)
+         goto no_res;
+
+      surf->templat = templat;
+      surfaces[i] = handle_table_add(drv->htab, surf);
+   }
+
+   return VA_STATUS_SUCCESS;
+
+no_res:
+   if (i)
+      vlVaDestroySurfaces(ctx, surfaces, i);
+
+   return VA_STATUS_ERROR_ALLOCATION_FAILED;
 }
 
 VAStatus
 vlVaDestroySurfaces(VADriverContextP ctx, VASurfaceID *surface_list, int num_surfaces)
 {
+   vlVaDriver *drv;
+   int i;
+
    if (!ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
-   return VA_STATUS_ERROR_UNIMPLEMENTED;
+   drv = VL_VA_DRIVER(ctx);
+   for (i = 0; i < num_surfaces; ++i) {
+      vlVaSurface *surf = handle_table_get(drv->htab, surface_list[i]);
+      if (surf->buffer)
+         surf->buffer->destroy(surf->buffer);
+      FREE(surf);
+      handle_table_remove(drv->htab, surface_list[i]);
+   }
+
+   return VA_STATUS_SUCCESS;
 }
 
 VAStatus
diff --git a/src/gallium/state_trackers/va/va_private.h b/src/gallium/state_trackers/va/va_private.h
index cd6c7d7..88418f9 100644
--- a/src/gallium/state_trackers/va/va_private.h
+++ b/src/gallium/state_trackers/va/va_private.h
@@ -35,10 +35,27 @@
 #include <va/va_backend.h>
 
 #include "pipe/p_video_enums.h"
+#include "pipe/p_video_decoder.h"
 
 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
 
+static inline enum pipe_video_chroma_format
+ChromaToPipe(int format)
+{
+   switch (format) {
+   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 PIPE_VIDEO_CHROMA_FORMAT_420;
+   }
+}
+
 static inline VAProfile
 PipeToProfile(enum pipe_video_profile profile)
 {
@@ -100,8 +117,13 @@ ProfileToPipe(VAProfile profile)
 
 typedef struct {
    struct vl_screen *vscreen;
+   struct handle_table *htab;
 } vlVaDriver;
 
+typedef struct {
+   struct pipe_video_buffer templat, *buffer;
+} vlVaSurface;
+
 // Public functions:
 VAStatus __vaDriverInit_0_32(VADriverContextP ctx);
 
-- 
1.7.9.5



More information about the mesa-dev mailing list