2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
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 */
27 static struct graphics_driver *first_driver;
28 static struct graphics_driver *display_driver;
29 static const DC_FUNCTIONS *win16_driver;
32 /**********************************************************************
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;
44 driver->module = module;
47 /* fill the function table */
49 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
59 GET_FUNC(ChoosePixelFormat);
61 GET_FUNC(CloseFigure);
62 GET_FUNC(CreateBitmap);
64 GET_FUNC(CreateDIBSection);
66 GET_FUNC(DeleteObject);
67 GET_FUNC(DescribePixelFormat);
68 GET_FUNC(DeviceCapabilities);
73 GET_FUNC(EnumDeviceFonts);
74 GET_FUNC(ExcludeClipRect);
75 GET_FUNC(ExtDeviceMode);
77 GET_FUNC(ExtFloodFill);
81 GET_FUNC(FlattenPath);
83 GET_FUNC(GetCharWidth);
85 GET_FUNC(GetDeviceCaps);
86 GET_FUNC(GetDeviceGammaRamp);
88 GET_FUNC(GetPixelFormat);
89 GET_FUNC(GetTextExtentPoint);
90 GET_FUNC(GetTextMetrics);
91 GET_FUNC(IntersectClipRect);
95 GET_FUNC(OffsetClipRgn);
96 GET_FUNC(OffsetViewportOrg);
97 GET_FUNC(OffsetWindowOrg);
101 GET_FUNC(PolyBezier);
102 GET_FUNC(PolyBezierTo);
104 GET_FUNC(PolyPolygon);
105 GET_FUNC(PolyPolyline);
108 GET_FUNC(PolylineTo);
109 GET_FUNC(RealizePalette);
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);
122 GET_FUNC(SetDIBitsToDevice);
123 GET_FUNC(SetDeviceClipping);
124 GET_FUNC(SetDeviceGammaRamp);
125 GET_FUNC(SetMapMode);
126 GET_FUNC(SetMapperFlags);
128 GET_FUNC(SetPixelFormat);
129 GET_FUNC(SetPolyFillMode);
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);
143 GET_FUNC(StretchBlt);
144 GET_FUNC(StretchDIBits);
145 GET_FUNC(StrokeAndFillPath);
146 GET_FUNC(StrokePath);
147 GET_FUNC(SwapBuffers);
151 /* add it to the list */
153 if ((driver->next = first_driver)) driver->next->prev = driver;
154 first_driver = 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];
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 );
184 if (!(module = LoadLibraryA( buffer )))
186 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
190 if (!(display_driver = create_driver( module )))
192 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
193 FreeLibrary( module );
197 display_driver->count++; /* we don't want to free it */
198 return display_driver;
202 /**********************************************************************
205 const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name )
208 struct graphics_driver *driver;
212 /* display driver is a special case */
213 if (!strcasecmp( name, "display" ))
215 driver = load_display_driver();
217 return &driver->funcs;
220 if ((module = GetModuleHandleA( name )))
222 for (driver = first_driver; driver; driver = driver->next)
224 if (driver->module == module)
228 return &driver->funcs;
233 if (!(module = LoadLibraryA( name )))
235 if (!win16_driver) win16_driver = WIN16DRV_Init();
240 if (!(driver = create_driver( module )))
242 FreeLibrary( module );
247 TRACE( "loaded driver %p for %s\n", driver, name );
249 return &driver->funcs;
253 /**********************************************************************
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;
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" );
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;
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 );
307 /*****************************************************************************
308 * DRIVER_GetDriverName
311 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
314 size = GetProfileStringA("devices", device, "", driver, size);
316 WARN("Unable to find '%s' in [devices] section of win.ini\n", device);
319 p = strchr(driver, ',');
322 WARN("'%s' entry in [devices] section of win.ini is malformed.\n", device);
326 TRACE("Found '%s' for '%s'\n", driver, device);
330 /*****************************************************************************
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 );
342 /*****************************************************************************
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:
356 * HPROPSHEETPAGE pages[10];
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 );
366 /*****************************************************************************
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 )
382 TRACE("(%04x, %p, %s, %s, %p, %s, %ld)\n",
383 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
385 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
387 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
389 if ((dc = DC_GetDCPtr( hdc )))
391 if (dc->funcs->pExtDeviceMode)
392 ret = dc->funcs->pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
393 lpdmInput, lpszProfile, fwMode);
394 GDI_ReleaseObj( hdc );
400 /****************************************************************************
403 * This should load the correct driver for lpszDevice and calls this driver's
404 * AdvancedSetupDialog proc.
406 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
407 LPDEVMODEA devin, LPDEVMODEA devout )
409 TRACE("(%04x, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
413 /*****************************************************************************
416 * This should load the correct driver for lpszDevice and calls this driver's
417 * DeviceCapabilities proc.
419 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
420 WORD fwCapability, LPSTR lpszOutput,
428 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
430 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
432 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
434 if ((dc = DC_GetDCPtr( hdc )))
436 if (dc->funcs->pDeviceCapabilities)
437 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
438 fwCapability, lpszOutput, lpdm );
439 GDI_ReleaseObj( hdc );