softpipe: Remove unnecessary header.
[mesa.git] / src / gallium / drivers / softpipe / sp_winsys.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28
29 /**
30 * @file
31 * Malloc softpipe winsys. Uses malloc for all memory allocations.
32 *
33 * @author Keith Whitwell
34 * @author Brian Paul
35 * @author Jose Fonseca
36 */
37
38
39 #include "pipe/internal/p_winsys_screen.h"/* port to just p_screen */
40 #include "pipe/p_format.h"
41 #include "pipe/p_context.h"
42 #include "util/u_format.h"
43 #include "util/u_math.h"
44 #include "util/u_memory.h"
45 #include "softpipe/sp_winsys.h"
46
47
48 struct st_softpipe_buffer
49 {
50 struct pipe_buffer base;
51 boolean userBuffer; /** Is this a user-space buffer? */
52 void *data;
53 void *mapped;
54 };
55
56
57 /** Cast wrapper */
58 static INLINE struct st_softpipe_buffer *
59 st_softpipe_buffer( struct pipe_buffer *buf )
60 {
61 return (struct st_softpipe_buffer *)buf;
62 }
63
64
65 static void *
66 st_softpipe_buffer_map(struct pipe_winsys *winsys,
67 struct pipe_buffer *buf,
68 unsigned flags)
69 {
70 struct st_softpipe_buffer *st_softpipe_buf = st_softpipe_buffer(buf);
71 st_softpipe_buf->mapped = st_softpipe_buf->data;
72 return st_softpipe_buf->mapped;
73 }
74
75
76 static void
77 st_softpipe_buffer_unmap(struct pipe_winsys *winsys,
78 struct pipe_buffer *buf)
79 {
80 struct st_softpipe_buffer *st_softpipe_buf = st_softpipe_buffer(buf);
81 st_softpipe_buf->mapped = NULL;
82 }
83
84
85 static void
86 st_softpipe_buffer_destroy(struct pipe_buffer *buf)
87 {
88 struct st_softpipe_buffer *oldBuf = st_softpipe_buffer(buf);
89
90 if (oldBuf->data) {
91 if (!oldBuf->userBuffer)
92 align_free(oldBuf->data);
93
94 oldBuf->data = NULL;
95 }
96
97 FREE(oldBuf);
98 }
99
100
101 static void
102 st_softpipe_flush_frontbuffer(struct pipe_winsys *winsys,
103 struct pipe_surface *surf,
104 void *context_private)
105 {
106 }
107
108
109
110 static const char *
111 st_softpipe_get_name(struct pipe_winsys *winsys)
112 {
113 return "softpipe";
114 }
115
116
117 static struct pipe_buffer *
118 st_softpipe_buffer_create(struct pipe_winsys *winsys,
119 unsigned alignment,
120 unsigned usage,
121 unsigned size)
122 {
123 struct st_softpipe_buffer *buffer = CALLOC_STRUCT(st_softpipe_buffer);
124
125 pipe_reference_init(&buffer->base.reference, 1);
126 buffer->base.alignment = alignment;
127 buffer->base.usage = usage;
128 buffer->base.size = size;
129
130 buffer->data = align_malloc(size, alignment);
131
132 return &buffer->base;
133 }
134
135
136 /**
137 * Create buffer which wraps user-space data.
138 */
139 static struct pipe_buffer *
140 st_softpipe_user_buffer_create(struct pipe_winsys *winsys,
141 void *ptr,
142 unsigned bytes)
143 {
144 struct st_softpipe_buffer *buffer;
145
146 buffer = CALLOC_STRUCT(st_softpipe_buffer);
147 if(!buffer)
148 return NULL;
149
150 pipe_reference_init(&buffer->base.reference, 1);
151 buffer->base.size = bytes;
152 buffer->userBuffer = TRUE;
153 buffer->data = ptr;
154
155 return &buffer->base;
156 }
157
158
159 static struct pipe_buffer *
160 st_softpipe_surface_buffer_create(struct pipe_winsys *winsys,
161 unsigned width, unsigned height,
162 enum pipe_format format,
163 unsigned usage,
164 unsigned tex_usage,
165 unsigned *stride)
166 {
167 const unsigned alignment = 64;
168 unsigned nblocksy;
169
170 nblocksy = util_format_get_nblocksy(format, height);
171 *stride = align(util_format_get_stride(format, width), alignment);
172
173 return winsys->buffer_create(winsys, alignment,
174 usage,
175 *stride * nblocksy);
176 }
177
178
179 static void
180 st_softpipe_fence_reference(struct pipe_winsys *winsys,
181 struct pipe_fence_handle **ptr,
182 struct pipe_fence_handle *fence)
183 {
184 }
185
186
187 static int
188 st_softpipe_fence_signalled(struct pipe_winsys *winsys,
189 struct pipe_fence_handle *fence,
190 unsigned flag)
191 {
192 return 0;
193 }
194
195
196 static int
197 st_softpipe_fence_finish(struct pipe_winsys *winsys,
198 struct pipe_fence_handle *fence,
199 unsigned flag)
200 {
201 return 0;
202 }
203
204
205 static void
206 st_softpipe_destroy(struct pipe_winsys *winsys)
207 {
208 FREE(winsys);
209 }
210
211
212 struct pipe_screen *
213 softpipe_create_screen_malloc(void)
214 {
215 static struct pipe_winsys *winsys;
216 struct pipe_screen *screen;
217
218 winsys = CALLOC_STRUCT(pipe_winsys);
219 if(!winsys)
220 return NULL;
221
222 winsys->destroy = st_softpipe_destroy;
223
224 winsys->buffer_create = st_softpipe_buffer_create;
225 winsys->user_buffer_create = st_softpipe_user_buffer_create;
226 winsys->buffer_map = st_softpipe_buffer_map;
227 winsys->buffer_unmap = st_softpipe_buffer_unmap;
228 winsys->buffer_destroy = st_softpipe_buffer_destroy;
229
230 winsys->surface_buffer_create = st_softpipe_surface_buffer_create;
231
232 winsys->fence_reference = st_softpipe_fence_reference;
233 winsys->fence_signalled = st_softpipe_fence_signalled;
234 winsys->fence_finish = st_softpipe_fence_finish;
235
236 winsys->flush_frontbuffer = st_softpipe_flush_frontbuffer;
237 winsys->get_name = st_softpipe_get_name;
238
239 screen = softpipe_create_screen(winsys);
240 if(!screen)
241 st_softpipe_destroy(winsys);
242
243 return screen;
244 }