mshtml: Use wide-char string literals.
[wine.git] / dlls / gdi32 / driver.c
blobe2528ece0465c0a0633b02f4b119191454a12fed
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 <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winreg.h"
32 #include "ddrawgdi.h"
33 #include "wine/winbase16.h"
34 #include "winuser.h"
35 #include "winternl.h"
36 #include "initguid.h"
37 #include "devguid.h"
38 #include "setupapi.h"
39 #include "ddk/d3dkmthk.h"
41 #include "gdi_private.h"
42 #include "wine/list.h"
43 #include "wine/debug.h"
44 #include "wine/heap.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(driver);
48 DEFINE_DEVPROPKEY(DEVPROPKEY_GPU_LUID, 0x60b193cb, 0x5276, 0x4d0f, 0x96, 0xfc, 0xf1, 0x73, 0xab, 0xad, 0x3e, 0xc6, 2);
50 struct graphics_driver
52 struct list entry;
53 HMODULE module; /* module handle */
54 const struct gdi_dc_funcs *funcs;
57 struct d3dkmt_adapter
59 D3DKMT_HANDLE handle; /* Kernel mode graphics adapter handle */
60 struct list entry; /* List entry */
63 struct d3dkmt_device
65 D3DKMT_HANDLE handle; /* Kernel mode graphics device handle*/
66 struct list entry; /* List entry */
69 static struct list drivers = LIST_INIT( drivers );
70 static struct graphics_driver *display_driver;
72 static struct list d3dkmt_adapters = LIST_INIT( d3dkmt_adapters );
73 static struct list d3dkmt_devices = LIST_INIT( d3dkmt_devices );
75 static CRITICAL_SECTION driver_section;
76 static CRITICAL_SECTION_DEBUG critsect_debug =
78 0, 0, &driver_section,
79 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
80 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
82 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
84 static HWND (WINAPI *pGetDesktopWindow)(void);
85 static INT (WINAPI *pGetSystemMetrics)(INT);
86 static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
88 /**********************************************************************
89 * create_driver
91 * Allocate and fill the driver structure for a given module.
93 static struct graphics_driver *create_driver( HMODULE module )
95 static const struct gdi_dc_funcs empty_funcs;
96 const struct gdi_dc_funcs *funcs = NULL;
97 struct graphics_driver *driver;
99 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
100 driver->module = module;
102 if (module)
104 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
106 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
107 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
109 if (!funcs) funcs = &empty_funcs;
110 driver->funcs = funcs;
111 return driver;
115 /**********************************************************************
116 * get_display_driver
118 * Special case for loading the display driver: get the name from the config file
120 static const struct gdi_dc_funcs *get_display_driver(void)
122 if (!display_driver)
124 HMODULE user32 = LoadLibraryA( "user32.dll" );
125 pGetDesktopWindow = (void *)GetProcAddress( user32, "GetDesktopWindow" );
127 if (!pGetDesktopWindow() || !display_driver)
129 WARN( "failed to load the display driver, falling back to null driver\n" );
130 __wine_set_display_driver( 0 );
133 return display_driver->funcs;
137 /**********************************************************************
138 * is_display_device
140 static BOOL is_display_device( LPCWSTR name )
142 const WCHAR *p = name;
144 if (wcsnicmp( name, L"\\\\.\\DISPLAY", lstrlenW(L"\\\\.\\DISPLAY") )) return FALSE;
146 p += lstrlenW(L"\\\\.\\DISPLAY");
148 if (!iswdigit( *p++ ))
149 return FALSE;
151 for (; *p; p++)
153 if (!iswdigit( *p ))
154 return FALSE;
157 return TRUE;
160 static HANDLE get_display_device_init_mutex( void )
162 HANDLE mutex = CreateMutexW( NULL, FALSE, L"display_device_init" );
164 WaitForSingleObject( mutex, INFINITE );
165 return mutex;
168 static void release_display_device_init_mutex( HANDLE mutex )
170 ReleaseMutex( mutex );
171 CloseHandle( mutex );
174 /**********************************************************************
175 * DRIVER_load_driver
177 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
179 HMODULE module;
180 struct graphics_driver *driver, *new_driver;
182 /* display driver is a special case */
183 if (!wcsicmp( name, L"display" ) || is_display_device( name )) return get_display_driver();
185 if ((module = GetModuleHandleW( name )))
187 if (display_driver && display_driver->module == module) return display_driver->funcs;
189 EnterCriticalSection( &driver_section );
190 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
192 if (driver->module == module) goto done;
194 LeaveCriticalSection( &driver_section );
197 if (!(module = LoadLibraryW( name ))) return NULL;
199 if (!(new_driver = create_driver( module )))
201 FreeLibrary( module );
202 return NULL;
205 /* check if someone else added it in the meantime */
206 EnterCriticalSection( &driver_section );
207 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
209 if (driver->module != module) continue;
210 FreeLibrary( module );
211 HeapFree( GetProcessHeap(), 0, new_driver );
212 goto done;
214 driver = new_driver;
215 list_add_head( &drivers, &driver->entry );
216 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
217 done:
218 LeaveCriticalSection( &driver_section );
219 return driver->funcs;
223 /***********************************************************************
224 * __wine_set_display_driver (GDI32.@)
226 void CDECL __wine_set_display_driver( HMODULE module )
228 struct graphics_driver *driver;
229 HMODULE user32;
231 if (!(driver = create_driver( module )))
233 ERR( "Could not create graphics driver\n" );
234 ExitProcess(1);
236 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
237 HeapFree( GetProcessHeap(), 0, driver );
239 user32 = LoadLibraryA( "user32.dll" );
240 pGetSystemMetrics = (void *)GetProcAddress( user32, "GetSystemMetrics" );
241 pSetThreadDpiAwarenessContext = (void *)GetProcAddress( user32, "SetThreadDpiAwarenessContext" );
245 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
247 return 0;
250 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
251 INT xstart, INT ystart, INT xend, INT yend )
253 return TRUE;
256 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
257 INT xstart, INT ystart, INT xend, INT yend )
259 return TRUE;
262 static BOOL CDECL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
264 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
265 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
268 static BOOL CDECL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
269 LPCWSTR output, const DEVMODEW *devmode )
271 assert(0); /* should never be called */
272 return FALSE;
275 static BOOL CDECL nulldrv_DeleteDC( PHYSDEV dev )
277 assert(0); /* should never be called */
278 return TRUE;
281 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
283 return TRUE;
286 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
287 WORD cap, LPSTR output, DEVMODEA *devmode )
289 return -1;
292 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
294 return TRUE;
297 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
299 return 0;
302 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
304 return 0;
307 static BOOL CDECL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
309 return TRUE;
312 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
314 return -1;
317 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
318 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
320 return -1;
323 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
324 INT out_size, void *out_data )
326 return 0;
329 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
331 return TRUE;
334 static BOOL CDECL nulldrv_FontIsLinked( PHYSDEV dev )
336 return FALSE;
339 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
341 return FALSE;
344 static UINT CDECL nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
346 return DCB_RESET;
349 static BOOL CDECL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
351 return FALSE;
354 static BOOL CDECL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
356 return FALSE;
359 static BOOL CDECL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
361 return FALSE;
364 static BOOL CDECL nulldrv_GetCharWidthInfo( PHYSDEV dev, void *info )
366 return FALSE;
369 static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
371 int bpp;
373 switch (cap)
375 case DRIVERVERSION: return 0x4000;
376 case TECHNOLOGY: return DT_RASDISPLAY;
377 case HORZSIZE: return MulDiv( GetDeviceCaps( dev->hdc, HORZRES ), 254,
378 GetDeviceCaps( dev->hdc, LOGPIXELSX ) * 10 );
379 case VERTSIZE: return MulDiv( GetDeviceCaps( dev->hdc, VERTRES ), 254,
380 GetDeviceCaps( dev->hdc, LOGPIXELSY ) * 10 );
381 case HORZRES: return pGetSystemMetrics ? pGetSystemMetrics( SM_CXSCREEN ) : 640;
382 case VERTRES: return pGetSystemMetrics ? pGetSystemMetrics( SM_CYSCREEN ) : 480;
383 case BITSPIXEL: return 32;
384 case PLANES: return 1;
385 case NUMBRUSHES: return -1;
386 case NUMPENS: return -1;
387 case NUMMARKERS: return 0;
388 case NUMFONTS: return 0;
389 case PDEVICESIZE: return 0;
390 case CURVECAPS: return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
391 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
392 case LINECAPS: return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
393 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
394 case POLYGONALCAPS: return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
395 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
396 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
397 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
398 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
399 case CLIPCAPS: return CP_RECTANGLE;
400 case RASTERCAPS: return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DI_BITMAP | RC_DIBTODEV |
401 RC_BIGFONT | RC_STRETCHBLT | RC_FLOODFILL | RC_STRETCHDIB | RC_DEVBITS |
402 (GetDeviceCaps( dev->hdc, SIZEPALETTE ) ? RC_PALETTE : 0));
403 case ASPECTX: return 36;
404 case ASPECTY: return 36;
405 case ASPECTXY: return (int)(hypot( GetDeviceCaps( dev->hdc, ASPECTX ),
406 GetDeviceCaps( dev->hdc, ASPECTY )) + 0.5);
407 case CAPS1: return 0;
408 case SIZEPALETTE: return 0;
409 case NUMRESERVED: return 20;
410 case PHYSICALWIDTH: return 0;
411 case PHYSICALHEIGHT: return 0;
412 case PHYSICALOFFSETX: return 0;
413 case PHYSICALOFFSETY: return 0;
414 case SCALINGFACTORX: return 0;
415 case SCALINGFACTORY: return 0;
416 case VREFRESH: return GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY ? 1 : 0;
417 case DESKTOPHORZRES:
418 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && pGetSystemMetrics)
420 DPI_AWARENESS_CONTEXT context;
421 UINT ret;
422 context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
423 ret = pGetSystemMetrics( SM_CXVIRTUALSCREEN );
424 pSetThreadDpiAwarenessContext( context );
425 return ret;
427 return GetDeviceCaps( dev->hdc, HORZRES );
428 case DESKTOPVERTRES:
429 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && pGetSystemMetrics)
431 DPI_AWARENESS_CONTEXT context;
432 UINT ret;
433 context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
434 ret = pGetSystemMetrics( SM_CYVIRTUALSCREEN );
435 pSetThreadDpiAwarenessContext( context );
436 return ret;
438 return GetDeviceCaps( dev->hdc, VERTRES );
439 case BLTALIGNMENT: return 0;
440 case SHADEBLENDCAPS: return 0;
441 case COLORMGMTCAPS: return 0;
442 case LOGPIXELSX:
443 case LOGPIXELSY: return get_system_dpi();
444 case NUMCOLORS:
445 bpp = GetDeviceCaps( dev->hdc, BITSPIXEL );
446 return (bpp > 8) ? -1 : (1 << bpp);
447 case COLORRES:
448 /* The observed correspondence between BITSPIXEL and COLORRES is:
449 * BITSPIXEL: 8 -> COLORRES: 18
450 * BITSPIXEL: 16 -> COLORRES: 16
451 * BITSPIXEL: 24 -> COLORRES: 24
452 * BITSPIXEL: 32 -> COLORRES: 24 */
453 bpp = GetDeviceCaps( dev->hdc, BITSPIXEL );
454 return (bpp <= 8) ? 18 : min( 24, bpp );
455 default:
456 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
457 return 0;
461 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
463 SetLastError( ERROR_INVALID_PARAMETER );
464 return FALSE;
467 static DWORD CDECL nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
469 return FALSE;
472 static BOOL CDECL nulldrv_GetFontRealizationInfo( PHYSDEV dev, void *info )
474 return FALSE;
477 static DWORD CDECL nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
479 return 0;
482 static DWORD CDECL nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
484 return GDI_ERROR;
487 static DWORD CDECL nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
488 DWORD size, LPVOID buffer, const MAT2 *mat )
490 return GDI_ERROR;
493 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
495 return FALSE;
498 static DWORD CDECL nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
499 struct bitblt_coords *src )
501 return ERROR_NOT_SUPPORTED;
504 static DWORD CDECL nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
506 return 0;
509 static UINT CDECL nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
511 return 0;
514 static UINT CDECL nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
516 return DEFAULT_CHARSET;
519 static BOOL CDECL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
521 return FALSE;
524 static BOOL CDECL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
526 return FALSE;
529 static INT CDECL nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
531 INT ret = 0;
532 LOGFONTW font;
533 DC *dc = get_nulldrv_dc( dev );
535 if (GetObjectW( dc->hFont, sizeof(font), &font ))
537 ret = lstrlenW( font.lfFaceName ) + 1;
538 if (name)
540 lstrcpynW( name, font.lfFaceName, size );
541 ret = min( size, ret );
544 return ret;
547 static BOOL CDECL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
549 return FALSE;
552 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
554 return TRUE;
557 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
559 return TRUE;
562 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
564 return TRUE;
567 static BOOL CDECL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
569 return TRUE;
572 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
573 INT xstart, INT ystart, INT xend, INT yend )
575 return TRUE;
578 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
580 return TRUE;
583 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
585 return TRUE;
588 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
590 INT counts[1] = { count };
592 return PolyPolygon( dev->hdc, points, counts, 1 );
595 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
597 DWORD counts[1] = { count };
599 if (count < 0) return FALSE;
600 return PolyPolyline( dev->hdc, points, counts, 1 );
603 static DWORD CDECL nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
604 const struct gdi_image_bits *bits, struct bitblt_coords *src,
605 struct bitblt_coords *dst, DWORD rop )
607 return ERROR_SUCCESS;
610 static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
612 return 0;
615 static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
617 return 0;
620 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
622 return TRUE;
625 static HDC CDECL nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
627 return 0;
630 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
631 INT ell_width, INT ell_height )
633 return TRUE;
636 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
638 return bitmap;
641 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
643 return brush;
646 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, UINT *aa_flags )
648 return font;
651 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
653 return palette;
656 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
658 return pen;
661 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
663 return dir;
666 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
668 return color;
671 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
673 return mode;
676 static UINT CDECL nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
678 return DCB_RESET;
681 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
683 return color;
686 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
688 return color;
691 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
695 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
697 return layout;
700 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
702 SetLastError( ERROR_INVALID_PARAMETER );
703 return FALSE;
706 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
708 return flags;
711 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
713 return color;
716 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
718 return mode;
721 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
723 return rop;
726 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
728 return mode;
731 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
733 return mode;
736 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
738 return align;
741 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
743 return extra;
746 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
748 return color;
751 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
753 return TRUE;
756 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
758 return 0;
761 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
763 return 1;
766 static BOOL CDECL nulldrv_UnrealizePalette( HPALETTE palette )
768 return FALSE;
771 static NTSTATUS CDECL nulldrv_D3DKMTCheckVidPnExclusiveOwnership( const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *desc )
773 return STATUS_PROCEDURE_NOT_FOUND;
776 static NTSTATUS CDECL nulldrv_D3DKMTSetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER *desc )
778 return STATUS_PROCEDURE_NOT_FOUND;
781 static struct opengl_funcs * CDECL nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
783 return (void *)-1;
786 static const struct vulkan_funcs * CDECL nulldrv_wine_get_vulkan_driver( PHYSDEV dev, UINT version )
788 return NULL;
791 const struct gdi_dc_funcs null_driver =
793 nulldrv_AbortDoc, /* pAbortDoc */
794 nulldrv_AbortPath, /* pAbortPath */
795 nulldrv_AlphaBlend, /* pAlphaBlend */
796 nulldrv_AngleArc, /* pAngleArc */
797 nulldrv_Arc, /* pArc */
798 nulldrv_ArcTo, /* pArcTo */
799 nulldrv_BeginPath, /* pBeginPath */
800 nulldrv_BlendImage, /* pBlendImage */
801 nulldrv_Chord, /* pChord */
802 nulldrv_CloseFigure, /* pCloseFigure */
803 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
804 nulldrv_CreateDC, /* pCreateDC */
805 nulldrv_DeleteDC, /* pDeleteDC */
806 nulldrv_DeleteObject, /* pDeleteObject */
807 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
808 nulldrv_Ellipse, /* pEllipse */
809 nulldrv_EndDoc, /* pEndDoc */
810 nulldrv_EndPage, /* pEndPage */
811 nulldrv_EndPath, /* pEndPath */
812 nulldrv_EnumFonts, /* pEnumFonts */
813 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
814 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
815 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
816 nulldrv_ExtEscape, /* pExtEscape */
817 nulldrv_ExtFloodFill, /* pExtFloodFill */
818 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
819 nulldrv_ExtTextOut, /* pExtTextOut */
820 nulldrv_FillPath, /* pFillPath */
821 nulldrv_FillRgn, /* pFillRgn */
822 nulldrv_FlattenPath, /* pFlattenPath */
823 nulldrv_FontIsLinked, /* pFontIsLinked */
824 nulldrv_FrameRgn, /* pFrameRgn */
825 nulldrv_GdiComment, /* pGdiComment */
826 nulldrv_GetBoundsRect, /* pGetBoundsRect */
827 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
828 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
829 nulldrv_GetCharWidth, /* pGetCharWidth */
830 nulldrv_GetCharWidthInfo, /* pGetCharWidthInfo */
831 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
832 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
833 nulldrv_GetFontData, /* pGetFontData */
834 nulldrv_GetFontRealizationInfo, /* pGetFontRealizationInfo */
835 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
836 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
837 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
838 nulldrv_GetICMProfile, /* pGetICMProfile */
839 nulldrv_GetImage, /* pGetImage */
840 nulldrv_GetKerningPairs, /* pGetKerningPairs */
841 nulldrv_GetNearestColor, /* pGetNearestColor */
842 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
843 nulldrv_GetPixel, /* pGetPixel */
844 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
845 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
846 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
847 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
848 nulldrv_GetTextFace, /* pGetTextFace */
849 nulldrv_GetTextMetrics, /* pGetTextMetrics */
850 nulldrv_GradientFill, /* pGradientFill */
851 nulldrv_IntersectClipRect, /* pIntersectClipRect */
852 nulldrv_InvertRgn, /* pInvertRgn */
853 nulldrv_LineTo, /* pLineTo */
854 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
855 nulldrv_MoveTo, /* pMoveTo */
856 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
857 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
858 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
859 nulldrv_PaintRgn, /* pPaintRgn */
860 nulldrv_PatBlt, /* pPatBlt */
861 nulldrv_Pie, /* pPie */
862 nulldrv_PolyBezier, /* pPolyBezier */
863 nulldrv_PolyBezierTo, /* pPolyBezierTo */
864 nulldrv_PolyDraw, /* pPolyDraw */
865 nulldrv_PolyPolygon, /* pPolyPolygon */
866 nulldrv_PolyPolyline, /* pPolyPolyline */
867 nulldrv_Polygon, /* pPolygon */
868 nulldrv_Polyline, /* pPolyline */
869 nulldrv_PolylineTo, /* pPolylineTo */
870 nulldrv_PutImage, /* pPutImage */
871 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
872 nulldrv_RealizePalette, /* pRealizePalette */
873 nulldrv_Rectangle, /* pRectangle */
874 nulldrv_ResetDC, /* pResetDC */
875 nulldrv_RestoreDC, /* pRestoreDC */
876 nulldrv_RoundRect, /* pRoundRect */
877 nulldrv_SaveDC, /* pSaveDC */
878 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
879 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
880 nulldrv_SelectBitmap, /* pSelectBitmap */
881 nulldrv_SelectBrush, /* pSelectBrush */
882 nulldrv_SelectClipPath, /* pSelectClipPath */
883 nulldrv_SelectFont, /* pSelectFont */
884 nulldrv_SelectPalette, /* pSelectPalette */
885 nulldrv_SelectPen, /* pSelectPen */
886 nulldrv_SetArcDirection, /* pSetArcDirection */
887 nulldrv_SetBkColor, /* pSetBkColor */
888 nulldrv_SetBkMode, /* pSetBkMode */
889 nulldrv_SetBoundsRect, /* pSetBoundsRect */
890 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
891 nulldrv_SetDCPenColor, /* pSetDCPenColor */
892 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
893 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
894 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
895 nulldrv_SetLayout, /* pSetLayout */
896 nulldrv_SetMapMode, /* pSetMapMode */
897 nulldrv_SetMapperFlags, /* pSetMapperFlags */
898 nulldrv_SetPixel, /* pSetPixel */
899 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
900 nulldrv_SetROP2, /* pSetROP2 */
901 nulldrv_SetRelAbs, /* pSetRelAbs */
902 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
903 nulldrv_SetTextAlign, /* pSetTextAlign */
904 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
905 nulldrv_SetTextColor, /* pSetTextColor */
906 nulldrv_SetTextJustification, /* pSetTextJustification */
907 nulldrv_SetViewportExtEx, /* pSetViewportExt */
908 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
909 nulldrv_SetWindowExtEx, /* pSetWindowExt */
910 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
911 nulldrv_SetWorldTransform, /* pSetWorldTransform */
912 nulldrv_StartDoc, /* pStartDoc */
913 nulldrv_StartPage, /* pStartPage */
914 nulldrv_StretchBlt, /* pStretchBlt */
915 nulldrv_StretchDIBits, /* pStretchDIBits */
916 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
917 nulldrv_StrokePath, /* pStrokePath */
918 nulldrv_UnrealizePalette, /* pUnrealizePalette */
919 nulldrv_WidenPath, /* pWidenPath */
920 nulldrv_D3DKMTCheckVidPnExclusiveOwnership, /* pD3DKMTCheckVidPnExclusiveOwnership */
921 nulldrv_D3DKMTSetVidPnSourceOwner, /* pD3DKMTSetVidPnSourceOwner */
922 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
923 nulldrv_wine_get_vulkan_driver, /* wine_get_vulkan_driver */
925 GDI_PRIORITY_NULL_DRV /* priority */
929 /*****************************************************************************
930 * DRIVER_GetDriverName
933 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
935 WCHAR *p;
937 /* display is a special case */
938 if (!wcsicmp( device, L"display" ) || is_display_device( device ))
940 lstrcpynW( driver, L"display", size );
941 return TRUE;
944 size = GetProfileStringW(L"devices", device, L"", driver, size);
945 if(!size) {
946 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
947 return FALSE;
949 p = wcschr(driver, ',');
950 if(!p)
952 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
953 return FALSE;
955 *p = 0;
956 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
957 return TRUE;
961 /***********************************************************************
962 * GdiConvertToDevmodeW (GDI32.@)
964 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
966 DEVMODEW *dmW;
967 WORD dmW_size, dmA_size;
969 dmA_size = dmA->dmSize;
971 /* this is the minimal dmSize that XP accepts */
972 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
973 return NULL;
975 if (dmA_size > sizeof(DEVMODEA))
976 dmA_size = sizeof(DEVMODEA);
978 dmW_size = dmA_size + CCHDEVICENAME;
979 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
980 dmW_size += CCHFORMNAME;
982 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
983 if (!dmW) return NULL;
985 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
986 dmW->dmDeviceName, CCHDEVICENAME);
987 /* copy slightly more, to avoid long computations */
988 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
990 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
992 if (dmA->dmFields & DM_FORMNAME)
993 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
994 dmW->dmFormName, CCHFORMNAME);
995 else
996 dmW->dmFormName[0] = 0;
998 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
999 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
1002 if (dmA->dmDriverExtra)
1003 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
1005 dmW->dmSize = dmW_size;
1007 return dmW;
1011 /*****************************************************************************
1012 * @ [GDI32.100]
1014 * This should thunk to 16-bit and simply call the proc with the given args.
1016 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
1017 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
1019 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
1020 return -1;
1023 /*****************************************************************************
1024 * @ [GDI32.101]
1026 * This should load the correct driver for lpszDevice and calls this driver's
1027 * ExtDeviceModePropSheet proc.
1029 * Note: The driver calls a callback routine for each property sheet page; these
1030 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
1031 * The layout of this structure is:
1033 * struct
1035 * DWORD nPages;
1036 * DWORD unknown;
1037 * HPROPSHEETPAGE pages[10];
1038 * };
1040 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
1041 LPCSTR lpszPort, LPVOID lpPropSheet )
1043 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
1044 return -1;
1047 /*****************************************************************************
1048 * @ [GDI32.102]
1050 * This should load the correct driver for lpszDevice and call this driver's
1051 * ExtDeviceMode proc.
1053 * FIXME: convert ExtDeviceMode to unicode in the driver interface
1055 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1056 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1057 LPSTR lpszPort, LPDEVMODEA lpdmInput,
1058 LPSTR lpszProfile, DWORD fwMode )
1060 WCHAR deviceW[300];
1061 WCHAR bufW[300];
1062 char buf[300];
1063 HDC hdc;
1064 DC *dc;
1065 INT ret = -1;
1067 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1068 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1070 if (!lpszDevice) return -1;
1071 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1073 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1075 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1077 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1079 if ((dc = get_dc_ptr( hdc )))
1081 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1082 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1083 lpdmInput, lpszProfile, fwMode );
1084 release_dc_ptr( dc );
1086 DeleteDC( hdc );
1087 return ret;
1090 /****************************************************************************
1091 * @ [GDI32.103]
1093 * This should load the correct driver for lpszDevice and calls this driver's
1094 * AdvancedSetupDialog proc.
1096 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1097 LPDEVMODEA devin, LPDEVMODEA devout )
1099 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1100 return -1;
1103 /*****************************************************************************
1104 * @ [GDI32.104]
1106 * This should load the correct driver for lpszDevice and calls this driver's
1107 * DeviceCapabilities proc.
1109 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1111 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1112 WORD fwCapability, LPSTR lpszOutput,
1113 LPDEVMODEA lpdm )
1115 WCHAR deviceW[300];
1116 WCHAR bufW[300];
1117 char buf[300];
1118 HDC hdc;
1119 DC *dc;
1120 INT ret = -1;
1122 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1124 if (!lpszDevice) return -1;
1125 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1127 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1129 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1131 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1133 if ((dc = get_dc_ptr( hdc )))
1135 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1136 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1137 fwCapability, lpszOutput, lpdm );
1138 release_dc_ptr( dc );
1140 DeleteDC( hdc );
1141 return ret;
1145 /************************************************************************
1146 * Escape [GDI32.@]
1148 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1150 INT ret;
1151 POINT *pt;
1153 switch (escape)
1155 case ABORTDOC:
1156 return AbortDoc( hdc );
1158 case ENDDOC:
1159 return EndDoc( hdc );
1161 case GETPHYSPAGESIZE:
1162 pt = out_data;
1163 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1164 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1165 return 1;
1167 case GETPRINTINGOFFSET:
1168 pt = out_data;
1169 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1170 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1171 return 1;
1173 case GETSCALINGFACTOR:
1174 pt = out_data;
1175 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1176 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1177 return 1;
1179 case NEWFRAME:
1180 return EndPage( hdc );
1182 case SETABORTPROC:
1183 return SetAbortProc( hdc, (ABORTPROC)in_data );
1185 case STARTDOC:
1187 DOCINFOA doc;
1188 char *name = NULL;
1190 /* in_data may not be 0 terminated so we must copy it */
1191 if (in_data)
1193 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1194 memcpy( name, in_data, in_count );
1195 name[in_count] = 0;
1197 /* out_data is actually a pointer to the DocInfo structure and used as
1198 * a second input parameter */
1199 if (out_data) doc = *(DOCINFOA *)out_data;
1200 else
1202 doc.cbSize = sizeof(doc);
1203 doc.lpszOutput = NULL;
1204 doc.lpszDatatype = NULL;
1205 doc.fwType = 0;
1207 doc.lpszDocName = name;
1208 ret = StartDocA( hdc, &doc );
1209 HeapFree( GetProcessHeap(), 0, name );
1210 if (ret > 0) ret = StartPage( hdc );
1211 return ret;
1214 case QUERYESCSUPPORT:
1216 DWORD code;
1218 if (in_count < sizeof(SHORT)) return 0;
1219 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1220 switch (code)
1222 case ABORTDOC:
1223 case ENDDOC:
1224 case GETPHYSPAGESIZE:
1225 case GETPRINTINGOFFSET:
1226 case GETSCALINGFACTOR:
1227 case NEWFRAME:
1228 case QUERYESCSUPPORT:
1229 case SETABORTPROC:
1230 case STARTDOC:
1231 return TRUE;
1233 break;
1237 /* if not handled internally, pass it to the driver */
1238 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1242 /******************************************************************************
1243 * ExtEscape [GDI32.@]
1245 * Access capabilities of a particular device that are not available through GDI.
1247 * PARAMS
1248 * hdc [I] Handle to device context
1249 * nEscape [I] Escape function
1250 * cbInput [I] Number of bytes in input structure
1251 * lpszInData [I] Pointer to input structure
1252 * cbOutput [I] Number of bytes in output structure
1253 * lpszOutData [O] Pointer to output structure
1255 * RETURNS
1256 * Success: >0
1257 * Not implemented: 0
1258 * Failure: <0
1260 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1261 INT cbOutput, LPSTR lpszOutData )
1263 PHYSDEV physdev;
1264 INT ret;
1265 DC * dc = get_dc_ptr( hdc );
1267 if (!dc) return 0;
1268 update_dc( dc );
1269 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1270 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1271 release_dc_ptr( dc );
1272 return ret;
1276 /*******************************************************************
1277 * DrawEscape [GDI32.@]
1281 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1283 FIXME("DrawEscape, stub\n");
1284 return 0;
1287 /*******************************************************************
1288 * NamedEscape [GDI32.@]
1290 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1291 INT cbOutput, LPSTR lpszOutData )
1293 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1294 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1295 lpszOutData);
1296 return 0;
1299 /*******************************************************************
1300 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1301 * GdiEntry13 [GDI32.@]
1303 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1305 static int warn_once;
1307 if (!warn_once++)
1308 FIXME("stub\n");
1309 return 0;
1312 /******************************************************************************
1313 * D3DKMTOpenAdapterFromHdc [GDI32.@]
1315 NTSTATUS WINAPI D3DKMTOpenAdapterFromHdc( void *pData )
1317 FIXME("(%p): stub\n", pData);
1318 return STATUS_NO_MEMORY;
1321 /******************************************************************************
1322 * D3DKMTEscape [GDI32.@]
1324 NTSTATUS WINAPI D3DKMTEscape( const void *pData )
1326 FIXME("(%p): stub\n", pData);
1327 return STATUS_NO_MEMORY;
1330 /******************************************************************************
1331 * D3DKMTCloseAdapter [GDI32.@]
1333 NTSTATUS WINAPI D3DKMTCloseAdapter( const D3DKMT_CLOSEADAPTER *desc )
1335 NTSTATUS status = STATUS_INVALID_PARAMETER;
1336 struct d3dkmt_adapter *adapter;
1338 TRACE("(%p)\n", desc);
1340 if (!desc || !desc->hAdapter)
1341 return STATUS_INVALID_PARAMETER;
1343 EnterCriticalSection( &driver_section );
1344 LIST_FOR_EACH_ENTRY( adapter, &d3dkmt_adapters, struct d3dkmt_adapter, entry )
1346 if (adapter->handle == desc->hAdapter)
1348 list_remove( &adapter->entry );
1349 heap_free( adapter );
1350 status = STATUS_SUCCESS;
1351 break;
1354 LeaveCriticalSection( &driver_section );
1356 return status;
1359 /******************************************************************************
1360 * D3DKMTOpenAdapterFromGdiDisplayName [GDI32.@]
1362 NTSTATUS WINAPI D3DKMTOpenAdapterFromGdiDisplayName( D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME *desc )
1364 WCHAR *end, key_nameW[MAX_PATH], bufferW[MAX_PATH];
1365 HDEVINFO devinfo = INVALID_HANDLE_VALUE;
1366 NTSTATUS status = STATUS_UNSUCCESSFUL;
1367 static D3DKMT_HANDLE handle_start = 0;
1368 struct d3dkmt_adapter *adapter;
1369 SP_DEVINFO_DATA device_data;
1370 DWORD size, state_flags;
1371 DEVPROPTYPE type;
1372 HANDLE mutex;
1373 LUID luid;
1374 int index;
1376 TRACE("(%p)\n", desc);
1378 if (!desc)
1379 return STATUS_UNSUCCESSFUL;
1381 TRACE("DeviceName: %s\n", wine_dbgstr_w( desc->DeviceName ));
1382 if (wcsnicmp( desc->DeviceName, L"\\\\.\\DISPLAY", lstrlenW(L"\\\\.\\DISPLAY") ))
1383 return STATUS_UNSUCCESSFUL;
1385 index = wcstol( desc->DeviceName + lstrlenW(L"\\\\.\\DISPLAY"), &end, 10 ) - 1;
1386 if (*end)
1387 return STATUS_UNSUCCESSFUL;
1389 adapter = heap_alloc( sizeof( *adapter ) );
1390 if (!adapter)
1391 return STATUS_NO_MEMORY;
1393 /* Get adapter LUID from SetupAPI */
1394 mutex = get_display_device_init_mutex();
1396 size = sizeof( bufferW );
1397 swprintf( key_nameW, MAX_PATH, L"\\Device\\Video%d", index );
1398 if (RegGetValueW( HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\VIDEO", key_nameW, RRF_RT_REG_SZ, NULL, bufferW, &size ))
1399 goto done;
1401 /* Strip \Registry\Machine\ prefix and retrieve Wine specific data set by the display driver */
1402 lstrcpyW( key_nameW, bufferW + 18 );
1403 size = sizeof( state_flags );
1404 if (RegGetValueW( HKEY_CURRENT_CONFIG, key_nameW, L"StateFlags", RRF_RT_REG_DWORD, NULL,
1405 &state_flags, &size ))
1406 goto done;
1408 if (!(state_flags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
1409 goto done;
1411 size = sizeof( bufferW );
1412 if (RegGetValueW( HKEY_CURRENT_CONFIG, key_nameW, L"GPUID", RRF_RT_REG_SZ, NULL, bufferW, &size ))
1413 goto done;
1415 devinfo = SetupDiCreateDeviceInfoList( &GUID_DEVCLASS_DISPLAY, NULL );
1416 device_data.cbSize = sizeof( device_data );
1417 SetupDiOpenDeviceInfoW( devinfo, bufferW, NULL, 0, &device_data );
1418 if (!SetupDiGetDevicePropertyW( devinfo, &device_data, &DEVPROPKEY_GPU_LUID, &type,
1419 (BYTE *)&luid, sizeof( luid ), NULL, 0))
1420 goto done;
1422 EnterCriticalSection( &driver_section );
1423 /* D3DKMT_HANDLE is UINT, so we can't use pointer as handle */
1424 adapter->handle = ++handle_start;
1425 list_add_tail( &d3dkmt_adapters, &adapter->entry );
1426 LeaveCriticalSection( &driver_section );
1428 desc->hAdapter = handle_start;
1429 desc->AdapterLuid = luid;
1430 desc->VidPnSourceId = index;
1431 status = STATUS_SUCCESS;
1433 done:
1434 SetupDiDestroyDeviceInfoList( devinfo );
1435 release_display_device_init_mutex( mutex );
1436 if (status != STATUS_SUCCESS)
1437 heap_free( adapter );
1438 return status;
1441 /******************************************************************************
1442 * D3DKMTCreateDevice [GDI32.@]
1444 NTSTATUS WINAPI D3DKMTCreateDevice( D3DKMT_CREATEDEVICE *desc )
1446 static D3DKMT_HANDLE handle_start = 0;
1447 struct d3dkmt_adapter *adapter;
1448 struct d3dkmt_device *device;
1449 BOOL found = FALSE;
1451 TRACE("(%p)\n", desc);
1453 if (!desc)
1454 return STATUS_INVALID_PARAMETER;
1456 EnterCriticalSection( &driver_section );
1457 LIST_FOR_EACH_ENTRY( adapter, &d3dkmt_adapters, struct d3dkmt_adapter, entry )
1459 if (adapter->handle == desc->hAdapter)
1461 found = TRUE;
1462 break;
1465 LeaveCriticalSection( &driver_section );
1467 if (!found)
1468 return STATUS_INVALID_PARAMETER;
1470 if (desc->Flags.LegacyMode || desc->Flags.RequestVSync || desc->Flags.DisableGpuTimeout)
1471 FIXME("Flags unsupported.\n");
1473 device = heap_alloc_zero( sizeof( *device ) );
1474 if (!device)
1475 return STATUS_NO_MEMORY;
1477 EnterCriticalSection( &driver_section );
1478 device->handle = ++handle_start;
1479 list_add_tail( &d3dkmt_devices, &device->entry );
1480 LeaveCriticalSection( &driver_section );
1482 desc->hDevice = device->handle;
1483 return STATUS_SUCCESS;
1486 /******************************************************************************
1487 * D3DKMTDestroyDevice [GDI32.@]
1489 NTSTATUS WINAPI D3DKMTDestroyDevice( const D3DKMT_DESTROYDEVICE *desc )
1491 NTSTATUS status = STATUS_INVALID_PARAMETER;
1492 D3DKMT_SETVIDPNSOURCEOWNER set_owner_desc;
1493 struct d3dkmt_device *device;
1495 TRACE("(%p)\n", desc);
1497 if (!desc || !desc->hDevice)
1498 return STATUS_INVALID_PARAMETER;
1500 EnterCriticalSection( &driver_section );
1501 LIST_FOR_EACH_ENTRY( device, &d3dkmt_devices, struct d3dkmt_device, entry )
1503 if (device->handle == desc->hDevice)
1505 memset( &set_owner_desc, 0, sizeof(set_owner_desc) );
1506 set_owner_desc.hDevice = desc->hDevice;
1507 D3DKMTSetVidPnSourceOwner( &set_owner_desc );
1508 list_remove( &device->entry );
1509 heap_free( device );
1510 status = STATUS_SUCCESS;
1511 break;
1514 LeaveCriticalSection( &driver_section );
1516 return status;
1519 /******************************************************************************
1520 * D3DKMTQueryStatistics [GDI32.@]
1522 NTSTATUS WINAPI D3DKMTQueryStatistics(D3DKMT_QUERYSTATISTICS *stats)
1524 FIXME("(%p): stub\n", stats);
1525 return STATUS_SUCCESS;
1528 /******************************************************************************
1529 * D3DKMTSetQueuedLimit [GDI32.@]
1531 NTSTATUS WINAPI D3DKMTSetQueuedLimit( D3DKMT_SETQUEUEDLIMIT *desc )
1533 FIXME( "(%p): stub\n", desc );
1534 return STATUS_NOT_IMPLEMENTED;
1537 /******************************************************************************
1538 * D3DKMTSetVidPnSourceOwner [GDI32.@]
1540 NTSTATUS WINAPI D3DKMTSetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER *desc )
1542 TRACE("(%p)\n", desc);
1544 if (!get_display_driver()->pD3DKMTSetVidPnSourceOwner)
1545 return STATUS_PROCEDURE_NOT_FOUND;
1547 if (!desc || !desc->hDevice || (desc->VidPnSourceCount && (!desc->pType || !desc->pVidPnSourceId)))
1548 return STATUS_INVALID_PARAMETER;
1550 /* Store the VidPN source ownership info in the graphics driver because
1551 * the graphics driver needs to change ownership sometimes. For example,
1552 * when a new window is moved to a VidPN source with an exclusive owner,
1553 * such an exclusive owner will be released before showing the new window */
1554 return get_display_driver()->pD3DKMTSetVidPnSourceOwner( desc );
1557 /******************************************************************************
1558 * D3DKMTCheckVidPnExclusiveOwnership [GDI32.@]
1560 NTSTATUS WINAPI D3DKMTCheckVidPnExclusiveOwnership( const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *desc )
1562 TRACE("(%p)\n", desc);
1564 if (!get_display_driver()->pD3DKMTCheckVidPnExclusiveOwnership)
1565 return STATUS_PROCEDURE_NOT_FOUND;
1567 if (!desc || !desc->hAdapter)
1568 return STATUS_INVALID_PARAMETER;
1570 return get_display_driver()->pD3DKMTCheckVidPnExclusiveOwnership( desc );