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 "util/u_simple_screen.h"
42 #include "pipe/p_format.h"
43 #include "pipe/p_context.h"
44 #include "util/u_inlines.h"
45 #include "util/u_format.h"
46 #include "util/u_math.h"
47 #include "util/u_memory.h"
48 #include "softpipe/sp_winsys.h"
49 #include "softpipe/sp_texture.h"
50 #include "stw_winsys.h"
53 struct gdi_softpipe_buffer
55 struct pipe_buffer base
;
56 boolean userBuffer
; /** Is this a user-space buffer? */
63 static INLINE
struct gdi_softpipe_buffer
*
64 gdi_softpipe_buffer( struct pipe_buffer
*buf
)
66 return (struct gdi_softpipe_buffer
*)buf
;
71 gdi_softpipe_buffer_map(struct pipe_winsys
*winsys
,
72 struct pipe_buffer
*buf
,
75 struct gdi_softpipe_buffer
*gdi_softpipe_buf
= gdi_softpipe_buffer(buf
);
76 gdi_softpipe_buf
->mapped
= gdi_softpipe_buf
->data
;
77 return gdi_softpipe_buf
->mapped
;
82 gdi_softpipe_buffer_unmap(struct pipe_winsys
*winsys
,
83 struct pipe_buffer
*buf
)
85 struct gdi_softpipe_buffer
*gdi_softpipe_buf
= gdi_softpipe_buffer(buf
);
86 gdi_softpipe_buf
->mapped
= NULL
;
91 gdi_softpipe_buffer_destroy(struct pipe_buffer
*buf
)
93 struct gdi_softpipe_buffer
*oldBuf
= gdi_softpipe_buffer(buf
);
96 if (!oldBuf
->userBuffer
)
97 align_free(oldBuf
->data
);
107 gdi_softpipe_get_name(struct pipe_winsys
*winsys
)
113 static struct pipe_buffer
*
114 gdi_softpipe_buffer_create(struct pipe_winsys
*winsys
,
119 struct gdi_softpipe_buffer
*buffer
= CALLOC_STRUCT(gdi_softpipe_buffer
);
121 pipe_reference_init(&buffer
->base
.reference
, 1);
122 buffer
->base
.alignment
= alignment
;
123 buffer
->base
.usage
= usage
;
124 buffer
->base
.size
= size
;
126 buffer
->data
= align_malloc(size
, alignment
);
128 return &buffer
->base
;
133 * Create buffer which wraps user-space data.
135 static struct pipe_buffer
*
136 gdi_softpipe_user_buffer_create(struct pipe_winsys
*winsys
,
140 struct gdi_softpipe_buffer
*buffer
;
142 buffer
= CALLOC_STRUCT(gdi_softpipe_buffer
);
146 pipe_reference_init(&buffer
->base
.reference
, 1);
147 buffer
->base
.size
= bytes
;
148 buffer
->userBuffer
= TRUE
;
151 return &buffer
->base
;
155 static struct pipe_buffer
*
156 gdi_softpipe_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 gdi_softpipe_dummy_flush_frontbuffer(struct pipe_winsys
*winsys
,
177 struct pipe_surface
*surface
,
178 void *context_private
)
185 gdi_softpipe_fence_reference(struct pipe_winsys
*winsys
,
186 struct pipe_fence_handle
**ptr
,
187 struct pipe_fence_handle
*fence
)
193 gdi_softpipe_fence_signalled(struct pipe_winsys
*winsys
,
194 struct pipe_fence_handle
*fence
,
202 gdi_softpipe_fence_finish(struct pipe_winsys
*winsys
,
203 struct pipe_fence_handle
*fence
,
211 gdi_softpipe_destroy(struct pipe_winsys
*winsys
)
217 static struct pipe_screen
*
218 gdi_softpipe_screen_create(void)
220 static struct pipe_winsys
*winsys
;
221 struct pipe_screen
*screen
;
223 winsys
= CALLOC_STRUCT(pipe_winsys
);
227 winsys
->destroy
= gdi_softpipe_destroy
;
229 winsys
->buffer_create
= gdi_softpipe_buffer_create
;
230 winsys
->user_buffer_create
= gdi_softpipe_user_buffer_create
;
231 winsys
->buffer_map
= gdi_softpipe_buffer_map
;
232 winsys
->buffer_unmap
= gdi_softpipe_buffer_unmap
;
233 winsys
->buffer_destroy
= gdi_softpipe_buffer_destroy
;
235 winsys
->surface_buffer_create
= gdi_softpipe_surface_buffer_create
;
237 winsys
->fence_reference
= gdi_softpipe_fence_reference
;
238 winsys
->fence_signalled
= gdi_softpipe_fence_signalled
;
239 winsys
->fence_finish
= gdi_softpipe_fence_finish
;
241 winsys
->flush_frontbuffer
= gdi_softpipe_dummy_flush_frontbuffer
;
242 winsys
->get_name
= gdi_softpipe_get_name
;
244 screen
= softpipe_create_screen(winsys
);
246 gdi_softpipe_destroy(winsys
);
253 gdi_softpipe_present(struct pipe_screen
*screen
,
254 struct pipe_surface
*surface
,
257 struct softpipe_texture
*texture
;
258 struct gdi_softpipe_buffer
*buffer
;
261 texture
= softpipe_texture(surface
->texture
);
263 buffer
= gdi_softpipe_buffer(texture
->buffer
);
265 memset(&bmi
, 0, sizeof(BITMAPINFO
));
266 bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
267 bmi
.bmiHeader
.biWidth
= texture
->stride
[surface
->level
] / util_format_get_blocksize(surface
->format
);
268 bmi
.bmiHeader
.biHeight
= -(long)surface
->height
;
269 bmi
.bmiHeader
.biPlanes
= 1;
270 bmi
.bmiHeader
.biBitCount
= util_format_get_blocksizebits(surface
->format
);
271 bmi
.bmiHeader
.biCompression
= BI_RGB
;
272 bmi
.bmiHeader
.biSizeImage
= 0;
273 bmi
.bmiHeader
.biXPelsPerMeter
= 0;
274 bmi
.bmiHeader
.biYPelsPerMeter
= 0;
275 bmi
.bmiHeader
.biClrUsed
= 0;
276 bmi
.bmiHeader
.biClrImportant
= 0;
279 0, 0, surface
->width
, surface
->height
,
280 0, 0, surface
->width
, surface
->height
,
281 buffer
->data
, &bmi
, 0, SRCCOPY
);
285 static const struct stw_winsys stw_winsys
= {
286 &gdi_softpipe_screen_create
,
287 &gdi_softpipe_present
,
288 NULL
, /* get_adapter_luid */
289 NULL
, /* shared_surface_open */
290 NULL
, /* shared_surface_close */
296 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
299 case DLL_PROCESS_ATTACH
:
300 if (!stw_init(&stw_winsys
)) {
303 return stw_init_thread();
305 case DLL_THREAD_ATTACH
:
306 return stw_init_thread();
308 case DLL_THREAD_DETACH
:
309 stw_cleanup_thread();
312 case DLL_PROCESS_DETACH
:
313 stw_cleanup_thread();