DIB Engine: Hook the engine between GDI32 and Display driver
[wine/hacks.git] / dlls / gdi32 / driver.c
blob945bb77cdabdd78eb94d8407b77be35671e4b7af
1 /*
2 * Graphics driver management functions
4 * Copyright 1994 Bob Amstadt
5 * Copyright 1996, 2001 Alexandre Julliard
6 * Copyright 2009 Massimo Del Fedele
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "ddrawgdi.h"
34 #include "wine/winbase16.h"
36 #include "gdi_private.h"
37 #include "wine/unicode.h"
38 #include "wine/list.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(driver);
43 struct graphics_driver
45 struct list entry;
46 HMODULE module; /* module handle */
47 DC_FUNCTIONS funcs;
50 static struct list drivers = LIST_INIT( drivers );
51 static struct graphics_driver *display_driver;
53 static CRITICAL_SECTION driver_section;
54 static CRITICAL_SECTION_DEBUG critsect_debug =
56 0, 0, &driver_section,
57 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
58 0, 0, { (DWORD_PTR)(__FILE__ ": driver_section") }
60 static CRITICAL_SECTION driver_section = { &critsect_debug, -1, 0, 0, 0, 0 };
62 /**********************************************************************
63 * create_driver
65 * Allocate and fill the driver structure for a given module.
67 static struct graphics_driver *create_driver( HMODULE module )
69 struct graphics_driver *driver;
71 if (!(driver = HeapAlloc( GetProcessHeap(), 0, sizeof(*driver)))) return NULL;
72 driver->module = module;
74 /* fill the function table */
75 if (module)
77 #define GET_FUNC(name) driver->funcs.p##name = (void*)GetProcAddress( module, #name )
78 GET_FUNC(AbortDoc);
79 GET_FUNC(AbortPath);
80 GET_FUNC(AlphaBlend);
81 GET_FUNC(AngleArc);
82 GET_FUNC(Arc);
83 GET_FUNC(ArcTo);
84 GET_FUNC(BeginPath);
85 GET_FUNC(BitBlt);
86 GET_FUNC(ChoosePixelFormat);
87 GET_FUNC(Chord);
88 GET_FUNC(CloseFigure);
89 GET_FUNC(CreateBitmap);
90 GET_FUNC(CreateDC);
91 GET_FUNC(CreateDIBSection);
92 GET_FUNC(DeleteBitmap);
93 GET_FUNC(DeleteDC);
94 GET_FUNC(DescribePixelFormat);
95 GET_FUNC(DeviceCapabilities);
96 GET_FUNC(Ellipse);
97 GET_FUNC(EndDoc);
98 GET_FUNC(EndPage);
99 GET_FUNC(EndPath);
100 GET_FUNC(EnumDeviceFonts);
101 GET_FUNC(ExcludeClipRect);
102 GET_FUNC(ExtDeviceMode);
103 GET_FUNC(ExtEscape);
104 GET_FUNC(ExtFloodFill);
105 GET_FUNC(ExtSelectClipRgn);
106 GET_FUNC(ExtTextOut);
107 GET_FUNC(FillPath);
108 GET_FUNC(FillRgn);
109 GET_FUNC(FlattenPath);
110 GET_FUNC(FrameRgn);
111 GET_FUNC(GdiComment);
112 GET_FUNC(GetBitmapBits);
113 GET_FUNC(GetCharWidth);
114 GET_FUNC(GetDCOrgEx);
115 GET_FUNC(GetDIBColorTable);
116 GET_FUNC(GetDIBits);
117 GET_FUNC(GetDeviceCaps);
118 GET_FUNC(GetDeviceGammaRamp);
119 GET_FUNC(GetICMProfile);
120 GET_FUNC(GetNearestColor);
121 GET_FUNC(GetPixel);
122 GET_FUNC(GetPixelFormat);
123 GET_FUNC(GetSystemPaletteEntries);
124 GET_FUNC(GetTextExtentExPoint);
125 GET_FUNC(GetTextMetrics);
126 GET_FUNC(IntersectClipRect);
127 GET_FUNC(InvertRgn);
128 GET_FUNC(LineTo);
129 GET_FUNC(MoveTo);
130 GET_FUNC(ModifyWorldTransform);
131 GET_FUNC(OffsetClipRgn);
132 GET_FUNC(OffsetViewportOrg);
133 GET_FUNC(OffsetWindowOrg);
134 GET_FUNC(PaintRgn);
135 GET_FUNC(PatBlt);
136 GET_FUNC(Pie);
137 GET_FUNC(PolyBezier);
138 GET_FUNC(PolyBezierTo);
139 GET_FUNC(PolyDraw);
140 GET_FUNC(PolyPolygon);
141 GET_FUNC(PolyPolyline);
142 GET_FUNC(Polygon);
143 GET_FUNC(Polyline);
144 GET_FUNC(PolylineTo);
145 GET_FUNC(RealizeDefaultPalette);
146 GET_FUNC(RealizePalette);
147 GET_FUNC(Rectangle);
148 GET_FUNC(ResetDC);
149 GET_FUNC(RestoreDC);
150 GET_FUNC(RoundRect);
151 GET_FUNC(SaveDC);
152 GET_FUNC(ScaleViewportExt);
153 GET_FUNC(ScaleWindowExt);
154 GET_FUNC(SelectBitmap);
155 GET_FUNC(SelectBrush);
156 GET_FUNC(SelectClipPath);
157 GET_FUNC(SelectFont);
158 GET_FUNC(SelectPalette);
159 GET_FUNC(SelectPen);
160 GET_FUNC(SetArcDirection);
161 GET_FUNC(SetBitmapBits);
162 GET_FUNC(SetBkColor);
163 GET_FUNC(SetBkMode);
164 GET_FUNC(SetDCBrushColor);
165 GET_FUNC(SetDCPenColor);
166 GET_FUNC(SetDIBColorTable);
167 GET_FUNC(SetDIBits);
168 GET_FUNC(SetDIBitsToDevice);
169 GET_FUNC(SetDeviceClipping);
170 GET_FUNC(SetDeviceGammaRamp);
171 GET_FUNC(SetMapMode);
172 GET_FUNC(SetMapperFlags);
173 GET_FUNC(SetPixel);
174 GET_FUNC(SetPixelFormat);
175 GET_FUNC(SetPolyFillMode);
176 GET_FUNC(SetROP2);
177 GET_FUNC(SetRelAbs);
178 GET_FUNC(SetStretchBltMode);
179 GET_FUNC(SetTextAlign);
180 GET_FUNC(SetTextCharacterExtra);
181 GET_FUNC(SetTextColor);
182 GET_FUNC(SetTextJustification);
183 GET_FUNC(SetViewportExt);
184 GET_FUNC(SetViewportOrg);
185 GET_FUNC(SetWindowExt);
186 GET_FUNC(SetWindowOrg);
187 GET_FUNC(SetWorldTransform);
188 GET_FUNC(StartDoc);
189 GET_FUNC(StartPage);
190 GET_FUNC(StretchBlt);
191 GET_FUNC(StretchDIBits);
192 GET_FUNC(StrokeAndFillPath);
193 GET_FUNC(StrokePath);
194 GET_FUNC(SwapBuffers);
195 GET_FUNC(UnrealizePalette);
196 GET_FUNC(WidenPath);
198 /* OpenGL32 */
199 GET_FUNC(wglCreateContext);
200 GET_FUNC(wglCreateContextAttribsARB);
201 GET_FUNC(wglDeleteContext);
202 GET_FUNC(wglGetProcAddress);
203 GET_FUNC(wglGetPbufferDCARB);
204 GET_FUNC(wglMakeContextCurrentARB);
205 GET_FUNC(wglMakeCurrent);
206 GET_FUNC(wglSetPixelFormatWINE);
207 GET_FUNC(wglShareLists);
208 GET_FUNC(wglUseFontBitmapsA);
209 GET_FUNC(wglUseFontBitmapsW);
210 #undef GET_FUNC
212 else memset( &driver->funcs, 0, sizeof(driver->funcs) );
214 return driver;
218 /**********************************************************************
219 * Load_Dib_Driver
221 * Check if we want the DIB engine and try to load it
223 static HMODULE Load_Dib_Driver(void)
225 HMODULE module;
227 static const char *winedib_drv = "winedib.drv";
229 /* we do want use DIB Engine ? */
230 BOOL driverRequired = TRUE;
232 /* already checked env/registry for DIB driver ? */
233 BOOL envChecked = FALSE;
235 char *winedib;
236 char buffer[10];
238 /* environment variable WINEDIB takes precedence */
239 if( (winedib = getenv("WINEDIB")) != NULL)
241 if(!strcasecmp(winedib, "ON") ||
242 !strcasecmp(winedib, "TRUE") ||
243 !strcasecmp(winedib, "ENABLE") ||
244 !strcasecmp(winedib, "ENABLED")
247 TRACE("DIB Engine enabled by environment\n");
248 envChecked = TRUE;
249 driverRequired = TRUE;
251 else if(!strcasecmp(winedib, "OFF") ||
252 !strcasecmp(winedib, "FALSE") ||
253 !strcasecmp(winedib, "DISABLE") ||
254 !strcasecmp(winedib, "DISABLED")
257 TRACE("DIB Engine disabled by environment\n");
258 envChecked = TRUE;
259 driverRequired = FALSE;
261 else
262 ERR("Bad WINEDIB environment variable\n");
265 /* no WINEDIB environment var found or wrong value, we check registry */
266 if(!envChecked)
268 HKEY hkey;
269 buffer[0] = 0;
270 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DIB Engine", &hkey ))
272 DWORD type, count = sizeof(buffer);
273 RegQueryValueExA( hkey, "Enable", 0, &type, (LPBYTE) buffer, &count );
274 RegCloseKey( hkey );
276 if(*buffer)
278 /* registry value found, must be Y or y to enable driver, N or n to disable */
279 if(!strncasecmp(buffer, "Y", 1))
281 TRACE("DIB Engine enabled by registry\n");
282 envChecked = TRUE;
283 driverRequired = TRUE;
285 else if(!strncasecmp(buffer, "N", 1))
287 TRACE("DIB Engine disabled by registry\n");
288 envChecked = TRUE;
289 driverRequired = FALSE;
294 /* none of above, we assume we don't want to use engine */
295 if(!envChecked)
297 TRACE("DIB Engine disabled by default\n");
298 envChecked = TRUE;
299 driverRequired = FALSE;
302 /* if DIB Engine is required, try to load it
303 * otherwise just return NULL module */
304 if(driverRequired)
306 if( (module = LoadLibraryA( winedib_drv )) != 0)
307 TRACE("Succesfully loaded DIB Engine\n");
308 else
309 ERR("Couldn't load DIB Engine\n");
310 return module;
312 else
313 return 0;
316 /**********************************************************************
317 * DRIVER_get_display_driver
319 * Special case for loading the display driver: get the name from the config file
321 const DC_FUNCTIONS *DRIVER_get_display_driver(void)
323 struct graphics_driver *driver;
324 char buffer[MAX_PATH], libname[32], *name, *next;
325 HMODULE module = 0;
326 HKEY hkey;
328 if (display_driver) return &display_driver->funcs; /* already loaded */
330 /* check at first if DIB engine is present and if we want
331 * to use it */
332 if( (module = Load_Dib_Driver()) == 0)
334 /* no DIB Engine loaded, just load normal display driver */
336 strcpy( buffer, "x11" ); /* default value */
337 /* @@ Wine registry key: HKCU\Software\Wine\Drivers */
338 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Drivers", &hkey ))
340 DWORD type, count = sizeof(buffer);
341 RegQueryValueExA( hkey, "Graphics", 0, &type, (LPBYTE) buffer, &count );
342 RegCloseKey( hkey );
345 name = buffer;
346 while (name)
348 next = strchr( name, ',' );
349 if (next) *next++ = 0;
351 snprintf( libname, sizeof(libname), "wine%s.drv", name );
352 if ((module = LoadLibraryA( libname )) != 0) break;
353 name = next;
357 if (!(driver = create_driver( module )))
359 MESSAGE( "Could not create graphics driver '%s'\n", buffer );
360 FreeLibrary( module );
361 ExitProcess(1);
363 if (InterlockedCompareExchangePointer( (void **)&display_driver, driver, NULL ))
365 /* somebody beat us to it */
366 FreeLibrary( driver->module );
367 HeapFree( GetProcessHeap(), 0, driver );
369 return &display_driver->funcs;
373 /**********************************************************************
374 * DRIVER_load_driver
376 const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name )
378 HMODULE module;
379 struct graphics_driver *driver, *new_driver;
380 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
381 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
383 /* display driver is a special case */
384 if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver();
386 if ((module = GetModuleHandleW( name )))
388 if (display_driver && display_driver->module == module) return &display_driver->funcs;
389 EnterCriticalSection( &driver_section );
390 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
392 if (driver->module == module) goto done;
394 LeaveCriticalSection( &driver_section );
397 if (!(module = LoadLibraryW( name ))) return NULL;
399 if (!(new_driver = create_driver( module )))
401 FreeLibrary( module );
402 return NULL;
405 /* check if someone else added it in the meantime */
406 EnterCriticalSection( &driver_section );
407 LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry )
409 if (driver->module != module) continue;
410 FreeLibrary( module );
411 HeapFree( GetProcessHeap(), 0, new_driver );
412 goto done;
414 driver = new_driver;
415 list_add_head( &drivers, &driver->entry );
416 TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) );
417 done:
418 LeaveCriticalSection( &driver_section );
419 return &driver->funcs;
423 /*****************************************************************************
424 * DRIVER_GetDriverName
427 BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size )
429 static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 };
430 static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 };
431 static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
432 static const WCHAR empty_strW[] = { 0 };
433 WCHAR *p;
435 /* display is a special case */
436 if (!strcmpiW( device, displayW ) ||
437 !strcmpiW( device, display1W ))
439 lstrcpynW( driver, displayW, size );
440 return TRUE;
443 size = GetProfileStringW(devicesW, device, empty_strW, driver, size);
444 if(!size) {
445 WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device));
446 return FALSE;
448 p = strchrW(driver, ',');
449 if(!p)
451 WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device));
452 return FALSE;
454 *p = 0;
455 TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device));
456 return TRUE;
460 /***********************************************************************
461 * GdiConvertToDevmodeW (GDI32.@)
463 DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
465 DEVMODEW *dmW;
466 WORD dmW_size, dmA_size;
468 dmA_size = dmA->dmSize;
470 /* this is the minimal dmSize that XP accepts */
471 if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
472 return NULL;
474 if (dmA_size > sizeof(DEVMODEA))
475 dmA_size = sizeof(DEVMODEA);
477 dmW_size = dmA_size + CCHDEVICENAME;
478 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
479 dmW_size += CCHFORMNAME;
481 dmW = HeapAlloc(GetProcessHeap(), 0, dmW_size + dmA->dmDriverExtra);
482 if (!dmW) return NULL;
484 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmDeviceName, -1,
485 dmW->dmDeviceName, CCHDEVICENAME);
486 /* copy slightly more, to avoid long computations */
487 memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion, dmA_size - CCHDEVICENAME);
489 if (dmA_size >= FIELD_OFFSET(DEVMODEA, dmFormName) + CCHFORMNAME)
491 if (dmA->dmFields & DM_FORMNAME)
492 MultiByteToWideChar(CP_ACP, 0, (const char*) dmA->dmFormName, -1,
493 dmW->dmFormName, CCHFORMNAME);
494 else
495 dmW->dmFormName[0] = 0;
497 if (dmA_size > FIELD_OFFSET(DEVMODEA, dmLogPixels))
498 memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA_size - FIELD_OFFSET(DEVMODEA, dmLogPixels));
501 if (dmA->dmDriverExtra)
502 memcpy((char *)dmW + dmW_size, (const char *)dmA + dmA_size, dmA->dmDriverExtra);
504 dmW->dmSize = dmW_size;
506 return dmW;
510 /*****************************************************************************
511 * @ [GDI32.100]
513 * This should thunk to 16-bit and simply call the proc with the given args.
515 INT WINAPI GDI_CallDevInstall16( FARPROC16 lpfnDevInstallProc, HWND hWnd,
516 LPSTR lpModelName, LPSTR OldPort, LPSTR NewPort )
518 FIXME("(%p, %p, %s, %s, %s)\n", lpfnDevInstallProc, hWnd, lpModelName, OldPort, NewPort );
519 return -1;
522 /*****************************************************************************
523 * @ [GDI32.101]
525 * This should load the correct driver for lpszDevice and calls this driver's
526 * ExtDeviceModePropSheet proc.
528 * Note: The driver calls a callback routine for each property sheet page; these
529 * pages are supposed to be filled into the structure pointed to by lpPropSheet.
530 * The layout of this structure is:
532 * struct
534 * DWORD nPages;
535 * DWORD unknown;
536 * HPROPSHEETPAGE pages[10];
537 * };
539 INT WINAPI GDI_CallExtDeviceModePropSheet16( HWND hWnd, LPCSTR lpszDevice,
540 LPCSTR lpszPort, LPVOID lpPropSheet )
542 FIXME("(%p, %s, %s, %p)\n", hWnd, lpszDevice, lpszPort, lpPropSheet );
543 return -1;
546 /*****************************************************************************
547 * @ [GDI32.102]
549 * This should load the correct driver for lpszDevice and call this driver's
550 * ExtDeviceMode proc.
552 * FIXME: convert ExtDeviceMode to unicode in the driver interface
554 INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd,
555 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
556 LPSTR lpszPort, LPDEVMODEA lpdmInput,
557 LPSTR lpszProfile, DWORD fwMode )
559 WCHAR deviceW[300];
560 WCHAR bufW[300];
561 char buf[300];
562 HDC hdc;
563 DC *dc;
564 INT ret = -1;
566 TRACE("(%p, %p, %s, %s, %p, %s, %d)\n",
567 hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode );
569 if (!lpszDevice) return -1;
570 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
572 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
574 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
576 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
578 if ((dc = get_dc_ptr( hdc )))
580 if (dc->funcs->pExtDeviceMode)
581 ret = dc->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort,
582 lpdmInput, lpszProfile, fwMode );
583 release_dc_ptr( dc );
585 DeleteDC( hdc );
586 return ret;
589 /****************************************************************************
590 * @ [GDI32.103]
592 * This should load the correct driver for lpszDevice and calls this driver's
593 * AdvancedSetupDialog proc.
595 INT WINAPI GDI_CallAdvancedSetupDialog16( HWND hwnd, LPSTR lpszDevice,
596 LPDEVMODEA devin, LPDEVMODEA devout )
598 TRACE("(%p, %s, %p, %p)\n", hwnd, lpszDevice, devin, devout );
599 return -1;
602 /*****************************************************************************
603 * @ [GDI32.104]
605 * This should load the correct driver for lpszDevice and calls this driver's
606 * DeviceCapabilities proc.
608 * FIXME: convert DeviceCapabilities to unicode in the driver interface
610 DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort,
611 WORD fwCapability, LPSTR lpszOutput,
612 LPDEVMODEA lpdm )
614 WCHAR deviceW[300];
615 WCHAR bufW[300];
616 char buf[300];
617 HDC hdc;
618 DC *dc;
619 INT ret = -1;
621 TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm );
623 if (!lpszDevice) return -1;
624 if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1;
626 if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1;
628 if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1;
630 if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1;
632 if ((dc = get_dc_ptr( hdc )))
634 if (dc->funcs->pDeviceCapabilities)
635 ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort,
636 fwCapability, lpszOutput, lpdm );
637 release_dc_ptr( dc );
639 DeleteDC( hdc );
640 return ret;
644 /************************************************************************
645 * Escape [GDI32.@]
647 INT WINAPI Escape( HDC hdc, INT escape, INT in_count, LPCSTR in_data, LPVOID out_data )
649 INT ret;
650 POINT *pt;
652 switch (escape)
654 case ABORTDOC:
655 return AbortDoc( hdc );
657 case ENDDOC:
658 return EndDoc( hdc );
660 case GETPHYSPAGESIZE:
661 pt = out_data;
662 pt->x = GetDeviceCaps( hdc, PHYSICALWIDTH );
663 pt->y = GetDeviceCaps( hdc, PHYSICALHEIGHT );
664 return 1;
666 case GETPRINTINGOFFSET:
667 pt = out_data;
668 pt->x = GetDeviceCaps( hdc, PHYSICALOFFSETX );
669 pt->y = GetDeviceCaps( hdc, PHYSICALOFFSETY );
670 return 1;
672 case GETSCALINGFACTOR:
673 pt = out_data;
674 pt->x = GetDeviceCaps( hdc, SCALINGFACTORX );
675 pt->y = GetDeviceCaps( hdc, SCALINGFACTORY );
676 return 1;
678 case NEWFRAME:
679 return EndPage( hdc );
681 case SETABORTPROC:
682 return SetAbortProc( hdc, (ABORTPROC)in_data );
684 case STARTDOC:
686 DOCINFOA doc;
687 char *name = NULL;
689 /* in_data may not be 0 terminated so we must copy it */
690 if (in_data)
692 name = HeapAlloc( GetProcessHeap(), 0, in_count+1 );
693 memcpy( name, in_data, in_count );
694 name[in_count] = 0;
696 /* out_data is actually a pointer to the DocInfo structure and used as
697 * a second input parameter */
698 if (out_data) doc = *(DOCINFOA *)out_data;
699 else
701 doc.cbSize = sizeof(doc);
702 doc.lpszOutput = NULL;
703 doc.lpszDatatype = NULL;
704 doc.fwType = 0;
706 doc.lpszDocName = name;
707 ret = StartDocA( hdc, &doc );
708 HeapFree( GetProcessHeap(), 0, name );
709 if (ret > 0) ret = StartPage( hdc );
710 return ret;
713 case QUERYESCSUPPORT:
715 const INT *ptr = (const INT *)in_data;
716 if (in_count < sizeof(INT)) return 0;
717 switch(*ptr)
719 case ABORTDOC:
720 case ENDDOC:
721 case GETPHYSPAGESIZE:
722 case GETPRINTINGOFFSET:
723 case GETSCALINGFACTOR:
724 case NEWFRAME:
725 case QUERYESCSUPPORT:
726 case SETABORTPROC:
727 case STARTDOC:
728 return TRUE;
730 break;
734 /* if not handled internally, pass it to the driver */
735 return ExtEscape( hdc, escape, in_count, in_data, 0, out_data );
739 /******************************************************************************
740 * ExtEscape [GDI32.@]
742 * Access capabilities of a particular device that are not available through GDI.
744 * PARAMS
745 * hdc [I] Handle to device context
746 * nEscape [I] Escape function
747 * cbInput [I] Number of bytes in input structure
748 * lpszInData [I] Pointer to input structure
749 * cbOutput [I] Number of bytes in output structure
750 * lpszOutData [O] Pointer to output structure
752 * RETURNS
753 * Success: >0
754 * Not implemented: 0
755 * Failure: <0
757 INT WINAPI ExtEscape( HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData,
758 INT cbOutput, LPSTR lpszOutData )
760 INT ret = 0;
761 DC * dc = get_dc_ptr( hdc );
762 if (dc)
764 if (dc->funcs->pExtEscape)
765 ret = dc->funcs->pExtEscape( dc->physDev, nEscape, cbInput, lpszInData, cbOutput, lpszOutData );
766 release_dc_ptr( dc );
768 return ret;
772 /*******************************************************************
773 * DrawEscape [GDI32.@]
777 INT WINAPI DrawEscape(HDC hdc, INT nEscape, INT cbInput, LPCSTR lpszInData)
779 FIXME("DrawEscape, stub\n");
780 return 0;
783 /*******************************************************************
784 * NamedEscape [GDI32.@]
786 INT WINAPI NamedEscape( HDC hdc, LPCWSTR pDriver, INT nEscape, INT cbInput, LPCSTR lpszInData,
787 INT cbOutput, LPSTR lpszOutData )
789 FIXME("(%p, %s, %d, %d, %p, %d, %p)\n",
790 hdc, wine_dbgstr_w(pDriver), nEscape, cbInput, lpszInData, cbOutput,
791 lpszOutData);
792 return 0;
795 /*******************************************************************
796 * DdQueryDisplaySettingsUniqueness [GDI32.@]
797 * GdiEntry13 [GDI32.@]
799 ULONG WINAPI DdQueryDisplaySettingsUniqueness(VOID)
801 static int warn_once;
803 if (!warn_once++)
804 FIXME("stub\n");
805 return 0;