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 * Set 'ptr' to point to 'surf' and update reference counting.
43 * The old thing pointed to, if any, will be unreferenced first.
47 pipe_surface_reference(struct pipe_surface
**ptr
, struct pipe_surface
*surf
)
49 /* bump the refcount first */
51 assert(surf
->refcount
);
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
);
69 * \sa pipe_surface_reference
72 pipe_transfer_reference(struct pipe_transfer
**ptr
, struct pipe_transfer
*trans
)
74 /* bump the refcount first */
76 assert(trans
->refcount
);
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
);
94 * \sa pipe_surface_reference
97 pipe_texture_reference(struct pipe_texture
**ptr
,
98 struct pipe_texture
*pt
)
103 assert(pt
->refcount
);
108 struct pipe_screen
*screen
= (*ptr
)->screen
;
110 assert((*ptr
)->refcount
);
111 screen
->texture_release(screen
, ptr
);
121 pipe_texture_release(struct pipe_texture
**ptr
)
123 struct pipe_screen
*screen
;
125 screen
= (*ptr
)->screen
;
126 assert((*ptr
)->refcount
);
127 screen
->texture_release(screen
, ptr
);
133 * Convenience wrappers for screen buffer functions.
136 static INLINE
struct pipe_buffer
*
137 pipe_buffer_create( struct pipe_screen
*screen
,
138 unsigned alignment
, unsigned usage
, unsigned size
)
140 return screen
->buffer_create(screen
, alignment
, usage
, size
);
143 static INLINE
struct pipe_buffer
*
144 pipe_user_buffer_create( struct pipe_screen
*screen
, void *ptr
, unsigned size
)
146 return screen
->user_buffer_create(screen
, ptr
, size
);
150 pipe_buffer_map(struct pipe_screen
*screen
,
151 struct pipe_buffer
*buf
,
154 if(screen
->buffer_map_range
) {
156 unsigned length
= buf
->size
;
157 return screen
->buffer_map_range(screen
, buf
, offset
, length
, usage
);
160 return screen
->buffer_map(screen
, buf
, usage
);
164 pipe_buffer_unmap(struct pipe_screen
*screen
,
165 struct pipe_buffer
*buf
)
167 screen
->buffer_unmap(screen
, buf
);
171 pipe_buffer_map_range(struct pipe_screen
*screen
,
172 struct pipe_buffer
*buf
,
177 if(screen
->buffer_map_range
)
178 return screen
->buffer_map_range(screen
, buf
, offset
, length
, usage
);
181 map
= screen
->buffer_map(screen
, buf
, usage
);
182 return map
? map
+ offset
: NULL
;
187 pipe_buffer_flush_mapped_range(struct pipe_screen
*screen
,
188 struct pipe_buffer
*buf
,
192 if(screen
->buffer_flush_mapped_range
)
193 screen
->buffer_flush_mapped_range(screen
, buf
, offset
, length
);
197 pipe_buffer_write(struct pipe_screen
*screen
,
198 struct pipe_buffer
*buf
,
199 unsigned offset
, unsigned size
,
204 assert(offset
< buf
->size
);
205 assert(offset
+ size
<= buf
->size
);
207 map
= pipe_buffer_map_range(screen
, buf
, offset
, size
, PIPE_BUFFER_USAGE_CPU_WRITE
);
210 memcpy(map
, data
, size
);
211 pipe_buffer_flush_mapped_range(screen
, buf
, offset
, size
);
212 pipe_buffer_unmap(screen
, buf
);
217 pipe_buffer_read(struct pipe_screen
*screen
,
218 struct pipe_buffer
*buf
,
219 unsigned offset
, unsigned size
,
224 assert(offset
< buf
->size
);
225 assert(offset
+ size
<= buf
->size
);
227 map
= pipe_buffer_map_range(screen
, buf
, offset
, size
, PIPE_BUFFER_USAGE_CPU_READ
);
230 memcpy(data
, map
, size
);
231 pipe_buffer_unmap(screen
, buf
);
235 /* XXX: thread safety issues!
238 pipe_buffer_reference(struct pipe_screen
*screen
,
239 struct pipe_buffer
**ptr
,
240 struct pipe_buffer
*buf
)
243 assert(buf
->refcount
);
248 assert((*ptr
)->refcount
);
249 if(--(*ptr
)->refcount
== 0) {
250 screen
->buffer_destroy( screen
, *ptr
);
262 #endif /* P_INLINES_H */