gdi32: Add D3DKMTCloseAdapter() stub.
[wine.git] / dlls / gdi32 / driver.c
blob054d7cf41899cd1ace14505b32f73f90168f7425
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 "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "ddrawgdi.h"
35 #include "wine/winbase16.h"
36 #include "winuser.h"
37 #include "winternl.h"
38 #include "ddk/d3dkmthk.h"
40 #include "gdi_private.h"
41 #include "wine/unicode.h"
42 #include "wine/list.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(driver);
47 struct graphics_driver
49 struct list entry;
50 HMODULE module; /* module handle */
51 const struct gdi_dc_funcs *funcs;
54 static struct list drivers = LIST_INIT( drivers );
55 static struct graphics_driver *display_driver;
57 const struct gdi_dc_funcs *font_driver = NULL;
59 static CRITICAL_SECTION driver_section;
60 static CRITICAL_SECTION_DEBUG critsect_debug =
62 0, 0, &driver_section,
63 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
64 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
66 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
68 static HWND (WINAPI *pGetDesktopWindow)(void);
69 static INT (WINAPI *pGetSystemMetrics)(INT);
70 static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
72 /**********************************************************************
73 * create_driver
75 * Allocate and fill the driver structure for a given module.
77 static struct graphics_driver *create_driver( HMODULE module )
79 static const struct gdi_dc_funcs empty_funcs;
80 const struct gdi_dc_funcs *funcs = NULL;
81 struct graphics_driver *driver;
83 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
84 driver->module = module;
86 if (module)
88 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
90 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
91 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
93 if (!funcs) funcs = &empty_funcs;
94 driver->funcs = funcs;
95 return driver;
99 /**********************************************************************
100 * get_display_driver
102 * Special case for loading the display driver: get the name from the config file
104 static const struct gdi_dc_funcs *get_display_driver(void)
106 if (!display_driver)
108 HMODULE user32 = LoadLibraryA( "user32.dll" );
109 pGetDesktopWindow = (void *)GetProcAddress( user32, "GetDesktopWindow" );
111 if (!pGetDesktopWindow() || !display_driver)
113 WARN( "failed to load the display driver, falling back to null driver\n" );
114 __wine_set_display_driver( 0 );
117 return display_driver->funcs;
121 /**********************************************************************
122 * DRIVER_load_driver
124 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
126 HMODULE module;
127 struct graphics_driver *driver, *new_driver;
128 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
129 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
131 /* display driver is a special case */
132 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
134 if ((module = GetModuleHandleW( name )))
136 if (display_driver && display_driver->module == module) return display_driver->funcs;
138 EnterCriticalSection( &driver_section );
139 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
141 if (driver->module == module) goto done;
143 LeaveCriticalSection( &driver_section );
146 if (!(module = LoadLibraryW( name ))) return NULL;
148 if (!(new_driver = create_driver( module )))
150 FreeLibrary( module );
151 return NULL;
154 /* check if someone else added it in the meantime */
155 EnterCriticalSection( &driver_section );
156 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
158 if (driver->module != module) continue;
159 FreeLibrary( module );
160 HeapFree( GetProcessHeap(), 0, new_driver );
161 goto done;
163 driver = new_driver;
164 list_add_head( &drivers, &driver->entry );
165 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
166 done:
167 LeaveCriticalSection( &driver_section );
168 return driver->funcs;
172 /***********************************************************************
173 * __wine_set_display_driver (GDI32.@)
175 void CDECL __wine_set_display_driver( HMODULE module )
177 struct graphics_driver *driver;
178 HMODULE user32;
180 if (!(driver = create_driver( module )))
182 ERR( "Could not create graphics driver\n" );
183 ExitProcess(1);
185 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
186 HeapFree( GetProcessHeap(), 0, driver );
188 user32 = LoadLibraryA( "user32.dll" );
189 pGetSystemMetrics = (void *)GetProcAddress( user32, "GetSystemMetrics" );
190 pSetThreadDpiAwarenessContext = (void *)GetProcAddress( user32, "SetThreadDpiAwarenessContext" );
194 static INT nulldrv_AbortDoc( PHYSDEV dev )
196 return 0;
199 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
200 INT xstart, INT ystart, INT xend, INT yend )
202 return TRUE;
205 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
206 INT xstart, INT ystart, INT xend, INT yend )
208 return TRUE;
211 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
213 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
214 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
217 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
218 LPCWSTR output, const DEVMODEW *devmode )
220 assert(0); /* should never be called */
221 return FALSE;
224 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
226 assert(0); /* should never be called */
227 return TRUE;
230 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
232 return TRUE;
235 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
236 WORD cap, LPSTR output, DEVMODEA *devmode )
238 return -1;
241 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
243 return TRUE;
246 static INT nulldrv_EndDoc( PHYSDEV dev )
248 return 0;
251 static INT nulldrv_EndPage( PHYSDEV dev )
253 return 0;
256 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
258 return TRUE;
261 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
263 return -1;
266 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
267 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
269 return -1;
272 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
273 INT out_size, void *out_data )
275 return 0;
278 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
280 return TRUE;
283 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
285 return FALSE;
288 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
290 return FALSE;
293 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
295 return DCB_RESET;
298 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
300 return FALSE;
303 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
305 return FALSE;
308 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
310 return FALSE;
313 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
315 int bpp;
317 switch (cap)
319 case DRIVERVERSION: return 0x4000;
320 case TECHNOLOGY: return DT_RASDISPLAY;
321 case HORZSIZE: return MulDiv( GetDeviceCaps( dev->hdc, HORZRES ), 254,
322 GetDeviceCaps( dev->hdc, LOGPIXELSX ) * 10 );
323 case VERTSIZE: return MulDiv( GetDeviceCaps( dev->hdc, VERTRES ), 254,
324 GetDeviceCaps( dev->hdc, LOGPIXELSY ) * 10 );
325 case HORZRES: return pGetSystemMetrics ? pGetSystemMetrics( SM_CXSCREEN ) : 640;
326 case VERTRES: return pGetSystemMetrics ? pGetSystemMetrics( SM_CYSCREEN ) : 480;
327 case BITSPIXEL: return 32;
328 case PLANES: return 1;
329 case NUMBRUSHES: return -1;
330 case NUMPENS: return -1;
331 case NUMMARKERS: return 0;
332 case NUMFONTS: return 0;
333 case PDEVICESIZE: return 0;
334 case CURVECAPS: return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
335 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
336 case LINECAPS: return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
337 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
338 case POLYGONALCAPS: return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
339 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
340 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
341 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
342 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
343 case CLIPCAPS: return CP_RECTANGLE;
344 case RASTERCAPS: return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DI_BITMAP | RC_DIBTODEV |
345 RC_BIGFONT | RC_STRETCHBLT | RC_FLOODFILL | RC_STRETCHDIB | RC_DEVBITS |
346 (GetDeviceCaps( dev->hdc, SIZEPALETTE ) ? RC_PALETTE : 0));
347 case ASPECTX: return 36;
348 case ASPECTY: return 36;
349 case ASPECTXY: return (int)(hypot( GetDeviceCaps( dev->hdc, ASPECTX ),
350 GetDeviceCaps( dev->hdc, ASPECTY )) + 0.5);
351 case CAPS1: return 0;
352 case SIZEPALETTE: return 0;
353 case NUMRESERVED: return 20;
354 case PHYSICALWIDTH: return 0;
355 case PHYSICALHEIGHT: return 0;
356 case PHYSICALOFFSETX: return 0;
357 case PHYSICALOFFSETY: return 0;
358 case SCALINGFACTORX: return 0;
359 case SCALINGFACTORY: return 0;
360 case VREFRESH: return GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY ? 1 : 0;
361 case DESKTOPHORZRES:
362 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && pGetSystemMetrics)
364 DPI_AWARENESS_CONTEXT context;
365 UINT ret;
366 context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
367 ret = pGetSystemMetrics( SM_CXVIRTUALSCREEN );
368 pSetThreadDpiAwarenessContext( context );
369 return ret;
371 return GetDeviceCaps( dev->hdc, HORZRES );
372 case DESKTOPVERTRES:
373 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && pGetSystemMetrics)
375 DPI_AWARENESS_CONTEXT context;
376 UINT ret;
377 context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
378 ret = pGetSystemMetrics( SM_CYVIRTUALSCREEN );
379 pSetThreadDpiAwarenessContext( context );
380 return ret;
382 return GetDeviceCaps( dev->hdc, VERTRES );
383 case BLTALIGNMENT: return 0;
384 case SHADEBLENDCAPS: return 0;
385 case COLORMGMTCAPS: return 0;
386 case LOGPIXELSX:
387 case LOGPIXELSY: return get_system_dpi();
388 case NUMCOLORS:
389 bpp = GetDeviceCaps( dev->hdc, BITSPIXEL );
390 return (bpp > 8) ? -1 : (1 << bpp);
391 case COLORRES:
392 /* The observed correspondence between BITSPIXEL and COLORRES is:
393 * BITSPIXEL: 8 -> COLORRES: 18
394 * BITSPIXEL: 16 -> COLORRES: 16
395 * BITSPIXEL: 24 -> COLORRES: 24
396 * BITSPIXEL: 32 -> COLORRES: 24 */
397 bpp = GetDeviceCaps( dev->hdc, BITSPIXEL );
398 return (bpp <= 8) ? 18 : min( 24, bpp );
399 default:
400 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
401 return 0;
405 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
407 SetLastError( ERROR_INVALID_PARAMETER );
408 return FALSE;
411 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
413 return FALSE;
416 static BOOL nulldrv_GetFontRealizationInfo( PHYSDEV dev, void *info )
418 return FALSE;
421 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
423 return 0;
426 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
428 return GDI_ERROR;
431 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
432 DWORD size, LPVOID buffer, const MAT2 *mat )
434 return GDI_ERROR;
437 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
439 return FALSE;
442 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
443 struct bitblt_coords *src )
445 return ERROR_NOT_SUPPORTED;
448 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
450 return 0;
453 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
455 return 0;
458 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
460 return DEFAULT_CHARSET;
463 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
465 return FALSE;
468 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
470 return FALSE;
473 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
475 INT ret = 0;
476 LOGFONTW font;
477 DC *dc = get_nulldrv_dc( dev );
479 if (GetObjectW( dc->hFont, sizeof(font), &font ))
481 ret = strlenW( font.lfFaceName ) + 1;
482 if (name)
484 lstrcpynW( name, font.lfFaceName, size );
485 ret = min( size, ret );
488 return ret;
491 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
493 return FALSE;
496 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
498 return TRUE;
501 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
503 return TRUE;
506 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
508 return TRUE;
511 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
513 return TRUE;
516 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
517 INT xstart, INT ystart, INT xend, INT yend )
519 return TRUE;
522 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
524 return TRUE;
527 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
529 return TRUE;
532 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
534 INT counts[1] = { count };
536 return PolyPolygon( dev->hdc, points, counts, 1 );
539 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
541 DWORD counts[1] = { count };
543 if (count < 0) return FALSE;
544 return PolyPolyline( dev->hdc, points, counts, 1 );
547 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
548 const struct gdi_image_bits *bits, struct bitblt_coords *src,
549 struct bitblt_coords *dst, DWORD rop )
551 return ERROR_SUCCESS;
554 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
556 return 0;
559 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
561 return 0;
564 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
566 return TRUE;
569 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
571 return 0;
574 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
575 INT ell_width, INT ell_height )
577 return TRUE;
580 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
582 return bitmap;
585 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
587 return brush;
590 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
592 return palette;
595 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
597 return pen;
600 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
602 return dir;
605 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
607 return color;
610 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
612 return mode;
615 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
617 return DCB_RESET;
620 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
622 return color;
625 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
627 return color;
630 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
634 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
636 return layout;
639 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
641 SetLastError( ERROR_INVALID_PARAMETER );
642 return FALSE;
645 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
647 return flags;
650 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
652 return color;
655 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
657 return mode;
660 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
662 return rop;
665 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
667 return mode;
670 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
672 return mode;
675 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
677 return align;
680 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
682 return extra;
685 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
687 return color;
690 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
692 return TRUE;
695 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
697 return 0;
700 static INT nulldrv_StartPage( PHYSDEV dev )
702 return 1;
705 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
707 return FALSE;
710 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
712 return (void *)-1;
715 static const struct vulkan_funcs *nulldrv_wine_get_vulkan_driver( PHYSDEV dev, UINT version )
717 return NULL;
720 const struct gdi_dc_funcs null_driver =
722 nulldrv_AbortDoc, /* pAbortDoc */
723 nulldrv_AbortPath, /* pAbortPath */
724 nulldrv_AlphaBlend, /* pAlphaBlend */
725 nulldrv_AngleArc, /* pAngleArc */
726 nulldrv_Arc, /* pArc */
727 nulldrv_ArcTo, /* pArcTo */
728 nulldrv_BeginPath, /* pBeginPath */
729 nulldrv_BlendImage, /* pBlendImage */
730 nulldrv_Chord, /* pChord */
731 nulldrv_CloseFigure, /* pCloseFigure */
732 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
733 nulldrv_CreateDC, /* pCreateDC */
734 nulldrv_DeleteDC, /* pDeleteDC */
735 nulldrv_DeleteObject, /* pDeleteObject */
736 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
737 nulldrv_Ellipse, /* pEllipse */
738 nulldrv_EndDoc, /* pEndDoc */
739 nulldrv_EndPage, /* pEndPage */
740 nulldrv_EndPath, /* pEndPath */
741 nulldrv_EnumFonts, /* pEnumFonts */
742 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
743 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
744 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
745 nulldrv_ExtEscape, /* pExtEscape */
746 nulldrv_ExtFloodFill, /* pExtFloodFill */
747 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
748 nulldrv_ExtTextOut, /* pExtTextOut */
749 nulldrv_FillPath, /* pFillPath */
750 nulldrv_FillRgn, /* pFillRgn */
751 nulldrv_FlattenPath, /* pFlattenPath */
752 nulldrv_FontIsLinked, /* pFontIsLinked */
753 nulldrv_FrameRgn, /* pFrameRgn */
754 nulldrv_GdiComment, /* pGdiComment */
755 nulldrv_GetBoundsRect, /* pGetBoundsRect */
756 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
757 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
758 nulldrv_GetCharWidth, /* pGetCharWidth */
759 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
760 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
761 nulldrv_GetFontData, /* pGetFontData */
762 nulldrv_GetFontRealizationInfo, /* pGetFontRealizationInfo */
763 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
764 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
765 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
766 nulldrv_GetICMProfile, /* pGetICMProfile */
767 nulldrv_GetImage, /* pGetImage */
768 nulldrv_GetKerningPairs, /* pGetKerningPairs */
769 nulldrv_GetNearestColor, /* pGetNearestColor */
770 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
771 nulldrv_GetPixel, /* pGetPixel */
772 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
773 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
774 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
775 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
776 nulldrv_GetTextFace, /* pGetTextFace */
777 nulldrv_GetTextMetrics, /* pGetTextMetrics */
778 nulldrv_GradientFill, /* pGradientFill */
779 nulldrv_IntersectClipRect, /* pIntersectClipRect */
780 nulldrv_InvertRgn, /* pInvertRgn */
781 nulldrv_LineTo, /* pLineTo */
782 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
783 nulldrv_MoveTo, /* pMoveTo */
784 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
785 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
786 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
787 nulldrv_PaintRgn, /* pPaintRgn */
788 nulldrv_PatBlt, /* pPatBlt */
789 nulldrv_Pie, /* pPie */
790 nulldrv_PolyBezier, /* pPolyBezier */
791 nulldrv_PolyBezierTo, /* pPolyBezierTo */
792 nulldrv_PolyDraw, /* pPolyDraw */
793 nulldrv_PolyPolygon, /* pPolyPolygon */
794 nulldrv_PolyPolyline, /* pPolyPolyline */
795 nulldrv_Polygon, /* pPolygon */
796 nulldrv_Polyline, /* pPolyline */
797 nulldrv_PolylineTo, /* pPolylineTo */
798 nulldrv_PutImage, /* pPutImage */
799 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
800 nulldrv_RealizePalette, /* pRealizePalette */
801 nulldrv_Rectangle, /* pRectangle */
802 nulldrv_ResetDC, /* pResetDC */
803 nulldrv_RestoreDC, /* pRestoreDC */
804 nulldrv_RoundRect, /* pRoundRect */
805 nulldrv_SaveDC, /* pSaveDC */
806 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
807 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
808 nulldrv_SelectBitmap, /* pSelectBitmap */
809 nulldrv_SelectBrush, /* pSelectBrush */
810 nulldrv_SelectClipPath, /* pSelectClipPath */
811 nulldrv_SelectFont, /* pSelectFont */
812 nulldrv_SelectPalette, /* pSelectPalette */
813 nulldrv_SelectPen, /* pSelectPen */
814 nulldrv_SetArcDirection, /* pSetArcDirection */
815 nulldrv_SetBkColor, /* pSetBkColor */
816 nulldrv_SetBkMode, /* pSetBkMode */
817 nulldrv_SetBoundsRect, /* pSetBoundsRect */
818 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
819 nulldrv_SetDCPenColor, /* pSetDCPenColor */
820 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
821 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
822 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
823 nulldrv_SetLayout, /* pSetLayout */
824 nulldrv_SetMapMode, /* pSetMapMode */
825 nulldrv_SetMapperFlags, /* pSetMapperFlags */
826 nulldrv_SetPixel, /* pSetPixel */
827 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
828 nulldrv_SetROP2, /* pSetROP2 */
829 nulldrv_SetRelAbs, /* pSetRelAbs */
830 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
831 nulldrv_SetTextAlign, /* pSetTextAlign */
832 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
833 nulldrv_SetTextColor, /* pSetTextColor */
834 nulldrv_SetTextJustification, /* pSetTextJustification */
835 nulldrv_SetViewportExtEx, /* pSetViewportExt */
836 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
837 nulldrv_SetWindowExtEx, /* pSetWindowExt */
838 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
839 nulldrv_SetWorldTransform, /* pSetWorldTransform */
840 nulldrv_StartDoc, /* pStartDoc */
841 nulldrv_StartPage, /* pStartPage */
842 nulldrv_StretchBlt, /* pStretchBlt */
843 nulldrv_StretchDIBits, /* pStretchDIBits */
844 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
845 nulldrv_StrokePath, /* pStrokePath */
846 nulldrv_UnrealizePalette, /* pUnrealizePalette */
847 nulldrv_WidenPath, /* pWidenPath */
848 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
849 nulldrv_wine_get_vulkan_driver, /* wine_get_vulkan_driver */
851 GDI_PRIORITY_NULL_DRV /* priority */
855 /*****************************************************************************
856 * DRIVER_GetDriverName
859 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
861 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
862 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
863 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
864 static const WCHAR empty_strW[] = { 0 };
865 WCHAR *p;
867 /* display is a special case */
868 if (!strcmpiW( device, displayW ) ||
869 !strcmpiW( device, display1W ))
871 lstrcpynW( driver, displayW, size );
872 return TRUE;
875 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
876 if(!size) {
877 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
878 return FALSE;
880 p = strchrW(driver, ',');
881 if(!p)
883 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
884 return FALSE;
886 *p = 0;
887 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
888 return TRUE;
892 /***********************************************************************
893 * GdiConvertToDevmodeW (GDI32.@)
895 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
897 DEVMODEW *dmW;
898 WORD dmW_size, dmA_size;
900 dmA_size = dmA->dmSize;
902 /* this is the minimal dmSize that XP accepts */
903 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
904 return NULL;
906 if (dmA_size > sizeof(DEVMODEA))
907 dmA_size = sizeof(DEVMODEA);
909 dmW_size = dmA_size + CCHDEVICENAME;
910 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
911 dmW_size += CCHFORMNAME;
913 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
914 if (!dmW) return NULL;
916 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
917 dmW->dmDeviceName, CCHDEVICENAME);
918 /* copy slightly more, to avoid long computations */
919 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
921 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
923 if (dmA->dmFields & DM_FORMNAME)
924 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
925 dmW->dmFormName, CCHFORMNAME);
926 else
927 dmW->dmFormName[0] = 0;
929 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
930 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
933 if (dmA->dmDriverExtra)
934 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
936 dmW->dmSize = dmW_size;
938 return dmW;
942 /*****************************************************************************
943 * @ [GDI32.100]
945 * This should thunk to 16-bit and simply call the proc with the given args.
947 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
948 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
950 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
951 return -1;
954 /*****************************************************************************
955 * @ [GDI32.101]
957 * This should load the correct driver for lpszDevice and calls this driver's
958 * ExtDeviceModePropSheet proc.
960 * Note: The driver calls a callback routine for each property sheet page; these
961 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
962 * The layout of this structure is:
964 * struct
966 * DWORD nPages;
967 * DWORD unknown;
968 * HPROPSHEETPAGE pages[10];
969 * };
971 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
972 LPCSTR lpszPort, LPVOID lpPropSheet )
974 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
975 return -1;
978 /*****************************************************************************
979 * @ [GDI32.102]
981 * This should load the correct driver for lpszDevice and call this driver's
982 * ExtDeviceMode proc.
984 * FIXME: convert ExtDeviceMode to unicode in the driver interface
986 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
987 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
988 LPSTR lpszPort, LPDEVMODEA lpdmInput,
989 LPSTR lpszProfile, DWORD fwMode )
991 WCHAR deviceW[300];
992 WCHAR bufW[300];
993 char buf[300];
994 HDC hdc;
995 DC *dc;
996 INT ret = -1;
998 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
999 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1001 if (!lpszDevice) return -1;
1002 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1004 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1006 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1008 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1010 if ((dc = get_dc_ptr( hdc )))
1012 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1013 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1014 lpdmInput, lpszProfile, fwMode );
1015 release_dc_ptr( dc );
1017 DeleteDC( hdc );
1018 return ret;
1021 /****************************************************************************
1022 * @ [GDI32.103]
1024 * This should load the correct driver for lpszDevice and calls this driver's
1025 * AdvancedSetupDialog proc.
1027 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1028 LPDEVMODEA devin, LPDEVMODEA devout )
1030 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1031 return -1;
1034 /*****************************************************************************
1035 * @ [GDI32.104]
1037 * This should load the correct driver for lpszDevice and calls this driver's
1038 * DeviceCapabilities proc.
1040 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1042 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1043 WORD fwCapability, LPSTR lpszOutput,
1044 LPDEVMODEA lpdm )
1046 WCHAR deviceW[300];
1047 WCHAR bufW[300];
1048 char buf[300];
1049 HDC hdc;
1050 DC *dc;
1051 INT ret = -1;
1053 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1055 if (!lpszDevice) return -1;
1056 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1058 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1060 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1062 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1064 if ((dc = get_dc_ptr( hdc )))
1066 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1067 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1068 fwCapability, lpszOutput, lpdm );
1069 release_dc_ptr( dc );
1071 DeleteDC( hdc );
1072 return ret;
1076 /************************************************************************
1077 * Escape [GDI32.@]
1079 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1081 INT ret;
1082 POINT *pt;
1084 switch (escape)
1086 case ABORTDOC:
1087 return AbortDoc( hdc );
1089 case ENDDOC:
1090 return EndDoc( hdc );
1092 case GETPHYSPAGESIZE:
1093 pt = out_data;
1094 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1095 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1096 return 1;
1098 case GETPRINTINGOFFSET:
1099 pt = out_data;
1100 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1101 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1102 return 1;
1104 case GETSCALINGFACTOR:
1105 pt = out_data;
1106 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1107 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1108 return 1;
1110 case NEWFRAME:
1111 return EndPage( hdc );
1113 case SETABORTPROC:
1114 return SetAbortProc( hdc, (ABORTPROC)in_data );
1116 case STARTDOC:
1118 DOCINFOA doc;
1119 char *name = NULL;
1121 /* in_data may not be 0 terminated so we must copy it */
1122 if (in_data)
1124 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1125 memcpy( name, in_data, in_count );
1126 name[in_count] = 0;
1128 /* out_data is actually a pointer to the DocInfo structure and used as
1129 * a second input parameter */
1130 if (out_data) doc = *(DOCINFOA *)out_data;
1131 else
1133 doc.cbSize = sizeof(doc);
1134 doc.lpszOutput = NULL;
1135 doc.lpszDatatype = NULL;
1136 doc.fwType = 0;
1138 doc.lpszDocName = name;
1139 ret = StartDocA( hdc, &doc );
1140 HeapFree( GetProcessHeap(), 0, name );
1141 if (ret > 0) ret = StartPage( hdc );
1142 return ret;
1145 case QUERYESCSUPPORT:
1147 DWORD code;
1149 if (in_count < sizeof(SHORT)) return 0;
1150 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1151 switch (code)
1153 case ABORTDOC:
1154 case ENDDOC:
1155 case GETPHYSPAGESIZE:
1156 case GETPRINTINGOFFSET:
1157 case GETSCALINGFACTOR:
1158 case NEWFRAME:
1159 case QUERYESCSUPPORT:
1160 case SETABORTPROC:
1161 case STARTDOC:
1162 return TRUE;
1164 break;
1168 /* if not handled internally, pass it to the driver */
1169 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1173 /******************************************************************************
1174 * ExtEscape [GDI32.@]
1176 * Access capabilities of a particular device that are not available through GDI.
1178 * PARAMS
1179 * hdc [I] Handle to device context
1180 * nEscape [I] Escape function
1181 * cbInput [I] Number of bytes in input structure
1182 * lpszInData [I] Pointer to input structure
1183 * cbOutput [I] Number of bytes in output structure
1184 * lpszOutData [O] Pointer to output structure
1186 * RETURNS
1187 * Success: >0
1188 * Not implemented: 0
1189 * Failure: <0
1191 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1192 INT cbOutput, LPSTR lpszOutData )
1194 PHYSDEV physdev;
1195 INT ret;
1196 DC * dc = get_dc_ptr( hdc );
1198 if (!dc) return 0;
1199 update_dc( dc );
1200 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1201 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1202 release_dc_ptr( dc );
1203 return ret;
1207 /*******************************************************************
1208 * DrawEscape [GDI32.@]
1212 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1214 FIXME("DrawEscape, stub\n");
1215 return 0;
1218 /*******************************************************************
1219 * NamedEscape [GDI32.@]
1221 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1222 INT cbOutput, LPSTR lpszOutData )
1224 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1225 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1226 lpszOutData);
1227 return 0;
1230 /*******************************************************************
1231 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1232 * GdiEntry13 [GDI32.@]
1234 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1236 static int warn_once;
1238 if (!warn_once++)
1239 FIXME("stub\n");
1240 return 0;
1243 /******************************************************************************
1244 * D3DKMTOpenAdapterFromHdc [GDI32.@]
1246 NTSTATUS WINAPI D3DKMTOpenAdapterFromHdc( void *pData )
1248 FIXME("(%p): stub\n", pData);
1249 return STATUS_NO_MEMORY;
1252 /******************************************************************************
1253 * D3DKMTEscape [GDI32.@]
1255 NTSTATUS WINAPI D3DKMTEscape( const void *pData )
1257 FIXME("(%p): stub\n", pData);
1258 return STATUS_NO_MEMORY;
1261 /******************************************************************************
1262 * D3DKMTCloseAdapter [GDI32.@]
1264 NTSTATUS WINAPI D3DKMTCloseAdapter( const D3DKMT_CLOSEADAPTER *desc )
1266 FIXME("(%p): stub\n", desc);
1267 return STATUS_SUCCESS;