1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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 Jose Fonseca <jfonseca@vmware.com>
39 #include "pipe/p_format.h"
40 #include "pipe/p_context.h"
41 #include "pipe/p_inlines.h"
42 #include "util/u_math.h"
43 #include "util/u_memory.h"
44 #include "llvmpipe/lp_winsys.h"
45 #include "llvmpipe/lp_texture.h"
46 #include "stw_winsys.h"
49 struct gdi_llvmpipe_displaytarget
51 enum pipe_format format
;
52 struct pipe_format_block block
;
66 static INLINE
struct gdi_llvmpipe_displaytarget
*
67 gdi_llvmpipe_displaytarget( struct llvmpipe_displaytarget
*buf
)
69 return (struct gdi_llvmpipe_displaytarget
*)buf
;
74 gdi_llvmpipe_is_displaytarget_format_supported( struct llvmpipe_winsys
*ws
,
75 enum pipe_format format
)
78 case PIPE_FORMAT_X8R8G8B8_UNORM
:
79 case PIPE_FORMAT_A8R8G8B8_UNORM
:
82 /* TODO: Support other formats possible with BMPs, as described in
83 * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */
92 gdi_llvmpipe_displaytarget_map(struct llvmpipe_winsys
*ws
,
93 struct llvmpipe_displaytarget
*dt
,
96 struct gdi_llvmpipe_displaytarget
*gdt
= gdi_llvmpipe_displaytarget(dt
);
103 gdi_llvmpipe_displaytarget_unmap(struct llvmpipe_winsys
*ws
,
104 struct llvmpipe_displaytarget
*dt
)
111 gdi_llvmpipe_displaytarget_destroy(struct llvmpipe_winsys
*winsys
,
112 struct llvmpipe_displaytarget
*dt
)
114 struct gdi_llvmpipe_displaytarget
*gdt
= gdi_llvmpipe_displaytarget(dt
);
116 align_free(gdt
->data
);
122 * Round n up to next multiple.
124 static INLINE
unsigned
125 round_up(unsigned n
, unsigned multiple
)
127 return (n
+ multiple
- 1) & ~(multiple
- 1);
131 static struct llvmpipe_displaytarget
*
132 gdi_llvmpipe_displaytarget_create(struct llvmpipe_winsys
*winsys
,
133 enum pipe_format format
,
134 unsigned width
, unsigned height
,
138 struct gdi_llvmpipe_displaytarget
*gdt
;
142 gdt
= CALLOC_STRUCT(gdi_llvmpipe_displaytarget
);
146 gdt
->format
= format
;
148 gdt
->height
= height
;
150 bpp
= pf_get_bits(format
);
151 cpp
= pf_get_size(format
);
153 gdt
->stride
= round_up(width
* cpp
, alignment
);
154 gdt
->size
= gdt
->stride
* height
;
156 gdt
->data
= align_malloc(gdt
->size
, alignment
);
160 gdt
->bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
161 gdt
->bmi
.bmiHeader
.biWidth
= gdt
->stride
/ cpp
;
162 gdt
->bmi
.bmiHeader
.biHeight
= -(long)height
;
163 gdt
->bmi
.bmiHeader
.biPlanes
= 1;
164 gdt
->bmi
.bmiHeader
.biBitCount
= bpp
;
165 gdt
->bmi
.bmiHeader
.biCompression
= BI_RGB
;
166 gdt
->bmi
.bmiHeader
.biSizeImage
= 0;
167 gdt
->bmi
.bmiHeader
.biXPelsPerMeter
= 0;
168 gdt
->bmi
.bmiHeader
.biYPelsPerMeter
= 0;
169 gdt
->bmi
.bmiHeader
.biClrUsed
= 0;
170 gdt
->bmi
.bmiHeader
.biClrImportant
= 0;
172 *stride
= gdt
->stride
;
173 return (struct llvmpipe_displaytarget
*)gdt
;
183 gdi_llvmpipe_displaytarget_display(struct llvmpipe_winsys
*winsys
,
184 struct llvmpipe_displaytarget
*dt
,
185 void *context_private
)
192 gdi_llvmpipe_destroy(struct llvmpipe_winsys
*winsys
)
198 static struct pipe_screen
*
199 gdi_llvmpipe_screen_create(void)
201 static struct llvmpipe_winsys
*winsys
;
202 struct pipe_screen
*screen
;
204 winsys
= CALLOC_STRUCT(llvmpipe_winsys
);
208 winsys
->destroy
= gdi_llvmpipe_destroy
;
209 winsys
->is_displaytarget_format_supported
= gdi_llvmpipe_is_displaytarget_format_supported
;
210 winsys
->displaytarget_create
= gdi_llvmpipe_displaytarget_create
;
211 winsys
->displaytarget_map
= gdi_llvmpipe_displaytarget_map
;
212 winsys
->displaytarget_unmap
= gdi_llvmpipe_displaytarget_unmap
;
213 winsys
->displaytarget_display
= gdi_llvmpipe_displaytarget_display
;
214 winsys
->displaytarget_destroy
= gdi_llvmpipe_displaytarget_destroy
;
216 screen
= llvmpipe_create_screen(winsys
);
229 static struct pipe_context
*
230 gdi_llvmpipe_context_create(struct pipe_screen
*screen
)
232 return llvmpipe_create(screen
);
237 gdi_llvmpipe_present(struct pipe_screen
*screen
,
238 struct pipe_surface
*surface
,
241 struct llvmpipe_texture
*texture
;
242 struct gdi_llvmpipe_displaytarget
*gdt
;
244 texture
= llvmpipe_texture(surface
->texture
);
245 gdt
= gdi_llvmpipe_displaytarget(texture
->dt
);
248 0, 0, gdt
->width
, gdt
->height
,
249 0, 0, gdt
->width
, gdt
->height
,
250 gdt
->data
, &gdt
->bmi
, 0, SRCCOPY
);
254 static const struct stw_winsys stw_winsys
= {
255 &gdi_llvmpipe_screen_create
,
256 &gdi_llvmpipe_context_create
,
257 &gdi_llvmpipe_present
,
258 NULL
, /* get_adapter_luid */
259 NULL
, /* shared_surface_open */
260 NULL
, /* shared_surface_close */
266 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
269 case DLL_PROCESS_ATTACH
:
270 if (!stw_init(&stw_winsys
)) {
273 return stw_init_thread();
275 case DLL_THREAD_ATTACH
:
276 return stw_init_thread();
278 case DLL_THREAD_DETACH
:
279 stw_cleanup_thread();
282 case DLL_PROCESS_DETACH
:
283 stw_cleanup_thread();