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