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.148 2004/12/07 19:53:44 royce 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
;
469 for (DisplayNumber
= 0; ; DisplayNumber
++)
471 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
473 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
475 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
477 /* Open the miniport driver */
478 if (PrimarySurface
.VideoFileObject
== NULL
)
480 DPRINT1("FindMPDriver failed\n");
484 /* Retrieve DDI driver names from registry */
485 RtlInitUnicodeString(&DriverFileNames
, NULL
);
486 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
488 DPRINT1("FindDriverFileNames failed\n");
494 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
495 * scan all of them until a good one found.
497 CurrentName
= DriverFileNames
.Buffer
;
500 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
502 /* Get the DDI driver's entry point */
503 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
504 if (NULL
== GDEnableDriver
)
506 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
510 /* Call DDI driver's EnableDriver function */
511 RtlZeroMemory(&DED
, sizeof(DED
));
513 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
515 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
525 /* Skip to the next name but never get past the Unicode string */
526 while (L
'\0' != *CurrentName
&&
527 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
531 if (CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
538 RtlFreeUnicodeString(&DriverFileNames
);
542 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
543 DPRINT1("No suitable DDI driver found\n");
548 DPRINT("Display driver %S loaded\n", CurrentName
);
550 DPRINT("Building DDI Functions\n");
552 /* Construct DDI driver function dispatch table */
553 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
555 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
556 DPRINT1("BuildDDIFunctions failed\n");
560 /* Allocate a phyical device handle from the driver */
561 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
562 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
564 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
568 PrimarySurface
.FillPatterns
,
569 sizeof(PrimarySurface
.GDIInfo
),
570 (ULONG
*) &PrimarySurface
.GDIInfo
,
571 sizeof(PrimarySurface
.DevInfo
),
572 &PrimarySurface
.DevInfo
,
575 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
576 DoDefault
= (NULL
== PrimarySurface
.PDev
);
579 DPRINT1("DrvEnablePDev with registry parameters failed\n");
589 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
590 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
591 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
595 PrimarySurface
.FillPatterns
,
596 sizeof(PrimarySurface
.GDIInfo
),
597 (ULONG
*) &PrimarySurface
.GDIInfo
,
598 sizeof(PrimarySurface
.DevInfo
),
599 &PrimarySurface
.DevInfo
,
602 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
604 if (NULL
== PrimarySurface
.PDev
)
606 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
607 DPRINT1("DrvEnablePDEV with default parameters failed\n");
608 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
614 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
616 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
617 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
619 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
621 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
622 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
625 DPRINT("calling completePDev\n");
627 /* Complete initialization of the physical device */
628 PrimarySurface
.DriverFunctions
.CompletePDEV(
630 (HDEV
)&PrimarySurface
);
632 DPRINT("calling DRIVER_ReferenceDriver\n");
634 DRIVER_ReferenceDriver(L
"DISPLAY");
636 DPRINT("calling EnableSurface\n");
638 /* Enable the drawing surface */
639 PrimarySurface
.Handle
=
640 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
641 if (NULL
== PrimarySurface
.Handle
)
643 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
644 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
645 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
646 DPRINT1("DrvEnableSurface failed\n");
652 IntAttachMonitor(&PrimarySurface
, DisplayNumber
);
654 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
655 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
656 SurfSize
= SurfObj
->sizlBitmap
;
657 EngUnlockSurface(SurfObj
);
658 IntShowDesktop(IntGetActiveDesktop(), SurfSize
.cx
, SurfSize
.cy
);
666 IntDestroyPrimarySurface()
668 DRIVER_UnreferenceDriver(L
"DISPLAY");
671 IntDetachMonitor(&PrimarySurface
);
674 * FIXME: Hide a mouse pointer there. Also because we have to prevent
675 * memory leaks with the Eng* mouse routines.
678 DPRINT("Reseting display\n" );
679 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
680 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
681 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
685 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
689 IntGdiCreateDC(PUNICODE_STRING Driver
,
690 PUNICODE_STRING Device
,
691 PUNICODE_STRING Output
,
692 CONST PDEVMODEW InitData
)
699 UNICODE_STRING StdDriver
;
701 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
703 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
705 if (! IntGraphicsCheck(TRUE
))
707 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
712 /* Check for existing DC object */
713 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
716 return NtGdiCreateCompatableDC(hDC
);
719 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
721 DPRINT("NAME: %S\n", Driver
->Buffer
); // FIXME: Should not crash if NULL
724 /* Allocate a DC object */
725 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
730 NewDC
= DC_LockDc( hNewDC
);
733 NewDC
->DMW
= PrimarySurface
.DMW
;
734 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
735 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
736 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
737 sizeof(NewDC
->FillPatternSurfaces
));
738 NewDC
->PDev
= PrimarySurface
.PDev
;
739 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
740 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
741 NewDC
->w
.hBitmap
= PrimarySurface
.Handle
;
743 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
744 NewDC
->DMW
.dmFields
= 0x000fc000;
746 /* FIXME: get mode selection information from somewhere */
748 NewDC
->DMW
.dmLogPixels
= 96;
749 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
750 NewDC
->DMW
.dmBitsPerPel
= BitsPerFormat(SurfObj
->iBitmapFormat
);
751 NewDC
->DMW
.dmPelsWidth
= SurfObj
->sizlBitmap
.cx
;
752 NewDC
->DMW
.dmPelsHeight
= SurfObj
->sizlBitmap
.cy
;
753 NewDC
->DMW
.dmDisplayFlags
= 0;
754 NewDC
->DMW
.dmDisplayFrequency
= 0;
756 NewDC
->w
.bitsPerPixel
= NewDC
->DMW
.dmBitsPerPel
; // FIXME: set this here??
758 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
760 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
762 DC_UnlockDc( hNewDC
);
764 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfObj
->sizlBitmap
.cx
,
765 SurfObj
->sizlBitmap
.cy
);
766 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
767 NtGdiDeleteObject(hVisRgn
);
769 /* Initialize the DC state */
771 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
772 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
773 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
774 NtGdiSetBkMode(hNewDC
, OPAQUE
);
776 EngUnlockSurface(SurfObj
);
782 NtGdiCreateDC(PUNICODE_STRING Driver
,
783 PUNICODE_STRING Device
,
784 PUNICODE_STRING Output
,
785 CONST PDEVMODEW InitData
)
787 UNICODE_STRING SafeDriver
, SafeDevice
;
788 DEVMODEW SafeInitData
;
794 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
795 if(!NT_SUCCESS(Status
))
797 SetLastNtError(Status
);
800 /* FIXME - InitData can have some more bytes! */
805 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
806 if(!NT_SUCCESS(Status
))
808 SetLastNtError(Status
);
815 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
816 if(!NT_SUCCESS(Status
))
818 RtlFreeUnicodeString(&SafeDriver
);
819 SetLastNtError(Status
);
824 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
);
830 NtGdiCreateIC(PUNICODE_STRING Driver
,
831 PUNICODE_STRING Device
,
832 PUNICODE_STRING Output
,
833 CONST PDEVMODEW DevMode
)
835 /* FIXME: this should probably do something else... */
836 return NtGdiCreateDC(Driver
, Device
, Output
, DevMode
);
840 NtGdiDeleteDC(HDC DCHandle
)
844 DCToDelete
= DC_LockDc(DCHandle
);
845 if (DCToDelete
== NULL
)
849 DPRINT( "Deleting DC\n" );
851 /* First delete all saved DCs */
852 while (DCToDelete
->saveLevel
)
857 savedHDC
= DC_GetNextDC (DCToDelete
);
858 savedDC
= DC_LockDc (savedHDC
);
863 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
864 DCToDelete
->saveLevel
--;
865 DC_UnlockDc( savedHDC
);
866 NtGdiDeleteDC (savedHDC
);
869 /* Free GDI resources allocated to this DC */
870 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
873 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
874 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
875 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
876 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
877 if (DCToDelete
->w
.flags
& DC_MEMORY
)
879 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
881 if (DCToDelete
->XlateBrush
!= NULL
)
882 EngDeleteXlate(DCToDelete
->XlateBrush
);
883 if (DCToDelete
->XlatePen
!= NULL
)
884 EngDeleteXlate(DCToDelete
->XlatePen
);
886 if (DCToDelete
->w
.hClipRgn
)
888 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
890 if (DCToDelete
->w
.hVisRgn
)
892 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
894 if (NULL
!= DCToDelete
->CombinedClip
)
896 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
898 if (DCToDelete
->w
.hGCClipRgn
)
900 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
903 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
905 DC_UnlockDc( DCHandle
);
906 DC_FreeDC ( DCHandle
);
912 NtGdiDrawEscape(HDC hDC
,
922 NtGdiEnumObjects(HDC hDC
,
924 GOBJENUMPROC ObjectFunc
,
931 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
932 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
933 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
934 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
937 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
942 if(!(dc
= DC_LockDc(hDC
)))
944 SetLastWin32Error(ERROR_INVALID_HANDLE
);
951 SelObject
= dc
->w
.hPen
;
954 SelObject
= dc
->w
.hBrush
;
957 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
961 SelObject
= dc
->w
.hFont
;
964 SelObject
= dc
->w
.hBitmap
;
967 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
972 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
980 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
983 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
985 Point
->x
= dc
->w
.DCOrgX
;
986 Point
->y
= dc
->w
.DCOrgY
;
992 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1001 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1005 dc
= DC_LockDc(hDC
);
1008 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1012 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1014 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
1015 if(!NT_SUCCESS(Status
))
1017 SetLastNtError(Status
);
1027 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1033 if (!(dc
= DC_LockDc(hDC
)))
1035 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1039 oldColor
= dc
->w
.backgroundColor
;
1040 dc
->w
.backgroundColor
= color
;
1041 hBrush
= dc
->w
.hBrush
;
1042 DC_UnlockDc ( hDC
);
1043 NtGdiSelectObject(hDC
, hBrush
);
1048 NtGdiGetDCState(HDC hDC
)
1053 dc
= DC_LockDc(hDC
);
1056 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1060 hnewdc
= DC_AllocDC(NULL
);
1066 newdc
= DC_LockDc( hnewdc
);
1069 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1070 newdc
->w
.hPen
= dc
->w
.hPen
;
1071 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1072 newdc
->w
.hFont
= dc
->w
.hFont
;
1073 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1074 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1076 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1078 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1079 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1080 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1081 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1082 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1083 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1084 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1085 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1086 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1087 newdc
->w
.textColor
= dc
->w
.textColor
;
1088 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1089 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1090 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1091 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1092 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1093 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1094 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1095 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1096 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1097 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1099 /* Apparently, the DC origin is not changed by [GS]etDCState */
1100 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1101 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1103 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1104 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1105 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1106 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1107 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1108 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1109 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1110 newdc
->wndOrgX
= dc
->wndOrgX
;
1111 newdc
->wndOrgY
= dc
->wndOrgY
;
1112 newdc
->wndExtX
= dc
->wndExtX
;
1113 newdc
->wndExtY
= dc
->wndExtY
;
1114 newdc
->vportOrgX
= dc
->vportOrgX
;
1115 newdc
->vportOrgY
= dc
->vportOrgY
;
1116 newdc
->vportExtX
= dc
->vportExtX
;
1117 newdc
->vportExtY
= dc
->vportExtY
;
1119 newdc
->hSelf
= hnewdc
;
1120 newdc
->saveLevel
= 0;
1123 PATH_InitGdiPath( &newdc
->w
.path
);
1126 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1128 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1131 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1132 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1134 DC_UnlockDc( hnewdc
);
1142 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1146 dc
= DC_LockDc ( hDC
);
1149 dcs
= DC_LockDc ( hDCSave
);
1152 if ( dcs
->w
.flags
& DC_SAVED
)
1154 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1156 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1159 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1162 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1163 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1164 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1165 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1166 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1167 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1168 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1169 dc
->w
.textColor
= dcs
->w
.textColor
;
1170 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1171 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1172 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1173 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1174 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1175 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1176 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1177 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1178 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1179 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1181 /* Apparently, the DC origin is not changed by [GS]etDCState */
1182 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1183 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1185 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1186 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1187 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1189 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1190 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1191 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1192 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1194 dc
->wndOrgX
= dcs
->wndOrgX
;
1195 dc
->wndOrgY
= dcs
->wndOrgY
;
1196 dc
->wndExtX
= dcs
->wndExtX
;
1197 dc
->wndExtY
= dcs
->wndExtY
;
1198 dc
->vportOrgX
= dcs
->vportOrgX
;
1199 dc
->vportOrgY
= dcs
->vportOrgY
;
1200 dc
->vportExtX
= dcs
->vportExtX
;
1201 dc
->vportExtY
= dcs
->vportExtY
;
1203 if (!(dc
->w
.flags
& DC_MEMORY
))
1205 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1209 if (dcs
->w
.hClipRgn
)
1211 if (!dc
->w
.hClipRgn
)
1213 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1215 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1221 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1228 res
= CLIPPING_UpdateGCRegion( dc
);
1229 ASSERT ( res
!= ERROR
);
1231 DC_UnlockDc ( hDC
);
1233 DC_UnlockDc ( hDC
);
1234 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1237 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1238 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1239 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1240 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1241 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1242 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1244 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1247 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1252 DC_UnlockDc ( hDCSave
);
1254 DC_UnlockDc ( hDC
);
1255 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1259 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1263 NtGdiGetDeviceCaps(HDC hDC
,
1270 dc
= DC_LockDc(hDC
);
1273 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1277 /* Retrieve capability */
1281 ret
= dc
->GDIInfo
->ulVersion
;
1285 ret
= dc
->GDIInfo
->ulTechnology
;
1289 ret
= dc
->GDIInfo
->ulHorzSize
;
1293 ret
= dc
->GDIInfo
->ulVertSize
;
1297 ret
= dc
->GDIInfo
->ulHorzRes
;
1301 ret
= dc
->GDIInfo
->ulVertRes
;
1305 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1309 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1313 ret
= dc
->GDIInfo
->cBitsPixel
;
1317 ret
= dc
->GDIInfo
->cPlanes
;
1321 UNIMPLEMENTED
; /* FIXME */
1325 UNIMPLEMENTED
; /* FIXME */
1329 UNIMPLEMENTED
; /* FIXME */
1333 ret
= dc
->GDIInfo
->ulNumColors
;
1337 ret
= dc
->GDIInfo
->ulAspectX
;
1341 ret
= dc
->GDIInfo
->ulAspectY
;
1345 ret
= dc
->GDIInfo
->ulAspectXY
;
1349 UNIMPLEMENTED
; /* FIXME */
1353 UNIMPLEMENTED
; /* FIXME */
1357 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1365 UNIMPLEMENTED
; /* FIXME */
1369 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1379 case PHYSICALHEIGHT
:
1380 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1390 case PHYSICALOFFSETX
:
1391 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1401 case PHYSICALOFFSETY
:
1402 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1413 UNIMPLEMENTED
; /* FIXME */
1416 case SCALINGFACTORX
:
1417 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1427 case SCALINGFACTORY
:
1428 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1439 ret
= dc
->GDIInfo
->flRaster
;
1443 UNIMPLEMENTED
; /* FIXME */
1447 UNIMPLEMENTED
; /* FIXME */
1451 UNIMPLEMENTED
; /* FIXME */
1455 ret
= dc
->GDIInfo
->flTextCaps
;
1463 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1469 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1470 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1473 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1475 PGDIOBJHDR GdiObject
;
1479 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1480 if (NULL
== GdiObject
)
1482 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1486 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1490 case GDI_OBJECT_TYPE_PEN
:
1491 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1493 case GDI_OBJECT_TYPE_BRUSH
:
1494 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1497 case GDI_OBJECT_TYPE_BITMAP
:
1498 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1500 case GDI_OBJECT_TYPE_FONT
:
1501 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1503 // Fix the LOGFONT structure for the stock fonts
1504 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1506 FixStockFontSizeW(Handle
, Count
, Buffer
);
1511 case GDI_OBJECT_TYPE_PALETTE
:
1512 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1516 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1520 GDIOBJ_UnlockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1526 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1537 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1540 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1544 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1546 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1547 ExFreePool(SafeBuf
);
1548 if(!NT_SUCCESS(Status
))
1550 SetLastNtError(Status
);
1558 NtGdiGetObjectType(HANDLE handle
)
1564 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1567 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1571 objectType
= GDIOBJ_GetObjectType(handle
);
1574 case GDI_OBJECT_TYPE_PEN
:
1577 case GDI_OBJECT_TYPE_BRUSH
:
1580 case GDI_OBJECT_TYPE_BITMAP
:
1581 result
= OBJ_BITMAP
;
1583 case GDI_OBJECT_TYPE_FONT
:
1586 case GDI_OBJECT_TYPE_PALETTE
:
1589 case GDI_OBJECT_TYPE_REGION
:
1590 result
= OBJ_REGION
;
1592 case GDI_OBJECT_TYPE_DC
:
1595 case GDI_OBJECT_TYPE_METADC
:
1596 result
= OBJ_METADC
;
1598 case GDI_OBJECT_TYPE_METAFILE
:
1599 result
= OBJ_METAFILE
;
1601 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1602 result
= OBJ_ENHMETAFILE
;
1604 case GDI_OBJECT_TYPE_ENHMETADC
:
1605 result
= OBJ_ENHMETADC
;
1607 case GDI_OBJECT_TYPE_EXTPEN
:
1608 result
= OBJ_EXTPEN
;
1610 case GDI_OBJECT_TYPE_MEMDC
:
1614 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1617 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1621 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1622 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1623 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1624 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1625 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1626 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1627 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1628 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1629 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1632 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1639 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1644 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1646 dc
= DC_LockDc(hDC
);
1649 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1653 if (SaveLevel
== -1)
1654 SaveLevel
= dc
->saveLevel
;
1656 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1663 while (dc
->saveLevel
>= SaveLevel
)
1665 HDC hdcs
= DC_GetNextDC (dc
);
1667 dcs
= DC_LockDc (hdcs
);
1673 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1674 if (--dc
->saveLevel
< SaveLevel
)
1677 DC_UnlockDc( hdcs
);
1678 NtGdiSetDCState(hDC
, hdcs
);
1680 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1682 /* FIXME: This might not be quite right, since we're
1683 * returning FALSE but still destroying the saved DC state */
1687 dc
= DC_LockDc(hDC
);
1695 DC_UnlockDc( hdcs
);
1697 NtGdiDeleteDC (hdcs
);
1704 NtGdiSaveDC(HDC hDC
)
1710 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1712 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1717 dcs
= DC_LockDc (hdcs
);
1720 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1723 dc
= DC_LockDc (hDC
);
1727 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1732 /* Copy path. The reason why path saving / restoring is in SaveDC/
1733 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1734 * functions are only in Win16 (which doesn't have paths) and that
1735 * SetDCState doesn't allow us to signal an error (which can happen
1736 * when copying paths).
1738 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1740 NtGdiDeleteDC (hdcs
);
1745 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1746 DC_SetNextDC (dc
, hdcs
);
1747 ret
= ++dc
->saveLevel
;
1748 DC_UnlockDc( hdcs
);
1756 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1758 HGDIOBJ objOrg
= NULL
; // default to failure
1765 ULONG NumColors
= 0;
1769 if(!hDC
|| !hGDIObj
) return NULL
;
1771 dc
= DC_LockDc(hDC
);
1774 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1778 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1782 case GDI_OBJECT_TYPE_PEN
:
1783 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1786 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1790 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
1791 PENOBJ_UnlockPen((HPEN
) hGDIObj
);
1794 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1798 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1799 dc
->w
.hPen
= hGDIObj
;
1800 if (dc
->XlatePen
!= NULL
)
1801 EngDeleteXlate(dc
->XlatePen
);
1802 dc
->XlatePen
= XlateObj
;
1805 case GDI_OBJECT_TYPE_BRUSH
:
1806 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
1809 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1813 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
1814 BRUSHOBJ_UnlockBrush((HPEN
) hGDIObj
);
1817 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1821 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1822 dc
->w
.hBrush
= hGDIObj
;
1823 if (dc
->XlateBrush
!= NULL
)
1824 EngDeleteXlate(dc
->XlateBrush
);
1825 dc
->XlateBrush
= XlateObj
;
1828 case GDI_OBJECT_TYPE_FONT
:
1829 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1830 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1831 TextIntRealizeFont(dc
->w
.hFont
);
1834 case GDI_OBJECT_TYPE_BITMAP
:
1835 // must be memory dc to select bitmap
1836 if (!(dc
->w
.flags
& DC_MEMORY
))
1841 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1844 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1848 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1850 /* Release the old bitmap, lock the new one and convert it to a SURF */
1851 dc
->w
.hBitmap
= hGDIObj
;
1853 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1856 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1858 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1860 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1861 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1862 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1863 dc
->w
.hPalette
= PALETTE_AllocPaletteIndexedRGB(NumColors
, pb
->ColorMap
);
1867 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1868 pb
->dib
->dsBitfields
[0],
1869 pb
->dib
->dsBitfields
[1],
1870 pb
->dib
->dsBitfields
[2]);
1875 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
1876 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1879 /* Reselect brush and pen to regenerate the XLATEOBJs. */
1880 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
1881 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
1883 DC_UnlockDc ( hDC
);
1884 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
1885 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1886 NtGdiDeleteObject ( hVisRgn
);
1887 BITMAPOBJ_UnlockBitmap(hGDIObj
);
1891 case GDI_OBJECT_TYPE_REGION
:
1894 * The return value is one of the following values:
1899 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
1909 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1912 DC
*dc
= DC_LockDc(hDC
);
1916 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1920 wRet
= dc
->w
.flags
& DC_DIRTY
;
1922 /* "Undocumented Windows" info is slightly confusing.
1925 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1927 if (Flags
& DCHF_INVALIDATEVISRGN
)
1929 dc
->w
.flags
|= DC_DIRTY
;
1931 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1933 dc
->w
.flags
&= ~DC_DIRTY
;
1941 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1942 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1943 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1944 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1945 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
1947 // ---------------------------------------------------- Private Interface
1950 DC_AllocDC(PUNICODE_STRING Driver
)
1958 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
1963 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
1966 hDC
= (HDC
) GDIOBJ_AllocObj(sizeof(DC
), GDI_OBJECT_TYPE_DC
, (GDICLEANUPPROC
) DC_InternalDeleteDC
);
1976 NewDC
= DC_LockDc(hDC
);
1980 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
1981 NewDC
->DriverName
.Buffer
= Buf
;
1984 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1985 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1986 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1987 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1988 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1989 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1990 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
1991 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
1992 NewDC
->w
.vport2WorldValid
= TRUE
;
1993 NewDC
->w
.MapMode
= MM_TEXT
;
1994 NewDC
->wndExtX
= 1.0f
;
1995 NewDC
->wndExtY
= 1.0f
;
1996 NewDC
->vportExtX
= 1.0f
;
1997 NewDC
->vportExtY
= 1.0f
;
1998 NewDC
->w
.textColor
= 0;
1999 NewDC
->w
.backgroundColor
= 0xffffff;
2001 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2002 TextIntRealizeFont(NewDC
->w
.hFont
);
2004 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2012 DC_FindOpenDC(PUNICODE_STRING Driver
)
2018 * Initialize some common fields in the Device Context structure.
2021 DC_InitDC(HDC DCHandle
)
2023 // NtGdiRealizeDefaultPalette(DCHandle);
2025 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2026 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2027 //NtGdiSelectObject(DCHandle, hFont);
2032 res = CLIPPING_UpdateGCRegion(DCToInit);
2033 ASSERT ( res != ERROR );
2039 DC_FreeDC(HDC DCToFree
)
2041 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
, GDIOBJFLAG_DEFAULT
))
2043 DPRINT("DC_FreeDC failed\n");
2048 DC_InternalDeleteDC( PDC DCToDelete
)
2051 RtlFreeUnicodeString(&DCToDelete
->DriverName
);
2056 DC_GetNextDC (PDC pDC
)
2062 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2064 pDC
->hNext
= hNextDC
;
2068 DC_UpdateXforms(PDC dc
)
2070 XFORM xformWnd2Vport
;
2071 FLOAT scaleX
, scaleY
;
2073 /* Construct a transformation to do the window-to-viewport conversion */
2074 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2075 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2076 xformWnd2Vport
.eM11
= scaleX
;
2077 xformWnd2Vport
.eM12
= 0.0;
2078 xformWnd2Vport
.eM21
= 0.0;
2079 xformWnd2Vport
.eM22
= scaleY
;
2080 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2081 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2083 /* Combine with the world transformation */
2084 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2086 /* Create inverse of world-to-viewport transformation */
2087 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2091 DC_InvertXform(const XFORM
*xformSrc
,
2096 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2097 if (determinant
> -1e-12 && determinant
< 1e-12)
2102 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2103 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2104 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2105 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2106 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2107 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2113 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2117 GDIOBJ_SetOwnership(hDC
, Owner
);
2118 DC
= DC_LockDc(hDC
);
2121 if (NULL
!= DC
->w
.hClipRgn
)
2123 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2125 if (NULL
!= DC
->w
.hVisRgn
)
2127 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2129 if (NULL
!= DC
->w
.hGCClipRgn
)
2131 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2138 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2140 if (PrimarySurface
.Handle
== NULL
)
2144 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2148 * Returns the color of the brush or pen that is currently selected into the DC.
2149 * This function is called from GetDCBrushColor() and GetDCPenColor()
2152 IntGetDCColor(HDC hDC
, ULONG Object
)
2155 * The previous implementation was completly incorrect. It modified the
2156 * brush that was currently selected into the device context, but in fact
2157 * the DC pen/brush color should be stored directly in the device context
2158 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2159 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2160 * into the device context and BRUSHOBJ for drawing is composed (belongs
2161 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2162 * the implementation should be moved to user mode GDI32.dll when UM
2163 * mapped GDI objects will be implemented.
2166 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2167 return 0xFFFFFF; /* The default DC color. */
2171 * Changes the color of the brush or pen that is currently selected into the DC.
2172 * This function is called from SetDCBrushColor() and SetDCPenColor()
2175 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2177 /* See the comment in IntGetDCColor. */
2179 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2183 #define SIZEOF_DEVMODEW_300 188
2184 #define SIZEOF_DEVMODEW_400 212
2185 #define SIZEOF_DEVMODEW_500 220
2187 /*! \brief Enumerate possible display settings for the given display...
2189 * \todo Make thread safe!?
2190 * \todo Don't ignore lpszDeviceName
2191 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2194 IntEnumDisplaySettings(
2195 PUNICODE_STRING lpszDeviceName
,
2197 LPDEVMODEW lpDevMode
,
2200 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2201 static DWORD SizeOfCachedDevModes
= 0;
2202 LPDEVMODEW CachedMode
= NULL
;
2205 ULONG DisplayNumber
= 0; /* only default display supported */
2207 if (lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2208 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2209 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2211 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2215 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2217 CachedMode
= &PrimarySurface
.DMW
;
2218 assert(CachedMode
->dmSize
> 0);
2220 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2222 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2223 DevMode
.dmSize
= sizeof (DevMode
);
2224 DevMode
.dmDriverExtra
= 0;
2225 if (SetupDevMode(&DevMode
, DisplayNumber
))
2226 CachedMode
= &DevMode
;
2229 SetLastWin32Error(0); /* FIXME: use error code */
2232 /* FIXME: Maybe look for the matching devmode supplied by the
2233 * driver so we can provide driver private/extra data?
2238 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2240 UNICODE_STRING DriverFileNames
;
2242 DRVENABLEDATA DrvEnableData
;
2244 /* Retrieve DDI driver names from registry */
2245 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2246 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2248 DPRINT1("FindDriverFileNames failed\n");
2253 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2254 * scan all of them until a good one found.
2256 CurrentName
= DriverFileNames
.Buffer
;
2257 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2258 CurrentName
+= wcslen(CurrentName
) + 1)
2261 PGD_ENABLEDRIVER GDEnableDriver
;
2263 /* Get the DDI driver's entry point */
2264 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2265 if (NULL
== GDEnableDriver
)
2267 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2271 /* Call DDI driver's EnableDriver function */
2272 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2274 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2276 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2280 CachedDevModesEnd
= CachedDevModes
;
2282 /* find DrvGetModes function */
2283 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2285 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2286 PGD_GETMODES GetModes
;
2287 INT SizeNeeded
, SizeUsed
;
2289 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2292 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2294 /* make sure we have enough memory to hold the modes */
2295 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2296 if (SizeNeeded
<= 0)
2298 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2302 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2303 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2307 SizeOfCachedDevModes
+= SizeNeeded
;
2308 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2309 if (NewBuffer
== NULL
)
2312 ExFreePool(CachedDevModes
);
2313 SizeOfCachedDevModes
= 0;
2314 CachedDevModes
= NULL
;
2315 CachedDevModesEnd
= NULL
;
2316 SetLastWin32Error(STATUS_NO_MEMORY
);
2319 if (CachedDevModes
!= NULL
)
2321 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2322 ExFreePool(CachedDevModes
);
2324 CachedDevModes
= NewBuffer
;
2325 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2329 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2330 SizeOfCachedDevModes
- SizeUsed
,
2332 if (SizeNeeded
<= 0)
2334 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2338 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2344 RtlFreeUnicodeString(&DriverFileNames
);
2347 /* return cached info */
2348 CachedMode
= CachedDevModes
;
2349 if (CachedMode
>= CachedDevModesEnd
)
2351 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2354 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2356 assert(CachedMode
->dmSize
> 0);
2357 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2359 if (CachedMode
>= CachedDevModesEnd
)
2361 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2366 assert(CachedMode
!= NULL
);
2368 Size
= OldSize
= lpDevMode
->dmSize
;
2369 if (Size
> CachedMode
->dmSize
)
2370 Size
= CachedMode
->dmSize
;
2371 RtlCopyMemory(lpDevMode
, CachedMode
, Size
);
2372 RtlZeroMemory((PCHAR
)lpDevMode
+ Size
, OldSize
- Size
);
2373 lpDevMode
->dmSize
= OldSize
;
2375 Size
= OldSize
= lpDevMode
->dmDriverExtra
;
2376 if (Size
> CachedMode
->dmDriverExtra
)
2377 Size
= CachedMode
->dmDriverExtra
;
2378 RtlCopyMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
,
2379 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2380 RtlZeroMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
+ Size
, OldSize
- Size
);
2381 lpDevMode
->dmDriverExtra
= OldSize
;