d3d8/tests: Add helpers to avoid multiple readbacks of the render target surface.
[wine.git] / dlls / gdi32 / driver.c
bloba6b138cab415672b51330bbc5a82979a715485f6
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 "ddrawgdi.h"
32 #include "wine/winbase16.h"
33 #include "winternl.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 if (!display_driver)
99 HMODULE user32 = LoadLibraryA( "user32.dll" );
100 HWND (WINAPI *pGetDesktopWindow)(void) = (void *)GetProcAddress( user32, "GetDesktopWindow" );
102 if (!pGetDesktopWindow() || !display_driver)
104 WARN( "failed to load the display driver, falling back to null driver\n" );
105 __wine_set_display_driver( 0 );
108 return display_driver->funcs;
112 /**********************************************************************
113 * DRIVER_load_driver
115 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
117 HMODULE module;
118 struct graphics_driver *driver, *new_driver;
119 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
120 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
122 /* display driver is a special case */
123 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
125 if ((module = GetModuleHandleW( name )))
127 if (display_driver && display_driver->module == module) return display_driver->funcs;
129 EnterCriticalSection( &driver_section );
130 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
132 if (driver->module == module) goto done;
134 LeaveCriticalSection( &driver_section );
137 if (!(module = LoadLibraryW( name ))) return NULL;
139 if (!(new_driver = create_driver( module )))
141 FreeLibrary( module );
142 return NULL;
145 /* check if someone else added it in the meantime */
146 EnterCriticalSection( &driver_section );
147 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
149 if (driver->module != module) continue;
150 FreeLibrary( module );
151 HeapFree( GetProcessHeap(), 0, new_driver );
152 goto done;
154 driver = new_driver;
155 list_add_head( &drivers, &driver->entry );
156 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
157 done:
158 LeaveCriticalSection( &driver_section );
159 return driver->funcs;
163 /***********************************************************************
164 * __wine_set_display_driver (GDI32.@)
166 void CDECL __wine_set_display_driver( HMODULE module )
168 struct graphics_driver *driver;
170 if (!(driver = create_driver( module )))
172 ERR( "Could not create graphics driver\n" );
173 ExitProcess(1);
175 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
176 HeapFree( GetProcessHeap(), 0, driver );
180 static INT nulldrv_AbortDoc( PHYSDEV dev )
182 return 0;
185 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
186 INT xstart, INT ystart, INT xend, INT yend )
188 return TRUE;
191 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
192 INT xstart, INT ystart, INT xend, INT yend )
194 return TRUE;
197 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
199 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
200 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
203 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
204 LPCWSTR output, const DEVMODEW *devmode )
206 assert(0); /* should never be called */
207 return FALSE;
210 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
212 assert(0); /* should never be called */
213 return TRUE;
216 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
218 return TRUE;
221 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
222 WORD cap, LPSTR output, DEVMODEA *devmode )
224 return -1;
227 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
229 return TRUE;
232 static INT nulldrv_EndDoc( PHYSDEV dev )
234 return 0;
237 static INT nulldrv_EndPage( PHYSDEV dev )
239 return 0;
242 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
244 return TRUE;
247 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
249 return -1;
252 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
253 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
255 return -1;
258 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
259 INT out_size, void *out_data )
261 return 0;
264 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
266 return TRUE;
269 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
271 return FALSE;
274 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
276 return FALSE;
279 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
281 return DCB_RESET;
284 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
286 return FALSE;
289 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
291 return FALSE;
294 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
296 return FALSE;
299 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
301 switch (cap) /* return meaningful values for some entries */
303 case HORZRES: return 640;
304 case VERTRES: return 480;
305 case BITSPIXEL: return 1;
306 case PLANES: return 1;
307 case NUMCOLORS: return 2;
308 case ASPECTX: return 36;
309 case ASPECTY: return 36;
310 case ASPECTXY: return 51;
311 case LOGPIXELSX: return 72;
312 case LOGPIXELSY: return 72;
313 case SIZEPALETTE: return 2;
314 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
315 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
316 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
317 default: return 0;
321 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
323 SetLastError( ERROR_INVALID_PARAMETER );
324 return FALSE;
327 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
329 return FALSE;
332 static BOOL nulldrv_GetFontRealizationInfo( PHYSDEV dev, void *info )
334 return FALSE;
337 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
339 return 0;
342 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
344 return GDI_ERROR;
347 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
348 DWORD size, LPVOID buffer, const MAT2 *mat )
350 return GDI_ERROR;
353 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
355 return FALSE;
358 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
359 struct bitblt_coords *src )
361 return ERROR_NOT_SUPPORTED;
364 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
366 return 0;
369 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
371 return 0;
374 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
376 return 0;
379 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
381 return DEFAULT_CHARSET;
384 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
386 return FALSE;
389 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
391 return FALSE;
394 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
396 INT ret = 0;
397 LOGFONTW font;
398 HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
400 if (GetObjectW( hfont, sizeof(font), &font ))
402 ret = strlenW( font.lfFaceName ) + 1;
403 if (name)
405 lstrcpynW( name, font.lfFaceName, size );
406 ret = min( size, ret );
409 return ret;
412 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
414 return FALSE;
417 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
419 return TRUE;
422 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
424 return TRUE;
427 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
429 return TRUE;
432 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
434 return TRUE;
437 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
438 INT xstart, INT ystart, INT xend, INT yend )
440 return TRUE;
443 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
445 return TRUE;
448 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
450 return TRUE;
453 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
455 INT counts[1] = { count };
457 return PolyPolygon( dev->hdc, points, counts, 1 );
460 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
462 DWORD counts[1] = { count };
464 if (count < 0) return FALSE;
465 return PolyPolyline( dev->hdc, points, counts, 1 );
468 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
469 const struct gdi_image_bits *bits, struct bitblt_coords *src,
470 struct bitblt_coords *dst, DWORD rop )
472 return ERROR_SUCCESS;
475 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
477 return 0;
480 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
482 return 0;
485 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
487 return TRUE;
490 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
492 return 0;
495 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
496 INT ell_width, INT ell_height )
498 return TRUE;
501 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
503 return bitmap;
506 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
508 return brush;
511 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
513 return palette;
516 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
518 return pen;
521 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
523 return dir;
526 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
528 return color;
531 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
533 return mode;
536 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
538 return DCB_RESET;
541 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
543 return color;
546 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
548 return color;
551 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
555 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
557 return layout;
560 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
562 SetLastError( ERROR_INVALID_PARAMETER );
563 return FALSE;
566 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
568 return flags;
571 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
573 return color;
576 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
578 return mode;
581 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
583 return rop;
586 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
588 return mode;
591 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
593 return mode;
596 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
598 return align;
601 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
603 return extra;
606 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
608 return color;
611 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
613 return TRUE;
616 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
618 return 0;
621 static INT nulldrv_StartPage( PHYSDEV dev )
623 return 1;
626 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
628 return FALSE;
631 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
633 return (void *)-1;
636 const struct gdi_dc_funcs null_driver =
638 nulldrv_AbortDoc, /* pAbortDoc */
639 nulldrv_AbortPath, /* pAbortPath */
640 nulldrv_AlphaBlend, /* pAlphaBlend */
641 nulldrv_AngleArc, /* pAngleArc */
642 nulldrv_Arc, /* pArc */
643 nulldrv_ArcTo, /* pArcTo */
644 nulldrv_BeginPath, /* pBeginPath */
645 nulldrv_BlendImage, /* pBlendImage */
646 nulldrv_Chord, /* pChord */
647 nulldrv_CloseFigure, /* pCloseFigure */
648 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
649 nulldrv_CreateDC, /* pCreateDC */
650 nulldrv_DeleteDC, /* pDeleteDC */
651 nulldrv_DeleteObject, /* pDeleteObject */
652 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
653 nulldrv_Ellipse, /* pEllipse */
654 nulldrv_EndDoc, /* pEndDoc */
655 nulldrv_EndPage, /* pEndPage */
656 nulldrv_EndPath, /* pEndPath */
657 nulldrv_EnumFonts, /* pEnumFonts */
658 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
659 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
660 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
661 nulldrv_ExtEscape, /* pExtEscape */
662 nulldrv_ExtFloodFill, /* pExtFloodFill */
663 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
664 nulldrv_ExtTextOut, /* pExtTextOut */
665 nulldrv_FillPath, /* pFillPath */
666 nulldrv_FillRgn, /* pFillRgn */
667 nulldrv_FlattenPath, /* pFlattenPath */
668 nulldrv_FontIsLinked, /* pFontIsLinked */
669 nulldrv_FrameRgn, /* pFrameRgn */
670 nulldrv_GdiComment, /* pGdiComment */
671 nulldrv_GetBoundsRect, /* pGetBoundsRect */
672 nulldrv_GetCharABCWidths, /* pGetCharABCWidths */
673 nulldrv_GetCharABCWidthsI, /* pGetCharABCWidthsI */
674 nulldrv_GetCharWidth, /* pGetCharWidth */
675 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
676 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
677 nulldrv_GetFontData, /* pGetFontData */
678 nulldrv_GetFontRealizationInfo, /* pGetFontRealizationInfo */
679 nulldrv_GetFontUnicodeRanges, /* pGetFontUnicodeRanges */
680 nulldrv_GetGlyphIndices, /* pGetGlyphIndices */
681 nulldrv_GetGlyphOutline, /* pGetGlyphOutline */
682 nulldrv_GetICMProfile, /* pGetICMProfile */
683 nulldrv_GetImage, /* pGetImage */
684 nulldrv_GetKerningPairs, /* pGetKerningPairs */
685 nulldrv_GetNearestColor, /* pGetNearestColor */
686 nulldrv_GetOutlineTextMetrics, /* pGetOutlineTextMetrics */
687 nulldrv_GetPixel, /* pGetPixel */
688 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
689 nulldrv_GetTextCharsetInfo, /* pGetTextCharsetInfo */
690 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
691 nulldrv_GetTextExtentExPointI, /* pGetTextExtentExPointI */
692 nulldrv_GetTextFace, /* pGetTextFace */
693 nulldrv_GetTextMetrics, /* pGetTextMetrics */
694 nulldrv_GradientFill, /* pGradientFill */
695 nulldrv_IntersectClipRect, /* pIntersectClipRect */
696 nulldrv_InvertRgn, /* pInvertRgn */
697 nulldrv_LineTo, /* pLineTo */
698 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
699 nulldrv_MoveTo, /* pMoveTo */
700 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
701 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
702 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
703 nulldrv_PaintRgn, /* pPaintRgn */
704 nulldrv_PatBlt, /* pPatBlt */
705 nulldrv_Pie, /* pPie */
706 nulldrv_PolyBezier, /* pPolyBezier */
707 nulldrv_PolyBezierTo, /* pPolyBezierTo */
708 nulldrv_PolyDraw, /* pPolyDraw */
709 nulldrv_PolyPolygon, /* pPolyPolygon */
710 nulldrv_PolyPolyline, /* pPolyPolyline */
711 nulldrv_Polygon, /* pPolygon */
712 nulldrv_Polyline, /* pPolyline */
713 nulldrv_PolylineTo, /* pPolylineTo */
714 nulldrv_PutImage, /* pPutImage */
715 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
716 nulldrv_RealizePalette, /* pRealizePalette */
717 nulldrv_Rectangle, /* pRectangle */
718 nulldrv_ResetDC, /* pResetDC */
719 nulldrv_RestoreDC, /* pRestoreDC */
720 nulldrv_RoundRect, /* pRoundRect */
721 nulldrv_SaveDC, /* pSaveDC */
722 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
723 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
724 nulldrv_SelectBitmap, /* pSelectBitmap */
725 nulldrv_SelectBrush, /* pSelectBrush */
726 nulldrv_SelectClipPath, /* pSelectClipPath */
727 nulldrv_SelectFont, /* pSelectFont */
728 nulldrv_SelectPalette, /* pSelectPalette */
729 nulldrv_SelectPen, /* pSelectPen */
730 nulldrv_SetArcDirection, /* pSetArcDirection */
731 nulldrv_SetBkColor, /* pSetBkColor */
732 nulldrv_SetBkMode, /* pSetBkMode */
733 nulldrv_SetBoundsRect, /* pSetBoundsRect */
734 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
735 nulldrv_SetDCPenColor, /* pSetDCPenColor */
736 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
737 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
738 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
739 nulldrv_SetLayout, /* pSetLayout */
740 nulldrv_SetMapMode, /* pSetMapMode */
741 nulldrv_SetMapperFlags, /* pSetMapperFlags */
742 nulldrv_SetPixel, /* pSetPixel */
743 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
744 nulldrv_SetROP2, /* pSetROP2 */
745 nulldrv_SetRelAbs, /* pSetRelAbs */
746 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
747 nulldrv_SetTextAlign, /* pSetTextAlign */
748 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
749 nulldrv_SetTextColor, /* pSetTextColor */
750 nulldrv_SetTextJustification, /* pSetTextJustification */
751 nulldrv_SetViewportExtEx, /* pSetViewportExt */
752 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
753 nulldrv_SetWindowExtEx, /* pSetWindowExt */
754 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
755 nulldrv_SetWorldTransform, /* pSetWorldTransform */
756 nulldrv_StartDoc, /* pStartDoc */
757 nulldrv_StartPage, /* pStartPage */
758 nulldrv_StretchBlt, /* pStretchBlt */
759 nulldrv_StretchDIBits, /* pStretchDIBits */
760 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
761 nulldrv_StrokePath, /* pStrokePath */
762 nulldrv_UnrealizePalette, /* pUnrealizePalette */
763 nulldrv_WidenPath, /* pWidenPath */
764 nulldrv_wine_get_wgl_driver, /* wine_get_wgl_driver */
766 GDI_PRIORITY_NULL_DRV /* priority */
770 /*****************************************************************************
771 * DRIVER_GetDriverName
774 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
776 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
777 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
778 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
779 static const WCHAR empty_strW[] = { 0 };
780 WCHAR *p;
782 /* display is a special case */
783 if (!strcmpiW( device, displayW ) ||
784 !strcmpiW( device, display1W ))
786 lstrcpynW( driver, displayW, size );
787 return TRUE;
790 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
791 if(!size) {
792 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
793 return FALSE;
795 p = strchrW(driver, ',');
796 if(!p)
798 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
799 return FALSE;
801 *p = 0;
802 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
803 return TRUE;
807 /***********************************************************************
808 * GdiConvertToDevmodeW (GDI32.@)
810 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
812 DEVMODEW *dmW;
813 WORD dmW_size, dmA_size;
815 dmA_size = dmA->dmSize;
817 /* this is the minimal dmSize that XP accepts */
818 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
819 return NULL;
821 if (dmA_size > sizeof(DEVMODEA))
822 dmA_size = sizeof(DEVMODEA);
824 dmW_size = dmA_size + CCHDEVICENAME;
825 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
826 dmW_size += CCHFORMNAME;
828 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
829 if (!dmW) return NULL;
831 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
832 dmW->dmDeviceName, CCHDEVICENAME);
833 /* copy slightly more, to avoid long computations */
834 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
836 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
838 if (dmA->dmFields & DM_FORMNAME)
839 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
840 dmW->dmFormName, CCHFORMNAME);
841 else
842 dmW->dmFormName[0] = 0;
844 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
845 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
848 if (dmA->dmDriverExtra)
849 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
851 dmW->dmSize = dmW_size;
853 return dmW;
857 /*****************************************************************************
858 * @ [GDI32.100]
860 * This should thunk to 16-bit and simply call the proc with the given args.
862 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
863 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
865 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
866 return -1;
869 /*****************************************************************************
870 * @ [GDI32.101]
872 * This should load the correct driver for lpszDevice and calls this driver's
873 * ExtDeviceModePropSheet proc.
875 * Note: The driver calls a callback routine for each property sheet page; these
876 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
877 * The layout of this structure is:
879 * struct
881 * DWORD nPages;
882 * DWORD unknown;
883 * HPROPSHEETPAGE pages[10];
884 * };
886 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
887 LPCSTR lpszPort, LPVOID lpPropSheet )
889 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
890 return -1;
893 /*****************************************************************************
894 * @ [GDI32.102]
896 * This should load the correct driver for lpszDevice and call this driver's
897 * ExtDeviceMode proc.
899 * FIXME: convert ExtDeviceMode to unicode in the driver interface
901 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
902 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
903 LPSTR lpszPort, LPDEVMODEA lpdmInput,
904 LPSTR lpszProfile, DWORD fwMode )
906 WCHAR deviceW[300];
907 WCHAR bufW[300];
908 char buf[300];
909 HDC hdc;
910 DC *dc;
911 INT ret = -1;
913 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
914 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
916 if (!lpszDevice) return -1;
917 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
919 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
921 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
923 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
925 if ((dc = get_dc_ptr( hdc )))
927 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
928 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
929 lpdmInput, lpszProfile, fwMode );
930 release_dc_ptr( dc );
932 DeleteDC( hdc );
933 return ret;
936 /****************************************************************************
937 * @ [GDI32.103]
939 * This should load the correct driver for lpszDevice and calls this driver's
940 * AdvancedSetupDialog proc.
942 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
943 LPDEVMODEA devin, LPDEVMODEA devout )
945 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
946 return -1;
949 /*****************************************************************************
950 * @ [GDI32.104]
952 * This should load the correct driver for lpszDevice and calls this driver's
953 * DeviceCapabilities proc.
955 * FIXME: convert DeviceCapabilities to unicode in the driver interface
957 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
958 WORD fwCapability, LPSTR lpszOutput,
959 LPDEVMODEA lpdm )
961 WCHAR deviceW[300];
962 WCHAR bufW[300];
963 char buf[300];
964 HDC hdc;
965 DC *dc;
966 INT ret = -1;
968 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
970 if (!lpszDevice) return -1;
971 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
973 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
975 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
977 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
979 if ((dc = get_dc_ptr( hdc )))
981 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
982 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
983 fwCapability, lpszOutput, lpdm );
984 release_dc_ptr( dc );
986 DeleteDC( hdc );
987 return ret;
991 /************************************************************************
992 * Escape [GDI32.@]
994 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
996 INT ret;
997 POINT *pt;
999 switch (escape)
1001 case ABORTDOC:
1002 return AbortDoc( hdc );
1004 case ENDDOC:
1005 return EndDoc( hdc );
1007 case GETPHYSPAGESIZE:
1008 pt = out_data;
1009 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1010 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1011 return 1;
1013 case GETPRINTINGOFFSET:
1014 pt = out_data;
1015 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1016 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1017 return 1;
1019 case GETSCALINGFACTOR:
1020 pt = out_data;
1021 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1022 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1023 return 1;
1025 case NEWFRAME:
1026 return EndPage( hdc );
1028 case SETABORTPROC:
1029 return SetAbortProc( hdc, (ABORTPROC)in_data );
1031 case STARTDOC:
1033 DOCINFOA doc;
1034 char *name = NULL;
1036 /* in_data may not be 0 terminated so we must copy it */
1037 if (in_data)
1039 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1040 memcpy( name, in_data, in_count );
1041 name[in_count] = 0;
1043 /* out_data is actually a pointer to the DocInfo structure and used as
1044 * a second input parameter */
1045 if (out_data) doc = *(DOCINFOA *)out_data;
1046 else
1048 doc.cbSize = sizeof(doc);
1049 doc.lpszOutput = NULL;
1050 doc.lpszDatatype = NULL;
1051 doc.fwType = 0;
1053 doc.lpszDocName = name;
1054 ret = StartDocA( hdc, &doc );
1055 HeapFree( GetProcessHeap(), 0, name );
1056 if (ret > 0) ret = StartPage( hdc );
1057 return ret;
1060 case QUERYESCSUPPORT:
1062 DWORD code;
1064 if (in_count < sizeof(SHORT)) return 0;
1065 code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
1066 switch (code)
1068 case ABORTDOC:
1069 case ENDDOC:
1070 case GETPHYSPAGESIZE:
1071 case GETPRINTINGOFFSET:
1072 case GETSCALINGFACTOR:
1073 case NEWFRAME:
1074 case QUERYESCSUPPORT:
1075 case SETABORTPROC:
1076 case STARTDOC:
1077 return TRUE;
1079 break;
1083 /* if not handled internally, pass it to the driver */
1084 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1088 /******************************************************************************
1089 * ExtEscape [GDI32.@]
1091 * Access capabilities of a particular device that are not available through GDI.
1093 * PARAMS
1094 * hdc [I] Handle to device context
1095 * nEscape [I] Escape function
1096 * cbInput [I] Number of bytes in input structure
1097 * lpszInData [I] Pointer to input structure
1098 * cbOutput [I] Number of bytes in output structure
1099 * lpszOutData [O] Pointer to output structure
1101 * RETURNS
1102 * Success: >0
1103 * Not implemented: 0
1104 * Failure: <0
1106 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1107 INT cbOutput, LPSTR lpszOutData )
1109 PHYSDEV physdev;
1110 INT ret;
1111 DC * dc = get_dc_ptr( hdc );
1113 if (!dc) return 0;
1114 update_dc( dc );
1115 physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1116 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1117 release_dc_ptr( dc );
1118 return ret;
1122 /*******************************************************************
1123 * DrawEscape [GDI32.@]
1127 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1129 FIXME("DrawEscape, stub\n");
1130 return 0;
1133 /*******************************************************************
1134 * NamedEscape [GDI32.@]
1136 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1137 INT cbOutput, LPSTR lpszOutData )
1139 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1140 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1141 lpszOutData);
1142 return 0;
1145 /*******************************************************************
1146 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1147 * GdiEntry13 [GDI32.@]
1149 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1151 static int warn_once;
1153 if (!warn_once++)
1154 FIXME("stub\n");
1155 return 0;
1158 /******************************************************************************
1159 * D3DKMTOpenAdapterFromHdc [GDI32.@]
1161 NTSTATUS WINAPI D3DKMTOpenAdapterFromHdc( void *pData )
1163 FIXME("(%p): stub\n", pData);
1164 return STATUS_NO_MEMORY;
1167 /******************************************************************************
1168 * D3DKMTEscape [GDI32.@]
1170 NTSTATUS WINAPI D3DKMTEscape( const void *pData )
1172 FIXME("(%p): stub\n", pData);
1173 return STATUS_NO_MEMORY;