gdi32: Support OpenGL in bitmaps through libOSMesa.
[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 <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"
34
35 #include "gdi_private.h"
36 #include "wine/unicode.h"
37 #include "wine/list.h"
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(driver);
41
42 struct graphics_driver
43 {
44     struct list                entry;
45     HMODULE                    module;  /* module handle */
46     const struct gdi_dc_funcs *funcs;
47 };
48
49 static struct list drivers = LIST_INIT( drivers );
50 static struct graphics_driver *display_driver;
51
52 const struct gdi_dc_funcs *font_driver = NULL;
53
54 static CRITICAL_SECTION driver_section;
55 static CRITICAL_SECTION_DEBUG critsect_debug =
56 {
57     0, 0, &driver_section,
58     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
59       0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
60 };
61 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
62
63 /**********************************************************************
64  *           create_driver
65  *
66  * Allocate and fill the driver structure for a given module.
67  */
68 static struct graphics_driver *create_driver( HMODULE module )
69 {
70     static const struct gdi_dc_funcs empty_funcs;
71     const struct gdi_dc_funcs *funcs = NULL;
72     struct graphics_driver *driver;
73
74     if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
75     driver->module = module;
76
77     if (module)
78     {
79         const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
80
81         if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
82             funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
83     }
84     if (!funcs) funcs = &empty_funcs;
85     driver->funcs = funcs;
86     return driver;
87 }
88
89
90 /**********************************************************************
91  *           get_display_driver
92  *
93  * Special case for loading the display driver: get the name from the config file
94  */
95 static const struct gdi_dc_funcs *get_display_driver(void)
96 {
97     struct graphics_driver *driver;
98     char buffer[MAX_PATH], libname[32], *name, *next;
99     HMODULE module = 0;
100     HKEY hkey;
101
102     if (display_driver) return display_driver->funcs;  /* already loaded */
103
104     strcpy( buffer, "x11" );  /* default value */
105     /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
106     if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
107     {
108         DWORD type, count = sizeof(buffer);
109         RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
110         RegCloseKey( hkey );
111     }
112
113     name = buffer;
114     while (name)
115     {
116         next = strchr( name, ',' );
117         if (next) *next++ = 0;
118
119         snprintf( libname, sizeof(libname), "wine%s.drv", name );
120         if ((module = LoadLibraryA( libname )) != 0) break;
121         name = next;
122     }
123
124     if (!(driver = create_driver( module )))
125     {
126         MESSAGE( "Could not create graphics driver '%s'\n", buffer );
127         FreeLibrary( module );
128         ExitProcess(1);
129     }
130     if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
131     {
132         /* somebody beat us to it */
133         FreeLibrary( driver->module );
134         HeapFree( GetProcessHeap(), 0, driver );
135     }
136     return display_driver->funcs;
137 }
138
139
140 /**********************************************************************
141  *           DRIVER_load_driver
142  */
143 const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
144 {
145     HMODULE module;
146     struct graphics_driver *driver, *new_driver;
147     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
148     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
149
150     /* display driver is a special case */
151     if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
152
153     if ((module = GetModuleHandleW( name )))
154     {
155         if (display_driver && display_driver->module == module) return display_driver->funcs;
156         EnterCriticalSection( &driver_section );
157         LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
158         {
159             if (driver->module == module) goto done;
160         }
161         LeaveCriticalSection( &driver_section );
162     }
163
164     if (!(module = LoadLibraryW( name ))) return NULL;
165
166     if (!(new_driver = create_driver( module )))
167     {
168         FreeLibrary( module );
169         return NULL;
170     }
171
172     /* check if someone else added it in the meantime */
173     EnterCriticalSection( &driver_section );
174     LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
175     {
176         if (driver->module != module) continue;
177         FreeLibrary( module );
178         HeapFree( GetProcessHeap(), 0, new_driver );
179         goto done;
180     }
181     driver = new_driver;
182     list_add_head( &drivers, &driver->entry );
183     TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
184 done:
185     LeaveCriticalSection( &driver_section );
186     return driver->funcs;
187 }
188
189
190 static INT nulldrv_AbortDoc( PHYSDEV dev )
191 {
192     return 0;
193 }
194
195 static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
196                          INT xstart, INT ystart, INT xend, INT yend )
197 {
198     return TRUE;
199 }
200
201 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
202                            INT xstart, INT ystart, INT xend, INT yend )
203 {
204     return TRUE;
205 }
206
207 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
208 {
209     if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
210     return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
211 }
212
213 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
214                               LPCWSTR output, const DEVMODEW *devmode )
215 {
216     assert(0);  /* should never be called */
217     return FALSE;
218 }
219
220 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
221 {
222     assert(0);  /* should never be called */
223     return TRUE;
224 }
225
226 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
227 {
228     return TRUE;
229 }
230
231 static INT nulldrv_DescribePixelFormat( PHYSDEV dev, INT format, UINT size, PIXELFORMATDESCRIPTOR * descr )
232 {
233     return 0;
234 }
235
236 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
237                                          WORD cap, LPSTR output, DEVMODEA *devmode )
238 {
239     return -1;
240 }
241
242 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
243 {
244     return TRUE;
245 }
246
247 static INT nulldrv_EndDoc( PHYSDEV dev )
248 {
249     return 0;
250 }
251
252 static INT nulldrv_EndPage( PHYSDEV dev )
253 {
254     return 0;
255 }
256
257 static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
258 {
259     return TRUE;
260 }
261
262 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
263 {
264     return -1;
265 }
266
267 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
268                                   LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
269 {
270     return -1;
271 }
272
273 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
274                                     INT out_size, void *out_data )
275 {
276     return 0;
277 }
278
279 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
280 {
281     return TRUE;
282 }
283
284 static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
285 {
286     return FALSE;
287 }
288
289 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
290 {
291     return FALSE;
292 }
293
294 static BOOL nulldrv_GdiRealizationInfo( PHYSDEV dev, void *info )
295 {
296     return FALSE;
297 }
298
299 static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
300 {
301     return DCB_RESET;
302 }
303
304 static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
305 {
306     return FALSE;
307 }
308
309 static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
310 {
311     return FALSE;
312 }
313
314 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
315 {
316     return FALSE;
317 }
318
319 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
320 {
321     switch (cap)  /* return meaningful values for some entries */
322     {
323     case HORZRES:     return 640;
324     case VERTRES:     return 480;
325     case BITSPIXEL:   return 1;
326     case PLANES:      return 1;
327     case NUMCOLORS:   return 2;
328     case ASPECTX:     return 36;
329     case ASPECTY:     return 36;
330     case ASPECTXY:    return 51;
331     case LOGPIXELSX:  return 72;
332     case LOGPIXELSY:  return 72;
333     case SIZEPALETTE: return 2;
334     case TEXTCAPS:    return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
335                               TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
336                               TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
337     default:          return 0;
338     }
339 }
340
341 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
342 {
343     SetLastError( ERROR_INVALID_PARAMETER );
344     return FALSE;
345 }
346
347 static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
348 {
349     return FALSE;
350 }
351
352 static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
353 {
354     return 0;
355 }
356
357 static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
358 {
359     return GDI_ERROR;
360 }
361
362 static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
363                                       DWORD size, LPVOID buffer, const MAT2 *mat )
364 {
365     return GDI_ERROR;
366 }
367
368 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
369 {
370     return FALSE;
371 }
372
373 static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
374                                struct bitblt_coords *src )
375 {
376     return ERROR_NOT_SUPPORTED;
377 }
378
379 static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
380 {
381     return 0;
382 }
383
384 static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
385 {
386     return 0;
387 }
388
389 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
390 {
391     return 0;
392 }
393
394 static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
395 {
396     return DEFAULT_CHARSET;
397 }
398
399 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
400                                           INT *fit, INT *dx, SIZE *size )
401 {
402     return FALSE;
403 }
404
405 static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT max_ext,
406                                            INT *fit, INT *dx, SIZE *size )
407 {
408     return FALSE;
409 }
410
411 static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
412 {
413     INT ret = 0;
414     LOGFONTW font;
415     HFONT hfont = GetCurrentObject( dev->hdc, OBJ_FONT );
416
417     if (GetObjectW( hfont, sizeof(font), &font ))
418     {
419         ret = strlenW( font.lfFaceName ) + 1;
420         if (name)
421         {
422             lstrcpynW( name, font.lfFaceName, size );
423             ret = min( size, ret );
424         }
425     }
426     return ret;
427 }
428
429 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
430 {
431     return FALSE;
432 }
433
434 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
435 {
436     return TRUE;
437 }
438
439 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
440 {
441     return TRUE;
442 }
443
444 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
445 {
446     return TRUE;
447 }
448
449 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
450 {
451     return TRUE;
452 }
453
454 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
455                          INT xstart, INT ystart, INT xend, INT yend )
456 {
457     return TRUE;
458 }
459
460 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
461 {
462     return TRUE;
463 }
464
465 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
466 {
467     return TRUE;
468 }
469
470 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
471 {
472     INT counts[1] = { count };
473
474     return PolyPolygon( dev->hdc, points, counts, 1 );
475 }
476
477 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
478 {
479     DWORD counts[1] = { count };
480
481     if (count < 0) return FALSE;
482     return PolyPolyline( dev->hdc, points, counts, 1 );
483 }
484
485 static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
486                                const struct gdi_image_bits *bits, struct bitblt_coords *src,
487                                struct bitblt_coords *dst, DWORD rop )
488 {
489     return ERROR_SUCCESS;
490 }
491
492 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
493 {
494     return 0;
495 }
496
497 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
498 {
499     return 0;
500 }
501
502 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
503 {
504     return TRUE;
505 }
506
507 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
508 {
509     return 0;
510 }
511
512 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
513                                INT ell_width, INT ell_height )
514 {
515     return TRUE;
516 }
517
518 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
519 {
520     return bitmap;
521 }
522
523 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
524 {
525     return brush;
526 }
527
528 static HFONT nulldrv_SelectFont( PHYSDEV dev, HFONT font )
529 {
530     return 0;
531 }
532
533 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
534 {
535     return palette;
536 }
537
538 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
539 {
540     return pen;
541 }
542
543 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
544 {
545     return dir;
546 }
547
548 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
549 {
550     return color;
551 }
552
553 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
554 {
555     return mode;
556 }
557
558 static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
559 {
560     return DCB_RESET;
561 }
562
563 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
564 {
565     return color;
566 }
567
568 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
569 {
570     return color;
571 }
572
573 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
574 {
575 }
576
577 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
578 {
579     return layout;
580 }
581
582 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
583 {
584     SetLastError( ERROR_INVALID_PARAMETER );
585     return FALSE;
586 }
587
588 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
589 {
590     return flags;
591 }
592
593 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
594 {
595     return color;
596 }
597
598 static BOOL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
599 {
600     return FALSE;
601 }
602
603 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
604 {
605     return mode;
606 }
607
608 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
609 {
610     return rop;
611 }
612
613 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
614 {
615     return mode;
616 }
617
618 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
619 {
620     return mode;
621 }
622
623 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
624 {
625     return align;
626 }
627
628 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
629 {
630     return extra;
631 }
632
633 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
634 {
635     return color;
636 }
637
638 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
639 {
640     return TRUE;
641 }
642
643 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
644 {
645     return 0;
646 }
647
648 static INT nulldrv_StartPage( PHYSDEV dev )
649 {
650     return 1;
651 }
652
653 static BOOL nulldrv_SwapBuffers( PHYSDEV dev )
654 {
655     return TRUE;
656 }
657
658 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
659 {
660     return FALSE;
661 }
662
663 static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
664 {
665     return (void *)-1;
666 }
667
668 const struct gdi_dc_funcs null_driver =
669 {
670     nulldrv_AbortDoc,                   /* pAbortDoc */
671     nulldrv_AbortPath,                  /* pAbortPath */
672     nulldrv_AlphaBlend,                 /* pAlphaBlend */
673     nulldrv_AngleArc,                   /* pAngleArc */
674     nulldrv_Arc,                        /* pArc */
675     nulldrv_ArcTo,                      /* pArcTo */
676     nulldrv_BeginPath,                  /* pBeginPath */
677     nulldrv_BlendImage,                 /* pBlendImage */
678     nulldrv_Chord,                      /* pChord */
679     nulldrv_CloseFigure,                /* pCloseFigure */
680     nulldrv_CreateCompatibleDC,         /* pCreateCompatibleDC */
681     nulldrv_CreateDC,                   /* pCreateDC */
682     nulldrv_DeleteDC,                   /* pDeleteDC */
683     nulldrv_DeleteObject,               /* pDeleteObject */
684     nulldrv_DescribePixelFormat,        /* pDescribePixelFormat */
685     nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
686     nulldrv_Ellipse,                    /* pEllipse */
687     nulldrv_EndDoc,                     /* pEndDoc */
688     nulldrv_EndPage,                    /* pEndPage */
689     nulldrv_EndPath,                    /* pEndPath */
690     nulldrv_EnumFonts,                  /* pEnumFonts */
691     nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
692     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
693     nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
694     nulldrv_ExtEscape,                  /* pExtEscape */
695     nulldrv_ExtFloodFill,               /* pExtFloodFill */
696     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
697     nulldrv_ExtTextOut,                 /* pExtTextOut */
698     nulldrv_FillPath,                   /* pFillPath */
699     nulldrv_FillRgn,                    /* pFillRgn */
700     nulldrv_FlattenPath,                /* pFlattenPath */
701     nulldrv_FontIsLinked,               /* pFontIsLinked */
702     nulldrv_FrameRgn,                   /* pFrameRgn */
703     nulldrv_GdiComment,                 /* pGdiComment */
704     nulldrv_GdiRealizationInfo,         /* pGdiRealizationInfo */
705     nulldrv_GetBoundsRect,              /* pGetBoundsRect */
706     nulldrv_GetCharABCWidths,           /* pGetCharABCWidths */
707     nulldrv_GetCharABCWidthsI,          /* pGetCharABCWidthsI */
708     nulldrv_GetCharWidth,               /* pGetCharWidth */
709     nulldrv_GetDeviceCaps,              /* pGetDeviceCaps */
710     nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
711     nulldrv_GetFontData,                /* pGetFontData */
712     nulldrv_GetFontUnicodeRanges,       /* pGetFontUnicodeRanges */
713     nulldrv_GetGlyphIndices,            /* pGetGlyphIndices */
714     nulldrv_GetGlyphOutline,            /* pGetGlyphOutline */
715     nulldrv_GetICMProfile,              /* pGetICMProfile */
716     nulldrv_GetImage,                   /* pGetImage */
717     nulldrv_GetKerningPairs,            /* pGetKerningPairs */
718     nulldrv_GetNearestColor,            /* pGetNearestColor */
719     nulldrv_GetOutlineTextMetrics,      /* pGetOutlineTextMetrics */
720     nulldrv_GetPixel,                   /* pGetPixel */
721     nulldrv_GetSystemPaletteEntries,    /* pGetSystemPaletteEntries */
722     nulldrv_GetTextCharsetInfo,         /* pGetTextCharsetInfo */
723     nulldrv_GetTextExtentExPoint,       /* pGetTextExtentExPoint */
724     nulldrv_GetTextExtentExPointI,      /* pGetTextExtentExPointI */
725     nulldrv_GetTextFace,                /* pGetTextFace */
726     nulldrv_GetTextMetrics,             /* pGetTextMetrics */
727     nulldrv_GradientFill,               /* pGradientFill */
728     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
729     nulldrv_InvertRgn,                  /* pInvertRgn */
730     nulldrv_LineTo,                     /* pLineTo */
731     nulldrv_ModifyWorldTransform,       /* pModifyWorldTransform */
732     nulldrv_MoveTo,                     /* pMoveTo */
733     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
734     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
735     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
736     nulldrv_PaintRgn,                   /* pPaintRgn */
737     nulldrv_PatBlt,                     /* pPatBlt */
738     nulldrv_Pie,                        /* pPie */
739     nulldrv_PolyBezier,                 /* pPolyBezier */
740     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
741     nulldrv_PolyDraw,                   /* pPolyDraw */
742     nulldrv_PolyPolygon,                /* pPolyPolygon */
743     nulldrv_PolyPolyline,               /* pPolyPolyline */
744     nulldrv_Polygon,                    /* pPolygon */
745     nulldrv_Polyline,                   /* pPolyline */
746     nulldrv_PolylineTo,                 /* pPolylineTo */
747     nulldrv_PutImage,                   /* pPutImage */
748     nulldrv_RealizeDefaultPalette,      /* pRealizeDefaultPalette */
749     nulldrv_RealizePalette,             /* pRealizePalette */
750     nulldrv_Rectangle,                  /* pRectangle */
751     nulldrv_ResetDC,                    /* pResetDC */
752     nulldrv_RestoreDC,                  /* pRestoreDC */
753     nulldrv_RoundRect,                  /* pRoundRect */
754     nulldrv_SaveDC,                     /* pSaveDC */
755     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
756     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
757     nulldrv_SelectBitmap,               /* pSelectBitmap */
758     nulldrv_SelectBrush,                /* pSelectBrush */
759     nulldrv_SelectClipPath,             /* pSelectClipPath */
760     nulldrv_SelectFont,                 /* pSelectFont */
761     nulldrv_SelectPalette,              /* pSelectPalette */
762     nulldrv_SelectPen,                  /* pSelectPen */
763     nulldrv_SetArcDirection,            /* pSetArcDirection */
764     nulldrv_SetBkColor,                 /* pSetBkColor */
765     nulldrv_SetBkMode,                  /* pSetBkMode */
766     nulldrv_SetBoundsRect,              /* pSetBoundsRect */
767     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
768     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
769     nulldrv_SetDIBitsToDevice,          /* pSetDIBitsToDevice */
770     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
771     nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
772     nulldrv_SetLayout,                  /* pSetLayout */
773     nulldrv_SetMapMode,                 /* pSetMapMode */
774     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
775     nulldrv_SetPixel,                   /* pSetPixel */
776     nulldrv_SetPixelFormat,             /* pSetPixelFormat */
777     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
778     nulldrv_SetROP2,                    /* pSetROP2 */
779     nulldrv_SetRelAbs,                  /* pSetRelAbs */
780     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
781     nulldrv_SetTextAlign,               /* pSetTextAlign */
782     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
783     nulldrv_SetTextColor,               /* pSetTextColor */
784     nulldrv_SetTextJustification,       /* pSetTextJustification */
785     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
786     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
787     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
788     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
789     nulldrv_SetWorldTransform,          /* pSetWorldTransform */
790     nulldrv_StartDoc,                   /* pStartDoc */
791     nulldrv_StartPage,                  /* pStartPage */
792     nulldrv_StretchBlt,                 /* pStretchBlt */
793     nulldrv_StretchDIBits,              /* pStretchDIBits */
794     nulldrv_StrokeAndFillPath,          /* pStrokeAndFillPath */
795     nulldrv_StrokePath,                 /* pStrokePath */
796     nulldrv_SwapBuffers,                /* pSwapBuffers */
797     nulldrv_UnrealizePalette,           /* pUnrealizePalette */
798     nulldrv_WidenPath,                  /* pWidenPath */
799     nulldrv_wine_get_wgl_driver,        /* wine_get_wgl_driver */
800
801     GDI_PRIORITY_NULL_DRV               /* priority */
802 };
803
804
805 /*****************************************************************************
806  *      DRIVER_GetDriverName
807  *
808  */
809 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
810 {
811     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
812     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
813     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
814     static const WCHAR empty_strW[] = { 0 };
815     WCHAR *p;
816
817     /* display is a special case */
818     if (!strcmpiW( device, displayW ) ||
819         !strcmpiW( device, display1W ))
820     {
821         lstrcpynW( driver, displayW, size );
822         return TRUE;
823     }
824
825     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
826     if(!size) {
827         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
828         return FALSE;
829     }
830     p = strchrW(driver, ',');
831     if(!p)
832     {
833         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
834         return FALSE;
835     }
836     *p = 0;
837     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
838     return TRUE;
839 }
840
841
842 /***********************************************************************
843  *           GdiConvertToDevmodeW    (GDI32.@)
844  */
845 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
846 {
847     DEVMODEW *dmW;
848     WORD dmW_size, dmA_size;
849
850     dmA_size = dmA->dmSize;
851
852     /* this is the minimal dmSize that XP accepts */
853     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
854         return NULL;
855
856     if (dmA_size > sizeof(DEVMODEA))
857         dmA_size = sizeof(DEVMODEA);
858
859     dmW_size = dmA_size + CCHDEVICENAME;
860     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
861         dmW_size += CCHFORMNAME;
862
863     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
864     if (!dmW) return NULL;
865
866     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
867                                    dmW->dmDeviceName, CCHDEVICENAME);
868     /* copy slightly more, to avoid long computations */
869     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
870
871     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
872     {
873         if (dmA->dmFields & DM_FORMNAME)
874             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
875                                        dmW->dmFormName, CCHFORMNAME);
876         else
877             dmW->dmFormName[0] = 0;
878
879         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
880             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
881     }
882
883     if (dmA->dmDriverExtra)
884         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
885
886     dmW->dmSize = dmW_size;
887
888     return dmW;
889 }
890
891
892 /*****************************************************************************
893  *      @ [GDI32.100]
894  *
895  * This should thunk to 16-bit and simply call the proc with the given args.
896  */
897 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
898                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
899 {
900     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
901     return -1;
902 }
903
904 /*****************************************************************************
905  *      @ [GDI32.101]
906  *
907  * This should load the correct driver for lpszDevice and calls this driver's
908  * ExtDeviceModePropSheet proc.
909  *
910  * Note: The driver calls a callback routine for each property sheet page; these
911  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
912  * The layout of this structure is:
913  *
914  * struct
915  * {
916  *   DWORD  nPages;
917  *   DWORD  unknown;
918  *   HPROPSHEETPAGE  pages[10];
919  * };
920  */
921 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
922                                              LPCSTR lpszPort, LPVOID lpPropSheet )
923 {
924     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
925     return -1;
926 }
927
928 /*****************************************************************************
929  *      @ [GDI32.102]
930  *
931  * This should load the correct driver for lpszDevice and call this driver's
932  * ExtDeviceMode proc.
933  *
934  * FIXME: convert ExtDeviceMode to unicode in the driver interface
935  */
936 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
937                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
938                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
939                                     LPSTR lpszProfile, DWORD fwMode )
940 {
941     WCHAR deviceW[300];
942     WCHAR bufW[300];
943     char buf[300];
944     HDC hdc;
945     DC *dc;
946     INT ret = -1;
947
948     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
949           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
950
951     if (!lpszDevice) return -1;
952     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
953
954     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
955
956     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
957
958     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
959
960     if ((dc = get_dc_ptr( hdc )))
961     {
962         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
963         ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
964                                               lpdmInput, lpszProfile, fwMode );
965         release_dc_ptr( dc );
966     }
967     DeleteDC( hdc );
968     return ret;
969 }
970
971 /****************************************************************************
972  *      @ [GDI32.103]
973  *
974  * This should load the correct driver for lpszDevice and calls this driver's
975  * AdvancedSetupDialog proc.
976  */
977 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
978                                           LPDEVMODEA devin, LPDEVMODEA devout )
979 {
980     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
981     return -1;
982 }
983
984 /*****************************************************************************
985  *      @ [GDI32.104]
986  *
987  * This should load the correct driver for lpszDevice and calls this driver's
988  * DeviceCapabilities proc.
989  *
990  * FIXME: convert DeviceCapabilities to unicode in the driver interface
991  */
992 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
993                                            WORD fwCapability, LPSTR lpszOutput,
994                                            LPDEVMODEA lpdm )
995 {
996     WCHAR deviceW[300];
997     WCHAR bufW[300];
998     char buf[300];
999     HDC hdc;
1000     DC *dc;
1001     INT ret = -1;
1002
1003     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
1004
1005     if (!lpszDevice) return -1;
1006     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
1007
1008     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
1009
1010     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
1011
1012     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1013
1014     if ((dc = get_dc_ptr( hdc )))
1015     {
1016         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1017         ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1018                                                    fwCapability, lpszOutput, lpdm );
1019         release_dc_ptr( dc );
1020     }
1021     DeleteDC( hdc );
1022     return ret;
1023 }
1024
1025
1026 /************************************************************************
1027  *             Escape  [GDI32.@]
1028  */
1029 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1030 {
1031     INT ret;
1032     POINT *pt;
1033
1034     switch (escape)
1035     {
1036     case ABORTDOC:
1037         return AbortDoc( hdc );
1038
1039     case ENDDOC:
1040         return EndDoc( hdc );
1041
1042     case GETPHYSPAGESIZE:
1043         pt = out_data;
1044         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1045         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1046         return 1;
1047
1048     case GETPRINTINGOFFSET:
1049         pt = out_data;
1050         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1051         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1052         return 1;
1053
1054     case GETSCALINGFACTOR:
1055         pt = out_data;
1056         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1057         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1058         return 1;
1059
1060     case NEWFRAME:
1061         return EndPage( hdc );
1062
1063     case SETABORTPROC:
1064         return SetAbortProc( hdc, (ABORTPROC)in_data );
1065
1066     case STARTDOC:
1067         {
1068             DOCINFOA doc;
1069             char *name = NULL;
1070
1071             /* in_data may not be 0 terminated so we must copy it */
1072             if (in_data)
1073             {
1074                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1075                 memcpy( name, in_data, in_count );
1076                 name[in_count] = 0;
1077             }
1078             /* out_data is actually a pointer to the DocInfo structure and used as
1079              * a second input parameter */
1080             if (out_data) doc = *(DOCINFOA *)out_data;
1081             else
1082             {
1083                 doc.cbSize = sizeof(doc);
1084                 doc.lpszOutput = NULL;
1085                 doc.lpszDatatype = NULL;
1086                 doc.fwType = 0;
1087             }
1088             doc.lpszDocName = name;
1089             ret = StartDocA( hdc, &doc );
1090             HeapFree( GetProcessHeap(), 0, name );
1091             if (ret > 0) ret = StartPage( hdc );
1092             return ret;
1093         }
1094
1095     case QUERYESCSUPPORT:
1096         {
1097             const INT *ptr = (const INT *)in_data;
1098             if (in_count < sizeof(INT)) return 0;
1099             switch(*ptr)
1100             {
1101             case ABORTDOC:
1102             case ENDDOC:
1103             case GETPHYSPAGESIZE:
1104             case GETPRINTINGOFFSET:
1105             case GETSCALINGFACTOR:
1106             case NEWFRAME:
1107             case QUERYESCSUPPORT:
1108             case SETABORTPROC:
1109             case STARTDOC:
1110                 return TRUE;
1111             }
1112             break;
1113         }
1114     }
1115
1116     /* if not handled internally, pass it to the driver */
1117     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1118 }
1119
1120
1121 /******************************************************************************
1122  *              ExtEscape       [GDI32.@]
1123  *
1124  * Access capabilities of a particular device that are not available through GDI.
1125  *
1126  * PARAMS
1127  *    hdc         [I] Handle to device context
1128  *    nEscape     [I] Escape function
1129  *    cbInput     [I] Number of bytes in input structure
1130  *    lpszInData  [I] Pointer to input structure
1131  *    cbOutput    [I] Number of bytes in output structure
1132  *    lpszOutData [O] Pointer to output structure
1133  *
1134  * RETURNS
1135  *    Success: >0
1136  *    Not implemented: 0
1137  *    Failure: <0
1138  */
1139 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1140                       INT cbOutput, LPSTR lpszOutData )
1141 {
1142     INT ret = 0;
1143     DC * dc = get_dc_ptr( hdc );
1144
1145     if (dc)
1146     {
1147         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1148         update_dc( dc );
1149         ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1150         release_dc_ptr( dc );
1151     }
1152     return ret;
1153 }
1154
1155
1156 /*******************************************************************
1157  *      DrawEscape [GDI32.@]
1158  *
1159  *
1160  */
1161 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1162 {
1163     FIXME("DrawEscape, stub\n");
1164     return 0;
1165 }
1166
1167 /*******************************************************************
1168  *      NamedEscape [GDI32.@]
1169  */
1170 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1171                         INT cbOutput, LPSTR lpszOutData )
1172 {
1173     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1174           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1175           lpszOutData);
1176     return 0;
1177 }
1178
1179 /*******************************************************************
1180  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1181  *      GdiEntry13                       [GDI32.@]
1182  */
1183 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1184 {
1185     static int warn_once;
1186
1187     if (!warn_once++)
1188         FIXME("stub\n");
1189     return 0;
1190 }