gdi32: Properly manage the driver stack during DC creation and deletion.
[wine.git] / dlls / gdi32 / driver.c
blob4b7a16549f4dd524a28bd9f7a13144b681d0ee25
1 /*
2 * Graphics driver management functions
4 * Copyright 1994 Bob Amstadt
5 * Copyright 1996, 2001 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winreg.h"
32 #include "ddrawgdi.h"
33 #include "wine/winbase16.h"
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(driver);
42 struct graphics_driver
44 struct list entry;
45 HMODULE module; /* module handle */
46 DC_FUNCTIONS funcs;
49 static struct list drivers = LIST_INIT( drivers );
50 static struct graphics_driver *display_driver;
52 static CRITICAL_SECTION driver_section;
53 static CRITICAL_SECTION_DEBUG critsect_debug =
55 0, 0, &driver_section,
56 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
57 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
59 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
61 /**********************************************************************
62 * create_driver
64 * Allocate and fill the driver structure for a given module.
66 static struct graphics_driver *create_driver( HMODULE module )
68 struct graphics_driver *driver;
70 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
71 driver->module = module;
73 /* fill the function table */
74 if (module)
76 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
77 GET_FUNC(AbortDoc);
78 GET_FUNC(AbortPath);
79 GET_FUNC(AlphaBlend);
80 GET_FUNC(AngleArc);
81 GET_FUNC(Arc);
82 GET_FUNC(ArcTo);
83 GET_FUNC(BeginPath);
84 GET_FUNC(BitBlt);
85 GET_FUNC(ChoosePixelFormat);
86 GET_FUNC(Chord);
87 GET_FUNC(CloseFigure);
88 GET_FUNC(CreateBitmap);
89 GET_FUNC(CreateDC);
90 GET_FUNC(CreateDIBSection);
91 GET_FUNC(DeleteBitmap);
92 GET_FUNC(DeleteDC);
93 GET_FUNC(DescribePixelFormat);
94 GET_FUNC(DeviceCapabilities);
95 GET_FUNC(Ellipse);
96 GET_FUNC(EndDoc);
97 GET_FUNC(EndPage);
98 GET_FUNC(EndPath);
99 GET_FUNC(EnumDeviceFonts);
100 GET_FUNC(EnumICMProfiles);
101 GET_FUNC(ExcludeClipRect);
102 GET_FUNC(ExtDeviceMode);
103 GET_FUNC(ExtEscape);
104 GET_FUNC(ExtFloodFill);
105 GET_FUNC(ExtSelectClipRgn);
106 GET_FUNC(ExtTextOut);
107 GET_FUNC(FillPath);
108 GET_FUNC(FillRgn);
109 GET_FUNC(FlattenPath);
110 GET_FUNC(FrameRgn);
111 GET_FUNC(GdiComment);
112 GET_FUNC(GetBitmapBits);
113 GET_FUNC(GetCharWidth);
114 GET_FUNC(GetDIBits);
115 GET_FUNC(GetDeviceCaps);
116 GET_FUNC(GetDeviceGammaRamp);
117 GET_FUNC(GetICMProfile);
118 GET_FUNC(GetNearestColor);
119 GET_FUNC(GetPixel);
120 GET_FUNC(GetPixelFormat);
121 GET_FUNC(GetSystemPaletteEntries);
122 GET_FUNC(GetTextExtentExPoint);
123 GET_FUNC(GetTextMetrics);
124 GET_FUNC(IntersectClipRect);
125 GET_FUNC(InvertRgn);
126 GET_FUNC(LineTo);
127 GET_FUNC(MoveTo);
128 GET_FUNC(ModifyWorldTransform);
129 GET_FUNC(OffsetClipRgn);
130 GET_FUNC(OffsetViewportOrgEx);
131 GET_FUNC(OffsetWindowOrgEx);
132 GET_FUNC(PaintRgn);
133 GET_FUNC(PatBlt);
134 GET_FUNC(Pie);
135 GET_FUNC(PolyBezier);
136 GET_FUNC(PolyBezierTo);
137 GET_FUNC(PolyDraw);
138 GET_FUNC(PolyPolygon);
139 GET_FUNC(PolyPolyline);
140 GET_FUNC(Polygon);
141 GET_FUNC(Polyline);
142 GET_FUNC(PolylineTo);
143 GET_FUNC(RealizeDefaultPalette);
144 GET_FUNC(RealizePalette);
145 GET_FUNC(Rectangle);
146 GET_FUNC(ResetDC);
147 GET_FUNC(RestoreDC);
148 GET_FUNC(RoundRect);
149 GET_FUNC(SaveDC);
150 GET_FUNC(ScaleViewportExtEx);
151 GET_FUNC(ScaleWindowExtEx);
152 GET_FUNC(SelectBitmap);
153 GET_FUNC(SelectBrush);
154 GET_FUNC(SelectClipPath);
155 GET_FUNC(SelectFont);
156 GET_FUNC(SelectPalette);
157 GET_FUNC(SelectPen);
158 GET_FUNC(SetArcDirection);
159 GET_FUNC(SetBitmapBits);
160 GET_FUNC(SetBkColor);
161 GET_FUNC(SetBkMode);
162 GET_FUNC(SetDCBrushColor);
163 GET_FUNC(SetDCPenColor);
164 GET_FUNC(SetDIBColorTable);
165 GET_FUNC(SetDIBits);
166 GET_FUNC(SetDIBitsToDevice);
167 GET_FUNC(SetDeviceClipping);
168 GET_FUNC(SetDeviceGammaRamp);
169 GET_FUNC(SetMapMode);
170 GET_FUNC(SetMapperFlags);
171 GET_FUNC(SetPixel);
172 GET_FUNC(SetPixelFormat);
173 GET_FUNC(SetPolyFillMode);
174 GET_FUNC(SetROP2);
175 GET_FUNC(SetRelAbs);
176 GET_FUNC(SetStretchBltMode);
177 GET_FUNC(SetTextAlign);
178 GET_FUNC(SetTextCharacterExtra);
179 GET_FUNC(SetTextColor);
180 GET_FUNC(SetTextJustification);
181 GET_FUNC(SetViewportExtEx);
182 GET_FUNC(SetViewportOrgEx);
183 GET_FUNC(SetWindowExtEx);
184 GET_FUNC(SetWindowOrgEx);
185 GET_FUNC(SetWorldTransform);
186 GET_FUNC(StartDoc);
187 GET_FUNC(StartPage);
188 GET_FUNC(StretchBlt);
189 GET_FUNC(StretchDIBits);
190 GET_FUNC(StrokeAndFillPath);
191 GET_FUNC(StrokePath);
192 GET_FUNC(SwapBuffers);
193 GET_FUNC(UnrealizePalette);
194 GET_FUNC(WidenPath);
196 /* OpenGL32 */
197 GET_FUNC(wglCreateContext);
198 GET_FUNC(wglCreateContextAttribsARB);
199 GET_FUNC(wglDeleteContext);
200 GET_FUNC(wglGetProcAddress);
201 GET_FUNC(wglGetPbufferDCARB);
202 GET_FUNC(wglMakeContextCurrentARB);
203 GET_FUNC(wglMakeCurrent);
204 GET_FUNC(wglSetPixelFormatWINE);
205 GET_FUNC(wglShareLists);
206 GET_FUNC(wglUseFontBitmapsA);
207 GET_FUNC(wglUseFontBitmapsW);
208 #undef GET_FUNC
210 else memset( &driver->funcs, 0, sizeof(driver->funcs) );
212 return driver;
216 /**********************************************************************
217 * DRIVER_get_display_driver
219 * Special case for loading the display driver: get the name from the config file
221 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
223 struct graphics_driver *driver;
224 char buffer[MAX_PATH], libname[32], *name, *next;
225 HMODULE module = 0;
226 HKEY hkey;
228 if (display_driver) return &display_driver->funcs; /* already loaded */
230 strcpy( buffer, "x11" ); /* default value */
231 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
232 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
234 DWORD type, count = sizeof(buffer);
235 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
236 RegCloseKey( hkey );
239 name = buffer;
240 while (name)
242 next = strchr( name, ',' );
243 if (next) *next++ = 0;
245 snprintf( libname, sizeof(libname), "wine%s.drv", name );
246 if ((module = LoadLibraryA( libname )) != 0) break;
247 name = next;
250 if (!(driver = create_driver( module )))
252 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
253 FreeLibrary( module );
254 ExitProcess(1);
256 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
258 /* somebody beat us to it */
259 FreeLibrary( driver->module );
260 HeapFree( GetProcessHeap(), 0, driver );
262 return &display_driver->funcs;
266 /**********************************************************************
267 * DRIVER_load_driver
269 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
271 HMODULE module;
272 struct graphics_driver *driver, *new_driver;
273 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
274 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
276 /* display driver is a special case */
277 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
279 if ((module = GetModuleHandleW( name )))
281 if (display_driver && display_driver->module == module) return &display_driver->funcs;
282 EnterCriticalSection( &driver_section );
283 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
285 if (driver->module == module) goto done;
287 LeaveCriticalSection( &driver_section );
290 if (!(module = LoadLibraryW( name ))) return NULL;
292 if (!(new_driver = create_driver( module )))
294 FreeLibrary( module );
295 return NULL;
298 /* check if someone else added it in the meantime */
299 EnterCriticalSection( &driver_section );
300 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
302 if (driver->module != module) continue;
303 FreeLibrary( module );
304 HeapFree( GetProcessHeap(), 0, new_driver );
305 goto done;
307 driver = new_driver;
308 list_add_head( &drivers, &driver->entry );
309 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
310 done:
311 LeaveCriticalSection( &driver_section );
312 return &driver->funcs;
316 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
318 return 0;
321 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
322 INT xstart, INT ystart, INT xend, INT yend )
324 return TRUE;
327 static INT CDECL nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
329 return 0;
332 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
333 INT xstart, INT ystart, INT xend, INT yend )
335 return TRUE;
338 static BOOL CDECL nulldrv_CreateBitmap( PHYSDEV dev, HBITMAP bitmap, LPVOID bits )
340 return TRUE;
343 static BOOL CDECL nulldrv_CreateDC( HDC hdc, PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
344 LPCWSTR output, const DEVMODEW *devmode )
346 assert(0); /* should never be called */
347 return FALSE;
350 static HBITMAP CDECL nulldrv_CreateDIBSection( PHYSDEV dev, HBITMAP bitmap,
351 const BITMAPINFO *info, UINT usage )
353 return bitmap;
356 static BOOL CDECL nulldrv_DeleteBitmap( HBITMAP bitmap )
358 return TRUE;
361 static BOOL CDECL nulldrv_DeleteDC( PHYSDEV dev )
363 assert(0); /* should never be called */
364 return TRUE;
367 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
369 return TRUE;
372 static INT CDECL nulldrv_DescribePixelFormat( PHYSDEV dev, INT format,
373 UINT size, PIXELFORMATDESCRIPTOR * descr )
375 return 0;
378 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
379 WORD cap, LPSTR output, DEVMODEA *devmode )
381 return -1;
384 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
386 return TRUE;
389 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
391 return 0;
394 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
396 return 0;
399 static BOOL CDECL nulldrv_EnumDeviceFonts( PHYSDEV dev, LOGFONTW *logfont,
400 FONTENUMPROCW proc, LPARAM lParam )
402 return FALSE;
405 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
407 return -1;
410 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
411 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
413 return -1;
416 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
417 INT out_size, void *out_data )
419 return 0;
422 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
424 return TRUE;
427 static BOOL CDECL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
428 LPCWSTR str, UINT count, const INT *dx )
430 return TRUE;
433 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
435 return FALSE;
438 static BOOL CDECL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
440 return FALSE;
443 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
445 return FALSE;
448 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
450 return FALSE;
453 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
455 return 0;
458 static INT CDECL nulldrv_GetPixelFormat( PHYSDEV dev )
460 return 0;
463 static UINT CDECL nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start,
464 UINT count, PALETTEENTRY *entries )
466 return 0;
469 static BOOL CDECL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
470 INT *fit, INT *dx, SIZE *size )
472 return FALSE;
475 static BOOL CDECL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
477 return FALSE;
480 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
482 return TRUE;
485 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
487 return TRUE;
490 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
492 return TRUE;
495 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
496 INT xstart, INT ystart, INT xend, INT yend )
498 return TRUE;
501 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
503 /* FIXME: could be implemented with Polygon */
504 return TRUE;
507 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
509 /* FIXME: could be implemented with Polyline */
510 return TRUE;
513 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
515 return TRUE;
518 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
520 return TRUE;
523 static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
525 return 0;
528 static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
530 return 0;
533 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
535 return TRUE;
538 static HDC CDECL nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
540 return 0;
543 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
544 INT ell_width, INT ell_height )
546 return TRUE;
549 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
551 return bitmap;
554 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
556 return brush;
559 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
561 return 0;
564 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
566 return palette;
569 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
571 return pen;
574 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
576 return dir;
579 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
581 return color;
584 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
586 return mode;
589 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
591 return color;
594 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
596 return color;
599 static UINT CDECL nulldrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
601 return 0;
604 static INT CDECL nulldrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD width, DWORD height,
605 INT x_src, INT y_src, UINT start, UINT lines,
606 const void *bits, const BITMAPINFO *info, UINT coloruse )
608 return 0;
611 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
615 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
617 return layout;
620 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
622 return FALSE;
625 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
627 return flags;
630 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
632 return color;
635 static BOOL CDECL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
637 return FALSE;
640 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
642 return mode;
645 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
647 return rop;
650 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
652 return mode;
655 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
657 return mode;
660 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
662 return align;
665 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
667 return extra;
670 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
672 return color;
675 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
677 return TRUE;
680 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
682 return 0;
685 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
687 return 1;
690 static BOOL CDECL nulldrv_SwapBuffers( PHYSDEV dev )
692 return TRUE;
695 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
697 return FALSE;
700 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
702 return 0;
705 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
707 return 0;
710 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
712 return FALSE;
715 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
717 return NULL;
720 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
722 return 0;
725 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
727 return FALSE;
730 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
732 return FALSE;
735 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
736 const PIXELFORMATDESCRIPTOR *descr )
738 return FALSE;
741 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
743 return FALSE;
746 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
748 return FALSE;
751 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
753 return FALSE;
756 const DC_FUNCTIONS null_driver =
758 nulldrv_AbortDoc, /* pAbortDoc */
759 nulldrv_AbortPath, /* pAbortPath */
760 NULL, /* pAlphaBlend */
761 nulldrv_AngleArc, /* pAngleArc */
762 nulldrv_Arc, /* pArc */
763 nulldrv_ArcTo, /* pArcTo */
764 nulldrv_BeginPath, /* pBeginPath */
765 NULL, /* pBitBlt */
766 nulldrv_ChoosePixelFormat, /* pChoosePixelFormat */
767 nulldrv_Chord, /* pChord */
768 nulldrv_CloseFigure, /* pCloseFigure */
769 nulldrv_CreateBitmap, /* pCreateBitmap */
770 nulldrv_CreateDC, /* pCreateDC */
771 nulldrv_CreateDIBSection, /* pCreateDIBSection */
772 nulldrv_DeleteBitmap, /* pDeleteBitmap */
773 nulldrv_DeleteDC, /* pDeleteDC */
774 nulldrv_DeleteObject, /* pDeleteObject */
775 nulldrv_DescribePixelFormat, /* pDescribePixelFormat */
776 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
777 nulldrv_Ellipse, /* pEllipse */
778 nulldrv_EndDoc, /* pEndDoc */
779 nulldrv_EndPage, /* pEndPage */
780 nulldrv_EndPath, /* pEndPath */
781 nulldrv_EnumDeviceFonts, /* pEnumDeviceFonts */
782 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
783 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
784 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
785 nulldrv_ExtEscape, /* pExtEscape */
786 nulldrv_ExtFloodFill, /* pExtFloodFill */
787 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
788 nulldrv_ExtTextOut, /* pExtTextOut */
789 nulldrv_FillPath, /* pFillPath */
790 nulldrv_FillRgn, /* pFillRgn */
791 nulldrv_FlattenPath, /* pFlattenPath */
792 nulldrv_FrameRgn, /* pFrameRgn */
793 nulldrv_GdiComment, /* pGdiComment */
794 nulldrv_GetBitmapBits, /* pGetBitmapBits */
795 nulldrv_GetCharWidth, /* pGetCharWidth */
796 nulldrv_GetDIBits, /* pGetDIBits */
797 NULL, /* pGetDeviceCaps */
798 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
799 nulldrv_GetICMProfile, /* pGetICMProfile */
800 nulldrv_GetNearestColor, /* pGetNearestColor */
801 nulldrv_GetPixel, /* pGetPixel */
802 nulldrv_GetPixelFormat, /* pGetPixelFormat */
803 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
804 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
805 nulldrv_GetTextMetrics, /* pGetTextMetrics */
806 nulldrv_IntersectClipRect, /* pIntersectClipRect */
807 nulldrv_InvertRgn, /* pInvertRgn */
808 nulldrv_LineTo, /* pLineTo */
809 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
810 nulldrv_MoveTo, /* pMoveTo */
811 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
812 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
813 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
814 nulldrv_PaintRgn, /* pPaintRgn */
815 NULL, /* pPatBlt */
816 nulldrv_Pie, /* pPie */
817 nulldrv_PolyBezier, /* pPolyBezier */
818 nulldrv_PolyBezierTo, /* pPolyBezierTo */
819 nulldrv_PolyDraw, /* pPolyDraw */
820 nulldrv_PolyPolygon, /* pPolyPolygon */
821 nulldrv_PolyPolyline, /* pPolyPolyline */
822 nulldrv_Polygon, /* pPolygon */
823 nulldrv_Polyline, /* pPolyline */
824 nulldrv_PolylineTo, /* pPolylineTo */
825 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
826 nulldrv_RealizePalette, /* pRealizePalette */
827 nulldrv_Rectangle, /* pRectangle */
828 nulldrv_ResetDC, /* pResetDC */
829 nulldrv_RestoreDC, /* pRestoreDC */
830 nulldrv_RoundRect, /* pRoundRect */
831 nulldrv_SaveDC, /* pSaveDC */
832 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
833 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
834 nulldrv_SelectBitmap, /* pSelectBitmap */
835 nulldrv_SelectBrush, /* pSelectBrush */
836 nulldrv_SelectClipPath, /* pSelectClipPath */
837 nulldrv_SelectFont, /* pSelectFont */
838 nulldrv_SelectPalette, /* pSelectPalette */
839 nulldrv_SelectPen, /* pSelectPen */
840 nulldrv_SetArcDirection, /* pSetArcDirection */
841 nulldrv_SetBitmapBits, /* pSetBitmapBits */
842 nulldrv_SetBkColor, /* pSetBkColor */
843 nulldrv_SetBkMode, /* pSetBkMode */
844 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
845 nulldrv_SetDCPenColor, /* pSetDCPenColor */
846 nulldrv_SetDIBColorTable, /* pSetDIBColorTable */
847 nulldrv_SetDIBits, /* pSetDIBits */
848 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
849 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
850 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
851 nulldrv_SetLayout, /* pSetLayout */
852 nulldrv_SetMapMode, /* pSetMapMode */
853 nulldrv_SetMapperFlags, /* pSetMapperFlags */
854 nulldrv_SetPixel, /* pSetPixel */
855 nulldrv_SetPixelFormat, /* pSetPixelFormat */
856 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
857 nulldrv_SetROP2, /* pSetROP2 */
858 nulldrv_SetRelAbs, /* pSetRelAbs */
859 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
860 nulldrv_SetTextAlign, /* pSetTextAlign */
861 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
862 nulldrv_SetTextColor, /* pSetTextColor */
863 nulldrv_SetTextJustification, /* pSetTextJustification */
864 nulldrv_SetViewportExtEx, /* pSetViewportExt */
865 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
866 nulldrv_SetWindowExtEx, /* pSetWindowExt */
867 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
868 nulldrv_SetWorldTransform, /* pSetWorldTransform */
869 nulldrv_StartDoc, /* pStartDoc */
870 nulldrv_StartPage, /* pStartPage */
871 NULL, /* pStretchBlt */
872 NULL, /* pStretchDIBits */
873 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
874 nulldrv_StrokePath, /* pStrokePath */
875 nulldrv_SwapBuffers, /* pSwapBuffers */
876 NULL, /* pUnrealizePalette */
877 nulldrv_WidenPath, /* pWidenPath */
878 nulldrv_wglCopyContext, /* pwglCopyContext */
879 nulldrv_wglCreateContext, /* pwglCreateContext */
880 nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
881 nulldrv_wglDeleteContext, /* pwglDeleteContext */
882 nulldrv_wglGetProcAddress, /* pwglGetProcAddress */
883 nulldrv_wglGetPbufferDCARB, /* pwglGetPbufferDCARB */
884 nulldrv_wglMakeCurrent, /* pwglMakeCurrent */
885 nulldrv_wglMakeContextCurrentARB, /* pwglMakeContextCurrentARB */
886 nulldrv_wglSetPixelFormatWINE, /* pwglSetPixelFormatWINE */
887 nulldrv_wglShareLists, /* pwglShareLists */
888 nulldrv_wglUseFontBitmapsA, /* pwglUseFontBitmapsA */
889 nulldrv_wglUseFontBitmapsW, /* pwglUseFontBitmapsW */
893 /*****************************************************************************
894 * DRIVER_GetDriverName
897 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
899 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
900 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
901 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
902 static const WCHAR empty_strW[] = { 0 };
903 WCHAR *p;
905 /* display is a special case */
906 if (!strcmpiW( device, displayW ) ||
907 !strcmpiW( device, display1W ))
909 lstrcpynW( driver, displayW, size );
910 return TRUE;
913 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
914 if(!size) {
915 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
916 return FALSE;
918 p = strchrW(driver, ',');
919 if(!p)
921 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
922 return FALSE;
924 *p = 0;
925 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
926 return TRUE;
930 /***********************************************************************
931 * GdiConvertToDevmodeW (GDI32.@)
933 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
935 DEVMODEW *dmW;
936 WORD dmW_size, dmA_size;
938 dmA_size = dmA->dmSize;
940 /* this is the minimal dmSize that XP accepts */
941 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
942 return NULL;
944 if (dmA_size > sizeof(DEVMODEA))
945 dmA_size = sizeof(DEVMODEA);
947 dmW_size = dmA_size + CCHDEVICENAME;
948 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
949 dmW_size += CCHFORMNAME;
951 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
952 if (!dmW) return NULL;
954 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
955 dmW->dmDeviceName, CCHDEVICENAME);
956 /* copy slightly more, to avoid long computations */
957 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
959 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
961 if (dmA->dmFields & DM_FORMNAME)
962 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
963 dmW->dmFormName, CCHFORMNAME);
964 else
965 dmW->dmFormName[0] = 0;
967 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
968 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
971 if (dmA->dmDriverExtra)
972 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
974 dmW->dmSize = dmW_size;
976 return dmW;
980 /*****************************************************************************
981 * @ [GDI32.100]
983 * This should thunk to 16-bit and simply call the proc with the given args.
985 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
986 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
988 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
989 return -1;
992 /*****************************************************************************
993 * @ [GDI32.101]
995 * This should load the correct driver for lpszDevice and calls this driver's
996 * ExtDeviceModePropSheet proc.
998 * Note: The driver calls a callback routine for each property sheet page; these
999 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
1000 * The layout of this structure is:
1002 * struct
1004 * DWORD nPages;
1005 * DWORD unknown;
1006 * HPROPSHEETPAGE pages[10];
1007 * };
1009 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
1010 LPCSTR lpszPort, LPVOID lpPropSheet )
1012 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
1013 return -1;
1016 /*****************************************************************************
1017 * @ [GDI32.102]
1019 * This should load the correct driver for lpszDevice and call this driver's
1020 * ExtDeviceMode proc.
1022 * FIXME: convert ExtDeviceMode to unicode in the driver interface
1024 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1025 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1026 LPSTR lpszPort, LPDEVMODEA lpdmInput,
1027 LPSTR lpszProfile, DWORD fwMode )
1029 WCHAR deviceW[300];
1030 WCHAR bufW[300];
1031 char buf[300];
1032 HDC hdc;
1033 DC *dc;
1034 INT ret = -1;
1036 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1037 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1039 if (!lpszDevice) return -1;
1040 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1042 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1044 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1046 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1048 if ((dc = get_dc_ptr( hdc )))
1050 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1051 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1052 lpdmInput, lpszProfile, fwMode );
1053 release_dc_ptr( dc );
1055 DeleteDC( hdc );
1056 return ret;
1059 /****************************************************************************
1060 * @ [GDI32.103]
1062 * This should load the correct driver for lpszDevice and calls this driver's
1063 * AdvancedSetupDialog proc.
1065 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1066 LPDEVMODEA devin, LPDEVMODEA devout )
1068 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1069 return -1;
1072 /*****************************************************************************
1073 * @ [GDI32.104]
1075 * This should load the correct driver for lpszDevice and calls this driver's
1076 * DeviceCapabilities proc.
1078 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1080 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1081 WORD fwCapability, LPSTR lpszOutput,
1082 LPDEVMODEA lpdm )
1084 WCHAR deviceW[300];
1085 WCHAR bufW[300];
1086 char buf[300];
1087 HDC hdc;
1088 DC *dc;
1089 INT ret = -1;
1091 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1093 if (!lpszDevice) return -1;
1094 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1096 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1098 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1100 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1102 if ((dc = get_dc_ptr( hdc )))
1104 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1105 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1106 fwCapability, lpszOutput, lpdm );
1107 release_dc_ptr( dc );
1109 DeleteDC( hdc );
1110 return ret;
1114 /************************************************************************
1115 * Escape [GDI32.@]
1117 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1119 INT ret;
1120 POINT *pt;
1122 switch (escape)
1124 case ABORTDOC:
1125 return AbortDoc( hdc );
1127 case ENDDOC:
1128 return EndDoc( hdc );
1130 case GETPHYSPAGESIZE:
1131 pt = out_data;
1132 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1133 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1134 return 1;
1136 case GETPRINTINGOFFSET:
1137 pt = out_data;
1138 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1139 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1140 return 1;
1142 case GETSCALINGFACTOR:
1143 pt = out_data;
1144 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1145 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1146 return 1;
1148 case NEWFRAME:
1149 return EndPage( hdc );
1151 case SETABORTPROC:
1152 return SetAbortProc( hdc, (ABORTPROC)in_data );
1154 case STARTDOC:
1156 DOCINFOA doc;
1157 char *name = NULL;
1159 /* in_data may not be 0 terminated so we must copy it */
1160 if (in_data)
1162 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1163 memcpy( name, in_data, in_count );
1164 name[in_count] = 0;
1166 /* out_data is actually a pointer to the DocInfo structure and used as
1167 * a second input parameter */
1168 if (out_data) doc = *(DOCINFOA *)out_data;
1169 else
1171 doc.cbSize = sizeof(doc);
1172 doc.lpszOutput = NULL;
1173 doc.lpszDatatype = NULL;
1174 doc.fwType = 0;
1176 doc.lpszDocName = name;
1177 ret = StartDocA( hdc, &doc );
1178 HeapFree( GetProcessHeap(), 0, name );
1179 if (ret > 0) ret = StartPage( hdc );
1180 return ret;
1183 case QUERYESCSUPPORT:
1185 const INT *ptr = (const INT *)in_data;
1186 if (in_count < sizeof(INT)) return 0;
1187 switch(*ptr)
1189 case ABORTDOC:
1190 case ENDDOC:
1191 case GETPHYSPAGESIZE:
1192 case GETPRINTINGOFFSET:
1193 case GETSCALINGFACTOR:
1194 case NEWFRAME:
1195 case QUERYESCSUPPORT:
1196 case SETABORTPROC:
1197 case STARTDOC:
1198 return TRUE;
1200 break;
1204 /* if not handled internally, pass it to the driver */
1205 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1209 /******************************************************************************
1210 * ExtEscape [GDI32.@]
1212 * Access capabilities of a particular device that are not available through GDI.
1214 * PARAMS
1215 * hdc [I] Handle to device context
1216 * nEscape [I] Escape function
1217 * cbInput [I] Number of bytes in input structure
1218 * lpszInData [I] Pointer to input structure
1219 * cbOutput [I] Number of bytes in output structure
1220 * lpszOutData [O] Pointer to output structure
1222 * RETURNS
1223 * Success: >0
1224 * Not implemented: 0
1225 * Failure: <0
1227 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1228 INT cbOutput, LPSTR lpszOutData )
1230 INT ret = 0;
1231 DC * dc = get_dc_ptr( hdc );
1233 if (dc)
1235 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1236 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1237 release_dc_ptr( dc );
1239 return ret;
1243 /*******************************************************************
1244 * DrawEscape [GDI32.@]
1248 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1250 FIXME("DrawEscape, stub\n");
1251 return 0;
1254 /*******************************************************************
1255 * NamedEscape [GDI32.@]
1257 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1258 INT cbOutput, LPSTR lpszOutData )
1260 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1261 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1262 lpszOutData);
1263 return 0;
1266 /*******************************************************************
1267 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1268 * GdiEntry13 [GDI32.@]
1270 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1272 static int warn_once;
1274 if (!warn_once++)
1275 FIXME("stub\n");
1276 return 0;