Add a few extra fields to HTTP_GetStdHeaderIndex.
[wine.git] / dlls / gdi / driver.c
bloba0fd1a815fbd4bc517c400ba47592adc906ff179
1 /*
2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <string.h>
8 #include "winbase.h"
9 #include "winreg.h"
10 #include "ntddk.h"
12 #include "gdi.h"
13 #include "win16drv.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(driver);
18 struct graphics_driver
20 struct graphics_driver *next;
21 struct graphics_driver *prev;
22 HMODULE module; /* module handle */
23 unsigned int count; /* reference count */
24 DC_FUNCTIONS funcs;
27 static struct graphics_driver *first_driver;
28 static struct graphics_driver *display_driver;
29 static const DC_FUNCTIONS *win16_driver;
32 /**********************************************************************
33 * create_driver
35 * Allocate and fill the driver structure for a given module.
37 static struct graphics_driver *create_driver( HMODULE module )
39 struct graphics_driver *driver;
41 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
42 driver->next = NULL;
43 driver->prev = NULL;
44 driver->module = module;
45 driver->count = 1;
47 /* fill the function table */
49 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
51 GET_FUNC(AbortDoc);
52 GET_FUNC(AbortPath);
53 GET_FUNC(AngleArc);
54 GET_FUNC(Arc);
55 GET_FUNC(ArcTo);
56 GET_FUNC(BeginPath);
57 GET_FUNC(BitBlt);
58 GET_FUNC(BitmapBits);
59 GET_FUNC(ChoosePixelFormat);
60 GET_FUNC(Chord);
61 GET_FUNC(CloseFigure);
62 GET_FUNC(CreateBitmap);
63 GET_FUNC(CreateDC);
64 GET_FUNC(CreateDIBSection);
65 GET_FUNC(DeleteDC);
66 GET_FUNC(DeleteObject);
67 GET_FUNC(DescribePixelFormat);
68 GET_FUNC(DeviceCapabilities);
69 GET_FUNC(Ellipse);
70 GET_FUNC(EndDoc);
71 GET_FUNC(EndPage);
72 GET_FUNC(EndPath);
73 GET_FUNC(EnumDeviceFonts);
74 GET_FUNC(ExcludeClipRect);
75 GET_FUNC(ExtDeviceMode);
76 GET_FUNC(ExtEscape);
77 GET_FUNC(ExtFloodFill);
78 GET_FUNC(ExtTextOut);
79 GET_FUNC(FillPath);
80 GET_FUNC(FillRgn);
81 GET_FUNC(FlattenPath);
82 GET_FUNC(FrameRgn);
83 GET_FUNC(GetCharWidth);
84 GET_FUNC(GetDCOrgEx);
85 GET_FUNC(GetDeviceCaps);
86 GET_FUNC(GetDeviceGammaRamp);
87 GET_FUNC(GetPixel);
88 GET_FUNC(GetPixelFormat);
89 GET_FUNC(GetTextExtentPoint);
90 GET_FUNC(GetTextMetrics);
91 GET_FUNC(IntersectClipRect);
92 GET_FUNC(InvertRgn);
93 GET_FUNC(LineTo);
94 GET_FUNC(MoveTo);
95 GET_FUNC(OffsetClipRgn);
96 GET_FUNC(OffsetViewportOrg);
97 GET_FUNC(OffsetWindowOrg);
98 GET_FUNC(PaintRgn);
99 GET_FUNC(PatBlt);
100 GET_FUNC(Pie);
101 GET_FUNC(PolyBezier);
102 GET_FUNC(PolyBezierTo);
103 GET_FUNC(PolyDraw);
104 GET_FUNC(PolyPolygon);
105 GET_FUNC(PolyPolyline);
106 GET_FUNC(Polygon);
107 GET_FUNC(Polyline);
108 GET_FUNC(PolylineTo);
109 GET_FUNC(RealizePalette);
110 GET_FUNC(Rectangle);
111 GET_FUNC(RestoreDC);
112 GET_FUNC(RoundRect);
113 GET_FUNC(SaveDC);
114 GET_FUNC(ScaleViewportExt);
115 GET_FUNC(ScaleWindowExt);
116 GET_FUNC(SelectClipPath);
117 GET_FUNC(SelectClipRgn);
118 GET_FUNC(SelectObject);
119 GET_FUNC(SelectPalette);
120 GET_FUNC(SetBkColor);
121 GET_FUNC(SetBkMode);
122 GET_FUNC(SetDIBitsToDevice);
123 GET_FUNC(SetDeviceClipping);
124 GET_FUNC(SetDeviceGammaRamp);
125 GET_FUNC(SetMapMode);
126 GET_FUNC(SetMapperFlags);
127 GET_FUNC(SetPixel);
128 GET_FUNC(SetPixelFormat);
129 GET_FUNC(SetPolyFillMode);
130 GET_FUNC(SetROP2);
131 GET_FUNC(SetRelAbs);
132 GET_FUNC(SetStretchBltMode);
133 GET_FUNC(SetTextAlign);
134 GET_FUNC(SetTextCharacterExtra);
135 GET_FUNC(SetTextColor);
136 GET_FUNC(SetTextJustification);
137 GET_FUNC(SetViewportExt);
138 GET_FUNC(SetViewportOrg);
139 GET_FUNC(SetWindowExt);
140 GET_FUNC(SetWindowOrg);
141 GET_FUNC(StartDoc);
142 GET_FUNC(StartPage);
143 GET_FUNC(StretchBlt);
144 GET_FUNC(StretchDIBits);
145 GET_FUNC(StrokeAndFillPath);
146 GET_FUNC(StrokePath);
147 GET_FUNC(SwapBuffers);
148 GET_FUNC(WidenPath);
149 #undef GET_FUNC
151 /* add it to the list */
152 driver->prev = NULL;
153 if ((driver->next = first_driver)) driver->next->prev = driver;
154 first_driver = driver;
155 return driver;
159 /**********************************************************************
160 * load_display_driver
162 * Special case for loading the display driver: get the name from the config file
164 static struct graphics_driver *load_display_driver(void)
166 char buffer[MAX_PATH];
167 HMODULE module;
168 HKEY hkey;
170 if (display_driver) /* already loaded */
172 display_driver->count++;
173 return display_driver;
176 strcpy( buffer, "x11drv" ); /* default value */
177 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
179 DWORD type, count = sizeof(buffer);
180 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
181 RegCloseKey( hkey );
184 if (!(module = LoadLibraryA( buffer )))
186 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
187 return NULL;
190 if (!(display_driver = create_driver( module )))
192 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
193 FreeLibrary( module );
194 return NULL;
197 display_driver->count++; /* we don't want to free it */
198 return display_driver;
202 /**********************************************************************
203 * DRIVER_load_driver
205 const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name )
207 HMODULE module;
208 struct graphics_driver *driver;
210 RtlAcquirePebLock();
212 /* display driver is a special case */
213 if (!strcasecmp( name, "display" ))
215 driver = load_display_driver();
216 RtlReleasePebLock();
217 return &driver->funcs;
220 if ((module = GetModuleHandleA( name )))
222 for (driver = first_driver; driver; driver = driver->next)
224 if (driver->module == module)
226 driver->count++;
227 RtlReleasePebLock();
228 return &driver->funcs;
233 if (!(module = LoadLibraryA( name )))
235 if (!win16_driver) win16_driver = WIN16DRV_Init();
236 RtlReleasePebLock();
237 return win16_driver;
240 if (!(driver = create_driver( module )))
242 FreeLibrary( module );
243 RtlReleasePebLock();
244 return NULL;
247 TRACE( "loaded driver %p for %s\n", driver, name );
248 RtlReleasePebLock();
249 return &driver->funcs;
253 /**********************************************************************
254 * DRIVER_get_driver
256 * Get a new copy of an existing driver.
258 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
260 struct graphics_driver *driver;
262 RtlAcquirePebLock();
263 if (funcs != win16_driver)
265 for (driver = first_driver; driver; driver = driver->next)
266 if (&driver->funcs == funcs) break;
267 if (!driver) ERR( "driver not found, trouble ahead\n" );
268 driver->count++;
270 RtlReleasePebLock();
271 return funcs;
275 /**********************************************************************
276 * DRIVER_release_driver
278 * Release a driver by decrementing ref count and freeing it if needed.
280 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
282 struct graphics_driver *driver;
284 RtlAcquirePebLock();
286 if (funcs == win16_driver) goto done;
288 for (driver = first_driver; driver; driver = driver->next)
289 if (&driver->funcs == funcs) break;
291 if (!driver) goto done;
292 if (--driver->count) goto done;
294 /* removed last reference, free it */
295 if (driver->next) driver->next->prev = driver->prev;
296 if (driver->prev) driver->prev->next = driver->next;
297 else first_driver = driver->next;
298 if (driver == display_driver) display_driver = NULL;
300 FreeLibrary( driver->module );
301 HeapFree( GetProcessHeap(), 0, driver );
302 done:
303 RtlReleasePebLock();
307 /*****************************************************************************
308 * DRIVER_GetDriverName
311 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
313 char *p;
314 size = GetProfileStringA("devices", device, "", driver, size);
315 if(!size) {
316 WARN("Unable to find '%s' in [devices] section of win.ini\n", device);
317 return FALSE;
319 p = strchr(driver, ',');
320 if(!p)
322 WARN("'%s' entry in [devices] section of win.ini is malformed.\n", device);
323 return FALSE;
325 *p = '\0';
326 TRACE("Found '%s' for '%s'\n", driver, device);
327 return TRUE;
330 /*****************************************************************************
331 * @ [GDI32.100]
333 * This should thunk to 16-bit and simply call the proc with the given args.
335 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
336 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
338 FIXME("(%p, %04x, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
339 return -1;
342 /*****************************************************************************
343 * @ [GDI32.101]
345 * This should load the correct driver for lpszDevice and calls this driver's
346 * ExtDeviceModePropSheet proc.
348 * Note: The driver calls a callback routine for each property sheet page; these
349 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
350 * The layout of this structure is:
352 * struct
354 * DWORD nPages;
355 * DWORD unknown;
356 * HPROPSHEETPAGE pages[10];
357 * };
359 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
360 LPCSTR lpszPort, LPVOID lpPropSheet )
362 FIXME("(%04x, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
363 return -1;
366 /*****************************************************************************
367 * @ [GDI32.102]
369 * This should load the correct driver for lpszDevice and calls this driver's
370 * ExtDeviceMode proc.
372 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
373 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
374 LPSTR lpszPort, LPDEVMODEA lpdmInput,
375 LPSTR lpszProfile, DWORD fwMode )
377 char buf[300];
378 HDC hdc;
379 DC *dc;
380 INT ret = -1;
381 INT (*pExtDeviceMode)(LPSTR,HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,DWORD);
383 TRACE("(%04x, %p, %s, %s, %p, %s, %ld)\n",
384 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
386 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
388 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
390 if ((dc = DC_GetDCPtr( hdc )))
392 pExtDeviceMode = dc->funcs->pExtDeviceMode;
393 GDI_ReleaseObj( hdc );
394 if (pExtDeviceMode)
395 ret = pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
396 lpdmInput, lpszProfile, fwMode);
398 DeleteDC( hdc );
399 return ret;
402 /****************************************************************************
403 * @ [GDI32.103]
405 * This should load the correct driver for lpszDevice and calls this driver's
406 * AdvancedSetupDialog proc.
408 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
409 LPDEVMODEA devin, LPDEVMODEA devout )
411 TRACE("(%04x, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
412 return -1;
415 /*****************************************************************************
416 * @ [GDI32.104]
418 * This should load the correct driver for lpszDevice and calls this driver's
419 * DeviceCapabilities proc.
421 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
422 WORD fwCapability, LPSTR lpszOutput,
423 LPDEVMODEA lpdm )
425 char buf[300];
426 HDC hdc;
427 DC *dc;
428 INT ret = -1;
430 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
432 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
434 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
436 if ((dc = DC_GetDCPtr( hdc )))
438 if (dc->funcs->pDeviceCapabilities)
439 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
440 fwCapability, lpszOutput, lpdm );
441 GDI_ReleaseObj( hdc );
443 DeleteDC( hdc );
444 return ret;