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
->PalIndexed
= OrigDC
->PalIndexed
;
226 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
227 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
228 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
229 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
230 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
231 NewDC
->w
.ROPmode
= OrigDC
->w
.ROPmode
;
234 if (NULL
!= DisplayDC
)
236 NtGdiDeleteDC(DisplayDC
);
239 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
240 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
241 NtGdiDeleteObject(hVisRgn
);
249 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
251 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
252 WCHAR DeviceNameBuffer
[20];
255 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
256 RtlInitUnicodeString(RegistryPath
, NULL
);
257 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
258 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
259 QueryTable
[0].Name
= DeviceNameBuffer
;
260 QueryTable
[0].EntryContext
= RegistryPath
;
262 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
267 if (! NT_SUCCESS(Status
))
269 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
273 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
279 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
281 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
282 UNICODE_STRING RegistryPath
;
285 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
287 DPRINT("GetRegistryPath failed\n");
291 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
292 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
293 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
294 QueryTable
[0].EntryContext
= DriverFileNames
;
296 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
301 RtlFreeUnicodeString(&RegistryPath
);
302 if (! NT_SUCCESS(Status
))
304 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
308 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
313 static NTSTATUS STDCALL
314 DevModeCallback(IN PWSTR ValueName
,
317 IN ULONG ValueLength
,
319 IN PVOID EntryContext
)
321 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
323 DPRINT("Found registry value for name %S: type %d, length %d\n",
324 ValueName
, ValueType
, ValueLength
);
326 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
328 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
330 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
332 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
334 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
336 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
338 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
340 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
342 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
344 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
346 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
348 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
350 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
352 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
354 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
358 return STATUS_SUCCESS
;
362 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
364 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
365 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
366 static WCHAR ControlSet
[] = L
"CONTROLSET";
367 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
368 UNICODE_STRING RegistryPath
;
370 PWCHAR AfterControlSet
;
372 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
375 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
377 DPRINT("GetRegistryPath failed\n");
381 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
382 wcslen(RegistryMachineSystem
)));
385 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
386 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
388 AfterControlSet
+= wcslen(CurrentControlSet
);
390 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
392 AfterControlSet
+= wcslen(ControlSet
);
393 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
397 Valid
= (L
'\\' == *AfterControlSet
);
408 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
409 (wcslen(RegistryPath
.Buffer
) +
410 wcslen(Insert
) + 1) * sizeof(WCHAR
),
412 if (NULL
!= ProfilePath
)
414 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
415 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
416 wcscat(ProfilePath
, AfterControlSet
);
418 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
419 QueryTable
[0].QueryRoutine
= DevModeCallback
;
420 QueryTable
[0].Flags
= 0;
421 QueryTable
[0].Name
= NULL
;
422 QueryTable
[0].EntryContext
= NULL
;
423 QueryTable
[0].DefaultType
= REG_NONE
;
424 QueryTable
[0].DefaultData
= NULL
;
425 QueryTable
[0].DefaultLength
= 0;
427 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
432 if (! NT_SUCCESS(Status
))
434 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
435 ProfilePath
, Status
);
440 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
441 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
442 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
443 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
444 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
446 DPRINT("Not all required devmode members are set\n");
451 ExFreePool(ProfilePath
);
460 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
463 RtlFreeUnicodeString(&RegistryPath
);
467 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
476 PGD_ENABLEDRIVER GDEnableDriver
;
478 UNICODE_STRING DriverFileNames
;
484 for (DisplayNumber
= 0; ; DisplayNumber
++)
486 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
488 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
490 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
492 /* Open the miniport driver */
493 if (PrimarySurface
.VideoFileObject
== NULL
)
495 DPRINT1("FindMPDriver failed\n");
499 /* Retrieve DDI driver names from registry */
500 RtlInitUnicodeString(&DriverFileNames
, NULL
);
501 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
503 DPRINT1("FindDriverFileNames failed\n");
508 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
509 * scan all of them until a good one found.
511 CurrentName
= DriverFileNames
.Buffer
;
514 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
516 /* Get the DDI driver's entry point */
517 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
518 if (NULL
== GDEnableDriver
)
520 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
524 /* Call DDI driver's EnableDriver function */
525 RtlZeroMemory(&DED
, sizeof(DED
));
527 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
529 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
539 /* Skip to the next name but never get past the Unicode string */
540 while (L
'\0' != *CurrentName
&&
541 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
545 if (CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
552 RtlFreeUnicodeString(&DriverFileNames
);
556 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
557 DPRINT1("No suitable DDI driver found\n");
561 DPRINT("Display driver %S loaded\n", CurrentName
);
563 DPRINT("Building DDI Functions\n");
565 /* Construct DDI driver function dispatch table */
566 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
568 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
569 DPRINT1("BuildDDIFunctions failed\n");
573 /* Allocate a phyical device handle from the driver */
574 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
575 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
577 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
581 PrimarySurface
.FillPatterns
,
582 sizeof(PrimarySurface
.GDIInfo
),
583 (ULONG
*) &PrimarySurface
.GDIInfo
,
584 sizeof(PrimarySurface
.DevInfo
),
585 &PrimarySurface
.DevInfo
,
588 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
589 DoDefault
= (NULL
== PrimarySurface
.PDev
);
592 DPRINT1("DrvEnablePDev with registry parameters failed\n");
602 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
603 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
604 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
608 PrimarySurface
.FillPatterns
,
609 sizeof(PrimarySurface
.GDIInfo
),
610 (ULONG
*) &PrimarySurface
.GDIInfo
,
611 sizeof(PrimarySurface
.DevInfo
),
612 &PrimarySurface
.DevInfo
,
615 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
617 if (NULL
== PrimarySurface
.PDev
)
619 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
620 DPRINT1("DrvEnablePDEV with default parameters failed\n");
621 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
626 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
628 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
629 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
631 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
633 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
634 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
637 PrimarySurface
.Pointer
.Exclude
.right
= -1;
639 DPRINT("calling completePDev\n");
641 /* Complete initialization of the physical device */
642 PrimarySurface
.DriverFunctions
.CompletePDEV(
644 (HDEV
)&PrimarySurface
);
646 DPRINT("calling DRIVER_ReferenceDriver\n");
648 DRIVER_ReferenceDriver(L
"DISPLAY");
650 PrimarySurface
.PreparedDriver
= TRUE
;
651 PrimarySurface
.DisplayNumber
= DisplayNumber
;
660 IntPrepareDriverIfNeeded()
662 return (PrimarySurface
.PreparedDriver
? TRUE
: IntPrepareDriver());
670 IO_STATUS_BLOCK Iosb
;
672 ULONG Length
= sizeof(BOOL
);
673 PIO_STACK_LOCATION StackPtr
;
674 LARGE_INTEGER StartOffset
;
675 PFILE_OBJECT FileObject
= PrimarySurface
.VideoFileObject
;
676 PDEVICE_OBJECT DeviceObject
= FileObject
->DeviceObject
;
678 DPRINT("PrepareVideoPrt() called\n");
680 KeClearEvent(&PrimarySurface
.VideoFileObject
->Event
);
682 ObReferenceObjectByPointer(FileObject
, 0, IoFileObjectType
, KernelMode
);
684 StartOffset
.QuadPart
= 0;
685 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
,
697 /* Set up IRP Data */
698 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
699 Irp
->RequestorMode
= KernelMode
;
700 Irp
->Overlay
.AsynchronousParameters
.UserApcRoutine
= NULL
;
701 Irp
->Overlay
.AsynchronousParameters
.UserApcContext
= NULL
;
702 Irp
->Flags
|= IRP_WRITE_OPERATION
;
704 /* Setup Stack Data */
705 StackPtr
= IoGetNextIrpStackLocation(Irp
);
706 StackPtr
->FileObject
= PrimarySurface
.VideoFileObject
;
707 StackPtr
->Parameters
.Write
.Key
= 0;
709 Status
= IoCallDriver(DeviceObject
, Irp
);
711 if (STATUS_PENDING
== Status
)
713 KeWaitForSingleObject(&FileObject
->Event
, Executive
, KernelMode
, TRUE
, 0);
714 Status
= Iosb
.Status
;
717 return NT_SUCCESS(Status
);
721 IntCreatePrimarySurface()
728 if (! IntPrepareDriverIfNeeded())
733 if (! PrepareVideoPrt())
738 DPRINT("calling EnableSurface\n");
739 /* Enable the drawing surface */
740 PrimarySurface
.Handle
=
741 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
742 if (NULL
== PrimarySurface
.Handle
)
744 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
745 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
746 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
747 DPRINT1("DrvEnableSurface failed\n");
751 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, TRUE
);
753 calledFromUser
= UserIsEntered(); //fixme: possibly upgrade a shared lock
754 if (!calledFromUser
){
755 UserEnterExclusive();
759 IntAttachMonitor(&PrimarySurface
, PrimarySurface
.DisplayNumber
);
761 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
762 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
763 SurfSize
= SurfObj
->sizlBitmap
;
764 SurfaceRect
.left
= SurfaceRect
.top
= 0;
765 SurfaceRect
.right
= SurfObj
->sizlBitmap
.cx
;
766 SurfaceRect
.bottom
= SurfObj
->sizlBitmap
.cy
;
767 /* FIXME - why does EngEraseSurface() sometimes crash?
768 EngEraseSurface(SurfObj, &SurfaceRect, 0); */
770 /* Put the pointer in the center of the screen */
771 GDIDEV(SurfObj
)->Pointer
.Pos
.x
= (SurfaceRect
.right
- SurfaceRect
.left
) / 2;
772 GDIDEV(SurfObj
)->Pointer
.Pos
.y
= (SurfaceRect
.bottom
- SurfaceRect
.top
) / 2;
774 EngUnlockSurface(SurfObj
);
775 co_IntShowDesktop(IntGetActiveDesktop(), SurfSize
.cx
, SurfSize
.cy
);
777 if (!calledFromUser
){
785 IntDestroyPrimarySurface()
789 DRIVER_UnreferenceDriver(L
"DISPLAY");
791 calledFromUser
= UserIsEntered();
792 if (!calledFromUser
){
793 UserEnterExclusive();
797 IntDetachMonitor(&PrimarySurface
);
799 if (!calledFromUser
){
804 * FIXME: Hide a mouse pointer there. Also because we have to prevent
805 * memory leaks with the Eng* mouse routines.
808 DPRINT("Reseting display\n" );
809 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
810 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
811 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
812 PrimarySurface
.PreparedDriver
= FALSE
;
816 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
820 IntGdiCreateDC(PUNICODE_STRING Driver
,
821 PUNICODE_STRING Device
,
822 PUNICODE_STRING Output
,
823 CONST PDEVMODEW InitData
,
830 UNICODE_STRING StdDriver
;
833 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
835 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
839 if (! IntPrepareDriverIfNeeded())
841 DPRINT1("Unable to prepare graphics driver, returning NULL ic\n");
847 calledFromUser
= UserIsEntered();
848 if (!calledFromUser
){
849 UserEnterExclusive();
852 if (! co_IntGraphicsCheck(TRUE
))
854 if (!calledFromUser
){
857 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
861 if (!calledFromUser
){
868 /* Check for existing DC object */
869 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
872 return NtGdiCreateCompatibleDC(hDC
);
875 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
877 DPRINT("NAME: %wZ\n", Driver
); // FIXME: Should not crash if NULL
880 /* Allocate a DC object */
881 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
886 NewDC
= DC_LockDc( hNewDC
);
887 /* FIXME - NewDC can be NULL!!! Don't assert here! */
894 NewDC
->IsIC
= CreateAsIC
;
895 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
896 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
897 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
898 sizeof(NewDC
->FillPatternSurfaces
));
899 NewDC
->PDev
= PrimarySurface
.PDev
;
900 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
901 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
902 NewDC
->w
.hBitmap
= PrimarySurface
.Handle
;
904 NewDC
->w
.bitsPerPixel
= NewDC
->GDIInfo
->cBitsPixel
* NewDC
->GDIInfo
->cPlanes
;
905 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
909 NewDC
->PalIndexed
= NtGdiGetStockObject(DEFAULT_PALETTE
);
910 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
911 NewDC
->w
.ROPmode
= R2_COPYPEN
;
913 DC_UnlockDc( NewDC
);
915 hVisRgn
= NtGdiCreateRectRgn(0, 0, NewDC
->GDIInfo
->ulHorzRes
,
916 NewDC
->GDIInfo
->ulVertRes
);
917 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
918 NtGdiDeleteObject(hVisRgn
);
920 /* Initialize the DC state */
922 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
923 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
924 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
925 NtGdiSetBkMode(hNewDC
, OPAQUE
);
929 DC_UnlockDc( NewDC
);
936 NtGdiCreateDC(PUNICODE_STRING Driver
,
937 PUNICODE_STRING Device
,
938 PUNICODE_STRING Output
,
939 CONST PDEVMODEW InitData
)
941 UNICODE_STRING SafeDriver
, SafeDevice
;
942 DEVMODEW SafeInitData
;
944 NTSTATUS Status
= STATUS_SUCCESS
;
950 ProbeForRead(InitData
,
953 RtlCopyMemory(&SafeInitData
,
959 Status
= _SEH_GetExceptionCode();
963 if(!NT_SUCCESS(Status
))
965 SetLastNtError(Status
);
968 /* FIXME - InitData can have some more bytes! */
973 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
974 if(!NT_SUCCESS(Status
))
976 SetLastNtError(Status
);
983 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
984 if(!NT_SUCCESS(Status
))
986 RtlFreeUnicodeString(&SafeDriver
);
987 SetLastNtError(Status
);
992 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
993 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
994 NULL
== InitData
? NULL
: &SafeInitData
, FALSE
);
1000 NtGdiCreateIC(PUNICODE_STRING Driver
,
1001 PUNICODE_STRING Device
,
1002 PUNICODE_STRING Output
,
1003 CONST PDEVMODEW InitData
)
1005 UNICODE_STRING SafeDriver
, SafeDevice
;
1006 DEVMODEW SafeInitData
;
1008 NTSTATUS Status
= STATUS_SUCCESS
;
1014 ProbeForRead(InitData
,
1017 RtlCopyMemory(&SafeInitData
,
1023 Status
= _SEH_GetExceptionCode();
1026 if(!NT_SUCCESS(Status
))
1028 SetLastNtError(Status
);
1031 /* FIXME - InitData can have some more bytes! */
1036 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
1037 if(!NT_SUCCESS(Status
))
1039 SetLastNtError(Status
);
1046 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
1047 if(!NT_SUCCESS(Status
))
1049 RtlFreeUnicodeString(&SafeDriver
);
1050 SetLastNtError(Status
);
1055 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
1056 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
1057 NULL
== InitData
? NULL
: &SafeInitData
, TRUE
);
1063 NtGdiDeleteDC(HDC DCHandle
)
1067 if (!GDIOBJ_OwnedByCurrentProcess(DCHandle
))
1069 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1073 DCToDelete
= DC_LockDc(DCHandle
);
1074 if (DCToDelete
== NULL
)
1076 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1080 /* First delete all saved DCs */
1081 while (DCToDelete
->saveLevel
)
1086 savedHDC
= DC_GetNextDC (DCToDelete
);
1087 savedDC
= DC_LockDc (savedHDC
);
1088 if (savedDC
== NULL
)
1092 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
1093 DCToDelete
->saveLevel
--;
1094 DC_UnlockDc( savedDC
);
1095 NtGdiDeleteDC (savedHDC
);
1098 /* Free GDI resources allocated to this DC */
1099 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
1102 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
1103 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
1104 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
1105 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
1106 if (DCToDelete
->w
.flags
& DC_MEMORY
)
1108 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
1110 if (DCToDelete
->XlateBrush
!= NULL
)
1111 EngDeleteXlate(DCToDelete
->XlateBrush
);
1112 if (DCToDelete
->XlatePen
!= NULL
)
1113 EngDeleteXlate(DCToDelete
->XlatePen
);
1115 if (DCToDelete
->w
.hClipRgn
)
1117 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
1119 if (DCToDelete
->w
.hVisRgn
)
1121 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
1123 if (NULL
!= DCToDelete
->CombinedClip
)
1125 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
1127 if (DCToDelete
->w
.hGCClipRgn
)
1129 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
1132 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
1134 DC_UnlockDc( DCToDelete
);
1135 DC_FreeDC ( DCHandle
);
1141 NtGdiDrawEscape(HDC hDC
,
1151 NtGdiEnumObjects(HDC hDC
,
1153 GOBJENUMPROC ObjectFunc
,
1160 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
1161 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
1162 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
1163 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
1166 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
1171 if(!(dc
= DC_LockDc(hDC
)))
1173 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1180 SelObject
= dc
->w
.hPen
;
1183 SelObject
= dc
->w
.hBrush
;
1186 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
1190 SelObject
= dc
->w
.hFont
;
1193 SelObject
= dc
->w
.hBitmap
;
1195 case OBJ_COLORSPACE
:
1196 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
1201 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1209 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
1212 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
1214 Point
->x
= dc
->w
.DCOrgX
;
1215 Point
->y
= dc
->w
.DCOrgY
;
1221 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1226 NTSTATUS Status
= STATUS_SUCCESS
;
1230 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1234 dc
= DC_LockDc(hDC
);
1237 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1241 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1245 ProbeForWrite(Point
,
1252 Status
= _SEH_GetExceptionCode();
1256 if(!NT_SUCCESS(Status
))
1258 SetLastNtError(Status
);
1268 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1274 if (!(dc
= DC_LockDc(hDC
)))
1276 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1280 oldColor
= dc
->w
.backgroundColor
;
1281 dc
->w
.backgroundColor
= color
;
1282 hBrush
= dc
->w
.hBrush
;
1284 NtGdiSelectObject(hDC
, hBrush
);
1289 NtGdiGetDCState(HDC hDC
)
1294 dc
= DC_LockDc(hDC
);
1297 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1301 hnewdc
= DC_AllocDC(NULL
);
1307 newdc
= DC_LockDc( hnewdc
);
1308 /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
1311 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1312 newdc
->w
.hPen
= dc
->w
.hPen
;
1313 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1314 newdc
->w
.hFont
= dc
->w
.hFont
;
1315 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1316 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1318 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1320 newdc
->PalIndexed
= dc
->PalIndexed
;
1321 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1322 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1323 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1324 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1325 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1326 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1327 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1328 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1329 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1330 newdc
->w
.textColor
= dc
->w
.textColor
;
1331 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1332 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1333 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1334 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1335 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1336 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1337 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1338 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1339 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1340 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1342 /* Apparently, the DC origin is not changed by [GS]etDCState */
1343 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1344 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1346 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1347 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1348 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1349 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1350 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1351 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1352 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1353 newdc
->wndOrgX
= dc
->wndOrgX
;
1354 newdc
->wndOrgY
= dc
->wndOrgY
;
1355 newdc
->wndExtX
= dc
->wndExtX
;
1356 newdc
->wndExtY
= dc
->wndExtY
;
1357 newdc
->vportOrgX
= dc
->vportOrgX
;
1358 newdc
->vportOrgY
= dc
->vportOrgY
;
1359 newdc
->vportExtX
= dc
->vportExtX
;
1360 newdc
->vportExtY
= dc
->vportExtY
;
1362 newdc
->hSelf
= hnewdc
;
1363 newdc
->saveLevel
= 0;
1364 newdc
->IsIC
= dc
->IsIC
;
1367 PATH_InitGdiPath( &newdc
->w
.path
);
1370 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1372 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1375 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1376 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1378 DC_UnlockDc( newdc
);
1386 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1390 dc
= DC_LockDc ( hDC
);
1393 dcs
= DC_LockDc ( hDCSave
);
1396 if ( dcs
->w
.flags
& DC_SAVED
)
1398 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1400 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1403 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1406 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1407 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1408 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1409 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1410 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1411 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1412 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1413 dc
->w
.textColor
= dcs
->w
.textColor
;
1414 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1415 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1416 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1417 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1418 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1419 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1420 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1421 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1422 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1423 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1425 /* Apparently, the DC origin is not changed by [GS]etDCState */
1426 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1427 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1429 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1430 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1431 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1433 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1434 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1435 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1436 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1438 dc
->wndOrgX
= dcs
->wndOrgX
;
1439 dc
->wndOrgY
= dcs
->wndOrgY
;
1440 dc
->wndExtX
= dcs
->wndExtX
;
1441 dc
->wndExtY
= dcs
->wndExtY
;
1442 dc
->vportOrgX
= dcs
->vportOrgX
;
1443 dc
->vportOrgY
= dcs
->vportOrgY
;
1444 dc
->vportExtX
= dcs
->vportExtX
;
1445 dc
->vportExtY
= dcs
->vportExtY
;
1446 dc
->PalIndexed
= dcs
->PalIndexed
;
1448 if (!(dc
->w
.flags
& DC_MEMORY
))
1450 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1454 if (dcs
->w
.hClipRgn
)
1456 if (!dc
->w
.hClipRgn
)
1458 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1460 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1466 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1473 res
= CLIPPING_UpdateGCRegion( dc
);
1474 ASSERT ( res
!= ERROR
);
1479 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1482 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1483 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1484 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1485 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1486 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1487 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1489 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1492 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1497 DC_UnlockDc ( dcs
);
1500 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1504 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1508 IntGdiGetDeviceCaps(PDC dc
, INT Index
)
1513 /* Retrieve capability */
1517 ret
= dc
->GDIInfo
->ulVersion
;
1521 ret
= dc
->GDIInfo
->ulTechnology
;
1525 ret
= dc
->GDIInfo
->ulHorzSize
;
1529 ret
= dc
->GDIInfo
->ulVertSize
;
1533 ret
= dc
->GDIInfo
->ulHorzRes
;
1537 ret
= dc
->GDIInfo
->ulVertRes
;
1541 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1545 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1549 ret
= dc
->GDIInfo
->cBitsPixel
;
1553 ret
= dc
->GDIInfo
->cPlanes
;
1557 UNIMPLEMENTED
; /* FIXME */
1561 UNIMPLEMENTED
; /* FIXME */
1565 UNIMPLEMENTED
; /* FIXME */
1569 ret
= dc
->GDIInfo
->ulNumColors
;
1573 ret
= dc
->GDIInfo
->ulAspectX
;
1577 ret
= dc
->GDIInfo
->ulAspectY
;
1581 ret
= dc
->GDIInfo
->ulAspectXY
;
1585 UNIMPLEMENTED
; /* FIXME */
1589 UNIMPLEMENTED
; /* FIXME */
1593 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1601 UNIMPLEMENTED
; /* FIXME */
1605 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1615 case PHYSICALHEIGHT
:
1616 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1626 case PHYSICALOFFSETX
:
1627 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1637 case PHYSICALOFFSETY
:
1638 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1649 UNIMPLEMENTED
; /* FIXME */
1652 case SCALINGFACTORX
:
1653 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1663 case SCALINGFACTORY
:
1664 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1675 ret
= dc
->GDIInfo
->flRaster
;
1679 UNIMPLEMENTED
; /* FIXME */
1683 UNIMPLEMENTED
; /* FIXME */
1687 UNIMPLEMENTED
; /* FIXME */
1691 ret
= dc
->GDIInfo
->flTextCaps
;
1703 NtGdiGetDeviceCaps(HDC hDC
,
1709 dc
= DC_LockDc(hDC
);
1712 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1716 ret
= IntGdiGetDeviceCaps(dc
, Index
);
1718 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1724 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1725 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1728 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1734 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1735 if (NULL
== GdiObject
)
1737 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1741 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1745 case GDI_OBJECT_TYPE_PEN
:
1746 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1748 case GDI_OBJECT_TYPE_BRUSH
:
1749 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1752 case GDI_OBJECT_TYPE_BITMAP
:
1753 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1755 case GDI_OBJECT_TYPE_FONT
:
1756 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1758 // Fix the LOGFONT structure for the stock fonts
1759 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1761 FixStockFontSizeW(Handle
, Count
, Buffer
);
1766 case GDI_OBJECT_TYPE_PALETTE
:
1767 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1771 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1775 GDIOBJ_UnlockObjByPtr(GdiObject
);
1781 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1785 NTSTATUS Status
= STATUS_SUCCESS
;
1794 ProbeForWrite(buffer
,
1800 Status
= _SEH_GetExceptionCode();
1804 if(!NT_SUCCESS(Status
))
1806 SetLastNtError(Status
);
1810 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1813 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1817 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1821 /* pointer already probed! */
1822 RtlCopyMemory(buffer
,
1828 Status
= _SEH_GetExceptionCode();
1832 ExFreePool(SafeBuf
);
1833 if(!NT_SUCCESS(Status
))
1835 SetLastNtError(Status
);
1843 NtGdiGetObjectType(HANDLE handle
)
1849 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1852 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1856 objectType
= GDIOBJ_GetObjectType(handle
);
1859 case GDI_OBJECT_TYPE_PEN
:
1862 case GDI_OBJECT_TYPE_BRUSH
:
1865 case GDI_OBJECT_TYPE_BITMAP
:
1866 result
= OBJ_BITMAP
;
1868 case GDI_OBJECT_TYPE_FONT
:
1871 case GDI_OBJECT_TYPE_PALETTE
:
1874 case GDI_OBJECT_TYPE_REGION
:
1875 result
= OBJ_REGION
;
1877 case GDI_OBJECT_TYPE_DC
:
1880 case GDI_OBJECT_TYPE_METADC
:
1881 result
= OBJ_METADC
;
1883 case GDI_OBJECT_TYPE_METAFILE
:
1884 result
= OBJ_METAFILE
;
1886 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1887 result
= OBJ_ENHMETAFILE
;
1889 case GDI_OBJECT_TYPE_ENHMETADC
:
1890 result
= OBJ_ENHMETADC
;
1892 case GDI_OBJECT_TYPE_EXTPEN
:
1893 result
= OBJ_EXTPEN
;
1895 case GDI_OBJECT_TYPE_MEMDC
:
1900 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1904 GDIOBJ_UnlockObjByPtr(ptr
);
1908 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1909 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1910 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1911 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1912 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1913 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1914 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1915 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1916 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1919 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1926 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1931 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1933 dc
= DC_LockDc(hDC
);
1936 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1940 if (SaveLevel
== -1)
1941 SaveLevel
= dc
->saveLevel
;
1943 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1950 while (dc
->saveLevel
>= SaveLevel
)
1952 HDC hdcs
= DC_GetNextDC (dc
);
1954 dcs
= DC_LockDc (hdcs
);
1960 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1961 if (--dc
->saveLevel
< SaveLevel
)
1965 NtGdiSetDCState(hDC
, hdcs
);
1967 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1969 /* FIXME: This might not be quite right, since we're
1970 * returning FALSE but still destroying the saved DC state */
1974 dc
= DC_LockDc(hDC
);
1984 NtGdiDeleteDC (hdcs
);
1991 NtGdiSaveDC(HDC hDC
)
1997 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1999 if (!(hdcs
= NtGdiGetDCState(hDC
)))
2004 dcs
= DC_LockDc (hdcs
);
2007 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2010 dc
= DC_LockDc (hDC
);
2014 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2019 /* Copy path. The reason why path saving / restoring is in SaveDC/
2020 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
2021 * functions are only in Win16 (which doesn't have paths) and that
2022 * SetDCState doesn't allow us to signal an error (which can happen
2023 * when copying paths).
2025 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
2027 NtGdiDeleteDC (hdcs
);
2032 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
2033 DC_SetNextDC (dc
, hdcs
);
2034 ret
= ++dc
->saveLevel
;
2043 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
2045 HGDIOBJ objOrg
= NULL
; // default to failure
2055 if(!hDC
|| !hGDIObj
) return NULL
;
2057 dc
= DC_LockDc(hDC
);
2060 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2064 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
2068 case GDI_OBJECT_TYPE_PEN
:
2069 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
2072 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2076 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
2077 PENOBJ_UnlockPen(pen
);
2080 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2084 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
2085 dc
->w
.hPen
= hGDIObj
;
2086 if (dc
->XlatePen
!= NULL
)
2087 EngDeleteXlate(dc
->XlatePen
);
2088 dc
->XlatePen
= XlateObj
;
2091 case GDI_OBJECT_TYPE_BRUSH
:
2092 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
2095 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2099 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
2100 BRUSHOBJ_UnlockBrush(brush
);
2103 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2107 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
2108 dc
->w
.hBrush
= hGDIObj
;
2109 if (dc
->XlateBrush
!= NULL
)
2110 EngDeleteXlate(dc
->XlateBrush
);
2111 dc
->XlateBrush
= XlateObj
;
2114 case GDI_OBJECT_TYPE_FONT
:
2115 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
2117 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
2118 dc
->w
.hFont
= (HFONT
) hGDIObj
;
2122 case GDI_OBJECT_TYPE_BITMAP
:
2123 // must be memory dc to select bitmap
2124 if (!(dc
->w
.flags
& DC_MEMORY
))
2129 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
2132 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2136 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
2138 /* Release the old bitmap, lock the new one and convert it to a SURF */
2139 dc
->w
.hBitmap
= hGDIObj
;
2141 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
2144 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
2145 dc
->w
.hPalette
= pb
->hDIBPalette
;
2149 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
2150 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
2153 /* Reselect brush and pen to regenerate the XLATEOBJs. */
2154 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
2155 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
2158 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
2159 BITMAPOBJ_UnlockBitmap( pb
);
2160 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
2161 NtGdiDeleteObject ( hVisRgn
);
2165 case GDI_OBJECT_TYPE_REGION
:
2168 * The return value is one of the following values:
2173 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
2183 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
2186 DC
*dc
= DC_LockDc(hDC
);
2190 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2194 wRet
= dc
->w
.flags
& DC_DIRTY
;
2196 /* "Undocumented Windows" info is slightly confusing.
2199 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
2201 if (Flags
& DCHF_INVALIDATEVISRGN
)
2203 dc
->w
.flags
|= DC_DIRTY
;
2205 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
2207 dc
->w
.flags
&= ~DC_DIRTY
;
2215 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
2216 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
2217 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
2218 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
2219 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
2221 // ---------------------------------------------------- Private Interface
2224 DC_AllocDC(PUNICODE_STRING Driver
)
2232 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
2237 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
2240 hDC
= (HDC
) GDIOBJ_AllocObj(GDI_OBJECT_TYPE_DC
);
2250 NewDC
= DC_LockDc(hDC
);
2251 /* FIXME - Handle NewDC == NULL! */
2255 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2256 NewDC
->DriverName
.Buffer
= Buf
;
2259 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2260 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2261 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2262 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2263 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2264 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2265 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2266 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2267 NewDC
->w
.vport2WorldValid
= TRUE
;
2268 NewDC
->w
.MapMode
= MM_TEXT
;
2269 NewDC
->wndExtX
= 1.0f
;
2270 NewDC
->wndExtY
= 1.0f
;
2271 NewDC
->vportExtX
= 1.0f
;
2272 NewDC
->vportExtY
= 1.0f
;
2273 NewDC
->w
.textColor
= 0;
2274 NewDC
->w
.backgroundColor
= 0xffffff;
2276 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2277 TextIntRealizeFont(NewDC
->w
.hFont
);
2279 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2287 DC_FindOpenDC(PUNICODE_STRING Driver
)
2293 * Initialize some common fields in the Device Context structure.
2296 DC_InitDC(HDC DCHandle
)
2298 // NtGdiRealizeDefaultPalette(DCHandle);
2300 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2301 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2302 //NtGdiSelectObject(DCHandle, hFont);
2307 res = CLIPPING_UpdateGCRegion(DCToInit);
2308 ASSERT ( res != ERROR );
2314 DC_FreeDC(HDC DCToFree
)
2316 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
))
2318 DPRINT("DC_FreeDC failed\n");
2323 DC_Cleanup(PVOID ObjectBody
)
2325 PDC pDC
= (PDC
)ObjectBody
;
2326 RtlFreeUnicodeString(&pDC
->DriverName
);
2331 DC_GetNextDC (PDC pDC
)
2337 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2339 pDC
->hNext
= hNextDC
;
2343 DC_UpdateXforms(PDC dc
)
2345 XFORM xformWnd2Vport
;
2346 FLOAT scaleX
, scaleY
;
2348 /* Construct a transformation to do the window-to-viewport conversion */
2349 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2350 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2351 xformWnd2Vport
.eM11
= scaleX
;
2352 xformWnd2Vport
.eM12
= 0.0;
2353 xformWnd2Vport
.eM21
= 0.0;
2354 xformWnd2Vport
.eM22
= scaleY
;
2355 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2356 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2358 /* Combine with the world transformation */
2359 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2361 /* Create inverse of world-to-viewport transformation */
2362 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2366 DC_InvertXform(const XFORM
*xformSrc
,
2371 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2372 if (determinant
> -1e-12 && determinant
< 1e-12)
2377 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2378 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2379 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2380 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2381 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2382 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2388 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2392 GDIOBJ_SetOwnership(hDC
, Owner
);
2393 DC
= DC_LockDc(hDC
);
2396 if (NULL
!= DC
->w
.hClipRgn
)
2398 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2400 if (NULL
!= DC
->w
.hVisRgn
)
2402 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2404 if (NULL
!= DC
->w
.hGCClipRgn
)
2406 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2413 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2415 if (PrimarySurface
.Handle
== NULL
)
2419 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2423 * Returns the color of the brush or pen that is currently selected into the DC.
2424 * This function is called from GetDCBrushColor() and GetDCPenColor()
2427 IntGetDCColor(HDC hDC
, ULONG Object
)
2430 * The previous implementation was completly incorrect. It modified the
2431 * brush that was currently selected into the device context, but in fact
2432 * the DC pen/brush color should be stored directly in the device context
2433 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2434 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2435 * into the device context and BRUSHOBJ for drawing is composed (belongs
2436 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2437 * the implementation should be moved to user mode GDI32.dll when UM
2438 * mapped GDI objects will be implemented.
2441 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2442 return 0xFFFFFF; /* The default DC color. */
2446 * Changes the color of the brush or pen that is currently selected into the DC.
2447 * This function is called from SetDCBrushColor() and SetDCPenColor()
2450 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2452 /* See the comment in IntGetDCColor. */
2454 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2458 #define SIZEOF_DEVMODEW_300 188
2459 #define SIZEOF_DEVMODEW_400 212
2460 #define SIZEOF_DEVMODEW_500 220
2462 /*! \brief Enumerate possible display settings for the given display...
2464 * \todo Make thread safe!?
2465 * \todo Don't ignore pDeviceName
2466 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2469 IntEnumDisplaySettings(
2470 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2472 IN OUT LPDEVMODEW pDevMode
,
2475 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2476 static DWORD SizeOfCachedDevModes
= 0;
2477 PDEVMODEW CachedMode
= NULL
;
2480 ULONG DisplayNumber
= 0; /* only default display supported */
2482 DPRINT("DevMode->dmSize = %d\n", pDevMode
->dmSize
);
2483 DPRINT("DevMode->dmExtraSize = %d\n", pDevMode
->dmDriverExtra
);
2484 if (pDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2485 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2486 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2488 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2492 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2494 CachedMode
= &PrimarySurface
.DMW
;
2495 ASSERT(CachedMode
->dmSize
> 0);
2497 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2499 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2500 DevMode
.dmSize
= sizeof (DevMode
);
2501 DevMode
.dmDriverExtra
= 0;
2502 if (SetupDevMode(&DevMode
, DisplayNumber
))
2503 CachedMode
= &DevMode
;
2506 SetLastWin32Error(0); /* FIXME: use error code */
2509 /* FIXME: Maybe look for the matching devmode supplied by the
2510 * driver so we can provide driver private/extra data?
2515 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2517 BOOL PrimarySurfaceCreated
= FALSE
;
2518 UNICODE_STRING DriverFileNames
;
2520 DRVENABLEDATA DrvEnableData
;
2522 /* Retrieve DDI driver names from registry */
2523 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2524 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2526 DPRINT1("FindDriverFileNames failed\n");
2530 if (!HalQueryDisplayOwnership())
2532 IntCreatePrimarySurface();
2533 PrimarySurfaceCreated
= TRUE
;
2537 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2538 * scan all of them until a good one found.
2540 CurrentName
= DriverFileNames
.Buffer
;
2541 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2542 CurrentName
+= wcslen(CurrentName
) + 1)
2545 PGD_ENABLEDRIVER GDEnableDriver
;
2547 /* Get the DDI driver's entry point */
2548 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2549 if (NULL
== GDEnableDriver
)
2551 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2555 /* Call DDI driver's EnableDriver function */
2556 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2558 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2560 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2564 CachedDevModesEnd
= CachedDevModes
;
2566 /* find DrvGetModes function */
2567 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2569 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2570 PGD_GETMODES GetModes
;
2571 INT SizeNeeded
, SizeUsed
;
2573 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2576 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2578 /* make sure we have enough memory to hold the modes */
2579 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2580 if (SizeNeeded
<= 0)
2582 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2586 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2587 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2591 SizeOfCachedDevModes
+= SizeNeeded
;
2592 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2593 if (NewBuffer
== NULL
)
2596 ExFreePool(CachedDevModes
);
2597 SizeOfCachedDevModes
= 0;
2598 CachedDevModes
= NULL
;
2599 CachedDevModesEnd
= NULL
;
2600 if (PrimarySurfaceCreated
)
2602 IntDestroyPrimarySurface();
2604 SetLastWin32Error(STATUS_NO_MEMORY
);
2607 if (CachedDevModes
!= NULL
)
2609 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2610 ExFreePool(CachedDevModes
);
2612 CachedDevModes
= NewBuffer
;
2613 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2617 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2618 SizeOfCachedDevModes
- SizeUsed
,
2620 if (SizeNeeded
<= 0)
2622 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2626 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2632 if (PrimarySurfaceCreated
)
2634 IntDestroyPrimarySurface();
2637 RtlFreeUnicodeString(&DriverFileNames
);
2640 /* return cached info */
2641 CachedMode
= CachedDevModes
;
2642 if (CachedMode
>= CachedDevModesEnd
)
2644 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2647 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2649 assert(CachedMode
->dmSize
> 0);
2650 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2652 if (CachedMode
>= CachedDevModesEnd
)
2654 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2659 ASSERT(CachedMode
!= NULL
);
2661 Size
= OldSize
= pDevMode
->dmSize
;
2662 if (Size
> CachedMode
->dmSize
)
2663 Size
= CachedMode
->dmSize
;
2664 RtlCopyMemory(pDevMode
, CachedMode
, Size
);
2665 RtlZeroMemory((PCHAR
)pDevMode
+ Size
, OldSize
- Size
);
2666 pDevMode
->dmSize
= OldSize
;
2668 Size
= OldSize
= pDevMode
->dmDriverExtra
;
2669 if (Size
> CachedMode
->dmDriverExtra
)
2670 Size
= CachedMode
->dmDriverExtra
;
2671 RtlCopyMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
,
2672 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2673 RtlZeroMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
+ Size
, OldSize
- Size
);
2674 pDevMode
->dmDriverExtra
= OldSize
;
2680 IntChangeDisplaySettings(
2681 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2682 IN LPDEVMODEW DevMode
,
2684 IN PVOID lParam OPTIONAL
)
2686 BOOLEAN Global
= FALSE
;
2687 BOOLEAN NoReset
= FALSE
;
2688 BOOLEAN Reset
= FALSE
;
2689 BOOLEAN SetPrimary
= FALSE
;
2693 DPRINT1("display flag : %x\n",dwflags
);
2695 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2697 /* Check global, reset and noreset flags */
2698 if ((dwflags
& CDS_GLOBAL
) == CDS_GLOBAL
)
2700 if ((dwflags
& CDS_NORESET
) == CDS_NORESET
)
2702 dwflags
&= ~(CDS_GLOBAL
| CDS_NORESET
);
2704 if ((dwflags
& CDS_RESET
) == CDS_RESET
)
2706 if ((dwflags
& CDS_SET_PRIMARY
) == CDS_SET_PRIMARY
)
2708 dwflags
&= ~(CDS_RESET
| CDS_SET_PRIMARY
);
2710 if (Reset
&& NoReset
)
2711 return DISP_CHANGE_BADFLAGS
;
2715 /* Dynamically change graphics mode */
2716 DPRINT1("flag 0 UNIMPLEMENT \n");
2717 return DISP_CHANGE_FAILED
;
2720 if ((dwflags
& CDS_TEST
) == CDS_TEST
)
2722 /* Test reslution */
2723 dwflags
&= ~CDS_TEST
;
2724 DPRINT1("flag CDS_TEST UNIMPLEMENT");
2725 Ret
= DISP_CHANGE_FAILED
;
2728 if ((dwflags
& CDS_FULLSCREEN
) == CDS_FULLSCREEN
)
2732 dwflags
&= ~CDS_FULLSCREEN
;
2733 DPRINT1("flag CDS_FULLSCREEN partially implemented");
2734 Ret
= DISP_CHANGE_FAILED
;
2736 lpDevMode
.dmBitsPerPel
=0;
2737 lpDevMode
.dmPelsWidth
=0;
2738 lpDevMode
.dmPelsHeight
=0;
2739 lpDevMode
.dmDriverExtra
=0;
2741 lpDevMode
.dmSize
= sizeof(DEVMODE
);
2742 Status
= IntEnumDisplaySettings(pDeviceName
, ENUM_CURRENT_SETTINGS
, &lpDevMode
, 0);
2743 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2745 DPRINT1("Req Mode : %d x %d x %d\n", DevMode
->dmPelsWidth
,DevMode
->dmPelsHeight
,DevMode
->dmBitsPerPel
);
2746 DPRINT1("Current Mode : %d x %d x %d\n", lpDevMode
.dmPelsWidth
,lpDevMode
.dmPelsHeight
, lpDevMode
.dmBitsPerPel
);
2749 if ((lpDevMode
.dmBitsPerPel
== DevMode
->dmBitsPerPel
) &&
2750 (lpDevMode
.dmPelsWidth
== DevMode
->dmPelsWidth
) &&
2751 (lpDevMode
.dmPelsHeight
== DevMode
->dmPelsHeight
))
2752 Ret
= DISP_CHANGE_SUCCESSFUL
;
2755 if ((dwflags
& CDS_VIDEOPARAMETERS
) == CDS_VIDEOPARAMETERS
)
2757 dwflags
&= ~CDS_VIDEOPARAMETERS
;
2758 if (lParam
== NULL
) Ret
=DISP_CHANGE_BADPARAM
;
2761 DPRINT1("flag CDS_VIDEOPARAMETERS UNIMPLEMENT");
2762 Ret
= DISP_CHANGE_FAILED
;
2767 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2770 UNICODE_STRING ObjectName
;
2771 UNICODE_STRING KernelModeName
;
2772 WCHAR KernelModeNameBuffer
[256];
2773 UNICODE_STRING RegistryKey
;
2774 WCHAR RegistryKeyBuffer
[512];
2775 PDEVICE_OBJECT DeviceObject
;
2777 OBJECT_ATTRIBUTES ObjectAttributes
;
2778 HANDLE DevInstRegKey
;
2782 DPRINT1("set CDS_UPDATEREGISTRY \n");
2784 dwflags
&= ~CDS_UPDATEREGISTRY
;
2786 /* Get device name (pDeviceName is "\.\xxx") */
2787 for (LastSlash
= pDeviceName
->Length
/ sizeof(WCHAR
); LastSlash
> 0; LastSlash
--)
2789 if (pDeviceName
->Buffer
[LastSlash
- 1] == L
'\\')
2793 if (LastSlash
== 0) return DISP_CHANGE_RESTART
;
2794 ObjectName
= *pDeviceName
;
2795 ObjectName
.Length
-= LastSlash
* sizeof(WCHAR
);
2796 ObjectName
.MaximumLength
-= LastSlash
* sizeof(WCHAR
);
2797 ObjectName
.Buffer
+= LastSlash
;
2799 KernelModeName
.Length
= 0;
2800 KernelModeName
.MaximumLength
= sizeof(KernelModeNameBuffer
);
2801 KernelModeName
.Buffer
= KernelModeNameBuffer
;
2803 /* Open \??\xxx (ex: "\??\DISPLAY1") */
2804 Status
= RtlAppendUnicodeToString(&KernelModeName
, L
"\\??\\");
2806 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2807 Status
= RtlAppendUnicodeStringToString(&KernelModeName
, &ObjectName
);
2809 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2810 Status
= ObReferenceObjectByName(
2812 OBJ_CASE_INSENSITIVE
,
2818 (PVOID
*)&DeviceObject
);
2820 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2821 /* Get associated driver name (ex: "VBE") */
2822 for (LastSlash
= DeviceObject
->DriverObject
->DriverName
.Length
/ sizeof(WCHAR
); LastSlash
> 0; LastSlash
--)
2824 if (DeviceObject
->DriverObject
->DriverName
.Buffer
[LastSlash
- 1] == L
'\\')
2828 if (LastSlash
== 0) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2829 ObjectName
= DeviceObject
->DriverObject
->DriverName
;
2830 ObjectName
.Length
-= LastSlash
* sizeof(WCHAR
);
2831 ObjectName
.MaximumLength
-= LastSlash
* sizeof(WCHAR
);
2832 ObjectName
.Buffer
+= LastSlash
;
2834 RegistryKey
.Length
= 0;
2835 RegistryKey
.MaximumLength
= sizeof(RegistryKeyBuffer
);
2836 RegistryKey
.Buffer
= RegistryKeyBuffer
;
2838 /* Open registry key */
2839 Status
= RtlAppendUnicodeToString(&RegistryKey
,
2840 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\");
2842 if (!NT_SUCCESS(Status
)) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2843 Status
= RtlAppendUnicodeStringToString(&RegistryKey
, &ObjectName
);
2845 if (!NT_SUCCESS(Status
)) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2846 Status
= RtlAppendUnicodeToString(&RegistryKey
,
2849 if (!NT_SUCCESS(Status
)) { ObDereferenceObject(DeviceObject
); return DISP_CHANGE_FAILED
; }
2851 InitializeObjectAttributes(&ObjectAttributes
, &RegistryKey
,
2852 OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
2853 Status
= ZwOpenKey(&DevInstRegKey
, GENERIC_READ
| GENERIC_WRITE
, &ObjectAttributes
);
2854 ObDereferenceObject(DeviceObject
);
2855 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2857 /* Update needed fields */
2858 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_BITSPERPEL
)
2860 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.BitsPerPel");
2861 NewValue
= DevMode
->dmBitsPerPel
;
2862 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2865 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSWIDTH
)
2867 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.XResolution");
2868 NewValue
= DevMode
->dmPelsWidth
;
2869 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2872 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSHEIGHT
)
2874 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.YResolution");
2875 NewValue
= DevMode
->dmPelsHeight
;
2876 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2879 ZwClose(DevInstRegKey
);
2880 if (NT_SUCCESS(Status
))
2881 Ret
= DISP_CHANGE_RESTART
;
2883 /* return DISP_CHANGE_NOTUPDATED when we can save to reg only vaild for NT */
2884 Ret
= DISP_CHANGE_NOTUPDATED
;
2889 Ret
= DISP_CHANGE_BADFLAGS
;