gdi32: Make clip_line external.
[wine/multimedia.git] / dlls / gdi32 / driver.c
blob4f111c3f8f2323bc1a5bf2d1f344cb3ce541fa6c
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 static CRITICAL_SECTION driver_section;
53 static CRITICAL_SECTION_DEBUG critsect_debug =
55 0, 0, &driver_section,
56 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
57 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
59 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
61 /**********************************************************************
62 * create_driver
64 * Allocate and fill the driver structure for a given module.
66 static struct graphics_driver *create_driver( HMODULE module )
68 static const struct gdi_dc_funcs empty_funcs;
69 const struct gdi_dc_funcs *funcs = NULL;
70 struct graphics_driver *driver;
72 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
73 driver->module = module;
75 if (module)
77 const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
79 if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
80 funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
82 if (!funcs) funcs = &empty_funcs;
83 driver->funcs = funcs;
84 return driver;
88 /**********************************************************************
89 * get_display_driver
91 * Special case for loading the display driver: get the name from the config file
93 static const struct gdi_dc_funcs *get_display_driver(void)
95 struct graphics_driver *driver;
96 char buffer[MAX_PATH], libname[32], *name, *next;
97 HMODULE module = 0;
98 HKEY hkey;
100 if (display_driver) return display_driver->funcs; /* already loaded */
102 strcpy( buffer, "x11" ); /* default value */
103 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
104 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
106 DWORD type, count = sizeof(buffer);
107 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
108 RegCloseKey( hkey );
111 name = buffer;
112 while (name)
114 next = strchr( name, ',' );
115 if (next) *next++ = 0;
117 snprintf( libname, sizeof(libname), "wine%s.drv", name );
118 if ((module = LoadLibraryA( libname )) != 0) break;
119 name = next;
122 if (!(driver = create_driver( module )))
124 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
125 FreeLibrary( module );
126 ExitProcess(1);
128 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
130 /* somebody beat us to it */
131 FreeLibrary( driver->module );
132 HeapFree( GetProcessHeap(), 0, driver );
134 return display_driver->funcs;
138 /**********************************************************************
139 * DRIVER_load_driver
141 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
143 HMODULE module;
144 struct graphics_driver *driver, *new_driver;
145 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
146 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
148 /* display driver is a special case */
149 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
151 if ((module = GetModuleHandleW( name )))
153 if (display_driver && display_driver->module == module) return display_driver->funcs;
154 EnterCriticalSection( &driver_section );
155 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
157 if (driver->module == module) goto done;
159 LeaveCriticalSection( &driver_section );
162 if (!(module = LoadLibraryW( name ))) return NULL;
164 if (!(new_driver = create_driver( module )))
166 FreeLibrary( module );
167 return NULL;
170 /* check if someone else added it in the meantime */
171 EnterCriticalSection( &driver_section );
172 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
174 if (driver->module != module) continue;
175 FreeLibrary( module );
176 HeapFree( GetProcessHeap(), 0, new_driver );
177 goto done;
179 driver = new_driver;
180 list_add_head( &drivers, &driver->entry );
181 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
182 done:
183 LeaveCriticalSection( &driver_section );
184 return driver->funcs;
188 static INT nulldrv_AbortDoc( PHYSDEV dev )
190 return 0;
193 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
194 INT xstart, INT ystart, INT xend, INT yend )
196 return TRUE;
199 static DWORD nulldrv_BlendImage( PHYSDEV dev, BITMAPINFO *info, const struct gdi_image_bits *bits,
200 struct bitblt_coords *src, struct bitblt_coords *dst, BLENDFUNCTION func )
202 return TRUE;
205 static INT nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
207 return 0;
210 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
211 INT xstart, INT ystart, INT xend, INT yend )
213 return TRUE;
216 static BOOL nulldrv_CreateBitmap( PHYSDEV dev, HBITMAP bitmap )
218 return TRUE;
221 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
223 if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
224 return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
227 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
228 LPCWSTR output, const DEVMODEW *devmode )
230 assert(0); /* should never be called */
231 return FALSE;
234 static HBITMAP nulldrv_CreateDIBSection( PHYSDEV dev, HBITMAP bitmap, BITMAPINFO *info, UINT usage )
236 return bitmap;
239 static BOOL nulldrv_DeleteBitmap( HBITMAP bitmap )
241 return TRUE;
244 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
246 assert(0); /* should never be called */
247 return TRUE;
250 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
252 return TRUE;
255 static INT nulldrv_DescribePixelFormat( PHYSDEV dev, INT format, UINT size, PIXELFORMATDESCRIPTOR * descr )
257 return 0;
260 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
261 WORD cap, LPSTR output, DEVMODEA *devmode )
263 return -1;
266 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
268 return TRUE;
271 static INT nulldrv_EndDoc( PHYSDEV dev )
273 return 0;
276 static INT nulldrv_EndPage( PHYSDEV dev )
278 return 0;
281 static BOOL nulldrv_EnumDeviceFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
283 return FALSE;
286 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
288 return -1;
291 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
292 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
294 return -1;
297 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
298 INT out_size, void *out_data )
300 return 0;
303 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
305 return TRUE;
308 static BOOL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
309 LPCWSTR str, UINT count, const INT *dx )
311 return TRUE;
314 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
316 return FALSE;
319 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
321 return FALSE;
324 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
326 switch (cap) /* return meaningful values for some entries */
328 case HORZRES: return 640;
329 case VERTRES: return 480;
330 case BITSPIXEL: return 1;
331 case PLANES: return 1;
332 case NUMCOLORS: return 2;
333 case ASPECTX: return 36;
334 case ASPECTY: return 36;
335 case ASPECTXY: return 51;
336 case LOGPIXELSX: return 72;
337 case LOGPIXELSY: return 72;
338 case SIZEPALETTE: return 2;
339 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
340 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
341 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
342 default: return 0;
346 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
348 return FALSE;
351 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
353 return FALSE;
356 static COLORREF nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
358 return 0;
361 static INT nulldrv_GetPixelFormat( PHYSDEV dev )
363 return 0;
366 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
368 return 0;
371 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
372 INT *fit, INT *dx, SIZE *size )
374 return FALSE;
377 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
379 return FALSE;
382 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
384 return TRUE;
387 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
389 return TRUE;
392 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
394 return TRUE;
397 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
399 return TRUE;
402 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
403 INT xstart, INT ystart, INT xend, INT yend )
405 return TRUE;
408 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
410 /* FIXME: could be implemented with Polygon */
411 return TRUE;
414 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
416 /* FIXME: could be implemented with Polyline */
417 return TRUE;
420 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
422 return TRUE;
425 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
427 return TRUE;
430 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
432 return 0;
435 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
437 return 0;
440 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
442 return TRUE;
445 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
447 return 0;
450 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
451 INT ell_width, INT ell_height )
453 return TRUE;
456 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
458 return bitmap;
461 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
463 return brush;
466 static HFONT nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
468 return 0;
471 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
473 return palette;
476 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
478 return pen;
481 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
483 return dir;
486 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
488 return color;
491 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
493 return mode;
496 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
498 return color;
501 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
503 return color;
506 static UINT nulldrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
508 return 0;
511 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
515 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
517 return layout;
520 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
522 return FALSE;
525 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
527 return flags;
530 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
532 return color;
535 static BOOL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
537 return FALSE;
540 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
542 return mode;
545 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
547 return rop;
550 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
552 return mode;
555 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
557 return mode;
560 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
562 return align;
565 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
567 return extra;
570 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
572 return color;
575 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
577 return TRUE;
580 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
582 return 0;
585 static INT nulldrv_StartPage( PHYSDEV dev )
587 return 1;
590 static BOOL nulldrv_SwapBuffers( PHYSDEV dev )
592 return TRUE;
595 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
597 return FALSE;
600 static BOOL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
602 return FALSE;
605 static HGLRC nulldrv_wglCreateContext( PHYSDEV dev )
607 return 0;
610 static HGLRC nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
612 return 0;
615 static BOOL nulldrv_wglDeleteContext( HGLRC ctx )
617 return FALSE;
620 static PROC nulldrv_wglGetProcAddress( LPCSTR name )
622 return NULL;
625 static HDC nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
627 return 0;
630 static BOOL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
632 return FALSE;
635 static BOOL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
637 return FALSE;
640 static BOOL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
642 return FALSE;
645 static BOOL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
647 return FALSE;
650 static BOOL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
652 return FALSE;
655 static BOOL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
657 return FALSE;
660 const DC_FUNCTIONS null_driver =
662 nulldrv_AbortDoc, /* pAbortDoc */
663 nulldrv_AbortPath, /* pAbortPath */
664 nulldrv_AlphaBlend, /* pAlphaBlend */
665 nulldrv_AngleArc, /* pAngleArc */
666 nulldrv_Arc, /* pArc */
667 nulldrv_ArcTo, /* pArcTo */
668 nulldrv_BeginPath, /* pBeginPath */
669 nulldrv_BlendImage, /* pBlendImage */
670 nulldrv_ChoosePixelFormat, /* pChoosePixelFormat */
671 nulldrv_Chord, /* pChord */
672 nulldrv_CloseFigure, /* pCloseFigure */
673 nulldrv_CreateBitmap, /* pCreateBitmap */
674 nulldrv_CreateCompatibleDC, /* pCreateCompatibleDC */
675 nulldrv_CreateDC, /* pCreateDC */
676 nulldrv_CreateDIBSection, /* pCreateDIBSection */
677 nulldrv_DeleteBitmap, /* pDeleteBitmap */
678 nulldrv_DeleteDC, /* pDeleteDC */
679 nulldrv_DeleteObject, /* pDeleteObject */
680 nulldrv_DescribePixelFormat, /* pDescribePixelFormat */
681 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
682 nulldrv_Ellipse, /* pEllipse */
683 nulldrv_EndDoc, /* pEndDoc */
684 nulldrv_EndPage, /* pEndPage */
685 nulldrv_EndPath, /* pEndPath */
686 nulldrv_EnumDeviceFonts, /* pEnumDeviceFonts */
687 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
688 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
689 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
690 nulldrv_ExtEscape, /* pExtEscape */
691 nulldrv_ExtFloodFill, /* pExtFloodFill */
692 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
693 nulldrv_ExtTextOut, /* pExtTextOut */
694 nulldrv_FillPath, /* pFillPath */
695 nulldrv_FillRgn, /* pFillRgn */
696 nulldrv_FlattenPath, /* pFlattenPath */
697 nulldrv_FrameRgn, /* pFrameRgn */
698 nulldrv_GdiComment, /* pGdiComment */
699 nulldrv_GetCharWidth, /* pGetCharWidth */
700 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
701 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
702 nulldrv_GetICMProfile, /* pGetICMProfile */
703 nulldrv_GetImage, /* pGetImage */
704 nulldrv_GetNearestColor, /* pGetNearestColor */
705 nulldrv_GetPixel, /* pGetPixel */
706 nulldrv_GetPixelFormat, /* pGetPixelFormat */
707 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
708 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
709 nulldrv_GetTextMetrics, /* pGetTextMetrics */
710 nulldrv_IntersectClipRect, /* pIntersectClipRect */
711 nulldrv_InvertRgn, /* pInvertRgn */
712 nulldrv_LineTo, /* pLineTo */
713 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
714 nulldrv_MoveTo, /* pMoveTo */
715 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
716 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
717 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
718 nulldrv_PaintRgn, /* pPaintRgn */
719 nulldrv_PatBlt, /* pPatBlt */
720 nulldrv_Pie, /* pPie */
721 nulldrv_PolyBezier, /* pPolyBezier */
722 nulldrv_PolyBezierTo, /* pPolyBezierTo */
723 nulldrv_PolyDraw, /* pPolyDraw */
724 nulldrv_PolyPolygon, /* pPolyPolygon */
725 nulldrv_PolyPolyline, /* pPolyPolyline */
726 nulldrv_Polygon, /* pPolygon */
727 nulldrv_Polyline, /* pPolyline */
728 nulldrv_PolylineTo, /* pPolylineTo */
729 nulldrv_PutImage, /* pPutImage */
730 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
731 nulldrv_RealizePalette, /* pRealizePalette */
732 nulldrv_Rectangle, /* pRectangle */
733 nulldrv_ResetDC, /* pResetDC */
734 nulldrv_RestoreDC, /* pRestoreDC */
735 nulldrv_RoundRect, /* pRoundRect */
736 nulldrv_SaveDC, /* pSaveDC */
737 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
738 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
739 nulldrv_SelectBitmap, /* pSelectBitmap */
740 nulldrv_SelectBrush, /* pSelectBrush */
741 nulldrv_SelectClipPath, /* pSelectClipPath */
742 nulldrv_SelectFont, /* pSelectFont */
743 nulldrv_SelectPalette, /* pSelectPalette */
744 nulldrv_SelectPen, /* pSelectPen */
745 nulldrv_SetArcDirection, /* pSetArcDirection */
746 nulldrv_SetBkColor, /* pSetBkColor */
747 nulldrv_SetBkMode, /* pSetBkMode */
748 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
749 nulldrv_SetDCPenColor, /* pSetDCPenColor */
750 nulldrv_SetDIBColorTable, /* pSetDIBColorTable */
751 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
752 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
753 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
754 nulldrv_SetLayout, /* pSetLayout */
755 nulldrv_SetMapMode, /* pSetMapMode */
756 nulldrv_SetMapperFlags, /* pSetMapperFlags */
757 nulldrv_SetPixel, /* pSetPixel */
758 nulldrv_SetPixelFormat, /* pSetPixelFormat */
759 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
760 nulldrv_SetROP2, /* pSetROP2 */
761 nulldrv_SetRelAbs, /* pSetRelAbs */
762 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
763 nulldrv_SetTextAlign, /* pSetTextAlign */
764 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
765 nulldrv_SetTextColor, /* pSetTextColor */
766 nulldrv_SetTextJustification, /* pSetTextJustification */
767 nulldrv_SetViewportExtEx, /* pSetViewportExt */
768 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
769 nulldrv_SetWindowExtEx, /* pSetWindowExt */
770 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
771 nulldrv_SetWorldTransform, /* pSetWorldTransform */
772 nulldrv_StartDoc, /* pStartDoc */
773 nulldrv_StartPage, /* pStartPage */
774 nulldrv_StretchBlt, /* pStretchBlt */
775 nulldrv_StretchDIBits, /* pStretchDIBits */
776 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
777 nulldrv_StrokePath, /* pStrokePath */
778 nulldrv_SwapBuffers, /* pSwapBuffers */
779 nulldrv_UnrealizePalette, /* pUnrealizePalette */
780 nulldrv_WidenPath, /* pWidenPath */
781 nulldrv_wglCopyContext, /* pwglCopyContext */
782 nulldrv_wglCreateContext, /* pwglCreateContext */
783 nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
784 nulldrv_wglDeleteContext, /* pwglDeleteContext */
785 nulldrv_wglGetPbufferDCARB, /* pwglGetPbufferDCARB */
786 nulldrv_wglGetProcAddress, /* pwglGetProcAddress */
787 nulldrv_wglMakeContextCurrentARB, /* pwglMakeContextCurrentARB */
788 nulldrv_wglMakeCurrent, /* pwglMakeCurrent */
789 nulldrv_wglSetPixelFormatWINE, /* pwglSetPixelFormatWINE */
790 nulldrv_wglShareLists, /* pwglShareLists */
791 nulldrv_wglUseFontBitmapsA, /* pwglUseFontBitmapsA */
792 nulldrv_wglUseFontBitmapsW, /* pwglUseFontBitmapsW */
796 /*****************************************************************************
797 * DRIVER_GetDriverName
800 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
802 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
803 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
804 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
805 static const WCHAR empty_strW[] = { 0 };
806 WCHAR *p;
808 /* display is a special case */
809 if (!strcmpiW( device, displayW ) ||
810 !strcmpiW( device, display1W ))
812 lstrcpynW( driver, displayW, size );
813 return TRUE;
816 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
817 if(!size) {
818 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
819 return FALSE;
821 p = strchrW(driver, ',');
822 if(!p)
824 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
825 return FALSE;
827 *p = 0;
828 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
829 return TRUE;
833 /***********************************************************************
834 * GdiConvertToDevmodeW (GDI32.@)
836 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
838 DEVMODEW *dmW;
839 WORD dmW_size, dmA_size;
841 dmA_size = dmA->dmSize;
843 /* this is the minimal dmSize that XP accepts */
844 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
845 return NULL;
847 if (dmA_size > sizeof(DEVMODEA))
848 dmA_size = sizeof(DEVMODEA);
850 dmW_size = dmA_size + CCHDEVICENAME;
851 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
852 dmW_size += CCHFORMNAME;
854 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
855 if (!dmW) return NULL;
857 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
858 dmW->dmDeviceName, CCHDEVICENAME);
859 /* copy slightly more, to avoid long computations */
860 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
862 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
864 if (dmA->dmFields & DM_FORMNAME)
865 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
866 dmW->dmFormName, CCHFORMNAME);
867 else
868 dmW->dmFormName[0] = 0;
870 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
871 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
874 if (dmA->dmDriverExtra)
875 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
877 dmW->dmSize = dmW_size;
879 return dmW;
883 /*****************************************************************************
884 * @ [GDI32.100]
886 * This should thunk to 16-bit and simply call the proc with the given args.
888 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
889 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
891 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
892 return -1;
895 /*****************************************************************************
896 * @ [GDI32.101]
898 * This should load the correct driver for lpszDevice and calls this driver's
899 * ExtDeviceModePropSheet proc.
901 * Note: The driver calls a callback routine for each property sheet page; these
902 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
903 * The layout of this structure is:
905 * struct
907 * DWORD nPages;
908 * DWORD unknown;
909 * HPROPSHEETPAGE pages[10];
910 * };
912 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
913 LPCSTR lpszPort, LPVOID lpPropSheet )
915 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
916 return -1;
919 /*****************************************************************************
920 * @ [GDI32.102]
922 * This should load the correct driver for lpszDevice and call this driver's
923 * ExtDeviceMode proc.
925 * FIXME: convert ExtDeviceMode to unicode in the driver interface
927 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
928 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
929 LPSTR lpszPort, LPDEVMODEA lpdmInput,
930 LPSTR lpszProfile, DWORD fwMode )
932 WCHAR deviceW[300];
933 WCHAR bufW[300];
934 char buf[300];
935 HDC hdc;
936 DC *dc;
937 INT ret = -1;
939 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
940 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
942 if (!lpszDevice) return -1;
943 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
945 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
947 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
949 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
951 if ((dc = get_dc_ptr( hdc )))
953 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
954 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
955 lpdmInput, lpszProfile, fwMode );
956 release_dc_ptr( dc );
958 DeleteDC( hdc );
959 return ret;
962 /****************************************************************************
963 * @ [GDI32.103]
965 * This should load the correct driver for lpszDevice and calls this driver's
966 * AdvancedSetupDialog proc.
968 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
969 LPDEVMODEA devin, LPDEVMODEA devout )
971 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
972 return -1;
975 /*****************************************************************************
976 * @ [GDI32.104]
978 * This should load the correct driver for lpszDevice and calls this driver's
979 * DeviceCapabilities proc.
981 * FIXME: convert DeviceCapabilities to unicode in the driver interface
983 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
984 WORD fwCapability, LPSTR lpszOutput,
985 LPDEVMODEA lpdm )
987 WCHAR deviceW[300];
988 WCHAR bufW[300];
989 char buf[300];
990 HDC hdc;
991 DC *dc;
992 INT ret = -1;
994 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
996 if (!lpszDevice) return -1;
997 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
999 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1001 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1003 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1005 if ((dc = get_dc_ptr( hdc )))
1007 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1008 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1009 fwCapability, lpszOutput, lpdm );
1010 release_dc_ptr( dc );
1012 DeleteDC( hdc );
1013 return ret;
1017 /************************************************************************
1018 * Escape [GDI32.@]
1020 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1022 INT ret;
1023 POINT *pt;
1025 switch (escape)
1027 case ABORTDOC:
1028 return AbortDoc( hdc );
1030 case ENDDOC:
1031 return EndDoc( hdc );
1033 case GETPHYSPAGESIZE:
1034 pt = out_data;
1035 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1036 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1037 return 1;
1039 case GETPRINTINGOFFSET:
1040 pt = out_data;
1041 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1042 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1043 return 1;
1045 case GETSCALINGFACTOR:
1046 pt = out_data;
1047 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1048 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1049 return 1;
1051 case NEWFRAME:
1052 return EndPage( hdc );
1054 case SETABORTPROC:
1055 return SetAbortProc( hdc, (ABORTPROC)in_data );
1057 case STARTDOC:
1059 DOCINFOA doc;
1060 char *name = NULL;
1062 /* in_data may not be 0 terminated so we must copy it */
1063 if (in_data)
1065 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1066 memcpy( name, in_data, in_count );
1067 name[in_count] = 0;
1069 /* out_data is actually a pointer to the DocInfo structure and used as
1070 * a second input parameter */
1071 if (out_data) doc = *(DOCINFOA *)out_data;
1072 else
1074 doc.cbSize = sizeof(doc);
1075 doc.lpszOutput = NULL;
1076 doc.lpszDatatype = NULL;
1077 doc.fwType = 0;
1079 doc.lpszDocName = name;
1080 ret = StartDocA( hdc, &doc );
1081 HeapFree( GetProcessHeap(), 0, name );
1082 if (ret > 0) ret = StartPage( hdc );
1083 return ret;
1086 case QUERYESCSUPPORT:
1088 const INT *ptr = (const INT *)in_data;
1089 if (in_count < sizeof(INT)) return 0;
1090 switch(*ptr)
1092 case ABORTDOC:
1093 case ENDDOC:
1094 case GETPHYSPAGESIZE:
1095 case GETPRINTINGOFFSET:
1096 case GETSCALINGFACTOR:
1097 case NEWFRAME:
1098 case QUERYESCSUPPORT:
1099 case SETABORTPROC:
1100 case STARTDOC:
1101 return TRUE;
1103 break;
1107 /* if not handled internally, pass it to the driver */
1108 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1112 /******************************************************************************
1113 * ExtEscape [GDI32.@]
1115 * Access capabilities of a particular device that are not available through GDI.
1117 * PARAMS
1118 * hdc [I] Handle to device context
1119 * nEscape [I] Escape function
1120 * cbInput [I] Number of bytes in input structure
1121 * lpszInData [I] Pointer to input structure
1122 * cbOutput [I] Number of bytes in output structure
1123 * lpszOutData [O] Pointer to output structure
1125 * RETURNS
1126 * Success: >0
1127 * Not implemented: 0
1128 * Failure: <0
1130 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1131 INT cbOutput, LPSTR lpszOutData )
1133 INT ret = 0;
1134 DC * dc = get_dc_ptr( hdc );
1136 if (dc)
1138 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1139 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1140 release_dc_ptr( dc );
1142 return ret;
1146 /*******************************************************************
1147 * DrawEscape [GDI32.@]
1151 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1153 FIXME("DrawEscape, stub\n");
1154 return 0;
1157 /*******************************************************************
1158 * NamedEscape [GDI32.@]
1160 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1161 INT cbOutput, LPSTR lpszOutData )
1163 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1164 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1165 lpszOutData);
1166 return 0;
1169 /*******************************************************************
1170 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1171 * GdiEntry13 [GDI32.@]
1173 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1175 static int warn_once;
1177 if (!warn_once++)
1178 FIXME("stub\n");
1179 return 0;