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.152 2004/12/12 21:58:42 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
;
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 IntGdiGetDeviceCaps(PDC dc
, INT Index
)
1278 /* Retrieve capability */
1282 ret
= dc
->GDIInfo
->ulVersion
;
1286 ret
= dc
->GDIInfo
->ulTechnology
;
1290 ret
= dc
->GDIInfo
->ulHorzSize
;
1294 ret
= dc
->GDIInfo
->ulVertSize
;
1298 ret
= dc
->GDIInfo
->ulHorzRes
;
1302 ret
= dc
->GDIInfo
->ulVertRes
;
1306 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1310 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1314 ret
= dc
->GDIInfo
->cBitsPixel
;
1318 ret
= dc
->GDIInfo
->cPlanes
;
1322 UNIMPLEMENTED
; /* FIXME */
1326 UNIMPLEMENTED
; /* FIXME */
1330 UNIMPLEMENTED
; /* FIXME */
1334 ret
= dc
->GDIInfo
->ulNumColors
;
1338 ret
= dc
->GDIInfo
->ulAspectX
;
1342 ret
= dc
->GDIInfo
->ulAspectY
;
1346 ret
= dc
->GDIInfo
->ulAspectXY
;
1350 UNIMPLEMENTED
; /* FIXME */
1354 UNIMPLEMENTED
; /* FIXME */
1358 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1366 UNIMPLEMENTED
; /* FIXME */
1370 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1380 case PHYSICALHEIGHT
:
1381 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1391 case PHYSICALOFFSETX
:
1392 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1402 case PHYSICALOFFSETY
:
1403 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1414 UNIMPLEMENTED
; /* FIXME */
1417 case SCALINGFACTORX
:
1418 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1428 case SCALINGFACTORY
:
1429 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1440 ret
= dc
->GDIInfo
->flRaster
;
1444 UNIMPLEMENTED
; /* FIXME */
1448 UNIMPLEMENTED
; /* FIXME */
1452 UNIMPLEMENTED
; /* FIXME */
1456 ret
= dc
->GDIInfo
->flTextCaps
;
1468 NtGdiGetDeviceCaps(HDC hDC
,
1474 dc
= DC_LockDc(hDC
);
1477 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1481 ret
= IntGdiGetDeviceCaps(dc
, Index
);
1483 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1489 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1490 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1493 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1499 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1500 if (NULL
== GdiObject
)
1502 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1506 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1510 case GDI_OBJECT_TYPE_PEN
:
1511 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1513 case GDI_OBJECT_TYPE_BRUSH
:
1514 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1517 case GDI_OBJECT_TYPE_BITMAP
:
1518 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1520 case GDI_OBJECT_TYPE_FONT
:
1521 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1523 // Fix the LOGFONT structure for the stock fonts
1524 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1526 FixStockFontSizeW(Handle
, Count
, Buffer
);
1531 case GDI_OBJECT_TYPE_PALETTE
:
1532 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1536 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1540 GDIOBJ_UnlockObj(Handle
);
1546 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1557 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1560 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1564 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1566 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1567 ExFreePool(SafeBuf
);
1568 if(!NT_SUCCESS(Status
))
1570 SetLastNtError(Status
);
1578 NtGdiGetObjectType(HANDLE handle
)
1584 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1587 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1591 objectType
= GDIOBJ_GetObjectType(handle
);
1594 case GDI_OBJECT_TYPE_PEN
:
1597 case GDI_OBJECT_TYPE_BRUSH
:
1600 case GDI_OBJECT_TYPE_BITMAP
:
1601 result
= OBJ_BITMAP
;
1603 case GDI_OBJECT_TYPE_FONT
:
1606 case GDI_OBJECT_TYPE_PALETTE
:
1609 case GDI_OBJECT_TYPE_REGION
:
1610 result
= OBJ_REGION
;
1612 case GDI_OBJECT_TYPE_DC
:
1615 case GDI_OBJECT_TYPE_METADC
:
1616 result
= OBJ_METADC
;
1618 case GDI_OBJECT_TYPE_METAFILE
:
1619 result
= OBJ_METAFILE
;
1621 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1622 result
= OBJ_ENHMETAFILE
;
1624 case GDI_OBJECT_TYPE_ENHMETADC
:
1625 result
= OBJ_ENHMETADC
;
1627 case GDI_OBJECT_TYPE_EXTPEN
:
1628 result
= OBJ_EXTPEN
;
1630 case GDI_OBJECT_TYPE_MEMDC
:
1635 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1639 GDIOBJ_UnlockObj(handle
);
1643 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1644 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1645 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1646 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1647 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1648 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1649 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1650 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1651 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1654 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1661 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1666 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1668 dc
= DC_LockDc(hDC
);
1671 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1675 if (SaveLevel
== -1)
1676 SaveLevel
= dc
->saveLevel
;
1678 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1685 while (dc
->saveLevel
>= SaveLevel
)
1687 HDC hdcs
= DC_GetNextDC (dc
);
1689 dcs
= DC_LockDc (hdcs
);
1695 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1696 if (--dc
->saveLevel
< SaveLevel
)
1699 DC_UnlockDc( hdcs
);
1700 NtGdiSetDCState(hDC
, hdcs
);
1702 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1704 /* FIXME: This might not be quite right, since we're
1705 * returning FALSE but still destroying the saved DC state */
1709 dc
= DC_LockDc(hDC
);
1717 DC_UnlockDc( hdcs
);
1719 NtGdiDeleteDC (hdcs
);
1726 NtGdiSaveDC(HDC hDC
)
1732 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1734 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1739 dcs
= DC_LockDc (hdcs
);
1742 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1745 dc
= DC_LockDc (hDC
);
1749 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1754 /* Copy path. The reason why path saving / restoring is in SaveDC/
1755 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1756 * functions are only in Win16 (which doesn't have paths) and that
1757 * SetDCState doesn't allow us to signal an error (which can happen
1758 * when copying paths).
1760 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1762 NtGdiDeleteDC (hdcs
);
1767 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1768 DC_SetNextDC (dc
, hdcs
);
1769 ret
= ++dc
->saveLevel
;
1770 DC_UnlockDc( hdcs
);
1778 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1780 HGDIOBJ objOrg
= NULL
; // default to failure
1787 ULONG NumColors
= 0;
1791 if(!hDC
|| !hGDIObj
) return NULL
;
1793 dc
= DC_LockDc(hDC
);
1796 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1800 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1804 case GDI_OBJECT_TYPE_PEN
:
1805 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1808 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1812 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
1813 PENOBJ_UnlockPen(hGDIObj
);
1816 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1820 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1821 dc
->w
.hPen
= hGDIObj
;
1822 if (dc
->XlatePen
!= NULL
)
1823 EngDeleteXlate(dc
->XlatePen
);
1824 dc
->XlatePen
= XlateObj
;
1827 case GDI_OBJECT_TYPE_BRUSH
:
1828 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
1831 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1835 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
1836 BRUSHOBJ_UnlockBrush(hGDIObj
);
1839 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1843 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1844 dc
->w
.hBrush
= hGDIObj
;
1845 if (dc
->XlateBrush
!= NULL
)
1846 EngDeleteXlate(dc
->XlateBrush
);
1847 dc
->XlateBrush
= XlateObj
;
1850 case GDI_OBJECT_TYPE_FONT
:
1851 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
1853 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1854 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1858 case GDI_OBJECT_TYPE_BITMAP
:
1859 // must be memory dc to select bitmap
1860 if (!(dc
->w
.flags
& DC_MEMORY
))
1865 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1868 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1872 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1874 /* Release the old bitmap, lock the new one and convert it to a SURF */
1875 dc
->w
.hBitmap
= hGDIObj
;
1877 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1880 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1882 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1884 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1885 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1886 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1887 dc
->w
.hPalette
= PALETTE_AllocPaletteIndexedRGB(NumColors
, pb
->ColorMap
);
1891 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1892 pb
->dib
->dsBitfields
[0],
1893 pb
->dib
->dsBitfields
[1],
1894 pb
->dib
->dsBitfields
[2]);
1899 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
1900 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1903 /* Reselect brush and pen to regenerate the XLATEOBJs. */
1904 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
1905 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
1907 DC_UnlockDc ( hDC
);
1908 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
1909 BITMAPOBJ_UnlockBitmap( hGDIObj
);
1910 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1911 NtGdiDeleteObject ( hVisRgn
);
1915 case GDI_OBJECT_TYPE_REGION
:
1918 * The return value is one of the following values:
1923 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
1933 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1936 DC
*dc
= DC_LockDc(hDC
);
1940 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1944 wRet
= dc
->w
.flags
& DC_DIRTY
;
1946 /* "Undocumented Windows" info is slightly confusing.
1949 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1951 if (Flags
& DCHF_INVALIDATEVISRGN
)
1953 dc
->w
.flags
|= DC_DIRTY
;
1955 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1957 dc
->w
.flags
&= ~DC_DIRTY
;
1965 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1966 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1967 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1968 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1969 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
1971 // ---------------------------------------------------- Private Interface
1974 DC_AllocDC(PUNICODE_STRING Driver
)
1982 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
1987 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
1990 hDC
= (HDC
) GDIOBJ_AllocObj(GDI_OBJECT_TYPE_DC
);
2000 NewDC
= DC_LockDc(hDC
);
2001 /* FIXME - Handle NewDC == NULL! */
2005 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2006 NewDC
->DriverName
.Buffer
= Buf
;
2009 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2010 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2011 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2012 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2013 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2014 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2015 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2016 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2017 NewDC
->w
.vport2WorldValid
= TRUE
;
2018 NewDC
->w
.MapMode
= MM_TEXT
;
2019 NewDC
->wndExtX
= 1.0f
;
2020 NewDC
->wndExtY
= 1.0f
;
2021 NewDC
->vportExtX
= 1.0f
;
2022 NewDC
->vportExtY
= 1.0f
;
2023 NewDC
->w
.textColor
= 0;
2024 NewDC
->w
.backgroundColor
= 0xffffff;
2026 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2027 TextIntRealizeFont(NewDC
->w
.hFont
);
2029 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2037 DC_FindOpenDC(PUNICODE_STRING Driver
)
2043 * Initialize some common fields in the Device Context structure.
2046 DC_InitDC(HDC DCHandle
)
2048 // NtGdiRealizeDefaultPalette(DCHandle);
2050 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2051 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2052 //NtGdiSelectObject(DCHandle, hFont);
2057 res = CLIPPING_UpdateGCRegion(DCToInit);
2058 ASSERT ( res != ERROR );
2064 DC_FreeDC(HDC DCToFree
)
2066 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
))
2068 DPRINT("DC_FreeDC failed\n");
2073 DC_Cleanup(PVOID ObjectBody
)
2075 PDC pDC
= (PDC
)ObjectBody
;
2076 RtlFreeUnicodeString(&pDC
->DriverName
);
2081 DC_GetNextDC (PDC pDC
)
2087 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2089 pDC
->hNext
= hNextDC
;
2093 DC_UpdateXforms(PDC dc
)
2095 XFORM xformWnd2Vport
;
2096 FLOAT scaleX
, scaleY
;
2098 /* Construct a transformation to do the window-to-viewport conversion */
2099 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2100 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2101 xformWnd2Vport
.eM11
= scaleX
;
2102 xformWnd2Vport
.eM12
= 0.0;
2103 xformWnd2Vport
.eM21
= 0.0;
2104 xformWnd2Vport
.eM22
= scaleY
;
2105 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2106 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2108 /* Combine with the world transformation */
2109 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2111 /* Create inverse of world-to-viewport transformation */
2112 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2116 DC_InvertXform(const XFORM
*xformSrc
,
2121 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2122 if (determinant
> -1e-12 && determinant
< 1e-12)
2127 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2128 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2129 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2130 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2131 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2132 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2138 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2142 GDIOBJ_SetOwnership(hDC
, Owner
);
2143 DC
= DC_LockDc(hDC
);
2146 if (NULL
!= DC
->w
.hClipRgn
)
2148 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2150 if (NULL
!= DC
->w
.hVisRgn
)
2152 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2154 if (NULL
!= DC
->w
.hGCClipRgn
)
2156 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2163 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2165 if (PrimarySurface
.Handle
== NULL
)
2169 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2173 * Returns the color of the brush or pen that is currently selected into the DC.
2174 * This function is called from GetDCBrushColor() and GetDCPenColor()
2177 IntGetDCColor(HDC hDC
, ULONG Object
)
2180 * The previous implementation was completly incorrect. It modified the
2181 * brush that was currently selected into the device context, but in fact
2182 * the DC pen/brush color should be stored directly in the device context
2183 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2184 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2185 * into the device context and BRUSHOBJ for drawing is composed (belongs
2186 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2187 * the implementation should be moved to user mode GDI32.dll when UM
2188 * mapped GDI objects will be implemented.
2191 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2192 return 0xFFFFFF; /* The default DC color. */
2196 * Changes the color of the brush or pen that is currently selected into the DC.
2197 * This function is called from SetDCBrushColor() and SetDCPenColor()
2200 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2202 /* See the comment in IntGetDCColor. */
2204 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2208 #define SIZEOF_DEVMODEW_300 188
2209 #define SIZEOF_DEVMODEW_400 212
2210 #define SIZEOF_DEVMODEW_500 220
2212 /*! \brief Enumerate possible display settings for the given display...
2214 * \todo Make thread safe!?
2215 * \todo Don't ignore lpszDeviceName
2216 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2219 IntEnumDisplaySettings(
2220 PUNICODE_STRING lpszDeviceName
,
2222 LPDEVMODEW lpDevMode
,
2225 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2226 static DWORD SizeOfCachedDevModes
= 0;
2227 LPDEVMODEW CachedMode
= NULL
;
2230 ULONG DisplayNumber
= 0; /* only default display supported */
2232 if (lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2233 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2234 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2236 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2240 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2242 CachedMode
= &PrimarySurface
.DMW
;
2243 assert(CachedMode
->dmSize
> 0);
2245 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2247 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2248 DevMode
.dmSize
= sizeof (DevMode
);
2249 DevMode
.dmDriverExtra
= 0;
2250 if (SetupDevMode(&DevMode
, DisplayNumber
))
2251 CachedMode
= &DevMode
;
2254 SetLastWin32Error(0); /* FIXME: use error code */
2257 /* FIXME: Maybe look for the matching devmode supplied by the
2258 * driver so we can provide driver private/extra data?
2263 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2265 BOOL PrimarySurfaceCreated
= FALSE
;
2266 UNICODE_STRING DriverFileNames
;
2268 DRVENABLEDATA DrvEnableData
;
2270 /* Retrieve DDI driver names from registry */
2271 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2272 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2274 DPRINT1("FindDriverFileNames failed\n");
2278 if (!HalQueryDisplayOwnership())
2280 IntCreatePrimarySurface();
2281 PrimarySurfaceCreated
= TRUE
;
2285 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2286 * scan all of them until a good one found.
2288 CurrentName
= DriverFileNames
.Buffer
;
2289 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2290 CurrentName
+= wcslen(CurrentName
) + 1)
2293 PGD_ENABLEDRIVER GDEnableDriver
;
2295 /* Get the DDI driver's entry point */
2296 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2297 if (NULL
== GDEnableDriver
)
2299 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2303 /* Call DDI driver's EnableDriver function */
2304 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2306 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2308 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2312 CachedDevModesEnd
= CachedDevModes
;
2314 /* find DrvGetModes function */
2315 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2317 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2318 PGD_GETMODES GetModes
;
2319 INT SizeNeeded
, SizeUsed
;
2321 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2324 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2326 /* make sure we have enough memory to hold the modes */
2327 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2328 if (SizeNeeded
<= 0)
2330 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2334 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2335 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2339 SizeOfCachedDevModes
+= SizeNeeded
;
2340 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2341 if (NewBuffer
== NULL
)
2344 ExFreePool(CachedDevModes
);
2345 SizeOfCachedDevModes
= 0;
2346 CachedDevModes
= NULL
;
2347 CachedDevModesEnd
= NULL
;
2348 if (PrimarySurfaceCreated
)
2350 IntDestroyPrimarySurface();
2352 SetLastWin32Error(STATUS_NO_MEMORY
);
2355 if (CachedDevModes
!= NULL
)
2357 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2358 ExFreePool(CachedDevModes
);
2360 CachedDevModes
= NewBuffer
;
2361 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2365 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2366 SizeOfCachedDevModes
- SizeUsed
,
2368 if (SizeNeeded
<= 0)
2370 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2374 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2380 if (PrimarySurfaceCreated
)
2382 IntDestroyPrimarySurface();
2385 RtlFreeUnicodeString(&DriverFileNames
);
2388 /* return cached info */
2389 CachedMode
= CachedDevModes
;
2390 if (CachedMode
>= CachedDevModesEnd
)
2392 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2395 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2397 assert(CachedMode
->dmSize
> 0);
2398 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2400 if (CachedMode
>= CachedDevModesEnd
)
2402 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2407 assert(CachedMode
!= NULL
);
2409 Size
= OldSize
= lpDevMode
->dmSize
;
2410 if (Size
> CachedMode
->dmSize
)
2411 Size
= CachedMode
->dmSize
;
2412 RtlCopyMemory(lpDevMode
, CachedMode
, Size
);
2413 RtlZeroMemory((PCHAR
)lpDevMode
+ Size
, OldSize
- Size
);
2414 lpDevMode
->dmSize
= OldSize
;
2416 Size
= OldSize
= lpDevMode
->dmDriverExtra
;
2417 if (Size
> CachedMode
->dmDriverExtra
)
2418 Size
= CachedMode
->dmDriverExtra
;
2419 RtlCopyMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
,
2420 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2421 RtlZeroMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
+ Size
, OldSize
- Size
);
2422 lpDevMode
->dmDriverExtra
= OldSize
;