ole32/tests: Fix crash under NT.
[wine/multimedia.git] / dlls / gdi32 / driver.c
blobf625f324b0f79b65d98f5e075a40712b11b71f8c
1 /*
2 * Graphics driver management functions
4 * Copyright 1994 Bob Amstadt
5 * Copyright 1996, 2001 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winreg.h"
32 #include "ddrawgdi.h"
33 #include "wine/winbase16.h"
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(driver);
42 struct graphics_driver
44 struct list entry;
45 HMODULE module; /* module handle */
46 const struct gdi_dc_funcs *funcs;
49 static struct list drivers = LIST_INIT( drivers );
50 static struct graphics_driver *display_driver;
51 static DWORD display_driver_load_error;
53 const struct gdi_dc_funcs *font_driver = NULL;
55 static CRITICAL_SECTION driver_section;
56 static CRITICAL_SECTION_DEBUG critsect_debug =
58 0, 0, &driver_section,
59 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
60 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
62 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
64 #ifdef __APPLE__
65 static const char default_driver[] = "mac,x11";
66 #else
67 static const char default_driver[] = "x11";
68 #endif
70 /**********************************************************************
71 * create_driver
73 * Allocate and fill the driver structure for a given module.
75 static struct graphics_driver *create_driver( HMODULE module )
77 static const struct gdi_dc_funcs empty_funcs;
78 const struct gdi_dc_funcs *funcs = NULL;
79 struct graphics_driver *driver;
81 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
82 driver->module = module;
84 if (module)
86 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
88 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
89 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
91 if (!funcs) funcs = &empty_funcs;
92 driver->funcs = funcs;
93 return driver;
97 /**********************************************************************
98 * get_display_driver
100 * Special case for loading the display driver: get the name from the config file
102 static const struct gdi_dc_funcs *get_display_driver( HMODULE *module_ret )
104 struct graphics_driver *driver;
105 char buffer[MAX_PATH], libname[32], *name, *next;
106 HMODULE module = 0;
107 HKEY hkey;
109 if (display_driver) goto done;
111 strcpy( buffer, default_driver );
112 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
113 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
115 DWORD type, count = sizeof(buffer);
116 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
117 RegCloseKey( hkey );
120 name = buffer;
121 while (name)
123 next = strchr( name, ',' );
124 if (next) *next++ = 0;
126 snprintf( libname, sizeof(libname), "wine%s.drv", name );
127 if ((module = LoadLibraryA( libname )) != 0) break;
128 name = next;
131 if (!module) display_driver_load_error = GetLastError();
133 if (!(driver = create_driver( module )))
135 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
136 FreeLibrary( module );
137 ExitProcess(1);
139 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
141 /* somebody beat us to it */
142 FreeLibrary( driver->module );
143 HeapFree( GetProcessHeap(), 0, driver );
145 done:
146 *module_ret = display_driver->module;
147 return display_driver->funcs;
151 /**********************************************************************
152 * DRIVER_load_driver
154 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name, HMODULE *module_ret )
156 HMODULE module;
157 struct graphics_driver *driver, *new_driver;
158 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
159 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
161 /* display driver is a special case */
162 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W ))
163 return get_display_driver( module_ret );
165 if ((module = GetModuleHandleW( name )))
167 if (display_driver && display_driver->module == module)
169 *module_ret = module;
170 return display_driver->funcs;
172 EnterCriticalSection( &driver_section );
173 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
175 if (driver->module == module) goto done;
177 LeaveCriticalSection( &driver_section );
180 if (!(module = LoadLibraryW( name ))) return NULL;
182 if (!(new_driver = create_driver( module )))
184 FreeLibrary( module );
185 return NULL;
188 /* check if someone else added it in the meantime */
189 EnterCriticalSection( &driver_section );
190 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
192 if (driver->module != module) continue;
193 FreeLibrary( module );
194 HeapFree( GetProcessHeap(), 0, new_driver );
195 goto done;
197 driver = new_driver;
198 list_add_head( &drivers, &driver->entry );
199 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
200 done:
201 *module_ret = driver->module;
202 LeaveCriticalSection( &driver_section );
203 return driver->funcs;
207 /***********************************************************************
208 * __wine_get_driver_module (GDI32.@)
210 HMODULE CDECL __wine_get_driver_module( HDC hdc )
212 DC *dc;
213 HMODULE ret = 0;
215 if ((dc = get_dc_ptr( hdc )))
217 ret = dc->module;
218 release_dc_ptr( dc );
219 if (!ret) SetLastError( display_driver_load_error );
221 else SetLastError( ERROR_INVALID_HANDLE );
222 return ret;
226 static INT nulldrv_AbortDoc( PHYSDEV dev )
228 return 0;
231 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
232 INT xstart, INT ystart, INT xend, INT yend )
234 return TRUE;
237 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
238 INT xstart, INT ystart, INT xend, INT yend )
240 return TRUE;
243 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
245 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
246 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
249 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
250 LPCWSTR output, const DEVMODEW *devmode )
252 assert(0); /* should never be called */
253 return FALSE;
256 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
258 assert(0); /* should never be called */
259 return TRUE;
262 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
264 return TRUE;
267 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
268 WORD cap, LPSTR output, DEVMODEA *devmode )
270 return -1;
273 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
275 return TRUE;
278 static INT nulldrv_EndDoc( PHYSDEV dev )
280 return 0;
283 static INT nulldrv_EndPage( PHYSDEV dev )
285 return 0;
288 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
290 return TRUE;
293 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
295 return -1;
298 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
299 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
301 return -1;
304 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
305 INT out_size, void *out_data )
307 return 0;
310 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
312 return TRUE;
315 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
317 return FALSE;
320 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
322 return FALSE;
325 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
327 return FALSE;
330 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
332 return DCB_RESET;
335 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
337 return FALSE;
340 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
342 return FALSE;
345 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
347 return FALSE;
350 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
352 switch (cap) /* return meaningful values for some entries */
354 case HORZRES: return 640;
355 case VERTRES: return 480;
356 case BITSPIXEL: return 1;
357 case PLANES: return 1;
358 case NUMCOLORS: return 2;
359 case ASPECTX: return 36;
360 case ASPECTY: return 36;
361 case ASPECTXY: return 51;
362 case LOGPIXELSX: return 72;
363 case LOGPIXELSY: return 72;
364 case SIZEPALETTE: return 2;
365 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
366 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
367 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
368 default: return 0;
372 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
374 SetLastError( ERROR_INVALID_PARAMETER );
375 return FALSE;
378 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
380 return FALSE;
383 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
385 return 0;
388 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
390 return GDI_ERROR;
393 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
394 DWORD size, LPVOID buffer, const MAT2 *mat )
396 return GDI_ERROR;
399 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
401 return FALSE;
404 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
405 struct bitblt_coords *src )
407 return ERROR_NOT_SUPPORTED;
410 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
412 return 0;
415 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
417 return 0;
420 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
422 return 0;
425 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
427 return DEFAULT_CHARSET;
430 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
432 return FALSE;
435 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
437 return FALSE;
440 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
442 INT ret = 0;
443 LOGFONTW font;
444 HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
446 if (GetObjectW( hfont, sizeof(font), &font ))
448 ret = strlenW( font.lfFaceName ) + 1;
449 if (name)
451 lstrcpynW( name, font.lfFaceName, size );
452 ret = min( size, ret );
455 return ret;
458 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
460 return FALSE;
463 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
465 return TRUE;
468 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
470 return TRUE;
473 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
475 return TRUE;
478 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
480 return TRUE;
483 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
484 INT xstart, INT ystart, INT xend, INT yend )
486 return TRUE;
489 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
491 return TRUE;
494 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
496 return TRUE;
499 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
501 INT counts[1] = { count };
503 return PolyPolygon( dev->hdc, points, counts, 1 );
506 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
508 DWORD counts[1] = { count };
510 if (count < 0) return FALSE;
511 return PolyPolyline( dev->hdc, points, counts, 1 );
514 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
515 const struct gdi_image_bits *bits, struct bitblt_coords *src,
516 struct bitblt_coords *dst, DWORD rop )
518 return ERROR_SUCCESS;
521 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
523 return 0;
526 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
528 return 0;
531 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
533 return TRUE;
536 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
538 return 0;
541 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
542 INT ell_width, INT ell_height )
544 return TRUE;
547 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
549 return bitmap;
552 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
554 return brush;
557 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
559 return palette;
562 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
564 return pen;
567 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
569 return dir;
572 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
574 return color;
577 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
579 return mode;
582 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
584 return DCB_RESET;
587 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
589 return color;
592 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
594 return color;
597 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
601 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
603 return layout;
606 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
608 SetLastError( ERROR_INVALID_PARAMETER );
609 return FALSE;
612 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
614 return flags;
617 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
619 return color;
622 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
624 return mode;
627 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
629 return rop;
632 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
634 return mode;
637 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
639 return mode;
642 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
644 return align;
647 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
649 return extra;
652 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
654 return color;
657 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
659 return TRUE;
662 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
664 return 0;
667 static INT nulldrv_StartPage( PHYSDEV dev )
669 return 1;
672 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
674 return FALSE;
677 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
679 return (void *)-1;
682 const struct gdi_dc_funcs null_driver =
684 nulldrv_AbortDoc, /* pAbortDoc */
685 nulldrv_AbortPath, /* pAbortPath */
686 nulldrv_AlphaBlend, /* pAlphaBlend */
687 nulldrv_AngleArc, /* pAngleArc */
688 nulldrv_Arc, /* pArc */
689 nulldrv_ArcTo, /* pArcTo */
690 nulldrv_BeginPath, /* pBeginPath */
691 nulldrv_BlendImage, /* pBlendImage */
692 nulldrv_Chord, /* pChord */
693 nulldrv_CloseFigure, /* pCloseFigure */
694 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
695 nulldrv_CreateDC, /* pCreateDC */
696 nulldrv_DeleteDC, /* pDeleteDC */
697 nulldrv_DeleteObject, /* pDeleteObject */
698 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
699 nulldrv_Ellipse, /* pEllipse */
700 nulldrv_EndDoc, /* pEndDoc */
701 nulldrv_EndPage, /* pEndPage */
702 nulldrv_EndPath, /* pEndPath */
703 nulldrv_EnumFonts, /* pEnumFonts */
704 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
705 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
706 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
707 nulldrv_ExtEscape, /* pExtEscape */
708 nulldrv_ExtFloodFill, /* pExtFloodFill */
709 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
710 nulldrv_ExtTextOut, /* pExtTextOut */
711 nulldrv_FillPath, /* pFillPath */
712 nulldrv_FillRgn, /* pFillRgn */
713 nulldrv_FlattenPath, /* pFlattenPath */
714 nulldrv_FontIsLinked, /* pFontIsLinked */
715 nulldrv_FrameRgn, /* pFrameRgn */
716 nulldrv_GdiComment, /* pGdiComment */
717 nulldrv_GdiRealizationInfo, /* pGdiRealizationInfo */
718 nulldrv_GetBoundsRect, /* pGetBoundsRect */
719 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
720 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
721 nulldrv_GetCharWidth, /* pGetCharWidth */
722 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
723 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
724 nulldrv_GetFontData, /* pGetFontData */
725 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
726 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
727 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
728 nulldrv_GetICMProfile, /* pGetICMProfile */
729 nulldrv_GetImage, /* pGetImage */
730 nulldrv_GetKerningPairs, /* pGetKerningPairs */
731 nulldrv_GetNearestColor, /* pGetNearestColor */
732 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
733 nulldrv_GetPixel, /* pGetPixel */
734 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
735 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
736 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
737 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
738 nulldrv_GetTextFace, /* pGetTextFace */
739 nulldrv_GetTextMetrics, /* pGetTextMetrics */
740 nulldrv_GradientFill, /* pGradientFill */
741 nulldrv_IntersectClipRect, /* pIntersectClipRect */
742 nulldrv_InvertRgn, /* pInvertRgn */
743 nulldrv_LineTo, /* pLineTo */
744 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
745 nulldrv_MoveTo, /* pMoveTo */
746 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
747 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
748 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
749 nulldrv_PaintRgn, /* pPaintRgn */
750 nulldrv_PatBlt, /* pPatBlt */
751 nulldrv_Pie, /* pPie */
752 nulldrv_PolyBezier, /* pPolyBezier */
753 nulldrv_PolyBezierTo, /* pPolyBezierTo */
754 nulldrv_PolyDraw, /* pPolyDraw */
755 nulldrv_PolyPolygon, /* pPolyPolygon */
756 nulldrv_PolyPolyline, /* pPolyPolyline */
757 nulldrv_Polygon, /* pPolygon */
758 nulldrv_Polyline, /* pPolyline */
759 nulldrv_PolylineTo, /* pPolylineTo */
760 nulldrv_PutImage, /* pPutImage */
761 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
762 nulldrv_RealizePalette, /* pRealizePalette */
763 nulldrv_Rectangle, /* pRectangle */
764 nulldrv_ResetDC, /* pResetDC */
765 nulldrv_RestoreDC, /* pRestoreDC */
766 nulldrv_RoundRect, /* pRoundRect */
767 nulldrv_SaveDC, /* pSaveDC */
768 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
769 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
770 nulldrv_SelectBitmap, /* pSelectBitmap */
771 nulldrv_SelectBrush, /* pSelectBrush */
772 nulldrv_SelectClipPath, /* pSelectClipPath */
773 nulldrv_SelectFont, /* pSelectFont */
774 nulldrv_SelectPalette, /* pSelectPalette */
775 nulldrv_SelectPen, /* pSelectPen */
776 nulldrv_SetArcDirection, /* pSetArcDirection */
777 nulldrv_SetBkColor, /* pSetBkColor */
778 nulldrv_SetBkMode, /* pSetBkMode */
779 nulldrv_SetBoundsRect, /* pSetBoundsRect */
780 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
781 nulldrv_SetDCPenColor, /* pSetDCPenColor */
782 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
783 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
784 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
785 nulldrv_SetLayout, /* pSetLayout */
786 nulldrv_SetMapMode, /* pSetMapMode */
787 nulldrv_SetMapperFlags, /* pSetMapperFlags */
788 nulldrv_SetPixel, /* pSetPixel */
789 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
790 nulldrv_SetROP2, /* pSetROP2 */
791 nulldrv_SetRelAbs, /* pSetRelAbs */
792 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
793 nulldrv_SetTextAlign, /* pSetTextAlign */
794 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
795 nulldrv_SetTextColor, /* pSetTextColor */
796 nulldrv_SetTextJustification, /* pSetTextJustification */
797 nulldrv_SetViewportExtEx, /* pSetViewportExt */
798 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
799 nulldrv_SetWindowExtEx, /* pSetWindowExt */
800 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
801 nulldrv_SetWorldTransform, /* pSetWorldTransform */
802 nulldrv_StartDoc, /* pStartDoc */
803 nulldrv_StartPage, /* pStartPage */
804 nulldrv_StretchBlt, /* pStretchBlt */
805 nulldrv_StretchDIBits, /* pStretchDIBits */
806 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
807 nulldrv_StrokePath, /* pStrokePath */
808 nulldrv_UnrealizePalette, /* pUnrealizePalette */
809 nulldrv_WidenPath, /* pWidenPath */
810 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
812 GDI_PRIORITY_NULL_DRV /* priority */
816 /*****************************************************************************
817 * DRIVER_GetDriverName
820 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
822 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
823 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
824 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
825 static const WCHAR empty_strW[] = { 0 };
826 WCHAR *p;
828 /* display is a special case */
829 if (!strcmpiW( device, displayW ) ||
830 !strcmpiW( device, display1W ))
832 lstrcpynW( driver, displayW, size );
833 return TRUE;
836 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
837 if(!size) {
838 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
839 return FALSE;
841 p = strchrW(driver, ',');
842 if(!p)
844 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
845 return FALSE;
847 *p = 0;
848 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
849 return TRUE;
853 /***********************************************************************
854 * GdiConvertToDevmodeW (GDI32.@)
856 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
858 DEVMODEW *dmW;
859 WORD dmW_size, dmA_size;
861 dmA_size = dmA->dmSize;
863 /* this is the minimal dmSize that XP accepts */
864 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
865 return NULL;
867 if (dmA_size > sizeof(DEVMODEA))
868 dmA_size = sizeof(DEVMODEA);
870 dmW_size = dmA_size + CCHDEVICENAME;
871 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
872 dmW_size += CCHFORMNAME;
874 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
875 if (!dmW) return NULL;
877 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
878 dmW->dmDeviceName, CCHDEVICENAME);
879 /* copy slightly more, to avoid long computations */
880 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
882 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
884 if (dmA->dmFields & DM_FORMNAME)
885 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
886 dmW->dmFormName, CCHFORMNAME);
887 else
888 dmW->dmFormName[0] = 0;
890 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
891 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
894 if (dmA->dmDriverExtra)
895 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
897 dmW->dmSize = dmW_size;
899 return dmW;
903 /*****************************************************************************
904 * @ [GDI32.100]
906 * This should thunk to 16-bit and simply call the proc with the given args.
908 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
909 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
911 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
912 return -1;
915 /*****************************************************************************
916 * @ [GDI32.101]
918 * This should load the correct driver for lpszDevice and calls this driver's
919 * ExtDeviceModePropSheet proc.
921 * Note: The driver calls a callback routine for each property sheet page; these
922 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
923 * The layout of this structure is:
925 * struct
927 * DWORD nPages;
928 * DWORD unknown;
929 * HPROPSHEETPAGE pages[10];
930 * };
932 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
933 LPCSTR lpszPort, LPVOID lpPropSheet )
935 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
936 return -1;
939 /*****************************************************************************
940 * @ [GDI32.102]
942 * This should load the correct driver for lpszDevice and call this driver's
943 * ExtDeviceMode proc.
945 * FIXME: convert ExtDeviceMode to unicode in the driver interface
947 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
948 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
949 LPSTR lpszPort, LPDEVMODEA lpdmInput,
950 LPSTR lpszProfile, DWORD fwMode )
952 WCHAR deviceW[300];
953 WCHAR bufW[300];
954 char buf[300];
955 HDC hdc;
956 DC *dc;
957 INT ret = -1;
959 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
960 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
962 if (!lpszDevice) return -1;
963 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
965 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
967 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
969 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
971 if ((dc = get_dc_ptr( hdc )))
973 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
974 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
975 lpdmInput, lpszProfile, fwMode );
976 release_dc_ptr( dc );
978 DeleteDC( hdc );
979 return ret;
982 /****************************************************************************
983 * @ [GDI32.103]
985 * This should load the correct driver for lpszDevice and calls this driver's
986 * AdvancedSetupDialog proc.
988 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
989 LPDEVMODEA devin, LPDEVMODEA devout )
991 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
992 return -1;
995 /*****************************************************************************
996 * @ [GDI32.104]
998 * This should load the correct driver for lpszDevice and calls this driver's
999 * DeviceCapabilities proc.
1001 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1003 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1004 WORD fwCapability, LPSTR lpszOutput,
1005 LPDEVMODEA lpdm )
1007 WCHAR deviceW[300];
1008 WCHAR bufW[300];
1009 char buf[300];
1010 HDC hdc;
1011 DC *dc;
1012 INT ret = -1;
1014 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1016 if (!lpszDevice) return -1;
1017 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1019 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1021 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1023 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1025 if ((dc = get_dc_ptr( hdc )))
1027 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1028 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1029 fwCapability, lpszOutput, lpdm );
1030 release_dc_ptr( dc );
1032 DeleteDC( hdc );
1033 return ret;
1037 /************************************************************************
1038 * Escape [GDI32.@]
1040 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1042 INT ret;
1043 POINT *pt;
1045 switch (escape)
1047 case ABORTDOC:
1048 return AbortDoc( hdc );
1050 case ENDDOC:
1051 return EndDoc( hdc );
1053 case GETPHYSPAGESIZE:
1054 pt = out_data;
1055 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1056 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1057 return 1;
1059 case GETPRINTINGOFFSET:
1060 pt = out_data;
1061 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1062 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1063 return 1;
1065 case GETSCALINGFACTOR:
1066 pt = out_data;
1067 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1068 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1069 return 1;
1071 case NEWFRAME:
1072 return EndPage( hdc );
1074 case SETABORTPROC:
1075 return SetAbortProc( hdc, (ABORTPROC)in_data );
1077 case STARTDOC:
1079 DOCINFOA doc;
1080 char *name = NULL;
1082 /* in_data may not be 0 terminated so we must copy it */
1083 if (in_data)
1085 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1086 memcpy( name, in_data, in_count );
1087 name[in_count] = 0;
1089 /* out_data is actually a pointer to the DocInfo structure and used as
1090 * a second input parameter */
1091 if (out_data) doc = *(DOCINFOA *)out_data;
1092 else
1094 doc.cbSize = sizeof(doc);
1095 doc.lpszOutput = NULL;
1096 doc.lpszDatatype = NULL;
1097 doc.fwType = 0;
1099 doc.lpszDocName = name;
1100 ret = StartDocA( hdc, &doc );
1101 HeapFree( GetProcessHeap(), 0, name );
1102 if (ret > 0) ret = StartPage( hdc );
1103 return ret;
1106 case QUERYESCSUPPORT:
1108 DWORD code;
1110 if (in_count < sizeof(SHORT)) return 0;
1111 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1112 switch (code)
1114 case ABORTDOC:
1115 case ENDDOC:
1116 case GETPHYSPAGESIZE:
1117 case GETPRINTINGOFFSET:
1118 case GETSCALINGFACTOR:
1119 case NEWFRAME:
1120 case QUERYESCSUPPORT:
1121 case SETABORTPROC:
1122 case STARTDOC:
1123 return TRUE;
1125 break;
1129 /* if not handled internally, pass it to the driver */
1130 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1134 /******************************************************************************
1135 * ExtEscape [GDI32.@]
1137 * Access capabilities of a particular device that are not available through GDI.
1139 * PARAMS
1140 * hdc [I] Handle to device context
1141 * nEscape [I] Escape function
1142 * cbInput [I] Number of bytes in input structure
1143 * lpszInData [I] Pointer to input structure
1144 * cbOutput [I] Number of bytes in output structure
1145 * lpszOutData [O] Pointer to output structure
1147 * RETURNS
1148 * Success: >0
1149 * Not implemented: 0
1150 * Failure: <0
1152 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1153 INT cbOutput, LPSTR lpszOutData )
1155 PHYSDEV physdev;
1156 INT ret;
1157 DC * dc = get_dc_ptr( hdc );
1159 if (!dc) return 0;
1160 update_dc( dc );
1161 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1162 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1163 release_dc_ptr( dc );
1164 return ret;
1168 /*******************************************************************
1169 * DrawEscape [GDI32.@]
1173 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1175 FIXME("DrawEscape, stub\n");
1176 return 0;
1179 /*******************************************************************
1180 * NamedEscape [GDI32.@]
1182 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1183 INT cbOutput, LPSTR lpszOutData )
1185 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1186 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1187 lpszOutData);
1188 return 0;
1191 /*******************************************************************
1192 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1193 * GdiEntry13 [GDI32.@]
1195 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1197 static int warn_once;
1199 if (!warn_once++)
1200 FIXME("stub\n");
1201 return 0;