[Mesa-dev] [PATCH 08/15] st/va: implement vlVa(Create|Destroy)Buffer
Christian König
deathsimple at vodafone.de
Tue Jun 18 02:27:38 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/buffer.c | 83 +++++++++++++++++++++++++---
src/gallium/state_trackers/va/va_private.h | 7 +++
2 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/src/gallium/state_trackers/va/buffer.c b/src/gallium/state_trackers/va/buffer.c
index 5610775..c672484 100644
--- a/src/gallium/state_trackers/va/buffer.c
+++ b/src/gallium/state_trackers/va/buffer.c
@@ -26,6 +26,9 @@
*
**************************************************************************/
+#include "util/u_memory.h"
+#include "util/u_handle_table.h"
+
#include "va_private.h"
VAStatus
@@ -33,55 +36,121 @@ vlVaCreateBuffer(VADriverContextP ctx, VAContextID context, VABufferType type,
unsigned int size, unsigned int num_elements, void *data,
VABufferID *buf_id)
{
+ vlVaBuffer *buf;
+
if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT;
- return VA_STATUS_ERROR_UNIMPLEMENTED;
+ buf = CALLOC(1, sizeof(vlVaBuffer));
+ if (!buf)
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;
+
+ buf->type = type;
+ buf->size = size;
+ buf->num_elements = num_elements;
+ buf->data = MALLOC(size * num_elements);
+
+ if (!buf->data) {
+ FREE(buf);
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;
+ }
+
+ if (data)
+ memcpy(buf->data, data, size * num_elements);
+
+ *buf_id = handle_table_add(VL_VA_DRIVER(ctx)->htab, buf);
+
+ return VA_STATUS_SUCCESS;
}
VAStatus
vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id,
unsigned int num_elements)
{
+ vlVaBuffer *buf;
+
if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT;
- return VA_STATUS_ERROR_UNIMPLEMENTED;
+ buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
+ buf->data = REALLOC(buf->data, buf->size * buf->num_elements,
+ buf->size * num_elements);
+ buf->num_elements = num_elements;
+
+ if (!buf->data)
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;
+
+ return VA_STATUS_SUCCESS;
}
VAStatus
vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff)
{
+ vlVaBuffer *buf;
+
if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT;
- return VA_STATUS_ERROR_UNIMPLEMENTED;
+ buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
+ if (!buf)
+ return VA_STATUS_ERROR_INVALID_BUFFER;
+
+ *pbuff = buf->data;
+
+ return VA_STATUS_SUCCESS;
}
VAStatus
vlVaUnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
{
+ vlVaBuffer *buf;
+
if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT;
- return VA_STATUS_ERROR_UNIMPLEMENTED;
+ buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
+ if (!buf)
+ return VA_STATUS_ERROR_INVALID_BUFFER;
+
+ /* Nothing to do here */
+
+ return VA_STATUS_SUCCESS;
}
VAStatus
-vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
+vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buf_id)
{
+ vlVaBuffer *buf;
+
if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT;
- return VA_STATUS_ERROR_UNIMPLEMENTED;
+ buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
+ if (!buf)
+ return VA_STATUS_ERROR_INVALID_BUFFER;
+
+ FREE(buf->data);
+ FREE(buf);
+
+ return VA_STATUS_SUCCESS;
}
VAStatus
vlVaBufferInfo(VADriverContextP ctx, VABufferID buf_id, VABufferType *type,
unsigned int *size, unsigned int *num_elements)
{
+ vlVaBuffer *buf;
+
if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT;
- return VA_STATUS_ERROR_UNIMPLEMENTED;
+ buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
+ if (!buf)
+ return VA_STATUS_ERROR_INVALID_BUFFER;
+
+ *type = buf->type;
+ *size = buf->size;
+ *num_elements = buf->num_elements;
+
+ return VA_STATUS_SUCCESS;
}
diff --git a/src/gallium/state_trackers/va/va_private.h b/src/gallium/state_trackers/va/va_private.h
index fcc1c59..caa8c4a 100644
--- a/src/gallium/state_trackers/va/va_private.h
+++ b/src/gallium/state_trackers/va/va_private.h
@@ -133,6 +133,13 @@ typedef struct {
} vlVaContext;
typedef struct {
+ VABufferType type;
+ unsigned int size;
+ unsigned int num_elements;
+ void *data;
+} vlVaBuffer;
+
+typedef struct {
struct pipe_video_buffer templat, *buffer;
} vlVaSurface;
--
1.7.9.5
More information about the mesa-dev
mailing list