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
;
65 static INLINE
struct gdi_llvmpipe_displaytarget
*
66 gdi_llvmpipe_displaytarget( struct llvmpipe_displaytarget
*buf
)
68 return (struct gdi_llvmpipe_displaytarget
*)buf
;
73 gdi_llvmpipe_is_displaytarget_format_supported( struct llvmpipe_winsys
*ws
,
74 enum pipe_format format
)
77 case PIPE_FORMAT_X8R8G8B8_UNORM
:
78 case PIPE_FORMAT_A8R8G8B8_UNORM
:
81 /* TODO: Support other formats possible with BMPs, as described in
82 * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */
91 gdi_llvmpipe_displaytarget_map(struct llvmpipe_winsys
*ws
,
92 struct llvmpipe_displaytarget
*dt
,
95 struct gdi_llvmpipe_displaytarget
*gdt
= gdi_llvmpipe_displaytarget(dt
);
102 gdi_llvmpipe_displaytarget_unmap(struct llvmpipe_winsys
*ws
,
103 struct llvmpipe_displaytarget
*dt
)
110 gdi_llvmpipe_displaytarget_destroy(struct llvmpipe_winsys
*winsys
,
111 struct llvmpipe_displaytarget
*dt
)
113 struct gdi_llvmpipe_displaytarget
*gdt
= gdi_llvmpipe_displaytarget(dt
);
115 align_free(gdt
->data
);
120 static struct llvmpipe_displaytarget
*
121 gdi_llvmpipe_displaytarget_create(struct llvmpipe_winsys
*winsys
,
122 enum pipe_format format
,
123 unsigned width
, unsigned height
,
127 struct gdi_llvmpipe_displaytarget
*gdt
;
131 gdt
= CALLOC_STRUCT(gdi_llvmpipe_displaytarget
);
135 gdt
->format
= format
;
137 gdt
->height
= height
;
139 bpp
= pf_get_blocksizebits(format
);
140 cpp
= pf_get_blocksize(format
);
142 gdt
->stride
= align(width
* cpp
, alignment
);
143 gdt
->size
= gdt
->stride
* height
;
145 gdt
->data
= align_malloc(gdt
->size
, alignment
);
149 gdt
->bmi
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
150 gdt
->bmi
.bmiHeader
.biWidth
= gdt
->stride
/ cpp
;
151 gdt
->bmi
.bmiHeader
.biHeight
= -(long)height
;
152 gdt
->bmi
.bmiHeader
.biPlanes
= 1;
153 gdt
->bmi
.bmiHeader
.biBitCount
= bpp
;
154 gdt
->bmi
.bmiHeader
.biCompression
= BI_RGB
;
155 gdt
->bmi
.bmiHeader
.biSizeImage
= 0;
156 gdt
->bmi
.bmiHeader
.biXPelsPerMeter
= 0;
157 gdt
->bmi
.bmiHeader
.biYPelsPerMeter
= 0;
158 gdt
->bmi
.bmiHeader
.biClrUsed
= 0;
159 gdt
->bmi
.bmiHeader
.biClrImportant
= 0;
161 *stride
= gdt
->stride
;
162 return (struct llvmpipe_displaytarget
*)gdt
;
172 gdi_llvmpipe_displaytarget_display(struct llvmpipe_winsys
*winsys
,
173 struct llvmpipe_displaytarget
*dt
,
174 void *context_private
)
181 gdi_llvmpipe_destroy(struct llvmpipe_winsys
*winsys
)
187 static struct pipe_screen
*
188 gdi_llvmpipe_screen_create(void)
190 static struct llvmpipe_winsys
*winsys
;
191 struct pipe_screen
*screen
;
193 winsys
= CALLOC_STRUCT(llvmpipe_winsys
);
197 winsys
->destroy
= gdi_llvmpipe_destroy
;
198 winsys
->is_displaytarget_format_supported
= gdi_llvmpipe_is_displaytarget_format_supported
;
199 winsys
->displaytarget_create
= gdi_llvmpipe_displaytarget_create
;
200 winsys
->displaytarget_map
= gdi_llvmpipe_displaytarget_map
;
201 winsys
->displaytarget_unmap
= gdi_llvmpipe_displaytarget_unmap
;
202 winsys
->displaytarget_display
= gdi_llvmpipe_displaytarget_display
;
203 winsys
->displaytarget_destroy
= gdi_llvmpipe_displaytarget_destroy
;
205 screen
= llvmpipe_create_screen(winsys
);
218 static struct pipe_context
*
219 gdi_llvmpipe_context_create(struct pipe_screen
*screen
)
221 return llvmpipe_create(screen
);
226 gdi_llvmpipe_present(struct pipe_screen
*screen
,
227 struct pipe_surface
*surface
,
230 struct llvmpipe_texture
*texture
;
231 struct gdi_llvmpipe_displaytarget
*gdt
;
233 texture
= llvmpipe_texture(surface
->texture
);
234 gdt
= gdi_llvmpipe_displaytarget(texture
->dt
);
237 0, 0, gdt
->width
, gdt
->height
,
238 0, 0, gdt
->width
, gdt
->height
,
239 gdt
->data
, &gdt
->bmi
, 0, SRCCOPY
);
243 static const struct stw_winsys stw_winsys
= {
244 &gdi_llvmpipe_screen_create
,
245 &gdi_llvmpipe_context_create
,
246 &gdi_llvmpipe_present
,
247 NULL
, /* get_adapter_luid */
248 NULL
, /* shared_surface_open */
249 NULL
, /* shared_surface_close */
255 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
258 case DLL_PROCESS_ATTACH
:
259 if (!stw_init(&stw_winsys
)) {
262 return stw_init_thread();
264 case DLL_THREAD_ATTACH
:
265 return stw_init_thread();
267 case DLL_THREAD_DETACH
:
268 stw_cleanup_thread();
271 case DLL_PROCESS_DETACH
:
272 stw_cleanup_thread();