joy.cpl: Correct joystick testing thread behavior.
[wine.git] / dlls / gdi32 / driver.c
blobf4c5f52c333bc7563f89853134442fb4c543cb92
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;
52 const struct gdi_dc_funcs *font_driver = NULL;
53 static const struct wgl_funcs null_wgl_driver;
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 /**********************************************************************
65 * create_driver
67 * Allocate and fill the driver structure for a given module.
69 static struct graphics_driver *create_driver( HMODULE module )
71 static const struct gdi_dc_funcs empty_funcs;
72 const struct gdi_dc_funcs *funcs = NULL;
73 struct graphics_driver *driver;
75 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
76 driver->module = module;
78 if (module)
80 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
82 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
83 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
85 if (!funcs) funcs = &empty_funcs;
86 driver->funcs = funcs;
87 return driver;
91 /**********************************************************************
92 * get_display_driver
94 * Special case for loading the display driver: get the name from the config file
96 static const struct gdi_dc_funcs *get_display_driver(void)
98 struct graphics_driver *driver;
99 char buffer[MAX_PATH], libname[32], *name, *next;
100 HMODULE module = 0;
101 HKEY hkey;
103 if (display_driver) return display_driver->funcs; /* already loaded */
105 strcpy( buffer, "x11" ); /* default value */
106 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
107 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
109 DWORD type, count = sizeof(buffer);
110 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
111 RegCloseKey( hkey );
114 name = buffer;
115 while (name)
117 next = strchr( name, ',' );
118 if (next) *next++ = 0;
120 snprintf( libname, sizeof(libname), "wine%s.drv", name );
121 if ((module = LoadLibraryA( libname )) != 0) break;
122 name = next;
125 if (!(driver = create_driver( module )))
127 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
128 FreeLibrary( module );
129 ExitProcess(1);
131 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
133 /* somebody beat us to it */
134 FreeLibrary( driver->module );
135 HeapFree( GetProcessHeap(), 0, driver );
137 return display_driver->funcs;
141 /**********************************************************************
142 * DRIVER_load_driver
144 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
146 HMODULE module;
147 struct graphics_driver *driver, *new_driver;
148 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
149 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
151 /* display driver is a special case */
152 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
154 if ((module = GetModuleHandleW( name )))
156 if (display_driver && display_driver->module == module) return display_driver->funcs;
157 EnterCriticalSection( &driver_section );
158 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
160 if (driver->module == module) goto done;
162 LeaveCriticalSection( &driver_section );
165 if (!(module = LoadLibraryW( name ))) return NULL;
167 if (!(new_driver = create_driver( module )))
169 FreeLibrary( module );
170 return NULL;
173 /* check if someone else added it in the meantime */
174 EnterCriticalSection( &driver_section );
175 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
177 if (driver->module != module) continue;
178 FreeLibrary( module );
179 HeapFree( GetProcessHeap(), 0, new_driver );
180 goto done;
182 driver = new_driver;
183 list_add_head( &drivers, &driver->entry );
184 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
185 done:
186 LeaveCriticalSection( &driver_section );
187 return driver->funcs;
191 static INT nulldrv_AbortDoc( PHYSDEV dev )
193 return 0;
196 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
197 INT xstart, INT ystart, INT xend, INT yend )
199 return TRUE;
202 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
203 INT xstart, INT ystart, INT xend, INT yend )
205 return TRUE;
208 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
210 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
211 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
214 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
215 LPCWSTR output, const DEVMODEW *devmode )
217 assert(0); /* should never be called */
218 return FALSE;
221 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
223 assert(0); /* should never be called */
224 return TRUE;
227 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
229 return TRUE;
232 static INT nulldrv_DescribePixelFormat( PHYSDEV dev, INT format, UINT size, PIXELFORMATDESCRIPTOR * descr )
234 return 0;
237 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
238 WORD cap, LPSTR output, DEVMODEA *devmode )
240 return -1;
243 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
245 return TRUE;
248 static INT nulldrv_EndDoc( PHYSDEV dev )
250 return 0;
253 static INT nulldrv_EndPage( PHYSDEV dev )
255 return 0;
258 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
260 return TRUE;
263 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
265 return -1;
268 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
269 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
271 return -1;
274 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
275 INT out_size, void *out_data )
277 return 0;
280 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
282 return TRUE;
285 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
287 return FALSE;
290 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
292 return FALSE;
295 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
297 return FALSE;
300 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
302 return DCB_RESET;
305 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
307 return FALSE;
310 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
312 return FALSE;
315 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
317 return FALSE;
320 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
322 switch (cap) /* return meaningful values for some entries */
324 case HORZRES: return 640;
325 case VERTRES: return 480;
326 case BITSPIXEL: return 1;
327 case PLANES: return 1;
328 case NUMCOLORS: return 2;
329 case ASPECTX: return 36;
330 case ASPECTY: return 36;
331 case ASPECTXY: return 51;
332 case LOGPIXELSX: return 72;
333 case LOGPIXELSY: return 72;
334 case SIZEPALETTE: return 2;
335 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
336 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
337 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
338 default: return 0;
342 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
344 SetLastError( ERROR_INVALID_PARAMETER );
345 return FALSE;
348 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
350 return FALSE;
353 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
355 return 0;
358 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
360 return GDI_ERROR;
363 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
364 DWORD size, LPVOID buffer, const MAT2 *mat )
366 return GDI_ERROR;
369 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
371 return FALSE;
374 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
375 struct bitblt_coords *src )
377 return ERROR_NOT_SUPPORTED;
380 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
382 return 0;
385 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
387 return 0;
390 static INT nulldrv_GetPixelFormat( HDC hdc )
392 return 0;
395 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
397 return 0;
400 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
402 return DEFAULT_CHARSET;
405 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
406 INT *fit, INT *dx, SIZE *size )
408 return FALSE;
411 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT max_ext,
412 INT *fit, INT *dx, SIZE *size )
414 return FALSE;
417 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
419 INT ret = 0;
420 LOGFONTW font;
421 HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
423 if (GetObjectW( hfont, sizeof(font), &font ))
425 ret = strlenW( font.lfFaceName ) + 1;
426 if (name)
428 lstrcpynW( name, font.lfFaceName, size );
429 ret = min( size, ret );
432 return ret;
435 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
437 return FALSE;
440 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
442 return TRUE;
445 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
447 return TRUE;
450 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
452 return TRUE;
455 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
457 return TRUE;
460 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
461 INT xstart, INT ystart, INT xend, INT yend )
463 return TRUE;
466 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
468 return TRUE;
471 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
473 return TRUE;
476 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
478 INT counts[1] = { count };
480 return PolyPolygon( dev->hdc, points, counts, 1 );
483 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
485 DWORD counts[1] = { count };
487 if (count < 0) return FALSE;
488 return PolyPolyline( dev->hdc, points, counts, 1 );
491 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
492 const struct gdi_image_bits *bits, struct bitblt_coords *src,
493 struct bitblt_coords *dst, DWORD rop )
495 return ERROR_SUCCESS;
498 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
500 return 0;
503 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
505 return 0;
508 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
510 return TRUE;
513 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
515 return 0;
518 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
519 INT ell_width, INT ell_height )
521 return TRUE;
524 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
526 return bitmap;
529 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
531 return brush;
534 static HFONT nulldrv_SelectFont( PHYSDEV dev, HFONT font )
536 return 0;
539 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
541 return palette;
544 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
546 return pen;
549 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
551 return dir;
554 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
556 return color;
559 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
561 return mode;
564 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
566 return DCB_RESET;
569 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
571 return color;
574 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
576 return color;
579 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
583 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
585 return layout;
588 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
590 SetLastError( ERROR_INVALID_PARAMETER );
591 return FALSE;
594 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
596 return flags;
599 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
601 return color;
604 static BOOL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
606 return FALSE;
609 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
611 return mode;
614 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
616 return rop;
619 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
621 return mode;
624 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
626 return mode;
629 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
631 return align;
634 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
636 return extra;
639 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
641 return color;
644 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
646 return TRUE;
649 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
651 return 0;
654 static INT nulldrv_StartPage( PHYSDEV dev )
656 return 1;
659 static BOOL nulldrv_SwapBuffers( PHYSDEV dev )
661 return TRUE;
664 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
666 return FALSE;
669 static BOOL nulldrv_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask )
671 return FALSE;
674 static struct wgl_context *nulldrv_wglCreateContext( HDC hdc )
676 return 0;
679 static struct wgl_context *nulldrv_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *share_ctx,
680 const int *attribs )
682 return 0;
685 static void nulldrv_wglDeleteContext( struct wgl_context *context )
689 static HDC nulldrv_wglGetCurrentDC( struct wgl_context *context )
691 return 0;
694 static PROC nulldrv_wglGetProcAddress( LPCSTR name )
696 return NULL;
699 static BOOL nulldrv_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *context )
701 return FALSE;
704 static BOOL nulldrv_wglMakeCurrent( HDC hdc, struct wgl_context *context )
706 return FALSE;
709 static BOOL nulldrv_wglShareLists( struct wgl_context *org, struct wgl_context *dst )
711 return FALSE;
714 static const struct wgl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
716 if (version != WINE_GDI_DRIVER_VERSION)
718 ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_GDI_DRIVER_VERSION );
719 return NULL;
721 return &null_wgl_driver;
724 const struct gdi_dc_funcs null_driver =
726 nulldrv_AbortDoc, /* pAbortDoc */
727 nulldrv_AbortPath, /* pAbortPath */
728 nulldrv_AlphaBlend, /* pAlphaBlend */
729 nulldrv_AngleArc, /* pAngleArc */
730 nulldrv_Arc, /* pArc */
731 nulldrv_ArcTo, /* pArcTo */
732 nulldrv_BeginPath, /* pBeginPath */
733 nulldrv_BlendImage, /* pBlendImage */
734 nulldrv_Chord, /* pChord */
735 nulldrv_CloseFigure, /* pCloseFigure */
736 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
737 nulldrv_CreateDC, /* pCreateDC */
738 nulldrv_DeleteDC, /* pDeleteDC */
739 nulldrv_DeleteObject, /* pDeleteObject */
740 nulldrv_DescribePixelFormat, /* pDescribePixelFormat */
741 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
742 nulldrv_Ellipse, /* pEllipse */
743 nulldrv_EndDoc, /* pEndDoc */
744 nulldrv_EndPage, /* pEndPage */
745 nulldrv_EndPath, /* pEndPath */
746 nulldrv_EnumFonts, /* pEnumFonts */
747 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
748 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
749 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
750 nulldrv_ExtEscape, /* pExtEscape */
751 nulldrv_ExtFloodFill, /* pExtFloodFill */
752 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
753 nulldrv_ExtTextOut, /* pExtTextOut */
754 nulldrv_FillPath, /* pFillPath */
755 nulldrv_FillRgn, /* pFillRgn */
756 nulldrv_FlattenPath, /* pFlattenPath */
757 nulldrv_FontIsLinked, /* pFontIsLinked */
758 nulldrv_FrameRgn, /* pFrameRgn */
759 nulldrv_GdiComment, /* pGdiComment */
760 nulldrv_GdiRealizationInfo, /* pGdiRealizationInfo */
761 nulldrv_GetBoundsRect, /* pGetBoundsRect */
762 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
763 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
764 nulldrv_GetCharWidth, /* pGetCharWidth */
765 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
766 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
767 nulldrv_GetFontData, /* pGetFontData */
768 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
769 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
770 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
771 nulldrv_GetICMProfile, /* pGetICMProfile */
772 nulldrv_GetImage, /* pGetImage */
773 nulldrv_GetKerningPairs, /* pGetKerningPairs */
774 nulldrv_GetNearestColor, /* pGetNearestColor */
775 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
776 nulldrv_GetPixel, /* pGetPixel */
777 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
778 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
779 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
780 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
781 nulldrv_GetTextFace, /* pGetTextFace */
782 nulldrv_GetTextMetrics, /* pGetTextMetrics */
783 nulldrv_GradientFill, /* pGradientFill */
784 nulldrv_IntersectClipRect, /* pIntersectClipRect */
785 nulldrv_InvertRgn, /* pInvertRgn */
786 nulldrv_LineTo, /* pLineTo */
787 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
788 nulldrv_MoveTo, /* pMoveTo */
789 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
790 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
791 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
792 nulldrv_PaintRgn, /* pPaintRgn */
793 nulldrv_PatBlt, /* pPatBlt */
794 nulldrv_Pie, /* pPie */
795 nulldrv_PolyBezier, /* pPolyBezier */
796 nulldrv_PolyBezierTo, /* pPolyBezierTo */
797 nulldrv_PolyDraw, /* pPolyDraw */
798 nulldrv_PolyPolygon, /* pPolyPolygon */
799 nulldrv_PolyPolyline, /* pPolyPolyline */
800 nulldrv_Polygon, /* pPolygon */
801 nulldrv_Polyline, /* pPolyline */
802 nulldrv_PolylineTo, /* pPolylineTo */
803 nulldrv_PutImage, /* pPutImage */
804 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
805 nulldrv_RealizePalette, /* pRealizePalette */
806 nulldrv_Rectangle, /* pRectangle */
807 nulldrv_ResetDC, /* pResetDC */
808 nulldrv_RestoreDC, /* pRestoreDC */
809 nulldrv_RoundRect, /* pRoundRect */
810 nulldrv_SaveDC, /* pSaveDC */
811 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
812 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
813 nulldrv_SelectBitmap, /* pSelectBitmap */
814 nulldrv_SelectBrush, /* pSelectBrush */
815 nulldrv_SelectClipPath, /* pSelectClipPath */
816 nulldrv_SelectFont, /* pSelectFont */
817 nulldrv_SelectPalette, /* pSelectPalette */
818 nulldrv_SelectPen, /* pSelectPen */
819 nulldrv_SetArcDirection, /* pSetArcDirection */
820 nulldrv_SetBkColor, /* pSetBkColor */
821 nulldrv_SetBkMode, /* pSetBkMode */
822 nulldrv_SetBoundsRect, /* pSetBoundsRect */
823 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
824 nulldrv_SetDCPenColor, /* pSetDCPenColor */
825 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
826 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
827 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
828 nulldrv_SetLayout, /* pSetLayout */
829 nulldrv_SetMapMode, /* pSetMapMode */
830 nulldrv_SetMapperFlags, /* pSetMapperFlags */
831 nulldrv_SetPixel, /* pSetPixel */
832 nulldrv_SetPixelFormat, /* pSetPixelFormat */
833 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
834 nulldrv_SetROP2, /* pSetROP2 */
835 nulldrv_SetRelAbs, /* pSetRelAbs */
836 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
837 nulldrv_SetTextAlign, /* pSetTextAlign */
838 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
839 nulldrv_SetTextColor, /* pSetTextColor */
840 nulldrv_SetTextJustification, /* pSetTextJustification */
841 nulldrv_SetViewportExtEx, /* pSetViewportExt */
842 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
843 nulldrv_SetWindowExtEx, /* pSetWindowExt */
844 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
845 nulldrv_SetWorldTransform, /* pSetWorldTransform */
846 nulldrv_StartDoc, /* pStartDoc */
847 nulldrv_StartPage, /* pStartPage */
848 nulldrv_StretchBlt, /* pStretchBlt */
849 nulldrv_StretchDIBits, /* pStretchDIBits */
850 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
851 nulldrv_StrokePath, /* pStrokePath */
852 nulldrv_SwapBuffers, /* pSwapBuffers */
853 nulldrv_UnrealizePalette, /* pUnrealizePalette */
854 nulldrv_WidenPath, /* pWidenPath */
855 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
857 GDI_PRIORITY_NULL_DRV /* priority */
860 static const struct wgl_funcs null_wgl_driver =
862 nulldrv_GetPixelFormat, /* p_GetPixelFormat */
863 nulldrv_wglCopyContext, /* p_wglCopyContext */
864 nulldrv_wglCreateContext, /* p_wglCreateContext */
865 nulldrv_wglCreateContextAttribsARB, /* p_wglCreateContextAttribsARB */
866 nulldrv_wglDeleteContext, /* p_wglDeleteContext */
867 nulldrv_wglGetCurrentDC, /* p_wglGetCurrentDC */
868 nulldrv_wglGetProcAddress, /* p_wglGetProcAddress */
869 nulldrv_wglMakeContextCurrentARB, /* p_wglMakeContextCurrentARB */
870 nulldrv_wglMakeCurrent, /* p_wglMakeCurrent */
871 nulldrv_wglShareLists, /* p_wglShareLists */
874 /*****************************************************************************
875 * DRIVER_GetDriverName
878 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
880 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
881 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
882 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
883 static const WCHAR empty_strW[] = { 0 };
884 WCHAR *p;
886 /* display is a special case */
887 if (!strcmpiW( device, displayW ) ||
888 !strcmpiW( device, display1W ))
890 lstrcpynW( driver, displayW, size );
891 return TRUE;
894 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
895 if(!size) {
896 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
897 return FALSE;
899 p = strchrW(driver, ',');
900 if(!p)
902 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
903 return FALSE;
905 *p = 0;
906 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
907 return TRUE;
911 /***********************************************************************
912 * GdiConvertToDevmodeW (GDI32.@)
914 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
916 DEVMODEW *dmW;
917 WORD dmW_size, dmA_size;
919 dmA_size = dmA->dmSize;
921 /* this is the minimal dmSize that XP accepts */
922 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
923 return NULL;
925 if (dmA_size > sizeof(DEVMODEA))
926 dmA_size = sizeof(DEVMODEA);
928 dmW_size = dmA_size + CCHDEVICENAME;
929 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
930 dmW_size += CCHFORMNAME;
932 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
933 if (!dmW) return NULL;
935 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
936 dmW->dmDeviceName, CCHDEVICENAME);
937 /* copy slightly more, to avoid long computations */
938 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
940 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
942 if (dmA->dmFields & DM_FORMNAME)
943 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
944 dmW->dmFormName, CCHFORMNAME);
945 else
946 dmW->dmFormName[0] = 0;
948 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
949 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
952 if (dmA->dmDriverExtra)
953 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
955 dmW->dmSize = dmW_size;
957 return dmW;
961 /*****************************************************************************
962 * @ [GDI32.100]
964 * This should thunk to 16-bit and simply call the proc with the given args.
966 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
967 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
969 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
970 return -1;
973 /*****************************************************************************
974 * @ [GDI32.101]
976 * This should load the correct driver for lpszDevice and calls this driver's
977 * ExtDeviceModePropSheet proc.
979 * Note: The driver calls a callback routine for each property sheet page; these
980 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
981 * The layout of this structure is:
983 * struct
985 * DWORD nPages;
986 * DWORD unknown;
987 * HPROPSHEETPAGE pages[10];
988 * };
990 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
991 LPCSTR lpszPort, LPVOID lpPropSheet )
993 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
994 return -1;
997 /*****************************************************************************
998 * @ [GDI32.102]
1000 * This should load the correct driver for lpszDevice and call this driver's
1001 * ExtDeviceMode proc.
1003 * FIXME: convert ExtDeviceMode to unicode in the driver interface
1005 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1006 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1007 LPSTR lpszPort, LPDEVMODEA lpdmInput,
1008 LPSTR lpszProfile, DWORD fwMode )
1010 WCHAR deviceW[300];
1011 WCHAR bufW[300];
1012 char buf[300];
1013 HDC hdc;
1014 DC *dc;
1015 INT ret = -1;
1017 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1018 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1020 if (!lpszDevice) return -1;
1021 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1023 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1025 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1027 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1029 if ((dc = get_dc_ptr( hdc )))
1031 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1032 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1033 lpdmInput, lpszProfile, fwMode );
1034 release_dc_ptr( dc );
1036 DeleteDC( hdc );
1037 return ret;
1040 /****************************************************************************
1041 * @ [GDI32.103]
1043 * This should load the correct driver for lpszDevice and calls this driver's
1044 * AdvancedSetupDialog proc.
1046 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1047 LPDEVMODEA devin, LPDEVMODEA devout )
1049 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1050 return -1;
1053 /*****************************************************************************
1054 * @ [GDI32.104]
1056 * This should load the correct driver for lpszDevice and calls this driver's
1057 * DeviceCapabilities proc.
1059 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1061 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1062 WORD fwCapability, LPSTR lpszOutput,
1063 LPDEVMODEA lpdm )
1065 WCHAR deviceW[300];
1066 WCHAR bufW[300];
1067 char buf[300];
1068 HDC hdc;
1069 DC *dc;
1070 INT ret = -1;
1072 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1074 if (!lpszDevice) return -1;
1075 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1077 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1079 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1081 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1083 if ((dc = get_dc_ptr( hdc )))
1085 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1086 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1087 fwCapability, lpszOutput, lpdm );
1088 release_dc_ptr( dc );
1090 DeleteDC( hdc );
1091 return ret;
1095 /************************************************************************
1096 * Escape [GDI32.@]
1098 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1100 INT ret;
1101 POINT *pt;
1103 switch (escape)
1105 case ABORTDOC:
1106 return AbortDoc( hdc );
1108 case ENDDOC:
1109 return EndDoc( hdc );
1111 case GETPHYSPAGESIZE:
1112 pt = out_data;
1113 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1114 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1115 return 1;
1117 case GETPRINTINGOFFSET:
1118 pt = out_data;
1119 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1120 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1121 return 1;
1123 case GETSCALINGFACTOR:
1124 pt = out_data;
1125 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1126 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1127 return 1;
1129 case NEWFRAME:
1130 return EndPage( hdc );
1132 case SETABORTPROC:
1133 return SetAbortProc( hdc, (ABORTPROC)in_data );
1135 case STARTDOC:
1137 DOCINFOA doc;
1138 char *name = NULL;
1140 /* in_data may not be 0 terminated so we must copy it */
1141 if (in_data)
1143 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1144 memcpy( name, in_data, in_count );
1145 name[in_count] = 0;
1147 /* out_data is actually a pointer to the DocInfo structure and used as
1148 * a second input parameter */
1149 if (out_data) doc = *(DOCINFOA *)out_data;
1150 else
1152 doc.cbSize = sizeof(doc);
1153 doc.lpszOutput = NULL;
1154 doc.lpszDatatype = NULL;
1155 doc.fwType = 0;
1157 doc.lpszDocName = name;
1158 ret = StartDocA( hdc, &doc );
1159 HeapFree( GetProcessHeap(), 0, name );
1160 if (ret > 0) ret = StartPage( hdc );
1161 return ret;
1164 case QUERYESCSUPPORT:
1166 const INT *ptr = (const INT *)in_data;
1167 if (in_count < sizeof(INT)) return 0;
1168 switch(*ptr)
1170 case ABORTDOC:
1171 case ENDDOC:
1172 case GETPHYSPAGESIZE:
1173 case GETPRINTINGOFFSET:
1174 case GETSCALINGFACTOR:
1175 case NEWFRAME:
1176 case QUERYESCSUPPORT:
1177 case SETABORTPROC:
1178 case STARTDOC:
1179 return TRUE;
1181 break;
1185 /* if not handled internally, pass it to the driver */
1186 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1190 /******************************************************************************
1191 * ExtEscape [GDI32.@]
1193 * Access capabilities of a particular device that are not available through GDI.
1195 * PARAMS
1196 * hdc [I] Handle to device context
1197 * nEscape [I] Escape function
1198 * cbInput [I] Number of bytes in input structure
1199 * lpszInData [I] Pointer to input structure
1200 * cbOutput [I] Number of bytes in output structure
1201 * lpszOutData [O] Pointer to output structure
1203 * RETURNS
1204 * Success: >0
1205 * Not implemented: 0
1206 * Failure: <0
1208 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1209 INT cbOutput, LPSTR lpszOutData )
1211 INT ret = 0;
1212 DC * dc = get_dc_ptr( hdc );
1214 if (dc)
1216 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1217 update_dc( dc );
1218 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1219 release_dc_ptr( dc );
1221 return ret;
1225 /*******************************************************************
1226 * DrawEscape [GDI32.@]
1230 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1232 FIXME("DrawEscape, stub\n");
1233 return 0;
1236 /*******************************************************************
1237 * NamedEscape [GDI32.@]
1239 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1240 INT cbOutput, LPSTR lpszOutData )
1242 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1243 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1244 lpszOutData);
1245 return 0;
1248 /*******************************************************************
1249 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1250 * GdiEntry13 [GDI32.@]
1252 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1254 static int warn_once;
1256 if (!warn_once++)
1257 FIXME("stub\n");
1258 return 0;