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.
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
, TRUE
);
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
;
174 NewDC
->PDev
= OrigDC
->PDev
;
175 NewDC
->DMW
= OrigDC
->DMW
;
176 memcpy(NewDC
->FillPatternSurfaces
,
177 OrigDC
->FillPatternSurfaces
,
178 sizeof OrigDC
->FillPatternSurfaces
);
179 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
180 NewDC
->DevInfo
= OrigDC
->DevInfo
;
181 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
183 /* DriverName is copied in the AllocDC routine */
184 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
185 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
186 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
187 NewDC
->wndExtX
= OrigDC
->wndExtX
;
188 NewDC
->wndExtY
= OrigDC
->wndExtY
;
189 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
190 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
191 NewDC
->vportExtX
= OrigDC
->vportExtX
;
192 NewDC
->vportExtY
= OrigDC
->vportExtY
;
194 /* Create default bitmap */
195 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
198 DC_UnlockDc( hNewDC
);
200 if (NULL
!= DisplayDC
)
202 NtGdiDeleteDC(DisplayDC
);
206 NewDC
->w
.flags
= DC_MEMORY
;
207 NewDC
->w
.hBitmap
= hBitmap
;
208 NewDC
->w
.hFirstBitmap
= hBitmap
;
209 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
211 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
212 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
213 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
214 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
215 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
216 NewDC
->w
.ROPmode
= OrigDC
->w
.ROPmode
;
218 if (NULL
!= DisplayDC
)
220 NtGdiDeleteDC(DisplayDC
);
224 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
225 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
226 NtGdiDeleteObject(hVisRgn
);
234 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
236 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
237 WCHAR DeviceNameBuffer
[20];
240 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
241 RtlInitUnicodeString(RegistryPath
, NULL
);
242 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
243 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
244 QueryTable
[0].Name
= DeviceNameBuffer
;
245 QueryTable
[0].EntryContext
= RegistryPath
;
247 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
252 if (! NT_SUCCESS(Status
))
254 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
258 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
264 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
266 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
267 UNICODE_STRING RegistryPath
;
270 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
272 DPRINT("GetRegistryPath failed\n");
276 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
277 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
278 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
279 QueryTable
[0].EntryContext
= DriverFileNames
;
281 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
286 RtlFreeUnicodeString(&RegistryPath
);
287 if (! NT_SUCCESS(Status
))
289 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
293 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
298 static NTSTATUS STDCALL
299 DevModeCallback(IN PWSTR ValueName
,
302 IN ULONG ValueLength
,
304 IN PVOID EntryContext
)
306 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
308 DPRINT("Found registry value for name %S: type %d, length %d\n",
309 ValueName
, ValueType
, ValueLength
);
311 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
313 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
315 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
317 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
319 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
321 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
323 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
325 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
327 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
329 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
331 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
333 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
335 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
337 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
339 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
343 return STATUS_SUCCESS
;
347 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
349 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
350 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
351 static WCHAR ControlSet
[] = L
"CONTROLSET";
352 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
353 UNICODE_STRING RegistryPath
;
355 PWCHAR AfterControlSet
;
357 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
360 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
362 DPRINT("GetRegistryPath failed\n");
366 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
367 wcslen(RegistryMachineSystem
)));
370 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
371 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
373 AfterControlSet
+= wcslen(CurrentControlSet
);
375 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
377 AfterControlSet
+= wcslen(ControlSet
);
378 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
382 Valid
= (L
'\\' == *AfterControlSet
);
393 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
394 (wcslen(RegistryPath
.Buffer
) +
395 wcslen(Insert
) + 1) * sizeof(WCHAR
),
397 if (NULL
!= ProfilePath
)
399 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
400 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
401 wcscat(ProfilePath
, AfterControlSet
);
403 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
404 QueryTable
[0].QueryRoutine
= DevModeCallback
;
405 QueryTable
[0].Flags
= 0;
406 QueryTable
[0].Name
= NULL
;
407 QueryTable
[0].EntryContext
= NULL
;
408 QueryTable
[0].DefaultType
= REG_NONE
;
409 QueryTable
[0].DefaultData
= NULL
;
410 QueryTable
[0].DefaultLength
= 0;
412 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
417 if (! NT_SUCCESS(Status
))
419 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
420 ProfilePath
, Status
);
425 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
426 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
427 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
428 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
429 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
431 DPRINT("Not all required devmode members are set\n");
436 ExFreePool(ProfilePath
);
445 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
448 RtlFreeUnicodeString(&RegistryPath
);
452 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
461 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");
493 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
494 * scan all of them until a good one found.
496 CurrentName
= DriverFileNames
.Buffer
;
499 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
501 /* Get the DDI driver's entry point */
502 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
503 if (NULL
== GDEnableDriver
)
505 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
509 /* Call DDI driver's EnableDriver function */
510 RtlZeroMemory(&DED
, sizeof(DED
));
512 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
514 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
524 /* Skip to the next name but never get past the Unicode string */
525 while (L
'\0' != *CurrentName
&&
526 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
530 if (CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
537 RtlFreeUnicodeString(&DriverFileNames
);
541 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
542 DPRINT1("No suitable DDI driver found\n");
546 DPRINT("Display driver %S loaded\n", CurrentName
);
548 DPRINT("Building DDI Functions\n");
550 /* Construct DDI driver function dispatch table */
551 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
553 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
554 DPRINT1("BuildDDIFunctions failed\n");
558 /* Allocate a phyical device handle from the driver */
559 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
560 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
562 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
566 PrimarySurface
.FillPatterns
,
567 sizeof(PrimarySurface
.GDIInfo
),
568 (ULONG
*) &PrimarySurface
.GDIInfo
,
569 sizeof(PrimarySurface
.DevInfo
),
570 &PrimarySurface
.DevInfo
,
573 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
574 DoDefault
= (NULL
== PrimarySurface
.PDev
);
577 DPRINT1("DrvEnablePDev with registry parameters failed\n");
587 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
588 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
589 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
593 PrimarySurface
.FillPatterns
,
594 sizeof(PrimarySurface
.GDIInfo
),
595 (ULONG
*) &PrimarySurface
.GDIInfo
,
596 sizeof(PrimarySurface
.DevInfo
),
597 &PrimarySurface
.DevInfo
,
600 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
602 if (NULL
== PrimarySurface
.PDev
)
604 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
605 DPRINT1("DrvEnablePDEV with default parameters failed\n");
606 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
611 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
613 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
614 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
616 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
618 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
619 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
622 PrimarySurface
.Pointer
.Exclude
.right
= -1;
624 DPRINT("calling completePDev\n");
626 /* Complete initialization of the physical device */
627 PrimarySurface
.DriverFunctions
.CompletePDEV(
629 (HDEV
)&PrimarySurface
);
631 DPRINT("calling DRIVER_ReferenceDriver\n");
633 DRIVER_ReferenceDriver(L
"DISPLAY");
635 PrimarySurface
.PreparedDriver
= TRUE
;
636 PrimarySurface
.DisplayNumber
= DisplayNumber
;
645 IntPrepareDriverIfNeeded()
647 return (PrimarySurface
.PreparedDriver
? TRUE
: IntPrepareDriver());
651 IntCreatePrimarySurface()
657 if (! IntPrepareDriverIfNeeded())
662 DPRINT("calling EnableSurface\n");
663 /* Enable the drawing surface */
664 PrimarySurface
.Handle
=
665 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
666 if (NULL
== PrimarySurface
.Handle
)
668 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
669 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
670 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
671 DPRINT1("DrvEnableSurface failed\n");
676 IntAttachMonitor(&PrimarySurface
, PrimarySurface
.DisplayNumber
);
678 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
679 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
680 SurfSize
= SurfObj
->sizlBitmap
;
681 SurfSize
= SurfObj
->sizlBitmap
;
682 SurfaceRect
.left
= SurfaceRect
.top
= 0;
683 SurfaceRect
.right
= SurfObj
->sizlBitmap
.cx
;
684 SurfaceRect
.bottom
= SurfObj
->sizlBitmap
.cy
;
685 /* FIXME - why does EngEraseSurface() sometimes crash?
686 EngEraseSurface(SurfObj, &SurfaceRect, 0); */
688 /* Put the pointer in the center of the screen */
689 GDIDEV(SurfObj
)->Pointer
.Pos
.x
= (SurfaceRect
.right
- SurfaceRect
.left
) / 2;
690 GDIDEV(SurfObj
)->Pointer
.Pos
.y
= (SurfaceRect
.bottom
- SurfaceRect
.top
) / 2;
692 EngUnlockSurface(SurfObj
);
693 IntShowDesktop(IntGetActiveDesktop(), SurfSize
.cx
, SurfSize
.cy
);
699 IntDestroyPrimarySurface()
701 DRIVER_UnreferenceDriver(L
"DISPLAY");
704 IntDetachMonitor(&PrimarySurface
);
707 * FIXME: Hide a mouse pointer there. Also because we have to prevent
708 * memory leaks with the Eng* mouse routines.
711 DPRINT("Reseting display\n" );
712 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
713 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
714 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
715 PrimarySurface
.PreparedDriver
= FALSE
;
719 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
723 IntGdiCreateDC(PUNICODE_STRING Driver
,
724 PUNICODE_STRING Device
,
725 PUNICODE_STRING Output
,
726 CONST PDEVMODEW InitData
,
734 UNICODE_STRING StdDriver
;
736 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
738 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
742 if (! IntPrepareDriverIfNeeded())
744 DPRINT1("Unable to prepare graphics driver, returning NULL ic\n");
748 else if (! IntGraphicsCheck(TRUE
))
750 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
755 /* Check for existing DC object */
756 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
759 return NtGdiCreateCompatableDC(hDC
);
762 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
764 DPRINT("NAME: %ws\n", Driver
); // FIXME: Should not crash if NULL
767 /* Allocate a DC object */
768 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
773 NewDC
= DC_LockDc( hNewDC
);
774 /* FIXME - NewDC can be NULL!!! Don't assert here! */
781 NewDC
->IsIC
= CreateAsIC
;
782 NewDC
->DMW
= PrimarySurface
.DMW
;
783 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
784 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
785 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
786 sizeof(NewDC
->FillPatternSurfaces
));
787 NewDC
->PDev
= PrimarySurface
.PDev
;
788 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
789 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
790 NewDC
->w
.hBitmap
= PrimarySurface
.Handle
;
792 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
793 NewDC
->DMW
.dmFields
= 0x000fc000;
795 NewDC
->DMW
.dmLogPixels
= 96;
796 NewDC
->w
.bitsPerPixel
= NewDC
->DMW
.dmBitsPerPel
; // FIXME: set this here??
797 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
801 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
804 DC_UnlockDc ( hNewDC
);
805 DC_FreeDC ( hNewDC
) ;
808 ASSERT(NewDC
->DMW
.dmBitsPerPel
== BitsPerFormat(SurfObj
->iBitmapFormat
));
809 ASSERT(NewDC
->DMW
.dmPelsWidth
== SurfObj
->sizlBitmap
.cx
);
810 ASSERT(NewDC
->DMW
.dmPelsHeight
== SurfObj
->sizlBitmap
.cy
);
812 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
813 NewDC
->w
.ROPmode
= R2_COPYPEN
;
815 DC_UnlockDc( hNewDC
);
817 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfObj
->sizlBitmap
.cx
,
818 SurfObj
->sizlBitmap
.cy
);
819 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
820 NtGdiDeleteObject(hVisRgn
);
822 /* Initialize the DC state */
824 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
825 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
826 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
827 NtGdiSetBkMode(hNewDC
, OPAQUE
);
829 EngUnlockSurface(SurfObj
);
833 DC_UnlockDc( hNewDC
);
840 NtGdiCreateDC(PUNICODE_STRING Driver
,
841 PUNICODE_STRING Device
,
842 PUNICODE_STRING Output
,
843 CONST PDEVMODEW InitData
)
845 UNICODE_STRING SafeDriver
, SafeDevice
;
846 DEVMODEW SafeInitData
;
852 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
853 if(!NT_SUCCESS(Status
))
855 SetLastNtError(Status
);
858 /* FIXME - InitData can have some more bytes! */
863 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
864 if(!NT_SUCCESS(Status
))
866 SetLastNtError(Status
);
873 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
874 if(!NT_SUCCESS(Status
))
876 RtlFreeUnicodeString(&SafeDriver
);
877 SetLastNtError(Status
);
882 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
, FALSE
);
888 NtGdiCreateIC(PUNICODE_STRING Driver
,
889 PUNICODE_STRING Device
,
890 PUNICODE_STRING Output
,
891 CONST PDEVMODEW InitData
)
893 UNICODE_STRING SafeDriver
, SafeDevice
;
894 DEVMODEW SafeInitData
;
900 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
901 if(!NT_SUCCESS(Status
))
903 SetLastNtError(Status
);
906 /* FIXME - InitData can have some more bytes! */
911 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
912 if(!NT_SUCCESS(Status
))
914 SetLastNtError(Status
);
921 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
922 if(!NT_SUCCESS(Status
))
924 RtlFreeUnicodeString(&SafeDriver
);
925 SetLastNtError(Status
);
930 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
931 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
932 NULL
== InitData
? NULL
: &SafeInitData
, TRUE
);
938 NtGdiDeleteDC(HDC DCHandle
)
942 DCToDelete
= DC_LockDc(DCHandle
);
943 if (DCToDelete
== NULL
)
948 /* First delete all saved DCs */
949 while (DCToDelete
->saveLevel
)
954 savedHDC
= DC_GetNextDC (DCToDelete
);
955 savedDC
= DC_LockDc (savedHDC
);
960 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
961 DCToDelete
->saveLevel
--;
962 DC_UnlockDc( savedHDC
);
963 NtGdiDeleteDC (savedHDC
);
966 /* Free GDI resources allocated to this DC */
967 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
970 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
971 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
972 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
973 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
974 if (DCToDelete
->w
.flags
& DC_MEMORY
)
976 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
978 if (DCToDelete
->XlateBrush
!= NULL
)
979 EngDeleteXlate(DCToDelete
->XlateBrush
);
980 if (DCToDelete
->XlatePen
!= NULL
)
981 EngDeleteXlate(DCToDelete
->XlatePen
);
983 if (DCToDelete
->w
.hClipRgn
)
985 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
987 if (DCToDelete
->w
.hVisRgn
)
989 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
991 if (NULL
!= DCToDelete
->CombinedClip
)
993 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
995 if (DCToDelete
->w
.hGCClipRgn
)
997 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
1000 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
1002 DC_UnlockDc( DCHandle
);
1003 DC_FreeDC ( DCHandle
);
1009 NtGdiDrawEscape(HDC hDC
,
1019 NtGdiEnumObjects(HDC hDC
,
1021 GOBJENUMPROC ObjectFunc
,
1028 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
1029 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
1030 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
1031 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
1034 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
1039 if(!(dc
= DC_LockDc(hDC
)))
1041 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1048 SelObject
= dc
->w
.hPen
;
1051 SelObject
= dc
->w
.hBrush
;
1054 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
1058 SelObject
= dc
->w
.hFont
;
1061 SelObject
= dc
->w
.hBitmap
;
1063 case OBJ_COLORSPACE
:
1064 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
1069 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1077 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
1080 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
1082 Point
->x
= dc
->w
.DCOrgX
;
1083 Point
->y
= dc
->w
.DCOrgY
;
1089 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1098 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1102 dc
= DC_LockDc(hDC
);
1105 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1109 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1111 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
1112 if(!NT_SUCCESS(Status
))
1114 SetLastNtError(Status
);
1124 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1130 if (!(dc
= DC_LockDc(hDC
)))
1132 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1136 oldColor
= dc
->w
.backgroundColor
;
1137 dc
->w
.backgroundColor
= color
;
1138 hBrush
= dc
->w
.hBrush
;
1139 DC_UnlockDc ( hDC
);
1140 NtGdiSelectObject(hDC
, hBrush
);
1145 NtGdiGetDCState(HDC hDC
)
1150 dc
= DC_LockDc(hDC
);
1153 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1157 hnewdc
= DC_AllocDC(NULL
);
1163 newdc
= DC_LockDc( hnewdc
);
1164 /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
1167 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1168 newdc
->w
.hPen
= dc
->w
.hPen
;
1169 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1170 newdc
->w
.hFont
= dc
->w
.hFont
;
1171 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1172 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1174 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1176 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1177 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1178 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1179 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1180 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1181 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1182 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1183 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1184 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1185 newdc
->w
.textColor
= dc
->w
.textColor
;
1186 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1187 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1188 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1189 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1190 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1191 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1192 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1193 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1194 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1195 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1197 /* Apparently, the DC origin is not changed by [GS]etDCState */
1198 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1199 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1201 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1202 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1203 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1204 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1205 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1206 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1207 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1208 newdc
->wndOrgX
= dc
->wndOrgX
;
1209 newdc
->wndOrgY
= dc
->wndOrgY
;
1210 newdc
->wndExtX
= dc
->wndExtX
;
1211 newdc
->wndExtY
= dc
->wndExtY
;
1212 newdc
->vportOrgX
= dc
->vportOrgX
;
1213 newdc
->vportOrgY
= dc
->vportOrgY
;
1214 newdc
->vportExtX
= dc
->vportExtX
;
1215 newdc
->vportExtY
= dc
->vportExtY
;
1217 newdc
->hSelf
= hnewdc
;
1218 newdc
->saveLevel
= 0;
1219 newdc
->IsIC
= dc
->IsIC
;
1222 PATH_InitGdiPath( &newdc
->w
.path
);
1225 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1227 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1230 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1231 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1233 DC_UnlockDc( hnewdc
);
1241 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1245 dc
= DC_LockDc ( hDC
);
1248 dcs
= DC_LockDc ( hDCSave
);
1251 if ( dcs
->w
.flags
& DC_SAVED
)
1253 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1255 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1258 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1261 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1262 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1263 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1264 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1265 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1266 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1267 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1268 dc
->w
.textColor
= dcs
->w
.textColor
;
1269 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1270 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1271 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1272 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1273 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1274 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1275 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1276 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1277 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1278 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1280 /* Apparently, the DC origin is not changed by [GS]etDCState */
1281 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1282 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1284 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1285 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1286 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1288 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1289 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1290 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1291 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1293 dc
->wndOrgX
= dcs
->wndOrgX
;
1294 dc
->wndOrgY
= dcs
->wndOrgY
;
1295 dc
->wndExtX
= dcs
->wndExtX
;
1296 dc
->wndExtY
= dcs
->wndExtY
;
1297 dc
->vportOrgX
= dcs
->vportOrgX
;
1298 dc
->vportOrgY
= dcs
->vportOrgY
;
1299 dc
->vportExtX
= dcs
->vportExtX
;
1300 dc
->vportExtY
= dcs
->vportExtY
;
1302 if (!(dc
->w
.flags
& DC_MEMORY
))
1304 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1308 if (dcs
->w
.hClipRgn
)
1310 if (!dc
->w
.hClipRgn
)
1312 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1314 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1320 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1327 res
= CLIPPING_UpdateGCRegion( dc
);
1328 ASSERT ( res
!= ERROR
);
1330 DC_UnlockDc ( hDC
);
1332 DC_UnlockDc ( hDC
);
1333 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1336 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1337 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1338 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1339 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1340 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1341 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1343 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1346 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1351 DC_UnlockDc ( hDCSave
);
1353 DC_UnlockDc ( hDC
);
1354 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1358 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1362 IntGdiGetDeviceCaps(PDC dc
, INT Index
)
1367 /* Retrieve capability */
1371 ret
= dc
->GDIInfo
->ulVersion
;
1375 ret
= dc
->GDIInfo
->ulTechnology
;
1379 ret
= dc
->GDIInfo
->ulHorzSize
;
1383 ret
= dc
->GDIInfo
->ulVertSize
;
1387 ret
= dc
->GDIInfo
->ulHorzRes
;
1391 ret
= dc
->GDIInfo
->ulVertRes
;
1395 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1399 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1403 ret
= dc
->GDIInfo
->cBitsPixel
;
1407 ret
= dc
->GDIInfo
->cPlanes
;
1411 UNIMPLEMENTED
; /* FIXME */
1415 UNIMPLEMENTED
; /* FIXME */
1419 UNIMPLEMENTED
; /* FIXME */
1423 ret
= dc
->GDIInfo
->ulNumColors
;
1427 ret
= dc
->GDIInfo
->ulAspectX
;
1431 ret
= dc
->GDIInfo
->ulAspectY
;
1435 ret
= dc
->GDIInfo
->ulAspectXY
;
1439 UNIMPLEMENTED
; /* FIXME */
1443 UNIMPLEMENTED
; /* FIXME */
1447 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1455 UNIMPLEMENTED
; /* FIXME */
1459 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1469 case PHYSICALHEIGHT
:
1470 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1480 case PHYSICALOFFSETX
:
1481 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1491 case PHYSICALOFFSETY
:
1492 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1503 UNIMPLEMENTED
; /* FIXME */
1506 case SCALINGFACTORX
:
1507 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1517 case SCALINGFACTORY
:
1518 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1529 ret
= dc
->GDIInfo
->flRaster
;
1533 UNIMPLEMENTED
; /* FIXME */
1537 UNIMPLEMENTED
; /* FIXME */
1541 UNIMPLEMENTED
; /* FIXME */
1545 ret
= dc
->GDIInfo
->flTextCaps
;
1557 NtGdiGetDeviceCaps(HDC hDC
,
1563 dc
= DC_LockDc(hDC
);
1566 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1570 ret
= IntGdiGetDeviceCaps(dc
, Index
);
1572 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1578 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1579 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1582 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1588 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1589 if (NULL
== GdiObject
)
1591 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1595 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1599 case GDI_OBJECT_TYPE_PEN
:
1600 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1602 case GDI_OBJECT_TYPE_BRUSH
:
1603 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1606 case GDI_OBJECT_TYPE_BITMAP
:
1607 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1609 case GDI_OBJECT_TYPE_FONT
:
1610 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1612 // Fix the LOGFONT structure for the stock fonts
1613 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1615 FixStockFontSizeW(Handle
, Count
, Buffer
);
1620 case GDI_OBJECT_TYPE_PALETTE
:
1621 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1625 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1629 GDIOBJ_UnlockObj(Handle
);
1635 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1646 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1649 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1653 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1655 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1656 ExFreePool(SafeBuf
);
1657 if(!NT_SUCCESS(Status
))
1659 SetLastNtError(Status
);
1667 NtGdiGetObjectType(HANDLE handle
)
1673 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1676 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1680 objectType
= GDIOBJ_GetObjectType(handle
);
1683 case GDI_OBJECT_TYPE_PEN
:
1686 case GDI_OBJECT_TYPE_BRUSH
:
1689 case GDI_OBJECT_TYPE_BITMAP
:
1690 result
= OBJ_BITMAP
;
1692 case GDI_OBJECT_TYPE_FONT
:
1695 case GDI_OBJECT_TYPE_PALETTE
:
1698 case GDI_OBJECT_TYPE_REGION
:
1699 result
= OBJ_REGION
;
1701 case GDI_OBJECT_TYPE_DC
:
1704 case GDI_OBJECT_TYPE_METADC
:
1705 result
= OBJ_METADC
;
1707 case GDI_OBJECT_TYPE_METAFILE
:
1708 result
= OBJ_METAFILE
;
1710 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1711 result
= OBJ_ENHMETAFILE
;
1713 case GDI_OBJECT_TYPE_ENHMETADC
:
1714 result
= OBJ_ENHMETADC
;
1716 case GDI_OBJECT_TYPE_EXTPEN
:
1717 result
= OBJ_EXTPEN
;
1719 case GDI_OBJECT_TYPE_MEMDC
:
1724 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1728 GDIOBJ_UnlockObj(handle
);
1732 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1733 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1734 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1735 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1736 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1737 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1738 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1739 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1740 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1743 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1750 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1755 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1757 dc
= DC_LockDc(hDC
);
1760 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1764 if (SaveLevel
== -1)
1765 SaveLevel
= dc
->saveLevel
;
1767 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1774 while (dc
->saveLevel
>= SaveLevel
)
1776 HDC hdcs
= DC_GetNextDC (dc
);
1778 dcs
= DC_LockDc (hdcs
);
1784 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1785 if (--dc
->saveLevel
< SaveLevel
)
1788 DC_UnlockDc( hdcs
);
1789 NtGdiSetDCState(hDC
, hdcs
);
1791 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1793 /* FIXME: This might not be quite right, since we're
1794 * returning FALSE but still destroying the saved DC state */
1798 dc
= DC_LockDc(hDC
);
1806 DC_UnlockDc( hdcs
);
1808 NtGdiDeleteDC (hdcs
);
1815 NtGdiSaveDC(HDC hDC
)
1821 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1823 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1828 dcs
= DC_LockDc (hdcs
);
1831 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1834 dc
= DC_LockDc (hDC
);
1838 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1843 /* Copy path. The reason why path saving / restoring is in SaveDC/
1844 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1845 * functions are only in Win16 (which doesn't have paths) and that
1846 * SetDCState doesn't allow us to signal an error (which can happen
1847 * when copying paths).
1849 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1851 NtGdiDeleteDC (hdcs
);
1856 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1857 DC_SetNextDC (dc
, hdcs
);
1858 ret
= ++dc
->saveLevel
;
1859 DC_UnlockDc( hdcs
);
1867 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1869 HGDIOBJ objOrg
= NULL
; // default to failure
1876 ULONG NumColors
= 0;
1880 if(!hDC
|| !hGDIObj
) return NULL
;
1882 dc
= DC_LockDc(hDC
);
1885 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1889 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1893 case GDI_OBJECT_TYPE_PEN
:
1894 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1897 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1901 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
1902 PENOBJ_UnlockPen(hGDIObj
);
1905 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1909 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1910 dc
->w
.hPen
= hGDIObj
;
1911 if (dc
->XlatePen
!= NULL
)
1912 EngDeleteXlate(dc
->XlatePen
);
1913 dc
->XlatePen
= XlateObj
;
1916 case GDI_OBJECT_TYPE_BRUSH
:
1917 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
1920 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1924 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
1925 BRUSHOBJ_UnlockBrush(hGDIObj
);
1928 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1932 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1933 dc
->w
.hBrush
= hGDIObj
;
1934 if (dc
->XlateBrush
!= NULL
)
1935 EngDeleteXlate(dc
->XlateBrush
);
1936 dc
->XlateBrush
= XlateObj
;
1939 case GDI_OBJECT_TYPE_FONT
:
1940 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
1942 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1943 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1947 case GDI_OBJECT_TYPE_BITMAP
:
1948 // must be memory dc to select bitmap
1949 if (!(dc
->w
.flags
& DC_MEMORY
))
1954 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1957 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1961 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1963 /* Release the old bitmap, lock the new one and convert it to a SURF */
1964 dc
->w
.hBitmap
= hGDIObj
;
1966 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1969 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1971 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1973 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1974 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1975 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1976 dc
->w
.hPalette
= PALETTE_AllocPaletteIndexedRGB(NumColors
, pb
->ColorMap
);
1980 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, 0, NULL
,
1981 pb
->dib
->dsBitfields
[0],
1982 pb
->dib
->dsBitfields
[1],
1983 pb
->dib
->dsBitfields
[2]);
1988 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
1989 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1992 /* Reselect brush and pen to regenerate the XLATEOBJs. */
1993 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
1994 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
1996 DC_UnlockDc ( hDC
);
1997 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
1998 BITMAPOBJ_UnlockBitmap( hGDIObj
);
1999 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
2000 NtGdiDeleteObject ( hVisRgn
);
2004 case GDI_OBJECT_TYPE_REGION
:
2007 * The return value is one of the following values:
2012 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
2022 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
2025 DC
*dc
= DC_LockDc(hDC
);
2029 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2033 wRet
= dc
->w
.flags
& DC_DIRTY
;
2035 /* "Undocumented Windows" info is slightly confusing.
2038 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
2040 if (Flags
& DCHF_INVALIDATEVISRGN
)
2042 dc
->w
.flags
|= DC_DIRTY
;
2044 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
2046 dc
->w
.flags
&= ~DC_DIRTY
;
2054 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
2055 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
2056 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
2057 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
2058 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
2060 // ---------------------------------------------------- Private Interface
2063 DC_AllocDC(PUNICODE_STRING Driver
)
2071 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
2076 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
2079 hDC
= (HDC
) GDIOBJ_AllocObj(GDI_OBJECT_TYPE_DC
);
2089 NewDC
= DC_LockDc(hDC
);
2090 /* FIXME - Handle NewDC == NULL! */
2094 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2095 NewDC
->DriverName
.Buffer
= Buf
;
2098 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2099 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2100 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2101 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2102 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2103 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2104 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2105 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2106 NewDC
->w
.vport2WorldValid
= TRUE
;
2107 NewDC
->w
.MapMode
= MM_TEXT
;
2108 NewDC
->wndExtX
= 1.0f
;
2109 NewDC
->wndExtY
= 1.0f
;
2110 NewDC
->vportExtX
= 1.0f
;
2111 NewDC
->vportExtY
= 1.0f
;
2112 NewDC
->w
.textColor
= 0;
2113 NewDC
->w
.backgroundColor
= 0xffffff;
2115 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2116 TextIntRealizeFont(NewDC
->w
.hFont
);
2118 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2126 DC_FindOpenDC(PUNICODE_STRING Driver
)
2132 * Initialize some common fields in the Device Context structure.
2135 DC_InitDC(HDC DCHandle
)
2137 // NtGdiRealizeDefaultPalette(DCHandle);
2139 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2140 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2141 //NtGdiSelectObject(DCHandle, hFont);
2146 res = CLIPPING_UpdateGCRegion(DCToInit);
2147 ASSERT ( res != ERROR );
2153 DC_FreeDC(HDC DCToFree
)
2155 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
))
2157 DPRINT("DC_FreeDC failed\n");
2162 DC_Cleanup(PVOID ObjectBody
)
2164 PDC pDC
= (PDC
)ObjectBody
;
2165 RtlFreeUnicodeString(&pDC
->DriverName
);
2170 DC_GetNextDC (PDC pDC
)
2176 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2178 pDC
->hNext
= hNextDC
;
2182 DC_UpdateXforms(PDC dc
)
2184 XFORM xformWnd2Vport
;
2185 FLOAT scaleX
, scaleY
;
2187 /* Construct a transformation to do the window-to-viewport conversion */
2188 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2189 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2190 xformWnd2Vport
.eM11
= scaleX
;
2191 xformWnd2Vport
.eM12
= 0.0;
2192 xformWnd2Vport
.eM21
= 0.0;
2193 xformWnd2Vport
.eM22
= scaleY
;
2194 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2195 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2197 /* Combine with the world transformation */
2198 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2200 /* Create inverse of world-to-viewport transformation */
2201 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2205 DC_InvertXform(const XFORM
*xformSrc
,
2210 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2211 if (determinant
> -1e-12 && determinant
< 1e-12)
2216 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2217 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2218 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2219 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2220 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2221 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2227 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2231 GDIOBJ_SetOwnership(hDC
, Owner
);
2232 DC
= DC_LockDc(hDC
);
2235 if (NULL
!= DC
->w
.hClipRgn
)
2237 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2239 if (NULL
!= DC
->w
.hVisRgn
)
2241 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2243 if (NULL
!= DC
->w
.hGCClipRgn
)
2245 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2252 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2254 if (PrimarySurface
.Handle
== NULL
)
2258 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2262 * Returns the color of the brush or pen that is currently selected into the DC.
2263 * This function is called from GetDCBrushColor() and GetDCPenColor()
2266 IntGetDCColor(HDC hDC
, ULONG Object
)
2269 * The previous implementation was completly incorrect. It modified the
2270 * brush that was currently selected into the device context, but in fact
2271 * the DC pen/brush color should be stored directly in the device context
2272 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2273 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2274 * into the device context and BRUSHOBJ for drawing is composed (belongs
2275 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2276 * the implementation should be moved to user mode GDI32.dll when UM
2277 * mapped GDI objects will be implemented.
2280 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2281 return 0xFFFFFF; /* The default DC color. */
2285 * Changes the color of the brush or pen that is currently selected into the DC.
2286 * This function is called from SetDCBrushColor() and SetDCPenColor()
2289 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2291 /* See the comment in IntGetDCColor. */
2293 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2297 #define SIZEOF_DEVMODEW_300 188
2298 #define SIZEOF_DEVMODEW_400 212
2299 #define SIZEOF_DEVMODEW_500 220
2301 /*! \brief Enumerate possible display settings for the given display...
2303 * \todo Make thread safe!?
2304 * \todo Don't ignore lpszDeviceName
2305 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2308 IntEnumDisplaySettings(
2309 PUNICODE_STRING lpszDeviceName
,
2311 LPDEVMODEW lpDevMode
,
2314 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2315 static DWORD SizeOfCachedDevModes
= 0;
2316 LPDEVMODEW CachedMode
= NULL
;
2319 ULONG DisplayNumber
= 0; /* only default display supported */
2321 if (lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2322 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2323 lpDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2325 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2329 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2331 CachedMode
= &PrimarySurface
.DMW
;
2332 assert(CachedMode
->dmSize
> 0);
2334 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2336 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2337 DevMode
.dmSize
= sizeof (DevMode
);
2338 DevMode
.dmDriverExtra
= 0;
2339 if (SetupDevMode(&DevMode
, DisplayNumber
))
2340 CachedMode
= &DevMode
;
2343 SetLastWin32Error(0); /* FIXME: use error code */
2346 /* FIXME: Maybe look for the matching devmode supplied by the
2347 * driver so we can provide driver private/extra data?
2352 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2354 BOOL PrimarySurfaceCreated
= FALSE
;
2355 UNICODE_STRING DriverFileNames
;
2357 DRVENABLEDATA DrvEnableData
;
2359 /* Retrieve DDI driver names from registry */
2360 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2361 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2363 DPRINT1("FindDriverFileNames failed\n");
2367 if (!HalQueryDisplayOwnership())
2369 IntCreatePrimarySurface();
2370 PrimarySurfaceCreated
= TRUE
;
2374 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2375 * scan all of them until a good one found.
2377 CurrentName
= DriverFileNames
.Buffer
;
2378 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2379 CurrentName
+= wcslen(CurrentName
) + 1)
2382 PGD_ENABLEDRIVER GDEnableDriver
;
2384 /* Get the DDI driver's entry point */
2385 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2386 if (NULL
== GDEnableDriver
)
2388 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2392 /* Call DDI driver's EnableDriver function */
2393 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2395 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2397 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2401 CachedDevModesEnd
= CachedDevModes
;
2403 /* find DrvGetModes function */
2404 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2406 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2407 PGD_GETMODES GetModes
;
2408 INT SizeNeeded
, SizeUsed
;
2410 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2413 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2415 /* make sure we have enough memory to hold the modes */
2416 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2417 if (SizeNeeded
<= 0)
2419 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2423 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2424 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2428 SizeOfCachedDevModes
+= SizeNeeded
;
2429 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2430 if (NewBuffer
== NULL
)
2433 ExFreePool(CachedDevModes
);
2434 SizeOfCachedDevModes
= 0;
2435 CachedDevModes
= NULL
;
2436 CachedDevModesEnd
= NULL
;
2437 if (PrimarySurfaceCreated
)
2439 IntDestroyPrimarySurface();
2441 SetLastWin32Error(STATUS_NO_MEMORY
);
2444 if (CachedDevModes
!= NULL
)
2446 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2447 ExFreePool(CachedDevModes
);
2449 CachedDevModes
= NewBuffer
;
2450 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2454 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2455 SizeOfCachedDevModes
- SizeUsed
,
2457 if (SizeNeeded
<= 0)
2459 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2463 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2469 if (PrimarySurfaceCreated
)
2471 IntDestroyPrimarySurface();
2474 RtlFreeUnicodeString(&DriverFileNames
);
2477 /* return cached info */
2478 CachedMode
= CachedDevModes
;
2479 if (CachedMode
>= CachedDevModesEnd
)
2481 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2484 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2486 assert(CachedMode
->dmSize
> 0);
2487 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2489 if (CachedMode
>= CachedDevModesEnd
)
2491 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2496 assert(CachedMode
!= NULL
);
2498 Size
= OldSize
= lpDevMode
->dmSize
;
2499 if (Size
> CachedMode
->dmSize
)
2500 Size
= CachedMode
->dmSize
;
2501 RtlCopyMemory(lpDevMode
, CachedMode
, Size
);
2502 RtlZeroMemory((PCHAR
)lpDevMode
+ Size
, OldSize
- Size
);
2503 lpDevMode
->dmSize
= OldSize
;
2505 Size
= OldSize
= lpDevMode
->dmDriverExtra
;
2506 if (Size
> CachedMode
->dmDriverExtra
)
2507 Size
= CachedMode
->dmDriverExtra
;
2508 RtlCopyMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
,
2509 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2510 RtlZeroMemory((PCHAR
)lpDevMode
+ lpDevMode
->dmSize
+ Size
, OldSize
- Size
);
2511 lpDevMode
->dmDriverExtra
= OldSize
;