1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "util/u_memory.h"
30 #include "util/u_handle_table.h"
32 #include "va_private.h"
35 vlVaCreateBuffer(VADriverContextP ctx
, VAContextID context
, VABufferType type
,
36 unsigned int size
, unsigned int num_elements
, void *data
,
42 return VA_STATUS_ERROR_INVALID_CONTEXT
;
44 buf
= CALLOC(1, sizeof(vlVaBuffer
));
46 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
50 buf
->num_elements
= num_elements
;
51 buf
->data
= MALLOC(size
* num_elements
);
55 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
59 memcpy(buf
->data
, data
, size
* num_elements
);
61 *buf_id
= handle_table_add(VL_VA_DRIVER(ctx
)->htab
, buf
);
63 return VA_STATUS_SUCCESS
;
67 vlVaBufferSetNumElements(VADriverContextP ctx
, VABufferID buf_id
,
68 unsigned int num_elements
)
73 return VA_STATUS_ERROR_INVALID_CONTEXT
;
75 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
76 buf
->data
= REALLOC(buf
->data
, buf
->size
* buf
->num_elements
,
77 buf
->size
* num_elements
);
78 buf
->num_elements
= num_elements
;
81 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
83 return VA_STATUS_SUCCESS
;
87 vlVaMapBuffer(VADriverContextP ctx
, VABufferID buf_id
, void **pbuff
)
92 return VA_STATUS_ERROR_INVALID_CONTEXT
;
94 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
96 return VA_STATUS_ERROR_INVALID_BUFFER
;
100 return VA_STATUS_SUCCESS
;
104 vlVaUnmapBuffer(VADriverContextP ctx
, VABufferID buf_id
)
109 return VA_STATUS_ERROR_INVALID_CONTEXT
;
111 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
113 return VA_STATUS_ERROR_INVALID_BUFFER
;
115 /* Nothing to do here */
117 return VA_STATUS_SUCCESS
;
121 vlVaDestroyBuffer(VADriverContextP ctx
, VABufferID buf_id
)
126 return VA_STATUS_ERROR_INVALID_CONTEXT
;
128 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
130 return VA_STATUS_ERROR_INVALID_BUFFER
;
134 handle_table_remove(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
136 return VA_STATUS_SUCCESS
;
140 vlVaBufferInfo(VADriverContextP ctx
, VABufferID buf_id
, VABufferType
*type
,
141 unsigned int *size
, unsigned int *num_elements
)
146 return VA_STATUS_ERROR_INVALID_CONTEXT
;
148 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
150 return VA_STATUS_ERROR_INVALID_BUFFER
;
154 *num_elements
= buf
->num_elements
;
156 return VA_STATUS_SUCCESS
;