Add tests for NORM_IGNORENONSPACE and NORM_IGNORESYMBOLS in the
[wine/wine64.git] / dlls / gdi / driver.c
blobd184ca9ec89226c8da0ee29a1906900d02776eaa
1 /*
2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <string.h>
25 #include "winbase.h"
26 #include "winreg.h"
28 #include "gdi.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(driver);
33 struct graphics_driver
35 struct graphics_driver *next;
36 struct graphics_driver *prev;
37 HMODULE module; /* module handle */
38 unsigned int count; /* reference count */
39 DC_FUNCTIONS funcs;
42 static struct graphics_driver *first_driver;
43 static struct graphics_driver *display_driver;
44 static CRITICAL_SECTION driver_section = CRITICAL_SECTION_INIT( "driver_section" );
46 /**********************************************************************
47 * create_driver
49 * Allocate and fill the driver structure for a given module.
51 static struct graphics_driver *create_driver( HMODULE module )
53 struct graphics_driver *driver;
55 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
56 driver->next = NULL;
57 driver->prev = NULL;
58 driver->module = module;
59 driver->count = 1;
61 /* fill the function table */
63 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
65 GET_FUNC(AbortDoc);
66 GET_FUNC(AbortPath);
67 GET_FUNC(AngleArc);
68 GET_FUNC(Arc);
69 GET_FUNC(ArcTo);
70 GET_FUNC(BeginPath);
71 GET_FUNC(BitBlt);
72 GET_FUNC(ChoosePixelFormat);
73 GET_FUNC(Chord);
74 GET_FUNC(CloseFigure);
75 GET_FUNC(CreateBitmap);
76 GET_FUNC(CreateDC);
77 GET_FUNC(CreateDIBSection);
78 GET_FUNC(DeleteBitmap);
79 GET_FUNC(DeleteDC);
80 GET_FUNC(DescribePixelFormat);
81 GET_FUNC(DeviceCapabilities);
82 GET_FUNC(Ellipse);
83 GET_FUNC(EndDoc);
84 GET_FUNC(EndPage);
85 GET_FUNC(EndPath);
86 GET_FUNC(EnumDeviceFonts);
87 GET_FUNC(ExcludeClipRect);
88 GET_FUNC(ExtDeviceMode);
89 GET_FUNC(ExtEscape);
90 GET_FUNC(ExtFloodFill);
91 GET_FUNC(ExtSelectClipRgn);
92 GET_FUNC(ExtTextOut);
93 GET_FUNC(FillPath);
94 GET_FUNC(FillRgn);
95 GET_FUNC(FlattenPath);
96 GET_FUNC(FrameRgn);
97 GET_FUNC(GdiComment);
98 GET_FUNC(GetBitmapBits);
99 GET_FUNC(GetCharWidth);
100 GET_FUNC(GetDCOrgEx);
101 GET_FUNC(GetDIBColorTable);
102 GET_FUNC(GetDIBits);
103 GET_FUNC(GetDeviceCaps);
104 GET_FUNC(GetDeviceGammaRamp);
105 GET_FUNC(GetNearestColor);
106 GET_FUNC(GetPixel);
107 GET_FUNC(GetPixelFormat);
108 GET_FUNC(GetSystemPaletteEntries);
109 GET_FUNC(GetTextExtentPoint);
110 GET_FUNC(GetTextMetrics);
111 GET_FUNC(IntersectClipRect);
112 GET_FUNC(InvertRgn);
113 GET_FUNC(LineTo);
114 GET_FUNC(MoveTo);
115 GET_FUNC(ModifyWorldTransform);
116 GET_FUNC(OffsetClipRgn);
117 GET_FUNC(OffsetViewportOrg);
118 GET_FUNC(OffsetWindowOrg);
119 GET_FUNC(PaintRgn);
120 GET_FUNC(PatBlt);
121 GET_FUNC(Pie);
122 GET_FUNC(PolyBezier);
123 GET_FUNC(PolyBezierTo);
124 GET_FUNC(PolyDraw);
125 GET_FUNC(PolyPolygon);
126 GET_FUNC(PolyPolyline);
127 GET_FUNC(Polygon);
128 GET_FUNC(Polyline);
129 GET_FUNC(PolylineTo);
130 GET_FUNC(RealizeDefaultPalette);
131 GET_FUNC(RealizePalette);
132 GET_FUNC(Rectangle);
133 GET_FUNC(ResetDC);
134 GET_FUNC(RestoreDC);
135 GET_FUNC(RoundRect);
136 GET_FUNC(SaveDC);
137 GET_FUNC(ScaleViewportExt);
138 GET_FUNC(ScaleWindowExt);
139 GET_FUNC(SelectBitmap);
140 GET_FUNC(SelectBrush);
141 GET_FUNC(SelectClipPath);
142 GET_FUNC(SelectFont);
143 GET_FUNC(SelectPalette);
144 GET_FUNC(SelectPen);
145 GET_FUNC(SetBitmapBits);
146 GET_FUNC(SetBkColor);
147 GET_FUNC(SetBkMode);
148 GET_FUNC(SetDCOrg);
149 GET_FUNC(SetDIBColorTable);
150 GET_FUNC(SetDIBits);
151 GET_FUNC(SetDIBitsToDevice);
152 GET_FUNC(SetDeviceClipping);
153 GET_FUNC(SetDeviceGammaRamp);
154 GET_FUNC(SetMapMode);
155 GET_FUNC(SetMapperFlags);
156 GET_FUNC(SetPixel);
157 GET_FUNC(SetPixelFormat);
158 GET_FUNC(SetPolyFillMode);
159 GET_FUNC(SetROP2);
160 GET_FUNC(SetRelAbs);
161 GET_FUNC(SetStretchBltMode);
162 GET_FUNC(SetTextAlign);
163 GET_FUNC(SetTextCharacterExtra);
164 GET_FUNC(SetTextColor);
165 GET_FUNC(SetTextJustification);
166 GET_FUNC(SetViewportExt);
167 GET_FUNC(SetViewportOrg);
168 GET_FUNC(SetWindowExt);
169 GET_FUNC(SetWindowOrg);
170 GET_FUNC(SetWorldTransform);
171 GET_FUNC(StartDoc);
172 GET_FUNC(StartPage);
173 GET_FUNC(StretchBlt);
174 GET_FUNC(StretchDIBits);
175 GET_FUNC(StrokeAndFillPath);
176 GET_FUNC(StrokePath);
177 GET_FUNC(SwapBuffers);
178 GET_FUNC(WidenPath);
179 #undef GET_FUNC
181 /* add it to the list */
182 driver->prev = NULL;
183 if ((driver->next = first_driver)) driver->next->prev = driver;
184 first_driver = driver;
185 return driver;
189 /**********************************************************************
190 * load_display_driver
192 * Special case for loading the display driver: get the name from the config file
194 static struct graphics_driver *load_display_driver(void)
196 char buffer[MAX_PATH];
197 HMODULE module;
198 HKEY hkey;
200 if (display_driver) /* already loaded */
202 display_driver->count++;
203 return display_driver;
206 strcpy( buffer, "x11drv" ); /* default value */
207 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
209 DWORD type, count = sizeof(buffer);
210 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
211 RegCloseKey( hkey );
214 if (!(module = LoadLibraryA( buffer )))
216 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
217 return NULL;
220 if (!(display_driver = create_driver( module )))
222 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
223 FreeLibrary( module );
224 return NULL;
227 display_driver->count++; /* we don't want to free it */
228 return display_driver;
232 /**********************************************************************
233 * DRIVER_load_driver
235 const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name )
237 HMODULE module;
238 struct graphics_driver *driver;
240 EnterCriticalSection( &driver_section );
242 /* display driver is a special case */
243 if (!strcasecmp( name, "display" ))
245 driver = load_display_driver();
246 LeaveCriticalSection( &driver_section );
247 return &driver->funcs;
250 if ((module = GetModuleHandleA( name )))
252 for (driver = first_driver; driver; driver = driver->next)
254 if (driver->module == module)
256 driver->count++;
257 LeaveCriticalSection( &driver_section );
258 return &driver->funcs;
263 if (!(module = LoadLibraryA( name )))
265 LeaveCriticalSection( &driver_section );
266 return NULL;
269 if (!(driver = create_driver( module )))
271 FreeLibrary( module );
272 LeaveCriticalSection( &driver_section );
273 return NULL;
276 TRACE( "loaded driver %p for %s\n", driver, name );
277 LeaveCriticalSection( &driver_section );
278 return &driver->funcs;
282 /**********************************************************************
283 * DRIVER_get_driver
285 * Get a new copy of an existing driver.
287 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
289 struct graphics_driver *driver;
291 EnterCriticalSection( &driver_section );
292 for (driver = first_driver; driver; driver = driver->next)
293 if (&driver->funcs == funcs) break;
294 if (!driver) ERR( "driver not found, trouble ahead\n" );
295 driver->count++;
296 LeaveCriticalSection( &driver_section );
297 return funcs;
301 /**********************************************************************
302 * DRIVER_release_driver
304 * Release a driver by decrementing ref count and freeing it if needed.
306 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
308 struct graphics_driver *driver;
310 EnterCriticalSection( &driver_section );
312 for (driver = first_driver; driver; driver = driver->next)
313 if (&driver->funcs == funcs) break;
315 if (!driver) goto done;
316 if (--driver->count) goto done;
318 /* removed last reference, free it */
319 if (driver->next) driver->next->prev = driver->prev;
320 if (driver->prev) driver->prev->next = driver->next;
321 else first_driver = driver->next;
322 if (driver == display_driver) display_driver = NULL;
324 FreeLibrary( driver->module );
325 HeapFree( GetProcessHeap(), 0, driver );
326 done:
327 LeaveCriticalSection( &driver_section );
331 /*****************************************************************************
332 * DRIVER_GetDriverName
335 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
337 char *p;
339 /* display is a special case */
340 if (!strcasecmp( device, "display" ))
342 lstrcpynA( driver, "display", size );
343 return TRUE;
346 size = GetProfileStringA("devices", device, "", driver, size);
347 if(!size) {
348 WARN("Unable to find '%s' in [devices] section of win.ini\n", device);
349 return FALSE;
351 p = strchr(driver, ',');
352 if(!p)
354 WARN("'%s' entry in [devices] section of win.ini is malformed.\n", device);
355 return FALSE;
357 *p = '\0';
358 TRACE("Found '%s' for '%s'\n", driver, device);
359 return TRUE;
362 /*****************************************************************************
363 * @ [GDI32.100]
365 * This should thunk to 16-bit and simply call the proc with the given args.
367 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
368 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
370 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
371 return -1;
374 /*****************************************************************************
375 * @ [GDI32.101]
377 * This should load the correct driver for lpszDevice and calls this driver's
378 * ExtDeviceModePropSheet proc.
380 * Note: The driver calls a callback routine for each property sheet page; these
381 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
382 * The layout of this structure is:
384 * struct
386 * DWORD nPages;
387 * DWORD unknown;
388 * HPROPSHEETPAGE pages[10];
389 * };
391 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
392 LPCSTR lpszPort, LPVOID lpPropSheet )
394 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
395 return -1;
398 /*****************************************************************************
399 * @ [GDI32.102]
401 * This should load the correct driver for lpszDevice and calls this driver's
402 * ExtDeviceMode proc.
404 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
405 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
406 LPSTR lpszPort, LPDEVMODEA lpdmInput,
407 LPSTR lpszProfile, DWORD fwMode )
409 char buf[300];
410 HDC hdc;
411 DC *dc;
412 INT ret = -1;
413 INT (*pExtDeviceMode)(LPSTR,HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,DWORD);
415 TRACE("(%p, %p, %s, %s, %p, %s, %ld)\n",
416 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
418 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
420 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
422 if ((dc = DC_GetDCPtr( hdc )))
424 pExtDeviceMode = dc->funcs->pExtDeviceMode;
425 GDI_ReleaseObj( hdc );
426 if (pExtDeviceMode)
427 ret = pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
428 lpdmInput, lpszProfile, fwMode);
430 DeleteDC( hdc );
431 return ret;
434 /****************************************************************************
435 * @ [GDI32.103]
437 * This should load the correct driver for lpszDevice and calls this driver's
438 * AdvancedSetupDialog proc.
440 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
441 LPDEVMODEA devin, LPDEVMODEA devout )
443 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
444 return -1;
447 /*****************************************************************************
448 * @ [GDI32.104]
450 * This should load the correct driver for lpszDevice and calls this driver's
451 * DeviceCapabilities proc.
453 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
454 WORD fwCapability, LPSTR lpszOutput,
455 LPDEVMODEA lpdm )
457 char buf[300];
458 HDC hdc;
459 DC *dc;
460 INT ret = -1;
462 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
464 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
466 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
468 if ((dc = DC_GetDCPtr( hdc )))
470 if (dc->funcs->pDeviceCapabilities)
471 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
472 fwCapability, lpszOutput, lpdm );
473 GDI_ReleaseObj( hdc );
475 DeleteDC( hdc );
476 return ret;