winex11: Create contexts at initialization time to avoid the need for locks.
[wine/multimedia.git] / dlls / gdi32 / driver.c
blob4cf868f2455df329d08ef27b05ca887f6bfacb8e
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;
54 static CRITICAL_SECTION driver_section;
55 static CRITICAL_SECTION_DEBUG critsect_debug =
57 0, 0, &driver_section,
58 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
59 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
61 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
63 /**********************************************************************
64 * create_driver
66 * Allocate and fill the driver structure for a given module.
68 static struct graphics_driver *create_driver( HMODULE module )
70 static const struct gdi_dc_funcs empty_funcs;
71 const struct gdi_dc_funcs *funcs = NULL;
72 struct graphics_driver *driver;
74 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
75 driver->module = module;
77 if (module)
79 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
81 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
82 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
84 if (!funcs) funcs = &empty_funcs;
85 driver->funcs = funcs;
86 return driver;
90 /**********************************************************************
91 * get_display_driver
93 * Special case for loading the display driver: get the name from the config file
95 static const struct gdi_dc_funcs *get_display_driver(void)
97 struct graphics_driver *driver;
98 char buffer[MAX_PATH], libname[32], *name, *next;
99 HMODULE module = 0;
100 HKEY hkey;
102 if (display_driver) return display_driver->funcs; /* already loaded */
104 strcpy( buffer, "x11" ); /* default value */
105 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
106 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
108 DWORD type, count = sizeof(buffer);
109 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
110 RegCloseKey( hkey );
113 name = buffer;
114 while (name)
116 next = strchr( name, ',' );
117 if (next) *next++ = 0;
119 snprintf( libname, sizeof(libname), "wine%s.drv", name );
120 if ((module = LoadLibraryA( libname )) != 0) break;
121 name = next;
124 if (!(driver = create_driver( module )))
126 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
127 FreeLibrary( module );
128 ExitProcess(1);
130 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
132 /* somebody beat us to it */
133 FreeLibrary( driver->module );
134 HeapFree( GetProcessHeap(), 0, driver );
136 return display_driver->funcs;
140 /**********************************************************************
141 * DRIVER_load_driver
143 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
145 HMODULE module;
146 struct graphics_driver *driver, *new_driver;
147 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
148 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
150 /* display driver is a special case */
151 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
153 if ((module = GetModuleHandleW( name )))
155 if (display_driver && display_driver->module == module) return display_driver->funcs;
156 EnterCriticalSection( &driver_section );
157 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
159 if (driver->module == module) goto done;
161 LeaveCriticalSection( &driver_section );
164 if (!(module = LoadLibraryW( name ))) return NULL;
166 if (!(new_driver = create_driver( module )))
168 FreeLibrary( module );
169 return NULL;
172 /* check if someone else added it in the meantime */
173 EnterCriticalSection( &driver_section );
174 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
176 if (driver->module != module) continue;
177 FreeLibrary( module );
178 HeapFree( GetProcessHeap(), 0, new_driver );
179 goto done;
181 driver = new_driver;
182 list_add_head( &drivers, &driver->entry );
183 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
184 done:
185 LeaveCriticalSection( &driver_section );
186 return driver->funcs;
190 static INT nulldrv_AbortDoc( PHYSDEV dev )
192 return 0;
195 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
196 INT xstart, INT ystart, INT xend, INT yend )
198 return TRUE;
201 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
202 INT xstart, INT ystart, INT xend, INT yend )
204 return TRUE;
207 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
209 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
210 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
213 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
214 LPCWSTR output, const DEVMODEW *devmode )
216 assert(0); /* should never be called */
217 return FALSE;
220 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
222 assert(0); /* should never be called */
223 return TRUE;
226 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
228 return TRUE;
231 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
232 WORD cap, LPSTR output, DEVMODEA *devmode )
234 return -1;
237 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
239 return TRUE;
242 static INT nulldrv_EndDoc( PHYSDEV dev )
244 return 0;
247 static INT nulldrv_EndPage( PHYSDEV dev )
249 return 0;
252 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
254 return TRUE;
257 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
259 return -1;
262 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
263 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
265 return -1;
268 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
269 INT out_size, void *out_data )
271 return 0;
274 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
276 return TRUE;
279 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
281 return FALSE;
284 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
286 return FALSE;
289 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
291 return FALSE;
294 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
296 return DCB_RESET;
299 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
301 return FALSE;
304 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
306 return FALSE;
309 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
311 return FALSE;
314 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
316 switch (cap) /* return meaningful values for some entries */
318 case HORZRES: return 640;
319 case VERTRES: return 480;
320 case BITSPIXEL: return 1;
321 case PLANES: return 1;
322 case NUMCOLORS: return 2;
323 case ASPECTX: return 36;
324 case ASPECTY: return 36;
325 case ASPECTXY: return 51;
326 case LOGPIXELSX: return 72;
327 case LOGPIXELSY: return 72;
328 case SIZEPALETTE: return 2;
329 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
330 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
331 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
332 default: return 0;
336 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
338 SetLastError( ERROR_INVALID_PARAMETER );
339 return FALSE;
342 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
344 return FALSE;
347 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
349 return 0;
352 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
354 return GDI_ERROR;
357 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
358 DWORD size, LPVOID buffer, const MAT2 *mat )
360 return GDI_ERROR;
363 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
365 return FALSE;
368 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
369 struct bitblt_coords *src )
371 return ERROR_NOT_SUPPORTED;
374 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
376 return 0;
379 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
381 return 0;
384 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
386 return 0;
389 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
391 return DEFAULT_CHARSET;
394 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
395 INT *fit, INT *dx, SIZE *size )
397 return FALSE;
400 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT max_ext,
401 INT *fit, INT *dx, SIZE *size )
403 return FALSE;
406 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
408 INT ret = 0;
409 LOGFONTW font;
410 HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
412 if (GetObjectW( hfont, sizeof(font), &font ))
414 ret = strlenW( font.lfFaceName ) + 1;
415 if (name)
417 lstrcpynW( name, font.lfFaceName, size );
418 ret = min( size, ret );
421 return ret;
424 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
426 return FALSE;
429 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
431 return TRUE;
434 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
436 return TRUE;
439 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
441 return TRUE;
444 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
446 return TRUE;
449 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
450 INT xstart, INT ystart, INT xend, INT yend )
452 return TRUE;
455 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
457 return TRUE;
460 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
462 return TRUE;
465 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
467 INT counts[1] = { count };
469 return PolyPolygon( dev->hdc, points, counts, 1 );
472 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
474 DWORD counts[1] = { count };
476 if (count < 0) return FALSE;
477 return PolyPolyline( dev->hdc, points, counts, 1 );
480 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
481 const struct gdi_image_bits *bits, struct bitblt_coords *src,
482 struct bitblt_coords *dst, DWORD rop )
484 return ERROR_SUCCESS;
487 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
489 return 0;
492 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
494 return 0;
497 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
499 return TRUE;
502 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
504 return 0;
507 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
508 INT ell_width, INT ell_height )
510 return TRUE;
513 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
515 return bitmap;
518 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
520 return brush;
523 static HFONT nulldrv_SelectFont( PHYSDEV dev, HFONT font )
525 return 0;
528 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
530 return palette;
533 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
535 return pen;
538 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
540 return dir;
543 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
545 return color;
548 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
550 return mode;
553 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
555 return DCB_RESET;
558 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
560 return color;
563 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
565 return color;
568 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
572 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
574 return layout;
577 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
579 SetLastError( ERROR_INVALID_PARAMETER );
580 return FALSE;
583 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
585 return flags;
588 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
590 return color;
593 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
595 return mode;
598 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
600 return rop;
603 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
605 return mode;
608 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
610 return mode;
613 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
615 return align;
618 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
620 return extra;
623 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
625 return color;
628 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
630 return TRUE;
633 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
635 return 0;
638 static INT nulldrv_StartPage( PHYSDEV dev )
640 return 1;
643 static BOOL nulldrv_SwapBuffers( PHYSDEV dev )
645 return TRUE;
648 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
650 return FALSE;
653 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
655 return (void *)-1;
658 const struct gdi_dc_funcs null_driver =
660 nulldrv_AbortDoc, /* pAbortDoc */
661 nulldrv_AbortPath, /* pAbortPath */
662 nulldrv_AlphaBlend, /* pAlphaBlend */
663 nulldrv_AngleArc, /* pAngleArc */
664 nulldrv_Arc, /* pArc */
665 nulldrv_ArcTo, /* pArcTo */
666 nulldrv_BeginPath, /* pBeginPath */
667 nulldrv_BlendImage, /* pBlendImage */
668 nulldrv_Chord, /* pChord */
669 nulldrv_CloseFigure, /* pCloseFigure */
670 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
671 nulldrv_CreateDC, /* pCreateDC */
672 nulldrv_DeleteDC, /* pDeleteDC */
673 nulldrv_DeleteObject, /* pDeleteObject */
674 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
675 nulldrv_Ellipse, /* pEllipse */
676 nulldrv_EndDoc, /* pEndDoc */
677 nulldrv_EndPage, /* pEndPage */
678 nulldrv_EndPath, /* pEndPath */
679 nulldrv_EnumFonts, /* pEnumFonts */
680 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
681 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
682 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
683 nulldrv_ExtEscape, /* pExtEscape */
684 nulldrv_ExtFloodFill, /* pExtFloodFill */
685 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
686 nulldrv_ExtTextOut, /* pExtTextOut */
687 nulldrv_FillPath, /* pFillPath */
688 nulldrv_FillRgn, /* pFillRgn */
689 nulldrv_FlattenPath, /* pFlattenPath */
690 nulldrv_FontIsLinked, /* pFontIsLinked */
691 nulldrv_FrameRgn, /* pFrameRgn */
692 nulldrv_GdiComment, /* pGdiComment */
693 nulldrv_GdiRealizationInfo, /* pGdiRealizationInfo */
694 nulldrv_GetBoundsRect, /* pGetBoundsRect */
695 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
696 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
697 nulldrv_GetCharWidth, /* pGetCharWidth */
698 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
699 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
700 nulldrv_GetFontData, /* pGetFontData */
701 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
702 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
703 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
704 nulldrv_GetICMProfile, /* pGetICMProfile */
705 nulldrv_GetImage, /* pGetImage */
706 nulldrv_GetKerningPairs, /* pGetKerningPairs */
707 nulldrv_GetNearestColor, /* pGetNearestColor */
708 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
709 nulldrv_GetPixel, /* pGetPixel */
710 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
711 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
712 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
713 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
714 nulldrv_GetTextFace, /* pGetTextFace */
715 nulldrv_GetTextMetrics, /* pGetTextMetrics */
716 nulldrv_GradientFill, /* pGradientFill */
717 nulldrv_IntersectClipRect, /* pIntersectClipRect */
718 nulldrv_InvertRgn, /* pInvertRgn */
719 nulldrv_LineTo, /* pLineTo */
720 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
721 nulldrv_MoveTo, /* pMoveTo */
722 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
723 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
724 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
725 nulldrv_PaintRgn, /* pPaintRgn */
726 nulldrv_PatBlt, /* pPatBlt */
727 nulldrv_Pie, /* pPie */
728 nulldrv_PolyBezier, /* pPolyBezier */
729 nulldrv_PolyBezierTo, /* pPolyBezierTo */
730 nulldrv_PolyDraw, /* pPolyDraw */
731 nulldrv_PolyPolygon, /* pPolyPolygon */
732 nulldrv_PolyPolyline, /* pPolyPolyline */
733 nulldrv_Polygon, /* pPolygon */
734 nulldrv_Polyline, /* pPolyline */
735 nulldrv_PolylineTo, /* pPolylineTo */
736 nulldrv_PutImage, /* pPutImage */
737 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
738 nulldrv_RealizePalette, /* pRealizePalette */
739 nulldrv_Rectangle, /* pRectangle */
740 nulldrv_ResetDC, /* pResetDC */
741 nulldrv_RestoreDC, /* pRestoreDC */
742 nulldrv_RoundRect, /* pRoundRect */
743 nulldrv_SaveDC, /* pSaveDC */
744 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
745 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
746 nulldrv_SelectBitmap, /* pSelectBitmap */
747 nulldrv_SelectBrush, /* pSelectBrush */
748 nulldrv_SelectClipPath, /* pSelectClipPath */
749 nulldrv_SelectFont, /* pSelectFont */
750 nulldrv_SelectPalette, /* pSelectPalette */
751 nulldrv_SelectPen, /* pSelectPen */
752 nulldrv_SetArcDirection, /* pSetArcDirection */
753 nulldrv_SetBkColor, /* pSetBkColor */
754 nulldrv_SetBkMode, /* pSetBkMode */
755 nulldrv_SetBoundsRect, /* pSetBoundsRect */
756 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
757 nulldrv_SetDCPenColor, /* pSetDCPenColor */
758 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
759 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
760 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
761 nulldrv_SetLayout, /* pSetLayout */
762 nulldrv_SetMapMode, /* pSetMapMode */
763 nulldrv_SetMapperFlags, /* pSetMapperFlags */
764 nulldrv_SetPixel, /* pSetPixel */
765 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
766 nulldrv_SetROP2, /* pSetROP2 */
767 nulldrv_SetRelAbs, /* pSetRelAbs */
768 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
769 nulldrv_SetTextAlign, /* pSetTextAlign */
770 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
771 nulldrv_SetTextColor, /* pSetTextColor */
772 nulldrv_SetTextJustification, /* pSetTextJustification */
773 nulldrv_SetViewportExtEx, /* pSetViewportExt */
774 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
775 nulldrv_SetWindowExtEx, /* pSetWindowExt */
776 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
777 nulldrv_SetWorldTransform, /* pSetWorldTransform */
778 nulldrv_StartDoc, /* pStartDoc */
779 nulldrv_StartPage, /* pStartPage */
780 nulldrv_StretchBlt, /* pStretchBlt */
781 nulldrv_StretchDIBits, /* pStretchDIBits */
782 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
783 nulldrv_StrokePath, /* pStrokePath */
784 nulldrv_SwapBuffers, /* pSwapBuffers */
785 nulldrv_UnrealizePalette, /* pUnrealizePalette */
786 nulldrv_WidenPath, /* pWidenPath */
787 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
789 GDI_PRIORITY_NULL_DRV /* priority */
793 /*****************************************************************************
794 * DRIVER_GetDriverName
797 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
799 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
800 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
801 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
802 static const WCHAR empty_strW[] = { 0 };
803 WCHAR *p;
805 /* display is a special case */
806 if (!strcmpiW( device, displayW ) ||
807 !strcmpiW( device, display1W ))
809 lstrcpynW( driver, displayW, size );
810 return TRUE;
813 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
814 if(!size) {
815 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
816 return FALSE;
818 p = strchrW(driver, ',');
819 if(!p)
821 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
822 return FALSE;
824 *p = 0;
825 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
826 return TRUE;
830 /***********************************************************************
831 * GdiConvertToDevmodeW (GDI32.@)
833 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
835 DEVMODEW *dmW;
836 WORD dmW_size, dmA_size;
838 dmA_size = dmA->dmSize;
840 /* this is the minimal dmSize that XP accepts */
841 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
842 return NULL;
844 if (dmA_size > sizeof(DEVMODEA))
845 dmA_size = sizeof(DEVMODEA);
847 dmW_size = dmA_size + CCHDEVICENAME;
848 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
849 dmW_size += CCHFORMNAME;
851 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
852 if (!dmW) return NULL;
854 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
855 dmW->dmDeviceName, CCHDEVICENAME);
856 /* copy slightly more, to avoid long computations */
857 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
859 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
861 if (dmA->dmFields & DM_FORMNAME)
862 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
863 dmW->dmFormName, CCHFORMNAME);
864 else
865 dmW->dmFormName[0] = 0;
867 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
868 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
871 if (dmA->dmDriverExtra)
872 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
874 dmW->dmSize = dmW_size;
876 return dmW;
880 /*****************************************************************************
881 * @ [GDI32.100]
883 * This should thunk to 16-bit and simply call the proc with the given args.
885 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
886 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
888 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
889 return -1;
892 /*****************************************************************************
893 * @ [GDI32.101]
895 * This should load the correct driver for lpszDevice and calls this driver's
896 * ExtDeviceModePropSheet proc.
898 * Note: The driver calls a callback routine for each property sheet page; these
899 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
900 * The layout of this structure is:
902 * struct
904 * DWORD nPages;
905 * DWORD unknown;
906 * HPROPSHEETPAGE pages[10];
907 * };
909 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
910 LPCSTR lpszPort, LPVOID lpPropSheet )
912 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
913 return -1;
916 /*****************************************************************************
917 * @ [GDI32.102]
919 * This should load the correct driver for lpszDevice and call this driver's
920 * ExtDeviceMode proc.
922 * FIXME: convert ExtDeviceMode to unicode in the driver interface
924 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
925 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
926 LPSTR lpszPort, LPDEVMODEA lpdmInput,
927 LPSTR lpszProfile, DWORD fwMode )
929 WCHAR deviceW[300];
930 WCHAR bufW[300];
931 char buf[300];
932 HDC hdc;
933 DC *dc;
934 INT ret = -1;
936 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
937 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
939 if (!lpszDevice) return -1;
940 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
942 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
944 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
946 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
948 if ((dc = get_dc_ptr( hdc )))
950 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
951 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
952 lpdmInput, lpszProfile, fwMode );
953 release_dc_ptr( dc );
955 DeleteDC( hdc );
956 return ret;
959 /****************************************************************************
960 * @ [GDI32.103]
962 * This should load the correct driver for lpszDevice and calls this driver's
963 * AdvancedSetupDialog proc.
965 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
966 LPDEVMODEA devin, LPDEVMODEA devout )
968 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
969 return -1;
972 /*****************************************************************************
973 * @ [GDI32.104]
975 * This should load the correct driver for lpszDevice and calls this driver's
976 * DeviceCapabilities proc.
978 * FIXME: convert DeviceCapabilities to unicode in the driver interface
980 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
981 WORD fwCapability, LPSTR lpszOutput,
982 LPDEVMODEA lpdm )
984 WCHAR deviceW[300];
985 WCHAR bufW[300];
986 char buf[300];
987 HDC hdc;
988 DC *dc;
989 INT ret = -1;
991 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
993 if (!lpszDevice) return -1;
994 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
996 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
998 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1000 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1002 if ((dc = get_dc_ptr( hdc )))
1004 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1005 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1006 fwCapability, lpszOutput, lpdm );
1007 release_dc_ptr( dc );
1009 DeleteDC( hdc );
1010 return ret;
1014 /************************************************************************
1015 * Escape [GDI32.@]
1017 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1019 INT ret;
1020 POINT *pt;
1022 switch (escape)
1024 case ABORTDOC:
1025 return AbortDoc( hdc );
1027 case ENDDOC:
1028 return EndDoc( hdc );
1030 case GETPHYSPAGESIZE:
1031 pt = out_data;
1032 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1033 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1034 return 1;
1036 case GETPRINTINGOFFSET:
1037 pt = out_data;
1038 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1039 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1040 return 1;
1042 case GETSCALINGFACTOR:
1043 pt = out_data;
1044 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1045 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1046 return 1;
1048 case NEWFRAME:
1049 return EndPage( hdc );
1051 case SETABORTPROC:
1052 return SetAbortProc( hdc, (ABORTPROC)in_data );
1054 case STARTDOC:
1056 DOCINFOA doc;
1057 char *name = NULL;
1059 /* in_data may not be 0 terminated so we must copy it */
1060 if (in_data)
1062 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1063 memcpy( name, in_data, in_count );
1064 name[in_count] = 0;
1066 /* out_data is actually a pointer to the DocInfo structure and used as
1067 * a second input parameter */
1068 if (out_data) doc = *(DOCINFOA *)out_data;
1069 else
1071 doc.cbSize = sizeof(doc);
1072 doc.lpszOutput = NULL;
1073 doc.lpszDatatype = NULL;
1074 doc.fwType = 0;
1076 doc.lpszDocName = name;
1077 ret = StartDocA( hdc, &doc );
1078 HeapFree( GetProcessHeap(), 0, name );
1079 if (ret > 0) ret = StartPage( hdc );
1080 return ret;
1083 case QUERYESCSUPPORT:
1085 const INT *ptr = (const INT *)in_data;
1086 if (in_count < sizeof(INT)) return 0;
1087 switch(*ptr)
1089 case ABORTDOC:
1090 case ENDDOC:
1091 case GETPHYSPAGESIZE:
1092 case GETPRINTINGOFFSET:
1093 case GETSCALINGFACTOR:
1094 case NEWFRAME:
1095 case QUERYESCSUPPORT:
1096 case SETABORTPROC:
1097 case STARTDOC:
1098 return TRUE;
1100 break;
1104 /* if not handled internally, pass it to the driver */
1105 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1109 /******************************************************************************
1110 * ExtEscape [GDI32.@]
1112 * Access capabilities of a particular device that are not available through GDI.
1114 * PARAMS
1115 * hdc [I] Handle to device context
1116 * nEscape [I] Escape function
1117 * cbInput [I] Number of bytes in input structure
1118 * lpszInData [I] Pointer to input structure
1119 * cbOutput [I] Number of bytes in output structure
1120 * lpszOutData [O] Pointer to output structure
1122 * RETURNS
1123 * Success: >0
1124 * Not implemented: 0
1125 * Failure: <0
1127 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1128 INT cbOutput, LPSTR lpszOutData )
1130 INT ret = 0;
1131 DC * dc = get_dc_ptr( hdc );
1133 if (dc)
1135 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1136 update_dc( dc );
1137 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1138 release_dc_ptr( dc );
1140 return ret;
1144 /*******************************************************************
1145 * DrawEscape [GDI32.@]
1149 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1151 FIXME("DrawEscape, stub\n");
1152 return 0;
1155 /*******************************************************************
1156 * NamedEscape [GDI32.@]
1158 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1159 INT cbOutput, LPSTR lpszOutData )
1161 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1162 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1163 lpszOutData);
1164 return 0;
1167 /*******************************************************************
1168 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1169 * GdiEntry13 [GDI32.@]
1171 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1173 static int warn_once;
1175 if (!warn_once++)
1176 FIXME("stub\n");
1177 return 0;