gallium: Define PIPE_PRIM_MAX.
[mesa.git] / src / gallium / include / pipe / p_inlines.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef P_INLINES_H
29 #define P_INLINES_H
30
31 #include "p_context.h"
32 #include "p_defines.h"
33 #include "p_screen.h"
34
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40
41 /**
42 * Set 'ptr' to point to 'surf' and update reference counting.
43 * The old thing pointed to, if any, will be unreferenced first.
44 * 'surf' may be NULL.
45 */
46 static INLINE void
47 pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
48 {
49 /* bump the refcount first */
50 if (surf) {
51 assert(surf->refcount);
52 surf->refcount++;
53 }
54
55 if (*ptr) {
56 struct pipe_screen *screen;
57 assert((*ptr)->refcount);
58 assert((*ptr)->texture);
59 screen = (*ptr)->texture->screen;
60 screen->tex_surface_release( screen, ptr );
61 assert(!*ptr);
62 }
63
64 *ptr = surf;
65 }
66
67
68 /**
69 * \sa pipe_surface_reference
70 */
71 static INLINE void
72 pipe_transfer_reference(struct pipe_transfer **ptr, struct pipe_transfer *trans)
73 {
74 /* bump the refcount first */
75 if (trans) {
76 assert(trans->refcount);
77 trans->refcount++;
78 }
79
80 if (*ptr) {
81 struct pipe_screen *screen;
82 assert((*ptr)->refcount);
83 assert((*ptr)->texture);
84 screen = (*ptr)->texture->screen;
85 screen->tex_transfer_release( screen, ptr );
86 assert(!*ptr);
87 }
88
89 *ptr = trans;
90 }
91
92
93 /**
94 * \sa pipe_surface_reference
95 */
96 static INLINE void
97 pipe_texture_reference(struct pipe_texture **ptr,
98 struct pipe_texture *pt)
99 {
100 assert(ptr);
101
102 if (pt) {
103 assert(pt->refcount);
104 pt->refcount++;
105 }
106
107 if (*ptr) {
108 struct pipe_screen *screen = (*ptr)->screen;
109 assert(screen);
110 assert((*ptr)->refcount);
111 screen->texture_release(screen, ptr);
112
113 assert(!*ptr);
114 }
115
116 *ptr = pt;
117 }
118
119
120 static INLINE void
121 pipe_texture_release(struct pipe_texture **ptr)
122 {
123 struct pipe_screen *screen;
124 assert(ptr);
125 screen = (*ptr)->screen;
126 assert((*ptr)->refcount);
127 screen->texture_release(screen, ptr);
128 *ptr = NULL;
129 }
130
131
132 /**
133 * Convenience wrappers for screen buffer functions.
134 */
135
136 static INLINE struct pipe_buffer *
137 pipe_buffer_create( struct pipe_screen *screen,
138 unsigned alignment, unsigned usage, unsigned size )
139 {
140 return screen->buffer_create(screen, alignment, usage, size);
141 }
142
143 static INLINE struct pipe_buffer *
144 pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size )
145 {
146 return screen->user_buffer_create(screen, ptr, size);
147 }
148
149 static INLINE void *
150 pipe_buffer_map(struct pipe_screen *screen,
151 struct pipe_buffer *buf,
152 unsigned usage)
153 {
154 return screen->buffer_map(screen, buf, usage);
155 }
156
157 static INLINE void
158 pipe_buffer_unmap(struct pipe_screen *screen,
159 struct pipe_buffer *buf)
160 {
161 screen->buffer_unmap(screen, buf);
162 }
163
164 /* XXX: thread safety issues!
165 */
166 static INLINE void
167 pipe_buffer_reference(struct pipe_screen *screen,
168 struct pipe_buffer **ptr,
169 struct pipe_buffer *buf)
170 {
171 if (buf) {
172 assert(buf->refcount);
173 buf->refcount++;
174 }
175
176 if (*ptr) {
177 assert((*ptr)->refcount);
178 if(--(*ptr)->refcount == 0) {
179 screen->buffer_destroy( screen, *ptr );
180 }
181 }
182
183 *ptr = buf;
184 }
185
186
187 #ifdef __cplusplus
188 }
189 #endif
190
191 #endif /* P_INLINES_H */