usp10: Free default_language items when freeing script cache.
[wine.git] / dlls / gdi32 / driver.c
blob70208fbd9e25ef81b38b390cc0d39d130ab83e10
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 /**********************************************************************
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( HMODULE *module_ret )
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) goto done;
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 (!module) display_driver_load_error = GetLastError();
127 if (!(driver = create_driver( module )))
129 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
130 FreeLibrary( module );
131 ExitProcess(1);
133 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
135 /* somebody beat us to it */
136 FreeLibrary( driver->module );
137 HeapFree( GetProcessHeap(), 0, driver );
139 done:
140 *module_ret = display_driver->module;
141 return display_driver->funcs;
145 /**********************************************************************
146 * DRIVER_load_driver
148 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name, HMODULE *module_ret )
150 HMODULE module;
151 struct graphics_driver *driver, *new_driver;
152 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
153 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
155 /* display driver is a special case */
156 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W ))
157 return get_display_driver( module_ret );
159 if ((module = GetModuleHandleW( name )))
161 if (display_driver && display_driver->module == module)
163 *module_ret = module;
164 return display_driver->funcs;
166 EnterCriticalSection( &driver_section );
167 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
169 if (driver->module == module) goto done;
171 LeaveCriticalSection( &driver_section );
174 if (!(module = LoadLibraryW( name ))) return NULL;
176 if (!(new_driver = create_driver( module )))
178 FreeLibrary( module );
179 return NULL;
182 /* check if someone else added it in the meantime */
183 EnterCriticalSection( &driver_section );
184 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
186 if (driver->module != module) continue;
187 FreeLibrary( module );
188 HeapFree( GetProcessHeap(), 0, new_driver );
189 goto done;
191 driver = new_driver;
192 list_add_head( &drivers, &driver->entry );
193 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
194 done:
195 *module_ret = driver->module;
196 LeaveCriticalSection( &driver_section );
197 return driver->funcs;
201 /***********************************************************************
202 * __wine_get_driver_module (GDI32.@)
204 HMODULE CDECL __wine_get_driver_module( HDC hdc )
206 DC *dc;
207 HMODULE ret = 0;
209 if ((dc = get_dc_ptr( hdc )))
211 ret = dc->module;
212 release_dc_ptr( dc );
213 if (!ret) SetLastError( display_driver_load_error );
215 else SetLastError( ERROR_INVALID_HANDLE );
216 return ret;
220 static INT nulldrv_AbortDoc( PHYSDEV dev )
222 return 0;
225 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
226 INT xstart, INT ystart, INT xend, INT yend )
228 return TRUE;
231 static BOOL nulldrv_Chord( 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_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
239 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
240 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
243 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
244 LPCWSTR output, const DEVMODEW *devmode )
246 assert(0); /* should never be called */
247 return FALSE;
250 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
252 assert(0); /* should never be called */
253 return TRUE;
256 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
258 return TRUE;
261 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
262 WORD cap, LPSTR output, DEVMODEA *devmode )
264 return -1;
267 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
269 return TRUE;
272 static INT nulldrv_EndDoc( PHYSDEV dev )
274 return 0;
277 static INT nulldrv_EndPage( PHYSDEV dev )
279 return 0;
282 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
284 return TRUE;
287 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
289 return -1;
292 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
293 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
295 return -1;
298 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
299 INT out_size, void *out_data )
301 return 0;
304 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
306 return TRUE;
309 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
311 return FALSE;
314 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
316 return FALSE;
319 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
321 return FALSE;
324 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
326 return DCB_RESET;
329 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
331 return FALSE;
334 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
336 return FALSE;
339 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
341 return FALSE;
344 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
346 switch (cap) /* return meaningful values for some entries */
348 case HORZRES: return 640;
349 case VERTRES: return 480;
350 case BITSPIXEL: return 1;
351 case PLANES: return 1;
352 case NUMCOLORS: return 2;
353 case ASPECTX: return 36;
354 case ASPECTY: return 36;
355 case ASPECTXY: return 51;
356 case LOGPIXELSX: return 72;
357 case LOGPIXELSY: return 72;
358 case SIZEPALETTE: return 2;
359 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
360 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
361 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
362 default: return 0;
366 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
368 SetLastError( ERROR_INVALID_PARAMETER );
369 return FALSE;
372 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
374 return FALSE;
377 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
379 return 0;
382 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
384 return GDI_ERROR;
387 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
388 DWORD size, LPVOID buffer, const MAT2 *mat )
390 return GDI_ERROR;
393 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
395 return FALSE;
398 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
399 struct bitblt_coords *src )
401 return ERROR_NOT_SUPPORTED;
404 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
406 return 0;
409 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
411 return 0;
414 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
416 return 0;
419 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
421 return DEFAULT_CHARSET;
424 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
426 return FALSE;
429 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
431 return FALSE;
434 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
436 INT ret = 0;
437 LOGFONTW font;
438 HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
440 if (GetObjectW( hfont, sizeof(font), &font ))
442 ret = strlenW( font.lfFaceName ) + 1;
443 if (name)
445 lstrcpynW( name, font.lfFaceName, size );
446 ret = min( size, ret );
449 return ret;
452 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
454 return FALSE;
457 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
459 return TRUE;
462 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
464 return TRUE;
467 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
469 return TRUE;
472 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
474 return TRUE;
477 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
478 INT xstart, INT ystart, INT xend, INT yend )
480 return TRUE;
483 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
485 return TRUE;
488 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
490 return TRUE;
493 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
495 INT counts[1] = { count };
497 return PolyPolygon( dev->hdc, points, counts, 1 );
500 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
502 DWORD counts[1] = { count };
504 if (count < 0) return FALSE;
505 return PolyPolyline( dev->hdc, points, counts, 1 );
508 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
509 const struct gdi_image_bits *bits, struct bitblt_coords *src,
510 struct bitblt_coords *dst, DWORD rop )
512 return ERROR_SUCCESS;
515 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
517 return 0;
520 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
522 return 0;
525 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
527 return TRUE;
530 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
532 return 0;
535 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
536 INT ell_width, INT ell_height )
538 return TRUE;
541 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
543 return bitmap;
546 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
548 return brush;
551 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
553 return palette;
556 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
558 return pen;
561 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
563 return dir;
566 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
568 return color;
571 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
573 return mode;
576 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
578 return DCB_RESET;
581 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
583 return color;
586 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
588 return color;
591 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
595 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
597 return layout;
600 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
602 SetLastError( ERROR_INVALID_PARAMETER );
603 return FALSE;
606 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
608 return flags;
611 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
613 return color;
616 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
618 return mode;
621 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
623 return rop;
626 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
628 return mode;
631 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
633 return mode;
636 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
638 return align;
641 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
643 return extra;
646 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
648 return color;
651 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
653 return TRUE;
656 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
658 return 0;
661 static INT nulldrv_StartPage( PHYSDEV dev )
663 return 1;
666 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
668 return FALSE;
671 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
673 return (void *)-1;
676 const struct gdi_dc_funcs null_driver =
678 nulldrv_AbortDoc, /* pAbortDoc */
679 nulldrv_AbortPath, /* pAbortPath */
680 nulldrv_AlphaBlend, /* pAlphaBlend */
681 nulldrv_AngleArc, /* pAngleArc */
682 nulldrv_Arc, /* pArc */
683 nulldrv_ArcTo, /* pArcTo */
684 nulldrv_BeginPath, /* pBeginPath */
685 nulldrv_BlendImage, /* pBlendImage */
686 nulldrv_Chord, /* pChord */
687 nulldrv_CloseFigure, /* pCloseFigure */
688 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
689 nulldrv_CreateDC, /* pCreateDC */
690 nulldrv_DeleteDC, /* pDeleteDC */
691 nulldrv_DeleteObject, /* pDeleteObject */
692 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
693 nulldrv_Ellipse, /* pEllipse */
694 nulldrv_EndDoc, /* pEndDoc */
695 nulldrv_EndPage, /* pEndPage */
696 nulldrv_EndPath, /* pEndPath */
697 nulldrv_EnumFonts, /* pEnumFonts */
698 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
699 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
700 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
701 nulldrv_ExtEscape, /* pExtEscape */
702 nulldrv_ExtFloodFill, /* pExtFloodFill */
703 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
704 nulldrv_ExtTextOut, /* pExtTextOut */
705 nulldrv_FillPath, /* pFillPath */
706 nulldrv_FillRgn, /* pFillRgn */
707 nulldrv_FlattenPath, /* pFlattenPath */
708 nulldrv_FontIsLinked, /* pFontIsLinked */
709 nulldrv_FrameRgn, /* pFrameRgn */
710 nulldrv_GdiComment, /* pGdiComment */
711 nulldrv_GdiRealizationInfo, /* pGdiRealizationInfo */
712 nulldrv_GetBoundsRect, /* pGetBoundsRect */
713 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
714 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
715 nulldrv_GetCharWidth, /* pGetCharWidth */
716 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
717 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
718 nulldrv_GetFontData, /* pGetFontData */
719 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
720 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
721 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
722 nulldrv_GetICMProfile, /* pGetICMProfile */
723 nulldrv_GetImage, /* pGetImage */
724 nulldrv_GetKerningPairs, /* pGetKerningPairs */
725 nulldrv_GetNearestColor, /* pGetNearestColor */
726 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
727 nulldrv_GetPixel, /* pGetPixel */
728 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
729 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
730 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
731 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
732 nulldrv_GetTextFace, /* pGetTextFace */
733 nulldrv_GetTextMetrics, /* pGetTextMetrics */
734 nulldrv_GradientFill, /* pGradientFill */
735 nulldrv_IntersectClipRect, /* pIntersectClipRect */
736 nulldrv_InvertRgn, /* pInvertRgn */
737 nulldrv_LineTo, /* pLineTo */
738 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
739 nulldrv_MoveTo, /* pMoveTo */
740 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
741 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
742 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
743 nulldrv_PaintRgn, /* pPaintRgn */
744 nulldrv_PatBlt, /* pPatBlt */
745 nulldrv_Pie, /* pPie */
746 nulldrv_PolyBezier, /* pPolyBezier */
747 nulldrv_PolyBezierTo, /* pPolyBezierTo */
748 nulldrv_PolyDraw, /* pPolyDraw */
749 nulldrv_PolyPolygon, /* pPolyPolygon */
750 nulldrv_PolyPolyline, /* pPolyPolyline */
751 nulldrv_Polygon, /* pPolygon */
752 nulldrv_Polyline, /* pPolyline */
753 nulldrv_PolylineTo, /* pPolylineTo */
754 nulldrv_PutImage, /* pPutImage */
755 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
756 nulldrv_RealizePalette, /* pRealizePalette */
757 nulldrv_Rectangle, /* pRectangle */
758 nulldrv_ResetDC, /* pResetDC */
759 nulldrv_RestoreDC, /* pRestoreDC */
760 nulldrv_RoundRect, /* pRoundRect */
761 nulldrv_SaveDC, /* pSaveDC */
762 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
763 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
764 nulldrv_SelectBitmap, /* pSelectBitmap */
765 nulldrv_SelectBrush, /* pSelectBrush */
766 nulldrv_SelectClipPath, /* pSelectClipPath */
767 nulldrv_SelectFont, /* pSelectFont */
768 nulldrv_SelectPalette, /* pSelectPalette */
769 nulldrv_SelectPen, /* pSelectPen */
770 nulldrv_SetArcDirection, /* pSetArcDirection */
771 nulldrv_SetBkColor, /* pSetBkColor */
772 nulldrv_SetBkMode, /* pSetBkMode */
773 nulldrv_SetBoundsRect, /* pSetBoundsRect */
774 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
775 nulldrv_SetDCPenColor, /* pSetDCPenColor */
776 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
777 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
778 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
779 nulldrv_SetLayout, /* pSetLayout */
780 nulldrv_SetMapMode, /* pSetMapMode */
781 nulldrv_SetMapperFlags, /* pSetMapperFlags */
782 nulldrv_SetPixel, /* pSetPixel */
783 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
784 nulldrv_SetROP2, /* pSetROP2 */
785 nulldrv_SetRelAbs, /* pSetRelAbs */
786 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
787 nulldrv_SetTextAlign, /* pSetTextAlign */
788 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
789 nulldrv_SetTextColor, /* pSetTextColor */
790 nulldrv_SetTextJustification, /* pSetTextJustification */
791 nulldrv_SetViewportExtEx, /* pSetViewportExt */
792 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
793 nulldrv_SetWindowExtEx, /* pSetWindowExt */
794 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
795 nulldrv_SetWorldTransform, /* pSetWorldTransform */
796 nulldrv_StartDoc, /* pStartDoc */
797 nulldrv_StartPage, /* pStartPage */
798 nulldrv_StretchBlt, /* pStretchBlt */
799 nulldrv_StretchDIBits, /* pStretchDIBits */
800 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
801 nulldrv_StrokePath, /* pStrokePath */
802 nulldrv_UnrealizePalette, /* pUnrealizePalette */
803 nulldrv_WidenPath, /* pWidenPath */
804 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
806 GDI_PRIORITY_NULL_DRV /* priority */
810 /*****************************************************************************
811 * DRIVER_GetDriverName
814 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
816 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
817 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
818 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
819 static const WCHAR empty_strW[] = { 0 };
820 WCHAR *p;
822 /* display is a special case */
823 if (!strcmpiW( device, displayW ) ||
824 !strcmpiW( device, display1W ))
826 lstrcpynW( driver, displayW, size );
827 return TRUE;
830 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
831 if(!size) {
832 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
833 return FALSE;
835 p = strchrW(driver, ',');
836 if(!p)
838 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
839 return FALSE;
841 *p = 0;
842 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
843 return TRUE;
847 /***********************************************************************
848 * GdiConvertToDevmodeW (GDI32.@)
850 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
852 DEVMODEW *dmW;
853 WORD dmW_size, dmA_size;
855 dmA_size = dmA->dmSize;
857 /* this is the minimal dmSize that XP accepts */
858 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
859 return NULL;
861 if (dmA_size > sizeof(DEVMODEA))
862 dmA_size = sizeof(DEVMODEA);
864 dmW_size = dmA_size + CCHDEVICENAME;
865 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
866 dmW_size += CCHFORMNAME;
868 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
869 if (!dmW) return NULL;
871 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
872 dmW->dmDeviceName, CCHDEVICENAME);
873 /* copy slightly more, to avoid long computations */
874 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
876 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
878 if (dmA->dmFields & DM_FORMNAME)
879 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
880 dmW->dmFormName, CCHFORMNAME);
881 else
882 dmW->dmFormName[0] = 0;
884 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
885 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
888 if (dmA->dmDriverExtra)
889 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
891 dmW->dmSize = dmW_size;
893 return dmW;
897 /*****************************************************************************
898 * @ [GDI32.100]
900 * This should thunk to 16-bit and simply call the proc with the given args.
902 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
903 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
905 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
906 return -1;
909 /*****************************************************************************
910 * @ [GDI32.101]
912 * This should load the correct driver for lpszDevice and calls this driver's
913 * ExtDeviceModePropSheet proc.
915 * Note: The driver calls a callback routine for each property sheet page; these
916 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
917 * The layout of this structure is:
919 * struct
921 * DWORD nPages;
922 * DWORD unknown;
923 * HPROPSHEETPAGE pages[10];
924 * };
926 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
927 LPCSTR lpszPort, LPVOID lpPropSheet )
929 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
930 return -1;
933 /*****************************************************************************
934 * @ [GDI32.102]
936 * This should load the correct driver for lpszDevice and call this driver's
937 * ExtDeviceMode proc.
939 * FIXME: convert ExtDeviceMode to unicode in the driver interface
941 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
942 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
943 LPSTR lpszPort, LPDEVMODEA lpdmInput,
944 LPSTR lpszProfile, DWORD fwMode )
946 WCHAR deviceW[300];
947 WCHAR bufW[300];
948 char buf[300];
949 HDC hdc;
950 DC *dc;
951 INT ret = -1;
953 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
954 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
956 if (!lpszDevice) return -1;
957 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
959 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
961 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
963 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
965 if ((dc = get_dc_ptr( hdc )))
967 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
968 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
969 lpdmInput, lpszProfile, fwMode );
970 release_dc_ptr( dc );
972 DeleteDC( hdc );
973 return ret;
976 /****************************************************************************
977 * @ [GDI32.103]
979 * This should load the correct driver for lpszDevice and calls this driver's
980 * AdvancedSetupDialog proc.
982 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
983 LPDEVMODEA devin, LPDEVMODEA devout )
985 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
986 return -1;
989 /*****************************************************************************
990 * @ [GDI32.104]
992 * This should load the correct driver for lpszDevice and calls this driver's
993 * DeviceCapabilities proc.
995 * FIXME: convert DeviceCapabilities to unicode in the driver interface
997 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
998 WORD fwCapability, LPSTR lpszOutput,
999 LPDEVMODEA lpdm )
1001 WCHAR deviceW[300];
1002 WCHAR bufW[300];
1003 char buf[300];
1004 HDC hdc;
1005 DC *dc;
1006 INT ret = -1;
1008 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1010 if (!lpszDevice) return -1;
1011 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1013 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1015 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1017 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1019 if ((dc = get_dc_ptr( hdc )))
1021 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1022 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1023 fwCapability, lpszOutput, lpdm );
1024 release_dc_ptr( dc );
1026 DeleteDC( hdc );
1027 return ret;
1031 /************************************************************************
1032 * Escape [GDI32.@]
1034 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1036 INT ret;
1037 POINT *pt;
1039 switch (escape)
1041 case ABORTDOC:
1042 return AbortDoc( hdc );
1044 case ENDDOC:
1045 return EndDoc( hdc );
1047 case GETPHYSPAGESIZE:
1048 pt = out_data;
1049 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1050 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1051 return 1;
1053 case GETPRINTINGOFFSET:
1054 pt = out_data;
1055 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1056 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1057 return 1;
1059 case GETSCALINGFACTOR:
1060 pt = out_data;
1061 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1062 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1063 return 1;
1065 case NEWFRAME:
1066 return EndPage( hdc );
1068 case SETABORTPROC:
1069 return SetAbortProc( hdc, (ABORTPROC)in_data );
1071 case STARTDOC:
1073 DOCINFOA doc;
1074 char *name = NULL;
1076 /* in_data may not be 0 terminated so we must copy it */
1077 if (in_data)
1079 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1080 memcpy( name, in_data, in_count );
1081 name[in_count] = 0;
1083 /* out_data is actually a pointer to the DocInfo structure and used as
1084 * a second input parameter */
1085 if (out_data) doc = *(DOCINFOA *)out_data;
1086 else
1088 doc.cbSize = sizeof(doc);
1089 doc.lpszOutput = NULL;
1090 doc.lpszDatatype = NULL;
1091 doc.fwType = 0;
1093 doc.lpszDocName = name;
1094 ret = StartDocA( hdc, &doc );
1095 HeapFree( GetProcessHeap(), 0, name );
1096 if (ret > 0) ret = StartPage( hdc );
1097 return ret;
1100 case QUERYESCSUPPORT:
1102 DWORD code;
1104 if (in_count < sizeof(SHORT)) return 0;
1105 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1106 switch (code)
1108 case ABORTDOC:
1109 case ENDDOC:
1110 case GETPHYSPAGESIZE:
1111 case GETPRINTINGOFFSET:
1112 case GETSCALINGFACTOR:
1113 case NEWFRAME:
1114 case QUERYESCSUPPORT:
1115 case SETABORTPROC:
1116 case STARTDOC:
1117 return TRUE;
1119 break;
1123 /* if not handled internally, pass it to the driver */
1124 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1128 /******************************************************************************
1129 * ExtEscape [GDI32.@]
1131 * Access capabilities of a particular device that are not available through GDI.
1133 * PARAMS
1134 * hdc [I] Handle to device context
1135 * nEscape [I] Escape function
1136 * cbInput [I] Number of bytes in input structure
1137 * lpszInData [I] Pointer to input structure
1138 * cbOutput [I] Number of bytes in output structure
1139 * lpszOutData [O] Pointer to output structure
1141 * RETURNS
1142 * Success: >0
1143 * Not implemented: 0
1144 * Failure: <0
1146 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1147 INT cbOutput, LPSTR lpszOutData )
1149 PHYSDEV physdev;
1150 INT ret;
1151 DC * dc = get_dc_ptr( hdc );
1153 if (!dc) return 0;
1154 update_dc( dc );
1155 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1156 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1157 release_dc_ptr( dc );
1158 return ret;
1162 /*******************************************************************
1163 * DrawEscape [GDI32.@]
1167 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1169 FIXME("DrawEscape, stub\n");
1170 return 0;
1173 /*******************************************************************
1174 * NamedEscape [GDI32.@]
1176 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1177 INT cbOutput, LPSTR lpszOutData )
1179 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1180 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1181 lpszOutData);
1182 return 0;
1185 /*******************************************************************
1186 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1187 * GdiEntry13 [GDI32.@]
1189 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1191 static int warn_once;
1193 if (!warn_once++)
1194 FIXME("stub\n");
1195 return 0;