1
by Jens Kuske
First release |
1 |
/*
|
2 |
* Copyright (c) 2013 Jens Kuske <jenskuske@gmail.com>
|
|
3 |
*
|
|
4 |
* This library is free software; you can redistribute it and/or
|
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
|
6 |
* License as published by the Free Software Foundation; either
|
|
7 |
* version 2.1 of the License, or (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This library is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 |
* Lesser General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
|
15 |
* License along with this library; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
||
5
by Jens Kuske
Make handle table self-growing |
20 |
#include <string.h> |
1
by Jens Kuske
First release |
21 |
#include "vdpau_private.h" |
22 |
||
5
by Jens Kuske
Make handle table self-growing |
23 |
#define INITIAL_SIZE 16
|
24 |
||
25 |
static struct |
|
26 |
{
|
|
27 |
void **data; |
|
28 |
int size; |
|
29 |
} ht; |
|
1
by Jens Kuske
First release |
30 |
|
31 |
int handle_create(void *data) |
|
32 |
{
|
|
5
by Jens Kuske
Make handle table self-growing |
33 |
int index; |
34 |
||
1
by Jens Kuske
First release |
35 |
if (!data) |
36 |
return -1; |
|
37 |
||
5
by Jens Kuske
Make handle table self-growing |
38 |
for (index = 0; index < ht.size; index++) |
39 |
if (ht.data[index] == NULL) |
|
1
by Jens Kuske
First release |
40 |
break; |
5
by Jens Kuske
Make handle table self-growing |
41 |
|
42 |
if (index >= ht.size) |
|
43 |
{
|
|
44 |
int new_size = ht.size ? ht.size * 2 : INITIAL_SIZE; |
|
45 |
void **new_data = realloc(ht.data, new_size * sizeof(void *)); |
|
46 |
if (!new_data) |
|
47 |
return -1; |
|
48 |
||
49 |
memset(new_data + ht.size, 0, (new_size - ht.size) * sizeof(void *)); |
|
50 |
ht.data = new_data; |
|
51 |
ht.size = new_size; |
|
52 |
}
|
|
53 |
||
54 |
ht.data[index] = data; |
|
55 |
return index + 1; |
|
1
by Jens Kuske
First release |
56 |
}
|
57 |
||
58 |
void *handle_get(int handle) |
|
59 |
{
|
|
16.1.5
by Paul Kendall
Handle null source/dest rects properly |
60 |
if (handle == VDP_INVALID_HANDLE) |
61 |
return NULL; |
|
62 |
||
5
by Jens Kuske
Make handle table self-growing |
63 |
int index = handle - 1; |
64 |
if (index < ht.size) |
|
65 |
return ht.data[index]; |
|
1
by Jens Kuske
First release |
66 |
|
5
by Jens Kuske
Make handle table self-growing |
67 |
return NULL; |
1
by Jens Kuske
First release |
68 |
}
|
69 |
||
70 |
void handle_destroy(int handle) |
|
71 |
{
|
|
5
by Jens Kuske
Make handle table self-growing |
72 |
int index = handle - 1; |
73 |
||
74 |
if (index < ht.size) |
|
75 |
ht.data[index] = NULL; |
|
1
by Jens Kuske
First release |
76 |
}
|