Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5563 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2010 VMware, Inc. All Rights Reserved. |
||
4 | * |
||
5 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
6 | * copy of this software and associated documentation files (the |
||
7 | * "Software"), to deal in the Software without restriction, including |
||
8 | * without limitation the rights to use, copy, modify, merge, publish, |
||
9 | * distribute, sub license, and/or sell copies of the Software, and to |
||
10 | * permit persons to whom the Software is furnished to do so, subject to |
||
11 | * the following conditions: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice (including the |
||
14 | * next paragraph) shall be included in all copies or substantial portions |
||
15 | * of the Software. |
||
16 | * |
||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
||
20 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
||
21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||
22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||
23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
24 | * |
||
25 | **************************************************************************/ |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Convert opaque VG object handles into pointers and vice versa. |
||
30 | * XXX This is not yet 64-bit safe! All VG handles are 32 bits in size. |
||
31 | */ |
||
32 | |||
33 | |||
34 | #ifndef HANDLE_H |
||
35 | #define HANDLE_H |
||
36 | |||
37 | #include "pipe/p_compiler.h" |
||
38 | #include "util/u_debug.h" |
||
39 | #include "util/u_hash_table.h" |
||
40 | #include "util/u_pointer.h" |
||
41 | |||
42 | #include "VG/openvg.h" |
||
43 | #include "vg_context.h" |
||
44 | |||
45 | |||
46 | extern struct util_hash_table *handle_hash; |
||
47 | |||
48 | |||
49 | struct vg_mask_layer; |
||
50 | struct vg_font; |
||
51 | struct vg_image; |
||
52 | struct vg_paint; |
||
53 | struct path; |
||
54 | |||
55 | |||
56 | extern void |
||
57 | init_handles(void); |
||
58 | |||
59 | |||
60 | extern void |
||
61 | free_handles(void); |
||
62 | |||
63 | |||
64 | extern VGHandle |
||
65 | create_handle(void *object); |
||
66 | |||
67 | |||
68 | extern void |
||
69 | destroy_handle(VGHandle h); |
||
70 | |||
71 | |||
72 | static INLINE VGHandle |
||
73 | object_to_handle(struct vg_object *obj) |
||
74 | { |
||
75 | return obj ? obj->handle : VG_INVALID_HANDLE; |
||
76 | } |
||
77 | |||
78 | |||
79 | static INLINE VGHandle |
||
80 | image_to_handle(struct vg_image *img) |
||
81 | { |
||
82 | /* vg_image is derived from vg_object */ |
||
83 | return object_to_handle((struct vg_object *) img); |
||
84 | } |
||
85 | |||
86 | |||
87 | static INLINE VGHandle |
||
88 | masklayer_to_handle(struct vg_mask_layer *mask) |
||
89 | { |
||
90 | /* vg_object is derived from vg_object */ |
||
91 | return object_to_handle((struct vg_object *) mask); |
||
92 | } |
||
93 | |||
94 | |||
95 | static INLINE VGHandle |
||
96 | font_to_handle(struct vg_font *font) |
||
97 | { |
||
98 | return object_to_handle((struct vg_object *) font); |
||
99 | } |
||
100 | |||
101 | |||
102 | static INLINE VGHandle |
||
103 | paint_to_handle(struct vg_paint *paint) |
||
104 | { |
||
105 | return object_to_handle((struct vg_object *) paint); |
||
106 | } |
||
107 | |||
108 | |||
109 | static INLINE VGHandle |
||
110 | path_to_handle(struct path *path) |
||
111 | { |
||
112 | return object_to_handle((struct vg_object *) path); |
||
113 | } |
||
114 | |||
115 | |||
116 | static INLINE void * |
||
117 | handle_to_pointer(VGHandle h) |
||
118 | { |
||
119 | void *v = util_hash_table_get(handle_hash, intptr_to_pointer(h)); |
||
120 | #ifdef DEBUG |
||
121 | if (v) { |
||
122 | struct vg_object *obj = (struct vg_object *) v; |
||
123 | assert(obj->handle == h); |
||
124 | } |
||
125 | #endif |
||
126 | return v; |
||
127 | } |
||
128 | |||
129 | |||
130 | static INLINE struct vg_font * |
||
131 | handle_to_font(VGHandle h) |
||
132 | { |
||
133 | return (struct vg_font *) handle_to_pointer(h); |
||
134 | } |
||
135 | |||
136 | |||
137 | static INLINE struct vg_image * |
||
138 | handle_to_image(VGHandle h) |
||
139 | { |
||
140 | return (struct vg_image *) handle_to_pointer(h); |
||
141 | } |
||
142 | |||
143 | |||
144 | static INLINE struct vg_mask_layer * |
||
145 | handle_to_masklayer(VGHandle h) |
||
146 | { |
||
147 | return (struct vg_mask_layer *) handle_to_pointer(h); |
||
148 | } |
||
149 | |||
150 | |||
151 | static INLINE struct vg_object * |
||
152 | handle_to_object(VGHandle h) |
||
153 | { |
||
154 | return (struct vg_object *) handle_to_pointer(h); |
||
155 | } |
||
156 | |||
157 | |||
158 | static INLINE struct vg_paint * |
||
159 | handle_to_paint(VGHandle h) |
||
160 | { |
||
161 | return (struct vg_paint *) handle_to_pointer(h); |
||
162 | } |
||
163 | |||
164 | |||
165 | static INLINE struct path * |
||
166 | handle_to_path(VGHandle h) |
||
167 | { |
||
168 | return (struct path *) handle_to_pointer(h); |
||
169 | } |
||
170 | |||
171 | |||
172 | #endif /* HANDLE_H */ |