handle.h revision 99c67f27d35a4bbbbefada8117d5972c7583cf42
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_hash_table.h" 39#include "util/u_pointer.h" 40 41#include "VG/openvg.h" 42#include "vg_context.h" 43 44 45extern struct util_hash_table *handle_hash; 46 47 48struct vg_mask_layer; 49struct vg_font; 50struct vg_image; 51struct vg_paint; 52struct path; 53 54 55extern void 56init_handles(void); 57 58 59extern void 60free_handles(void); 61 62 63extern VGHandle 64create_handle(void *object); 65 66 67extern void 68destroy_handle(VGHandle h); 69 70 71static INLINE VGHandle 72object_to_handle(struct vg_object *obj) 73{ 74 return obj ? obj->handle : VG_INVALID_HANDLE; 75} 76 77 78static INLINE VGHandle 79image_to_handle(struct vg_image *img) 80{ 81 /* vg_image is derived from vg_object */ 82 return object_to_handle((struct vg_object *) img); 83} 84 85 86static INLINE VGHandle 87masklayer_to_handle(struct vg_mask_layer *mask) 88{ 89 /* vg_object is derived from vg_object */ 90 return object_to_handle((struct vg_object *) mask); 91} 92 93 94static INLINE VGHandle 95font_to_handle(struct vg_font *font) 96{ 97 return object_to_handle((struct vg_object *) font); 98} 99 100 101static INLINE VGHandle 102paint_to_handle(struct vg_paint *paint) 103{ 104 return object_to_handle((struct vg_object *) paint); 105} 106 107 108static INLINE VGHandle 109path_to_handle(struct path *path) 110{ 111 return object_to_handle((struct vg_object *) path); 112} 113 114 115static INLINE void * 116handle_to_pointer(VGHandle h) 117{ 118 void *v = util_hash_table_get(handle_hash, intptr_to_pointer(h)); 119#ifdef DEBUG 120 if (v) { 121 struct vg_object *obj = (struct vg_object *) v; 122 assert(obj->handle == h); 123 } 124#endif 125 return v; 126} 127 128 129static INLINE struct vg_font * 130handle_to_font(VGHandle h) 131{ 132 return (struct vg_font *) handle_to_pointer(h); 133} 134 135 136static INLINE struct vg_image * 137handle_to_image(VGHandle h) 138{ 139 return (struct vg_image *) handle_to_pointer(h); 140} 141 142 143static INLINE struct vg_mask_layer * 144handle_to_masklayer(VGHandle h) 145{ 146 return (struct vg_mask_layer *) handle_to_pointer(h); 147} 148 149 150static INLINE struct vg_object * 151handle_to_object(VGHandle h) 152{ 153 return (struct vg_object *) handle_to_pointer(h); 154} 155 156 157static INLINE struct vg_paint * 158handle_to_paint(VGHandle h) 159{ 160 return (struct vg_paint *) handle_to_pointer(h); 161} 162 163 164static INLINE struct path * 165handle_to_path(VGHandle h) 166{ 167 return (struct path *) handle_to_pointer(h); 168} 169 170 171#endif /* HANDLE_H */ 172