rasapi32: Update spec file.
[wine/zf.git] / dlls / gdi32 / driver.c
blob09b051cd6fae03a15db313b05d2b774521cd4d8f
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 BOOL (WINAPI *pEnumDisplayMonitors)(HDC, LPRECT, MONITORENUMPROC, LPARAM);
85 static BOOL (WINAPI *pEnumDisplaySettingsW)(LPCWSTR, DWORD, LPDEVMODEW);
86 static HWND (WINAPI *pGetDesktopWindow)(void);
87 static BOOL (WINAPI *pGetMonitorInfoW)(HMONITOR, LPMONITORINFO);
88 static INT (WINAPI *pGetSystemMetrics)(INT);
89 static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
91 /**********************************************************************
92 * create_driver
94 * Allocate and fill the driver structure for a given module.
96 static struct graphics_driver *create_driver( HMODULE module )
98 static const struct gdi_dc_funcs empty_funcs;
99 const struct gdi_dc_funcs *funcs = NULL;
100 struct graphics_driver *driver;
102 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
103 driver->module = module;
105 if (module)
107 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
109 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
110 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
112 if (!funcs) funcs = &empty_funcs;
113 driver->funcs = funcs;
114 return driver;
118 /**********************************************************************
119 * get_display_driver
121 * Special case for loading the display driver: get the name from the config file
123 static const struct gdi_dc_funcs *get_display_driver(void)
125 if (!display_driver)
127 HMODULE user32 = LoadLibraryA( "user32.dll" );
128 pGetDesktopWindow = (void *)GetProcAddress( user32, "GetDesktopWindow" );
130 if (!pGetDesktopWindow() || !display_driver)
132 WARN( "failed to load the display driver, falling back to null driver\n" );
133 __wine_set_display_driver( 0 );
136 return display_driver->funcs;
140 /**********************************************************************
141 * is_display_device
143 BOOL is_display_device( LPCWSTR name )
145 const WCHAR *p = name;
147 if (!name)
148 return FALSE;
150 if (wcsnicmp( name, L"\\\\.\\DISPLAY", lstrlenW(L"\\\\.\\DISPLAY") )) return FALSE;
152 p += lstrlenW(L"\\\\.\\DISPLAY");
154 if (!iswdigit( *p++ ))
155 return FALSE;
157 for (; *p; p++)
159 if (!iswdigit( *p ))
160 return FALSE;
163 return TRUE;
166 static HANDLE get_display_device_init_mutex( void )
168 HANDLE mutex = CreateMutexW( NULL, FALSE, L"display_device_init" );
170 WaitForSingleObject( mutex, INFINITE );
171 return mutex;
174 static void release_display_device_init_mutex( HANDLE mutex )
176 ReleaseMutex( mutex );
177 CloseHandle( mutex );
180 #ifdef __i386__
181 static const WCHAR printer_env[] = L"w32x86";
182 #elif defined __x86_64__
183 static const WCHAR printer_env[] = L"x64";
184 #elif defined __arm__
185 static const WCHAR printer_env[] = L"arm";
186 #elif defined __aarch64__
187 static const WCHAR printer_env[] = L"arm64";
188 #else
189 #error not defined for this cpu
190 #endif
192 /**********************************************************************
193 * DRIVER_load_driver
195 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
197 HMODULE module;
198 struct graphics_driver *driver, *new_driver;
200 /* display driver is a special case */
201 if (!wcsicmp( name, L"display" ) || is_display_device( name )) return get_display_driver();
203 if ((module = GetModuleHandleW( name )))
205 if (display_driver && display_driver->module == module) return display_driver->funcs;
207 EnterCriticalSection( &driver_section );
208 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
210 if (driver->module == module) goto done;
212 LeaveCriticalSection( &driver_section );
215 if (!(module = LoadLibraryW( name )))
217 WCHAR path[MAX_PATH];
219 GetSystemDirectoryW( path, MAX_PATH );
220 swprintf( path + wcslen(path), MAX_PATH - wcslen(path), L"\\spool\\drivers\\%s\\3\\%s",
221 printer_env, name );
222 if (!(module = LoadLibraryW( path ))) return NULL;
225 if (!(new_driver = create_driver( module )))
227 FreeLibrary( module );
228 return NULL;
231 /* check if someone else added it in the meantime */
232 EnterCriticalSection( &driver_section );
233 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
235 if (driver->module != module) continue;
236 FreeLibrary( module );
237 HeapFree( GetProcessHeap(), 0, new_driver );
238 goto done;
240 driver = new_driver;
241 list_add_head( &drivers, &driver->entry );
242 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
243 done:
244 LeaveCriticalSection( &driver_section );
245 return driver->funcs;
249 /***********************************************************************
250 * __wine_set_display_driver (GDI32.@)
252 void CDECL __wine_set_display_driver( HMODULE module )
254 struct graphics_driver *driver;
255 HMODULE user32;
257 if (!(driver = create_driver( module )))
259 ERR( "Could not create graphics driver\n" );
260 ExitProcess(1);
262 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
263 HeapFree( GetProcessHeap(), 0, driver );
265 user32 = LoadLibraryA( "user32.dll" );
266 pGetMonitorInfoW = (void *)GetProcAddress( user32, "GetMonitorInfoW" );
267 pGetSystemMetrics = (void *)GetProcAddress( user32, "GetSystemMetrics" );
268 pEnumDisplayMonitors = (void *)GetProcAddress( user32, "EnumDisplayMonitors" );
269 pEnumDisplaySettingsW = (void *)GetProcAddress( user32, "EnumDisplaySettingsW" );
270 pSetThreadDpiAwarenessContext = (void *)GetProcAddress( user32, "SetThreadDpiAwarenessContext" );
273 struct monitor_info
275 const WCHAR *name;
276 RECT rect;
279 static BOOL CALLBACK monitor_enum_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lparam )
281 struct monitor_info *info = (struct monitor_info *)lparam;
282 MONITORINFOEXW mi;
284 mi.cbSize = sizeof(mi);
285 pGetMonitorInfoW( monitor, (MONITORINFO *)&mi );
286 if (!lstrcmpiW( info->name, mi.szDevice ))
288 info->rect = mi.rcMonitor;
289 return FALSE;
292 return TRUE;
295 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
297 return 0;
300 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
301 INT xstart, INT ystart, INT xend, INT yend )
303 return TRUE;
306 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
307 INT xstart, INT ystart, INT xend, INT yend )
309 return TRUE;
312 static BOOL CDECL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
314 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
315 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
318 static BOOL CDECL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
319 LPCWSTR output, const DEVMODEW *devmode )
321 assert(0); /* should never be called */
322 return FALSE;
325 static BOOL CDECL nulldrv_DeleteDC( PHYSDEV dev )
327 assert(0); /* should never be called */
328 return TRUE;
331 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
333 return TRUE;
336 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
337 WORD cap, LPSTR output, DEVMODEA *devmode )
339 return -1;
342 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
344 return TRUE;
347 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
349 return 0;
352 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
354 return 0;
357 static BOOL CDECL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
359 return TRUE;
362 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
364 return -1;
367 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
368 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
370 return -1;
373 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
374 INT out_size, void *out_data )
376 return 0;
379 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
381 return TRUE;
384 static BOOL CDECL nulldrv_FontIsLinked( PHYSDEV dev )
386 return FALSE;
389 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
391 return FALSE;
394 static UINT CDECL nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
396 return DCB_RESET;
399 static BOOL CDECL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
401 return FALSE;
404 static BOOL CDECL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
406 return FALSE;
409 static BOOL CDECL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
411 return FALSE;
414 static BOOL CDECL nulldrv_GetCharWidthInfo( PHYSDEV dev, void *info )
416 return FALSE;
419 static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
421 int bpp;
423 switch (cap)
425 case DRIVERVERSION: return 0x4000;
426 case TECHNOLOGY: return DT_RASDISPLAY;
427 case HORZSIZE: return MulDiv( GetDeviceCaps( dev->hdc, HORZRES ), 254,
428 GetDeviceCaps( dev->hdc, LOGPIXELSX ) * 10 );
429 case VERTSIZE: return MulDiv( GetDeviceCaps( dev->hdc, VERTRES ), 254,
430 GetDeviceCaps( dev->hdc, LOGPIXELSY ) * 10 );
431 case HORZRES:
433 DC *dc = get_nulldrv_dc( dev );
434 struct monitor_info info;
436 if (dc->display[0] && pEnumDisplayMonitors && pGetMonitorInfoW)
438 info.name = dc->display;
439 SetRectEmpty( &info.rect );
440 pEnumDisplayMonitors( NULL, NULL, monitor_enum_proc, (LPARAM)&info );
441 if (!IsRectEmpty( &info.rect ))
442 return info.rect.right - info.rect.left;
445 return pGetSystemMetrics ? pGetSystemMetrics( SM_CXSCREEN ) : 640;
447 case VERTRES:
449 DC *dc = get_nulldrv_dc( dev );
450 struct monitor_info info;
452 if (dc->display[0] && pEnumDisplayMonitors && pGetMonitorInfoW)
454 info.name = dc->display;
455 SetRectEmpty( &info.rect );
456 pEnumDisplayMonitors( NULL, NULL, monitor_enum_proc, (LPARAM)&info );
457 if (!IsRectEmpty( &info.rect ))
458 return info.rect.bottom - info.rect.top;
461 return pGetSystemMetrics ? pGetSystemMetrics( SM_CYSCREEN ) : 480;
463 case BITSPIXEL: return 32;
464 case PLANES: return 1;
465 case NUMBRUSHES: return -1;
466 case NUMPENS: return -1;
467 case NUMMARKERS: return 0;
468 case NUMFONTS: return 0;
469 case PDEVICESIZE: return 0;
470 case CURVECAPS: return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
471 CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
472 case LINECAPS: return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
473 LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
474 case POLYGONALCAPS: return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
475 PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
476 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
477 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
478 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
479 case CLIPCAPS: return CP_RECTANGLE;
480 case RASTERCAPS: return (RC_BITBLT | RC_BITMAP64 | RC_GDI20_OUTPUT | RC_DI_BITMAP | RC_DIBTODEV |
481 RC_BIGFONT | RC_STRETCHBLT | RC_FLOODFILL | RC_STRETCHDIB | RC_DEVBITS |
482 (GetDeviceCaps( dev->hdc, SIZEPALETTE ) ? RC_PALETTE : 0));
483 case ASPECTX: return 36;
484 case ASPECTY: return 36;
485 case ASPECTXY: return (int)(hypot( GetDeviceCaps( dev->hdc, ASPECTX ),
486 GetDeviceCaps( dev->hdc, ASPECTY )) + 0.5);
487 case CAPS1: return 0;
488 case SIZEPALETTE: return 0;
489 case NUMRESERVED: return 20;
490 case PHYSICALWIDTH: return 0;
491 case PHYSICALHEIGHT: return 0;
492 case PHYSICALOFFSETX: return 0;
493 case PHYSICALOFFSETY: return 0;
494 case SCALINGFACTORX: return 0;
495 case SCALINGFACTORY: return 0;
496 case VREFRESH:
498 DEVMODEW devmode;
499 WCHAR *display;
500 DC *dc;
502 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) != DT_RASDISPLAY)
503 return 0;
505 if (pEnumDisplaySettingsW)
507 dc = get_nulldrv_dc( dev );
509 memset( &devmode, 0, sizeof(devmode) );
510 devmode.dmSize = sizeof(devmode);
511 display = dc->display[0] ? dc->display : NULL;
512 if (pEnumDisplaySettingsW( display, ENUM_CURRENT_SETTINGS, &devmode ))
513 return devmode.dmDisplayFrequency ? devmode.dmDisplayFrequency : 1;
516 return 1;
518 case DESKTOPHORZRES:
519 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && pGetSystemMetrics)
521 DPI_AWARENESS_CONTEXT context;
522 UINT ret;
523 context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
524 ret = pGetSystemMetrics( SM_CXVIRTUALSCREEN );
525 pSetThreadDpiAwarenessContext( context );
526 return ret;
528 return GetDeviceCaps( dev->hdc, HORZRES );
529 case DESKTOPVERTRES:
530 if (GetDeviceCaps( dev->hdc, TECHNOLOGY ) == DT_RASDISPLAY && pGetSystemMetrics)
532 DPI_AWARENESS_CONTEXT context;
533 UINT ret;
534 context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
535 ret = pGetSystemMetrics( SM_CYVIRTUALSCREEN );
536 pSetThreadDpiAwarenessContext( context );
537 return ret;
539 return GetDeviceCaps( dev->hdc, VERTRES );
540 case BLTALIGNMENT: return 0;
541 case SHADEBLENDCAPS: return 0;
542 case COLORMGMTCAPS: return 0;
543 case LOGPIXELSX:
544 case LOGPIXELSY: return get_system_dpi();
545 case NUMCOLORS:
546 bpp = GetDeviceCaps( dev->hdc, BITSPIXEL );
547 return (bpp > 8) ? -1 : (1 << bpp);
548 case COLORRES:
549 /* The observed correspondence between BITSPIXEL and COLORRES is:
550 * BITSPIXEL: 8 -> COLORRES: 18
551 * BITSPIXEL: 16 -> COLORRES: 16
552 * BITSPIXEL: 24 -> COLORRES: 24
553 * BITSPIXEL: 32 -> COLORRES: 24 */
554 bpp = GetDeviceCaps( dev->hdc, BITSPIXEL );
555 return (bpp <= 8) ? 18 : min( 24, bpp );
556 default:
557 FIXME("(%p): unsupported capability %d, will return 0\n", dev->hdc, cap );
558 return 0;
562 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
564 SetLastError( ERROR_INVALID_PARAMETER );
565 return FALSE;
568 static DWORD CDECL nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
570 return FALSE;
573 static BOOL CDECL nulldrv_GetFontRealizationInfo( PHYSDEV dev, void *info )
575 return FALSE;
578 static DWORD CDECL nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
580 return 0;
583 static DWORD CDECL nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
585 return GDI_ERROR;
588 static DWORD CDECL nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
589 DWORD size, LPVOID buffer, const MAT2 *mat )
591 return GDI_ERROR;
594 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
596 return FALSE;
599 static DWORD CDECL nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
600 struct bitblt_coords *src )
602 return ERROR_NOT_SUPPORTED;
605 static DWORD CDECL nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
607 return 0;
610 static UINT CDECL nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
612 return 0;
615 static UINT CDECL nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
617 return DEFAULT_CHARSET;
620 static BOOL CDECL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
622 return FALSE;
625 static BOOL CDECL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
627 return FALSE;
630 static INT CDECL nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
632 INT ret = 0;
633 LOGFONTW font;
634 DC *dc = get_nulldrv_dc( dev );
636 if (GetObjectW( dc->hFont, sizeof(font), &font ))
638 ret = lstrlenW( font.lfFaceName ) + 1;
639 if (name)
641 lstrcpynW( name, font.lfFaceName, size );
642 ret = min( size, ret );
645 return ret;
648 static BOOL CDECL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
650 return FALSE;
653 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
655 return TRUE;
658 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
660 return TRUE;
663 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
665 return TRUE;
668 static BOOL CDECL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
670 return TRUE;
673 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
674 INT xstart, INT ystart, INT xend, INT yend )
676 return TRUE;
679 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
681 return TRUE;
684 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
686 return TRUE;
689 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
691 INT counts[1] = { count };
693 return PolyPolygon( dev->hdc, points, counts, 1 );
696 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
698 DWORD counts[1] = { count };
700 if (count < 0) return FALSE;
701 return PolyPolyline( dev->hdc, points, counts, 1 );
704 static DWORD CDECL nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
705 const struct gdi_image_bits *bits, struct bitblt_coords *src,
706 struct bitblt_coords *dst, DWORD rop )
708 return ERROR_SUCCESS;
711 static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
713 return 0;
716 static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
718 return 0;
721 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
723 return TRUE;
726 static HDC CDECL nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
728 return 0;
731 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
732 INT ell_width, INT ell_height )
734 return TRUE;
737 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
739 return bitmap;
742 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
744 return brush;
747 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, UINT *aa_flags )
749 return font;
752 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
754 return palette;
757 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
759 return pen;
762 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
764 return dir;
767 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
769 return color;
772 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
774 return mode;
777 static UINT CDECL nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
779 return DCB_RESET;
782 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
784 return color;
787 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
789 return color;
792 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
796 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
798 return layout;
801 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
803 SetLastError( ERROR_INVALID_PARAMETER );
804 return FALSE;
807 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
809 return flags;
812 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
814 return color;
817 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
819 return mode;
822 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
824 return rop;
827 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
829 return mode;
832 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
834 return mode;
837 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
839 return align;
842 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
844 return extra;
847 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
849 return color;
852 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
854 return TRUE;
857 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
859 return 0;
862 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
864 return 1;
867 static BOOL CDECL nulldrv_UnrealizePalette( HPALETTE palette )
869 return FALSE;
872 static NTSTATUS CDECL nulldrv_D3DKMTCheckVidPnExclusiveOwnership( const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *desc )
874 return STATUS_PROCEDURE_NOT_FOUND;
877 static NTSTATUS CDECL nulldrv_D3DKMTSetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER *desc )
879 return STATUS_PROCEDURE_NOT_FOUND;
882 static struct opengl_funcs * CDECL nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
884 return (void *)-1;
887 static const struct vulkan_funcs * CDECL nulldrv_wine_get_vulkan_driver( PHYSDEV dev, UINT version )
889 return NULL;
892 const struct gdi_dc_funcs null_driver =
894 nulldrv_AbortDoc, /* pAbortDoc */
895 nulldrv_AbortPath, /* pAbortPath */
896 nulldrv_AlphaBlend, /* pAlphaBlend */
897 nulldrv_AngleArc, /* pAngleArc */
898 nulldrv_Arc, /* pArc */
899 nulldrv_ArcTo, /* pArcTo */
900 nulldrv_BeginPath, /* pBeginPath */
901 nulldrv_BlendImage, /* pBlendImage */
902 nulldrv_Chord, /* pChord */
903 nulldrv_CloseFigure, /* pCloseFigure */
904 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
905 nulldrv_CreateDC, /* pCreateDC */
906 nulldrv_DeleteDC, /* pDeleteDC */
907 nulldrv_DeleteObject, /* pDeleteObject */
908 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
909 nulldrv_Ellipse, /* pEllipse */
910 nulldrv_EndDoc, /* pEndDoc */
911 nulldrv_EndPage, /* pEndPage */
912 nulldrv_EndPath, /* pEndPath */
913 nulldrv_EnumFonts, /* pEnumFonts */
914 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
915 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
916 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
917 nulldrv_ExtEscape, /* pExtEscape */
918 nulldrv_ExtFloodFill, /* pExtFloodFill */
919 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
920 nulldrv_ExtTextOut, /* pExtTextOut */
921 nulldrv_FillPath, /* pFillPath */
922 nulldrv_FillRgn, /* pFillRgn */
923 nulldrv_FlattenPath, /* pFlattenPath */
924 nulldrv_FontIsLinked, /* pFontIsLinked */
925 nulldrv_FrameRgn, /* pFrameRgn */
926 nulldrv_GdiComment, /* pGdiComment */
927 nulldrv_GetBoundsRect, /* pGetBoundsRect */
928 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
929 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
930 nulldrv_GetCharWidth, /* pGetCharWidth */
931 nulldrv_GetCharWidthInfo, /* pGetCharWidthInfo */
932 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
933 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
934 nulldrv_GetFontData, /* pGetFontData */
935 nulldrv_GetFontRealizationInfo, /* pGetFontRealizationInfo */
936 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
937 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
938 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
939 nulldrv_GetICMProfile, /* pGetICMProfile */
940 nulldrv_GetImage, /* pGetImage */
941 nulldrv_GetKerningPairs, /* pGetKerningPairs */
942 nulldrv_GetNearestColor, /* pGetNearestColor */
943 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
944 nulldrv_GetPixel, /* pGetPixel */
945 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
946 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
947 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
948 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
949 nulldrv_GetTextFace, /* pGetTextFace */
950 nulldrv_GetTextMetrics, /* pGetTextMetrics */
951 nulldrv_GradientFill, /* pGradientFill */
952 nulldrv_IntersectClipRect, /* pIntersectClipRect */
953 nulldrv_InvertRgn, /* pInvertRgn */
954 nulldrv_LineTo, /* pLineTo */
955 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
956 nulldrv_MoveTo, /* pMoveTo */
957 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
958 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
959 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
960 nulldrv_PaintRgn, /* pPaintRgn */
961 nulldrv_PatBlt, /* pPatBlt */
962 nulldrv_Pie, /* pPie */
963 nulldrv_PolyBezier, /* pPolyBezier */
964 nulldrv_PolyBezierTo, /* pPolyBezierTo */
965 nulldrv_PolyDraw, /* pPolyDraw */
966 nulldrv_PolyPolygon, /* pPolyPolygon */
967 nulldrv_PolyPolyline, /* pPolyPolyline */
968 nulldrv_Polygon, /* pPolygon */
969 nulldrv_Polyline, /* pPolyline */
970 nulldrv_PolylineTo, /* pPolylineTo */
971 nulldrv_PutImage, /* pPutImage */
972 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
973 nulldrv_RealizePalette, /* pRealizePalette */
974 nulldrv_Rectangle, /* pRectangle */
975 nulldrv_ResetDC, /* pResetDC */
976 nulldrv_RestoreDC, /* pRestoreDC */
977 nulldrv_RoundRect, /* pRoundRect */
978 nulldrv_SaveDC, /* pSaveDC */
979 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
980 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
981 nulldrv_SelectBitmap, /* pSelectBitmap */
982 nulldrv_SelectBrush, /* pSelectBrush */
983 nulldrv_SelectClipPath, /* pSelectClipPath */
984 nulldrv_SelectFont, /* pSelectFont */
985 nulldrv_SelectPalette, /* pSelectPalette */
986 nulldrv_SelectPen, /* pSelectPen */
987 nulldrv_SetArcDirection, /* pSetArcDirection */
988 nulldrv_SetBkColor, /* pSetBkColor */
989 nulldrv_SetBkMode, /* pSetBkMode */
990 nulldrv_SetBoundsRect, /* pSetBoundsRect */
991 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
992 nulldrv_SetDCPenColor, /* pSetDCPenColor */
993 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
994 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
995 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
996 nulldrv_SetLayout, /* pSetLayout */
997 nulldrv_SetMapMode, /* pSetMapMode */
998 nulldrv_SetMapperFlags, /* pSetMapperFlags */
999 nulldrv_SetPixel, /* pSetPixel */
1000 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
1001 nulldrv_SetROP2, /* pSetROP2 */
1002 nulldrv_SetRelAbs, /* pSetRelAbs */
1003 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
1004 nulldrv_SetTextAlign, /* pSetTextAlign */
1005 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
1006 nulldrv_SetTextColor, /* pSetTextColor */
1007 nulldrv_SetTextJustification, /* pSetTextJustification */
1008 nulldrv_SetViewportExtEx, /* pSetViewportExt */
1009 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
1010 nulldrv_SetWindowExtEx, /* pSetWindowExt */
1011 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
1012 nulldrv_SetWorldTransform, /* pSetWorldTransform */
1013 nulldrv_StartDoc, /* pStartDoc */
1014 nulldrv_StartPage, /* pStartPage */
1015 nulldrv_StretchBlt, /* pStretchBlt */
1016 nulldrv_StretchDIBits, /* pStretchDIBits */
1017 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
1018 nulldrv_StrokePath, /* pStrokePath */
1019 nulldrv_UnrealizePalette, /* pUnrealizePalette */
1020 nulldrv_WidenPath, /* pWidenPath */
1021 nulldrv_D3DKMTCheckVidPnExclusiveOwnership, /* pD3DKMTCheckVidPnExclusiveOwnership */
1022 nulldrv_D3DKMTSetVidPnSourceOwner, /* pD3DKMTSetVidPnSourceOwner */
1023 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
1024 nulldrv_wine_get_vulkan_driver, /* wine_get_vulkan_driver */
1026 GDI_PRIORITY_NULL_DRV /* priority */
1030 /*****************************************************************************
1031 * DRIVER_GetDriverName
1034 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
1036 WCHAR *p;
1038 /* display is a special case */
1039 if (!wcsicmp( device, L"display" ) || is_display_device( device ))
1041 lstrcpynW( driver, L"display", size );
1042 return TRUE;
1045 size = GetProfileStringW(L"devices", device, L"", driver, size);
1046 if(!size) {
1047 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
1048 return FALSE;
1050 p = wcschr(driver, ',');
1051 if(!p)
1053 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
1054 return FALSE;
1056 *p = 0;
1057 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
1058 return TRUE;
1062 /***********************************************************************
1063 * GdiConvertToDevmodeW (GDI32.@)
1065 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
1067 DEVMODEW *dmW;
1068 WORD dmW_size, dmA_size;
1070 dmA_size = dmA->dmSize;
1072 /* this is the minimal dmSize that XP accepts */
1073 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
1074 return NULL;
1076 if (dmA_size > sizeof(DEVMODEA))
1077 dmA_size = sizeof(DEVMODEA);
1079 dmW_size = dmA_size + CCHDEVICENAME;
1080 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
1081 dmW_size += CCHFORMNAME;
1083 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
1084 if (!dmW) return NULL;
1086 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
1087 dmW->dmDeviceName, CCHDEVICENAME);
1088 /* copy slightly more, to avoid long computations */
1089 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
1091 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
1093 if (dmA->dmFields & DM_FORMNAME)
1094 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
1095 dmW->dmFormName, CCHFORMNAME);
1096 else
1097 dmW->dmFormName[0] = 0;
1099 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
1100 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
1103 if (dmA->dmDriverExtra)
1104 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
1106 dmW->dmSize = dmW_size;
1108 return dmW;
1112 /*****************************************************************************
1113 * @ [GDI32.100]
1115 * This should thunk to 16-bit and simply call the proc with the given args.
1117 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
1118 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
1120 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
1121 return -1;
1124 /*****************************************************************************
1125 * @ [GDI32.101]
1127 * This should load the correct driver for lpszDevice and calls this driver's
1128 * ExtDeviceModePropSheet proc.
1130 * Note: The driver calls a callback routine for each property sheet page; these
1131 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
1132 * The layout of this structure is:
1134 * struct
1136 * DWORD nPages;
1137 * DWORD unknown;
1138 * HPROPSHEETPAGE pages[10];
1139 * };
1141 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
1142 LPCSTR lpszPort, LPVOID lpPropSheet )
1144 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
1145 return -1;
1148 /*****************************************************************************
1149 * @ [GDI32.102]
1151 * This should load the correct driver for lpszDevice and call this driver's
1152 * ExtDeviceMode proc.
1154 * FIXME: convert ExtDeviceMode to unicode in the driver interface
1156 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1157 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1158 LPSTR lpszPort, LPDEVMODEA lpdmInput,
1159 LPSTR lpszProfile, DWORD fwMode )
1161 WCHAR deviceW[300];
1162 WCHAR bufW[300];
1163 char buf[300];
1164 HDC hdc;
1165 DC *dc;
1166 INT ret = -1;
1168 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1169 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1171 if (!lpszDevice) return -1;
1172 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1174 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1176 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1178 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1180 if ((dc = get_dc_ptr( hdc )))
1182 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1183 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1184 lpdmInput, lpszProfile, fwMode );
1185 release_dc_ptr( dc );
1187 DeleteDC( hdc );
1188 return ret;
1191 /****************************************************************************
1192 * @ [GDI32.103]
1194 * This should load the correct driver for lpszDevice and calls this driver's
1195 * AdvancedSetupDialog proc.
1197 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1198 LPDEVMODEA devin, LPDEVMODEA devout )
1200 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1201 return -1;
1204 /*****************************************************************************
1205 * @ [GDI32.104]
1207 * This should load the correct driver for lpszDevice and calls this driver's
1208 * DeviceCapabilities proc.
1210 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1212 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1213 WORD fwCapability, LPSTR lpszOutput,
1214 LPDEVMODEA lpdm )
1216 WCHAR deviceW[300];
1217 WCHAR bufW[300];
1218 char buf[300];
1219 HDC hdc;
1220 DC *dc;
1221 INT ret = -1;
1223 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1225 if (!lpszDevice) return -1;
1226 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1228 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1230 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1232 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1234 if ((dc = get_dc_ptr( hdc )))
1236 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1237 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1238 fwCapability, lpszOutput, lpdm );
1239 release_dc_ptr( dc );
1241 DeleteDC( hdc );
1242 return ret;
1246 /************************************************************************
1247 * Escape [GDI32.@]
1249 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1251 INT ret;
1252 POINT *pt;
1254 switch (escape)
1256 case ABORTDOC:
1257 return AbortDoc( hdc );
1259 case ENDDOC:
1260 return EndDoc( hdc );
1262 case GETPHYSPAGESIZE:
1263 pt = out_data;
1264 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1265 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1266 return 1;
1268 case GETPRINTINGOFFSET:
1269 pt = out_data;
1270 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1271 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1272 return 1;
1274 case GETSCALINGFACTOR:
1275 pt = out_data;
1276 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1277 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1278 return 1;
1280 case NEWFRAME:
1281 return EndPage( hdc );
1283 case SETABORTPROC:
1284 return SetAbortProc( hdc, (ABORTPROC)in_data );
1286 case STARTDOC:
1288 DOCINFOA doc;
1289 char *name = NULL;
1291 /* in_data may not be 0 terminated so we must copy it */
1292 if (in_data)
1294 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1295 memcpy( name, in_data, in_count );
1296 name[in_count] = 0;
1298 /* out_data is actually a pointer to the DocInfo structure and used as
1299 * a second input parameter */
1300 if (out_data) doc = *(DOCINFOA *)out_data;
1301 else
1303 doc.cbSize = sizeof(doc);
1304 doc.lpszOutput = NULL;
1305 doc.lpszDatatype = NULL;
1306 doc.fwType = 0;
1308 doc.lpszDocName = name;
1309 ret = StartDocA( hdc, &doc );
1310 HeapFree( GetProcessHeap(), 0, name );
1311 if (ret > 0) ret = StartPage( hdc );
1312 return ret;
1315 case QUERYESCSUPPORT:
1317 DWORD code;
1319 if (in_count < sizeof(SHORT)) return 0;
1320 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1321 switch (code)
1323 case ABORTDOC:
1324 case ENDDOC:
1325 case GETPHYSPAGESIZE:
1326 case GETPRINTINGOFFSET:
1327 case GETSCALINGFACTOR:
1328 case NEWFRAME:
1329 case QUERYESCSUPPORT:
1330 case SETABORTPROC:
1331 case STARTDOC:
1332 return TRUE;
1334 break;
1338 /* if not handled internally, pass it to the driver */
1339 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1343 /******************************************************************************
1344 * ExtEscape [GDI32.@]
1346 * Access capabilities of a particular device that are not available through GDI.
1348 * PARAMS
1349 * hdc [I] Handle to device context
1350 * nEscape [I] Escape function
1351 * cbInput [I] Number of bytes in input structure
1352 * lpszInData [I] Pointer to input structure
1353 * cbOutput [I] Number of bytes in output structure
1354 * lpszOutData [O] Pointer to output structure
1356 * RETURNS
1357 * Success: >0
1358 * Not implemented: 0
1359 * Failure: <0
1361 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1362 INT cbOutput, LPSTR lpszOutData )
1364 PHYSDEV physdev;
1365 INT ret;
1366 DC * dc = get_dc_ptr( hdc );
1368 if (!dc) return 0;
1369 update_dc( dc );
1370 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1371 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1372 release_dc_ptr( dc );
1373 return ret;
1377 /*******************************************************************
1378 * DrawEscape [GDI32.@]
1382 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1384 FIXME("DrawEscape, stub\n");
1385 return 0;
1388 /*******************************************************************
1389 * NamedEscape [GDI32.@]
1391 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1392 INT cbOutput, LPSTR lpszOutData )
1394 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1395 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1396 lpszOutData);
1397 return 0;
1400 /*******************************************************************
1401 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1402 * GdiEntry13 [GDI32.@]
1404 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1406 static int warn_once;
1408 if (!warn_once++)
1409 FIXME("stub\n");
1410 return 0;
1413 /******************************************************************************
1414 * D3DKMTOpenAdapterFromHdc [GDI32.@]
1416 NTSTATUS WINAPI D3DKMTOpenAdapterFromHdc( void *pData )
1418 FIXME("(%p): stub\n", pData);
1419 return STATUS_NO_MEMORY;
1422 /******************************************************************************
1423 * D3DKMTEscape [GDI32.@]
1425 NTSTATUS WINAPI D3DKMTEscape( const void *pData )
1427 FIXME("(%p): stub\n", pData);
1428 return STATUS_NO_MEMORY;
1431 /******************************************************************************
1432 * D3DKMTCloseAdapter [GDI32.@]
1434 NTSTATUS WINAPI D3DKMTCloseAdapter( const D3DKMT_CLOSEADAPTER *desc )
1436 NTSTATUS status = STATUS_INVALID_PARAMETER;
1437 struct d3dkmt_adapter *adapter;
1439 TRACE("(%p)\n", desc);
1441 if (!desc || !desc->hAdapter)
1442 return STATUS_INVALID_PARAMETER;
1444 EnterCriticalSection( &driver_section );
1445 LIST_FOR_EACH_ENTRY( adapter, &d3dkmt_adapters, struct d3dkmt_adapter, entry )
1447 if (adapter->handle == desc->hAdapter)
1449 list_remove( &adapter->entry );
1450 heap_free( adapter );
1451 status = STATUS_SUCCESS;
1452 break;
1455 LeaveCriticalSection( &driver_section );
1457 return status;
1460 /******************************************************************************
1461 * D3DKMTOpenAdapterFromGdiDisplayName [GDI32.@]
1463 NTSTATUS WINAPI D3DKMTOpenAdapterFromGdiDisplayName( D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME *desc )
1465 WCHAR *end, key_nameW[MAX_PATH], bufferW[MAX_PATH];
1466 HDEVINFO devinfo = INVALID_HANDLE_VALUE;
1467 NTSTATUS status = STATUS_UNSUCCESSFUL;
1468 static D3DKMT_HANDLE handle_start = 0;
1469 struct d3dkmt_adapter *adapter;
1470 SP_DEVINFO_DATA device_data;
1471 DWORD size, state_flags;
1472 DEVPROPTYPE type;
1473 HANDLE mutex;
1474 LUID luid;
1475 int index;
1477 TRACE("(%p)\n", desc);
1479 if (!desc)
1480 return STATUS_UNSUCCESSFUL;
1482 TRACE("DeviceName: %s\n", wine_dbgstr_w( desc->DeviceName ));
1483 if (wcsnicmp( desc->DeviceName, L"\\\\.\\DISPLAY", lstrlenW(L"\\\\.\\DISPLAY") ))
1484 return STATUS_UNSUCCESSFUL;
1486 index = wcstol( desc->DeviceName + lstrlenW(L"\\\\.\\DISPLAY"), &end, 10 ) - 1;
1487 if (*end)
1488 return STATUS_UNSUCCESSFUL;
1490 adapter = heap_alloc( sizeof( *adapter ) );
1491 if (!adapter)
1492 return STATUS_NO_MEMORY;
1494 /* Get adapter LUID from SetupAPI */
1495 mutex = get_display_device_init_mutex();
1497 size = sizeof( bufferW );
1498 swprintf( key_nameW, MAX_PATH, L"\\Device\\Video%d", index );
1499 if (RegGetValueW( HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\VIDEO", key_nameW, RRF_RT_REG_SZ, NULL, bufferW, &size ))
1500 goto done;
1502 /* Strip \Registry\Machine\ prefix and retrieve Wine specific data set by the display driver */
1503 lstrcpyW( key_nameW, bufferW + 18 );
1504 size = sizeof( state_flags );
1505 if (RegGetValueW( HKEY_CURRENT_CONFIG, key_nameW, L"StateFlags", RRF_RT_REG_DWORD, NULL,
1506 &state_flags, &size ))
1507 goto done;
1509 if (!(state_flags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
1510 goto done;
1512 size = sizeof( bufferW );
1513 if (RegGetValueW( HKEY_CURRENT_CONFIG, key_nameW, L"GPUID", RRF_RT_REG_SZ, NULL, bufferW, &size ))
1514 goto done;
1516 devinfo = SetupDiCreateDeviceInfoList( &GUID_DEVCLASS_DISPLAY, NULL );
1517 device_data.cbSize = sizeof( device_data );
1518 SetupDiOpenDeviceInfoW( devinfo, bufferW, NULL, 0, &device_data );
1519 if (!SetupDiGetDevicePropertyW( devinfo, &device_data, &DEVPROPKEY_GPU_LUID, &type,
1520 (BYTE *)&luid, sizeof( luid ), NULL, 0))
1521 goto done;
1523 EnterCriticalSection( &driver_section );
1524 /* D3DKMT_HANDLE is UINT, so we can't use pointer as handle */
1525 adapter->handle = ++handle_start;
1526 list_add_tail( &d3dkmt_adapters, &adapter->entry );
1527 LeaveCriticalSection( &driver_section );
1529 desc->hAdapter = handle_start;
1530 desc->AdapterLuid = luid;
1531 desc->VidPnSourceId = index;
1532 status = STATUS_SUCCESS;
1534 done:
1535 SetupDiDestroyDeviceInfoList( devinfo );
1536 release_display_device_init_mutex( mutex );
1537 if (status != STATUS_SUCCESS)
1538 heap_free( adapter );
1539 return status;
1542 /******************************************************************************
1543 * D3DKMTCreateDevice [GDI32.@]
1545 NTSTATUS WINAPI D3DKMTCreateDevice( D3DKMT_CREATEDEVICE *desc )
1547 static D3DKMT_HANDLE handle_start = 0;
1548 struct d3dkmt_adapter *adapter;
1549 struct d3dkmt_device *device;
1550 BOOL found = FALSE;
1552 TRACE("(%p)\n", desc);
1554 if (!desc)
1555 return STATUS_INVALID_PARAMETER;
1557 EnterCriticalSection( &driver_section );
1558 LIST_FOR_EACH_ENTRY( adapter, &d3dkmt_adapters, struct d3dkmt_adapter, entry )
1560 if (adapter->handle == desc->hAdapter)
1562 found = TRUE;
1563 break;
1566 LeaveCriticalSection( &driver_section );
1568 if (!found)
1569 return STATUS_INVALID_PARAMETER;
1571 if (desc->Flags.LegacyMode || desc->Flags.RequestVSync || desc->Flags.DisableGpuTimeout)
1572 FIXME("Flags unsupported.\n");
1574 device = heap_alloc_zero( sizeof( *device ) );
1575 if (!device)
1576 return STATUS_NO_MEMORY;
1578 EnterCriticalSection( &driver_section );
1579 device->handle = ++handle_start;
1580 list_add_tail( &d3dkmt_devices, &device->entry );
1581 LeaveCriticalSection( &driver_section );
1583 desc->hDevice = device->handle;
1584 return STATUS_SUCCESS;
1587 /******************************************************************************
1588 * D3DKMTDestroyDevice [GDI32.@]
1590 NTSTATUS WINAPI D3DKMTDestroyDevice( const D3DKMT_DESTROYDEVICE *desc )
1592 NTSTATUS status = STATUS_INVALID_PARAMETER;
1593 D3DKMT_SETVIDPNSOURCEOWNER set_owner_desc;
1594 struct d3dkmt_device *device;
1596 TRACE("(%p)\n", desc);
1598 if (!desc || !desc->hDevice)
1599 return STATUS_INVALID_PARAMETER;
1601 EnterCriticalSection( &driver_section );
1602 LIST_FOR_EACH_ENTRY( device, &d3dkmt_devices, struct d3dkmt_device, entry )
1604 if (device->handle == desc->hDevice)
1606 memset( &set_owner_desc, 0, sizeof(set_owner_desc) );
1607 set_owner_desc.hDevice = desc->hDevice;
1608 D3DKMTSetVidPnSourceOwner( &set_owner_desc );
1609 list_remove( &device->entry );
1610 heap_free( device );
1611 status = STATUS_SUCCESS;
1612 break;
1615 LeaveCriticalSection( &driver_section );
1617 return status;
1620 /******************************************************************************
1621 * D3DKMTQueryStatistics [GDI32.@]
1623 NTSTATUS WINAPI D3DKMTQueryStatistics(D3DKMT_QUERYSTATISTICS *stats)
1625 FIXME("(%p): stub\n", stats);
1626 return STATUS_SUCCESS;
1629 /******************************************************************************
1630 * D3DKMTSetQueuedLimit [GDI32.@]
1632 NTSTATUS WINAPI D3DKMTSetQueuedLimit( D3DKMT_SETQUEUEDLIMIT *desc )
1634 FIXME( "(%p): stub\n", desc );
1635 return STATUS_NOT_IMPLEMENTED;
1638 /******************************************************************************
1639 * D3DKMTSetVidPnSourceOwner [GDI32.@]
1641 NTSTATUS WINAPI D3DKMTSetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER *desc )
1643 TRACE("(%p)\n", desc);
1645 if (!get_display_driver()->pD3DKMTSetVidPnSourceOwner)
1646 return STATUS_PROCEDURE_NOT_FOUND;
1648 if (!desc || !desc->hDevice || (desc->VidPnSourceCount && (!desc->pType || !desc->pVidPnSourceId)))
1649 return STATUS_INVALID_PARAMETER;
1651 /* Store the VidPN source ownership info in the graphics driver because
1652 * the graphics driver needs to change ownership sometimes. For example,
1653 * when a new window is moved to a VidPN source with an exclusive owner,
1654 * such an exclusive owner will be released before showing the new window */
1655 return get_display_driver()->pD3DKMTSetVidPnSourceOwner( desc );
1658 /******************************************************************************
1659 * D3DKMTCheckVidPnExclusiveOwnership [GDI32.@]
1661 NTSTATUS WINAPI D3DKMTCheckVidPnExclusiveOwnership( const D3DKMT_CHECKVIDPNEXCLUSIVEOWNERSHIP *desc )
1663 TRACE("(%p)\n", desc);
1665 if (!get_display_driver()->pD3DKMTCheckVidPnExclusiveOwnership)
1666 return STATUS_PROCEDURE_NOT_FOUND;
1668 if (!desc || !desc->hAdapter)
1669 return STATUS_INVALID_PARAMETER;
1671 return get_display_driver()->pD3DKMTCheckVidPnExclusiveOwnership( desc );