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 **************************************************************************/
30 * Implementation of client buffer (also designated as "user buffers"), which
31 * are just state-tracker owned data masqueraded as buffers.
33 * \author José Fonseca <jrfonseca@tungstengraphics.com>
37 #include "pipe/p_winsys.h"
38 #include "util/u_memory.h"
40 #include "pb_buffer.h"
44 * User buffers are special buffers that initially reference memory
45 * held by the user but which may if necessary copy that memory into
46 * device memory behind the scenes, for submission to hardware.
48 * These are particularly useful when the referenced data is never
49 * submitted to hardware at all, in the particular case of software
54 struct pb_buffer base
;
59 extern const struct pb_vtbl pb_user_buffer_vtbl
;
62 static INLINE
struct pb_user_buffer
*
63 pb_user_buffer(struct pb_buffer
*buf
)
66 assert(buf
->vtbl
== &pb_user_buffer_vtbl
);
67 return (struct pb_user_buffer
*)buf
;
72 pb_user_buffer_destroy(struct pb_buffer
*buf
)
80 pb_user_buffer_map(struct pb_buffer
*buf
,
83 return pb_user_buffer(buf
)->data
;
88 pb_user_buffer_unmap(struct pb_buffer
*buf
)
95 pb_user_buffer_get_base_buffer(struct pb_buffer
*buf
,
96 struct pb_buffer
**base_buf
,
105 pb_user_buffer_vtbl
= {
106 pb_user_buffer_destroy
,
108 pb_user_buffer_unmap
,
109 pb_user_buffer_get_base_buffer
113 static struct pipe_buffer
*
114 pb_winsys_user_buffer_create(struct pipe_winsys
*winsys
,
118 struct pb_user_buffer
*buf
= CALLOC_STRUCT(pb_user_buffer
);
123 buf
->base
.base
.refcount
= 1;
124 buf
->base
.base
.size
= bytes
;
125 buf
->base
.base
.alignment
= 0;
126 buf
->base
.base
.usage
= 0;
128 buf
->base
.vtbl
= &pb_user_buffer_vtbl
;
131 return &buf
->base
.base
;
136 pb_winsys_buffer_map(struct pipe_winsys
*winsys
,
137 struct pipe_buffer
*buf
,
141 return pb_map(pb_buffer(buf
), flags
);
146 pb_winsys_buffer_unmap(struct pipe_winsys
*winsys
,
147 struct pipe_buffer
*buf
)
150 pb_unmap(pb_buffer(buf
));
155 pb_winsys_buffer_destroy(struct pipe_winsys
*winsys
,
156 struct pipe_buffer
*buf
)
159 pb_destroy(pb_buffer(buf
));
164 pb_init_winsys(struct pipe_winsys
*winsys
)
166 winsys
->user_buffer_create
= pb_winsys_user_buffer_create
;
167 winsys
->buffer_map
= pb_winsys_buffer_map
;
168 winsys
->buffer_unmap
= pb_winsys_buffer_unmap
;
169 winsys
->buffer_destroy
= pb_winsys_buffer_destroy
;