author | prr |
Fri, 01 Mar 2019 16:59:19 -0800 | |
changeset 54232 | 7c11a7cc7c1d |
parent 50826 | src/java.desktop/share/native/libfontmanager/harfbuzz/hb-object-private.hh@f5b95be8b6e2 |
permissions | -rw-r--r-- |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
2 |
* Copyright © 2007 Chris Wilson |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
3 |
* Copyright © 2009,2010 Red Hat, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
4 |
* Copyright © 2011,2012 Google, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
5 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
6 |
* This is part of HarfBuzz, a text shaping library. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
7 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
8 |
* Permission is hereby granted, without written agreement and without |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
9 |
* license or royalty fees, to use, copy, modify, and distribute this |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
10 |
* software and its documentation for any purpose, provided that the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
11 |
* above copyright notice and the following two paragraphs appear in |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
12 |
* all copies of this software. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
13 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
14 |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
15 |
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
16 |
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
17 |
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
18 |
* DAMAGE. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
19 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
20 |
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
21 |
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
22 |
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
23 |
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
24 |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
25 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
26 |
* Contributor(s): |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
27 |
* Chris Wilson <chris@chris-wilson.co.uk> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
28 |
* Red Hat Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
29 |
* Google Author(s): Behdad Esfahbod |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
30 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
31 |
|
54232 | 32 |
#ifndef HB_OBJECT_HH |
33 |
#define HB_OBJECT_HH |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
34 |
|
54232 | 35 |
#include "hb.hh" |
36 |
#include "hb-atomic.hh" |
|
37 |
#include "hb-mutex.hh" |
|
38 |
#include "hb-vector.hh" |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
39 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
40 |
|
54232 | 41 |
/* |
42 |
* Lockable set |
|
43 |
*/ |
|
44 |
||
45 |
template <typename item_t, typename lock_t> |
|
46 |
struct hb_lockable_set_t |
|
47 |
{ |
|
48 |
hb_vector_t<item_t> items; |
|
49 |
||
50 |
void init () { items.init (); } |
|
51 |
||
52 |
template <typename T> |
|
53 |
item_t *replace_or_insert (T v, lock_t &l, bool replace) |
|
54 |
{ |
|
55 |
l.lock (); |
|
56 |
item_t *item = items.find (v); |
|
57 |
if (item) { |
|
58 |
if (replace) { |
|
59 |
item_t old = *item; |
|
60 |
*item = v; |
|
61 |
l.unlock (); |
|
62 |
old.fini (); |
|
63 |
} |
|
64 |
else { |
|
65 |
item = nullptr; |
|
66 |
l.unlock (); |
|
67 |
} |
|
68 |
} else { |
|
69 |
item = items.push (v); |
|
70 |
l.unlock (); |
|
71 |
} |
|
72 |
return item; |
|
73 |
} |
|
74 |
||
75 |
template <typename T> |
|
76 |
void remove (T v, lock_t &l) |
|
77 |
{ |
|
78 |
l.lock (); |
|
79 |
item_t *item = items.find (v); |
|
80 |
if (item) |
|
81 |
{ |
|
82 |
item_t old = *item; |
|
83 |
*item = items[items.length - 1]; |
|
84 |
items.pop (); |
|
85 |
l.unlock (); |
|
86 |
old.fini (); |
|
87 |
} else { |
|
88 |
l.unlock (); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
template <typename T> |
|
93 |
bool find (T v, item_t *i, lock_t &l) |
|
94 |
{ |
|
95 |
l.lock (); |
|
96 |
item_t *item = items.find (v); |
|
97 |
if (item) |
|
98 |
*i = *item; |
|
99 |
l.unlock (); |
|
100 |
return !!item; |
|
101 |
} |
|
102 |
||
103 |
template <typename T> |
|
104 |
item_t *find_or_insert (T v, lock_t &l) |
|
105 |
{ |
|
106 |
l.lock (); |
|
107 |
item_t *item = items.find (v); |
|
108 |
if (!item) { |
|
109 |
item = items.push (v); |
|
110 |
} |
|
111 |
l.unlock (); |
|
112 |
return item; |
|
113 |
} |
|
114 |
||
115 |
void fini (lock_t &l) |
|
116 |
{ |
|
117 |
if (!items.length) |
|
118 |
{ |
|
119 |
/* No need to lock. */ |
|
120 |
items.fini (); |
|
121 |
return; |
|
122 |
} |
|
123 |
l.lock (); |
|
124 |
while (items.length) |
|
125 |
{ |
|
126 |
item_t old = items[items.length - 1]; |
|
127 |
items.pop (); |
|
128 |
l.unlock (); |
|
129 |
old.fini (); |
|
130 |
l.lock (); |
|
131 |
} |
|
132 |
items.fini (); |
|
133 |
l.unlock (); |
|
134 |
} |
|
135 |
||
136 |
}; |
|
137 |
||
138 |
||
139 |
/* |
|
140 |
* Reference-count. |
|
141 |
*/ |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
142 |
|
50826 | 143 |
#define HB_REFERENCE_COUNT_INERT_VALUE 0 |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
144 |
#define HB_REFERENCE_COUNT_POISON_VALUE -0x0000DEAD |
50826 | 145 |
#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT (HB_REFERENCE_COUNT_INERT_VALUE)} |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
146 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
147 |
struct hb_reference_count_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
148 |
{ |
54232 | 149 |
mutable hb_atomic_int_t ref_count; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
150 |
|
54232 | 151 |
void init (int v = 1) { ref_count.set_relaxed (v); } |
152 |
int get_relaxed () const { return ref_count.get_relaxed (); } |
|
153 |
int inc () const { return ref_count.inc (); } |
|
154 |
int dec () const { return ref_count.dec (); } |
|
155 |
void fini () { ref_count.set_relaxed (HB_REFERENCE_COUNT_POISON_VALUE); } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
156 |
|
54232 | 157 |
bool is_inert () const { return ref_count.get_relaxed () == HB_REFERENCE_COUNT_INERT_VALUE; } |
158 |
bool is_valid () const { return ref_count.get_relaxed () > 0; } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
159 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
160 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
161 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
162 |
/* user_data */ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
163 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
164 |
struct hb_user_data_array_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
165 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
166 |
struct hb_user_data_item_t { |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
167 |
hb_user_data_key_t *key; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
168 |
void *data; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
169 |
hb_destroy_func_t destroy; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
170 |
|
54232 | 171 |
bool operator == (hb_user_data_key_t *other_key) const { return key == other_key; } |
172 |
bool operator == (hb_user_data_item_t &other) const { return key == other.key; } |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
173 |
|
54232 | 174 |
void fini () { if (destroy) destroy (data); } |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
175 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
176 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
177 |
hb_mutex_t lock; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
178 |
hb_lockable_set_t<hb_user_data_item_t, hb_mutex_t> items; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
179 |
|
54232 | 180 |
void init () { lock.init (); items.init (); } |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
181 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
182 |
HB_INTERNAL bool set (hb_user_data_key_t *key, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
183 |
void * data, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
184 |
hb_destroy_func_t destroy, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
185 |
hb_bool_t replace); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
186 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
187 |
HB_INTERNAL void *get (hb_user_data_key_t *key); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
188 |
|
54232 | 189 |
void fini () { items.fini (lock); lock.fini (); } |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
190 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
191 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
192 |
|
54232 | 193 |
/* |
194 |
* Object header |
|
195 |
*/ |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
196 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
197 |
struct hb_object_header_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
198 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
199 |
hb_reference_count_t ref_count; |
54232 | 200 |
mutable hb_atomic_int_t writable; |
201 |
hb_atomic_ptr_t<hb_user_data_array_t> user_data; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
202 |
}; |
54232 | 203 |
#define HB_OBJECT_HEADER_STATIC \ |
204 |
{ \ |
|
205 |
HB_REFERENCE_COUNT_INIT, \ |
|
206 |
HB_ATOMIC_INT_INIT (false), \ |
|
207 |
HB_ATOMIC_PTR_INIT (nullptr) \ |
|
208 |
} |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
209 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
210 |
|
54232 | 211 |
/* |
212 |
* Object |
|
213 |
*/ |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
214 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
215 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
216 |
static inline void hb_object_trace (const Type *obj, const char *function) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
217 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
218 |
DEBUG_MSG (OBJECT, (void *) obj, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
219 |
"%s refcount=%d", |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
220 |
function, |
54232 | 221 |
obj ? obj->header.ref_count.get_relaxed () : 0); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
222 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
223 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
224 |
template <typename Type> |
54232 | 225 |
static inline Type *hb_object_create () |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
226 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
227 |
Type *obj = (Type *) calloc (1, sizeof (Type)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
228 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
229 |
if (unlikely (!obj)) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
230 |
return obj; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
231 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
232 |
hb_object_init (obj); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
233 |
hb_object_trace (obj, HB_FUNC); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
234 |
return obj; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
235 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
236 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
237 |
static inline void hb_object_init (Type *obj) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
238 |
{ |
54232 | 239 |
obj->header.ref_count.init (); |
240 |
obj->header.writable.set_relaxed (true); |
|
241 |
obj->header.user_data.init (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
242 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
243 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
244 |
static inline bool hb_object_is_inert (const Type *obj) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
245 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
246 |
return unlikely (obj->header.ref_count.is_inert ()); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
247 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
248 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
249 |
static inline bool hb_object_is_valid (const Type *obj) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
250 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
251 |
return likely (obj->header.ref_count.is_valid ()); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
252 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
253 |
template <typename Type> |
54232 | 254 |
static inline bool hb_object_is_immutable (const Type *obj) |
255 |
{ |
|
256 |
return !obj->header.writable.get_relaxed (); |
|
257 |
} |
|
258 |
template <typename Type> |
|
259 |
static inline void hb_object_make_immutable (const Type *obj) |
|
260 |
{ |
|
261 |
obj->header.writable.set_relaxed (false); |
|
262 |
} |
|
263 |
template <typename Type> |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
264 |
static inline Type *hb_object_reference (Type *obj) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
265 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
266 |
hb_object_trace (obj, HB_FUNC); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
267 |
if (unlikely (!obj || hb_object_is_inert (obj))) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
268 |
return obj; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
269 |
assert (hb_object_is_valid (obj)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
270 |
obj->header.ref_count.inc (); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
271 |
return obj; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
272 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
273 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
274 |
static inline bool hb_object_destroy (Type *obj) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
275 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
276 |
hb_object_trace (obj, HB_FUNC); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
277 |
if (unlikely (!obj || hb_object_is_inert (obj))) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
278 |
return false; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
279 |
assert (hb_object_is_valid (obj)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
280 |
if (obj->header.ref_count.dec () != 1) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
281 |
return false; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
282 |
|
50826 | 283 |
hb_object_fini (obj); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
284 |
return true; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
285 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
286 |
template <typename Type> |
50826 | 287 |
static inline void hb_object_fini (Type *obj) |
288 |
{ |
|
289 |
obj->header.ref_count.fini (); /* Do this before user_data */ |
|
54232 | 290 |
hb_user_data_array_t *user_data = obj->header.user_data.get (); |
291 |
if (user_data) |
|
50826 | 292 |
{ |
54232 | 293 |
user_data->fini (); |
294 |
free (user_data); |
|
295 |
user_data = nullptr; |
|
50826 | 296 |
} |
297 |
} |
|
298 |
template <typename Type> |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
299 |
static inline bool hb_object_set_user_data (Type *obj, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
300 |
hb_user_data_key_t *key, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
301 |
void * data, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
302 |
hb_destroy_func_t destroy, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
303 |
hb_bool_t replace) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
304 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
305 |
if (unlikely (!obj || hb_object_is_inert (obj))) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
306 |
return false; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
307 |
assert (hb_object_is_valid (obj)); |
50826 | 308 |
|
309 |
retry: |
|
54232 | 310 |
hb_user_data_array_t *user_data = obj->header.user_data.get (); |
50826 | 311 |
if (unlikely (!user_data)) |
312 |
{ |
|
313 |
user_data = (hb_user_data_array_t *) calloc (sizeof (hb_user_data_array_t), 1); |
|
314 |
if (unlikely (!user_data)) |
|
315 |
return false; |
|
316 |
user_data->init (); |
|
54232 | 317 |
if (unlikely (!obj->header.user_data.cmpexch (nullptr, user_data))) |
50826 | 318 |
{ |
319 |
user_data->fini (); |
|
320 |
free (user_data); |
|
321 |
goto retry; |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
return user_data->set (key, data, destroy, replace); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
326 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
327 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
328 |
template <typename Type> |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
329 |
static inline void *hb_object_get_user_data (Type *obj, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
330 |
hb_user_data_key_t *key) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
331 |
{ |
54232 | 332 |
if (unlikely (!obj || hb_object_is_inert (obj))) |
48274 | 333 |
return nullptr; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
334 |
assert (hb_object_is_valid (obj)); |
54232 | 335 |
hb_user_data_array_t *user_data = obj->header.user_data.get (); |
336 |
if (!user_data) |
|
337 |
return nullptr; |
|
338 |
return user_data->get (key); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
339 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
340 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
341 |
|
54232 | 342 |
#endif /* HB_OBJECT_HH */ |