2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 #ifndef _NINE_HELPERS_H_
24 #define _NINE_HELPERS_H_
27 #include "nine_lock.h"
30 * Note: we use these function rather than the MIN2, MAX2, CLAMP macros to
31 * avoid evaluating arguments (which are often function calls) more than once.
34 static inline unsigned _min(unsigned a
, unsigned b
)
36 return (a
< b
) ? a
: b
;
41 #define nine_reference(a, b) _nine_reference((void **)(a), (b))
43 static inline void _nine_reference(void **ref
, void *ptr
)
47 NineUnknown_Release(*ref
);
49 NineUnknown_AddRef(ptr
);
54 #define nine_reference_set(a, b) _nine_reference_set((void **)(a), (b))
56 static inline void _nine_reference_set(void **ref
, void *ptr
)
60 NineUnknown_AddRef(ptr
);
63 #define nine_bind(a, b) _nine_bind((void **)(a), (b))
65 static inline void _nine_bind(void **dst
, void *obj
)
69 NineUnknown_Unbind(*dst
);
71 NineUnknown_Bind(obj
);
76 #define NINE_DEVICE_CHILD_NEW(nine, out, dev, ...) \
78 struct NineUnknownParams __params; \
79 struct Nine##nine *__data; \
81 __data = CALLOC_STRUCT(Nine##nine); \
82 if (!__data) { return E_OUTOFMEMORY; } \
84 __params.vtable = ((dev)->params.BehaviorFlags & D3DCREATE_MULTITHREADED) ? &Lock##nine##_vtable : &Nine##nine##_vtable; \
85 __params.guids = Nine##nine##_IIDs; \
86 __params.dtor = (void *)Nine##nine##_dtor; \
87 __params.container = NULL; \
88 __params.device = dev; \
90 HRESULT __hr = Nine##nine##_ctor(__data, &__params, ## __VA_ARGS__); \
92 Nine##nine##_dtor(__data); \
101 #define NINE_NEW(nine, out, lock, ...) \
103 struct NineUnknownParams __params; \
104 struct Nine##nine *__data; \
106 __data = CALLOC_STRUCT(Nine##nine); \
107 if (!__data) { return E_OUTOFMEMORY; } \
109 __params.vtable = (lock) ? &Lock##nine##_vtable : &Nine##nine##_vtable; \
110 __params.guids = Nine##nine##_IIDs; \
111 __params.dtor = (void *)Nine##nine##_dtor; \
112 __params.container = NULL; \
113 __params.device = NULL; \
115 HRESULT __hr = Nine##nine##_ctor(__data, &__params, ## __VA_ARGS__); \
116 if (FAILED(__hr)) { \
117 Nine##nine##_dtor(__data); \
126 static INLINE
float asfloat(DWORD value
)
136 #define CHECK_PIPE_RESOURCE_TEMPLATE(t) \
137 screen->is_format_supported(screen, (t).format, (t).target, (t).nr_samples, (t).bind)
142 struct nine_range
*next
;
143 int16_t bgn
; /* inclusive */
144 int16_t end
; /* exclusive */
147 /* We won't ever need more than 256 ranges, so just allocate once. */
148 struct nine_range_pool
150 struct nine_range
*free
;
151 struct nine_range
**slabs
;
153 unsigned num_slabs_max
;
157 nine_range_pool_put(struct nine_range_pool
*pool
, struct nine_range
*r
)
159 r
->next
= pool
->free
;
164 nine_range_pool_put_chain(struct nine_range_pool
*pool
,
165 struct nine_range
*head
,
166 struct nine_range
*tail
)
168 tail
->next
= pool
->free
;
173 nine_ranges_insert(struct nine_range
**head
, int16_t bgn
, int16_t end
,
174 struct nine_range_pool
*pool
);
176 #endif /* _NINE_HELPERS_H_ */