diff options
author | Christian König <[email protected]> | 2014-07-04 12:44:36 -0400 |
---|---|---|
committer | Leo Liu <[email protected]> | 2014-10-01 13:21:36 -0400 |
commit | 1be55158381f509d420e42f40018ec95fe329f5b (patch) | |
tree | dda90c46409f8af047d62ee595e1caa53d7298e1 /src/gallium/state_trackers/va/buffer.c | |
parent | 2825ef3abf29b152b12faef8cd5a373c71b9fbaf (diff) |
st/va: implement Context Surface and Buffer
This patch implements context managements, relate it HW driver,
functions for video surface managements, and functions for
application data memory buffer managements.
implemented functions:
vlVa(Create|Destroy)Context
vlVa(Create|Destroy|Put)Surfaces
vlVa(Create|Destroy)Buffer
Signed-off-by: Christian König <[email protected]>
Signed-off-by: Leo Liu <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/va/buffer.c')
-rw-r--r-- | src/gallium/state_trackers/va/buffer.c | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/src/gallium/state_trackers/va/buffer.c b/src/gallium/state_trackers/va/buffer.c index 0378f60afe8..4023c327629 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; } |