Code reorganization: s/aux/auxiliary/.
[mesa.git] / src / gallium / auxiliary / pipebuffer / pb_winsys.c
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 /**
29 * \file
30 * Implementation of client buffer (also designated as "user buffers"), which
31 * are just state-tracker owned data masqueraded as buffers.
32 *
33 * \author José Fonseca <jrfonseca@tungstengraphics.com>
34 */
35
36
37 #include "pipe/p_winsys.h"
38 #include "pipe/p_util.h"
39
40 #include "pb_buffer.h"
41
42
43 /**
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.
47 *
48 * These are particularly useful when the referenced data is never
49 * submitted to hardware at all, in the particular case of software
50 * vertex processing.
51 */
52 struct pb_user_buffer
53 {
54 struct pb_buffer base;
55 void *data;
56 };
57
58
59 extern const struct pb_vtbl pb_user_buffer_vtbl;
60
61
62 static INLINE struct pb_user_buffer *
63 pb_user_buffer(struct pb_buffer *buf)
64 {
65 assert(buf);
66 assert(buf->vtbl == &pb_user_buffer_vtbl);
67 return (struct pb_user_buffer *)buf;
68 }
69
70
71 static void
72 pb_user_buffer_destroy(struct pb_buffer *buf)
73 {
74 assert(buf);
75 FREE(buf);
76 }
77
78
79 static void *
80 pb_user_buffer_map(struct pb_buffer *buf,
81 unsigned flags)
82 {
83 return pb_user_buffer(buf)->data;
84 }
85
86
87 static void
88 pb_user_buffer_unmap(struct pb_buffer *buf)
89 {
90 /* No-op */
91 }
92
93
94 static void
95 pb_user_buffer_get_base_buffer(struct pb_buffer *buf,
96 struct pb_buffer **base_buf,
97 unsigned *offset)
98 {
99 *base_buf = buf;
100 *offset = 0;
101 }
102
103
104 const struct pb_vtbl
105 pb_user_buffer_vtbl = {
106 pb_user_buffer_destroy,
107 pb_user_buffer_map,
108 pb_user_buffer_unmap,
109 pb_user_buffer_get_base_buffer
110 };
111
112
113 static struct pipe_buffer *
114 pb_winsys_user_buffer_create(struct pipe_winsys *winsys,
115 void *data,
116 unsigned bytes)
117 {
118 struct pb_user_buffer *buf = CALLOC_STRUCT(pb_user_buffer);
119
120 if(!buf)
121 return NULL;
122
123 buf->base.base.refcount = 1;
124 buf->base.base.size = bytes;
125 buf->base.base.alignment = 0;
126 buf->base.base.usage = 0;
127
128 buf->base.vtbl = &pb_user_buffer_vtbl;
129 buf->data = data;
130
131 return &buf->base.base;
132 }
133
134
135 static void *
136 pb_winsys_buffer_map(struct pipe_winsys *winsys,
137 struct pipe_buffer *buf,
138 unsigned flags)
139 {
140 (void)winsys;
141 return pb_map(pb_buffer(buf), flags);
142 }
143
144
145 static void
146 pb_winsys_buffer_unmap(struct pipe_winsys *winsys,
147 struct pipe_buffer *buf)
148 {
149 (void)winsys;
150 pb_unmap(pb_buffer(buf));
151 }
152
153
154 static void
155 pb_winsys_buffer_destroy(struct pipe_winsys *winsys,
156 struct pipe_buffer *buf)
157 {
158 (void)winsys;
159 pb_destroy(pb_buffer(buf));
160 }
161
162
163 void
164 pb_init_winsys(struct pipe_winsys *winsys)
165 {
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;
170 }