2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: dc.c,v 1.151 2004/12/12 21:25:05 weiden Exp $
21 * DC.C - Device context functions
26 #ifndef OBJ_COLORSPACE
27 #define OBJ_COLORSPACE (14)
30 static GDIDEVICE PrimarySurface
;
32 /* FIXME: DCs should probably be thread safe */
35 * DC device-independent Get/SetXXX functions
36 * (RJJ) swiped from WINE
39 #define DC_GET_VAL( func_type, func_name, dc_field ) \
40 func_type STDCALL func_name( HDC hdc ) \
43 PDC dc = DC_LockDc( hdc ); \
46 SetLastWin32Error(ERROR_INVALID_HANDLE); \
54 /* DC_GET_VAL_EX is used to define functions returning a POINT or a SIZE. It is
55 * important that the function has the right signature, for the implementation
56 * we can do whatever we want.
58 #define DC_GET_VAL_EX( FuncName, ret_x, ret_y, type, ax, ay ) \
59 VOID FASTCALL Int##FuncName ( PDC dc, LP##type pt) \
66 BOOL STDCALL NtGdi##FuncName ( HDC hdc, LP##type pt ) \
73 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
76 if(!(dc = DC_LockDc(hdc))) \
78 SetLastWin32Error(ERROR_INVALID_HANDLE); \
81 Int##FuncName( dc, &Safept); \
83 Status = MmCopyToCaller(pt, &Safept, sizeof( type )); \
84 if(!NT_SUCCESS(Status)) \
86 SetLastNtError(Status); \
92 #define DC_SET_MODE( func_name, dc_field, min_val, max_val ) \
93 INT STDCALL func_name( HDC hdc, INT mode ) \
97 if ((mode < min_val) || (mode > max_val)) \
99 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
102 dc = DC_LockDc ( hdc ); \
105 SetLastWin32Error(ERROR_INVALID_HANDLE); \
108 prevMode = dc->dc_field; \
109 dc->dc_field = mode; \
110 DC_UnlockDc ( hdc ); \
115 // --------------------------------------------------------- File Statics
117 // ----------------------------------------------------- Public Functions
120 NtGdiCancelDC(HDC hDC
)
127 NtGdiCreateCompatableDC(HDC hDC
)
131 HDC hNewDC
, DisplayDC
;
133 UNICODE_STRING DriverName
;
138 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
139 DisplayDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
);
140 if (NULL
== DisplayDC
)
147 /* Allocate a new DC based on the original DC's device */
148 OrigDC
= DC_LockDc(hDC
);
151 if (NULL
!= DisplayDC
)
153 NtGdiDeleteDC(DisplayDC
);
157 hNewDC
= DC_AllocDC(&OrigDC
->DriverName
);
162 if (NULL
!= DisplayDC
)
164 NtGdiDeleteDC(DisplayDC
);
168 NewDC
= DC_LockDc( hNewDC
);
170 /* Copy information from original DC to new DC */
171 NewDC
->hSelf
= hNewDC
;
173 NewDC
->PDev
= OrigDC
->PDev
;
174 NewDC
->DMW
= OrigDC
->DMW
;
175 memcpy(NewDC
->FillPatternSurfaces
,
176 OrigDC
->FillPatternSurfaces
,
177 sizeof OrigDC
->FillPatternSurfaces
);
178 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
179 NewDC
->DevInfo
= OrigDC
->DevInfo
;
180 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
182 /* DriverName is copied in the AllocDC routine */
183 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
184 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
185 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
186 NewDC
->wndExtX
= OrigDC
->wndExtX
;
187 NewDC
->wndExtY
= OrigDC
->wndExtY
;
188 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
189 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
190 NewDC
->vportExtX
= OrigDC
->vportExtX
;
191 NewDC
->vportExtY
= OrigDC
->vportExtY
;
193 /* Create default bitmap */
194 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
197 DC_UnlockDc( hNewDC
);
199 if (NULL
!= DisplayDC
)
201 NtGdiDeleteDC(DisplayDC
);
205 NewDC
->w
.flags
= DC_MEMORY
;
206 NewDC
->w
.hBitmap
= hBitmap
;
207 NewDC
->w
.hFirstBitmap
= hBitmap
;
208 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
210 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
211 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
212 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
213 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
214 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
216 if (NULL
!= DisplayDC
)
218 NtGdiDeleteDC(DisplayDC
);
222 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
223 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
224 NtGdiDeleteObject(hVisRgn
);
232 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
234 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
235 WCHAR DeviceNameBuffer
[20];
238 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
239 RtlInitUnicodeString(RegistryPath
, NULL
);
240 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
241 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
242 QueryTable
[0].Name
= DeviceNameBuffer
;
243 QueryTable
[0].EntryContext
= RegistryPath
;
245 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
250 if (! NT_SUCCESS(Status
))
252 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
256 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
262 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
264 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
265 UNICODE_STRING RegistryPath
;
268 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
270 DPRINT("GetRegistryPath failed\n");
274 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
275 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
276 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
277 QueryTable
[0].EntryContext
= DriverFileNames
;
279 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
284 RtlFreeUnicodeString(&RegistryPath
);
285 if (! NT_SUCCESS(Status
))
287 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
291 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
296 static NTSTATUS STDCALL
297 DevModeCallback(IN PWSTR ValueName
,
300 IN ULONG ValueLength
,
302 IN PVOID EntryContext
)
304 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
306 DPRINT("Found registry value for name %S: type %d, length %d\n",
307 ValueName
, ValueType
, ValueLength
);
309 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
311 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
313 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
315 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
317 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
319 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
321 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
323 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
325 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
327 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
329 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
331 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
333 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
335 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
337 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
341 return STATUS_SUCCESS
;
345 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
347 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
348 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
349 static WCHAR ControlSet
[] = L
"CONTROLSET";
350 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
351 UNICODE_STRING RegistryPath
;
353 PWCHAR AfterControlSet
;
355 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
358 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
360 DPRINT("GetRegistryPath failed\n");
364 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
365 wcslen(RegistryMachineSystem
)));
368 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
369 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
371 AfterControlSet
+= wcslen(CurrentControlSet
);
373 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
375 AfterControlSet
+= wcslen(ControlSet
);
376 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
380 Valid
= (L
'\\' == *AfterControlSet
);
391 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
392 (wcslen(RegistryPath
.Buffer
) +
393 wcslen(Insert
) + 1) * sizeof(WCHAR
),
395 if (NULL
!= ProfilePath
)
397 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
398 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
399 wcscat(ProfilePath
, AfterControlSet
);
401 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
402 QueryTable
[0].QueryRoutine
= DevModeCallback
;
403 QueryTable
[0].Flags
= 0;
404 QueryTable
[0].Name
= NULL
;
405 QueryTable
[0].EntryContext
= NULL
;
406 QueryTable
[0].DefaultType
= REG_NONE
;
407 QueryTable
[0].DefaultData
= NULL
;
408 QueryTable
[0].DefaultLength
= 0;
410 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
415 if (! NT_SUCCESS(Status
))
417 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
418 ProfilePath
, Status
);
423 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
424 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
425 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
426 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
427 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
429 DPRINT("Not all required devmode members are set\n");
434 ExFreePool(ProfilePath
);
443 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
446 RtlFreeUnicodeString(&RegistryPath
);
450 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
457 IntCreatePrimarySurface()
459 PGD_ENABLEDRIVER GDEnableDriver
;
463 UNICODE_STRING DriverFileNames
;
470 for (DisplayNumber
= 0; ; DisplayNumber
++)
472 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
474 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
476 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
478 /* Open the miniport driver */
479 if (PrimarySurface
.VideoFileObject
== NULL
)
481 DPRINT1("FindMPDriver failed\n");
485 /* Retrieve DDI driver names from registry */
486 RtlInitUnicodeString(&DriverFileNames
, NULL
);
487 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
489 DPRINT1("FindDriverFileNames failed\n");
495 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
496 * scan all of them until a good one found.
498 CurrentName
= DriverFileNames
.Buffer
;
501 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
503 /* Get the DDI driver's entry point */
504 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
505 if (NULL
== GDEnableDriver
)
507 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
511 /* Call DDI driver's EnableDriver function */
512 RtlZeroMemory(&DED
, sizeof(DED
));
514 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
516 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
526 /* Skip to the next name but never get past the Unicode string */
527 while (L
'\0' != *CurrentName
&&
528 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
532 if (CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
539 RtlFreeUnicodeString(&DriverFileNames
);
543 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
544 DPRINT1("No suitable DDI driver found\n");
549 DPRINT("Display driver %S loaded\n", CurrentName
);
551 DPRINT("Building DDI Functions\n");
553 /* Construct DDI driver function dispatch table */
554 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
556 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
557 DPRINT1("BuildDDIFunctions failed\n");
561 /* Allocate a phyical device handle from the driver */
562 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
563 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
565 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
569 PrimarySurface
.FillPatterns
,
570 sizeof(PrimarySurface
.GDIInfo
),
571 (ULONG
*) &PrimarySurface
.GDIInfo
,
572 sizeof(PrimarySurface
.DevInfo
),
573 &PrimarySurface
.DevInfo
,
576 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
577 DoDefault
= (NULL
== PrimarySurface
.PDev
);
580 DPRINT1("DrvEnablePDev with registry parameters failed\n");
590 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
591 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
592 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
596 PrimarySurface
.FillPatterns
,
597 sizeof(PrimarySurface
.GDIInfo
),
598 (ULONG
*) &PrimarySurface
.GDIInfo
,
599 sizeof(PrimarySurface
.DevInfo
),
600 &PrimarySurface
.DevInfo
,
603 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
605 if (NULL
== PrimarySurface
.PDev
)
607 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
608 DPRINT1("DrvEnablePDEV with default parameters failed\n");
609 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
615 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
617 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
618 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
620 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
622 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
623 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
626 PrimarySurface
.Pointer
.Exclude
.right
= -1;
628 DPRINT("calling completePDev\n");
630 /* Complete initialization of the physical device */
631 PrimarySurface
.DriverFunctions
.CompletePDEV(
633 (HDEV
)&PrimarySurface
);
635 DPRINT("calling DRIVER_ReferenceDriver\n");
637 DRIVER_ReferenceDriver(L
"DISPLAY");
639 DPRINT("calling EnableSurface\n");
641 /* Enable the drawing surface */
642 PrimarySurface
.Handle
=
643 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
644 if (NULL
== PrimarySurface
.Handle
)
646 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
647 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
648 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
649 DPRINT1("DrvEnableSurface failed\n");
655 IntAttachMonitor(&PrimarySurface
, DisplayNumber
);
657 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
658 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
659 SurfSize
= SurfObj
->sizlBitmap
;
660 SurfSize
= SurfObj
->sizlBitmap
;
661 SurfaceRect
.left
= SurfaceRect
.top
= 0;
662 SurfaceRect
.right
= SurfObj
->sizlBitmap
.cx
;
663 SurfaceRect
.bottom
= SurfObj
->sizlBitmap
.cy
;
664 /* FIXME - why does EngEraseSurface() sometimes crash?
665 EngEraseSurface(SurfObj, &SurfaceRect, 0); */
666 EngUnlockSurface(SurfObj
);
667 IntShowDesktop(IntGetActiveDesktop(), SurfSize
.cx
, SurfSize
.cy
);
675 IntDestroyPrimarySurface()
677 DRIVER_UnreferenceDriver(L
"DISPLAY");
680 IntDetachMonitor(&PrimarySurface
);
683 * FIXME: Hide a mouse pointer there. Also because we have to prevent
684 * memory leaks with the Eng* mouse routines.
687 DPRINT("Reseting display\n" );
688 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
689 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
690 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
694 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
698 IntGdiCreateDC(PUNICODE_STRING Driver
,
699 PUNICODE_STRING Device
,
700 PUNICODE_STRING Output
,
701 CONST PDEVMODEW InitData
)
708 UNICODE_STRING StdDriver
;
710 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
712 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
714 if (! IntGraphicsCheck(TRUE
))
716 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
721 /* Check for existing DC object */
722 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
725 return NtGdiCreateCompatableDC(hDC
);
728 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
730 DPRINT("NAME: %S\n", Driver
->Buffer
); // FIXME: Should not crash if NULL
733 /* Allocate a DC object */
734 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
739 NewDC
= DC_LockDc( hNewDC
);
740 /* FIXME - NewDC can be NULL!!! Don't assert here! */
743 NewDC
->DMW
= PrimarySurface
.DMW
;
744 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
745 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
746 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
747 sizeof(NewDC
->FillPatternSurfaces
));
748 NewDC
->PDev
= PrimarySurface
.PDev
;
749 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
750 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
751 NewDC
->w
.hBitmap
= PrimarySurface
.Handle
;
753 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
754 NewDC
->DMW
.dmFields
= 0x000fc000;
756 /* FIXME: get mode selection information from somewhere */
758 NewDC
->DMW
.dmLogPixels
= 96;
759 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
760 NewDC
->DMW
.dmBitsPerPel
= BitsPerFormat(SurfObj
->iBitmapFormat
);
761 NewDC
->DMW
.dmPelsWidth
= SurfObj
->sizlBitmap
.cx
;
762 NewDC
->DMW
.dmPelsHeight
= SurfObj
->sizlBitmap
.cy
;
763 NewDC
->DMW
.dmDisplayFlags
= 0;
764 NewDC
->DMW
.dmDisplayFrequency
= 0;
766 NewDC
->w
.bitsPerPixel
= NewDC
->DMW
.dmBitsPerPel
; // FIXME: set this here??
768 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
770 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
772 DC_UnlockDc( hNewDC
);
774 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfObj
->sizlBitmap
.cx
,
775 SurfObj
->sizlBitmap
.cy
);
776 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
777 NtGdiDeleteObject(hVisRgn
);
779 /* Initialize the DC state */
781 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
782 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
783 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
784 NtGdiSetBkMode(hNewDC
, OPAQUE
);
786 EngUnlockSurface(SurfObj
);
792 NtGdiCreateDC(PUNICODE_STRING Driver
,
793 PUNICODE_STRING Device
,
794 PUNICODE_STRING Output
,
795 CONST PDEVMODEW InitData
)
797 UNICODE_STRING SafeDriver
, SafeDevice
;
798 DEVMODEW SafeInitData
;
804 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
805 if(!NT_SUCCESS(Status
))
807 SetLastNtError(Status
);
810 /* FIXME - InitData can have some more bytes! */
815 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
816 if(!NT_SUCCESS(Status
))
818 SetLastNtError(Status
);
825 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
826 if(!NT_SUCCESS(Status
))
828 RtlFreeUnicodeString(&SafeDriver
);
829 SetLastNtError(Status
);
834 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
);
840 NtGdiCreateIC(PUNICODE_STRING Driver
,
841 PUNICODE_STRING Device
,
842 PUNICODE_STRING Output
,
843 CONST PDEVMODEW DevMode
)
845 /* FIXME: this should probably do something else... */
846 return NtGdiCreateDC(Driver
, Device
, Output
, DevMode
);
850 NtGdiDeleteDC(HDC DCHandle
)
854 DCToDelete
= DC_LockDc(DCHandle
);
855 if (DCToDelete
== NULL
)
860 /* First delete all saved DCs */
861 while (DCToDelete
->saveLevel
)
866 savedHDC
= DC_GetNextDC (DCToDelete
);
867 savedDC
= DC_LockDc (savedHDC
);
872 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
873 DCToDelete
->saveLevel
--;
874 DC_UnlockDc( savedHDC
);
875 NtGdiDeleteDC (savedHDC
);
878 /* Free GDI resources allocated to this DC */
879 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
882 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
883 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
884 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
885 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
886 if (DCToDelete
->w
.flags
& DC_MEMORY
)
888 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
890 if (DCToDelete
->XlateBrush
!= NULL
)
891 EngDeleteXlate(DCToDelete
->XlateBrush
);
892 if (DCToDelete
->XlatePen
!= NULL
)
893 EngDeleteXlate(DCToDelete
->XlatePen
);
895 if (DCToDelete
->w
.hClipRgn
)
897 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
899 if (DCToDelete
->w
.hVisRgn
)
901 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
903 if (NULL
!= DCToDelete
->CombinedClip
)
905 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
907 if (DCToDelete
->w
.hGCClipRgn
)
909 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
912 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
914 DC_UnlockDc( DCHandle
);
915 DC_FreeDC ( DCHandle
);
921 NtGdiDrawEscape(HDC hDC
,
931 NtGdiEnumObjects(HDC hDC
,
933 GOBJENUMPROC ObjectFunc
,
940 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
941 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
942 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
943 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
946 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
951 if(!(dc
= DC_LockDc(hDC
)))
953 SetLastWin32Error(ERROR_INVALID_HANDLE
);
960 SelObject
= dc
->w
.hPen
;
963 SelObject
= dc
->w
.hBrush
;
966 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
970 SelObject
= dc
->w
.hFont
;
973 SelObject
= dc
->w
.hBitmap
;
976 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
981 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
989 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
992 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
994 Point
->x
= dc
->w
.DCOrgX
;
995 Point
->y
= dc
->w
.DCOrgY
;
1001 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1010 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1014 dc
= DC_LockDc(hDC
);
1017 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1021 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1023 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
1024 if(!NT_SUCCESS(Status
))
1026 SetLastNtError(Status
);
1036 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1042 if (!(dc
= DC_LockDc(hDC
)))
1044 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1048 oldColor
= dc
->w
.backgroundColor
;
1049 dc
->w
.backgroundColor
= color
;
1050 hBrush
= dc
->w
.hBrush
;
1051 DC_UnlockDc ( hDC
);
1052 NtGdiSelectObject(hDC
, hBrush
);
1057 NtGdiGetDCState(HDC hDC
)
1062 dc
= DC_LockDc(hDC
);
1065 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1069 hnewdc
= DC_AllocDC(NULL
);
1075 newdc
= DC_LockDc( hnewdc
);
1076 /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
1079 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1080 newdc
->w
.hPen
= dc
->w
.hPen
;
1081 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1082 newdc
->w
.hFont
= dc
->w
.hFont
;
1083 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1084 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1086 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1088 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1089 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1090 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1091 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1092 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1093 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1094 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1095 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1096 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1097 newdc
->w
.textColor
= dc
->w
.textColor
;
1098 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1099 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1100 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1101 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1102 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1103 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1104 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1105 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1106 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1107 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1109 /* Apparently, the DC origin is not changed by [GS]etDCState */
1110 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1111 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1113 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1114 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1115 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1116 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1117 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1118 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1119 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1120 newdc
->wndOrgX
= dc
->wndOrgX
;
1121 newdc
->wndOrgY
= dc
->wndOrgY
;
1122 newdc
->wndExtX
= dc
->wndExtX
;
1123 newdc
->wndExtY
= dc
->wndExtY
;
1124 newdc
->vportOrgX
= dc
->vportOrgX
;
1125 newdc
->vportOrgY
= dc
->vportOrgY
;
1126 newdc
->vportExtX
= dc
->vportExtX
;
1127 newdc
->vportExtY
= dc
->vportExtY
;
1129 newdc
->hSelf
= hnewdc
;
1130 newdc
->saveLevel
= 0;
1133 PATH_InitGdiPath( &newdc
->w
.path
);
1136 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1138 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1141 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1142 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1144 DC_UnlockDc( hnewdc
);
1152 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1156 dc
= DC_LockDc ( hDC
);
1159 dcs
= DC_LockDc ( hDCSave
);
1162 if ( dcs
->w
.flags
& DC_SAVED
)
1164 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1166 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1169 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1172 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1173 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1174 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1175 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1176 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1177 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1178 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1179 dc
->w
.textColor
= dcs
->w
.textColor
;
1180 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1181 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1182 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1183 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1184 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1185 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1186 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1187 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1188 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1189 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1191 /* Apparently, the DC origin is not changed by [GS]etDCState */
1192 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1193 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1195 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1196 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1197 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1199 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1200 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1201 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1202 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1204 dc
->wndOrgX
= dcs
->wndOrgX
;
1205 dc
->wndOrgY
= dcs
->wndOrgY
;
1206 dc
->wndExtX
= dcs
->wndExtX
;
1207 dc
->wndExtY
= dcs
->wndExtY
;
1208 dc
->vportOrgX
= dcs
->vportOrgX
;
1209 dc
->vportOrgY
= dcs
->vportOrgY
;
1210 dc
->vportExtX
= dcs
->vportExtX
;
1211 dc
->vportExtY
= dcs
->vportExtY
;
1213 if (!(dc
->w
.flags
& DC_MEMORY
))
1215 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1219 if (dcs
->w
.hClipRgn
)
1221 if (!dc
->w
.hClipRgn
)
1223 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1225 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1231 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1238 res
= CLIPPING_UpdateGCRegion( dc
);
1239 ASSERT ( res
!= ERROR
);
1241 DC_UnlockDc ( hDC
);
1243 DC_UnlockDc ( hDC
);
1244 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1247 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1248 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1249 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1250 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1251 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1252 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1254 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1257 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1262 DC_UnlockDc ( hDCSave
);
1264 DC_UnlockDc ( hDC
);
1265 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1269 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1273 NtGdiGetDeviceCaps(HDC hDC
,
1280 dc
= DC_LockDc(hDC
);
1283 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1287 /* Retrieve capability */
1291 ret
= dc
->GDIInfo
->ulVersion
;
1295 ret
= dc
->GDIInfo
->ulTechnology
;
1299 ret
= dc
->GDIInfo
->ulHorzSize
;
1303 ret
= dc
->GDIInfo
->ulVertSize
;
1307 ret
= dc
->GDIInfo
->ulHorzRes
;
1311 ret
= dc
->GDIInfo
->ulVertRes
;
1315 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1319 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1323 ret
= dc
->GDIInfo
->cBitsPixel
;
1327 ret
= dc
->GDIInfo
->cPlanes
;
1331 UNIMPLEMENTED
; /* FIXME */
1335 UNIMPLEMENTED
; /* FIXME */
1339 UNIMPLEMENTED
; /* FIXME */
1343 ret
= dc
->GDIInfo
->ulNumColors
;
1347 ret
= dc
->GDIInfo
->ulAspectX
;
1351 ret
= dc
->GDIInfo
->ulAspectY
;
1355 ret
= dc
->GDIInfo
->ulAspectXY
;
1359 UNIMPLEMENTED
; /* FIXME */
1363 UNIMPLEMENTED
; /* FIXME */
1367 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1375 UNIMPLEMENTED
; /* FIXME */
1379 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1389 case PHYSICALHEIGHT
:
1390 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1400 case PHYSICALOFFSETX
:
1401 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1411 case PHYSICALOFFSETY
:
1412 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1423 UNIMPLEMENTED
; /* FIXME */
1426 case SCALINGFACTORX
:
1427 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1437 case SCALINGFACTORY
:
1438 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1449 ret
= dc
->GDIInfo
->flRaster
;
1453 UNIMPLEMENTED
; /* FIXME */
1457 UNIMPLEMENTED
; /* FIXME */
1461 UNIMPLEMENTED
; /* FIXME */
1465 ret
= dc
->GDIInfo
->flTextCaps
;
1473 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1479 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1480 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1483 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1489 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1490 if (NULL
== GdiObject
)
1492 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1496 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1500 case GDI_OBJECT_TYPE_PEN
:
1501 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1503 case GDI_OBJECT_TYPE_BRUSH
:
1504 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1507 case GDI_OBJECT_TYPE_BITMAP
:
1508 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1510 case GDI_OBJECT_TYPE_FONT
:
1511 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1513 // Fix the LOGFONT structure for the stock fonts
1514 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1516 FixStockFontSizeW(Handle
, Count
, Buffer
);
1521 case GDI_OBJECT_TYPE_PALETTE
:
1522 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1526 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1530 GDIOBJ_UnlockObj(Handle
);
1536 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1547 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1550 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1554 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1556 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1557 ExFreePool(SafeBuf
);
1558 if(!NT_SUCCESS(Status
))
1560 SetLastNtError(Status
);
1568 NtGdiGetObjectType(HANDLE handle
)
1574 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1577 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1581 objectType
= GDIOBJ_GetObjectType(handle
);
1584 case GDI_OBJECT_TYPE_PEN
:
1587 case GDI_OBJECT_TYPE_BRUSH
:
1590 case GDI_OBJECT_TYPE_BITMAP
:
1591 result
= OBJ_BITMAP
;
1593 case GDI_OBJECT_TYPE_FONT
:
1596 case GDI_OBJECT_TYPE_PALETTE
:
1599 case GDI_OBJECT_TYPE_REGION
:
1600 result
= OBJ_REGION
;
1602 case GDI_OBJECT_TYPE_DC
:
1605 case GDI_OBJECT_TYPE_METADC
:
1606 result
= OBJ_METADC
;
1608 case GDI_OBJECT_TYPE_METAFILE
:
1609 result
= OBJ_METAFILE
;
1611 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1612 result
= OBJ_ENHMETAFILE
;
1614 case GDI_OBJECT_TYPE_ENHMETADC
:
1615 result
= OBJ_ENHMETADC
;
1617 case GDI_OBJECT_TYPE_EXTPEN
:
1618 result
= OBJ_EXTPEN
;
1620 case GDI_OBJECT_TYPE_MEMDC
:
1625 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1629 GDIOBJ_UnlockObj(handle
);
1633 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1634 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1635 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1636 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1637 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1638 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1639 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1640 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1641 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1644 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1651 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1656 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1658 dc
= DC_LockDc(hDC
);
1661 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1665 if (SaveLevel
== -1)
1666 SaveLevel
= dc
->saveLevel
;
1668 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1675 while (dc
->saveLevel
>= SaveLevel
)
1677 HDC hdcs
= DC_GetNextDC (dc
);
1679 dcs
= DC_LockDc (hdcs
);
1685 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1686 if (--dc
->saveLevel
< SaveLevel
)
1689 DC_UnlockDc( hdcs
);
1690 NtGdiSetDCState(hDC
, hdcs
);
1692 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1694 /* FIXME: This might not be quite right, since we're
1695 * returning FALSE but still destroying the saved DC state */
1699 dc
= DC_LockDc(hDC
);
1707 DC_UnlockDc( hdcs
);
1709 NtGdiDeleteDC (hdcs
);
1716 NtGdiSaveDC(HDC hDC
)
1722 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1724 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1729 dcs
= DC_LockDc (hdcs
);
1732 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1735 dc
= DC_LockDc (hDC
);
1739 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1744 /* Copy path. The reason why path saving / restoring is in SaveDC/
1745 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1746 * functions are only in Win16 (which doesn't have paths) and that
1747 * SetDCState doesn't allow us to signal an error (which can happen
1748 * when copying paths).
1750 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1752 NtGdiDeleteDC (hdcs
);
1757 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1758 DC_SetNextDC (dc
, hdcs
);
1759 ret
= ++dc
->saveLevel
;
1760 DC_UnlockDc( hdcs
);
1768 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1770 HGDIOBJ objOrg
= NULL
; // default to failure
1777 ULONG NumColors
= 0;
1781 if(!hDC
|| !hGDIObj
) return NULL
;
1783 dc
= DC_LockDc(hDC
);
1786 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1790 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1794 case GDI_OBJECT_TYPE_PEN
:
1795 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1798 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1802 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
1803 PENOBJ_UnlockPen(hGDIObj
);
1806 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1810 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1811 dc
->w
.hPen
= hGDIObj
;
1812 if (dc
->XlatePen
!= NULL
)
1813 EngDeleteXlate(dc
->XlatePen
);
1814 dc
->XlatePen
= XlateObj
;
1817 case GDI_OBJECT_TYPE_BRUSH
:
1818 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
1821 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1825 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
1826 BRUSHOBJ_UnlockBrush(hGDIObj
);
1829 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1833 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1834 dc
->w
.hBrush
= hGDIObj
;
1835 if (dc
->XlateBrush
!= NULL
)
1836 EngDeleteXlate(dc
->XlateBrush
);
1837 dc
->XlateBrush
= XlateObj
;
1840 case GDI_OBJECT_TYPE_FONT
:
1841 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
1843 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1844 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1848 case GDI_OBJECT_TYPE_BITMAP
:
1849 // must be memory dc to select bitmap
1850 if (!(dc
->w
.flags
& DC_MEMORY
))
1855 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1858 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1862 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1864 /* Release the old bitmap, lock the new one and convert it to a SURF */
1865 dc
->w
.hBitmap
= hGDIObj
;
1867 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1870 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1872 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1874 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1875 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1876 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1877 dc
->w
.hPalette
= PALETTE_AllocPaletteIndexedRGB(NumColors
, pb
->ColorMap
);
1881 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1882 pb
->dib
->dsBitfields
[0],
1883 pb
->dib
->dsBitfields
[1],
1884 pb
->dib
->dsBitfields
[2]);
1889 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
1890 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1893 /* Reselect brush and pen to regenerate the XLATEOBJs. */
1894 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
1895 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
1897 DC_UnlockDc ( hDC
);
1898 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
1899 BITMAPOBJ_UnlockBitmap( hGDIObj
);
1900 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1901 NtGdiDeleteObject ( hVisRgn
);
1905 case GDI_OBJECT_TYPE_REGION
:
1908 * The return value is one of the following values:
1913 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
1923 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1926 DC
*dc
= DC_LockDc(hDC
);
1930 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1934 wRet
= dc
->w
.flags
& DC_DIRTY
;
1936 /* "Undocumented Windows" info is slightly confusing.
1939 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1941 if (Flags
& DCHF_INVALIDATEVISRGN
)
1943 dc
->w
.flags
|= DC_DIRTY
;
1945 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1947 dc
->w
.flags
&= ~DC_DIRTY
;
1955 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1956 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1957 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1958 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1959 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
1961 // ---------------------------------------------------- Private Interface
1964 DC_AllocDC(PUNICODE_STRING Driver
)
1972 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
1977 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
1980 hDC
= (HDC
) GDIOBJ_AllocObj(GDI_OBJECT_TYPE_DC
);
1990 NewDC
= DC_LockDc(hDC
);
1991 /* FIXME - Handle NewDC == NULL! */
1995 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
1996 NewDC
->DriverName
.Buffer
= Buf
;
1999 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2000 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2001 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2002 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2003 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2004 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2005 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2006 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2007 NewDC
->w
.vport2WorldValid
= TRUE
;
2008 NewDC
->w
.MapMode
= MM_TEXT
;
2009 NewDC
->wndExtX
= 1.0f
;
2010 NewDC
->wndExtY
= 1.0f
;
2011 NewDC
->vportExtX
= 1.0f
;
2012 NewDC
->vportExtY
= 1.0f
;
2013 NewDC
->w
.textColor
= 0;
2014 NewDC
->w
.backgroundColor
= 0xffffff;
2016 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2017 TextIntRealizeFont(NewDC
->w
.hFont
);
2019 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2027 DC_FindOpenDC(PUNICODE_STRING Driver
)
2033 * Initialize some common fields in the Device Context structure.
2036 DC_InitDC(HDC DCHandle
)
2038 // NtGdiRealizeDefaultPalette(DCHandle);
2040 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2041 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2042 //NtGdiSelectObject(DCHandle, hFont);
2047 res = CLIPPING_UpdateGCRegion(DCToInit);
2048 ASSERT ( res != ERROR );
2054 DC_FreeDC(HDC DCToFree
)
2056 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
))
2058 DPRINT("DC_FreeDC failed\n");
2063 DC_Cleanup(PVOID ObjectBody
)
2065 PDC pDC
= (PDC
)ObjectBody
;
2066 RtlFreeUnicodeString(&pDC
->DriverName
);
2071 DC_GetNextDC (PDC pDC
)
2077 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2079 pDC
->hNext
= hNextDC
;
2083 DC_UpdateXforms(PDC dc
)
2085 XFORM xformWnd2Vport
;
2086 FLOAT scaleX
, scaleY
;
2088 /* Construct a transformation to do the window-to-viewport conversion */
2089 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2090 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2091 xformWnd2Vport
.eM11
= scaleX
;
2092 xformWnd2Vport
.eM12
= 0.0;
2093 xformWnd2Vport
.eM21
= 0.0;
2094 xformWnd2Vport
.eM22
= scaleY
;
2095 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2096 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2098 /* Combine with the world transformation */
2099 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2101 /* Create inverse of world-to-viewport transformation */
2102 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2106 DC_InvertXform(const XFORM
*xformSrc
,
2111 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2112 if (determinant
> -1e-12 && determinant
< 1e-12)
2117 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2118 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2119 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2120 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2121 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2122 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2128 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2132 GDIOBJ_SetOwnership(hDC
, Owner
);
2133 DC
= DC_LockDc(hDC
);
2136 if (NULL
!= DC
->w
.hClipRgn
)
2138 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2140 if (NULL
!= DC
->w
.hVisRgn
)
2142 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2144 if (NULL
!= DC
->w
.hGCClipRgn
)
2146 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2153 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2155 if (PrimarySurface
.Handle
== NULL
)
2159 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2163 * Returns the color of the brush or pen that is currently selected into the DC.
2164 * This function is called from GetDCBrushColor() and GetDCPenColor()
2167 IntGetDCColor(HDC hDC
, ULONG Object
)
2170 * The previous implementation was completly incorrect. It modified the
2171 * brush that was currently selected into the device context, but in fact
2172 * the DC pen/brush color should be stored directly in the device context
2173 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2174 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2175 * into the device context and BRUSHOBJ for drawing is composed (belongs
2176 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2177 * the implementation should be moved to user mode GDI32.dll when UM
2178 * mapped GDI objects will be implemented.
2181 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2182 return 0xFFFFFF; /* The default DC color. */
2186 * Changes the color of the brush or pen that is currently selected into the DC.
2187 * This function is called from SetDCBrushColor() and SetDCPenColor()
2190 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2192 /* See the comment in IntGetDCColor. */
2194 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2198 #define SIZEOF_DEVMODEW_300 188
2199 #define SIZEOF_DEVMODEW_400 212
2200 #define SIZEOF_DEVMODEW_500 220
2202 /*! \brief Enumerate possible display settings for the given display...
2204 * \todo Make thread safe!?
2205 * \todo Don't ignore lpszDeviceName
2206 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2209 IntEnumDisplaySettings(
2210 PUNICODE_STRING lpszDeviceName
,
2212 LPDEVMODEW lpDevMode
,
2215 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2216 static DWORD SizeOfCachedDevModes
= 0;
2217 LPDEVMODEW CachedMode
= NULL
;
2220 ULONG DisplayNumber
= 0; /* only default display supported */
2222 if (lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2223 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2224 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2226 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2230 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2232 CachedMode
= &PrimarySurface
.DMW
;
2233 assert(CachedMode
->dmSize
> 0);
2235 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2237 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2238 DevMode
.dmSize
= sizeof (DevMode
);
2239 DevMode
.dmDriverExtra
= 0;
2240 if (SetupDevMode(&DevMode
, DisplayNumber
))
2241 CachedMode
= &DevMode
;
2244 SetLastWin32Error(0); /* FIXME: use error code */
2247 /* FIXME: Maybe look for the matching devmode supplied by the
2248 * driver so we can provide driver private/extra data?
2253 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2255 BOOL PrimarySurfaceCreated
= FALSE
;
2256 UNICODE_STRING DriverFileNames
;
2258 DRVENABLEDATA DrvEnableData
;
2260 /* Retrieve DDI driver names from registry */
2261 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2262 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2264 DPRINT1("FindDriverFileNames failed\n");
2268 if (!HalQueryDisplayOwnership())
2270 IntCreatePrimarySurface();
2271 PrimarySurfaceCreated
= TRUE
;
2275 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2276 * scan all of them until a good one found.
2278 CurrentName
= DriverFileNames
.Buffer
;
2279 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2280 CurrentName
+= wcslen(CurrentName
) + 1)
2283 PGD_ENABLEDRIVER GDEnableDriver
;
2285 /* Get the DDI driver's entry point */
2286 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2287 if (NULL
== GDEnableDriver
)
2289 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2293 /* Call DDI driver's EnableDriver function */
2294 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2296 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2298 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2302 CachedDevModesEnd
= CachedDevModes
;
2304 /* find DrvGetModes function */
2305 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2307 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2308 PGD_GETMODES GetModes
;
2309 INT SizeNeeded
, SizeUsed
;
2311 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2314 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2316 /* make sure we have enough memory to hold the modes */
2317 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2318 if (SizeNeeded
<= 0)
2320 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2324 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2325 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2329 SizeOfCachedDevModes
+= SizeNeeded
;
2330 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2331 if (NewBuffer
== NULL
)
2334 ExFreePool(CachedDevModes
);
2335 SizeOfCachedDevModes
= 0;
2336 CachedDevModes
= NULL
;
2337 CachedDevModesEnd
= NULL
;
2338 if (PrimarySurfaceCreated
)
2340 IntDestroyPrimarySurface();
2342 SetLastWin32Error(STATUS_NO_MEMORY
);
2345 if (CachedDevModes
!= NULL
)
2347 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2348 ExFreePool(CachedDevModes
);
2350 CachedDevModes
= NewBuffer
;
2351 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2355 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2356 SizeOfCachedDevModes
- SizeUsed
,
2358 if (SizeNeeded
<= 0)
2360 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2364 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2370 if (PrimarySurfaceCreated
)
2372 IntDestroyPrimarySurface();
2375 RtlFreeUnicodeString(&DriverFileNames
);
2378 /* return cached info */
2379 CachedMode
= CachedDevModes
;
2380 if (CachedMode
>= CachedDevModesEnd
)
2382 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2385 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2387 assert(CachedMode
->dmSize
> 0);
2388 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2390 if (CachedMode
>= CachedDevModesEnd
)
2392 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2397 assert(CachedMode
!= NULL
);
2399 Size
= OldSize
= lpDevMode
->dmSize
;
2400 if (Size
> CachedMode
->dmSize
)
2401 Size
= CachedMode
->dmSize
;
2402 RtlCopyMemory(lpDevMode
, CachedMode
, Size
);
2403 RtlZeroMemory((PCHAR
)lpDevMode
+ Size
, OldSize
- Size
);
2404 lpDevMode
->dmSize
= OldSize
;
2406 Size
= OldSize
= lpDevMode
->dmDriverExtra
;
2407 if (Size
> CachedMode
->dmDriverExtra
)
2408 Size
= CachedMode
->dmDriverExtra
;
2409 RtlCopyMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
,
2410 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2411 RtlZeroMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
+ Size
, OldSize
- Size
);
2412 lpDevMode
->dmDriverExtra
= OldSize
;