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
);
77 return VA_STATUS_ERROR_INVALID_BUFFER
;
79 buf
->data
= REALLOC(buf
->data
, buf
->size
* buf
->num_elements
,
80 buf
->size
* num_elements
);
81 buf
->num_elements
= num_elements
;
84 return VA_STATUS_ERROR_ALLOCATION_FAILED
;
86 return VA_STATUS_SUCCESS
;
90 vlVaMapBuffer(VADriverContextP ctx
, VABufferID buf_id
, void **pbuff
)
95 return VA_STATUS_ERROR_INVALID_CONTEXT
;
98 return VA_STATUS_ERROR_INVALID_PARAMETER
;
100 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
102 return VA_STATUS_ERROR_INVALID_BUFFER
;
106 return VA_STATUS_SUCCESS
;
110 vlVaUnmapBuffer(VADriverContextP ctx
, VABufferID buf_id
)
115 return VA_STATUS_ERROR_INVALID_CONTEXT
;
117 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
119 return VA_STATUS_ERROR_INVALID_BUFFER
;
121 /* Nothing to do here */
123 return VA_STATUS_SUCCESS
;
127 vlVaDestroyBuffer(VADriverContextP ctx
, VABufferID buf_id
)
132 return VA_STATUS_ERROR_INVALID_CONTEXT
;
134 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
136 return VA_STATUS_ERROR_INVALID_BUFFER
;
140 handle_table_remove(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
142 return VA_STATUS_SUCCESS
;
146 vlVaBufferInfo(VADriverContextP ctx
, VABufferID buf_id
, VABufferType
*type
,
147 unsigned int *size
, unsigned int *num_elements
)
152 return VA_STATUS_ERROR_INVALID_CONTEXT
;
154 buf
= handle_table_get(VL_VA_DRIVER(ctx
)->htab
, buf_id
);
156 return VA_STATUS_ERROR_INVALID_BUFFER
;
160 *num_elements
= buf
->num_elements
;
162 return VA_STATUS_SUCCESS
;