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
23 #include "wine/port.h"
32 #include "wine/winbase16.h"
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(driver);
41 struct graphics_driver
44 HMODULE module; /* module handle */
48 static struct list drivers = LIST_INIT( drivers );
49 static struct graphics_driver *display_driver;
51 static CRITICAL_SECTION driver_section;
52 static CRITICAL_SECTION_DEBUG critsect_debug =
54 0, 0, &driver_section,
55 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
56 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
58 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
60 /**********************************************************************
63 * Allocate and fill the driver structure for a given module.
65 static struct graphics_driver *create_driver( HMODULE module )
67 struct graphics_driver *driver;
69 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
70 driver->module = module;
72 /* fill the function table */
75 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
84 GET_FUNC(ChoosePixelFormat);
86 GET_FUNC(CloseFigure);
87 GET_FUNC(CreateBitmap);
89 GET_FUNC(CreateDIBSection);
90 GET_FUNC(DeleteBitmap);
92 GET_FUNC(DescribePixelFormat);
93 GET_FUNC(DeviceCapabilities);
98 GET_FUNC(EnumDeviceFonts);
99 GET_FUNC(EnumICMProfiles);
100 GET_FUNC(ExcludeClipRect);
101 GET_FUNC(ExtDeviceMode);
103 GET_FUNC(ExtFloodFill);
104 GET_FUNC(ExtSelectClipRgn);
105 GET_FUNC(ExtTextOut);
108 GET_FUNC(FlattenPath);
110 GET_FUNC(GdiComment);
111 GET_FUNC(GetBitmapBits);
112 GET_FUNC(GetCharWidth);
114 GET_FUNC(GetDeviceCaps);
115 GET_FUNC(GetDeviceGammaRamp);
116 GET_FUNC(GetICMProfile);
117 GET_FUNC(GetNearestColor);
119 GET_FUNC(GetPixelFormat);
120 GET_FUNC(GetSystemPaletteEntries);
121 GET_FUNC(GetTextExtentExPoint);
122 GET_FUNC(GetTextMetrics);
123 GET_FUNC(IntersectClipRect);
127 GET_FUNC(ModifyWorldTransform);
128 GET_FUNC(OffsetClipRgn);
129 GET_FUNC(OffsetViewportOrgEx);
130 GET_FUNC(OffsetWindowOrgEx);
134 GET_FUNC(PolyBezier);
135 GET_FUNC(PolyBezierTo);
137 GET_FUNC(PolyPolygon);
138 GET_FUNC(PolyPolyline);
141 GET_FUNC(PolylineTo);
142 GET_FUNC(RealizeDefaultPalette);
143 GET_FUNC(RealizePalette);
149 GET_FUNC(ScaleViewportExtEx);
150 GET_FUNC(ScaleWindowExtEx);
151 GET_FUNC(SelectBitmap);
152 GET_FUNC(SelectBrush);
153 GET_FUNC(SelectClipPath);
154 GET_FUNC(SelectFont);
155 GET_FUNC(SelectPalette);
157 GET_FUNC(SetArcDirection);
158 GET_FUNC(SetBitmapBits);
159 GET_FUNC(SetBkColor);
161 GET_FUNC(SetDCBrushColor);
162 GET_FUNC(SetDCPenColor);
163 GET_FUNC(SetDIBColorTable);
165 GET_FUNC(SetDIBitsToDevice);
166 GET_FUNC(SetDeviceClipping);
167 GET_FUNC(SetDeviceGammaRamp);
168 GET_FUNC(SetMapMode);
169 GET_FUNC(SetMapperFlags);
171 GET_FUNC(SetPixelFormat);
172 GET_FUNC(SetPolyFillMode);
175 GET_FUNC(SetStretchBltMode);
176 GET_FUNC(SetTextAlign);
177 GET_FUNC(SetTextCharacterExtra);
178 GET_FUNC(SetTextColor);
179 GET_FUNC(SetTextJustification);
180 GET_FUNC(SetViewportExtEx);
181 GET_FUNC(SetViewportOrgEx);
182 GET_FUNC(SetWindowExtEx);
183 GET_FUNC(SetWindowOrgEx);
184 GET_FUNC(SetWorldTransform);
187 GET_FUNC(StretchBlt);
188 GET_FUNC(StretchDIBits);
189 GET_FUNC(StrokeAndFillPath);
190 GET_FUNC(StrokePath);
191 GET_FUNC(SwapBuffers);
192 GET_FUNC(UnrealizePalette);
196 GET_FUNC(wglCreateContext);
197 GET_FUNC(wglCreateContextAttribsARB);
198 GET_FUNC(wglDeleteContext);
199 GET_FUNC(wglGetProcAddress);
200 GET_FUNC(wglGetPbufferDCARB);
201 GET_FUNC(wglMakeContextCurrentARB);
202 GET_FUNC(wglMakeCurrent);
203 GET_FUNC(wglSetPixelFormatWINE);
204 GET_FUNC(wglShareLists);
205 GET_FUNC(wglUseFontBitmapsA);
206 GET_FUNC(wglUseFontBitmapsW);
209 else memset( &driver->funcs, 0, sizeof(driver->funcs) );
215 /**********************************************************************
216 * DRIVER_get_display_driver
218 * Special case for loading the display driver: get the name from the config file
220 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
222 struct graphics_driver *driver;
223 char buffer[MAX_PATH], libname[32], *name, *next;
227 if (display_driver) return &display_driver->funcs; /* already loaded */
229 strcpy( buffer, "x11" ); /* default value */
230 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
231 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
233 DWORD type, count = sizeof(buffer);
234 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
241 next = strchr( name, ',' );
242 if (next) *next++ = 0;
244 snprintf( libname, sizeof(libname), "wine%s.drv", name );
245 if ((module = LoadLibraryA( libname )) != 0) break;
249 if (!(driver = create_driver( module )))
251 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
252 FreeLibrary( module );
255 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
257 /* somebody beat us to it */
258 FreeLibrary( driver->module );
259 HeapFree( GetProcessHeap(), 0, driver );
261 return &display_driver->funcs;
265 /**********************************************************************
268 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
271 struct graphics_driver *driver, *new_driver;
272 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
273 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
275 /* display driver is a special case */
276 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
278 if ((module = GetModuleHandleW( name )))
280 if (display_driver && display_driver->module == module) return &display_driver->funcs;
281 EnterCriticalSection( &driver_section );
282 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
284 if (driver->module == module) goto done;
286 LeaveCriticalSection( &driver_section );
289 if (!(module = LoadLibraryW( name ))) return NULL;
291 if (!(new_driver = create_driver( module )))
293 FreeLibrary( module );
297 /* check if someone else added it in the meantime */
298 EnterCriticalSection( &driver_section );
299 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
301 if (driver->module != module) continue;
302 FreeLibrary( module );
303 HeapFree( GetProcessHeap(), 0, new_driver );
307 list_add_head( &drivers, &driver->entry );
308 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
310 LeaveCriticalSection( &driver_section );
311 return &driver->funcs;
315 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
320 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
321 INT xstart, INT ystart, INT xend, INT yend )
326 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
327 INT xstart, INT ystart, INT xend, INT yend )
332 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
337 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
342 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
347 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
352 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
357 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
362 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
367 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
372 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
377 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
378 INT xstart, INT ystart, INT xend, INT yend )
383 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
385 /* FIXME: could be implemented with Polygon */
389 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
391 /* FIXME: could be implemented with Polyline */
395 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
400 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
405 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
410 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
411 INT ell_width, INT ell_height )
416 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
421 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
426 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
431 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
436 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
441 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
446 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
451 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
456 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
461 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
466 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
470 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
475 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
480 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
485 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
490 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
495 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
500 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
505 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
510 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
515 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
520 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
525 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
530 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
535 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
540 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
545 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
550 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
555 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
560 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
565 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
570 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
575 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
576 const PIXELFORMATDESCRIPTOR *descr )
581 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
586 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
591 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
596 const DC_FUNCTIONS null_driver =
598 nulldrv_AbortDoc, /* pAbortDoc */
599 NULL, /* pAbortPath */
600 NULL, /* pAlphaBlend */
601 nulldrv_AngleArc, /* pAngleArc */
602 nulldrv_Arc, /* pArc */
603 nulldrv_ArcTo, /* pArcTo */
604 NULL, /* pBeginPath */
606 NULL, /* pChoosePixelFormat */
607 nulldrv_Chord, /* pChord */
608 NULL, /* pCloseFigure */
609 NULL, /* pCreateBitmap */
610 NULL, /* pCreateDC */
611 NULL, /* pCreateDIBSection */
612 NULL, /* pDeleteBitmap */
613 NULL, /* pDeleteDC */
614 nulldrv_DeleteObject, /* pDeleteObject */
615 NULL, /* pDescribePixelFormat */
616 NULL, /* pDeviceCapabilities */
617 nulldrv_Ellipse, /* pEllipse */
618 nulldrv_EndDoc, /* pEndDoc */
619 nulldrv_EndPage, /* pEndPage */
621 NULL, /* pEnumICMProfiles */
622 NULL, /* pEnumDeviceFonts */
623 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
624 NULL, /* pExtDeviceMode */
625 NULL, /* pExtEscape */
626 nulldrv_ExtFloodFill, /* pExtFloodFill */
627 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
628 NULL, /* pExtTextOut */
629 NULL, /* pFillPath */
630 nulldrv_FillRgn, /* pFillRgn */
631 NULL, /* pFlattenPath */
632 nulldrv_FrameRgn, /* pFrameRgn */
633 NULL, /* pGdiComment */
634 NULL, /* pGetBitmapBits */
635 NULL, /* pGetCharWidth */
636 NULL, /* pGetDIBits */
637 NULL, /* pGetDeviceCaps */
638 NULL, /* pGetDeviceGammaRamp */
639 NULL, /* pGetICMProfile */
640 NULL, /* pGetNearestColor */
641 nulldrv_GetPixel, /* pGetPixel */
642 NULL, /* pGetPixelFormat */
643 NULL, /* pGetSystemPaletteEntries */
644 NULL, /* pGetTextExtentExPoint */
645 NULL, /* pGetTextMetrics */
646 nulldrv_IntersectClipRect, /* pIntersectClipRect */
647 nulldrv_InvertRgn, /* pInvertRgn */
648 nulldrv_LineTo, /* pLineTo */
649 NULL, /* pModifyWorldTransform */
650 nulldrv_MoveTo, /* pMoveTo */
651 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
652 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
653 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
654 nulldrv_PaintRgn, /* pPaintRgn */
656 nulldrv_Pie, /* pPie */
657 nulldrv_PolyBezier, /* pPolyBezier */
658 nulldrv_PolyBezierTo, /* pPolyBezierTo */
659 nulldrv_PolyDraw, /* pPolyDraw */
660 nulldrv_PolyPolygon, /* pPolyPolygon */
661 nulldrv_PolyPolyline, /* pPolyPolyline */
662 nulldrv_Polygon, /* pPolygon */
663 nulldrv_Polyline, /* pPolyline */
664 nulldrv_PolylineTo, /* pPolylineTo */
665 NULL, /* pRealizeDefaultPalette */
666 NULL, /* pRealizePalette */
667 nulldrv_Rectangle, /* pRectangle */
669 NULL, /* pRestoreDC */
670 nulldrv_RoundRect, /* pRoundRect */
672 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
673 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
674 nulldrv_SelectBitmap, /* pSelectBitmap */
675 nulldrv_SelectBrush, /* pSelectBrush */
676 NULL, /* pSelectClipPath */
677 nulldrv_SelectFont, /* pSelectFont */
678 nulldrv_SelectPalette, /* pSelectPalette */
679 nulldrv_SelectPen, /* pSelectPen */
680 nulldrv_SetArcDirection, /* pSetArcDirection */
681 NULL, /* pSetBitmapBits */
682 nulldrv_SetBkColor, /* pSetBkColor */
683 nulldrv_SetBkMode, /* pSetBkMode */
684 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
685 nulldrv_SetDCPenColor, /* pSetDCPenColor */
686 NULL, /* pSetDIBColorTable */
687 NULL, /* pSetDIBits */
688 NULL, /* pSetDIBitsToDevice */
689 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
690 NULL, /* pSetDeviceGammaRamp */
691 nulldrv_SetLayout, /* pSetLayout */
692 nulldrv_SetMapMode, /* pSetMapMode */
693 nulldrv_SetMapperFlags, /* pSetMapperFlags */
694 nulldrv_SetPixel, /* pSetPixel */
695 NULL, /* pSetPixelFormat */
696 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
697 nulldrv_SetROP2, /* pSetROP2 */
698 nulldrv_SetRelAbs, /* pSetRelAbs */
699 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
700 nulldrv_SetTextAlign, /* pSetTextAlign */
701 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
702 nulldrv_SetTextColor, /* pSetTextColor */
703 nulldrv_SetTextJustification, /* pSetTextJustification */
704 nulldrv_SetViewportExtEx, /* pSetViewportExt */
705 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
706 nulldrv_SetWindowExtEx, /* pSetWindowExt */
707 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
708 NULL, /* pSetWorldTransform */
709 nulldrv_StartDoc, /* pStartDoc */
710 nulldrv_StartPage, /* pStartPage */
711 NULL, /* pStretchBlt */
712 NULL, /* pStretchDIBits */
713 NULL, /* pStrokeAndFillPath */
714 NULL, /* pStrokePath */
715 NULL, /* pSwapBuffers */
716 NULL, /* pUnrealizePalette */
717 NULL, /* pWidenPath */
718 nulldrv_wglCopyContext, /* pwglCopyContext */
719 nulldrv_wglCreateContext, /* pwglCreateContext */
720 nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
721 nulldrv_wglDeleteContext, /* pwglDeleteContext */
722 nulldrv_wglGetProcAddress, /* pwglGetProcAddress */
723 nulldrv_wglGetPbufferDCARB, /* pwglGetPbufferDCARB */
724 nulldrv_wglMakeCurrent, /* pwglMakeCurrent */
725 nulldrv_wglMakeContextCurrentARB, /* pwglMakeContextCurrentARB */
726 nulldrv_wglSetPixelFormatWINE, /* pwglSetPixelFormatWINE */
727 nulldrv_wglShareLists, /* pwglShareLists */
728 nulldrv_wglUseFontBitmapsA, /* pwglUseFontBitmapsA */
729 nulldrv_wglUseFontBitmapsW, /* pwglUseFontBitmapsW */
733 /*****************************************************************************
734 * DRIVER_GetDriverName
737 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
739 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
740 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
741 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
742 static const WCHAR empty_strW[] = { 0 };
745 /* display is a special case */
746 if (!strcmpiW( device, displayW ) ||
747 !strcmpiW( device, display1W ))
749 lstrcpynW( driver, displayW, size );
753 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
755 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
758 p = strchrW(driver, ',');
761 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
765 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
770 /***********************************************************************
771 * GdiConvertToDevmodeW (GDI32.@)
773 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
776 WORD dmW_size, dmA_size;
778 dmA_size = dmA->dmSize;
780 /* this is the minimal dmSize that XP accepts */
781 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
784 if (dmA_size > sizeof(DEVMODEA))
785 dmA_size = sizeof(DEVMODEA);
787 dmW_size = dmA_size + CCHDEVICENAME;
788 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
789 dmW_size += CCHFORMNAME;
791 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
792 if (!dmW) return NULL;
794 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
795 dmW->dmDeviceName, CCHDEVICENAME);
796 /* copy slightly more, to avoid long computations */
797 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
799 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
801 if (dmA->dmFields & DM_FORMNAME)
802 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
803 dmW->dmFormName, CCHFORMNAME);
805 dmW->dmFormName[0] = 0;
807 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
808 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
811 if (dmA->dmDriverExtra)
812 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
814 dmW->dmSize = dmW_size;
820 /*****************************************************************************
823 * This should thunk to 16-bit and simply call the proc with the given args.
825 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
826 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
828 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
832 /*****************************************************************************
835 * This should load the correct driver for lpszDevice and calls this driver's
836 * ExtDeviceModePropSheet proc.
838 * Note: The driver calls a callback routine for each property sheet page; these
839 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
840 * The layout of this structure is:
846 * HPROPSHEETPAGE pages[10];
849 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
850 LPCSTR lpszPort, LPVOID lpPropSheet )
852 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
856 /*****************************************************************************
859 * This should load the correct driver for lpszDevice and call this driver's
860 * ExtDeviceMode proc.
862 * FIXME: convert ExtDeviceMode to unicode in the driver interface
864 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
865 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
866 LPSTR lpszPort, LPDEVMODEA lpdmInput,
867 LPSTR lpszProfile, DWORD fwMode )
876 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
877 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
879 if (!lpszDevice) return -1;
880 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
882 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
884 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
886 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
888 if ((dc = get_dc_ptr( hdc )))
890 if (dc->funcs->pExtDeviceMode)
891 ret = dc->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
892 lpdmInput, lpszProfile, fwMode );
893 release_dc_ptr( dc );
899 /****************************************************************************
902 * This should load the correct driver for lpszDevice and calls this driver's
903 * AdvancedSetupDialog proc.
905 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
906 LPDEVMODEA devin, LPDEVMODEA devout )
908 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
912 /*****************************************************************************
915 * This should load the correct driver for lpszDevice and calls this driver's
916 * DeviceCapabilities proc.
918 * FIXME: convert DeviceCapabilities to unicode in the driver interface
920 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
921 WORD fwCapability, LPSTR lpszOutput,
931 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
933 if (!lpszDevice) return -1;
934 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
936 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
938 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
940 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
942 if ((dc = get_dc_ptr( hdc )))
944 if (dc->funcs->pDeviceCapabilities)
945 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
946 fwCapability, lpszOutput, lpdm );
947 release_dc_ptr( dc );
954 /************************************************************************
957 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
965 return AbortDoc( hdc );
968 return EndDoc( hdc );
970 case GETPHYSPAGESIZE:
972 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
973 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
976 case GETPRINTINGOFFSET:
978 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
979 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
982 case GETSCALINGFACTOR:
984 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
985 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
989 return EndPage( hdc );
992 return SetAbortProc( hdc, (ABORTPROC)in_data );
999 /* in_data may not be 0 terminated so we must copy it */
1002 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1003 memcpy( name, in_data, in_count );
1006 /* out_data is actually a pointer to the DocInfo structure and used as
1007 * a second input parameter */
1008 if (out_data) doc = *(DOCINFOA *)out_data;
1011 doc.cbSize = sizeof(doc);
1012 doc.lpszOutput = NULL;
1013 doc.lpszDatatype = NULL;
1016 doc.lpszDocName = name;
1017 ret = StartDocA( hdc, &doc );
1018 HeapFree( GetProcessHeap(), 0, name );
1019 if (ret > 0) ret = StartPage( hdc );
1023 case QUERYESCSUPPORT:
1025 const INT *ptr = (const INT *)in_data;
1026 if (in_count < sizeof(INT)) return 0;
1031 case GETPHYSPAGESIZE:
1032 case GETPRINTINGOFFSET:
1033 case GETSCALINGFACTOR:
1035 case QUERYESCSUPPORT:
1044 /* if not handled internally, pass it to the driver */
1045 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1049 /******************************************************************************
1050 * ExtEscape [GDI32.@]
1052 * Access capabilities of a particular device that are not available through GDI.
1055 * hdc [I] Handle to device context
1056 * nEscape [I] Escape function
1057 * cbInput [I] Number of bytes in input structure
1058 * lpszInData [I] Pointer to input structure
1059 * cbOutput [I] Number of bytes in output structure
1060 * lpszOutData [O] Pointer to output structure
1064 * Not implemented: 0
1067 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1068 INT cbOutput, LPSTR lpszOutData )
1071 DC * dc = get_dc_ptr( hdc );
1074 if (dc->funcs->pExtEscape)
1075 ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1076 release_dc_ptr( dc );
1082 /*******************************************************************
1083 * DrawEscape [GDI32.@]
1087 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1089 FIXME("DrawEscape, stub\n");
1093 /*******************************************************************
1094 * NamedEscape [GDI32.@]
1096 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1097 INT cbOutput, LPSTR lpszOutData )
1099 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1100 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1105 /*******************************************************************
1106 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1107 * GdiEntry13 [GDI32.@]
1109 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1111 static int warn_once;