radeon/r200/r300: cleanup some of the renderbuffer code
[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 /* XXX: these are a kludge. will fix when all surfaces are views into
42 * textures, and free-floating winsys surfaces go away.
43 */
44 static INLINE void *
45 pipe_surface_map( struct pipe_surface *surf, unsigned flags )
46 {
47 struct pipe_screen *screen;
48 assert(surf->texture);
49 screen = surf->texture->screen;
50 return screen->surface_map( screen, surf, flags );
51 }
52
53 static INLINE void
54 pipe_surface_unmap( struct pipe_surface *surf )
55 {
56 struct pipe_screen *screen;
57 assert(surf->texture);
58 screen = surf->texture->screen;
59 screen->surface_unmap( screen, surf );
60 }
61
62
63
64 /**
65 * Set 'ptr' to point to 'surf' and update reference counting.
66 * The old thing pointed to, if any, will be unreferenced first.
67 * 'surf' may be NULL.
68 */
69 static INLINE void
70 pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
71 {
72 /* bump the refcount first */
73 if (surf) {
74 assert(surf->refcount);
75 surf->refcount++;
76 }
77
78 if (*ptr) {
79 struct pipe_screen *screen;
80 assert((*ptr)->refcount);
81 assert((*ptr)->texture);
82 screen = (*ptr)->texture->screen;
83 screen->tex_surface_release( screen, ptr );
84 assert(!*ptr);
85 }
86
87 *ptr = surf;
88 }
89
90
91 /**
92 * \sa pipe_surface_reference
93 */
94 static INLINE void
95 pipe_texture_reference(struct pipe_texture **ptr,
96 struct pipe_texture *pt)
97 {
98 assert(ptr);
99
100 if (pt) {
101 assert(pt->refcount);
102 pt->refcount++;
103 }
104
105 if (*ptr) {
106 struct pipe_screen *screen = (*ptr)->screen;
107 assert(screen);
108 assert((*ptr)->refcount);
109 screen->texture_release(screen, ptr);
110
111 assert(!*ptr);
112 }
113
114 *ptr = pt;
115 }
116
117
118 static INLINE void
119 pipe_texture_release(struct pipe_texture **ptr)
120 {
121 struct pipe_screen *screen;
122 assert(ptr);
123 screen = (*ptr)->screen;
124 assert((*ptr)->refcount);
125 screen->texture_release(screen, ptr);
126 *ptr = NULL;
127 }
128
129
130 /**
131 * Convenience wrappers for screen buffer functions.
132 */
133
134 static INLINE struct pipe_buffer *
135 pipe_buffer_create( struct pipe_screen *screen,
136 unsigned alignment, unsigned usage, unsigned size )
137 {
138 return screen->buffer_create(screen, alignment, usage, size);
139 }
140
141 static INLINE struct pipe_buffer *
142 pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size )
143 {
144 return screen->user_buffer_create(screen, ptr, size);
145 }
146
147 static INLINE void *
148 pipe_buffer_map(struct pipe_screen *screen,
149 struct pipe_buffer *buf,
150 unsigned usage)
151 {
152 return screen->buffer_map(screen, buf, usage);
153 }
154
155 static INLINE void
156 pipe_buffer_unmap(struct pipe_screen *screen,
157 struct pipe_buffer *buf)
158 {
159 screen->buffer_unmap(screen, buf);
160 }
161
162 /* XXX: thread safety issues!
163 */
164 static INLINE void
165 pipe_buffer_reference(struct pipe_screen *screen,
166 struct pipe_buffer **ptr,
167 struct pipe_buffer *buf)
168 {
169 if (buf) {
170 assert(buf->refcount);
171 buf->refcount++;
172 }
173
174 if (*ptr) {
175 assert((*ptr)->refcount);
176 if(--(*ptr)->refcount == 0) {
177 screen->buffer_destroy( screen, *ptr );
178 }
179 }
180
181 *ptr = buf;
182 }
183
184
185 #ifdef __cplusplus
186 }
187 #endif
188
189 #endif /* P_INLINES_H */