1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
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 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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
33 * @author Keith Whitwell
35 * @author Jose Fonseca
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 "pipe/p_inlines.h"
43 #include "util/u_math.h"
44 #include "util/u_memory.h"
45 #include "softpipe/sp_winsys.h"
46 #include "st_winsys.h"
49 struct st_softpipe_buffer
51 struct pipe_buffer base
;
52 boolean userBuffer
; /** Is this a user-space buffer? */
59 static INLINE
struct st_softpipe_buffer
*
60 st_softpipe_buffer( struct pipe_buffer
*buf
)
62 return (struct st_softpipe_buffer
*)buf
;
67 st_softpipe_buffer_map(struct pipe_winsys
*winsys
,
68 struct pipe_buffer
*buf
,
71 struct st_softpipe_buffer
*st_softpipe_buf
= st_softpipe_buffer(buf
);
72 st_softpipe_buf
->mapped
= st_softpipe_buf
->data
;
73 return st_softpipe_buf
->mapped
;
78 st_softpipe_buffer_unmap(struct pipe_winsys
*winsys
,
79 struct pipe_buffer
*buf
)
81 struct st_softpipe_buffer
*st_softpipe_buf
= st_softpipe_buffer(buf
);
82 st_softpipe_buf
->mapped
= NULL
;
87 st_softpipe_buffer_destroy(struct pipe_winsys
*winsys
,
88 struct pipe_buffer
*buf
)
90 struct st_softpipe_buffer
*oldBuf
= st_softpipe_buffer(buf
);
93 if (!oldBuf
->userBuffer
)
94 align_free(oldBuf
->data
);
104 st_softpipe_flush_frontbuffer(struct pipe_winsys
*winsys
,
105 struct pipe_surface
*surf
,
106 void *context_private
)
113 st_softpipe_get_name(struct pipe_winsys
*winsys
)
119 static struct pipe_buffer
*
120 st_softpipe_buffer_create(struct pipe_winsys
*winsys
,
125 struct st_softpipe_buffer
*buffer
= CALLOC_STRUCT(st_softpipe_buffer
);
127 pipe_reference_init(&buffer
->base
.reference
, 1);
128 buffer
->base
.alignment
= alignment
;
129 buffer
->base
.usage
= usage
;
130 buffer
->base
.size
= size
;
132 buffer
->data
= align_malloc(size
, alignment
);
134 return &buffer
->base
;
139 * Create buffer which wraps user-space data.
141 static struct pipe_buffer
*
142 st_softpipe_user_buffer_create(struct pipe_winsys
*winsys
,
146 struct st_softpipe_buffer
*buffer
;
148 buffer
= CALLOC_STRUCT(st_softpipe_buffer
);
152 pipe_reference_init(&buffer
->base
.reference
, 1);
153 buffer
->base
.size
= bytes
;
154 buffer
->userBuffer
= TRUE
;
157 return &buffer
->base
;
162 * Round n up to next multiple.
164 static INLINE
unsigned
165 round_up(unsigned n
, unsigned multiple
)
167 return (n
+ multiple
- 1) & ~(multiple
- 1);
171 static struct pipe_buffer
*
172 st_softpipe_surface_buffer_create(struct pipe_winsys
*winsys
,
173 unsigned width
, unsigned height
,
174 enum pipe_format format
,
178 const unsigned alignment
= 64;
179 struct pipe_format_block block
;
180 unsigned nblocksx
, nblocksy
;
182 pf_get_block(format
, &block
);
183 nblocksx
= pf_get_nblocksx(&block
, width
);
184 nblocksy
= pf_get_nblocksy(&block
, height
);
185 *stride
= round_up(nblocksx
* block
.size
, alignment
);
187 return winsys
->buffer_create(winsys
, alignment
,
194 st_softpipe_fence_reference(struct pipe_winsys
*winsys
,
195 struct pipe_fence_handle
**ptr
,
196 struct pipe_fence_handle
*fence
)
202 st_softpipe_fence_signalled(struct pipe_winsys
*winsys
,
203 struct pipe_fence_handle
*fence
,
211 st_softpipe_fence_finish(struct pipe_winsys
*winsys
,
212 struct pipe_fence_handle
*fence
,
220 st_softpipe_destroy(struct pipe_winsys
*winsys
)
226 static struct pipe_screen
*
227 st_softpipe_screen_create(void)
229 static struct pipe_winsys
*winsys
;
230 struct pipe_screen
*screen
;
232 winsys
= CALLOC_STRUCT(pipe_winsys
);
236 winsys
->destroy
= st_softpipe_destroy
;
238 winsys
->buffer_create
= st_softpipe_buffer_create
;
239 winsys
->user_buffer_create
= st_softpipe_user_buffer_create
;
240 winsys
->buffer_map
= st_softpipe_buffer_map
;
241 winsys
->buffer_unmap
= st_softpipe_buffer_unmap
;
242 winsys
->buffer_destroy
= st_softpipe_buffer_destroy
;
244 winsys
->surface_buffer_create
= st_softpipe_surface_buffer_create
;
246 winsys
->fence_reference
= st_softpipe_fence_reference
;
247 winsys
->fence_signalled
= st_softpipe_fence_signalled
;
248 winsys
->fence_finish
= st_softpipe_fence_finish
;
250 winsys
->flush_frontbuffer
= st_softpipe_flush_frontbuffer
;
251 winsys
->get_name
= st_softpipe_get_name
;
253 screen
= softpipe_create_screen(winsys
);
255 st_softpipe_destroy(winsys
);
261 static struct pipe_context
*
262 st_softpipe_context_create(struct pipe_screen
*screen
)
264 return softpipe_create(screen
, screen
->winsys
, NULL
);
268 const struct st_winsys st_softpipe_winsys
= {
269 &st_softpipe_screen_create
,
270 &st_softpipe_context_create
,