2 * Graphics driver management functions
4 * Copyright 1996 Alexandre Julliard
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(driver
);
17 struct graphics_driver
19 struct graphics_driver
*next
;
20 struct graphics_driver
*prev
;
21 HMODULE module
; /* module handle */
22 unsigned int count
; /* reference count */
26 static struct graphics_driver
*first_driver
;
27 static struct graphics_driver
*display_driver
;
30 /**********************************************************************
33 * Allocate and fill the driver structure for a given module.
35 static struct graphics_driver
*create_driver( HMODULE module
)
37 struct graphics_driver
*driver
;
39 if (!(driver
= HeapAlloc( GetProcessHeap(), 0, sizeof(*driver
)))) return NULL
;
42 driver
->module
= module
;
45 /* fill the function table */
47 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
57 GET_FUNC(ChoosePixelFormat
);
59 GET_FUNC(CloseFigure
);
60 GET_FUNC(CreateBitmap
);
62 GET_FUNC(CreateDIBSection
);
64 GET_FUNC(DeleteObject
);
65 GET_FUNC(DescribePixelFormat
);
66 GET_FUNC(DeviceCapabilities
);
71 GET_FUNC(EnumDeviceFonts
);
72 GET_FUNC(ExcludeClipRect
);
73 GET_FUNC(ExtDeviceMode
);
75 GET_FUNC(ExtFloodFill
);
79 GET_FUNC(FlattenPath
);
81 GET_FUNC(GetCharWidth
);
83 GET_FUNC(GetDeviceCaps
);
84 GET_FUNC(GetDeviceGammaRamp
);
86 GET_FUNC(GetPixelFormat
);
87 GET_FUNC(GetTextExtentPoint
);
88 GET_FUNC(GetTextMetrics
);
89 GET_FUNC(IntersectClipRect
);
93 GET_FUNC(OffsetClipRgn
);
94 GET_FUNC(OffsetViewportOrg
);
95 GET_FUNC(OffsetWindowOrg
);
100 GET_FUNC(PolyBezierTo
);
102 GET_FUNC(PolyPolygon
);
103 GET_FUNC(PolyPolyline
);
106 GET_FUNC(PolylineTo
);
107 GET_FUNC(RealizePalette
);
112 GET_FUNC(ScaleViewportExt
);
113 GET_FUNC(ScaleWindowExt
);
114 GET_FUNC(SelectClipPath
);
115 GET_FUNC(SelectClipRgn
);
116 GET_FUNC(SelectObject
);
117 GET_FUNC(SelectPalette
);
118 GET_FUNC(SetBkColor
);
120 GET_FUNC(SetDIBitsToDevice
);
121 GET_FUNC(SetDeviceClipping
);
122 GET_FUNC(SetDeviceGammaRamp
);
123 GET_FUNC(SetMapMode
);
124 GET_FUNC(SetMapperFlags
);
126 GET_FUNC(SetPixelFormat
);
127 GET_FUNC(SetPolyFillMode
);
130 GET_FUNC(SetStretchBltMode
);
131 GET_FUNC(SetTextAlign
);
132 GET_FUNC(SetTextCharacterExtra
);
133 GET_FUNC(SetTextColor
);
134 GET_FUNC(SetTextJustification
);
135 GET_FUNC(SetViewportExt
);
136 GET_FUNC(SetViewportOrg
);
137 GET_FUNC(SetWindowExt
);
138 GET_FUNC(SetWindowOrg
);
141 GET_FUNC(StretchBlt
);
142 GET_FUNC(StretchDIBits
);
143 GET_FUNC(StrokeAndFillPath
);
144 GET_FUNC(StrokePath
);
145 GET_FUNC(SwapBuffers
);
149 /* add it to the list */
151 if ((driver
->next
= first_driver
)) driver
->next
->prev
= driver
;
152 first_driver
= driver
;
157 /**********************************************************************
158 * load_display_driver
160 * Special case for loading the display driver: get the name from the config file
162 static struct graphics_driver
*load_display_driver(void)
164 char buffer
[MAX_PATH
];
168 if (display_driver
) /* already loaded */
170 display_driver
->count
++;
171 return display_driver
;
174 strcpy( buffer
, "x11drv" ); /* default value */
175 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\Wine", &hkey
))
177 DWORD type
, count
= sizeof(buffer
);
178 RegQueryValueExA( hkey
, "GraphicsDriver", 0, &type
, buffer
, &count
);
182 if (!(module
= LoadLibraryA( buffer
)))
184 MESSAGE( "Could not load graphics driver '%s'\n", buffer
);
188 if (!(display_driver
= create_driver( module
)))
190 MESSAGE( "Could not create graphics driver '%s'\n", buffer
);
191 FreeLibrary( module
);
195 display_driver
->count
++; /* we don't want to free it */
196 return display_driver
;
200 /**********************************************************************
203 const DC_FUNCTIONS
*DRIVER_load_driver( LPCSTR name
)
206 struct graphics_driver
*driver
;
210 /* display driver is a special case */
211 if (!strcasecmp( name
, "display" ))
213 driver
= load_display_driver();
215 return &driver
->funcs
;
218 if ((module
= GetModuleHandleA( name
)))
220 for (driver
= first_driver
; driver
; driver
= driver
->next
)
222 if (driver
->module
== module
)
226 return &driver
->funcs
;
231 if (!(module
= LoadLibraryA( name
)))
237 if (!(driver
= create_driver( module
)))
239 FreeLibrary( module
);
244 TRACE( "loaded driver %p for %s\n", driver
, name
);
246 return &driver
->funcs
;
250 /**********************************************************************
253 * Get a new copy of an existing driver.
255 const DC_FUNCTIONS
*DRIVER_get_driver( const DC_FUNCTIONS
*funcs
)
257 struct graphics_driver
*driver
;
260 for (driver
= first_driver
; driver
; driver
= driver
->next
)
261 if (&driver
->funcs
== funcs
) break;
262 if (!driver
) ERR( "driver not found, trouble ahead\n" );
269 /**********************************************************************
270 * DRIVER_release_driver
272 * Release a driver by decrementing ref count and freeing it if needed.
274 void DRIVER_release_driver( const DC_FUNCTIONS
*funcs
)
276 struct graphics_driver
*driver
;
280 for (driver
= first_driver
; driver
; driver
= driver
->next
)
281 if (&driver
->funcs
== funcs
) break;
283 if (!driver
) goto done
;
284 if (--driver
->count
) goto done
;
286 /* removed last reference, free it */
287 if (driver
->next
) driver
->next
->prev
= driver
->prev
;
288 if (driver
->prev
) driver
->prev
->next
= driver
->next
;
289 else first_driver
= driver
->next
;
290 if (driver
== display_driver
) display_driver
= NULL
;
292 FreeLibrary( driver
->module
);
293 HeapFree( GetProcessHeap(), 0, driver
);
299 /*****************************************************************************
300 * DRIVER_GetDriverName
303 BOOL
DRIVER_GetDriverName( LPCSTR device
, LPSTR driver
, DWORD size
)
306 size
= GetProfileStringA("devices", device
, "", driver
, size
);
308 WARN("Unable to find '%s' in [devices] section of win.ini\n", device
);
311 p
= strchr(driver
, ',');
314 WARN("'%s' entry in [devices] section of win.ini is malformed.\n", device
);
318 TRACE("Found '%s' for '%s'\n", driver
, device
);
322 /*****************************************************************************
325 * This should thunk to 16-bit and simply call the proc with the given args.
327 INT WINAPI
GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc
, HWND hWnd
,
328 LPSTR lpModelName
, LPSTR OldPort
, LPSTR NewPort
)
330 FIXME("(%p, %04x, %s, %s, %s)\n", lpfnDevInstallProc
, hWnd
, lpModelName
, OldPort
, NewPort
);
334 /*****************************************************************************
337 * This should load the correct driver for lpszDevice and calls this driver's
338 * ExtDeviceModePropSheet proc.
340 * Note: The driver calls a callback routine for each property sheet page; these
341 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
342 * The layout of this structure is:
348 * HPROPSHEETPAGE pages[10];
351 INT WINAPI
GDI_CallExtDeviceModePropSheet16( HWND hWnd
, LPCSTR lpszDevice
,
352 LPCSTR lpszPort
, LPVOID lpPropSheet
)
354 FIXME("(%04x, %s, %s, %p)\n", hWnd
, lpszDevice
, lpszPort
, lpPropSheet
);
358 /*****************************************************************************
361 * This should load the correct driver for lpszDevice and calls this driver's
362 * ExtDeviceMode proc.
364 INT WINAPI
GDI_CallExtDeviceMode16( HWND hwnd
,
365 LPDEVMODEA lpdmOutput
, LPSTR lpszDevice
,
366 LPSTR lpszPort
, LPDEVMODEA lpdmInput
,
367 LPSTR lpszProfile
, DWORD fwMode
)
374 TRACE("(%04x, %p, %s, %s, %p, %s, %ld)\n",
375 hwnd
, lpdmOutput
, lpszDevice
, lpszPort
, lpdmInput
, lpszProfile
, fwMode
);
377 if(!DRIVER_GetDriverName( lpszDevice
, buf
, sizeof(buf
) )) return -1;
379 if (!(hdc
= CreateICA( buf
, NULL
, lpszPort
, NULL
))) return -1;
381 if ((dc
= DC_GetDCPtr( hdc
)))
383 if (dc
->funcs
->pExtDeviceMode
)
384 ret
= dc
->funcs
->pExtDeviceMode(buf
, hwnd
, lpdmOutput
, lpszDevice
, lpszPort
,
385 lpdmInput
, lpszProfile
, fwMode
);
386 GDI_ReleaseObj( hdc
);
392 /****************************************************************************
395 * This should load the correct driver for lpszDevice and calls this driver's
396 * AdvancedSetupDialog proc.
398 INT WINAPI
GDI_CallAdvancedSetupDialog16( HWND hwnd
, LPSTR lpszDevice
,
399 LPDEVMODEA devin
, LPDEVMODEA devout
)
401 TRACE("(%04x, %s, %p, %p)\n", hwnd
, lpszDevice
, devin
, devout
);
405 /*****************************************************************************
408 * This should load the correct driver for lpszDevice and calls this driver's
409 * DeviceCapabilities proc.
411 DWORD WINAPI
GDI_CallDeviceCapabilities16( LPCSTR lpszDevice
, LPCSTR lpszPort
,
412 WORD fwCapability
, LPSTR lpszOutput
,
420 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice
, lpszPort
, fwCapability
, lpszOutput
, lpdm
);
422 if(!DRIVER_GetDriverName( lpszDevice
, buf
, sizeof(buf
) )) return -1;
424 if (!(hdc
= CreateICA( buf
, NULL
, lpszPort
, NULL
))) return -1;
426 if ((dc
= DC_GetDCPtr( hdc
)))
428 if (dc
->funcs
->pDeviceCapabilities
)
429 ret
= dc
->funcs
->pDeviceCapabilities( buf
, lpszDevice
, lpszPort
,
430 fwCapability
, lpszOutput
, lpdm
);
431 GDI_ReleaseObj( hdc
);