1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
31 #include "p_context.h"
32 #include "p_defines.h"
42 /* XXX: these are a kludge. will fix when all surfaces are views into
43 * textures, and free-floating winsys surfaces go away.
46 pipe_surface_map( struct pipe_surface
*surf
, unsigned flags
)
49 struct pipe_screen
*screen
= surf
->texture
->screen
;
50 return surf
->texture
->screen
->surface_map( screen
, surf
, flags
);
53 struct pipe_winsys
*winsys
= surf
->winsys
;
54 char *map
= (char *)winsys
->buffer_map( winsys
, surf
->buffer
, flags
);
57 return (void *)(map
+ surf
->offset
);
62 pipe_surface_unmap( struct pipe_surface
*surf
)
65 struct pipe_screen
*screen
= surf
->texture
->screen
;
66 surf
->texture
->screen
->surface_unmap( screen
, surf
);
69 struct pipe_winsys
*winsys
= surf
->winsys
;
70 winsys
->buffer_unmap( winsys
, surf
->buffer
);
77 * Set 'ptr' to point to 'surf' and update reference counting.
78 * The old thing pointed to, if any, will be unreferenced first.
82 pipe_surface_reference(struct pipe_surface
**ptr
, struct pipe_surface
*surf
)
84 /* bump the refcount first */
90 /* There are currently two sorts of surfaces... This needs to be
91 * fixed so that all surfaces are views into a texture.
93 if ((*ptr
)->texture
) {
94 struct pipe_screen
*screen
= (*ptr
)->texture
->screen
;
95 screen
->tex_surface_release( screen
, ptr
);
98 struct pipe_winsys
*winsys
= (*ptr
)->winsys
;
99 winsys
->surface_release(winsys
, ptr
);
109 /* XXX: thread safety issues!
112 pipe_buffer_reference(struct pipe_winsys
*winsys
,
113 struct pipe_buffer
**ptr
,
114 struct pipe_buffer
*buf
)
119 if (*ptr
&& --(*ptr
)->refcount
== 0)
120 winsys
->buffer_destroy( winsys
, *ptr
);
128 * \sa pipe_surface_reference
131 pipe_texture_reference(struct pipe_texture
**ptr
,
132 struct pipe_texture
*pt
)
140 struct pipe_screen
*screen
= (*ptr
)->screen
;
142 screen
->texture_release(screen
, ptr
);
152 pipe_texture_release(struct pipe_texture
**ptr
)
154 struct pipe_screen
*screen
;
156 screen
= (*ptr
)->screen
;
157 screen
->texture_release(screen
, ptr
);
163 * Convenience wrappers for winsys buffer functions.
166 static INLINE
struct pipe_buffer
*
167 pipe_buffer_create( struct pipe_context
*pipe
,
168 unsigned alignment
, unsigned usage
, unsigned size
)
170 return pipe
->winsys
->buffer_create(pipe
->winsys
, alignment
, usage
, size
);
173 static INLINE
struct pipe_buffer
*
174 pipe_user_buffer_create( struct pipe_context
*pipe
, void *ptr
, unsigned size
)
176 return pipe
->winsys
->user_buffer_create(pipe
->winsys
, ptr
, size
);
180 pipe_buffer_destroy( struct pipe_context
*pipe
, struct pipe_buffer
*buf
)
182 pipe
->winsys
->buffer_destroy(pipe
->winsys
, buf
);
186 pipe_buffer_map(struct pipe_context
*pipe
,
187 struct pipe_buffer
*buf
,
190 return pipe
->winsys
->buffer_map(pipe
->winsys
, buf
, usage
);
194 pipe_buffer_unmap(struct pipe_context
*pipe
,
195 struct pipe_buffer
*buf
)
197 pipe
->winsys
->buffer_unmap(pipe
->winsys
, buf
);
200 /* XXX when we're using this everywhere, get rid of
201 * pipe_buffer_reference() above.
204 pipe_reference_buffer(struct pipe_context
*pipe
,
205 struct pipe_buffer
**ptr
,
206 struct pipe_buffer
*buf
)
208 pipe_buffer_reference(pipe
->winsys
, ptr
, buf
);
216 #endif /* P_INLINES_H */