windowscodecs: Add support for converting to 32bppPBGRA.
[wine.git] / dlls / gdi32 / driver.c
blob13bd7bd518f73ade6daa819da540d228b28d1407
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 DC_FUNCTIONS 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 struct graphics_driver *driver;
70 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
71 driver->module = module;
73 /* fill the function table */
74 if (module)
76 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
77 GET_FUNC(AbortDoc);
78 GET_FUNC(AbortPath);
79 GET_FUNC(AlphaBlend);
80 GET_FUNC(AngleArc);
81 GET_FUNC(Arc);
82 GET_FUNC(ArcTo);
83 GET_FUNC(BeginPath);
84 GET_FUNC(ChoosePixelFormat);
85 GET_FUNC(Chord);
86 GET_FUNC(CloseFigure);
87 GET_FUNC(CreateBitmap);
88 GET_FUNC(CreateDC);
89 GET_FUNC(CreateDIBSection);
90 GET_FUNC(DeleteBitmap);
91 GET_FUNC(DeleteDC);
92 GET_FUNC(DescribePixelFormat);
93 GET_FUNC(DeviceCapabilities);
94 GET_FUNC(Ellipse);
95 GET_FUNC(EndDoc);
96 GET_FUNC(EndPage);
97 GET_FUNC(EndPath);
98 GET_FUNC(EnumDeviceFonts);
99 GET_FUNC(EnumICMProfiles);
100 GET_FUNC(ExcludeClipRect);
101 GET_FUNC(ExtDeviceMode);
102 GET_FUNC(ExtEscape);
103 GET_FUNC(ExtFloodFill);
104 GET_FUNC(ExtSelectClipRgn);
105 GET_FUNC(ExtTextOut);
106 GET_FUNC(FillPath);
107 GET_FUNC(FillRgn);
108 GET_FUNC(FlattenPath);
109 GET_FUNC(FrameRgn);
110 GET_FUNC(GdiComment);
111 GET_FUNC(GetBitmapBits);
112 GET_FUNC(GetCharWidth);
113 GET_FUNC(GetDIBits);
114 GET_FUNC(GetDeviceCaps);
115 GET_FUNC(GetDeviceGammaRamp);
116 GET_FUNC(GetICMProfile);
117 GET_FUNC(GetNearestColor);
118 GET_FUNC(GetPixel);
119 GET_FUNC(GetPixelFormat);
120 GET_FUNC(GetSystemPaletteEntries);
121 GET_FUNC(GetTextExtentExPoint);
122 GET_FUNC(GetTextMetrics);
123 GET_FUNC(IntersectClipRect);
124 GET_FUNC(InvertRgn);
125 GET_FUNC(LineTo);
126 GET_FUNC(MoveTo);
127 GET_FUNC(ModifyWorldTransform);
128 GET_FUNC(OffsetClipRgn);
129 GET_FUNC(OffsetViewportOrgEx);
130 GET_FUNC(OffsetWindowOrgEx);
131 GET_FUNC(PaintRgn);
132 GET_FUNC(PatBlt);
133 GET_FUNC(Pie);
134 GET_FUNC(PolyBezier);
135 GET_FUNC(PolyBezierTo);
136 GET_FUNC(PolyDraw);
137 GET_FUNC(PolyPolygon);
138 GET_FUNC(PolyPolyline);
139 GET_FUNC(Polygon);
140 GET_FUNC(Polyline);
141 GET_FUNC(PolylineTo);
142 GET_FUNC(RealizeDefaultPalette);
143 GET_FUNC(RealizePalette);
144 GET_FUNC(Rectangle);
145 GET_FUNC(ResetDC);
146 GET_FUNC(RestoreDC);
147 GET_FUNC(RoundRect);
148 GET_FUNC(SaveDC);
149 GET_FUNC(ScaleViewportExtEx);
150 GET_FUNC(ScaleWindowExtEx);
151 GET_FUNC(SelectBitmap);
152 GET_FUNC(SelectBrush);
153 GET_FUNC(SelectClipPath);
154 GET_FUNC(SelectFont);
155 GET_FUNC(SelectPalette);
156 GET_FUNC(SelectPen);
157 GET_FUNC(SetArcDirection);
158 GET_FUNC(SetBitmapBits);
159 GET_FUNC(SetBkColor);
160 GET_FUNC(SetBkMode);
161 GET_FUNC(SetDCBrushColor);
162 GET_FUNC(SetDCPenColor);
163 GET_FUNC(SetDIBColorTable);
164 GET_FUNC(SetDIBits);
165 GET_FUNC(SetDIBitsToDevice);
166 GET_FUNC(SetDeviceClipping);
167 GET_FUNC(SetDeviceGammaRamp);
168 GET_FUNC(SetLayout);
169 GET_FUNC(SetMapMode);
170 GET_FUNC(SetMapperFlags);
171 GET_FUNC(SetPixel);
172 GET_FUNC(SetPixelFormat);
173 GET_FUNC(SetPolyFillMode);
174 GET_FUNC(SetROP2);
175 GET_FUNC(SetRelAbs);
176 GET_FUNC(SetStretchBltMode);
177 GET_FUNC(SetTextAlign);
178 GET_FUNC(SetTextCharacterExtra);
179 GET_FUNC(SetTextColor);
180 GET_FUNC(SetTextJustification);
181 GET_FUNC(SetViewportExtEx);
182 GET_FUNC(SetViewportOrgEx);
183 GET_FUNC(SetWindowExtEx);
184 GET_FUNC(SetWindowOrgEx);
185 GET_FUNC(SetWorldTransform);
186 GET_FUNC(StartDoc);
187 GET_FUNC(StartPage);
188 GET_FUNC(StretchBlt);
189 GET_FUNC(StretchDIBits);
190 GET_FUNC(StrokeAndFillPath);
191 GET_FUNC(StrokePath);
192 GET_FUNC(SwapBuffers);
193 GET_FUNC(UnrealizePalette);
194 GET_FUNC(WidenPath);
196 /* OpenGL32 */
197 GET_FUNC(wglCreateContext);
198 GET_FUNC(wglCreateContextAttribsARB);
199 GET_FUNC(wglDeleteContext);
200 GET_FUNC(wglGetProcAddress);
201 GET_FUNC(wglGetPbufferDCARB);
202 GET_FUNC(wglMakeContextCurrentARB);
203 GET_FUNC(wglMakeCurrent);
204 GET_FUNC(wglSetPixelFormatWINE);
205 GET_FUNC(wglShareLists);
206 GET_FUNC(wglUseFontBitmapsA);
207 GET_FUNC(wglUseFontBitmapsW);
208 #undef GET_FUNC
210 else memset( &driver->funcs, 0, sizeof(driver->funcs) );
212 return driver;
216 /**********************************************************************
217 * DRIVER_get_display_driver
219 * Special case for loading the display driver: get the name from the config file
221 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
223 struct graphics_driver *driver;
224 char buffer[MAX_PATH], libname[32], *name, *next;
225 HMODULE module = 0;
226 HKEY hkey;
228 if (display_driver) return &display_driver->funcs; /* already loaded */
230 strcpy( buffer, "x11" ); /* default value */
231 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
232 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
234 DWORD type, count = sizeof(buffer);
235 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
236 RegCloseKey( hkey );
239 name = buffer;
240 while (name)
242 next = strchr( name, ',' );
243 if (next) *next++ = 0;
245 snprintf( libname, sizeof(libname), "wine%s.drv", name );
246 if ((module = LoadLibraryA( libname )) != 0) break;
247 name = next;
250 if (!(driver = create_driver( module )))
252 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
253 FreeLibrary( module );
254 ExitProcess(1);
256 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
258 /* somebody beat us to it */
259 FreeLibrary( driver->module );
260 HeapFree( GetProcessHeap(), 0, driver );
262 return &display_driver->funcs;
266 /**********************************************************************
267 * DRIVER_load_driver
269 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
271 HMODULE module;
272 struct graphics_driver *driver, *new_driver;
273 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
274 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
276 /* display driver is a special case */
277 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
279 if ((module = GetModuleHandleW( name )))
281 if (display_driver && display_driver->module == module) return &display_driver->funcs;
282 EnterCriticalSection( &driver_section );
283 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
285 if (driver->module == module) goto done;
287 LeaveCriticalSection( &driver_section );
290 if (!(module = LoadLibraryW( name ))) return NULL;
292 if (!(new_driver = create_driver( module )))
294 FreeLibrary( module );
295 return NULL;
298 /* check if someone else added it in the meantime */
299 EnterCriticalSection( &driver_section );
300 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
302 if (driver->module != module) continue;
303 FreeLibrary( module );
304 HeapFree( GetProcessHeap(), 0, new_driver );
305 goto done;
307 driver = new_driver;
308 list_add_head( &drivers, &driver->entry );
309 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
310 done:
311 LeaveCriticalSection( &driver_section );
312 return &driver->funcs;
316 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
318 return 0;
321 static BOOL CDECL nulldrv_AlphaBlend( PHYSDEV dst_dev, INT x_dst, INT y_dst, INT width_dst, INT height_dst,
322 PHYSDEV src_dev, INT x_src, INT y_src, INT width_src, INT height_src,
323 BLENDFUNCTION func)
325 return TRUE;
328 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
329 INT xstart, INT ystart, INT xend, INT yend )
331 return TRUE;
334 static INT CDECL nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
336 return 0;
339 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
340 INT xstart, INT ystart, INT xend, INT yend )
342 return TRUE;
345 static BOOL CDECL nulldrv_CreateBitmap( PHYSDEV dev, HBITMAP bitmap, LPVOID bits )
347 return TRUE;
350 static BOOL CDECL nulldrv_CreateDC( HDC hdc, PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
351 LPCWSTR output, const DEVMODEW *devmode )
353 assert(0); /* should never be called */
354 return FALSE;
357 static HBITMAP CDECL nulldrv_CreateDIBSection( PHYSDEV dev, HBITMAP bitmap,
358 const BITMAPINFO *info, UINT usage )
360 return bitmap;
363 static BOOL CDECL nulldrv_DeleteBitmap( HBITMAP bitmap )
365 return TRUE;
368 static BOOL CDECL nulldrv_DeleteDC( PHYSDEV dev )
370 assert(0); /* should never be called */
371 return TRUE;
374 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
376 return TRUE;
379 static INT CDECL nulldrv_DescribePixelFormat( PHYSDEV dev, INT format,
380 UINT size, PIXELFORMATDESCRIPTOR * descr )
382 return 0;
385 static DWORD CDECL nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
386 WORD cap, LPSTR output, DEVMODEA *devmode )
388 return -1;
391 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
393 return TRUE;
396 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
398 return 0;
401 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
403 return 0;
406 static BOOL CDECL nulldrv_EnumDeviceFonts( PHYSDEV dev, LOGFONTW *logfont,
407 FONTENUMPROCW proc, LPARAM lParam )
409 return FALSE;
412 static INT CDECL nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
414 return -1;
417 static INT CDECL nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
418 LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
420 return -1;
423 static INT CDECL nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
424 INT out_size, void *out_data )
426 return 0;
429 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
431 return TRUE;
434 static BOOL CDECL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
435 LPCWSTR str, UINT count, const INT *dx )
437 return TRUE;
440 static BOOL CDECL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
442 return FALSE;
445 static BOOL CDECL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
447 return FALSE;
450 static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
452 switch (cap) /* return meaningful values for some entries */
454 case HORZRES: return 640;
455 case VERTRES: return 480;
456 case BITSPIXEL: return 1;
457 case PLANES: return 1;
458 case NUMCOLORS: return 2;
459 case ASPECTX: return 36;
460 case ASPECTY: return 36;
461 case ASPECTXY: return 51;
462 case LOGPIXELSX: return 72;
463 case LOGPIXELSY: return 72;
464 case SIZEPALETTE: return 2;
465 case TEXTCAPS: return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
466 TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
467 TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
468 default: return 0;
472 static BOOL CDECL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
474 return FALSE;
477 static BOOL CDECL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
479 return FALSE;
482 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
484 return 0;
487 static INT CDECL nulldrv_GetPixelFormat( PHYSDEV dev )
489 return 0;
492 static UINT CDECL nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start,
493 UINT count, PALETTEENTRY *entries )
495 return 0;
498 static BOOL CDECL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
499 INT *fit, INT *dx, SIZE *size )
501 return FALSE;
504 static BOOL CDECL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
506 return FALSE;
509 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
511 return TRUE;
514 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
516 return TRUE;
519 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
521 return TRUE;
524 static BOOL CDECL nulldrv_PatBlt( PHYSDEV dev, INT x, INT y, INT width, INT height, DWORD rop )
526 return TRUE;
529 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
530 INT xstart, INT ystart, INT xend, INT yend )
532 return TRUE;
535 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
537 /* FIXME: could be implemented with Polygon */
538 return TRUE;
541 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
543 /* FIXME: could be implemented with Polyline */
544 return TRUE;
547 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
549 return TRUE;
552 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
554 return TRUE;
557 static UINT CDECL nulldrv_RealizeDefaultPalette( PHYSDEV dev )
559 return 0;
562 static UINT CDECL nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
564 return 0;
567 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
569 return TRUE;
572 static HDC CDECL nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
574 return 0;
577 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
578 INT ell_width, INT ell_height )
580 return TRUE;
583 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
585 return bitmap;
588 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
590 return brush;
593 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
595 return 0;
598 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
600 return palette;
603 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
605 return pen;
608 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
610 return dir;
613 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
615 return color;
618 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
620 return mode;
623 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
625 return color;
628 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
630 return color;
633 static UINT CDECL nulldrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
635 return 0;
638 static INT CDECL nulldrv_SetDIBitsToDevice( PHYSDEV dev, INT x_dst, INT y_dst, DWORD width, DWORD height,
639 INT x_src, INT y_src, UINT start, UINT lines,
640 const void *bits, const BITMAPINFO *info, UINT coloruse )
642 return 0;
645 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
649 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
651 return layout;
654 static BOOL CDECL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
656 return FALSE;
659 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
661 return flags;
664 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
666 return color;
669 static BOOL CDECL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
671 return FALSE;
674 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
676 return mode;
679 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
681 return rop;
684 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
686 return mode;
689 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
691 return mode;
694 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
696 return align;
699 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
701 return extra;
704 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
706 return color;
709 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
711 return TRUE;
714 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
716 return 0;
719 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
721 return 1;
724 static BOOL CDECL nulldrv_SwapBuffers( PHYSDEV dev )
726 return TRUE;
729 static BOOL CDECL nulldrv_UnrealizePalette( HPALETTE palette )
731 return FALSE;
734 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
736 return FALSE;
739 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
741 return 0;
744 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
746 return 0;
749 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
751 return FALSE;
754 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
756 return NULL;
759 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
761 return 0;
764 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
766 return FALSE;
769 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
771 return FALSE;
774 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
775 const PIXELFORMATDESCRIPTOR *descr )
777 return FALSE;
780 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
782 return FALSE;
785 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
787 return FALSE;
790 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
792 return FALSE;
795 const DC_FUNCTIONS null_driver =
797 nulldrv_AbortDoc, /* pAbortDoc */
798 nulldrv_AbortPath, /* pAbortPath */
799 nulldrv_AlphaBlend, /* pAlphaBlend */
800 nulldrv_AngleArc, /* pAngleArc */
801 nulldrv_Arc, /* pArc */
802 nulldrv_ArcTo, /* pArcTo */
803 nulldrv_BeginPath, /* pBeginPath */
804 nulldrv_ChoosePixelFormat, /* pChoosePixelFormat */
805 nulldrv_Chord, /* pChord */
806 nulldrv_CloseFigure, /* pCloseFigure */
807 nulldrv_CreateBitmap, /* pCreateBitmap */
808 nulldrv_CreateDC, /* pCreateDC */
809 nulldrv_CreateDIBSection, /* pCreateDIBSection */
810 nulldrv_DeleteBitmap, /* pDeleteBitmap */
811 nulldrv_DeleteDC, /* pDeleteDC */
812 nulldrv_DeleteObject, /* pDeleteObject */
813 nulldrv_DescribePixelFormat, /* pDescribePixelFormat */
814 nulldrv_DeviceCapabilities, /* pDeviceCapabilities */
815 nulldrv_Ellipse, /* pEllipse */
816 nulldrv_EndDoc, /* pEndDoc */
817 nulldrv_EndPage, /* pEndPage */
818 nulldrv_EndPath, /* pEndPath */
819 nulldrv_EnumDeviceFonts, /* pEnumDeviceFonts */
820 nulldrv_EnumICMProfiles, /* pEnumICMProfiles */
821 nulldrv_ExcludeClipRect, /* pExcludeClipRect */
822 nulldrv_ExtDeviceMode, /* pExtDeviceMode */
823 nulldrv_ExtEscape, /* pExtEscape */
824 nulldrv_ExtFloodFill, /* pExtFloodFill */
825 nulldrv_ExtSelectClipRgn, /* pExtSelectClipRgn */
826 nulldrv_ExtTextOut, /* pExtTextOut */
827 nulldrv_FillPath, /* pFillPath */
828 nulldrv_FillRgn, /* pFillRgn */
829 nulldrv_FlattenPath, /* pFlattenPath */
830 nulldrv_FrameRgn, /* pFrameRgn */
831 nulldrv_GdiComment, /* pGdiComment */
832 nulldrv_GetBitmapBits, /* pGetBitmapBits */
833 nulldrv_GetCharWidth, /* pGetCharWidth */
834 nulldrv_GetDIBits, /* pGetDIBits */
835 nulldrv_GetDeviceCaps, /* pGetDeviceCaps */
836 nulldrv_GetDeviceGammaRamp, /* pGetDeviceGammaRamp */
837 nulldrv_GetICMProfile, /* pGetICMProfile */
838 nulldrv_GetNearestColor, /* pGetNearestColor */
839 nulldrv_GetPixel, /* pGetPixel */
840 nulldrv_GetPixelFormat, /* pGetPixelFormat */
841 nulldrv_GetSystemPaletteEntries, /* pGetSystemPaletteEntries */
842 nulldrv_GetTextExtentExPoint, /* pGetTextExtentExPoint */
843 nulldrv_GetTextMetrics, /* pGetTextMetrics */
844 nulldrv_IntersectClipRect, /* pIntersectClipRect */
845 nulldrv_InvertRgn, /* pInvertRgn */
846 nulldrv_LineTo, /* pLineTo */
847 nulldrv_ModifyWorldTransform, /* pModifyWorldTransform */
848 nulldrv_MoveTo, /* pMoveTo */
849 nulldrv_OffsetClipRgn, /* pOffsetClipRgn */
850 nulldrv_OffsetViewportOrgEx, /* pOffsetViewportOrg */
851 nulldrv_OffsetWindowOrgEx, /* pOffsetWindowOrg */
852 nulldrv_PaintRgn, /* pPaintRgn */
853 nulldrv_PatBlt, /* pPatBlt */
854 nulldrv_Pie, /* pPie */
855 nulldrv_PolyBezier, /* pPolyBezier */
856 nulldrv_PolyBezierTo, /* pPolyBezierTo */
857 nulldrv_PolyDraw, /* pPolyDraw */
858 nulldrv_PolyPolygon, /* pPolyPolygon */
859 nulldrv_PolyPolyline, /* pPolyPolyline */
860 nulldrv_Polygon, /* pPolygon */
861 nulldrv_Polyline, /* pPolyline */
862 nulldrv_PolylineTo, /* pPolylineTo */
863 nulldrv_RealizeDefaultPalette, /* pRealizeDefaultPalette */
864 nulldrv_RealizePalette, /* pRealizePalette */
865 nulldrv_Rectangle, /* pRectangle */
866 nulldrv_ResetDC, /* pResetDC */
867 nulldrv_RestoreDC, /* pRestoreDC */
868 nulldrv_RoundRect, /* pRoundRect */
869 nulldrv_SaveDC, /* pSaveDC */
870 nulldrv_ScaleViewportExtEx, /* pScaleViewportExt */
871 nulldrv_ScaleWindowExtEx, /* pScaleWindowExt */
872 nulldrv_SelectBitmap, /* pSelectBitmap */
873 nulldrv_SelectBrush, /* pSelectBrush */
874 nulldrv_SelectClipPath, /* pSelectClipPath */
875 nulldrv_SelectFont, /* pSelectFont */
876 nulldrv_SelectPalette, /* pSelectPalette */
877 nulldrv_SelectPen, /* pSelectPen */
878 nulldrv_SetArcDirection, /* pSetArcDirection */
879 nulldrv_SetBitmapBits, /* pSetBitmapBits */
880 nulldrv_SetBkColor, /* pSetBkColor */
881 nulldrv_SetBkMode, /* pSetBkMode */
882 nulldrv_SetDCBrushColor, /* pSetDCBrushColor */
883 nulldrv_SetDCPenColor, /* pSetDCPenColor */
884 nulldrv_SetDIBColorTable, /* pSetDIBColorTable */
885 nulldrv_SetDIBits, /* pSetDIBits */
886 nulldrv_SetDIBitsToDevice, /* pSetDIBitsToDevice */
887 nulldrv_SetDeviceClipping, /* pSetDeviceClipping */
888 nulldrv_SetDeviceGammaRamp, /* pSetDeviceGammaRamp */
889 nulldrv_SetLayout, /* pSetLayout */
890 nulldrv_SetMapMode, /* pSetMapMode */
891 nulldrv_SetMapperFlags, /* pSetMapperFlags */
892 nulldrv_SetPixel, /* pSetPixel */
893 nulldrv_SetPixelFormat, /* pSetPixelFormat */
894 nulldrv_SetPolyFillMode, /* pSetPolyFillMode */
895 nulldrv_SetROP2, /* pSetROP2 */
896 nulldrv_SetRelAbs, /* pSetRelAbs */
897 nulldrv_SetStretchBltMode, /* pSetStretchBltMode */
898 nulldrv_SetTextAlign, /* pSetTextAlign */
899 nulldrv_SetTextCharacterExtra, /* pSetTextCharacterExtra */
900 nulldrv_SetTextColor, /* pSetTextColor */
901 nulldrv_SetTextJustification, /* pSetTextJustification */
902 nulldrv_SetViewportExtEx, /* pSetViewportExt */
903 nulldrv_SetViewportOrgEx, /* pSetViewportOrg */
904 nulldrv_SetWindowExtEx, /* pSetWindowExt */
905 nulldrv_SetWindowOrgEx, /* pSetWindowOrg */
906 nulldrv_SetWorldTransform, /* pSetWorldTransform */
907 nulldrv_StartDoc, /* pStartDoc */
908 nulldrv_StartPage, /* pStartPage */
909 nulldrv_StretchBlt, /* pStretchBlt */
910 nulldrv_StretchDIBits, /* pStretchDIBits */
911 nulldrv_StrokeAndFillPath, /* pStrokeAndFillPath */
912 nulldrv_StrokePath, /* pStrokePath */
913 nulldrv_SwapBuffers, /* pSwapBuffers */
914 nulldrv_UnrealizePalette, /* pUnrealizePalette */
915 nulldrv_WidenPath, /* pWidenPath */
916 nulldrv_wglCopyContext, /* pwglCopyContext */
917 nulldrv_wglCreateContext, /* pwglCreateContext */
918 nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
919 nulldrv_wglDeleteContext, /* pwglDeleteContext */
920 nulldrv_wglGetProcAddress, /* pwglGetProcAddress */
921 nulldrv_wglGetPbufferDCARB, /* pwglGetPbufferDCARB */
922 nulldrv_wglMakeCurrent, /* pwglMakeCurrent */
923 nulldrv_wglMakeContextCurrentARB, /* pwglMakeContextCurrentARB */
924 nulldrv_wglSetPixelFormatWINE, /* pwglSetPixelFormatWINE */
925 nulldrv_wglShareLists, /* pwglShareLists */
926 nulldrv_wglUseFontBitmapsA, /* pwglUseFontBitmapsA */
927 nulldrv_wglUseFontBitmapsW, /* pwglUseFontBitmapsW */
931 /*****************************************************************************
932 * DRIVER_GetDriverName
935 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
937 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
938 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
939 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
940 static const WCHAR empty_strW[] = { 0 };
941 WCHAR *p;
943 /* display is a special case */
944 if (!strcmpiW( device, displayW ) ||
945 !strcmpiW( device, display1W ))
947 lstrcpynW( driver, displayW, size );
948 return TRUE;
951 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
952 if(!size) {
953 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
954 return FALSE;
956 p = strchrW(driver, ',');
957 if(!p)
959 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
960 return FALSE;
962 *p = 0;
963 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
964 return TRUE;
968 /***********************************************************************
969 * GdiConvertToDevmodeW (GDI32.@)
971 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
973 DEVMODEW *dmW;
974 WORD dmW_size, dmA_size;
976 dmA_size = dmA->dmSize;
978 /* this is the minimal dmSize that XP accepts */
979 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
980 return NULL;
982 if (dmA_size > sizeof(DEVMODEA))
983 dmA_size = sizeof(DEVMODEA);
985 dmW_size = dmA_size + CCHDEVICENAME;
986 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
987 dmW_size += CCHFORMNAME;
989 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
990 if (!dmW) return NULL;
992 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
993 dmW->dmDeviceName, CCHDEVICENAME);
994 /* copy slightly more, to avoid long computations */
995 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
997 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
999 if (dmA->dmFields & DM_FORMNAME)
1000 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
1001 dmW->dmFormName, CCHFORMNAME);
1002 else
1003 dmW->dmFormName[0] = 0;
1005 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
1006 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
1009 if (dmA->dmDriverExtra)
1010 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
1012 dmW->dmSize = dmW_size;
1014 return dmW;
1018 /*****************************************************************************
1019 * @ [GDI32.100]
1021 * This should thunk to 16-bit and simply call the proc with the given args.
1023 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
1024 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
1026 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
1027 return -1;
1030 /*****************************************************************************
1031 * @ [GDI32.101]
1033 * This should load the correct driver for lpszDevice and calls this driver's
1034 * ExtDeviceModePropSheet proc.
1036 * Note: The driver calls a callback routine for each property sheet page; these
1037 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
1038 * The layout of this structure is:
1040 * struct
1042 * DWORD nPages;
1043 * DWORD unknown;
1044 * HPROPSHEETPAGE pages[10];
1045 * };
1047 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
1048 LPCSTR lpszPort, LPVOID lpPropSheet )
1050 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
1051 return -1;
1054 /*****************************************************************************
1055 * @ [GDI32.102]
1057 * This should load the correct driver for lpszDevice and call this driver's
1058 * ExtDeviceMode proc.
1060 * FIXME: convert ExtDeviceMode to unicode in the driver interface
1062 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
1063 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
1064 LPSTR lpszPort, LPDEVMODEA lpdmInput,
1065 LPSTR lpszProfile, DWORD fwMode )
1067 WCHAR deviceW[300];
1068 WCHAR bufW[300];
1069 char buf[300];
1070 HDC hdc;
1071 DC *dc;
1072 INT ret = -1;
1074 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
1075 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
1077 if (!lpszDevice) return -1;
1078 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1080 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1082 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1084 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1086 if ((dc = get_dc_ptr( hdc )))
1088 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
1089 ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
1090 lpdmInput, lpszProfile, fwMode );
1091 release_dc_ptr( dc );
1093 DeleteDC( hdc );
1094 return ret;
1097 /****************************************************************************
1098 * @ [GDI32.103]
1100 * This should load the correct driver for lpszDevice and calls this driver's
1101 * AdvancedSetupDialog proc.
1103 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
1104 LPDEVMODEA devin, LPDEVMODEA devout )
1106 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
1107 return -1;
1110 /*****************************************************************************
1111 * @ [GDI32.104]
1113 * This should load the correct driver for lpszDevice and calls this driver's
1114 * DeviceCapabilities proc.
1116 * FIXME: convert DeviceCapabilities to unicode in the driver interface
1118 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
1119 WORD fwCapability, LPSTR lpszOutput,
1120 LPDEVMODEA lpdm )
1122 WCHAR deviceW[300];
1123 WCHAR bufW[300];
1124 char buf[300];
1125 HDC hdc;
1126 DC *dc;
1127 INT ret = -1;
1129 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1131 if (!lpszDevice) return -1;
1132 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1134 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1136 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1138 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1140 if ((dc = get_dc_ptr( hdc )))
1142 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1143 ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1144 fwCapability, lpszOutput, lpdm );
1145 release_dc_ptr( dc );
1147 DeleteDC( hdc );
1148 return ret;
1152 /************************************************************************
1153 * Escape [GDI32.@]
1155 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1157 INT ret;
1158 POINT *pt;
1160 switch (escape)
1162 case ABORTDOC:
1163 return AbortDoc( hdc );
1165 case ENDDOC:
1166 return EndDoc( hdc );
1168 case GETPHYSPAGESIZE:
1169 pt = out_data;
1170 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1171 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1172 return 1;
1174 case GETPRINTINGOFFSET:
1175 pt = out_data;
1176 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1177 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1178 return 1;
1180 case GETSCALINGFACTOR:
1181 pt = out_data;
1182 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1183 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1184 return 1;
1186 case NEWFRAME:
1187 return EndPage( hdc );
1189 case SETABORTPROC:
1190 return SetAbortProc( hdc, (ABORTPROC)in_data );
1192 case STARTDOC:
1194 DOCINFOA doc;
1195 char *name = NULL;
1197 /* in_data may not be 0 terminated so we must copy it */
1198 if (in_data)
1200 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1201 memcpy( name, in_data, in_count );
1202 name[in_count] = 0;
1204 /* out_data is actually a pointer to the DocInfo structure and used as
1205 * a second input parameter */
1206 if (out_data) doc = *(DOCINFOA *)out_data;
1207 else
1209 doc.cbSize = sizeof(doc);
1210 doc.lpszOutput = NULL;
1211 doc.lpszDatatype = NULL;
1212 doc.fwType = 0;
1214 doc.lpszDocName = name;
1215 ret = StartDocA( hdc, &doc );
1216 HeapFree( GetProcessHeap(), 0, name );
1217 if (ret > 0) ret = StartPage( hdc );
1218 return ret;
1221 case QUERYESCSUPPORT:
1223 const INT *ptr = (const INT *)in_data;
1224 if (in_count < sizeof(INT)) return 0;
1225 switch(*ptr)
1227 case ABORTDOC:
1228 case ENDDOC:
1229 case GETPHYSPAGESIZE:
1230 case GETPRINTINGOFFSET:
1231 case GETSCALINGFACTOR:
1232 case NEWFRAME:
1233 case QUERYESCSUPPORT:
1234 case SETABORTPROC:
1235 case STARTDOC:
1236 return TRUE;
1238 break;
1242 /* if not handled internally, pass it to the driver */
1243 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1247 /******************************************************************************
1248 * ExtEscape [GDI32.@]
1250 * Access capabilities of a particular device that are not available through GDI.
1252 * PARAMS
1253 * hdc [I] Handle to device context
1254 * nEscape [I] Escape function
1255 * cbInput [I] Number of bytes in input structure
1256 * lpszInData [I] Pointer to input structure
1257 * cbOutput [I] Number of bytes in output structure
1258 * lpszOutData [O] Pointer to output structure
1260 * RETURNS
1261 * Success: >0
1262 * Not implemented: 0
1263 * Failure: <0
1265 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1266 INT cbOutput, LPSTR lpszOutData )
1268 INT ret = 0;
1269 DC * dc = get_dc_ptr( hdc );
1271 if (dc)
1273 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1274 ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1275 release_dc_ptr( dc );
1277 return ret;
1281 /*******************************************************************
1282 * DrawEscape [GDI32.@]
1286 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1288 FIXME("DrawEscape, stub\n");
1289 return 0;
1292 /*******************************************************************
1293 * NamedEscape [GDI32.@]
1295 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1296 INT cbOutput, LPSTR lpszOutData )
1298 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1299 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1300 lpszOutData);
1301 return 0;
1304 /*******************************************************************
1305 * DdQueryDisplaySettingsUniqueness [GDI32.@]
1306 * GdiEntry13 [GDI32.@]
1308 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1310 static int warn_once;
1312 if (!warn_once++)
1313 FIXME("stub\n");
1314 return 0;