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 */
86 assert(surf
->refcount
);
91 assert((*ptr
)->refcount
);
93 /* There are currently two sorts of surfaces... This needs to be
94 * fixed so that all surfaces are views into a texture.
96 if ((*ptr
)->texture
) {
97 struct pipe_screen
*screen
= (*ptr
)->texture
->screen
;
98 screen
->tex_surface_release( screen
, ptr
);
101 struct pipe_winsys
*winsys
= (*ptr
)->winsys
;
102 winsys
->surface_release(winsys
, ptr
);
112 /* XXX: thread safety issues!
115 winsys_buffer_reference(struct pipe_winsys
*winsys
,
116 struct pipe_buffer
**ptr
,
117 struct pipe_buffer
*buf
)
120 assert(buf
->refcount
);
125 assert((*ptr
)->refcount
);
126 if(--(*ptr
)->refcount
== 0)
127 winsys
->buffer_destroy( winsys
, *ptr
);
136 * \sa pipe_surface_reference
139 pipe_texture_reference(struct pipe_texture
**ptr
,
140 struct pipe_texture
*pt
)
145 assert(pt
->refcount
);
150 struct pipe_screen
*screen
= (*ptr
)->screen
;
152 assert((*ptr
)->refcount
);
153 screen
->texture_release(screen
, ptr
);
163 pipe_texture_release(struct pipe_texture
**ptr
)
165 struct pipe_screen
*screen
;
167 screen
= (*ptr
)->screen
;
168 assert((*ptr
)->refcount
);
169 screen
->texture_release(screen
, ptr
);
175 * Convenience wrappers for winsys buffer functions.
178 static INLINE
struct pipe_buffer
*
179 pipe_buffer_create( struct pipe_screen
*screen
,
180 unsigned alignment
, unsigned usage
, unsigned size
)
182 return screen
->winsys
->buffer_create(screen
->winsys
, alignment
, usage
, size
);
185 static INLINE
struct pipe_buffer
*
186 pipe_user_buffer_create( struct pipe_screen
*screen
, void *ptr
, unsigned size
)
188 return screen
->winsys
->user_buffer_create(screen
->winsys
, ptr
, size
);
192 pipe_buffer_map(struct pipe_screen
*screen
,
193 struct pipe_buffer
*buf
,
196 return screen
->winsys
->buffer_map(screen
->winsys
, buf
, usage
);
200 pipe_buffer_unmap(struct pipe_screen
*screen
,
201 struct pipe_buffer
*buf
)
203 screen
->winsys
->buffer_unmap(screen
->winsys
, buf
);
206 /* XXX when we're using this everywhere, get rid of
207 * winsys_buffer_reference() above.
210 pipe_buffer_reference(struct pipe_screen
*screen
,
211 struct pipe_buffer
**ptr
,
212 struct pipe_buffer
*buf
)
214 winsys_buffer_reference(screen
->winsys
, ptr
, buf
);
222 #endif /* P_INLINES_H */