1 /*
2 * WinG support
3 *
4 * Copyright (C) Robert Pouliot <krynos@clic.net>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "wownt32.h"
29 #include "wine/wingdi16.h"
30 #include "wine/list.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(wing);
34
35 struct dib_segptr_bits
36 {
37 struct list entry;
38 HBITMAP bmp;
39 WORD sel;
40 WORD count;
41 };
42
43 static struct list dib_segptr_list = LIST_INIT( dib_segptr_list );
44
45 /* remove saved bits for bitmaps that no longer exist */
46 static void cleanup_segptr_bits(void)
47 {
48 unsigned int i;
49 struct dib_segptr_bits *bits, *next;
50
51 LIST_FOR_EACH_ENTRY_SAFE( bits, next, &dib_segptr_list, struct dib_segptr_bits, entry )
52 {
53 if (GetObjectType( bits->bmp ) == OBJ_BITMAP) continue;
54 for (i = 0; i < bits->count; i++) FreeSelector16( bits->sel + (i << __AHSHIFT) );
55 list_remove( &bits->entry );
56 HeapFree( GetProcessHeap(), 0, bits );
57 }
58 }
59
60 static SEGPTR alloc_segptr_bits( HBITMAP bmp, void *bits32 )
61 {
62 DIBSECTION dib;
63 unsigned int i, size;
64 struct dib_segptr_bits *bits;
65
66 cleanup_segptr_bits();
67
68 if (!(bits = HeapAlloc( GetProcessHeap(), 0, sizeof(*bits) ))) return 0;
69
70 GetObjectW( bmp, sizeof(dib), &dib );
71 size = dib.dsBm.bmHeight * dib.dsBm.bmWidthBytes;
72
73 /* calculate number of sel's needed for size with 64K steps */
74 bits->bmp = bmp;
75 bits->count = (size + 0xffff) / 0x10000;
76 bits->sel = AllocSelectorArray16( bits->count );
77
78 for (i = 0; i < bits->count; i++)
79 {
80 SetSelectorBase(bits->sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000);
81 SetSelectorLimit16(bits->sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */
82 size -= 0x10000;
83 }
84 list_add_head( &dib_segptr_list, &bits->entry );
85 return MAKESEGPTR( bits->sel, 0 );
86 }
87
88 /*************************************************************************
89 * WING {WING}
90 *
91 * The Windows Game dll provides a number of functions designed to allow
92 * programmers to bypass Gdi and write directly to video memory. The intention
93 * was to bolster the use of Windows as a gaming platform and remove the
94 * need for Dos based games using 32 bit Dos extenders.
95 *
96 * This initial approach could not compete with the performance of Dos games
97 * (such as Doom and Warcraft) at the time, and so this dll was eventually
98 * superseded by DirectX. It should not be used by new applications, and is
99 * provided only for compatibility with older Windows programs.
100 */
101
102 typedef enum WING_DITHER_TYPE
103 {
104 WING_DISPERSED_4x4, WING_DISPERSED_8x8, WING_CLUSTERED_4x4
105 } WING_DITHER_TYPE;
106
107 /***********************************************************************
108 * WinGCreateDC (WING.1001)
109 *
110 * Create a new WinG device context.
111 *
112 * PARAMS
113 * None.
114 *
115 * RETURNS
116 * Success: A handle to the created device context.
117 * Failure: A NULL handle.
118 */
119 HDC16 WINAPI WinGCreateDC16(void)
120 {
121 TRACE("(void)\n");
122 return HDC_16( CreateCompatibleDC( 0 ));
123 }
124
125 /***********************************************************************
126 * WinGRecommendDIBFormat (WING.1002)
127 *
128 * Get the recommended format of bitmaps for the current display.
129 *
130 * PARAMS
131 * bmpi [O] Destination for format information
132 *
133 * RETURNS
134 * Success: TRUE. bmpi is filled with the best (fastest) bitmap format
135 * Failure: FALSE, if bmpi is NULL.
136 */
137 BOOL16 WINAPI WinGRecommendDIBFormat16(BITMAPINFO *bmpi)
138 {
139 TRACE("(%p)\n", bmpi);
140
141 if (!bmpi)
142 return FALSE;
143
144 bmpi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
145 bmpi->bmiHeader.biWidth = 320;
146 bmpi->bmiHeader.biHeight = -1;
147 bmpi->bmiHeader.biPlanes = 1;
148 bmpi->bmiHeader.biBitCount = 8;
149 bmpi->bmiHeader.biCompression = BI_RGB;
150 bmpi->bmiHeader.biSizeImage = 0;
151 bmpi->bmiHeader.biXPelsPerMeter = 0;
152 bmpi->bmiHeader.biYPelsPerMeter = 0;
153 bmpi->bmiHeader.biClrUsed = 0;
154 bmpi->bmiHeader.biClrImportant = 0;
155
156 return TRUE;
157 }
158
159 /***********************************************************************
160 * WinGCreateBitmap (WING.1003)
161 *
162 * Create a new WinG bitmap.
163 *
164 * PARAMS
165 * hdc [I] WinG device context
166 * bmpi [I] Information about the bitmap
167 * bits [I] Location of the bitmap image data
168 *
169 * RETURNS
170 * Success: A handle to the created bitmap.
171 * Failure: A NULL handle.
172 */
173 HBITMAP16 WINAPI WinGCreateBitmap16(HDC16 hdc, BITMAPINFO *bmpi, SEGPTR *bits)
174 {
175 LPVOID bits32;
176 HBITMAP hbitmap;
177
178 TRACE("(%d,%p,%p): create %dx%dx%d bitmap\n", hdc, bmpi, bits,
179 bmpi->bmiHeader.biWidth, bmpi->bmiHeader.biHeight, bmpi->bmiHeader.biPlanes);
180
181 hbitmap = CreateDIBSection( HDC_32(hdc), bmpi, DIB_RGB_COLORS, &bits32, 0, 0 );
182 if (hbitmap)
183 {
184 SEGPTR segptr = alloc_segptr_bits( hbitmap, bits32 );
185 if (bits) *bits = segptr;
186 }
187 return HBITMAP_16(hbitmap);
188 }
189
190 /***********************************************************************
191 * WinGGetDIBPointer (WING.1004)
192 */
193 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
194 {
195 struct dib_segptr_bits *bits;
196
197 if (bmpi) FIXME( "%04x %p: setting BITMAPINFO not supported\n", hWinGBitmap, bmpi );
198
199 LIST_FOR_EACH_ENTRY( bits, &dib_segptr_list, struct dib_segptr_bits, entry )
200 if (HBITMAP_16(bits->bmp) == hWinGBitmap) return MAKESEGPTR( bits->sel, 0 );
201
202 return 0;
203 }
204
205 /***********************************************************************
206 * WinGSetDIBColorTable (WING.1006)
207 *
208 * Set all or part of the color table for a WinG device context.
209 *
210 * PARAMS
211 * hdc [I] WinG device context
212 * start [I] Start color
213 * num [I] Number of entries to set
214 * colors [I] Array of color data
215 *
216 * RETURNS
217 * The number of entries set.
218 */
219 UINT16 WINAPI WinGSetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
220 {
221 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
222 return SetDIBColorTable( HDC_32(hdc), start, num, colors );
223 }
224
225 /***********************************************************************
226 * WinGGetDIBColorTable (WING.1005)
227 *
228 * Get all or part of the color table for a WinG device context.
229 *
230 * PARAMS
231 * hdc [I] WinG device context
232 * start [I] Start color
233 * num [I] Number of entries to set
234 * colors [O] Destination for the array of color data
235 *
236 * RETURNS
237 * The number of entries retrieved.
238 */
239 UINT16 WINAPI WinGGetDIBColorTable16(HDC16 hdc, UINT16 start, UINT16 num, RGBQUAD *colors)
240 {
241 TRACE("(%d,%d,%d,%p)\n", hdc, start, num, colors);
242 return GetDIBColorTable( HDC_32(hdc), start, num, colors );
243 }
244
245 /***********************************************************************
246 * WinGCreateHalfTonePalette (WING.1007)
247 *
248 * Create a half tone palette.
249 *
250 * PARAMS
251 * None.
252 *
253 * RETURNS
254 * Success: A handle to the created palette.
255 * Failure: A NULL handle.
256 */
257 HPALETTE16 WINAPI WinGCreateHalfTonePalette16(void)
258 {
259 HDC hdc = CreateCompatibleDC(0);
260 HPALETTE16 ret = HPALETTE_16( CreateHalftonePalette( hdc ));
261 TRACE("(void)\n");
262 DeleteDC( hdc );
263 return ret;
264 }
265
266 /***********************************************************************
267 * WinGCreateHalfToneBrush (WING.1008)
268 *
269 * Create a half tone brush for a WinG device context.
270 *
271 * PARAMS
272 * winDC [I] WinG device context
273 * col [I] Color
274 * type [I] Desired dithering type.
275 *
276 * RETURNS
277 * Success: A handle to the created brush.
278 * Failure: A NULL handle.
279 */
280 HBRUSH16 WINAPI WinGCreateHalfToneBrush16(HDC16 winDC, COLORREF col,
281 WING_DITHER_TYPE type)
282 {
283 TRACE("(%d,%d,%d)\n", winDC, col, type);
284 return HBRUSH_16( CreateSolidBrush( col ));
285 }
286
287 /***********************************************************************
288 * WinGStretchBlt (WING.1009)
289 *
290 * See StretchBlt16.
291 */
292 BOOL16 WINAPI WinGStretchBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
293 INT16 widDest, INT16 heiDest,
294 HDC16 srcDC, INT16 xSrc, INT16 ySrc,
295 INT16 widSrc, INT16 heiSrc)
296 {
297 BOOL retval;
298 TRACE("(%d,%d,...)\n", destDC, srcDC);
299 SetStretchBltMode( HDC_32(destDC), COLORONCOLOR );
300 retval = StretchBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest,
301 HDC_32(srcDC), xSrc, ySrc, widSrc, heiSrc, SRCCOPY );
302 SetStretchBltMode( HDC_32(destDC), BLACKONWHITE );
303 return retval;
304 }
305
306 /***********************************************************************
307 * WinGBitBlt (WING.1010)
308 *
309 * See BitBlt16.
310 */
311 BOOL16 WINAPI WinGBitBlt16(HDC16 destDC, INT16 xDest, INT16 yDest,
312 INT16 widDest, INT16 heiDest, HDC16 srcDC,
313 INT16 xSrc, INT16 ySrc)
314 {
315 TRACE("(%d,%d,...)\n", destDC, srcDC);
316 return BitBlt( HDC_32(destDC), xDest, yDest, widDest, heiDest, HDC_32(srcDC), xSrc, ySrc, SRCCOPY );
317 }
318
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.