1 /**************************************************************************
3 * Copyright 2008 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
41 #include "pipe/internal/p_winsys_screen.h"
42 #include "pipe/p_format.h"
43 #include "pipe/p_context.h"
44 #include "pipe/p_inlines.h"
45 #include "util/u_math.h"
46 #include "util/u_memory.h"
47 #include "softpipe/sp_winsys.h"
48 #include "stw_winsys.h"
51 struct gdi_softpipe_buffer
53 struct pipe_buffer base
;
54 boolean userBuffer
; /** Is this a user-space buffer? */
61 static INLINE
struct gdi_softpipe_buffer
*
62 gdi_softpipe_buffer( struct pipe_buffer
*buf
)
64 return (struct gdi_softpipe_buffer
*)buf
;
69 gdi_softpipe_buffer_map(struct pipe_winsys
*winsys
,
70 struct pipe_buffer
*buf
,
73 struct gdi_softpipe_buffer
*gdi_softpipe_buf
= gdi_softpipe_buffer(buf
);
74 gdi_softpipe_buf
->mapped
= gdi_softpipe_buf
->data
;
75 return gdi_softpipe_buf
->mapped
;
80 gdi_softpipe_buffer_unmap(struct pipe_winsys
*winsys
,
81 struct pipe_buffer
*buf
)
83 struct gdi_softpipe_buffer
*gdi_softpipe_buf
= gdi_softpipe_buffer(buf
);
84 gdi_softpipe_buf
->mapped
= NULL
;
89 gdi_softpipe_buffer_destroy(struct pipe_winsys
*winsys
,
90 struct pipe_buffer
*buf
)
92 struct gdi_softpipe_buffer
*oldBuf
= gdi_softpipe_buffer(buf
);
95 if (!oldBuf
->userBuffer
)
96 align_free(oldBuf
->data
);
106 gdi_softpipe_get_name(struct pipe_winsys
*winsys
)
112 static struct pipe_buffer
*
113 gdi_softpipe_buffer_create(struct pipe_winsys
*winsys
,
118 struct gdi_softpipe_buffer
*buffer
= CALLOC_STRUCT(gdi_softpipe_buffer
);
120 buffer
->base
.refcount
= 1;
121 buffer
->base
.alignment
= alignment
;
122 buffer
->base
.usage
= usage
;
123 buffer
->base
.size
= size
;
125 buffer
->data
= align_malloc(size
, alignment
);
127 return &buffer
->base
;
132 * Create buffer which wraps user-space data.
134 static struct pipe_buffer
*
135 gdi_softpipe_user_buffer_create(struct pipe_winsys
*winsys
,
139 struct gdi_softpipe_buffer
*buffer
;
141 buffer
= CALLOC_STRUCT(gdi_softpipe_buffer
);
145 buffer
->base
.refcount
= 1;
146 buffer
->base
.size
= bytes
;
147 buffer
->userBuffer
= TRUE
;
150 return &buffer
->base
;
155 * Round n up to next multiple.
157 static INLINE
unsigned
158 round_up(unsigned n
, unsigned multiple
)
160 return (n
+ multiple
- 1) & ~(multiple
- 1);
164 static struct pipe_buffer
*
165 gdi_softpipe_surface_buffer_create(struct pipe_winsys
*winsys
,
166 unsigned width
, unsigned height
,
167 enum pipe_format format
,
171 const unsigned alignment
= 64;
172 struct pipe_format_block block
;
173 unsigned nblocksx
, nblocksy
;
175 pf_get_block(format
, &block
);
176 nblocksx
= pf_get_nblocksx(&block
, width
);
177 nblocksy
= pf_get_nblocksy(&block
, height
);
178 *stride
= round_up(nblocksx
* block
.size
, alignment
);
180 return winsys
->buffer_create(winsys
, alignment
,
187 gdi_softpipe_dummy_flush_frontbuffer(struct pipe_winsys
*winsys
,
188 struct pipe_surface
*surface
,
189 void *context_private
)
196 gdi_softpipe_fence_reference(struct pipe_winsys
*winsys
,
197 struct pipe_fence_handle
**ptr
,
198 struct pipe_fence_handle
*fence
)
204 gdi_softpipe_fence_signalled(struct pipe_winsys
*winsys
,
205 struct pipe_fence_handle
*fence
,
213 gdi_softpipe_fence_finish(struct pipe_winsys
*winsys
,
214 struct pipe_fence_handle
*fence
,
222 gdi_softpipe_destroy(struct pipe_winsys
*winsys
)
228 static struct pipe_screen
*
229 gdi_softpipe_screen_create(void)
231 static struct pipe_winsys
*winsys
;
232 struct pipe_screen
*screen
;
234 winsys
= CALLOC_STRUCT(pipe_winsys
);
238 winsys
->destroy
= gdi_softpipe_destroy
;
240 winsys
->buffer_create
= gdi_softpipe_buffer_create
;
241 winsys
->user_buffer_create
= gdi_softpipe_user_buffer_create
;
242 winsys
->buffer_map
= gdi_softpipe_buffer_map
;
243 winsys
->buffer_unmap
= gdi_softpipe_buffer_unmap
;
244 winsys
->buffer_destroy
= gdi_softpipe_buffer_destroy
;
246 winsys
->surface_buffer_create
= gdi_softpipe_surface_buffer_create
;
248 winsys
->fence_reference
= gdi_softpipe_fence_reference
;
249 winsys
->fence_signalled
= gdi_softpipe_fence_signalled
;
250 winsys
->fence_finish
= gdi_softpipe_fence_finish
;
252 winsys
->flush_frontbuffer
= gdi_softpipe_dummy_flush_frontbuffer
;
253 winsys
->get_name
= gdi_softpipe_get_name
;
255 screen
= softpipe_create_screen(winsys
);
257 gdi_softpipe_destroy(winsys
);
263 static struct pipe_context
*
264 gdi_softpipe_context_create(struct pipe_screen
*screen
)
266 return softpipe_create(screen
, screen
->winsys
, NULL
);
271 gdi_softpipe_flush_frontbuffer(struct pipe_screen
*screen
,
272 struct pipe_surface
*surface
,
275 struct gdi_softpipe_buffer
*buffer
;
278 buffer
= gdi_softpipe_buffer(surface
->buffer
);
280 memset(&bmi
, 0, sizeof(BITMAPINFO
));
281 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
282 bmi
.bmiHeader
.biWidth
= surface
->stride
/ pf_get_size(surface
->format
);
283 bmi
.bmiHeader
.biHeight
= -(long)surface
->height
;
284 bmi
.bmiHeader
.biPlanes
= 1;
285 bmi
.bmiHeader
.biBitCount
= pf_get_bits(surface
->format
);
286 bmi
.bmiHeader
.biCompression
= BI_RGB
;
287 bmi
.bmiHeader
.biSizeImage
= 0;
288 bmi
.bmiHeader
.biXPelsPerMeter
= 0;
289 bmi
.bmiHeader
.biYPelsPerMeter
= 0;
290 bmi
.bmiHeader
.biClrUsed
= 0;
291 bmi
.bmiHeader
.biClrImportant
= 0;
294 0, 0, surface
->width
, surface
->height
,
295 0, 0, surface
->width
, surface
->height
,
296 buffer
->data
, &bmi
, 0, SRCCOPY
);
300 static const struct stw_winsys stw_winsys
= {
301 &gdi_softpipe_screen_create
,
302 &gdi_softpipe_context_create
,
303 &gdi_softpipe_flush_frontbuffer
308 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
311 case DLL_PROCESS_ATTACH
:
312 return st_init(&stw_winsys
);
314 case DLL_PROCESS_DETACH
: