wined3d: Get rid of wined3d_buffer_get_desc().
[wine] / dlls / gdi32 / driver.c
1 /*
2  * Graphics driver management functions
3  *
4  * Copyright 1994 Bob Amstadt
5  * Copyright 1996, 2001 Alexandre Julliard
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "ddrawgdi.h"
32 #include "wine/winbase16.h"
33
34 #include "gdi_private.h"
35 #include "wine/unicode.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(driver);
40
41 struct graphics_driver
42 {
43     struct list             entry;
44     HMODULE                 module;  /* module handle */
45     DC_FUNCTIONS            funcs;
46 };
47
48 static struct list drivers = LIST_INIT( drivers );
49 static struct graphics_driver *display_driver;
50
51 static CRITICAL_SECTION driver_section;
52 static CRITICAL_SECTION_DEBUG critsect_debug =
53 {
54     0, 0, &driver_section,
55     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
56       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
57 };
58 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
59
60 /**********************************************************************
61  *           create_driver
62  *
63  * Allocate and fill the driver structure for a given module.
64  */
65 static struct graphics_driver *create_driver( HMODULE module )
66 {
67     struct graphics_driver *driver;
68
69     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
70     driver->module = module;
71
72     /* fill the function table */
73     if (module)
74     {
75 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
76         GET_FUNC(AbortDoc);
77         GET_FUNC(AbortPath);
78         GET_FUNC(AlphaBlend);
79         GET_FUNC(AngleArc);
80         GET_FUNC(Arc);
81         GET_FUNC(ArcTo);
82         GET_FUNC(BeginPath);
83         GET_FUNC(BitBlt);
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(SetMapMode);
169         GET_FUNC(SetMapperFlags);
170         GET_FUNC(SetPixel);
171         GET_FUNC(SetPixelFormat);
172         GET_FUNC(SetPolyFillMode);
173         GET_FUNC(SetROP2);
174         GET_FUNC(SetRelAbs);
175         GET_FUNC(SetStretchBltMode);
176         GET_FUNC(SetTextAlign);
177         GET_FUNC(SetTextCharacterExtra);
178         GET_FUNC(SetTextColor);
179         GET_FUNC(SetTextJustification);
180         GET_FUNC(SetViewportExtEx);
181         GET_FUNC(SetViewportOrgEx);
182         GET_FUNC(SetWindowExtEx);
183         GET_FUNC(SetWindowOrgEx);
184         GET_FUNC(SetWorldTransform);
185         GET_FUNC(StartDoc);
186         GET_FUNC(StartPage);
187         GET_FUNC(StretchBlt);
188         GET_FUNC(StretchDIBits);
189         GET_FUNC(StrokeAndFillPath);
190         GET_FUNC(StrokePath);
191         GET_FUNC(SwapBuffers);
192         GET_FUNC(UnrealizePalette);
193         GET_FUNC(WidenPath);
194
195         /* OpenGL32 */
196         GET_FUNC(wglCreateContext);
197         GET_FUNC(wglCreateContextAttribsARB);
198         GET_FUNC(wglDeleteContext);
199         GET_FUNC(wglGetProcAddress);
200         GET_FUNC(wglGetPbufferDCARB);
201         GET_FUNC(wglMakeContextCurrentARB);
202         GET_FUNC(wglMakeCurrent);
203         GET_FUNC(wglSetPixelFormatWINE);
204         GET_FUNC(wglShareLists);
205         GET_FUNC(wglUseFontBitmapsA);
206         GET_FUNC(wglUseFontBitmapsW);
207 #undef GET_FUNC
208     }
209     else memset( &driver->funcs, 0, sizeof(driver->funcs) );
210
211     return driver;
212 }
213
214
215 /**********************************************************************
216  *           DRIVER_get_display_driver
217  *
218  * Special case for loading the display driver: get the name from the config file
219  */
220 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
221 {
222     struct graphics_driver *driver;
223     char buffer[MAX_PATH], libname[32], *name, *next;
224     HMODULE module = 0;
225     HKEY hkey;
226
227     if (display_driver) return &display_driver->funcs;  /* already loaded */
228
229     strcpy( buffer, "x11" );  /* default value */
230     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
231     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
232     {
233         DWORD type, count = sizeof(buffer);
234         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
235         RegCloseKey( hkey );
236     }
237
238     name = buffer;
239     while (name)
240     {
241         next = strchr( name, ',' );
242         if (next) *next++ = 0;
243
244         snprintf( libname, sizeof(libname), "wine%s.drv", name );
245         if ((module = LoadLibraryA( libname )) != 0) break;
246         name = next;
247     }
248
249     if (!(driver = create_driver( module )))
250     {
251         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
252         FreeLibrary( module );
253         ExitProcess(1);
254     }
255     if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
256     {
257         /* somebody beat us to it */
258         FreeLibrary( driver->module );
259         HeapFree( GetProcessHeap(), 0, driver );
260     }
261     return &display_driver->funcs;
262 }
263
264
265 /**********************************************************************
266  *           DRIVER_load_driver
267  */
268 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
269 {
270     HMODULE module;
271     struct graphics_driver *driver, *new_driver;
272     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
273     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
274
275     /* display driver is a special case */
276     if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
277
278     if ((module = GetModuleHandleW( name )))
279     {
280         if (display_driver && display_driver->module == module) return &display_driver->funcs;
281         EnterCriticalSection( &driver_section );
282         LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
283         {
284             if (driver->module == module) goto done;
285         }
286         LeaveCriticalSection( &driver_section );
287     }
288
289     if (!(module = LoadLibraryW( name ))) return NULL;
290
291     if (!(new_driver = create_driver( module )))
292     {
293         FreeLibrary( module );
294         return NULL;
295     }
296
297     /* check if someone else added it in the meantime */
298     EnterCriticalSection( &driver_section );
299     LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
300     {
301         if (driver->module != module) continue;
302         FreeLibrary( module );
303         HeapFree( GetProcessHeap(), 0, new_driver );
304         goto done;
305     }
306     driver = new_driver;
307     list_add_head( &drivers, &driver->entry );
308     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
309 done:
310     LeaveCriticalSection( &driver_section );
311     return &driver->funcs;
312 }
313
314
315 static INT CDECL nulldrv_AbortDoc( PHYSDEV dev )
316 {
317     return 0;
318 }
319
320 static BOOL CDECL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
321                                INT xstart, INT ystart, INT xend, INT yend )
322 {
323     return TRUE;
324 }
325
326 static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
327                                  INT xstart, INT ystart, INT xend, INT yend )
328 {
329     return TRUE;
330 }
331
332 static BOOL CDECL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
333 {
334     return TRUE;
335 }
336
337 static BOOL CDECL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
338 {
339     return TRUE;
340 }
341
342 static INT CDECL nulldrv_EndDoc( PHYSDEV dev )
343 {
344     return 0;
345 }
346
347 static INT CDECL nulldrv_EndPage( PHYSDEV dev )
348 {
349     return 0;
350 }
351
352 static BOOL CDECL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
353 {
354     return TRUE;
355 }
356
357 static COLORREF CDECL nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
358 {
359     return 0;
360 }
361
362 static BOOL CDECL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
363 {
364     return TRUE;
365 }
366
367 static BOOL CDECL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
368 {
369     return TRUE;
370 }
371
372 static BOOL CDECL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
373 {
374     return TRUE;
375 }
376
377 static BOOL CDECL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
378                                INT xstart, INT ystart, INT xend, INT yend )
379 {
380     return TRUE;
381 }
382
383 static BOOL CDECL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
384 {
385     /* FIXME: could be implemented with Polygon */
386     return TRUE;
387 }
388
389 static BOOL CDECL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
390 {
391     /* FIXME: could be implemented with Polyline */
392     return TRUE;
393 }
394
395 static BOOL CDECL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
396 {
397     return TRUE;
398 }
399
400 static BOOL CDECL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
401 {
402     return TRUE;
403 }
404
405 static BOOL CDECL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
406 {
407     return TRUE;
408 }
409
410 static BOOL CDECL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
411                                      INT ell_width, INT ell_height )
412 {
413     return TRUE;
414 }
415
416 static HBITMAP CDECL nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
417 {
418     return bitmap;
419 }
420
421 static HBRUSH CDECL nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
422 {
423     return brush;
424 }
425
426 static HFONT CDECL nulldrv_SelectFont( PHYSDEV dev, HFONT font, HANDLE gdi_font )
427 {
428     return 0;
429 }
430
431 static HPALETTE CDECL nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
432 {
433     return palette;
434 }
435
436 static HPEN CDECL nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
437 {
438     return pen;
439 }
440
441 static INT CDECL nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
442 {
443     return dir;
444 }
445
446 static COLORREF CDECL nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
447 {
448     return color;
449 }
450
451 static INT CDECL nulldrv_SetBkMode( PHYSDEV dev, INT mode )
452 {
453     return mode;
454 }
455
456 static COLORREF CDECL nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
457 {
458     return color;
459 }
460
461 static COLORREF CDECL nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
462 {
463     return color;
464 }
465
466 static void CDECL nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
467 {
468 }
469
470 static DWORD CDECL nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
471 {
472     return layout;
473 }
474
475 static DWORD CDECL nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
476 {
477     return flags;
478 }
479
480 static COLORREF CDECL nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
481 {
482     return color;
483 }
484
485 static INT CDECL nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
486 {
487     return mode;
488 }
489
490 static INT CDECL nulldrv_SetROP2( PHYSDEV dev, INT rop )
491 {
492     return rop;
493 }
494
495 static INT CDECL nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
496 {
497     return mode;
498 }
499
500 static INT CDECL nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
501 {
502     return mode;
503 }
504
505 static UINT CDECL nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
506 {
507     return align;
508 }
509
510 static INT CDECL nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
511 {
512     return extra;
513 }
514
515 static COLORREF CDECL nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
516 {
517     return color;
518 }
519
520 static BOOL CDECL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
521 {
522     return TRUE;
523 }
524
525 static INT CDECL nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
526 {
527     return 0;
528 }
529
530 static INT CDECL nulldrv_StartPage( PHYSDEV dev )
531 {
532     return 1;
533 }
534
535 static BOOL CDECL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
536 {
537     return FALSE;
538 }
539
540 static HGLRC CDECL nulldrv_wglCreateContext( PHYSDEV dev )
541 {
542     return 0;
543 }
544
545 static HGLRC CDECL nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
546 {
547     return 0;
548 }
549
550 static BOOL CDECL nulldrv_wglDeleteContext( HGLRC ctx )
551 {
552     return FALSE;
553 }
554
555 static PROC CDECL nulldrv_wglGetProcAddress( LPCSTR name )
556 {
557     return NULL;
558 }
559
560 static HDC CDECL nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
561 {
562     return 0;
563 }
564
565 static BOOL CDECL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
566 {
567     return FALSE;
568 }
569
570 static BOOL CDECL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
571 {
572     return FALSE;
573 }
574
575 static BOOL CDECL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format,
576                                                  const PIXELFORMATDESCRIPTOR *descr )
577 {
578     return FALSE;
579 }
580
581 static BOOL CDECL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
582 {
583     return FALSE;
584 }
585
586 static BOOL CDECL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
587 {
588     return FALSE;
589 }
590
591 static BOOL CDECL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
592 {
593     return FALSE;
594 }
595
596 const DC_FUNCTIONS null_driver =
597 {
598     nulldrv_AbortDoc,                   /* pAbortDoc */
599     NULL,                               /* pAbortPath */
600     NULL,                               /* pAlphaBlend */
601     nulldrv_AngleArc,                   /* pAngleArc */
602     nulldrv_Arc,                        /* pArc */
603     nulldrv_ArcTo,                      /* pArcTo */
604     NULL,                               /* pBeginPath */
605     NULL,                               /* pBitBlt */
606     NULL,                               /* pChoosePixelFormat */
607     nulldrv_Chord,                      /* pChord */
608     NULL,                               /* pCloseFigure */
609     NULL,                               /* pCreateBitmap */
610     NULL,                               /* pCreateDC */
611     NULL,                               /* pCreateDIBSection */
612     NULL,                               /* pDeleteBitmap */
613     NULL,                               /* pDeleteDC */
614     nulldrv_DeleteObject,               /* pDeleteObject */
615     NULL,                               /* pDescribePixelFormat */
616     NULL,                               /* pDeviceCapabilities */
617     nulldrv_Ellipse,                    /* pEllipse */
618     nulldrv_EndDoc,                     /* pEndDoc */
619     nulldrv_EndPage,                    /* pEndPage */
620     NULL,                               /* pEndPath */
621     NULL,                               /* pEnumICMProfiles */
622     NULL,                               /* pEnumDeviceFonts */
623     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
624     NULL,                               /* pExtDeviceMode */
625     NULL,                               /* pExtEscape */
626     nulldrv_ExtFloodFill,               /* pExtFloodFill */
627     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
628     NULL,                               /* pExtTextOut */
629     NULL,                               /* pFillPath */
630     nulldrv_FillRgn,                    /* pFillRgn */
631     NULL,                               /* pFlattenPath */
632     nulldrv_FrameRgn,                   /* pFrameRgn */
633     NULL,                               /* pGdiComment */
634     NULL,                               /* pGetBitmapBits */
635     NULL,                               /* pGetCharWidth */
636     NULL,                               /* pGetDIBits */
637     NULL,                               /* pGetDeviceCaps */
638     NULL,                               /* pGetDeviceGammaRamp */
639     NULL,                               /* pGetICMProfile */
640     NULL,                               /* pGetNearestColor */
641     nulldrv_GetPixel,                   /* pGetPixel */
642     NULL,                               /* pGetPixelFormat */
643     NULL,                               /* pGetSystemPaletteEntries */
644     NULL,                               /* pGetTextExtentExPoint */
645     NULL,                               /* pGetTextMetrics */
646     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
647     nulldrv_InvertRgn,                  /* pInvertRgn */
648     nulldrv_LineTo,                     /* pLineTo */
649     NULL,                               /* pModifyWorldTransform */
650     nulldrv_MoveTo,                     /* pMoveTo */
651     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
652     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
653     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
654     nulldrv_PaintRgn,                   /* pPaintRgn */
655     NULL,                               /* pPatBlt */
656     nulldrv_Pie,                        /* pPie */
657     nulldrv_PolyBezier,                 /* pPolyBezier */
658     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
659     nulldrv_PolyDraw,                   /* pPolyDraw */
660     nulldrv_PolyPolygon,                /* pPolyPolygon */
661     nulldrv_PolyPolyline,               /* pPolyPolyline */
662     nulldrv_Polygon,                    /* pPolygon */
663     nulldrv_Polyline,                   /* pPolyline */
664     nulldrv_PolylineTo,                 /* pPolylineTo */
665     NULL,                               /* pRealizeDefaultPalette */
666     NULL,                               /* pRealizePalette */
667     nulldrv_Rectangle,                  /* pRectangle */
668     NULL,                               /* pResetDC */
669     NULL,                               /* pRestoreDC */
670     nulldrv_RoundRect,                  /* pRoundRect */
671     NULL,                               /* pSaveDC */
672     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
673     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
674     nulldrv_SelectBitmap,               /* pSelectBitmap */
675     nulldrv_SelectBrush,                /* pSelectBrush */
676     NULL,                               /* pSelectClipPath */
677     nulldrv_SelectFont,                 /* pSelectFont */
678     nulldrv_SelectPalette,              /* pSelectPalette */
679     nulldrv_SelectPen,                  /* pSelectPen */
680     nulldrv_SetArcDirection,            /* pSetArcDirection */
681     NULL,                               /* pSetBitmapBits */
682     nulldrv_SetBkColor,                 /* pSetBkColor */
683     nulldrv_SetBkMode,                  /* pSetBkMode */
684     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
685     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
686     NULL,                               /* pSetDIBColorTable */
687     NULL,                               /* pSetDIBits */
688     NULL,                               /* pSetDIBitsToDevice */
689     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
690     NULL,                               /* pSetDeviceGammaRamp */
691     nulldrv_SetLayout,                  /* pSetLayout */
692     nulldrv_SetMapMode,                 /* pSetMapMode */
693     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
694     nulldrv_SetPixel,                   /* pSetPixel */
695     NULL,                               /* pSetPixelFormat */
696     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
697     nulldrv_SetROP2,                    /* pSetROP2 */
698     nulldrv_SetRelAbs,                  /* pSetRelAbs */
699     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
700     nulldrv_SetTextAlign,               /* pSetTextAlign */
701     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
702     nulldrv_SetTextColor,               /* pSetTextColor */
703     nulldrv_SetTextJustification,       /* pSetTextJustification */
704     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
705     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
706     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
707     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
708     NULL,                               /* pSetWorldTransform */
709     nulldrv_StartDoc,                   /* pStartDoc */
710     nulldrv_StartPage,                  /* pStartPage */
711     NULL,                               /* pStretchBlt */
712     NULL,                               /* pStretchDIBits */
713     NULL,                               /* pStrokeAndFillPath */
714     NULL,                               /* pStrokePath */
715     NULL,                               /* pSwapBuffers */
716     NULL,                               /* pUnrealizePalette */
717     NULL,                               /* pWidenPath */
718     nulldrv_wglCopyContext,             /* pwglCopyContext */
719     nulldrv_wglCreateContext,           /* pwglCreateContext */
720     nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
721     nulldrv_wglDeleteContext,           /* pwglDeleteContext */
722     nulldrv_wglGetProcAddress,          /* pwglGetProcAddress */
723     nulldrv_wglGetPbufferDCARB,         /* pwglGetPbufferDCARB */
724     nulldrv_wglMakeCurrent,             /* pwglMakeCurrent */
725     nulldrv_wglMakeContextCurrentARB,   /* pwglMakeContextCurrentARB */
726     nulldrv_wglSetPixelFormatWINE,      /* pwglSetPixelFormatWINE */
727     nulldrv_wglShareLists,              /* pwglShareLists */
728     nulldrv_wglUseFontBitmapsA,         /* pwglUseFontBitmapsA */
729     nulldrv_wglUseFontBitmapsW,         /* pwglUseFontBitmapsW */
730 };
731
732
733 /*****************************************************************************
734  *      DRIVER_GetDriverName
735  *
736  */
737 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
738 {
739     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
740     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
741     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
742     static const WCHAR empty_strW[] = { 0 };
743     WCHAR *p;
744
745     /* display is a special case */
746     if (!strcmpiW( device, displayW ) ||
747         !strcmpiW( device, display1W ))
748     {
749         lstrcpynW( driver, displayW, size );
750         return TRUE;
751     }
752
753     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
754     if(!size) {
755         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
756         return FALSE;
757     }
758     p = strchrW(driver, ',');
759     if(!p)
760     {
761         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
762         return FALSE;
763     }
764     *p = 0;
765     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
766     return TRUE;
767 }
768
769
770 /***********************************************************************
771  *           GdiConvertToDevmodeW    (GDI32.@)
772  */
773 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
774 {
775     DEVMODEW *dmW;
776     WORD dmW_size, dmA_size;
777
778     dmA_size = dmA->dmSize;
779
780     /* this is the minimal dmSize that XP accepts */
781     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
782         return NULL;
783
784     if (dmA_size > sizeof(DEVMODEA))
785         dmA_size = sizeof(DEVMODEA);
786
787     dmW_size = dmA_size + CCHDEVICENAME;
788     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
789         dmW_size += CCHFORMNAME;
790
791     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
792     if (!dmW) return NULL;
793
794     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
795                                    dmW->dmDeviceName, CCHDEVICENAME);
796     /* copy slightly more, to avoid long computations */
797     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
798
799     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
800     {
801         if (dmA->dmFields & DM_FORMNAME)
802             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
803                                        dmW->dmFormName, CCHFORMNAME);
804         else
805             dmW->dmFormName[0] = 0;
806
807         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
808             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
809     }
810
811     if (dmA->dmDriverExtra)
812         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
813
814     dmW->dmSize = dmW_size;
815
816     return dmW;
817 }
818
819
820 /*****************************************************************************
821  *      @ [GDI32.100]
822  *
823  * This should thunk to 16-bit and simply call the proc with the given args.
824  */
825 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
826                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
827 {
828     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
829     return -1;
830 }
831
832 /*****************************************************************************
833  *      @ [GDI32.101]
834  *
835  * This should load the correct driver for lpszDevice and calls this driver's
836  * ExtDeviceModePropSheet proc.
837  *
838  * Note: The driver calls a callback routine for each property sheet page; these
839  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
840  * The layout of this structure is:
841  *
842  * struct
843  * {
844  *   DWORD  nPages;
845  *   DWORD  unknown;
846  *   HPROPSHEETPAGE  pages[10];
847  * };
848  */
849 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
850                                              LPCSTR lpszPort, LPVOID lpPropSheet )
851 {
852     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
853     return -1;
854 }
855
856 /*****************************************************************************
857  *      @ [GDI32.102]
858  *
859  * This should load the correct driver for lpszDevice and call this driver's
860  * ExtDeviceMode proc.
861  *
862  * FIXME: convert ExtDeviceMode to unicode in the driver interface
863  */
864 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
865                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
866                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
867                                     LPSTR lpszProfile, DWORD fwMode )
868 {
869     WCHAR deviceW[300];
870     WCHAR bufW[300];
871     char buf[300];
872     HDC hdc;
873     DC *dc;
874     INT ret = -1;
875
876     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
877           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
878
879     if (!lpszDevice) return -1;
880     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
881
882     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
883
884     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
885
886     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
887
888     if ((dc = get_dc_ptr( hdc )))
889     {
890         if (dc->funcs->pExtDeviceMode)
891             ret = dc->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
892                                              lpdmInput, lpszProfile, fwMode );
893         release_dc_ptr( dc );
894     }
895     DeleteDC( hdc );
896     return ret;
897 }
898
899 /****************************************************************************
900  *      @ [GDI32.103]
901  *
902  * This should load the correct driver for lpszDevice and calls this driver's
903  * AdvancedSetupDialog proc.
904  */
905 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
906                                           LPDEVMODEA devin, LPDEVMODEA devout )
907 {
908     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
909     return -1;
910 }
911
912 /*****************************************************************************
913  *      @ [GDI32.104]
914  *
915  * This should load the correct driver for lpszDevice and calls this driver's
916  * DeviceCapabilities proc.
917  *
918  * FIXME: convert DeviceCapabilities to unicode in the driver interface
919  */
920 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
921                                            WORD fwCapability, LPSTR lpszOutput,
922                                            LPDEVMODEA lpdm )
923 {
924     WCHAR deviceW[300];
925     WCHAR bufW[300];
926     char buf[300];
927     HDC hdc;
928     DC *dc;
929     INT ret = -1;
930
931     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
932
933     if (!lpszDevice) return -1;
934     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
935
936     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
937
938     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
939
940     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
941
942     if ((dc = get_dc_ptr( hdc )))
943     {
944         if (dc->funcs->pDeviceCapabilities)
945             ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
946                                                   fwCapability, lpszOutput, lpdm );
947         release_dc_ptr( dc );
948     }
949     DeleteDC( hdc );
950     return ret;
951 }
952
953
954 /************************************************************************
955  *             Escape  [GDI32.@]
956  */
957 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
958 {
959     INT ret;
960     POINT *pt;
961
962     switch (escape)
963     {
964     case ABORTDOC:
965         return AbortDoc( hdc );
966
967     case ENDDOC:
968         return EndDoc( hdc );
969
970     case GETPHYSPAGESIZE:
971         pt = out_data;
972         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
973         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
974         return 1;
975
976     case GETPRINTINGOFFSET:
977         pt = out_data;
978         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
979         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
980         return 1;
981
982     case GETSCALINGFACTOR:
983         pt = out_data;
984         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
985         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
986         return 1;
987
988     case NEWFRAME:
989         return EndPage( hdc );
990
991     case SETABORTPROC:
992         return SetAbortProc( hdc, (ABORTPROC)in_data );
993
994     case STARTDOC:
995         {
996             DOCINFOA doc;
997             char *name = NULL;
998
999             /* in_data may not be 0 terminated so we must copy it */
1000             if (in_data)
1001             {
1002                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1003                 memcpy( name, in_data, in_count );
1004                 name[in_count] = 0;
1005             }
1006             /* out_data is actually a pointer to the DocInfo structure and used as
1007              * a second input parameter */
1008             if (out_data) doc = *(DOCINFOA *)out_data;
1009             else
1010             {
1011                 doc.cbSize = sizeof(doc);
1012                 doc.lpszOutput = NULL;
1013                 doc.lpszDatatype = NULL;
1014                 doc.fwType = 0;
1015             }
1016             doc.lpszDocName = name;
1017             ret = StartDocA( hdc, &doc );
1018             HeapFree( GetProcessHeap(), 0, name );
1019             if (ret > 0) ret = StartPage( hdc );
1020             return ret;
1021         }
1022
1023     case QUERYESCSUPPORT:
1024         {
1025             const INT *ptr = (const INT *)in_data;
1026             if (in_count < sizeof(INT)) return 0;
1027             switch(*ptr)
1028             {
1029             case ABORTDOC:
1030             case ENDDOC:
1031             case GETPHYSPAGESIZE:
1032             case GETPRINTINGOFFSET:
1033             case GETSCALINGFACTOR:
1034             case NEWFRAME:
1035             case QUERYESCSUPPORT:
1036             case SETABORTPROC:
1037             case STARTDOC:
1038                 return TRUE;
1039             }
1040             break;
1041         }
1042     }
1043
1044     /* if not handled internally, pass it to the driver */
1045     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1046 }
1047
1048
1049 /******************************************************************************
1050  *              ExtEscape       [GDI32.@]
1051  *
1052  * Access capabilities of a particular device that are not available through GDI.
1053  *
1054  * PARAMS
1055  *    hdc         [I] Handle to device context
1056  *    nEscape     [I] Escape function
1057  *    cbInput     [I] Number of bytes in input structure
1058  *    lpszInData  [I] Pointer to input structure
1059  *    cbOutput    [I] Number of bytes in output structure
1060  *    lpszOutData [O] Pointer to output structure
1061  *
1062  * RETURNS
1063  *    Success: >0
1064  *    Not implemented: 0
1065  *    Failure: <0
1066  */
1067 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1068                       INT cbOutput, LPSTR lpszOutData )
1069 {
1070     INT ret = 0;
1071     DC * dc = get_dc_ptr( hdc );
1072     if (dc)
1073     {
1074         if (dc->funcs->pExtEscape)
1075             ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1076         release_dc_ptr( dc );
1077     }
1078     return ret;
1079 }
1080
1081
1082 /*******************************************************************
1083  *      DrawEscape [GDI32.@]
1084  *
1085  *
1086  */
1087 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1088 {
1089     FIXME("DrawEscape, stub\n");
1090     return 0;
1091 }
1092
1093 /*******************************************************************
1094  *      NamedEscape [GDI32.@]
1095  */
1096 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1097                         INT cbOutput, LPSTR lpszOutData )
1098 {
1099     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1100           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1101           lpszOutData);
1102     return 0;
1103 }
1104
1105 /*******************************************************************
1106  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1107  *      GdiEntry13                       [GDI32.@]
1108  */
1109 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1110 {
1111     static int warn_once;
1112
1113     if (!warn_once++)
1114         FIXME("stub\n");
1115     return 0;
1116 }