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 **************************************************************************/
31 * GDI software rasterizer support.
33 * @author Jose Fonseca <jfonseca@vmware.com>
39 #include "pipe/p_format.h"
40 #include "pipe/p_context.h"
41 #include "util/u_inlines.h"
42 #include "util/u_format.h"
43 #include "util/u_math.h"
44 #include "util/u_memory.h"
45 #include "state_tracker/sw_winsys.h"
46 #include "gdi_sw_winsys.h"
49 struct gdi_sw_displaytarget
51 enum pipe_format format;
65 static INLINE struct gdi_sw_displaytarget *
66 gdi_sw_displaytarget( struct sw_displaytarget *buf )
68 return (struct gdi_sw_displaytarget *)buf;
73 gdi_sw_is_displaytarget_format_supported( struct sw_winsys *ws,
75 enum pipe_format format )
78 case PIPE_FORMAT_B8G8R8X8_UNORM:
79 case PIPE_FORMAT_B8G8R8A8_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_sw_displaytarget_map(struct sw_winsys *ws,
93 struct sw_displaytarget *dt,
96 struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt);
103 gdi_sw_displaytarget_unmap(struct sw_winsys *ws,
104 struct sw_displaytarget *dt )
111 gdi_sw_displaytarget_destroy(struct sw_winsys *winsys,
112 struct sw_displaytarget *dt)
114 struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt);
116 align_free(gdt->data);
121 static struct sw_displaytarget *
122 gdi_sw_displaytarget_create(struct sw_winsys *winsys,
124 enum pipe_format format,
125 unsigned width, unsigned height,
129 struct gdi_sw_displaytarget *gdt;
133 gdt = CALLOC_STRUCT(gdi_sw_displaytarget);
137 gdt->format = format;
139 gdt->height = height;
141 bpp = util_format_get_blocksizebits(format);
142 cpp = util_format_get_blocksize(format);
144 gdt->stride = align(width * cpp, alignment);
145 gdt->size = gdt->stride * height;
147 gdt->data = align_malloc(gdt->size, alignment);
151 gdt->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
152 gdt->bmi.bmiHeader.biWidth = gdt->stride / cpp;
153 gdt->bmi.bmiHeader.biHeight= -(long)height;
154 gdt->bmi.bmiHeader.biPlanes = 1;
155 gdt->bmi.bmiHeader.biBitCount = bpp;
156 gdt->bmi.bmiHeader.biCompression = BI_RGB;
157 gdt->bmi.bmiHeader.biSizeImage = 0;
158 gdt->bmi.bmiHeader.biXPelsPerMeter = 0;
159 gdt->bmi.bmiHeader.biYPelsPerMeter = 0;
160 gdt->bmi.bmiHeader.biClrUsed = 0;
161 gdt->bmi.bmiHeader.biClrImportant = 0;
163 *stride = gdt->stride;
164 return (struct sw_displaytarget *)gdt;
173 static struct sw_displaytarget *
174 gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys,
175 const struct pipe_resource *templet,
176 struct winsys_handle *whandle,
185 gdi_sw_displaytarget_get_handle(struct sw_winsys *winsys,
186 struct sw_displaytarget *dt,
187 struct winsys_handle *whandle)
195 gdi_sw_display( struct sw_winsys *winsys,
196 struct sw_displaytarget *dt,
199 struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt);
202 0, 0, gdt->width, gdt->height,
203 0, 0, gdt->width, gdt->height,
204 gdt->data, &gdt->bmi, 0, SRCCOPY);
208 gdi_sw_displaytarget_display(struct sw_winsys *winsys,
209 struct sw_displaytarget *dt,
210 void *context_private)
214 HDC hDC = (HDC)context_private;
216 gdi_sw_display(winsys, dt, hDC);
221 gdi_sw_destroy(struct sw_winsys *winsys)
227 gdi_create_sw_winsys(void)
229 static struct sw_winsys *winsys;
231 winsys = CALLOC_STRUCT(sw_winsys);
235 winsys->destroy = gdi_sw_destroy;
236 winsys->is_displaytarget_format_supported = gdi_sw_is_displaytarget_format_supported;
237 winsys->displaytarget_create = gdi_sw_displaytarget_create;
238 winsys->displaytarget_from_handle = gdi_sw_displaytarget_from_handle;
239 winsys->displaytarget_get_handle = gdi_sw_displaytarget_get_handle;
240 winsys->displaytarget_map = gdi_sw_displaytarget_map;
241 winsys->displaytarget_unmap = gdi_sw_displaytarget_unmap;
242 winsys->displaytarget_display = gdi_sw_displaytarget_display;
243 winsys->displaytarget_destroy = gdi_sw_displaytarget_destroy;