driver.c 35.1 KB
Newer Older
1 2 3
/*
 * Graphics driver management functions
 *
4 5
 * Copyright 1994 Bob Amstadt
 * Copyright 1996, 2001 Alexandre Julliard
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 23 24
#include "config.h"
#include "wine/port.h"

25
#include <assert.h>
26
#include <stdarg.h>
27
#include <string.h>
28
#include <stdio.h>
29
#include "windef.h"
30
#include "winbase.h"
31
#include "ddrawgdi.h"
32
#include "wine/winbase16.h"
33
#include "winternl.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 43

struct graphics_driver
{
44 45 46
    struct list                entry;
    HMODULE                    module;  /* module handle */
    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 53
const struct gdi_dc_funcs *font_driver = NULL;

54 55 56 57 58
static CRITICAL_SECTION driver_section;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
    0, 0, &driver_section,
    { &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 65 66 67 68 69

/**********************************************************************
 *	     create_driver
 *
 * Allocate and fill the driver structure for a given module.
 */
static struct graphics_driver *create_driver( HMODULE module )
{
70 71
    static const struct gdi_dc_funcs empty_funcs;
    const struct gdi_dc_funcs *funcs = NULL;
72 73 74 75 76
    struct graphics_driver *driver;

    if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
    driver->module = module;

77 78
    if (module)
    {
79
        const struct gdi_dc_funcs * (CDECL *wine_get_gdi_driver)( unsigned int version );
80

81 82
        if ((wine_get_gdi_driver = (void *)GetProcAddress( module, "wine_get_gdi_driver" )))
            funcs = wine_get_gdi_driver( WINE_GDI_DRIVER_VERSION );
83
    }
84 85
    if (!funcs) funcs = &empty_funcs;
    driver->funcs = funcs;
86 87 88 89 90
    return driver;
}


/**********************************************************************
91
 *	     get_display_driver
92 93 94
 *
 * Special case for loading the display driver: get the name from the config file
 */
95
static const struct gdi_dc_funcs *get_display_driver(void)
96
{
97
    if (!display_driver)
98
    {
99 100
        HMODULE user32 = LoadLibraryA( "user32.dll" );
        HWND (WINAPI *pGetDesktopWindow)(void) = (void *)GetProcAddress( user32, "GetDesktopWindow" );
101

102 103 104 105 106
        if (!pGetDesktopWindow() || !display_driver)
        {
            WARN( "failed to load the display driver, falling back to null driver\n" );
            __wine_set_display_driver( 0 );
        }
107
    }
108
    return display_driver->funcs;
109 110 111 112 113 114
}


/**********************************************************************
 *	     DRIVER_load_driver
 */
115
const struct gdi_dc_funcs *DRIVER_load_driver( LPCWSTR name )
116 117
{
    HMODULE module;
118
    struct graphics_driver *driver, *new_driver;
119
    static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
120
    static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
121 122

    /* display driver is a special case */
123
    if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return get_display_driver();
124

125
    if ((module = GetModuleHandleW( name )))
126
    {
127 128
        if (display_driver && display_driver->module == module) return display_driver->funcs;

129
        EnterCriticalSection( &driver_section );
130
        LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
131
        {
132
            if (driver->module == module) goto done;
133
        }
134
        LeaveCriticalSection( &driver_section );
135 136
    }

137 138 139
    if (!(module = LoadLibraryW( name ))) return NULL;

    if (!(new_driver = create_driver( module )))
140
    {
141
        FreeLibrary( module );
142
        return NULL;
143 144
    }

145 146 147
    /* check if someone else added it in the meantime */
    EnterCriticalSection( &driver_section );
    LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
148
    {
149
        if (driver->module != module) continue;
150
        FreeLibrary( module );
151 152
        HeapFree( GetProcessHeap(), 0, new_driver );
        goto done;
153
    }
154 155
    driver = new_driver;
    list_add_head( &drivers, &driver->entry );
156
    TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
157
done:
Alexandre Julliard's avatar
Alexandre Julliard committed
158
    LeaveCriticalSection( &driver_section );
159
    return driver->funcs;
160 161 162
}


163
/***********************************************************************
André Hentschel's avatar
André Hentschel committed
164
 *           __wine_set_display_driver    (GDI32.@)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
 */
void CDECL __wine_set_display_driver( HMODULE module )
{
    struct graphics_driver *driver;

    if (!(driver = create_driver( module )))
    {
        ERR( "Could not create graphics driver\n" );
        ExitProcess(1);
    }
    if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
        HeapFree( GetProcessHeap(), 0, driver );
}


180
static INT nulldrv_AbortDoc( PHYSDEV dev )
181 182 183 184
{
    return 0;
}

185 186
static BOOL nulldrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                         INT xstart, INT ystart, INT xend, INT yend )
187 188 189 190
{
    return TRUE;
}

191 192
static BOOL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                           INT xstart, INT ystart, INT xend, INT yend )
193 194 195 196
{
    return TRUE;
}

197 198 199 200 201 202
static BOOL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
{
    if (!display_driver || !display_driver->funcs->pCreateCompatibleDC) return TRUE;
    return display_driver->funcs->pCreateCompatibleDC( NULL, pdev );
}

203
static BOOL nulldrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
204
                              LPCWSTR output, const DEVMODEW *devmode )
205 206 207 208 209
{
    assert(0);  /* should never be called */
    return FALSE;
}

210
static BOOL nulldrv_DeleteDC( PHYSDEV dev )
211 212 213 214 215
{
    assert(0);  /* should never be called */
    return TRUE;
}

216
static BOOL nulldrv_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
217 218 219 220
{
    return TRUE;
}

221 222
static DWORD nulldrv_DeviceCapabilities( LPSTR buffer, LPCSTR device, LPCSTR port,
                                         WORD cap, LPSTR output, DEVMODEA *devmode )
223 224 225 226
{
    return -1;
}

227
static BOOL nulldrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
228 229 230 231
{
    return TRUE;
}

232
static INT nulldrv_EndDoc( PHYSDEV dev )
233 234 235 236
{
    return 0;
}

237
static INT nulldrv_EndPage( PHYSDEV dev )
238 239 240 241
{
    return 0;
}

242
static BOOL nulldrv_EnumFonts( PHYSDEV dev, LOGFONTW *logfont, FONTENUMPROCW proc, LPARAM lParam )
243
{
244
    return TRUE;
245 246
}

247
static INT nulldrv_EnumICMProfiles( PHYSDEV dev, ICMENUMPROCW func, LPARAM lparam )
248 249 250 251
{
    return -1;
}

252 253
static INT nulldrv_ExtDeviceMode( LPSTR buffer, HWND hwnd, DEVMODEA *output, LPSTR device,
                                  LPSTR port, DEVMODEA *input, LPSTR profile, DWORD mode )
254 255 256 257
{
    return -1;
}

258
static INT nulldrv_ExtEscape( PHYSDEV dev, INT escape, INT in_size, const void *in_data,
259 260 261 262 263
                                    INT out_size, void *out_data )
{
    return 0;
}

264
static BOOL nulldrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type )
265 266 267 268
{
    return TRUE;
}

269 270 271 272 273
static BOOL nulldrv_FontIsLinked( PHYSDEV dev )
{
    return FALSE;
}

274
static BOOL nulldrv_GdiComment( PHYSDEV dev, UINT size, const BYTE *data )
275 276 277 278
{
    return FALSE;
}

279 280 281 282 283
static UINT nulldrv_GetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
{
    return DCB_RESET;
}

284 285 286 287 288 289 290 291 292 293
static BOOL nulldrv_GetCharABCWidths( PHYSDEV dev, UINT first, UINT last, LPABC abc )
{
    return FALSE;
}

static BOOL nulldrv_GetCharABCWidthsI( PHYSDEV dev, UINT first, UINT count, WORD *indices, LPABC abc )
{
    return FALSE;
}

294
static BOOL nulldrv_GetCharWidth( PHYSDEV dev, UINT first, UINT last, INT *buffer )
295 296 297 298
{
    return FALSE;
}

299
static INT nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
{
    switch (cap)  /* return meaningful values for some entries */
    {
    case HORZRES:     return 640;
    case VERTRES:     return 480;
    case BITSPIXEL:   return 1;
    case PLANES:      return 1;
    case NUMCOLORS:   return 2;
    case ASPECTX:     return 36;
    case ASPECTY:     return 36;
    case ASPECTXY:    return 51;
    case LOGPIXELSX:  return 72;
    case LOGPIXELSY:  return 72;
    case SIZEPALETTE: return 2;
    case TEXTCAPS:    return (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
                              TC_CR_ANY | TC_SF_X_YINDEP | TC_SA_DOUBLE | TC_SA_INTEGER |
                              TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE | TC_RA_ABLE | TC_VA_ABLE);
    default:          return 0;
    }
}

321
static BOOL nulldrv_GetDeviceGammaRamp( PHYSDEV dev, void *ramp )
322
{
323
    SetLastError( ERROR_INVALID_PARAMETER );
324 325 326
    return FALSE;
}

327 328 329 330 331
static DWORD nulldrv_GetFontData( PHYSDEV dev, DWORD table, DWORD offset, LPVOID buffer, DWORD length )
{
    return FALSE;
}

332 333 334 335 336
static BOOL nulldrv_GetFontRealizationInfo( PHYSDEV dev, void *info )
{
    return FALSE;
}

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
static DWORD nulldrv_GetFontUnicodeRanges( PHYSDEV dev, LPGLYPHSET glyphs )
{
    return 0;
}

static DWORD nulldrv_GetGlyphIndices( PHYSDEV dev, LPCWSTR str, INT count, LPWORD indices, DWORD flags )
{
    return GDI_ERROR;
}

static DWORD nulldrv_GetGlyphOutline( PHYSDEV dev, UINT ch, UINT format, LPGLYPHMETRICS metrics,
                                      DWORD size, LPVOID buffer, const MAT2 *mat )
{
    return GDI_ERROR;
}

353
static BOOL nulldrv_GetICMProfile( PHYSDEV dev, LPDWORD size, LPWSTR filename )
354 355 356 357
{
    return FALSE;
}

358 359
static DWORD nulldrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
                               struct bitblt_coords *src )
360 361 362 363
{
    return ERROR_NOT_SUPPORTED;
}

364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
static DWORD nulldrv_GetKerningPairs( PHYSDEV dev, DWORD count, LPKERNINGPAIR pairs )
{
    return 0;
}

static UINT nulldrv_GetOutlineTextMetrics( PHYSDEV dev, UINT size, LPOUTLINETEXTMETRICW otm )
{
    return 0;
}

static UINT nulldrv_GetTextCharsetInfo( PHYSDEV dev, LPFONTSIGNATURE fs, DWORD flags )
{
    return DEFAULT_CHARSET;
}

379
static BOOL nulldrv_GetTextExtentExPoint( PHYSDEV dev, LPCWSTR str, INT count, INT *dx )
380 381 382 383
{
    return FALSE;
}

384
static BOOL nulldrv_GetTextExtentExPointI( PHYSDEV dev, const WORD *indices, INT count, INT *dx )
385 386 387 388 389 390
{
    return FALSE;
}

static INT nulldrv_GetTextFace( PHYSDEV dev, INT size, LPWSTR name )
{
391 392
    INT ret = 0;
    LOGFONTW font;
393
    DC *dc = get_nulldrv_dc( dev );
394

395
    if (GetObjectW( dc->hFont, sizeof(font), &font ))
396 397 398 399 400 401 402 403 404
    {
        ret = strlenW( font.lfFaceName ) + 1;
        if (name)
        {
            lstrcpynW( name, font.lfFaceName, size );
            ret = min( size, ret );
        }
    }
    return ret;
405 406
}

407
static BOOL nulldrv_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
408 409 410 411
{
    return FALSE;
}

412
static BOOL nulldrv_LineTo( PHYSDEV dev, INT x, INT y )
413 414 415 416
{
    return TRUE;
}

417
static BOOL nulldrv_MoveTo( PHYSDEV dev, INT x, INT y )
418 419 420 421
{
    return TRUE;
}

422
static BOOL nulldrv_PaintRgn( PHYSDEV dev, HRGN rgn )
423 424 425 426
{
    return TRUE;
}

427
static BOOL nulldrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
428 429 430 431
{
    return TRUE;
}

432 433
static BOOL nulldrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                         INT xstart, INT ystart, INT xend, INT yend )
434 435 436 437
{
    return TRUE;
}

438
static BOOL nulldrv_PolyPolygon( PHYSDEV dev, const POINT *points, const INT *counts, UINT polygons )
439 440 441 442
{
    return TRUE;
}

443
static BOOL nulldrv_PolyPolyline( PHYSDEV dev, const POINT *points, const DWORD *counts, DWORD lines )
444 445 446 447
{
    return TRUE;
}

448
static BOOL nulldrv_Polygon( PHYSDEV dev, const POINT *points, INT count )
449
{
450 451 452
    INT counts[1] = { count };

    return PolyPolygon( dev->hdc, points, counts, 1 );
453 454
}

455
static BOOL nulldrv_Polyline( PHYSDEV dev, const POINT *points, INT count )
456
{
457 458 459 460
    DWORD counts[1] = { count };

    if (count < 0) return FALSE;
    return PolyPolyline( dev->hdc, points, counts, 1 );
461 462
}

463
static DWORD nulldrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
464 465 466 467 468 469
                               const struct gdi_image_bits *bits, struct bitblt_coords *src,
                               struct bitblt_coords *dst, DWORD rop )
{
    return ERROR_SUCCESS;
}

470
static UINT nulldrv_RealizeDefaultPalette( PHYSDEV dev )
471 472 473 474
{
    return 0;
}

475
static UINT nulldrv_RealizePalette( PHYSDEV dev, HPALETTE palette, BOOL primary )
476 477 478 479
{
    return 0;
}

480
static BOOL nulldrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
481 482 483 484
{
    return TRUE;
}

485
static HDC nulldrv_ResetDC( PHYSDEV dev, const DEVMODEW *devmode )
486 487 488 489
{
    return 0;
}

490 491
static BOOL nulldrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                               INT ell_width, INT ell_height )
492 493 494 495
{
    return TRUE;
}

496
static HBITMAP nulldrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
497 498 499 500
{
    return bitmap;
}

501
static HBRUSH nulldrv_SelectBrush( PHYSDEV dev, HBRUSH brush, const struct brush_pattern *pattern )
502 503 504 505
{
    return brush;
}

506
static HPALETTE nulldrv_SelectPalette( PHYSDEV dev, HPALETTE palette, BOOL bkgnd )
507 508 509 510
{
    return palette;
}

511
static HPEN nulldrv_SelectPen( PHYSDEV dev, HPEN pen, const struct brush_pattern *pattern )
512 513 514 515
{
    return pen;
}

516
static INT nulldrv_SetArcDirection( PHYSDEV dev, INT dir )
517 518 519 520
{
    return dir;
}

521
static COLORREF nulldrv_SetBkColor( PHYSDEV dev, COLORREF color )
522 523 524 525
{
    return color;
}

526
static INT nulldrv_SetBkMode( PHYSDEV dev, INT mode )
527 528 529 530
{
    return mode;
}

531 532 533 534 535
static UINT nulldrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags )
{
    return DCB_RESET;
}

536
static COLORREF nulldrv_SetDCBrushColor( PHYSDEV dev, COLORREF color )
537 538 539 540
{
    return color;
}

541
static COLORREF nulldrv_SetDCPenColor( PHYSDEV dev, COLORREF color )
542 543 544 545
{
    return color;
}

546
static void nulldrv_SetDeviceClipping( PHYSDEV dev, HRGN rgn )
547 548 549
{
}

550
static DWORD nulldrv_SetLayout( PHYSDEV dev, DWORD layout )
551 552 553 554
{
    return layout;
}

555
static BOOL nulldrv_SetDeviceGammaRamp( PHYSDEV dev, void *ramp )
556
{
557
    SetLastError( ERROR_INVALID_PARAMETER );
558 559 560
    return FALSE;
}

561
static DWORD nulldrv_SetMapperFlags( PHYSDEV dev, DWORD flags )
562 563 564 565
{
    return flags;
}

566
static COLORREF nulldrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
567 568 569 570
{
    return color;
}

571
static INT nulldrv_SetPolyFillMode( PHYSDEV dev, INT mode )
572 573 574 575
{
    return mode;
}

576
static INT nulldrv_SetROP2( PHYSDEV dev, INT rop )
577 578 579 580
{
    return rop;
}

581
static INT nulldrv_SetRelAbs( PHYSDEV dev, INT mode )
582 583 584 585
{
    return mode;
}

586
static INT nulldrv_SetStretchBltMode( PHYSDEV dev, INT mode )
587 588 589 590
{
    return mode;
}

591
static UINT nulldrv_SetTextAlign( PHYSDEV dev, UINT align )
592 593 594 595
{
    return align;
}

596
static INT nulldrv_SetTextCharacterExtra( PHYSDEV dev, INT extra )
597 598 599 600
{
    return extra;
}

601
static COLORREF nulldrv_SetTextColor( PHYSDEV dev, COLORREF color )
602 603 604 605
{
    return color;
}

606
static BOOL nulldrv_SetTextJustification( PHYSDEV dev, INT extra, INT breaks )
607 608 609 610
{
    return TRUE;
}

611
static INT nulldrv_StartDoc( PHYSDEV dev, const DOCINFOW *info )
612 613 614 615
{
    return 0;
}

616
static INT nulldrv_StartPage( PHYSDEV dev )
617 618 619 620
{
    return 1;
}

621
static BOOL nulldrv_UnrealizePalette( HPALETTE palette )
622 623 624 625
{
    return FALSE;
}

626
static struct opengl_funcs *nulldrv_wine_get_wgl_driver( PHYSDEV dev, UINT version )
627
{
628
    return (void *)-1;
629 630
}

631
const struct gdi_dc_funcs null_driver =
632
{
633
    nulldrv_AbortDoc,                   /* pAbortDoc */
634
    nulldrv_AbortPath,                  /* pAbortPath */
635
    nulldrv_AlphaBlend,                 /* pAlphaBlend */
636
    nulldrv_AngleArc,                   /* pAngleArc */
637
    nulldrv_Arc,                        /* pArc */
638
    nulldrv_ArcTo,                      /* pArcTo */
639
    nulldrv_BeginPath,                  /* pBeginPath */
640
    nulldrv_BlendImage,                 /* pBlendImage */
641
    nulldrv_Chord,                      /* pChord */
642
    nulldrv_CloseFigure,                /* pCloseFigure */
643
    nulldrv_CreateCompatibleDC,         /* pCreateCompatibleDC */
644 645
    nulldrv_CreateDC,                   /* pCreateDC */
    nulldrv_DeleteDC,                   /* pDeleteDC */
646
    nulldrv_DeleteObject,               /* pDeleteObject */
647
    nulldrv_DeviceCapabilities,         /* pDeviceCapabilities */
648
    nulldrv_Ellipse,                    /* pEllipse */
649 650
    nulldrv_EndDoc,                     /* pEndDoc */
    nulldrv_EndPage,                    /* pEndPage */
651
    nulldrv_EndPath,                    /* pEndPath */
652
    nulldrv_EnumFonts,                  /* pEnumFonts */
653
    nulldrv_EnumICMProfiles,            /* pEnumICMProfiles */
654
    nulldrv_ExcludeClipRect,            /* pExcludeClipRect */
655 656
    nulldrv_ExtDeviceMode,              /* pExtDeviceMode */
    nulldrv_ExtEscape,                  /* pExtEscape */
657
    nulldrv_ExtFloodFill,               /* pExtFloodFill */
658
    nulldrv_ExtSelectClipRgn,           /* pExtSelectClipRgn */
659
    nulldrv_ExtTextOut,                 /* pExtTextOut */
660
    nulldrv_FillPath,                   /* pFillPath */
661
    nulldrv_FillRgn,                    /* pFillRgn */
662
    nulldrv_FlattenPath,                /* pFlattenPath */
663
    nulldrv_FontIsLinked,               /* pFontIsLinked */
664
    nulldrv_FrameRgn,                   /* pFrameRgn */
665
    nulldrv_GdiComment,                 /* pGdiComment */
666
    nulldrv_GetBoundsRect,              /* pGetBoundsRect */
667 668
    nulldrv_GetCharABCWidths,           /* pGetCharABCWidths */
    nulldrv_GetCharABCWidthsI,          /* pGetCharABCWidthsI */
669
    nulldrv_GetCharWidth,               /* pGetCharWidth */
670
    nulldrv_GetDeviceCaps,              /* pGetDeviceCaps */
671
    nulldrv_GetDeviceGammaRamp,         /* pGetDeviceGammaRamp */
672
    nulldrv_GetFontData,                /* pGetFontData */
673
    nulldrv_GetFontRealizationInfo,     /* pGetFontRealizationInfo */
674 675 676
    nulldrv_GetFontUnicodeRanges,       /* pGetFontUnicodeRanges */
    nulldrv_GetGlyphIndices,            /* pGetGlyphIndices */
    nulldrv_GetGlyphOutline,            /* pGetGlyphOutline */
677
    nulldrv_GetICMProfile,              /* pGetICMProfile */
678
    nulldrv_GetImage,                   /* pGetImage */
679
    nulldrv_GetKerningPairs,            /* pGetKerningPairs */
680
    nulldrv_GetNearestColor,            /* pGetNearestColor */
681
    nulldrv_GetOutlineTextMetrics,      /* pGetOutlineTextMetrics */
682
    nulldrv_GetPixel,                   /* pGetPixel */
683
    nulldrv_GetSystemPaletteEntries,    /* pGetSystemPaletteEntries */
684
    nulldrv_GetTextCharsetInfo,         /* pGetTextCharsetInfo */
685
    nulldrv_GetTextExtentExPoint,       /* pGetTextExtentExPoint */
686 687
    nulldrv_GetTextExtentExPointI,      /* pGetTextExtentExPointI */
    nulldrv_GetTextFace,                /* pGetTextFace */
688
    nulldrv_GetTextMetrics,             /* pGetTextMetrics */
689
    nulldrv_GradientFill,               /* pGradientFill */
690
    nulldrv_IntersectClipRect,          /* pIntersectClipRect */
691
    nulldrv_InvertRgn,                  /* pInvertRgn */
692
    nulldrv_LineTo,                     /* pLineTo */
693
    nulldrv_ModifyWorldTransform,       /* pModifyWorldTransform */
694
    nulldrv_MoveTo,                     /* pMoveTo */
695
    nulldrv_OffsetClipRgn,              /* pOffsetClipRgn */
696 697
    nulldrv_OffsetViewportOrgEx,        /* pOffsetViewportOrg */
    nulldrv_OffsetWindowOrgEx,          /* pOffsetWindowOrg */
698
    nulldrv_PaintRgn,                   /* pPaintRgn */
699
    nulldrv_PatBlt,                     /* pPatBlt */
700
    nulldrv_Pie,                        /* pPie */
701 702 703
    nulldrv_PolyBezier,                 /* pPolyBezier */
    nulldrv_PolyBezierTo,               /* pPolyBezierTo */
    nulldrv_PolyDraw,                   /* pPolyDraw */
704 705 706 707
    nulldrv_PolyPolygon,                /* pPolyPolygon */
    nulldrv_PolyPolyline,               /* pPolyPolyline */
    nulldrv_Polygon,                    /* pPolygon */
    nulldrv_Polyline,                   /* pPolyline */
708
    nulldrv_PolylineTo,                 /* pPolylineTo */
709
    nulldrv_PutImage,                   /* pPutImage */
710 711
    nulldrv_RealizeDefaultPalette,      /* pRealizeDefaultPalette */
    nulldrv_RealizePalette,             /* pRealizePalette */
712
    nulldrv_Rectangle,                  /* pRectangle */
713 714
    nulldrv_ResetDC,                    /* pResetDC */
    nulldrv_RestoreDC,                  /* pRestoreDC */
715
    nulldrv_RoundRect,                  /* pRoundRect */
716
    nulldrv_SaveDC,                     /* pSaveDC */
717 718
    nulldrv_ScaleViewportExtEx,         /* pScaleViewportExt */
    nulldrv_ScaleWindowExtEx,           /* pScaleWindowExt */
719 720
    nulldrv_SelectBitmap,               /* pSelectBitmap */
    nulldrv_SelectBrush,                /* pSelectBrush */
721
    nulldrv_SelectClipPath,             /* pSelectClipPath */
722 723 724
    nulldrv_SelectFont,                 /* pSelectFont */
    nulldrv_SelectPalette,              /* pSelectPalette */
    nulldrv_SelectPen,                  /* pSelectPen */
725 726 727
    nulldrv_SetArcDirection,            /* pSetArcDirection */
    nulldrv_SetBkColor,                 /* pSetBkColor */
    nulldrv_SetBkMode,                  /* pSetBkMode */
728
    nulldrv_SetBoundsRect,              /* pSetBoundsRect */
729 730
    nulldrv_SetDCBrushColor,            /* pSetDCBrushColor */
    nulldrv_SetDCPenColor,              /* pSetDCPenColor */
731
    nulldrv_SetDIBitsToDevice,          /* pSetDIBitsToDevice */
732
    nulldrv_SetDeviceClipping,          /* pSetDeviceClipping */
733
    nulldrv_SetDeviceGammaRamp,         /* pSetDeviceGammaRamp */
734
    nulldrv_SetLayout,                  /* pSetLayout */
735
    nulldrv_SetMapMode,                 /* pSetMapMode */
736
    nulldrv_SetMapperFlags,             /* pSetMapperFlags */
737
    nulldrv_SetPixel,                   /* pSetPixel */
738 739 740 741 742 743 744 745
    nulldrv_SetPolyFillMode,            /* pSetPolyFillMode */
    nulldrv_SetROP2,                    /* pSetROP2 */
    nulldrv_SetRelAbs,                  /* pSetRelAbs */
    nulldrv_SetStretchBltMode,          /* pSetStretchBltMode */
    nulldrv_SetTextAlign,               /* pSetTextAlign */
    nulldrv_SetTextCharacterExtra,      /* pSetTextCharacterExtra */
    nulldrv_SetTextColor,               /* pSetTextColor */
    nulldrv_SetTextJustification,       /* pSetTextJustification */
746 747 748 749
    nulldrv_SetViewportExtEx,           /* pSetViewportExt */
    nulldrv_SetViewportOrgEx,           /* pSetViewportOrg */
    nulldrv_SetWindowExtEx,             /* pSetWindowExt */
    nulldrv_SetWindowOrgEx,             /* pSetWindowOrg */
750
    nulldrv_SetWorldTransform,          /* pSetWorldTransform */
751 752
    nulldrv_StartDoc,                   /* pStartDoc */
    nulldrv_StartPage,                  /* pStartPage */
753
    nulldrv_StretchBlt,                 /* pStretchBlt */
754
    nulldrv_StretchDIBits,              /* pStretchDIBits */
755 756
    nulldrv_StrokeAndFillPath,          /* pStrokeAndFillPath */
    nulldrv_StrokePath,                 /* pStrokePath */
757
    nulldrv_UnrealizePalette,           /* pUnrealizePalette */
758
    nulldrv_WidenPath,                  /* pWidenPath */
759
    nulldrv_wine_get_wgl_driver,        /* wine_get_wgl_driver */
760 761

    GDI_PRIORITY_NULL_DRV               /* priority */
762 763 764
};


765 766 767 768
/*****************************************************************************
 *      DRIVER_GetDriverName
 *
 */
769
BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
770
{
771 772
    static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
    static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
773
    static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
774 775
    static const WCHAR empty_strW[] = { 0 };
    WCHAR *p;
776 777

    /* display is a special case */
778 779
    if (!strcmpiW( device, displayW ) ||
        !strcmpiW( device, display1W ))
780
    {
781
        lstrcpynW( driver, displayW, size );
782 783 784
        return TRUE;
    }

785
    size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
786
    if(!size) {
787
        WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
788 789
        return FALSE;
    }
790
    p = strchrW(driver, ',');
791 792
    if(!p)
    {
793
        WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
794 795
        return FALSE;
    }
796 797
    *p = 0;
    TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
798 799 800
    return TRUE;
}

801 802 803 804 805 806 807

/***********************************************************************
 *           GdiConvertToDevmodeW    (GDI32.@)
 */
DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
{
    DEVMODEW *dmW;
808
    WORD dmW_size, dmA_size;
809

810
    dmA_size = dmA->dmSize;
811 812 813 814 815

    /* this is the minimal dmSize that XP accepts */
    if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
        return NULL;

816 817
    if (dmA_size > sizeof(DEVMODEA))
        dmA_size = sizeof(DEVMODEA);
818

819 820
    dmW_size = dmA_size + CCHDEVICENAME;
    if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
821 822 823 824 825
        dmW_size += CCHFORMNAME;

    dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
    if (!dmW) return NULL;

826
    MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
827 828
                                   dmW->dmDeviceName, CCHDEVICENAME);
    /* copy slightly more, to avoid long computations */
829
    memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
830

831
    if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
832
    {
833 834
        if (dmA->dmFields & DM_FORMNAME)
            MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
835
                                       dmW->dmFormName, CCHFORMNAME);
836 837 838
        else
            dmW->dmFormName[0] = 0;

839 840
        if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
            memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
841 842 843
    }

    if (dmA->dmDriverExtra)
844
        memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
845 846 847 848 849 850 851

    dmW->dmSize = dmW_size;

    return dmW;
}


852 853 854 855 856 857 858 859
/*****************************************************************************
 *      @ [GDI32.100]
 *
 * This should thunk to 16-bit and simply call the proc with the given args.
 */
INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
                                 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
{
860
    FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
861 862 863 864 865 866 867
    return -1;
}

/*****************************************************************************
 *      @ [GDI32.101]
 *
 * This should load the correct driver for lpszDevice and calls this driver's
868
 * ExtDeviceModePropSheet proc.
869
 *
870
 * Note: The driver calls a callback routine for each property sheet page; these
871 872
 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
 * The layout of this structure is:
873
 *
874 875 876 877 878 879 880 881 882 883
 * struct
 * {
 *   DWORD  nPages;
 *   DWORD  unknown;
 *   HPROPSHEETPAGE  pages[10];
 * };
 */
INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
                                             LPCSTR lpszPort, LPVOID lpPropSheet )
{
884
    FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
885 886 887 888 889 890
    return -1;
}

/*****************************************************************************
 *      @ [GDI32.102]
 *
891
 * This should load the correct driver for lpszDevice and call this driver's
892
 * ExtDeviceMode proc.
893 894
 *
 * FIXME: convert ExtDeviceMode to unicode in the driver interface
895 896 897 898 899 900
 */
INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
                                    LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
                                    LPSTR lpszPort, LPDEVMODEA lpdmInput,
                                    LPSTR lpszProfile, DWORD fwMode )
{
901 902
    WCHAR deviceW[300];
    WCHAR bufW[300];
903 904 905 906 907
    char buf[300];
    HDC hdc;
    DC *dc;
    INT ret = -1;

908
    TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
909 910
          hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );

911 912 913 914 915 916
    if (!lpszDevice) return -1;
    if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;

    if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;

    if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
917

918
    if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
919

920
    if ((dc = get_dc_ptr( hdc )))
921
    {
922 923 924
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtDeviceMode );
        ret = physdev->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
                                              lpdmInput, lpszProfile, fwMode );
925
	release_dc_ptr( dc );
926 927 928 929 930 931 932 933 934 935 936 937 938 939
    }
    DeleteDC( hdc );
    return ret;
}

/****************************************************************************
 *      @ [GDI32.103]
 *
 * This should load the correct driver for lpszDevice and calls this driver's
 * AdvancedSetupDialog proc.
 */
INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
                                          LPDEVMODEA devin, LPDEVMODEA devout )
{
940
    TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
941 942 943 944 945 946 947 948
    return -1;
}

/*****************************************************************************
 *      @ [GDI32.104]
 *
 * This should load the correct driver for lpszDevice and calls this driver's
 * DeviceCapabilities proc.
949 950
 *
 * FIXME: convert DeviceCapabilities to unicode in the driver interface
951 952 953 954 955
 */
DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
                                           WORD fwCapability, LPSTR lpszOutput,
                                           LPDEVMODEA lpdm )
{
956 957
    WCHAR deviceW[300];
    WCHAR bufW[300];
958 959 960 961 962 963 964
    char buf[300];
    HDC hdc;
    DC *dc;
    INT ret = -1;

    TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );

965 966 967 968 969 970
    if (!lpszDevice) return -1;
    if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;

    if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;

    if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
971

972
    if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
973

974
    if ((dc = get_dc_ptr( hdc )))
975
    {
976 977 978
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDeviceCapabilities );
        ret = physdev->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
                                                   fwCapability, lpszOutput, lpdm );
979
        release_dc_ptr( dc );
980 981 982 983
    }
    DeleteDC( hdc );
    return ret;
}
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049


/************************************************************************
 *             Escape  [GDI32.@]
 */
INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
{
    INT ret;
    POINT *pt;

    switch (escape)
    {
    case ABORTDOC:
        return AbortDoc( hdc );

    case ENDDOC:
        return EndDoc( hdc );

    case GETPHYSPAGESIZE:
        pt = out_data;
        pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
        pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
        return 1;

    case GETPRINTINGOFFSET:
        pt = out_data;
        pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
        pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
        return 1;

    case GETSCALINGFACTOR:
        pt = out_data;
        pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
        pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
        return 1;

    case NEWFRAME:
        return EndPage( hdc );

    case SETABORTPROC:
        return SetAbortProc( hdc, (ABORTPROC)in_data );

    case STARTDOC:
        {
            DOCINFOA doc;
            char *name = NULL;

            /* in_data may not be 0 terminated so we must copy it */
            if (in_data)
            {
                name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
                memcpy( name, in_data, in_count );
                name[in_count] = 0;
            }
            /* out_data is actually a pointer to the DocInfo structure and used as
             * a second input parameter */
            if (out_data) doc = *(DOCINFOA *)out_data;
            else
            {
                doc.cbSize = sizeof(doc);
                doc.lpszOutput = NULL;
                doc.lpszDatatype = NULL;
                doc.fwType = 0;
            }
            doc.lpszDocName = name;
            ret = StartDocA( hdc, &doc );
1050
            HeapFree( GetProcessHeap(), 0, name );
1051 1052 1053 1054 1055 1056
            if (ret > 0) ret = StartPage( hdc );
            return ret;
        }

    case QUERYESCSUPPORT:
        {
1057 1058 1059 1060 1061
            DWORD code;

            if (in_count < sizeof(SHORT)) return 0;
            code = (in_count < sizeof(DWORD)) ? *(const USHORT *)in_data : *(const DWORD *)in_data;
            switch (code)
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
            {
            case ABORTDOC:
            case ENDDOC:
            case GETPHYSPAGESIZE:
            case GETPRINTINGOFFSET:
            case GETSCALINGFACTOR:
            case NEWFRAME:
            case QUERYESCSUPPORT:
            case SETABORTPROC:
            case STARTDOC:
                return TRUE;
            }
            break;
        }
    }

    /* if not handled internally, pass it to the driver */
    return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
}


/******************************************************************************
 *		ExtEscape	[GDI32.@]
 *
1086 1087
 * Access capabilities of a particular device that are not available through GDI.
 *
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
 * PARAMS
 *    hdc         [I] Handle to device context
 *    nEscape     [I] Escape function
 *    cbInput     [I] Number of bytes in input structure
 *    lpszInData  [I] Pointer to input structure
 *    cbOutput    [I] Number of bytes in output structure
 *    lpszOutData [O] Pointer to output structure
 *
 * RETURNS
 *    Success: >0
 *    Not implemented: 0
 *    Failure: <0
 */
INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
                      INT cbOutput, LPSTR lpszOutData )
{
1104 1105
    PHYSDEV physdev;
    INT ret;
1106
    DC * dc = get_dc_ptr( hdc );
1107

1108 1109 1110 1111 1112
    if (!dc) return 0;
    update_dc( dc );
    physdev = GET_DC_PHYSDEV( dc, pExtEscape );
    ret = physdev->funcs->pExtEscape( physdev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
    release_dc_ptr( dc );
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
    return ret;
}


/*******************************************************************
 *      DrawEscape [GDI32.@]
 *
 *
 */
INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
{
    FIXME("DrawEscape, stub\n");
    return 0;
}
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138

/*******************************************************************
 *      NamedEscape [GDI32.@]
 */
INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
                        INT cbOutput, LPSTR lpszOutData )
{
    FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
          hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
          lpszOutData);
    return 0;
}
1139 1140 1141 1142 1143 1144 1145

/*******************************************************************
 *      DdQueryDisplaySettingsUniqueness [GDI32.@]
 *      GdiEntry13                       [GDI32.@]
 */
ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
{
Louis Lenders's avatar
Louis Lenders committed
1146 1147 1148 1149
    static int warn_once;

    if (!warn_once++)
        FIXME("stub\n");
1150 1151
    return 0;
}
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169

/******************************************************************************
 *		D3DKMTOpenAdapterFromHdc [GDI32.@]
 */
NTSTATUS WINAPI D3DKMTOpenAdapterFromHdc( void *pData )
{
    FIXME("(%p): stub\n", pData);
    return STATUS_NO_MEMORY;
}

/******************************************************************************
 *		D3DKMTEscape [GDI32.@]
 */
NTSTATUS WINAPI D3DKMTEscape( const void *pData )
{
    FIXME("(%p): stub\n", pData);
    return STATUS_NO_MEMORY;
}