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
22 #include "wine/port.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(driver);
34 struct graphics_driver
36 struct graphics_driver *next;
37 struct graphics_driver *prev;
38 HMODULE module; /* module handle */
39 unsigned int count; /* reference count */
43 static struct graphics_driver *first_driver;
44 static struct graphics_driver *display_driver;
45 static CRITICAL_SECTION driver_section = CRITICAL_SECTION_INIT( "driver_section" );
47 /**********************************************************************
50 * Allocate and fill the driver structure for a given module.
52 static struct graphics_driver *create_driver( HMODULE module )
54 struct graphics_driver *driver;
56 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
59 driver->module = module;
62 /* fill the function table */
64 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
73 GET_FUNC(ChoosePixelFormat);
75 GET_FUNC(CloseFigure);
76 GET_FUNC(CreateBitmap);
78 GET_FUNC(CreateDIBSection);
79 GET_FUNC(DeleteBitmap);
81 GET_FUNC(DescribePixelFormat);
82 GET_FUNC(DeviceCapabilities);
87 GET_FUNC(EnumDeviceFonts);
88 GET_FUNC(ExcludeClipRect);
89 GET_FUNC(ExtDeviceMode);
91 GET_FUNC(ExtFloodFill);
92 GET_FUNC(ExtSelectClipRgn);
96 GET_FUNC(FlattenPath);
98 GET_FUNC(GetBitmapBits);
99 GET_FUNC(GetCharWidth);
100 GET_FUNC(GetDCOrgEx);
101 GET_FUNC(GetDIBColorTable);
103 GET_FUNC(GetDeviceCaps);
104 GET_FUNC(GetDeviceGammaRamp);
105 GET_FUNC(GetNearestColor);
107 GET_FUNC(GetPixelFormat);
108 GET_FUNC(GetSystemPaletteEntries);
109 GET_FUNC(GetTextExtentPoint);
110 GET_FUNC(GetTextMetrics);
111 GET_FUNC(IntersectClipRect);
115 GET_FUNC(OffsetClipRgn);
116 GET_FUNC(OffsetViewportOrg);
117 GET_FUNC(OffsetWindowOrg);
121 GET_FUNC(PolyBezier);
122 GET_FUNC(PolyBezierTo);
124 GET_FUNC(PolyPolygon);
125 GET_FUNC(PolyPolyline);
128 GET_FUNC(PolylineTo);
129 GET_FUNC(RealizeDefaultPalette);
130 GET_FUNC(RealizePalette);
136 GET_FUNC(ScaleViewportExt);
137 GET_FUNC(ScaleWindowExt);
138 GET_FUNC(SelectBitmap);
139 GET_FUNC(SelectBrush);
140 GET_FUNC(SelectClipPath);
141 GET_FUNC(SelectFont);
142 GET_FUNC(SelectPalette);
144 GET_FUNC(SetBitmapBits);
145 GET_FUNC(SetBkColor);
148 GET_FUNC(SetDIBColorTable);
150 GET_FUNC(SetDIBitsToDevice);
151 GET_FUNC(SetDeviceClipping);
152 GET_FUNC(SetDeviceGammaRamp);
153 GET_FUNC(SetMapMode);
154 GET_FUNC(SetMapperFlags);
156 GET_FUNC(SetPixelFormat);
157 GET_FUNC(SetPolyFillMode);
160 GET_FUNC(SetStretchBltMode);
161 GET_FUNC(SetTextAlign);
162 GET_FUNC(SetTextCharacterExtra);
163 GET_FUNC(SetTextColor);
164 GET_FUNC(SetTextJustification);
165 GET_FUNC(SetViewportExt);
166 GET_FUNC(SetViewportOrg);
167 GET_FUNC(SetWindowExt);
168 GET_FUNC(SetWindowOrg);
171 GET_FUNC(StretchBlt);
172 GET_FUNC(StretchDIBits);
173 GET_FUNC(StrokeAndFillPath);
174 GET_FUNC(StrokePath);
175 GET_FUNC(SwapBuffers);
179 /* add it to the list */
181 if ((driver->next = first_driver)) driver->next->prev = driver;
182 first_driver = driver;
187 /**********************************************************************
188 * load_display_driver
190 * Special case for loading the display driver: get the name from the config file
192 static struct graphics_driver *load_display_driver(void)
194 char buffer[MAX_PATH];
198 if (display_driver) /* already loaded */
200 display_driver->count++;
201 return display_driver;
204 strcpy( buffer, "x11drv" ); /* default value */
205 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
207 DWORD type, count = sizeof(buffer);
208 RegQueryValueExA( hkey, "GraphicsDriver", 0, &type, buffer, &count );
212 if (!(module = LoadLibraryA( buffer )))
214 MESSAGE( "Could not load graphics driver '%s'\n", buffer );
218 if (!(display_driver = create_driver( module )))
220 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
221 FreeLibrary( module );
225 display_driver->count++; /* we don't want to free it */
226 return display_driver;
230 /**********************************************************************
233 const DC_FUNCTIONS *DRIVER_load_driver( LPCSTR name )
236 struct graphics_driver *driver;
238 RtlEnterCriticalSection( &driver_section );
240 /* display driver is a special case */
241 if (!strcasecmp( name, "display" ))
243 driver = load_display_driver();
244 RtlLeaveCriticalSection( &driver_section );
245 return &driver->funcs;
248 if ((module = GetModuleHandleA( name )))
250 for (driver = first_driver; driver; driver = driver->next)
252 if (driver->module == module)
255 RtlLeaveCriticalSection( &driver_section );
256 return &driver->funcs;
261 if (!(module = LoadLibraryA( name )))
263 RtlLeaveCriticalSection( &driver_section );
267 if (!(driver = create_driver( module )))
269 FreeLibrary( module );
270 RtlLeaveCriticalSection( &driver_section );
274 TRACE( "loaded driver %p for %s\n", driver, name );
275 RtlLeaveCriticalSection( &driver_section );
276 return &driver->funcs;
280 /**********************************************************************
283 * Get a new copy of an existing driver.
285 const DC_FUNCTIONS *DRIVER_get_driver( const DC_FUNCTIONS *funcs )
287 struct graphics_driver *driver;
289 RtlEnterCriticalSection( &driver_section );
290 for (driver = first_driver; driver; driver = driver->next)
291 if (&driver->funcs == funcs) break;
292 if (!driver) ERR( "driver not found, trouble ahead\n" );
294 RtlLeaveCriticalSection( &driver_section );
299 /**********************************************************************
300 * DRIVER_release_driver
302 * Release a driver by decrementing ref count and freeing it if needed.
304 void DRIVER_release_driver( const DC_FUNCTIONS *funcs )
306 struct graphics_driver *driver;
308 RtlEnterCriticalSection( &driver_section );
310 for (driver = first_driver; driver; driver = driver->next)
311 if (&driver->funcs == funcs) break;
313 if (!driver) goto done;
314 if (--driver->count) goto done;
316 /* removed last reference, free it */
317 if (driver->next) driver->next->prev = driver->prev;
318 if (driver->prev) driver->prev->next = driver->next;
319 else first_driver = driver->next;
320 if (driver == display_driver) display_driver = NULL;
322 FreeLibrary( driver->module );
323 HeapFree( GetProcessHeap(), 0, driver );
325 RtlLeaveCriticalSection( &driver_section );
329 /*****************************************************************************
330 * DRIVER_GetDriverName
333 BOOL DRIVER_GetDriverName( LPCSTR device, LPSTR driver, DWORD size )
336 size = GetProfileStringA("devices", device, "", driver, size);
338 WARN("Unable to find '%s' in [devices] section of win.ini\n", device);
341 p = strchr(driver, ',');
344 WARN("'%s' entry in [devices] section of win.ini is malformed.\n", device);
348 TRACE("Found '%s' for '%s'\n", driver, device);
352 /*****************************************************************************
355 * This should thunk to 16-bit and simply call the proc with the given args.
357 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
358 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
360 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
364 /*****************************************************************************
367 * This should load the correct driver for lpszDevice and calls this driver's
368 * ExtDeviceModePropSheet proc.
370 * Note: The driver calls a callback routine for each property sheet page; these
371 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
372 * The layout of this structure is:
378 * HPROPSHEETPAGE pages[10];
381 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
382 LPCSTR lpszPort, LPVOID lpPropSheet )
384 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
388 /*****************************************************************************
391 * This should load the correct driver for lpszDevice and calls this driver's
392 * ExtDeviceMode proc.
394 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
395 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
396 LPSTR lpszPort, LPDEVMODEA lpdmInput,
397 LPSTR lpszProfile, DWORD fwMode )
403 INT (*pExtDeviceMode)(LPSTR,HWND,LPDEVMODEA,LPSTR,LPSTR,LPDEVMODEA,LPSTR,DWORD);
405 TRACE("(%p, %p, %s, %s, %p, %s, %ld)\n",
406 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
408 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
410 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
412 if ((dc = DC_GetDCPtr( hdc )))
414 pExtDeviceMode = dc->funcs->pExtDeviceMode;
415 GDI_ReleaseObj( hdc );
417 ret = pExtDeviceMode(buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
418 lpdmInput, lpszProfile, fwMode);
424 /****************************************************************************
427 * This should load the correct driver for lpszDevice and calls this driver's
428 * AdvancedSetupDialog proc.
430 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
431 LPDEVMODEA devin, LPDEVMODEA devout )
433 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
437 /*****************************************************************************
440 * This should load the correct driver for lpszDevice and calls this driver's
441 * DeviceCapabilities proc.
443 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
444 WORD fwCapability, LPSTR lpszOutput,
452 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
454 if(!DRIVER_GetDriverName( lpszDevice, buf, sizeof(buf) )) return -1;
456 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
458 if ((dc = DC_GetDCPtr( hdc )))
460 if (dc->funcs->pDeviceCapabilities)
461 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
462 fwCapability, lpszOutput, lpdm );
463 GDI_ReleaseObj( hdc );