1 /**************************************************************************
3 * Copyright 2008 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 **************************************************************************/
29 * Totally software-based winsys layer.
30 * Note that the one winsys function that we can't implement here
31 * is flush_frontbuffer().
32 * Whoever uses this code will have to provide that.
38 #include "util/u_simple_screen.h"
39 #include "pipe/p_state.h"
40 #include "util/u_inlines.h"
41 #include "util/u_format.h"
42 #include "util/u_math.h"
43 #include "util/u_memory.h"
45 #include "sw_winsys.h"
49 /** Subclass of pipe_winsys */
52 struct pipe_winsys Base
;
53 /* no extra fields for now */
57 /** subclass of pipe_buffer */
60 struct pipe_buffer Base
;
61 boolean UserBuffer
; /** Is this a user-space buffer? */
68 static INLINE
struct sw_pipe_buffer
*
69 sw_pipe_buffer(struct pipe_buffer
*b
)
71 return (struct sw_pipe_buffer
*) b
;
76 get_name(struct pipe_winsys
*pws
)
82 /** Create new pipe_buffer and allocate storage of given size */
83 static struct pipe_buffer
*
84 buffer_create(struct pipe_winsys
*pws
,
89 struct sw_pipe_buffer
*buffer
= CALLOC_STRUCT(sw_pipe_buffer
);
93 pipe_reference_init(&buffer
->Base
.reference
, 1);
94 buffer
->Base
.alignment
= alignment
;
95 buffer
->Base
.usage
= usage
;
96 buffer
->Base
.size
= size
;
98 /* align to 16-byte multiple for Cell */
99 buffer
->Data
= align_malloc(size
, MAX2(alignment
, 16));
101 return &buffer
->Base
;
106 * Create buffer which wraps user-space data.
108 static struct pipe_buffer
*
109 user_buffer_create(struct pipe_winsys
*pws
, void *ptr
, unsigned bytes
)
111 struct sw_pipe_buffer
*buffer
= CALLOC_STRUCT(sw_pipe_buffer
);
115 pipe_reference_init(&buffer
->Base
.reference
, 1);
116 buffer
->Base
.size
= bytes
;
117 buffer
->UserBuffer
= TRUE
;
120 return &buffer
->Base
;
125 buffer_map(struct pipe_winsys
*pws
, struct pipe_buffer
*buf
, unsigned flags
)
127 struct sw_pipe_buffer
*buffer
= sw_pipe_buffer(buf
);
128 buffer
->Mapped
= buffer
->Data
;
129 return buffer
->Mapped
;
134 buffer_unmap(struct pipe_winsys
*pws
, struct pipe_buffer
*buf
)
136 struct sw_pipe_buffer
*buffer
= sw_pipe_buffer(buf
);
137 buffer
->Mapped
= NULL
;
142 buffer_destroy(struct pipe_buffer
*buf
)
144 struct sw_pipe_buffer
*buffer
= sw_pipe_buffer(buf
);
146 if (buffer
->Data
&& !buffer
->UserBuffer
) {
147 align_free(buffer
->Data
);
155 static struct pipe_buffer
*
156 surface_buffer_create(struct pipe_winsys
*winsys
,
157 unsigned width
, unsigned height
,
158 enum pipe_format format
,
163 const unsigned alignment
= 64;
166 nblocksy
= util_format_get_nblocksy(format
, height
);
167 *stride
= align(util_format_get_stride(format
, width
), alignment
);
169 return winsys
->buffer_create(winsys
, alignment
,
176 fence_reference(struct pipe_winsys
*sws
, struct pipe_fence_handle
**ptr
,
177 struct pipe_fence_handle
*fence
)
184 fence_signalled(struct pipe_winsys
*sws
, struct pipe_fence_handle
*fence
,
193 fence_finish(struct pipe_winsys
*sws
, struct pipe_fence_handle
*fence
,
202 * Create/return a new pipe_winsys object.
205 create_sw_winsys(void)
207 struct sw_pipe_winsys
*ws
= CALLOC_STRUCT(sw_pipe_winsys
);
211 /* Fill in this struct with callbacks that pipe will need to
212 * communicate with the window system, buffer manager, etc.
214 ws
->Base
.buffer_create
= buffer_create
;
215 ws
->Base
.user_buffer_create
= user_buffer_create
;
216 ws
->Base
.buffer_map
= buffer_map
;
217 ws
->Base
.buffer_unmap
= buffer_unmap
;
218 ws
->Base
.buffer_destroy
= buffer_destroy
;
220 ws
->Base
.surface_buffer_create
= surface_buffer_create
;
222 ws
->Base
.fence_reference
= fence_reference
;
223 ws
->Base
.fence_signalled
= fence_signalled
;
224 ws
->Base
.fence_finish
= fence_finish
;
226 ws
->Base
.flush_frontbuffer
= NULL
; /* not implemented here! */
228 ws
->Base
.get_name
= get_name
;