1 /**************************************************************************
3 * Copyright 2010 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
25 **************************************************************************/
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.
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"
42 #include "VG/openvg.h"
43 #include "vg_context.h"
46 extern struct util_hash_table
*handle_hash
;
65 create_handle(void *object
);
69 destroy_handle(VGHandle h
);
72 static INLINE VGHandle
73 object_to_handle(struct vg_object
*obj
)
75 return obj
? obj
->handle
: VG_INVALID_HANDLE
;
79 static INLINE VGHandle
80 image_to_handle(struct vg_image
*img
)
82 /* vg_image is derived from vg_object */
83 return object_to_handle((struct vg_object
*) img
);
87 static INLINE VGHandle
88 masklayer_to_handle(struct vg_mask_layer
*mask
)
90 /* vg_object is derived from vg_object */
91 return object_to_handle((struct vg_object
*) mask
);
95 static INLINE VGHandle
96 font_to_handle(struct vg_font
*font
)
98 return object_to_handle((struct vg_object
*) font
);
102 static INLINE VGHandle
103 paint_to_handle(struct vg_paint
*paint
)
105 return object_to_handle((struct vg_object
*) paint
);
109 static INLINE VGHandle
110 path_to_handle(struct path
*path
)
112 return object_to_handle((struct vg_object
*) path
);
117 handle_to_pointer(VGHandle h
)
119 void *v
= util_hash_table_get(handle_hash
, intptr_to_pointer(h
));
122 struct vg_object
*obj
= (struct vg_object
*) v
;
123 assert(obj
->handle
== h
);
130 static INLINE
struct vg_font
*
131 handle_to_font(VGHandle h
)
133 return (struct vg_font
*) handle_to_pointer(h
);
137 static INLINE
struct vg_image
*
138 handle_to_image(VGHandle h
)
140 return (struct vg_image
*) handle_to_pointer(h
);
144 static INLINE
struct vg_mask_layer
*
145 handle_to_masklayer(VGHandle h
)
147 return (struct vg_mask_layer
*) handle_to_pointer(h
);
151 static INLINE
struct vg_object
*
152 handle_to_object(VGHandle h
)
154 return (struct vg_object
*) handle_to_pointer(h
);
158 static INLINE
struct vg_paint
*
159 handle_to_paint(VGHandle h
)
161 return (struct vg_paint
*) handle_to_pointer(h
);
165 static INLINE
struct path
*
166 handle_to_path(VGHandle h
)
168 return (struct path
*) handle_to_pointer(h
);
172 #endif /* HANDLE_H */