dsound: Always enumerate the default device first.
[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 INT nulldrv_ChoosePixelFormat( PHYSDEV dev, const PIXELFORMATDESCRIPTOR *descr )
202 {
203     return 0;
204 }
205
206 static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
207                            INT xstart, INT ystart, INT xend, INT yend )
208 {
209     return TRUE;
210 }
211
212 static BOOL nulldrv_CreateBitmap( PHYSDEV dev, HBITMAP bitmap )
213 {
214     return TRUE;
215 }
216
217 static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
218 {
219     if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
220     return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
221 }
222
223 static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
224                               LPCWSTR output, const DEVMODEW *devmode )
225 {
226     assert(0);  /* should never be called */
227     return FALSE;
228 }
229
230 static HBITMAP nulldrv_CreateDIBSection( PHYSDEV dev, HBITMAP bitmap, BITMAPINFO *info, UINT usage )
231 {
232     return bitmap;
233 }
234
235 static BOOL nulldrv_DeleteBitmap( HBITMAP bitmap )
236 {
237     return TRUE;
238 }
239
240 static BOOL nulldrv_DeleteDC( PHYSDEV dev )
241 {
242     assert(0);  /* should never be called */
243     return TRUE;
244 }
245
246 static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
247 {
248     return TRUE;
249 }
250
251 static INT nulldrv_DescribePixelFormat( PHYSDEV dev, INT format, UINT size, PIXELFORMATDESCRIPTOR * descr )
252 {
253     return 0;
254 }
255
256 static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
257                                          WORD cap, LPSTR output, DEVMODEA *devmode )
258 {
259     return -1;
260 }
261
262 static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
263 {
264     return TRUE;
265 }
266
267 static INT nulldrv_EndDoc( PHYSDEV dev )
268 {
269     return 0;
270 }
271
272 static INT nulldrv_EndPage( PHYSDEV dev )
273 {
274     return 0;
275 }
276
277 static BOOL nulldrv_EnumDeviceFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
278 {
279     return FALSE;
280 }
281
282 static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
283 {
284     return -1;
285 }
286
287 static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
288                                   LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
289 {
290     return -1;
291 }
292
293 static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
294                                     INT out_size, void *out_data )
295 {
296     return 0;
297 }
298
299 static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
300 {
301     return TRUE;
302 }
303
304 static BOOL nulldrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *rect,
305                                 LPCWSTR str, UINT count, const INT *dx )
306 {
307     return TRUE;
308 }
309
310 static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
311 {
312     return FALSE;
313 }
314
315 static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
316 {
317     return FALSE;
318 }
319
320 static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
321 {
322     switch (cap)  /* return meaningful values for some entries */
323     {
324     case HORZRES:     return 640;
325     case VERTRES:     return 480;
326     case BITSPIXEL:   return 1;
327     case PLANES:      return 1;
328     case NUMCOLORS:   return 2;
329     case ASPECTX:     return 36;
330     case ASPECTY:     return 36;
331     case ASPECTXY:    return 51;
332     case LOGPIXELSX:  return 72;
333     case LOGPIXELSY:  return 72;
334     case SIZEPALETTE: return 2;
335     case TEXTCAPS:    return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
336                               TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
337                               TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
338     default:          return 0;
339     }
340 }
341
342 static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
343 {
344     return FALSE;
345 }
346
347 static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
348 {
349     return FALSE;
350 }
351
352 static COLORREF nulldrv_GetPixel( PHYSDEV dev, INT x, INT y )
353 {
354     return 0;
355 }
356
357 static INT nulldrv_GetPixelFormat( PHYSDEV dev )
358 {
359     return 0;
360 }
361
362 static UINT nulldrv_GetSystemPaletteEntries( PHYSDEV dev, UINT start, UINT count, PALETTEENTRY *entries )
363 {
364     return 0;
365 }
366
367 static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT max_ext,
368                                           INT *fit, INT *dx, SIZE *size )
369 {
370     return FALSE;
371 }
372
373 static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
374 {
375     return FALSE;
376 }
377
378 static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
379 {
380     return TRUE;
381 }
382
383 static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
384 {
385     return TRUE;
386 }
387
388 static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
389 {
390     return TRUE;
391 }
392
393 static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
394 {
395     return TRUE;
396 }
397
398 static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
399                          INT xstart, INT ystart, INT xend, INT yend )
400 {
401     return TRUE;
402 }
403
404 static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
405 {
406     /* FIXME: could be implemented with Polygon */
407     return TRUE;
408 }
409
410 static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
411 {
412     /* FIXME: could be implemented with Polyline */
413     return TRUE;
414 }
415
416 static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
417 {
418     return TRUE;
419 }
420
421 static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
422 {
423     return TRUE;
424 }
425
426 static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
427 {
428     return 0;
429 }
430
431 static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
432 {
433     return 0;
434 }
435
436 static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
437 {
438     return TRUE;
439 }
440
441 static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
442 {
443     return 0;
444 }
445
446 static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
447                                INT ell_width, INT ell_height )
448 {
449     return TRUE;
450 }
451
452 static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
453 {
454     return bitmap;
455 }
456
457 static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush )
458 {
459     return brush;
460 }
461
462 static HFONT nulldrv_SelectFont( PHYSDEV dev, HFONT font )
463 {
464     return 0;
465 }
466
467 static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
468 {
469     return palette;
470 }
471
472 static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen )
473 {
474     return pen;
475 }
476
477 static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
478 {
479     return dir;
480 }
481
482 static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
483 {
484     return color;
485 }
486
487 static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
488 {
489     return mode;
490 }
491
492 static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
493 {
494     return color;
495 }
496
497 static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
498 {
499     return color;
500 }
501
502 static UINT nulldrv_SetDIBColorTable( PHYSDEV dev, UINT pos, UINT count, const RGBQUAD *colors )
503 {
504     return 0;
505 }
506
507 static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
508 {
509 }
510
511 static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
512 {
513     return layout;
514 }
515
516 static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
517 {
518     return FALSE;
519 }
520
521 static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
522 {
523     return flags;
524 }
525
526 static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
527 {
528     return color;
529 }
530
531 static BOOL nulldrv_SetPixelFormat( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
532 {
533     return FALSE;
534 }
535
536 static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
537 {
538     return mode;
539 }
540
541 static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
542 {
543     return rop;
544 }
545
546 static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
547 {
548     return mode;
549 }
550
551 static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
552 {
553     return mode;
554 }
555
556 static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
557 {
558     return align;
559 }
560
561 static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
562 {
563     return extra;
564 }
565
566 static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
567 {
568     return color;
569 }
570
571 static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
572 {
573     return TRUE;
574 }
575
576 static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
577 {
578     return 0;
579 }
580
581 static INT nulldrv_StartPage( PHYSDEV dev )
582 {
583     return 1;
584 }
585
586 static BOOL nulldrv_SwapBuffers( PHYSDEV dev )
587 {
588     return TRUE;
589 }
590
591 static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
592 {
593     return FALSE;
594 }
595
596 static BOOL nulldrv_wglCopyContext( HGLRC ctx_src, HGLRC ctx_dst, UINT mask )
597 {
598     return FALSE;
599 }
600
601 static HGLRC nulldrv_wglCreateContext( PHYSDEV dev )
602 {
603     return 0;
604 }
605
606 static HGLRC nulldrv_wglCreateContextAttribsARB( PHYSDEV dev, HGLRC share_ctx, const int *attribs )
607 {
608     return 0;
609 }
610
611 static BOOL nulldrv_wglDeleteContext( HGLRC ctx )
612 {
613     return FALSE;
614 }
615
616 static PROC nulldrv_wglGetProcAddress( LPCSTR name )
617 {
618     return NULL;
619 }
620
621 static HDC nulldrv_wglGetPbufferDCARB( PHYSDEV dev, void *pbuffer )
622 {
623     return 0;
624 }
625
626 static BOOL nulldrv_wglMakeCurrent( PHYSDEV dev, HGLRC ctx )
627 {
628     return FALSE;
629 }
630
631 static BOOL nulldrv_wglMakeContextCurrentARB( PHYSDEV dev_draw, PHYSDEV dev_read, HGLRC ctx )
632 {
633     return FALSE;
634 }
635
636 static BOOL nulldrv_wglSetPixelFormatWINE( PHYSDEV dev, INT format, const PIXELFORMATDESCRIPTOR *descr )
637 {
638     return FALSE;
639 }
640
641 static BOOL nulldrv_wglShareLists( HGLRC ctx1, HGLRC ctx2 )
642 {
643     return FALSE;
644 }
645
646 static BOOL nulldrv_wglUseFontBitmapsA( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
647 {
648     return FALSE;
649 }
650
651 static BOOL nulldrv_wglUseFontBitmapsW( PHYSDEV dev, DWORD start, DWORD count, DWORD base )
652 {
653     return FALSE;
654 }
655
656 const struct gdi_dc_funcs null_driver =
657 {
658     nulldrv_AbortDoc,                   /* pAbortDoc */
659     nulldrv_AbortPath,                  /* pAbortPath */
660     nulldrv_AlphaBlend,                 /* pAlphaBlend */
661     nulldrv_AngleArc,                   /* pAngleArc */
662     nulldrv_Arc,                        /* pArc */
663     nulldrv_ArcTo,                      /* pArcTo */
664     nulldrv_BeginPath,                  /* pBeginPath */
665     nulldrv_BlendImage,                 /* pBlendImage */
666     nulldrv_ChoosePixelFormat,          /* pChoosePixelFormat */
667     nulldrv_Chord,                      /* pChord */
668     nulldrv_CloseFigure,                /* pCloseFigure */
669     nulldrv_CreateBitmap,               /* pCreateBitmap */
670     nulldrv_CreateCompatibleDC,         /* pCreateCompatibleDC */
671     nulldrv_CreateDC,                   /* pCreateDC */
672     nulldrv_CreateDIBSection,           /* pCreateDIBSection */
673     nulldrv_DeleteBitmap,               /* pDeleteBitmap */
674     nulldrv_DeleteDC,                   /* pDeleteDC */
675     nulldrv_DeleteObject,               /* pDeleteObject */
676     nulldrv_DescribePixelFormat,        /* pDescribePixelFormat */
677     nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
678     nulldrv_Ellipse,                    /* pEllipse */
679     nulldrv_EndDoc,                     /* pEndDoc */
680     nulldrv_EndPage,                    /* pEndPage */
681     nulldrv_EndPath,                    /* pEndPath */
682     nulldrv_EnumDeviceFonts,            /* pEnumDeviceFonts */
683     nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
684     nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
685     nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
686     nulldrv_ExtEscape,                  /* pExtEscape */
687     nulldrv_ExtFloodFill,               /* pExtFloodFill */
688     nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
689     nulldrv_ExtTextOut,                 /* pExtTextOut */
690     nulldrv_FillPath,                   /* pFillPath */
691     nulldrv_FillRgn,                    /* pFillRgn */
692     nulldrv_FlattenPath,                /* pFlattenPath */
693     nulldrv_FrameRgn,                   /* pFrameRgn */
694     nulldrv_GdiComment,                 /* pGdiComment */
695     nulldrv_GetCharWidth,               /* pGetCharWidth */
696     nulldrv_GetDeviceCaps,              /* pGetDeviceCaps */
697     nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
698     nulldrv_GetICMProfile,              /* pGetICMProfile */
699     nulldrv_GetImage,                   /* pGetImage */
700     nulldrv_GetNearestColor,            /* pGetNearestColor */
701     nulldrv_GetPixel,                   /* pGetPixel */
702     nulldrv_GetPixelFormat,             /* pGetPixelFormat */
703     nulldrv_GetSystemPaletteEntries,    /* pGetSystemPaletteEntries */
704     nulldrv_GetTextExtentExPoint,       /* pGetTextExtentExPoint */
705     nulldrv_GetTextMetrics,             /* pGetTextMetrics */
706     nulldrv_IntersectClipRect,          /* pIntersectClipRect */
707     nulldrv_InvertRgn,                  /* pInvertRgn */
708     nulldrv_LineTo,                     /* pLineTo */
709     nulldrv_ModifyWorldTransform,       /* pModifyWorldTransform */
710     nulldrv_MoveTo,                     /* pMoveTo */
711     nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
712     nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
713     nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
714     nulldrv_PaintRgn,                   /* pPaintRgn */
715     nulldrv_PatBlt,                     /* pPatBlt */
716     nulldrv_Pie,                        /* pPie */
717     nulldrv_PolyBezier,                 /* pPolyBezier */
718     nulldrv_PolyBezierTo,               /* pPolyBezierTo */
719     nulldrv_PolyDraw,                   /* pPolyDraw */
720     nulldrv_PolyPolygon,                /* pPolyPolygon */
721     nulldrv_PolyPolyline,               /* pPolyPolyline */
722     nulldrv_Polygon,                    /* pPolygon */
723     nulldrv_Polyline,                   /* pPolyline */
724     nulldrv_PolylineTo,                 /* pPolylineTo */
725     nulldrv_PutImage,                   /* pPutImage */
726     nulldrv_RealizeDefaultPalette,      /* pRealizeDefaultPalette */
727     nulldrv_RealizePalette,             /* pRealizePalette */
728     nulldrv_Rectangle,                  /* pRectangle */
729     nulldrv_ResetDC,                    /* pResetDC */
730     nulldrv_RestoreDC,                  /* pRestoreDC */
731     nulldrv_RoundRect,                  /* pRoundRect */
732     nulldrv_SaveDC,                     /* pSaveDC */
733     nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
734     nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
735     nulldrv_SelectBitmap,               /* pSelectBitmap */
736     nulldrv_SelectBrush,                /* pSelectBrush */
737     nulldrv_SelectClipPath,             /* pSelectClipPath */
738     nulldrv_SelectFont,                 /* pSelectFont */
739     nulldrv_SelectPalette,              /* pSelectPalette */
740     nulldrv_SelectPen,                  /* pSelectPen */
741     nulldrv_SetArcDirection,            /* pSetArcDirection */
742     nulldrv_SetBkColor,                 /* pSetBkColor */
743     nulldrv_SetBkMode,                  /* pSetBkMode */
744     nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
745     nulldrv_SetDCPenColor,              /* pSetDCPenColor */
746     nulldrv_SetDIBColorTable,           /* pSetDIBColorTable */
747     nulldrv_SetDIBitsToDevice,          /* pSetDIBitsToDevice */
748     nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
749     nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
750     nulldrv_SetLayout,                  /* pSetLayout */
751     nulldrv_SetMapMode,                 /* pSetMapMode */
752     nulldrv_SetMapperFlags,             /* pSetMapperFlags */
753     nulldrv_SetPixel,                   /* pSetPixel */
754     nulldrv_SetPixelFormat,             /* pSetPixelFormat */
755     nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
756     nulldrv_SetROP2,                    /* pSetROP2 */
757     nulldrv_SetRelAbs,                  /* pSetRelAbs */
758     nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
759     nulldrv_SetTextAlign,               /* pSetTextAlign */
760     nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
761     nulldrv_SetTextColor,               /* pSetTextColor */
762     nulldrv_SetTextJustification,       /* pSetTextJustification */
763     nulldrv_SetViewportExtEx,           /* pSetViewportExt */
764     nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
765     nulldrv_SetWindowExtEx,             /* pSetWindowExt */
766     nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
767     nulldrv_SetWorldTransform,          /* pSetWorldTransform */
768     nulldrv_StartDoc,                   /* pStartDoc */
769     nulldrv_StartPage,                  /* pStartPage */
770     nulldrv_StretchBlt,                 /* pStretchBlt */
771     nulldrv_StretchDIBits,              /* pStretchDIBits */
772     nulldrv_StrokeAndFillPath,          /* pStrokeAndFillPath */
773     nulldrv_StrokePath,                 /* pStrokePath */
774     nulldrv_SwapBuffers,                /* pSwapBuffers */
775     nulldrv_UnrealizePalette,           /* pUnrealizePalette */
776     nulldrv_WidenPath,                  /* pWidenPath */
777     nulldrv_wglCopyContext,             /* pwglCopyContext */
778     nulldrv_wglCreateContext,           /* pwglCreateContext */
779     nulldrv_wglCreateContextAttribsARB, /* pwglCreateContextAttribsARB */
780     nulldrv_wglDeleteContext,           /* pwglDeleteContext */
781     nulldrv_wglGetPbufferDCARB,         /* pwglGetPbufferDCARB */
782     nulldrv_wglGetProcAddress,          /* pwglGetProcAddress */
783     nulldrv_wglMakeContextCurrentARB,   /* pwglMakeContextCurrentARB */
784     nulldrv_wglMakeCurrent,             /* pwglMakeCurrent */
785     nulldrv_wglSetPixelFormatWINE,      /* pwglSetPixelFormatWINE */
786     nulldrv_wglShareLists,              /* pwglShareLists */
787     nulldrv_wglUseFontBitmapsA,         /* pwglUseFontBitmapsA */
788     nulldrv_wglUseFontBitmapsW,         /* pwglUseFontBitmapsW */
789 };
790
791
792 /*****************************************************************************
793  *      DRIVER_GetDriverName
794  *
795  */
796 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
797 {
798     static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
799     static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
800     static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
801     static const WCHAR empty_strW[] = { 0 };
802     WCHAR *p;
803
804     /* display is a special case */
805     if (!strcmpiW( device, displayW ) ||
806         !strcmpiW( device, display1W ))
807     {
808         lstrcpynW( driver, displayW, size );
809         return TRUE;
810     }
811
812     size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
813     if(!size) {
814         WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
815         return FALSE;
816     }
817     p = strchrW(driver, ',');
818     if(!p)
819     {
820         WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
821         return FALSE;
822     }
823     *p = 0;
824     TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
825     return TRUE;
826 }
827
828
829 /***********************************************************************
830  *           GdiConvertToDevmodeW    (GDI32.@)
831  */
832 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
833 {
834     DEVMODEW *dmW;
835     WORD dmW_size, dmA_size;
836
837     dmA_size = dmA->dmSize;
838
839     /* this is the minimal dmSize that XP accepts */
840     if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
841         return NULL;
842
843     if (dmA_size > sizeof(DEVMODEA))
844         dmA_size = sizeof(DEVMODEA);
845
846     dmW_size = dmA_size + CCHDEVICENAME;
847     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
848         dmW_size += CCHFORMNAME;
849
850     dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
851     if (!dmW) return NULL;
852
853     MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
854                                    dmW->dmDeviceName, CCHDEVICENAME);
855     /* copy slightly more, to avoid long computations */
856     memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
857
858     if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
859     {
860         if (dmA->dmFields & DM_FORMNAME)
861             MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
862                                        dmW->dmFormName, CCHFORMNAME);
863         else
864             dmW->dmFormName[0] = 0;
865
866         if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
867             memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
868     }
869
870     if (dmA->dmDriverExtra)
871         memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
872
873     dmW->dmSize = dmW_size;
874
875     return dmW;
876 }
877
878
879 /*****************************************************************************
880  *      @ [GDI32.100]
881  *
882  * This should thunk to 16-bit and simply call the proc with the given args.
883  */
884 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
885                                  LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
886 {
887     FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
888     return -1;
889 }
890
891 /*****************************************************************************
892  *      @ [GDI32.101]
893  *
894  * This should load the correct driver for lpszDevice and calls this driver's
895  * ExtDeviceModePropSheet proc.
896  *
897  * Note: The driver calls a callback routine for each property sheet page; these
898  * pages are supposed to be filled into the structure pointed to by lpPropSheet.
899  * The layout of this structure is:
900  *
901  * struct
902  * {
903  *   DWORD  nPages;
904  *   DWORD  unknown;
905  *   HPROPSHEETPAGE  pages[10];
906  * };
907  */
908 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
909                                              LPCSTR lpszPort, LPVOID lpPropSheet )
910 {
911     FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
912     return -1;
913 }
914
915 /*****************************************************************************
916  *      @ [GDI32.102]
917  *
918  * This should load the correct driver for lpszDevice and call this driver's
919  * ExtDeviceMode proc.
920  *
921  * FIXME: convert ExtDeviceMode to unicode in the driver interface
922  */
923 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
924                                     LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
925                                     LPSTR lpszPort, LPDEVMODEA lpdmInput,
926                                     LPSTR lpszProfile, DWORD fwMode )
927 {
928     WCHAR deviceW[300];
929     WCHAR bufW[300];
930     char buf[300];
931     HDC hdc;
932     DC *dc;
933     INT ret = -1;
934
935     TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
936           hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
937
938     if (!lpszDevice) return -1;
939     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
940
941     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
942
943     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
944
945     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
946
947     if ((dc = get_dc_ptr( hdc )))
948     {
949         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
950         ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
951                                               lpdmInput, lpszProfile, fwMode );
952         release_dc_ptr( dc );
953     }
954     DeleteDC( hdc );
955     return ret;
956 }
957
958 /****************************************************************************
959  *      @ [GDI32.103]
960  *
961  * This should load the correct driver for lpszDevice and calls this driver's
962  * AdvancedSetupDialog proc.
963  */
964 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
965                                           LPDEVMODEA devin, LPDEVMODEA devout )
966 {
967     TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
968     return -1;
969 }
970
971 /*****************************************************************************
972  *      @ [GDI32.104]
973  *
974  * This should load the correct driver for lpszDevice and calls this driver's
975  * DeviceCapabilities proc.
976  *
977  * FIXME: convert DeviceCapabilities to unicode in the driver interface
978  */
979 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
980                                            WORD fwCapability, LPSTR lpszOutput,
981                                            LPDEVMODEA lpdm )
982 {
983     WCHAR deviceW[300];
984     WCHAR bufW[300];
985     char buf[300];
986     HDC hdc;
987     DC *dc;
988     INT ret = -1;
989
990     TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
991
992     if (!lpszDevice) return -1;
993     if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
994
995     if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
996
997     if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
998
999     if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
1000
1001     if ((dc = get_dc_ptr( hdc )))
1002     {
1003         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
1004         ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
1005                                                    fwCapability, lpszOutput, lpdm );
1006         release_dc_ptr( dc );
1007     }
1008     DeleteDC( hdc );
1009     return ret;
1010 }
1011
1012
1013 /************************************************************************
1014  *             Escape  [GDI32.@]
1015  */
1016 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
1017 {
1018     INT ret;
1019     POINT *pt;
1020
1021     switch (escape)
1022     {
1023     case ABORTDOC:
1024         return AbortDoc( hdc );
1025
1026     case ENDDOC:
1027         return EndDoc( hdc );
1028
1029     case GETPHYSPAGESIZE:
1030         pt = out_data;
1031         pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
1032         pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
1033         return 1;
1034
1035     case GETPRINTINGOFFSET:
1036         pt = out_data;
1037         pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
1038         pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
1039         return 1;
1040
1041     case GETSCALINGFACTOR:
1042         pt = out_data;
1043         pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
1044         pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
1045         return 1;
1046
1047     case NEWFRAME:
1048         return EndPage( hdc );
1049
1050     case SETABORTPROC:
1051         return SetAbortProc( hdc, (ABORTPROC)in_data );
1052
1053     case STARTDOC:
1054         {
1055             DOCINFOA doc;
1056             char *name = NULL;
1057
1058             /* in_data may not be 0 terminated so we must copy it */
1059             if (in_data)
1060             {
1061                 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
1062                 memcpy( name, in_data, in_count );
1063                 name[in_count] = 0;
1064             }
1065             /* out_data is actually a pointer to the DocInfo structure and used as
1066              * a second input parameter */
1067             if (out_data) doc = *(DOCINFOA *)out_data;
1068             else
1069             {
1070                 doc.cbSize = sizeof(doc);
1071                 doc.lpszOutput = NULL;
1072                 doc.lpszDatatype = NULL;
1073                 doc.fwType = 0;
1074             }
1075             doc.lpszDocName = name;
1076             ret = StartDocA( hdc, &doc );
1077             HeapFree( GetProcessHeap(), 0, name );
1078             if (ret > 0) ret = StartPage( hdc );
1079             return ret;
1080         }
1081
1082     case QUERYESCSUPPORT:
1083         {
1084             const INT *ptr = (const INT *)in_data;
1085             if (in_count < sizeof(INT)) return 0;
1086             switch(*ptr)
1087             {
1088             case ABORTDOC:
1089             case ENDDOC:
1090             case GETPHYSPAGESIZE:
1091             case GETPRINTINGOFFSET:
1092             case GETSCALINGFACTOR:
1093             case NEWFRAME:
1094             case QUERYESCSUPPORT:
1095             case SETABORTPROC:
1096             case STARTDOC:
1097                 return TRUE;
1098             }
1099             break;
1100         }
1101     }
1102
1103     /* if not handled internally, pass it to the driver */
1104     return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
1105 }
1106
1107
1108 /******************************************************************************
1109  *              ExtEscape       [GDI32.@]
1110  *
1111  * Access capabilities of a particular device that are not available through GDI.
1112  *
1113  * PARAMS
1114  *    hdc         [I] Handle to device context
1115  *    nEscape     [I] Escape function
1116  *    cbInput     [I] Number of bytes in input structure
1117  *    lpszInData  [I] Pointer to input structure
1118  *    cbOutput    [I] Number of bytes in output structure
1119  *    lpszOutData [O] Pointer to output structure
1120  *
1121  * RETURNS
1122  *    Success: >0
1123  *    Not implemented: 0
1124  *    Failure: <0
1125  */
1126 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
1127                       INT cbOutput, LPSTR lpszOutData )
1128 {
1129     INT ret = 0;
1130     DC * dc = get_dc_ptr( hdc );
1131
1132     if (dc)
1133     {
1134         PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtEscape );
1135         ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
1136         release_dc_ptr( dc );
1137     }
1138     return ret;
1139 }
1140
1141
1142 /*******************************************************************
1143  *      DrawEscape [GDI32.@]
1144  *
1145  *
1146  */
1147 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
1148 {
1149     FIXME("DrawEscape, stub\n");
1150     return 0;
1151 }
1152
1153 /*******************************************************************
1154  *      NamedEscape [GDI32.@]
1155  */
1156 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
1157                         INT cbOutput, LPSTR lpszOutData )
1158 {
1159     FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
1160           hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
1161           lpszOutData);
1162     return 0;
1163 }
1164
1165 /*******************************************************************
1166  *      DdQueryDisplaySettingsUniqueness [GDI32.@]
1167  *      GdiEntry13                       [GDI32.@]
1168  */
1169 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
1170 {
1171     static int warn_once;
1172
1173     if (!warn_once++)
1174         FIXME("stub\n");
1175     return 0;
1176 }