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
30 #ifndef OBJ_COLORSPACE
31 #define OBJ_COLORSPACE (14)
34 static GDIDEVICE PrimarySurface
;
36 /* FIXME: DCs should probably be thread safe */
39 * DC device-independent Get/SetXXX functions
40 * (RJJ) swiped from WINE
43 #define DC_GET_VAL( func_type, func_name, dc_field ) \
44 func_type STDCALL func_name( HDC hdc ) \
47 PDC dc = DC_LockDc( hdc ); \
50 SetLastWin32Error(ERROR_INVALID_HANDLE); \
58 /* DC_GET_VAL_EX is used to define functions returning a POINT or a SIZE. It is
59 * important that the function has the right signature, for the implementation
60 * we can do whatever we want.
62 #define DC_GET_VAL_EX( FuncName, ret_x, ret_y, type, ax, ay ) \
63 VOID FASTCALL Int##FuncName ( PDC dc, LP##type pt) \
70 BOOL STDCALL NtGdi##FuncName ( HDC hdc, LP##type pt ) \
72 NTSTATUS Status = STATUS_SUCCESS; \
77 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
80 if(!(dc = DC_LockDc(hdc))) \
82 SetLastWin32Error(ERROR_INVALID_HANDLE); \
85 Int##FuncName( dc, &Safept); \
96 Status = _SEH_GetExceptionCode(); \
99 if(!NT_SUCCESS(Status)) \
101 SetLastNtError(Status); \
107 #define DC_SET_MODE( func_name, dc_field, min_val, max_val ) \
108 INT STDCALL func_name( HDC hdc, INT mode ) \
112 if ((mode < min_val) || (mode > max_val)) \
114 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
117 dc = DC_LockDc ( hdc ); \
120 SetLastWin32Error(ERROR_INVALID_HANDLE); \
123 prevMode = dc->dc_field; \
124 dc->dc_field = mode; \
125 DC_UnlockDc ( dc ); \
130 // --------------------------------------------------------- File Statics
132 // ----------------------------------------------------- Public Functions
135 NtGdiCancelDC(HDC hDC
)
142 NtGdiCreateCompatibleDC(HDC hDC
)
146 HDC hNewDC
, DisplayDC
;
148 UNICODE_STRING DriverName
;
153 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
154 DisplayDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, TRUE
);
155 if (NULL
== DisplayDC
)
162 /* Allocate a new DC based on the original DC's device */
163 OrigDC
= DC_LockDc(hDC
);
166 if (NULL
!= DisplayDC
)
168 NtGdiDeleteDC(DisplayDC
);
172 hNewDC
= DC_AllocDC(&OrigDC
->DriverName
);
177 if (NULL
!= DisplayDC
)
179 NtGdiDeleteDC(DisplayDC
);
183 NewDC
= DC_LockDc( hNewDC
);
185 /* Copy information from original DC to new DC */
186 NewDC
->hSelf
= hNewDC
;
189 NewDC
->PDev
= OrigDC
->PDev
;
190 memcpy(NewDC
->FillPatternSurfaces
,
191 OrigDC
->FillPatternSurfaces
,
192 sizeof OrigDC
->FillPatternSurfaces
);
193 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
194 NewDC
->DevInfo
= OrigDC
->DevInfo
;
195 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
197 /* DriverName is copied in the AllocDC routine */
198 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
199 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
200 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
201 NewDC
->wndExtX
= OrigDC
->wndExtX
;
202 NewDC
->wndExtY
= OrigDC
->wndExtY
;
203 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
204 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
205 NewDC
->vportExtX
= OrigDC
->vportExtX
;
206 NewDC
->vportExtY
= OrigDC
->vportExtY
;
208 /* Create default bitmap */
209 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
211 DC_UnlockDc( OrigDC
);
212 DC_UnlockDc( NewDC
);
214 if (NULL
!= DisplayDC
)
216 NtGdiDeleteDC(DisplayDC
);
220 NewDC
->w
.flags
= DC_MEMORY
;
221 NewDC
->w
.hBitmap
= hBitmap
;
222 NewDC
->w
.hFirstBitmap
= hBitmap
;
223 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
225 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
226 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
227 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
228 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
229 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
230 NewDC
->w
.ROPmode
= OrigDC
->w
.ROPmode
;
233 if (NULL
!= DisplayDC
)
235 NtGdiDeleteDC(DisplayDC
);
238 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
239 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
240 NtGdiDeleteObject(hVisRgn
);
248 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
250 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
251 WCHAR DeviceNameBuffer
[20];
254 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
255 RtlInitUnicodeString(RegistryPath
, NULL
);
256 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
257 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
258 QueryTable
[0].Name
= DeviceNameBuffer
;
259 QueryTable
[0].EntryContext
= RegistryPath
;
261 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
266 if (! NT_SUCCESS(Status
))
268 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
272 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
278 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
280 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
281 UNICODE_STRING RegistryPath
;
284 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
286 DPRINT("GetRegistryPath failed\n");
290 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
291 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
292 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
293 QueryTable
[0].EntryContext
= DriverFileNames
;
295 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
300 RtlFreeUnicodeString(&RegistryPath
);
301 if (! NT_SUCCESS(Status
))
303 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
307 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
312 static NTSTATUS STDCALL
313 DevModeCallback(IN PWSTR ValueName
,
316 IN ULONG ValueLength
,
318 IN PVOID EntryContext
)
320 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
322 DPRINT("Found registry value for name %S: type %d, length %d\n",
323 ValueName
, ValueType
, ValueLength
);
325 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
327 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
329 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
331 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
333 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
335 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
337 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
339 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
341 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
343 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
345 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
347 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
349 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
351 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
353 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
357 return STATUS_SUCCESS
;
361 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
363 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
364 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
365 static WCHAR ControlSet
[] = L
"CONTROLSET";
366 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
367 UNICODE_STRING RegistryPath
;
369 PWCHAR AfterControlSet
;
371 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
374 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
376 DPRINT("GetRegistryPath failed\n");
380 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
381 wcslen(RegistryMachineSystem
)));
384 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
385 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
387 AfterControlSet
+= wcslen(CurrentControlSet
);
389 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
391 AfterControlSet
+= wcslen(ControlSet
);
392 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
396 Valid
= (L
'\\' == *AfterControlSet
);
407 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
408 (wcslen(RegistryPath
.Buffer
) +
409 wcslen(Insert
) + 1) * sizeof(WCHAR
),
411 if (NULL
!= ProfilePath
)
413 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
414 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
415 wcscat(ProfilePath
, AfterControlSet
);
417 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
418 QueryTable
[0].QueryRoutine
= DevModeCallback
;
419 QueryTable
[0].Flags
= 0;
420 QueryTable
[0].Name
= NULL
;
421 QueryTable
[0].EntryContext
= NULL
;
422 QueryTable
[0].DefaultType
= REG_NONE
;
423 QueryTable
[0].DefaultData
= NULL
;
424 QueryTable
[0].DefaultLength
= 0;
426 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
431 if (! NT_SUCCESS(Status
))
433 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
434 ProfilePath
, Status
);
439 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
440 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
441 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
442 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
443 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
445 DPRINT("Not all required devmode members are set\n");
450 ExFreePool(ProfilePath
);
459 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
462 RtlFreeUnicodeString(&RegistryPath
);
466 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
475 PGD_ENABLEDRIVER GDEnableDriver
;
477 UNICODE_STRING DriverFileNames
;
483 for (DisplayNumber
= 0; ; DisplayNumber
++)
485 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
487 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
489 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
491 /* Open the miniport driver */
492 if (PrimarySurface
.VideoFileObject
== NULL
)
494 DPRINT1("FindMPDriver failed\n");
498 /* Retrieve DDI driver names from registry */
499 RtlInitUnicodeString(&DriverFileNames
, NULL
);
500 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
502 DPRINT1("FindDriverFileNames failed\n");
507 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
508 * scan all of them until a good one found.
510 CurrentName
= DriverFileNames
.Buffer
;
513 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
515 /* Get the DDI driver's entry point */
516 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
517 if (NULL
== GDEnableDriver
)
519 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
523 /* Call DDI driver's EnableDriver function */
524 RtlZeroMemory(&DED
, sizeof(DED
));
526 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
528 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
538 /* Skip to the next name but never get past the Unicode string */
539 while (L
'\0' != *CurrentName
&&
540 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
544 if (CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
551 RtlFreeUnicodeString(&DriverFileNames
);
555 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
556 DPRINT1("No suitable DDI driver found\n");
560 DPRINT("Display driver %S loaded\n", CurrentName
);
562 DPRINT("Building DDI Functions\n");
564 /* Construct DDI driver function dispatch table */
565 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
567 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
568 DPRINT1("BuildDDIFunctions failed\n");
572 /* Allocate a phyical device handle from the driver */
573 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
574 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
576 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
580 PrimarySurface
.FillPatterns
,
581 sizeof(PrimarySurface
.GDIInfo
),
582 (ULONG
*) &PrimarySurface
.GDIInfo
,
583 sizeof(PrimarySurface
.DevInfo
),
584 &PrimarySurface
.DevInfo
,
587 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
588 DoDefault
= (NULL
== PrimarySurface
.PDev
);
591 DPRINT1("DrvEnablePDev with registry parameters failed\n");
601 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
602 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
603 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
607 PrimarySurface
.FillPatterns
,
608 sizeof(PrimarySurface
.GDIInfo
),
609 (ULONG
*) &PrimarySurface
.GDIInfo
,
610 sizeof(PrimarySurface
.DevInfo
),
611 &PrimarySurface
.DevInfo
,
614 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
616 if (NULL
== PrimarySurface
.PDev
)
618 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
619 DPRINT1("DrvEnablePDEV with default parameters failed\n");
620 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
625 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
627 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
628 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
630 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
632 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
633 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
636 PrimarySurface
.Pointer
.Exclude
.right
= -1;
638 DPRINT("calling completePDev\n");
640 /* Complete initialization of the physical device */
641 PrimarySurface
.DriverFunctions
.CompletePDEV(
643 (HDEV
)&PrimarySurface
);
645 DPRINT("calling DRIVER_ReferenceDriver\n");
647 DRIVER_ReferenceDriver(L
"DISPLAY");
649 PrimarySurface
.PreparedDriver
= TRUE
;
650 PrimarySurface
.DisplayNumber
= DisplayNumber
;
659 IntPrepareDriverIfNeeded()
661 return (PrimarySurface
.PreparedDriver
? TRUE
: IntPrepareDriver());
669 IO_STATUS_BLOCK Iosb
;
671 ULONG Length
= sizeof(BOOL
);
672 PIO_STACK_LOCATION StackPtr
;
673 LARGE_INTEGER StartOffset
;
674 PFILE_OBJECT FileObject
= PrimarySurface
.VideoFileObject
;
675 PDEVICE_OBJECT DeviceObject
= FileObject
->DeviceObject
;
677 DPRINT("PrepareVideoPrt() called\n");
679 KeClearEvent(&PrimarySurface
.VideoFileObject
->Event
);
681 ObReferenceObjectByPointer(FileObject
, 0, IoFileObjectType
, KernelMode
);
683 StartOffset
.QuadPart
= 0;
684 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
,
696 /* Set up IRP Data */
697 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
698 Irp
->RequestorMode
= KernelMode
;
699 Irp
->Overlay
.AsynchronousParameters
.UserApcRoutine
= NULL
;
700 Irp
->Overlay
.AsynchronousParameters
.UserApcContext
= NULL
;
701 Irp
->Flags
|= IRP_WRITE_OPERATION
;
703 /* Setup Stack Data */
704 StackPtr
= IoGetNextIrpStackLocation(Irp
);
705 StackPtr
->FileObject
= PrimarySurface
.VideoFileObject
;
706 StackPtr
->Parameters
.Write
.Key
= 0;
708 Status
= IoCallDriver(DeviceObject
, Irp
);
710 if (STATUS_PENDING
== Status
)
712 KeWaitForSingleObject(&FileObject
->Event
, Executive
, KernelMode
, TRUE
, 0);
713 Status
= Iosb
.Status
;
716 return NT_SUCCESS(Status
);
720 IntCreatePrimarySurface()
727 if (! IntPrepareDriverIfNeeded())
732 if (! PrepareVideoPrt())
737 DPRINT("calling EnableSurface\n");
738 /* Enable the drawing surface */
739 PrimarySurface
.Handle
=
740 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
741 if (NULL
== PrimarySurface
.Handle
)
743 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
744 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
745 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
746 DPRINT1("DrvEnableSurface failed\n");
750 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, TRUE
);
752 calledFromUser
= UserIsEntered(); //fixme: possibly upgrade a shared lock
753 if (!calledFromUser
){
754 UserEnterExclusive();
758 IntAttachMonitor(&PrimarySurface
, PrimarySurface
.DisplayNumber
);
760 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
761 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
762 SurfSize
= SurfObj
->sizlBitmap
;
763 SurfaceRect
.left
= SurfaceRect
.top
= 0;
764 SurfaceRect
.right
= SurfObj
->sizlBitmap
.cx
;
765 SurfaceRect
.bottom
= SurfObj
->sizlBitmap
.cy
;
766 /* FIXME - why does EngEraseSurface() sometimes crash?
767 EngEraseSurface(SurfObj, &SurfaceRect, 0); */
769 /* Put the pointer in the center of the screen */
770 GDIDEV(SurfObj
)->Pointer
.Pos
.x
= (SurfaceRect
.right
- SurfaceRect
.left
) / 2;
771 GDIDEV(SurfObj
)->Pointer
.Pos
.y
= (SurfaceRect
.bottom
- SurfaceRect
.top
) / 2;
773 EngUnlockSurface(SurfObj
);
774 co_IntShowDesktop(IntGetActiveDesktop(), SurfSize
.cx
, SurfSize
.cy
);
776 if (!calledFromUser
){
784 IntDestroyPrimarySurface()
788 DRIVER_UnreferenceDriver(L
"DISPLAY");
790 calledFromUser
= UserIsEntered();
791 if (!calledFromUser
){
792 UserEnterExclusive();
796 IntDetachMonitor(&PrimarySurface
);
798 if (!calledFromUser
){
803 * FIXME: Hide a mouse pointer there. Also because we have to prevent
804 * memory leaks with the Eng* mouse routines.
807 DPRINT("Reseting display\n" );
808 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
809 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
810 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
811 PrimarySurface
.PreparedDriver
= FALSE
;
815 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
819 IntGdiCreateDC(PUNICODE_STRING Driver
,
820 PUNICODE_STRING Device
,
821 PUNICODE_STRING Output
,
822 CONST PDEVMODEW InitData
,
829 UNICODE_STRING StdDriver
;
832 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
834 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
838 if (! IntPrepareDriverIfNeeded())
840 DPRINT1("Unable to prepare graphics driver, returning NULL ic\n");
846 calledFromUser
= UserIsEntered();
847 if (!calledFromUser
){
848 UserEnterExclusive();
851 if (! co_IntGraphicsCheck(TRUE
))
853 if (!calledFromUser
){
856 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
860 if (!calledFromUser
){
867 /* Check for existing DC object */
868 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
871 return NtGdiCreateCompatibleDC(hDC
);
874 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
876 DPRINT("NAME: %wZ\n", Driver
); // FIXME: Should not crash if NULL
879 /* Allocate a DC object */
880 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
885 NewDC
= DC_LockDc( hNewDC
);
886 /* FIXME - NewDC can be NULL!!! Don't assert here! */
893 NewDC
->IsIC
= CreateAsIC
;
894 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
895 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
896 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
897 sizeof(NewDC
->FillPatternSurfaces
));
898 NewDC
->PDev
= PrimarySurface
.PDev
;
899 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
900 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
901 NewDC
->w
.hBitmap
= PrimarySurface
.Handle
;
903 NewDC
->w
.bitsPerPixel
= NewDC
->GDIInfo
->cBitsPixel
* NewDC
->GDIInfo
->cPlanes
;
904 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
908 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
909 NewDC
->w
.ROPmode
= R2_COPYPEN
;
911 DC_UnlockDc( NewDC
);
913 hVisRgn
= NtGdiCreateRectRgn(0, 0, NewDC
->GDIInfo
->ulHorzRes
,
914 NewDC
->GDIInfo
->ulVertRes
);
915 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
916 NtGdiDeleteObject(hVisRgn
);
918 /* Initialize the DC state */
920 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
921 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
922 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
923 NtGdiSetBkMode(hNewDC
, OPAQUE
);
927 DC_UnlockDc( NewDC
);
934 NtGdiCreateDC(PUNICODE_STRING Driver
,
935 PUNICODE_STRING Device
,
936 PUNICODE_STRING Output
,
937 CONST PDEVMODEW InitData
)
939 UNICODE_STRING SafeDriver
, SafeDevice
;
940 DEVMODEW SafeInitData
;
942 NTSTATUS Status
= STATUS_SUCCESS
;
948 ProbeForRead(InitData
,
951 RtlCopyMemory(&SafeInitData
,
957 Status
= _SEH_GetExceptionCode();
961 if(!NT_SUCCESS(Status
))
963 SetLastNtError(Status
);
966 /* FIXME - InitData can have some more bytes! */
971 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
972 if(!NT_SUCCESS(Status
))
974 SetLastNtError(Status
);
981 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
982 if(!NT_SUCCESS(Status
))
984 RtlFreeUnicodeString(&SafeDriver
);
985 SetLastNtError(Status
);
990 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
991 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
992 NULL
== InitData
? NULL
: &SafeInitData
, FLASE
);
998 NtGdiCreateIC(PUNICODE_STRING Driver
,
999 PUNICODE_STRING Device
,
1000 PUNICODE_STRING Output
,
1001 CONST PDEVMODEW InitData
)
1003 UNICODE_STRING SafeDriver
, SafeDevice
;
1004 DEVMODEW SafeInitData
;
1006 NTSTATUS Status
= STATUS_SUCCESS
;
1012 ProbeForRead(InitData
,
1015 RtlCopyMemory(&SafeInitData
,
1021 Status
= _SEH_GetExceptionCode();
1024 if(!NT_SUCCESS(Status
))
1026 SetLastNtError(Status
);
1029 /* FIXME - InitData can have some more bytes! */
1034 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
1035 if(!NT_SUCCESS(Status
))
1037 SetLastNtError(Status
);
1044 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
1045 if(!NT_SUCCESS(Status
))
1047 RtlFreeUnicodeString(&SafeDriver
);
1048 SetLastNtError(Status
);
1053 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
1054 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
1055 NULL
== InitData
? NULL
: &SafeInitData
, TRUE
);
1061 NtGdiDeleteDC(HDC DCHandle
)
1065 if (!GDIOBJ_OwnedByCurrentProcess(DCHandle
))
1067 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1071 DCToDelete
= DC_LockDc(DCHandle
);
1072 if (DCToDelete
== NULL
)
1074 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1078 /* First delete all saved DCs */
1079 while (DCToDelete
->saveLevel
)
1084 savedHDC
= DC_GetNextDC (DCToDelete
);
1085 savedDC
= DC_LockDc (savedHDC
);
1086 if (savedDC
== NULL
)
1090 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
1091 DCToDelete
->saveLevel
--;
1092 DC_UnlockDc( savedDC
);
1093 NtGdiDeleteDC (savedHDC
);
1096 /* Free GDI resources allocated to this DC */
1097 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
1100 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
1101 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
1102 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
1103 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
1104 if (DCToDelete
->w
.flags
& DC_MEMORY
)
1106 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
1108 if (DCToDelete
->XlateBrush
!= NULL
)
1109 EngDeleteXlate(DCToDelete
->XlateBrush
);
1110 if (DCToDelete
->XlatePen
!= NULL
)
1111 EngDeleteXlate(DCToDelete
->XlatePen
);
1113 if (DCToDelete
->w
.hClipRgn
)
1115 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
1117 if (DCToDelete
->w
.hVisRgn
)
1119 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
1121 if (NULL
!= DCToDelete
->CombinedClip
)
1123 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
1125 if (DCToDelete
->w
.hGCClipRgn
)
1127 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
1130 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
1132 DC_UnlockDc( DCToDelete
);
1133 DC_FreeDC ( DCHandle
);
1139 NtGdiDrawEscape(HDC hDC
,
1149 NtGdiEnumObjects(HDC hDC
,
1151 GOBJENUMPROC ObjectFunc
,
1158 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
1159 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
1160 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
1161 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
1164 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
1169 if(!(dc
= DC_LockDc(hDC
)))
1171 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1178 SelObject
= dc
->w
.hPen
;
1181 SelObject
= dc
->w
.hBrush
;
1184 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
1188 SelObject
= dc
->w
.hFont
;
1191 SelObject
= dc
->w
.hBitmap
;
1193 case OBJ_COLORSPACE
:
1194 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
1199 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1207 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
1210 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
1212 Point
->x
= dc
->w
.DCOrgX
;
1213 Point
->y
= dc
->w
.DCOrgY
;
1219 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1224 NTSTATUS Status
= STATUS_SUCCESS
;
1228 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1232 dc
= DC_LockDc(hDC
);
1235 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1239 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1243 ProbeForWrite(Point
,
1250 Status
= _SEH_GetExceptionCode();
1254 if(!NT_SUCCESS(Status
))
1256 SetLastNtError(Status
);
1266 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1272 if (!(dc
= DC_LockDc(hDC
)))
1274 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1278 oldColor
= dc
->w
.backgroundColor
;
1279 dc
->w
.backgroundColor
= color
;
1280 hBrush
= dc
->w
.hBrush
;
1282 NtGdiSelectObject(hDC
, hBrush
);
1287 NtGdiGetDCState(HDC hDC
)
1292 dc
= DC_LockDc(hDC
);
1295 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1299 hnewdc
= DC_AllocDC(NULL
);
1305 newdc
= DC_LockDc( hnewdc
);
1306 /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
1309 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1310 newdc
->w
.hPen
= dc
->w
.hPen
;
1311 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1312 newdc
->w
.hFont
= dc
->w
.hFont
;
1313 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1314 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1316 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1318 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1319 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1320 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1321 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1322 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1323 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1324 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1325 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1326 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1327 newdc
->w
.textColor
= dc
->w
.textColor
;
1328 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1329 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1330 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1331 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1332 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1333 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1334 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1335 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1336 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1337 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1339 /* Apparently, the DC origin is not changed by [GS]etDCState */
1340 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1341 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1343 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1344 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1345 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1346 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1347 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1348 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1349 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1350 newdc
->wndOrgX
= dc
->wndOrgX
;
1351 newdc
->wndOrgY
= dc
->wndOrgY
;
1352 newdc
->wndExtX
= dc
->wndExtX
;
1353 newdc
->wndExtY
= dc
->wndExtY
;
1354 newdc
->vportOrgX
= dc
->vportOrgX
;
1355 newdc
->vportOrgY
= dc
->vportOrgY
;
1356 newdc
->vportExtX
= dc
->vportExtX
;
1357 newdc
->vportExtY
= dc
->vportExtY
;
1359 newdc
->hSelf
= hnewdc
;
1360 newdc
->saveLevel
= 0;
1361 newdc
->IsIC
= dc
->IsIC
;
1364 PATH_InitGdiPath( &newdc
->w
.path
);
1367 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1369 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1372 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1373 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1375 DC_UnlockDc( newdc
);
1383 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1387 dc
= DC_LockDc ( hDC
);
1390 dcs
= DC_LockDc ( hDCSave
);
1393 if ( dcs
->w
.flags
& DC_SAVED
)
1395 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1397 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1400 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1403 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1404 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1405 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1406 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1407 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1408 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1409 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1410 dc
->w
.textColor
= dcs
->w
.textColor
;
1411 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1412 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1413 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1414 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1415 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1416 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1417 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1418 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1419 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1420 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1422 /* Apparently, the DC origin is not changed by [GS]etDCState */
1423 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1424 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1426 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1427 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1428 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1430 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1431 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1432 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1433 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1435 dc
->wndOrgX
= dcs
->wndOrgX
;
1436 dc
->wndOrgY
= dcs
->wndOrgY
;
1437 dc
->wndExtX
= dcs
->wndExtX
;
1438 dc
->wndExtY
= dcs
->wndExtY
;
1439 dc
->vportOrgX
= dcs
->vportOrgX
;
1440 dc
->vportOrgY
= dcs
->vportOrgY
;
1441 dc
->vportExtX
= dcs
->vportExtX
;
1442 dc
->vportExtY
= dcs
->vportExtY
;
1444 if (!(dc
->w
.flags
& DC_MEMORY
))
1446 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1450 if (dcs
->w
.hClipRgn
)
1452 if (!dc
->w
.hClipRgn
)
1454 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1456 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1462 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1469 res
= CLIPPING_UpdateGCRegion( dc
);
1470 ASSERT ( res
!= ERROR
);
1475 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1478 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1479 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1480 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1481 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1482 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1483 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1485 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1488 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1493 DC_UnlockDc ( dcs
);
1496 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1500 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1504 IntGdiGetDeviceCaps(PDC dc
, INT Index
)
1509 /* Retrieve capability */
1513 ret
= dc
->GDIInfo
->ulVersion
;
1517 ret
= dc
->GDIInfo
->ulTechnology
;
1521 ret
= dc
->GDIInfo
->ulHorzSize
;
1525 ret
= dc
->GDIInfo
->ulVertSize
;
1529 ret
= dc
->GDIInfo
->ulHorzRes
;
1533 ret
= dc
->GDIInfo
->ulVertRes
;
1537 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1541 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1545 ret
= dc
->GDIInfo
->cBitsPixel
;
1549 ret
= dc
->GDIInfo
->cPlanes
;
1553 UNIMPLEMENTED
; /* FIXME */
1557 UNIMPLEMENTED
; /* FIXME */
1561 UNIMPLEMENTED
; /* FIXME */
1565 ret
= dc
->GDIInfo
->ulNumColors
;
1569 ret
= dc
->GDIInfo
->ulAspectX
;
1573 ret
= dc
->GDIInfo
->ulAspectY
;
1577 ret
= dc
->GDIInfo
->ulAspectXY
;
1581 UNIMPLEMENTED
; /* FIXME */
1585 UNIMPLEMENTED
; /* FIXME */
1589 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1597 UNIMPLEMENTED
; /* FIXME */
1601 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1611 case PHYSICALHEIGHT
:
1612 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1622 case PHYSICALOFFSETX
:
1623 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1633 case PHYSICALOFFSETY
:
1634 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1645 UNIMPLEMENTED
; /* FIXME */
1648 case SCALINGFACTORX
:
1649 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1659 case SCALINGFACTORY
:
1660 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1671 ret
= dc
->GDIInfo
->flRaster
;
1675 UNIMPLEMENTED
; /* FIXME */
1679 UNIMPLEMENTED
; /* FIXME */
1683 UNIMPLEMENTED
; /* FIXME */
1687 ret
= dc
->GDIInfo
->flTextCaps
;
1699 NtGdiGetDeviceCaps(HDC hDC
,
1705 dc
= DC_LockDc(hDC
);
1708 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1712 ret
= IntGdiGetDeviceCaps(dc
, Index
);
1714 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1720 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1721 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1724 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1730 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1731 if (NULL
== GdiObject
)
1733 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1737 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1741 case GDI_OBJECT_TYPE_PEN
:
1742 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1744 case GDI_OBJECT_TYPE_BRUSH
:
1745 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1748 case GDI_OBJECT_TYPE_BITMAP
:
1749 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1751 case GDI_OBJECT_TYPE_FONT
:
1752 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1754 // Fix the LOGFONT structure for the stock fonts
1755 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1757 FixStockFontSizeW(Handle
, Count
, Buffer
);
1762 case GDI_OBJECT_TYPE_PALETTE
:
1763 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1767 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1771 GDIOBJ_UnlockObjByPtr(GdiObject
);
1777 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1781 NTSTATUS Status
= STATUS_SUCCESS
;
1790 ProbeForWrite(buffer
,
1796 Status
= _SEH_GetExceptionCode();
1800 if(!NT_SUCCESS(Status
))
1802 SetLastNtError(Status
);
1806 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1809 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1813 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1817 /* pointer already probed! */
1818 RtlCopyMemory(buffer
,
1824 Status
= _SEH_GetExceptionCode();
1828 ExFreePool(SafeBuf
);
1829 if(!NT_SUCCESS(Status
))
1831 SetLastNtError(Status
);
1839 NtGdiGetObjectType(HANDLE handle
)
1845 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1848 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1852 objectType
= GDIOBJ_GetObjectType(handle
);
1855 case GDI_OBJECT_TYPE_PEN
:
1858 case GDI_OBJECT_TYPE_BRUSH
:
1861 case GDI_OBJECT_TYPE_BITMAP
:
1862 result
= OBJ_BITMAP
;
1864 case GDI_OBJECT_TYPE_FONT
:
1867 case GDI_OBJECT_TYPE_PALETTE
:
1870 case GDI_OBJECT_TYPE_REGION
:
1871 result
= OBJ_REGION
;
1873 case GDI_OBJECT_TYPE_DC
:
1876 case GDI_OBJECT_TYPE_METADC
:
1877 result
= OBJ_METADC
;
1879 case GDI_OBJECT_TYPE_METAFILE
:
1880 result
= OBJ_METAFILE
;
1882 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1883 result
= OBJ_ENHMETAFILE
;
1885 case GDI_OBJECT_TYPE_ENHMETADC
:
1886 result
= OBJ_ENHMETADC
;
1888 case GDI_OBJECT_TYPE_EXTPEN
:
1889 result
= OBJ_EXTPEN
;
1891 case GDI_OBJECT_TYPE_MEMDC
:
1896 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1900 GDIOBJ_UnlockObjByPtr(ptr
);
1904 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1905 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1906 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1907 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1908 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1909 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1910 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1911 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1912 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1915 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1922 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1927 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1929 dc
= DC_LockDc(hDC
);
1932 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1936 if (SaveLevel
== -1)
1937 SaveLevel
= dc
->saveLevel
;
1939 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1946 while (dc
->saveLevel
>= SaveLevel
)
1948 HDC hdcs
= DC_GetNextDC (dc
);
1950 dcs
= DC_LockDc (hdcs
);
1956 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1957 if (--dc
->saveLevel
< SaveLevel
)
1961 NtGdiSetDCState(hDC
, hdcs
);
1963 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1965 /* FIXME: This might not be quite right, since we're
1966 * returning FALSE but still destroying the saved DC state */
1970 dc
= DC_LockDc(hDC
);
1980 NtGdiDeleteDC (hdcs
);
1987 NtGdiSaveDC(HDC hDC
)
1993 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1995 if (!(hdcs
= NtGdiGetDCState(hDC
)))
2000 dcs
= DC_LockDc (hdcs
);
2003 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2006 dc
= DC_LockDc (hDC
);
2010 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2015 /* Copy path. The reason why path saving / restoring is in SaveDC/
2016 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
2017 * functions are only in Win16 (which doesn't have paths) and that
2018 * SetDCState doesn't allow us to signal an error (which can happen
2019 * when copying paths).
2021 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
2023 NtGdiDeleteDC (hdcs
);
2028 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
2029 DC_SetNextDC (dc
, hdcs
);
2030 ret
= ++dc
->saveLevel
;
2039 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
2041 HGDIOBJ objOrg
= NULL
; // default to failure
2051 if(!hDC
|| !hGDIObj
) return NULL
;
2053 dc
= DC_LockDc(hDC
);
2056 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2060 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
2064 case GDI_OBJECT_TYPE_PEN
:
2065 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
2068 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2072 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
2073 PENOBJ_UnlockPen(pen
);
2076 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2080 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
2081 dc
->w
.hPen
= hGDIObj
;
2082 if (dc
->XlatePen
!= NULL
)
2083 EngDeleteXlate(dc
->XlatePen
);
2084 dc
->XlatePen
= XlateObj
;
2087 case GDI_OBJECT_TYPE_BRUSH
:
2088 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
2091 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2095 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
2096 BRUSHOBJ_UnlockBrush(brush
);
2099 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2103 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
2104 dc
->w
.hBrush
= hGDIObj
;
2105 if (dc
->XlateBrush
!= NULL
)
2106 EngDeleteXlate(dc
->XlateBrush
);
2107 dc
->XlateBrush
= XlateObj
;
2110 case GDI_OBJECT_TYPE_FONT
:
2111 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
2113 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
2114 dc
->w
.hFont
= (HFONT
) hGDIObj
;
2118 case GDI_OBJECT_TYPE_BITMAP
:
2119 // must be memory dc to select bitmap
2120 if (!(dc
->w
.flags
& DC_MEMORY
))
2125 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
2128 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2132 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
2134 /* Release the old bitmap, lock the new one and convert it to a SURF */
2135 dc
->w
.hBitmap
= hGDIObj
;
2137 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
2140 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
2141 dc
->w
.hPalette
= pb
->hDIBPalette
;
2145 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
2146 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
2149 /* Reselect brush and pen to regenerate the XLATEOBJs. */
2150 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
2151 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
2154 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
2155 BITMAPOBJ_UnlockBitmap( pb
);
2156 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
2157 NtGdiDeleteObject ( hVisRgn
);
2161 case GDI_OBJECT_TYPE_REGION
:
2164 * The return value is one of the following values:
2169 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
2179 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
2182 DC
*dc
= DC_LockDc(hDC
);
2186 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2190 wRet
= dc
->w
.flags
& DC_DIRTY
;
2192 /* "Undocumented Windows" info is slightly confusing.
2195 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
2197 if (Flags
& DCHF_INVALIDATEVISRGN
)
2199 dc
->w
.flags
|= DC_DIRTY
;
2201 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
2203 dc
->w
.flags
&= ~DC_DIRTY
;
2211 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
2212 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
2213 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
2214 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
2215 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
2217 // ---------------------------------------------------- Private Interface
2220 DC_AllocDC(PUNICODE_STRING Driver
)
2228 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
2233 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
2236 hDC
= (HDC
) GDIOBJ_AllocObj(GDI_OBJECT_TYPE_DC
);
2246 NewDC
= DC_LockDc(hDC
);
2247 /* FIXME - Handle NewDC == NULL! */
2251 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2252 NewDC
->DriverName
.Buffer
= Buf
;
2255 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2256 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2257 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2258 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2259 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2260 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2261 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2262 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2263 NewDC
->w
.vport2WorldValid
= TRUE
;
2264 NewDC
->w
.MapMode
= MM_TEXT
;
2265 NewDC
->wndExtX
= 1.0f
;
2266 NewDC
->wndExtY
= 1.0f
;
2267 NewDC
->vportExtX
= 1.0f
;
2268 NewDC
->vportExtY
= 1.0f
;
2269 NewDC
->w
.textColor
= 0;
2270 NewDC
->w
.backgroundColor
= 0xffffff;
2272 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2273 TextIntRealizeFont(NewDC
->w
.hFont
);
2275 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2283 DC_FindOpenDC(PUNICODE_STRING Driver
)
2289 * Initialize some common fields in the Device Context structure.
2292 DC_InitDC(HDC DCHandle
)
2294 // NtGdiRealizeDefaultPalette(DCHandle);
2296 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2297 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2298 //NtGdiSelectObject(DCHandle, hFont);
2303 res = CLIPPING_UpdateGCRegion(DCToInit);
2304 ASSERT ( res != ERROR );
2310 DC_FreeDC(HDC DCToFree
)
2312 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
))
2314 DPRINT("DC_FreeDC failed\n");
2319 DC_Cleanup(PVOID ObjectBody
)
2321 PDC pDC
= (PDC
)ObjectBody
;
2322 RtlFreeUnicodeString(&pDC
->DriverName
);
2327 DC_GetNextDC (PDC pDC
)
2333 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2335 pDC
->hNext
= hNextDC
;
2339 DC_UpdateXforms(PDC dc
)
2341 XFORM xformWnd2Vport
;
2342 FLOAT scaleX
, scaleY
;
2344 /* Construct a transformation to do the window-to-viewport conversion */
2345 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2346 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2347 xformWnd2Vport
.eM11
= scaleX
;
2348 xformWnd2Vport
.eM12
= 0.0;
2349 xformWnd2Vport
.eM21
= 0.0;
2350 xformWnd2Vport
.eM22
= scaleY
;
2351 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2352 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2354 /* Combine with the world transformation */
2355 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2357 /* Create inverse of world-to-viewport transformation */
2358 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2362 DC_InvertXform(const XFORM
*xformSrc
,
2367 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2368 if (determinant
> -1e-12 && determinant
< 1e-12)
2373 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2374 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2375 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2376 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2377 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2378 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2384 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2388 GDIOBJ_SetOwnership(hDC
, Owner
);
2389 DC
= DC_LockDc(hDC
);
2392 if (NULL
!= DC
->w
.hClipRgn
)
2394 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2396 if (NULL
!= DC
->w
.hVisRgn
)
2398 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2400 if (NULL
!= DC
->w
.hGCClipRgn
)
2402 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2409 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2411 if (PrimarySurface
.Handle
== NULL
)
2415 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2419 * Returns the color of the brush or pen that is currently selected into the DC.
2420 * This function is called from GetDCBrushColor() and GetDCPenColor()
2423 IntGetDCColor(HDC hDC
, ULONG Object
)
2426 * The previous implementation was completly incorrect. It modified the
2427 * brush that was currently selected into the device context, but in fact
2428 * the DC pen/brush color should be stored directly in the device context
2429 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2430 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2431 * into the device context and BRUSHOBJ for drawing is composed (belongs
2432 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2433 * the implementation should be moved to user mode GDI32.dll when UM
2434 * mapped GDI objects will be implemented.
2437 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2438 return 0xFFFFFF; /* The default DC color. */
2442 * Changes the color of the brush or pen that is currently selected into the DC.
2443 * This function is called from SetDCBrushColor() and SetDCPenColor()
2446 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2448 /* See the comment in IntGetDCColor. */
2450 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2454 #define SIZEOF_DEVMODEW_300 188
2455 #define SIZEOF_DEVMODEW_400 212
2456 #define SIZEOF_DEVMODEW_500 220
2458 /*! \brief Enumerate possible display settings for the given display...
2460 * \todo Make thread safe!?
2461 * \todo Don't ignore pDeviceName
2462 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2465 IntEnumDisplaySettings(
2466 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2468 IN OUT LPDEVMODEW pDevMode
,
2471 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2472 static DWORD SizeOfCachedDevModes
= 0;
2473 PDEVMODEW CachedMode
= NULL
;
2476 ULONG DisplayNumber
= 0; /* only default display supported */
2478 DPRINT("DevMode->dmSize = %d\n", pDevMode
->dmSize
);
2479 DPRINT("DevMode->dmExtraSize = %d\n", pDevMode
->dmDriverExtra
);
2480 if (pDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2481 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2482 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2484 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2488 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2490 CachedMode
= &PrimarySurface
.DMW
;
2491 ASSERT(CachedMode
->dmSize
> 0);
2493 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2495 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2496 DevMode
.dmSize
= sizeof (DevMode
);
2497 DevMode
.dmDriverExtra
= 0;
2498 if (SetupDevMode(&DevMode
, DisplayNumber
))
2499 CachedMode
= &DevMode
;
2502 SetLastWin32Error(0); /* FIXME: use error code */
2505 /* FIXME: Maybe look for the matching devmode supplied by the
2506 * driver so we can provide driver private/extra data?
2511 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2513 BOOL PrimarySurfaceCreated
= FALSE
;
2514 UNICODE_STRING DriverFileNames
;
2516 DRVENABLEDATA DrvEnableData
;
2518 /* Retrieve DDI driver names from registry */
2519 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2520 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2522 DPRINT1("FindDriverFileNames failed\n");
2526 if (!HalQueryDisplayOwnership())
2528 IntCreatePrimarySurface();
2529 PrimarySurfaceCreated
= TRUE
;
2533 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2534 * scan all of them until a good one found.
2536 CurrentName
= DriverFileNames
.Buffer
;
2537 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2538 CurrentName
+= wcslen(CurrentName
) + 1)
2541 PGD_ENABLEDRIVER GDEnableDriver
;
2543 /* Get the DDI driver's entry point */
2544 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2545 if (NULL
== GDEnableDriver
)
2547 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2551 /* Call DDI driver's EnableDriver function */
2552 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2554 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2556 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2560 CachedDevModesEnd
= CachedDevModes
;
2562 /* find DrvGetModes function */
2563 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2565 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2566 PGD_GETMODES GetModes
;
2567 INT SizeNeeded
, SizeUsed
;
2569 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2572 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2574 /* make sure we have enough memory to hold the modes */
2575 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2576 if (SizeNeeded
<= 0)
2578 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2582 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2583 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2587 SizeOfCachedDevModes
+= SizeNeeded
;
2588 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2589 if (NewBuffer
== NULL
)
2592 ExFreePool(CachedDevModes
);
2593 SizeOfCachedDevModes
= 0;
2594 CachedDevModes
= NULL
;
2595 CachedDevModesEnd
= NULL
;
2596 if (PrimarySurfaceCreated
)
2598 IntDestroyPrimarySurface();
2600 SetLastWin32Error(STATUS_NO_MEMORY
);
2603 if (CachedDevModes
!= NULL
)
2605 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2606 ExFreePool(CachedDevModes
);
2608 CachedDevModes
= NewBuffer
;
2609 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2613 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2614 SizeOfCachedDevModes
- SizeUsed
,
2616 if (SizeNeeded
<= 0)
2618 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2622 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2628 if (PrimarySurfaceCreated
)
2630 IntDestroyPrimarySurface();
2633 RtlFreeUnicodeString(&DriverFileNames
);
2636 /* return cached info */
2637 CachedMode
= CachedDevModes
;
2638 if (CachedMode
>= CachedDevModesEnd
)
2640 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2643 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2645 assert(CachedMode
->dmSize
> 0);
2646 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2648 if (CachedMode
>= CachedDevModesEnd
)
2650 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2655 ASSERT(CachedMode
!= NULL
);
2657 Size
= OldSize
= pDevMode
->dmSize
;
2658 if (Size
> CachedMode
->dmSize
)
2659 Size
= CachedMode
->dmSize
;
2660 RtlCopyMemory(pDevMode
, CachedMode
, Size
);
2661 RtlZeroMemory((PCHAR
)pDevMode
+ Size
, OldSize
- Size
);
2662 pDevMode
->dmSize
= OldSize
;
2664 Size
= OldSize
= pDevMode
->dmDriverExtra
;
2665 if (Size
> CachedMode
->dmDriverExtra
)
2666 Size
= CachedMode
->dmDriverExtra
;
2667 RtlCopyMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
,
2668 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2669 RtlZeroMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
+ Size
, OldSize
- Size
);
2670 pDevMode
->dmDriverExtra
= OldSize
;
2676 IntChangeDisplaySettings(
2677 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2678 IN LPDEVMODEW DevMode
,
2680 IN PVOID lParam OPTIONAL
)
2682 BOOLEAN Global
= FALSE
;
2683 BOOLEAN NoReset
= FALSE
;
2684 BOOLEAN Reset
= FALSE
;
2685 BOOLEAN SetPrimary
= FALSE
;
2689 DPRINT1("display flag : %x\n",dwflags
);
2691 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2693 /* Check global, reset and noreset flags */
2694 if ((dwflags
& CDS_GLOBAL
) == CDS_GLOBAL
)
2696 if ((dwflags
& CDS_NORESET
) == CDS_NORESET
)
2698 dwflags
&= ~(CDS_GLOBAL
| CDS_NORESET
);
2700 if ((dwflags
& CDS_RESET
) == CDS_RESET
)
2702 if ((dwflags
& CDS_SET_PRIMARY
) == CDS_SET_PRIMARY
)
2704 dwflags
&= ~(CDS_RESET
| CDS_SET_PRIMARY
);
2706 if (Reset
&& NoReset
)
2707 return DISP_CHANGE_BADFLAGS
;
2711 /* Dynamically change graphics mode */
2712 DPRINT1("flag 0 UNIMPLEMENT \n");
2713 return DISP_CHANGE_FAILED
;
2716 if ((dwflags
& CDS_TEST
) == CDS_TEST
)
2718 /* Test reslution */
2719 dwflags
&= ~CDS_TEST
;
2720 DPRINT1("flag CDS_TEST UNIMPLEMENT");
2721 Ret
= DISP_CHANGE_FAILED
;
2724 if ((dwflags
& CDS_FULLSCREEN
) == CDS_FULLSCREEN
)
2728 dwflags
&= ~CDS_FULLSCREEN
;
2729 DPRINT1("flag CDS_FULLSCREEN partially implemented");
2730 Ret
= DISP_CHANGE_FAILED
;
2732 lpDevMode
.dmBitsPerPel
=0;
2733 lpDevMode
.dmPelsWidth
=0;
2734 lpDevMode
.dmPelsHeight
=0;
2735 lpDevMode
.dmDriverExtra
=0;
2737 lpDevMode
.dmSize
= sizeof(DEVMODE
);
2738 Status
= IntEnumDisplaySettings(pDeviceName
, ENUM_CURRENT_SETTINGS
, &lpDevMode
, 0);
2739 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2741 DPRINT1("Req Mode : %d x %d x %d\n", DevMode
->dmPelsWidth
,DevMode
->dmPelsHeight
,DevMode
->dmBitsPerPel
);
2742 DPRINT1("Current Mode : %d x %d x %d\n", lpDevMode
.dmPelsWidth
,lpDevMode
.dmPelsHeight
, lpDevMode
.dmBitsPerPel
);
2745 if ((lpDevMode
.dmBitsPerPel
== DevMode
->dmBitsPerPel
) &&
2746 (lpDevMode
.dmPelsWidth
== DevMode
->dmPelsWidth
) &&
2747 (lpDevMode
.dmPelsHeight
== DevMode
->dmPelsHeight
))
2748 Ret
= DISP_CHANGE_SUCCESSFUL
;
2751 if ((dwflags
& CDS_VIDEOPARAMETERS
) == CDS_VIDEOPARAMETERS
)
2753 dwflags
&= ~CDS_VIDEOPARAMETERS
;
2754 if (lParam
== NULL
) Ret
=DISP_CHANGE_BADPARAM
;
2757 DPRINT1("flag CDS_VIDEOPARAMETERS UNIMPLEMENT");
2758 Ret
= DISP_CHANGE_FAILED
;
2763 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2766 UNICODE_STRING ObjectName
;
2767 UNICODE_STRING KernelModeName
;
2768 WCHAR KernelModeNameBuffer
[256];
2769 UNICODE_STRING RegistryKey
;
2770 WCHAR RegistryKeyBuffer
[512];
2771 PDEVICE_OBJECT DeviceObject
;
2773 OBJECT_ATTRIBUTES ObjectAttributes
;
2774 HANDLE DevInstRegKey
;
2778 DPRINT1("set CDS_UPDATEREGISTRY \n");
2780 dwflags
&= ~CDS_UPDATEREGISTRY
;
2782 /* Get device name (pDeviceName is "\.\xxx") */
2783 for (LastSlash
= pDeviceName
->Length
/ sizeof(WCHAR
); LastSlash
> 0; LastSlash
--)
2785 if (pDeviceName
->Buffer
[LastSlash
- 1] == L
'\\')
2789 if (LastSlash
== 0) return DISP_CHANGE_RESTART
;
2790 ObjectName
= *pDeviceName
;
2791 ObjectName
.Length
-= LastSlash
* sizeof(WCHAR
);
2792 ObjectName
.MaximumLength
-= LastSlash
* sizeof(WCHAR
);
2793 ObjectName
.Buffer
+= LastSlash
;
2795 KernelModeName
.Length
= 0;
2796 KernelModeName
.MaximumLength
= sizeof(KernelModeNameBuffer
);
2797 KernelModeName
.Buffer
= KernelModeNameBuffer
;
2799 /* Open \??\xxx (ex: "\??\DISPLAY1") */
2800 Status
= RtlAppendUnicodeToString(&KernelModeName
, L
"\\??\\");
2802 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2803 Status
= RtlAppendUnicodeStringToString(&KernelModeName
, &ObjectName
);
2805 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2806 Status
= ObReferenceObjectByName(
2808 OBJ_CASE_INSENSITIVE
,
2814 (PVOID
*)&DeviceObject
);
2816 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2817 /* Get associated driver name (ex: "VBE") */
2818 for (LastSlash
= DeviceObject
->DriverObject
->DriverName
.Length
/ sizeof(WCHAR
); LastSlash
> 0; LastSlash
--)
2820 if (DeviceObject
->DriverObject
->DriverName
.Buffer
[LastSlash
- 1] == L
'\\')
2824 if (LastSlash
== 0) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2825 ObjectName
= DeviceObject
->DriverObject
->DriverName
;
2826 ObjectName
.Length
-= LastSlash
* sizeof(WCHAR
);
2827 ObjectName
.MaximumLength
-= LastSlash
* sizeof(WCHAR
);
2828 ObjectName
.Buffer
+= LastSlash
;
2830 RegistryKey
.Length
= 0;
2831 RegistryKey
.MaximumLength
= sizeof(RegistryKeyBuffer
);
2832 RegistryKey
.Buffer
= RegistryKeyBuffer
;
2834 /* Open registry key */
2835 Status
= RtlAppendUnicodeToString(&RegistryKey
,
2836 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\");
2838 if (!NT_SUCCESS(Status
)) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2839 Status
= RtlAppendUnicodeStringToString(&RegistryKey
, &ObjectName
);
2841 if (!NT_SUCCESS(Status
)) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2842 Status
= RtlAppendUnicodeToString(&RegistryKey
,
2845 if (!NT_SUCCESS(Status
)) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2847 InitializeObjectAttributes(&ObjectAttributes
, &RegistryKey
,
2848 OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
2849 Status
= ZwOpenKey(&DevInstRegKey
, GENERIC_READ
| GENERIC_WRITE
, &ObjectAttributes
);
2850 ObDereferenceObject(DeviceObject
);
2851 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2853 /* Update needed fields */
2854 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_BITSPERPEL
)
2856 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.BitsPerPel");
2857 NewValue
= DevMode
->dmBitsPerPel
;
2858 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2861 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSWIDTH
)
2863 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.XResolution");
2864 NewValue
= DevMode
->dmPelsWidth
;
2865 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2868 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSHEIGHT
)
2870 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.YResolution");
2871 NewValue
= DevMode
->dmPelsHeight
;
2872 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2875 ZwClose(DevInstRegKey
);
2876 if (NT_SUCCESS(Status
))
2877 Ret
= DISP_CHANGE_RESTART
;
2879 /* return DISP_CHANGE_NOTUPDATED when we can save to reg only vaild for NT */
2880 Ret
= DISP_CHANGE_NOTUPDATED
;
2885 Ret
= DISP_CHANGE_BADFLAGS
;