3 * ReactOS W32 Subsystem
4 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * DC.C - Device context functions
31 /* ROS Internal. Please deprecate */
35 HalQueryDisplayOwnership(
39 #ifndef OBJ_COLORSPACE
40 #define OBJ_COLORSPACE (14)
43 static GDIDEVICE PrimarySurface
;
44 static KEVENT VideoDriverNeedsPreparation
;
45 static KEVENT VideoDriverPrepared
;
51 KeInitializeEvent(&VideoDriverNeedsPreparation
, SynchronizationEvent
, TRUE
);
52 KeInitializeEvent(&VideoDriverPrepared
, NotificationEvent
, FALSE
);
53 return STATUS_SUCCESS
;
56 /* FIXME: DCs should probably be thread safe */
59 * DC device-independent Get/SetXXX functions
60 * (RJJ) swiped from WINE
63 #define DC_GET_VAL( func_type, func_name, dc_field ) \
64 func_type STDCALL func_name( HDC hdc ) \
67 PDC dc = DC_LockDc( hdc ); \
70 SetLastWin32Error(ERROR_INVALID_HANDLE); \
78 /* DC_GET_VAL_EX is used to define functions returning a POINT or a SIZE. It is
79 * important that the function has the right signature, for the implementation
80 * we can do whatever we want.
82 #define DC_GET_VAL_EX( FuncName, ret_x, ret_y, type, ax, ay ) \
83 VOID FASTCALL Int##FuncName ( PDC dc, LP##type pt) \
90 BOOL STDCALL NtGdi##FuncName ( HDC hdc, LP##type pt ) \
92 NTSTATUS Status = STATUS_SUCCESS; \
97 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
100 if(!(dc = DC_LockDc(hdc))) \
102 SetLastWin32Error(ERROR_INVALID_HANDLE); \
105 Int##FuncName( dc, &Safept); \
116 Status = _SEH_GetExceptionCode(); \
119 if(!NT_SUCCESS(Status)) \
121 SetLastNtError(Status); \
127 #define DC_SET_MODE( func_name, dc_field, min_val, max_val ) \
128 INT STDCALL func_name( HDC hdc, INT mode ) \
132 if ((mode < min_val) || (mode > max_val)) \
134 SetLastWin32Error(ERROR_INVALID_PARAMETER); \
137 dc = DC_LockDc ( hdc ); \
140 SetLastWin32Error(ERROR_INVALID_HANDLE); \
143 prevMode = dc->dc_field; \
144 dc->dc_field = mode; \
145 DC_UnlockDc ( dc ); \
150 // --------------------------------------------------------- File Statics
152 // ----------------------------------------------------- Public Functions
155 NtGdiCancelDC(HDC hDC
)
162 NtGdiCreateCompatibleDC(HDC hDC
)
166 HDC hNewDC
, DisplayDC
;
168 UNICODE_STRING DriverName
;
173 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
174 DisplayDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, TRUE
);
175 if (NULL
== DisplayDC
)
182 /* Allocate a new DC based on the original DC's device */
183 OrigDC
= DC_LockDc(hDC
);
186 if (NULL
!= DisplayDC
)
188 NtGdiDeleteObjectApp(DisplayDC
);
192 hNewDC
= DC_AllocDC(&OrigDC
->DriverName
);
197 if (NULL
!= DisplayDC
)
199 NtGdiDeleteObjectApp(DisplayDC
);
203 NewDC
= DC_LockDc( hNewDC
);
205 /* Copy information from original DC to new DC */
206 NewDC
->hSelf
= hNewDC
;
209 NewDC
->PDev
= OrigDC
->PDev
;
210 memcpy(NewDC
->FillPatternSurfaces
,
211 OrigDC
->FillPatternSurfaces
,
212 sizeof OrigDC
->FillPatternSurfaces
);
213 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
214 NewDC
->DevInfo
= OrigDC
->DevInfo
;
215 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
217 /* DriverName is copied in the AllocDC routine */
218 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
219 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
220 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
221 NewDC
->wndExtX
= OrigDC
->wndExtX
;
222 NewDC
->wndExtY
= OrigDC
->wndExtY
;
223 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
224 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
225 NewDC
->vportExtX
= OrigDC
->vportExtX
;
226 NewDC
->vportExtY
= OrigDC
->vportExtY
;
228 /* Create default bitmap */
229 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
231 DC_UnlockDc( OrigDC
);
232 DC_UnlockDc( NewDC
);
234 if (NULL
!= DisplayDC
)
236 NtGdiDeleteObjectApp(DisplayDC
);
240 NewDC
->w
.flags
= DC_MEMORY
;
241 NewDC
->w
.hBitmap
= hBitmap
;
242 NewDC
->w
.hFirstBitmap
= hBitmap
;
243 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
245 NewDC
->PalIndexed
= OrigDC
->PalIndexed
;
246 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
247 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
248 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
249 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
250 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
251 NewDC
->w
.ROPmode
= OrigDC
->w
.ROPmode
;
254 if (NULL
!= DisplayDC
)
256 NtGdiDeleteObjectApp(DisplayDC
);
259 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
260 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
261 NtGdiDeleteObject(hVisRgn
);
268 static BOOLEAN FASTCALL
269 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
271 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
272 WCHAR DeviceNameBuffer
[20];
275 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%lu", DisplayNumber
);
276 RtlInitUnicodeString(RegistryPath
, NULL
);
277 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
278 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
279 QueryTable
[0].Name
= DeviceNameBuffer
;
280 QueryTable
[0].EntryContext
= RegistryPath
;
282 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
287 if (! NT_SUCCESS(Status
))
289 DPRINT1("No \\Device\\Video%lu value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
293 DPRINT("RegistryPath %wZ\n", RegistryPath
);
299 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
301 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
302 UNICODE_STRING RegistryPath
;
305 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
307 DPRINT("GetRegistryPath failed\n");
311 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
312 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
313 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
314 QueryTable
[0].EntryContext
= DriverFileNames
;
316 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
321 RtlFreeUnicodeString(&RegistryPath
);
322 if (! NT_SUCCESS(Status
))
324 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
328 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
333 static NTSTATUS STDCALL
334 DevModeCallback(IN PWSTR ValueName
,
337 IN ULONG ValueLength
,
339 IN PVOID EntryContext
)
341 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
343 DPRINT("Found registry value for name %S: type %d, length %d\n",
344 ValueName
, ValueType
, ValueLength
);
346 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
348 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
350 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
352 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
354 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
356 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
358 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
360 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
362 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
364 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
366 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
368 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
370 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
372 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
374 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
378 return STATUS_SUCCESS
;
382 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
384 UNICODE_STRING RegistryPath
;
385 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
387 BOOLEAN Valid
= TRUE
;
389 if (!GetRegistryPath(&RegistryPath
, DisplayNumber
))
391 DPRINT("GetRegistryPath failed\n");
395 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
396 QueryTable
[0].QueryRoutine
= DevModeCallback
;
397 QueryTable
[0].Flags
= 0;
398 QueryTable
[0].Name
= NULL
;
399 QueryTable
[0].EntryContext
= NULL
;
400 QueryTable
[0].DefaultType
= REG_NONE
;
401 QueryTable
[0].DefaultData
= NULL
;
402 QueryTable
[0].DefaultLength
= 0;
404 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
409 if (! NT_SUCCESS(Status
))
411 DPRINT("RtlQueryRegistryValues for %wZ failed with status 0x%08x\n",
412 &RegistryPath
, Status
);
417 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
418 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
419 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
420 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
421 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
423 DPRINT("Not all required devmode members are set\n");
428 RtlFreeUnicodeString(&RegistryPath
);
432 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
441 PGD_ENABLEDRIVER GDEnableDriver
;
443 UNICODE_STRING DriverFileNames
;
452 if (STATUS_SUCCESS
!= KeWaitForSingleObject(&VideoDriverNeedsPreparation
, Executive
, KernelMode
, TRUE
, &Zero
))
454 /* Concurrent access. Wait for VideoDriverPrepared event */
455 if (STATUS_SUCCESS
== KeWaitForSingleObject(&VideoDriverPrepared
, Executive
, KernelMode
, TRUE
, NULL
))
456 ret
= PrimarySurface
.PreparedDriver
;
460 for (DisplayNumber
= 0; ; DisplayNumber
++)
462 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
464 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
466 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
468 /* Open the miniport driver */
469 if (PrimarySurface
.VideoFileObject
== NULL
)
471 DPRINT1("FindMPDriver failed\n");
475 /* Retrieve DDI driver names from registry */
476 RtlInitUnicodeString(&DriverFileNames
, NULL
);
477 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
479 DPRINT1("FindDriverFileNames failed\n");
484 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
485 * scan all of them until a good one found.
487 CurrentName
= DriverFileNames
.Buffer
;
490 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
492 /* Get the DDI driver's entry point */
493 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
494 if (NULL
== GDEnableDriver
)
496 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
500 /* Call DDI driver's EnableDriver function */
501 RtlZeroMemory(&DED
, sizeof(DED
));
503 if (! GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof(DED
), &DED
))
505 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
515 /* Skip to the next name but never get past the Unicode string */
516 while (L
'\0' != *CurrentName
&&
517 CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
521 if (CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
)))
528 RtlFreeUnicodeString(&DriverFileNames
);
532 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
533 DPRINT1("No suitable DDI driver found\n");
537 DPRINT("Display driver %S loaded\n", CurrentName
);
539 DPRINT("Building DDI Functions\n");
541 /* Construct DDI driver function dispatch table */
542 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
544 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
545 DPRINT1("BuildDDIFunctions failed\n");
549 /* Allocate a phyical device handle from the driver */
550 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
551 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
553 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
557 PrimarySurface
.FillPatterns
,
558 sizeof(PrimarySurface
.GDIInfo
),
559 (ULONG
*) &PrimarySurface
.GDIInfo
,
560 sizeof(PrimarySurface
.DevInfo
),
561 &PrimarySurface
.DevInfo
,
564 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
565 DoDefault
= (NULL
== PrimarySurface
.PDev
);
568 DPRINT1("DrvEnablePDev with registry parameters failed\n");
578 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
579 PrimarySurface
.DMW
.dmSize
= sizeof (PrimarySurface
.DMW
);
580 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDEV(
584 PrimarySurface
.FillPatterns
,
585 sizeof(PrimarySurface
.GDIInfo
),
586 (ULONG
*) &PrimarySurface
.GDIInfo
,
587 sizeof(PrimarySurface
.DevInfo
),
588 &PrimarySurface
.DevInfo
,
591 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
593 if (NULL
== PrimarySurface
.PDev
)
595 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
596 DPRINT1("DrvEnablePDEV with default parameters failed\n");
597 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
602 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
604 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
605 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
607 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
609 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
610 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
613 PrimarySurface
.Pointer
.Exclude
.right
= -1;
615 DPRINT("calling completePDev\n");
617 /* Complete initialization of the physical device */
618 PrimarySurface
.DriverFunctions
.CompletePDEV(
620 (HDEV
)&PrimarySurface
);
622 DPRINT("calling DRIVER_ReferenceDriver\n");
624 DRIVER_ReferenceDriver(L
"DISPLAY");
626 PrimarySurface
.PreparedDriver
= TRUE
;
627 PrimarySurface
.DisplayNumber
= DisplayNumber
;
634 KeSetEvent(&VideoDriverPrepared
, 1, FALSE
);
639 IntPrepareDriverIfNeeded()
641 return (PrimarySurface
.PreparedDriver
? TRUE
: IntPrepareDriver());
649 IO_STATUS_BLOCK Iosb
;
651 ULONG Length
= sizeof(BOOL
);
652 PIO_STACK_LOCATION StackPtr
;
653 LARGE_INTEGER StartOffset
;
654 PFILE_OBJECT FileObject
= PrimarySurface
.VideoFileObject
;
655 PDEVICE_OBJECT DeviceObject
= FileObject
->DeviceObject
;
657 DPRINT("PrepareVideoPrt() called\n");
659 KeClearEvent(&PrimarySurface
.VideoFileObject
->Event
);
661 ObReferenceObjectByPointer(FileObject
, 0, IoFileObjectType
, KernelMode
);
663 StartOffset
.QuadPart
= 0;
664 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_WRITE
,
676 /* Set up IRP Data */
677 Irp
->Tail
.Overlay
.OriginalFileObject
= FileObject
;
678 Irp
->RequestorMode
= KernelMode
;
679 Irp
->Overlay
.AsynchronousParameters
.UserApcRoutine
= NULL
;
680 Irp
->Overlay
.AsynchronousParameters
.UserApcContext
= NULL
;
681 Irp
->Flags
|= IRP_WRITE_OPERATION
;
683 /* Setup Stack Data */
684 StackPtr
= IoGetNextIrpStackLocation(Irp
);
685 StackPtr
->FileObject
= PrimarySurface
.VideoFileObject
;
686 StackPtr
->Parameters
.Write
.Key
= 0;
688 Status
= IoCallDriver(DeviceObject
, Irp
);
690 if (STATUS_PENDING
== Status
)
692 KeWaitForSingleObject(&FileObject
->Event
, Executive
, KernelMode
, TRUE
, 0);
693 Status
= Iosb
.Status
;
696 return NT_SUCCESS(Status
);
700 IntCreatePrimarySurface()
707 if (! IntPrepareDriverIfNeeded())
712 if (! PrepareVideoPrt())
717 DPRINT("calling EnableSurface\n");
718 /* Enable the drawing surface */
719 PrimarySurface
.Handle
=
720 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
721 if (NULL
== PrimarySurface
.Handle
)
723 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
724 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
725 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
726 DPRINT1("DrvEnableSurface failed\n");
730 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, TRUE
);
732 calledFromUser
= UserIsEntered(); //fixme: possibly upgrade a shared lock
733 if (!calledFromUser
){
734 UserEnterExclusive();
738 IntAttachMonitor(&PrimarySurface
, PrimarySurface
.DisplayNumber
);
740 SurfObj
= EngLockSurface((HSURF
)PrimarySurface
.Handle
);
741 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
742 SurfSize
= SurfObj
->sizlBitmap
;
743 SurfaceRect
.left
= SurfaceRect
.top
= 0;
744 SurfaceRect
.right
= SurfObj
->sizlBitmap
.cx
;
745 SurfaceRect
.bottom
= SurfObj
->sizlBitmap
.cy
;
746 /* FIXME - why does EngEraseSurface() sometimes crash?
747 EngEraseSurface(SurfObj, &SurfaceRect, 0); */
749 /* Put the pointer in the center of the screen */
750 GDIDEV(SurfObj
)->Pointer
.Pos
.x
= (SurfaceRect
.right
- SurfaceRect
.left
) / 2;
751 GDIDEV(SurfObj
)->Pointer
.Pos
.y
= (SurfaceRect
.bottom
- SurfaceRect
.top
) / 2;
753 EngUnlockSurface(SurfObj
);
754 co_IntShowDesktop(IntGetActiveDesktop(), SurfSize
.cx
, SurfSize
.cy
);
756 if (!calledFromUser
){
764 IntDestroyPrimarySurface()
768 DRIVER_UnreferenceDriver(L
"DISPLAY");
770 calledFromUser
= UserIsEntered();
771 if (!calledFromUser
){
772 UserEnterExclusive();
776 IntDetachMonitor(&PrimarySurface
);
778 if (!calledFromUser
){
783 * FIXME: Hide a mouse pointer there. Also because we have to prevent
784 * memory leaks with the Eng* mouse routines.
787 DPRINT("Reseting display\n" );
788 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
789 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
790 PrimarySurface
.DriverFunctions
.DisablePDEV(PrimarySurface
.PDev
);
791 PrimarySurface
.PreparedDriver
= FALSE
;
795 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
799 IntGdiCreateDC(PUNICODE_STRING Driver
,
800 PUNICODE_STRING Device
,
801 PUNICODE_STRING Output
,
802 CONST PDEVMODEW InitData
,
809 UNICODE_STRING StdDriver
;
812 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
814 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
818 if (! IntPrepareDriverIfNeeded())
820 DPRINT1("Unable to prepare graphics driver, returning NULL ic\n");
826 calledFromUser
= UserIsEntered();
827 if (!calledFromUser
){
828 UserEnterExclusive();
831 if (! co_IntGraphicsCheck(TRUE
))
833 if (!calledFromUser
){
836 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
840 if (!calledFromUser
){
847 /* Check for existing DC object */
848 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
851 return NtGdiCreateCompatibleDC(hDC
);
854 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
856 DPRINT("NAME: %wZ\n", Driver
); // FIXME: Should not crash if NULL
859 /* Allocate a DC object */
860 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
865 NewDC
= DC_LockDc( hNewDC
);
866 /* FIXME - NewDC can be NULL!!! Don't assert here! */
873 NewDC
->IsIC
= CreateAsIC
;
874 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
875 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
876 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
877 sizeof(NewDC
->FillPatternSurfaces
));
878 NewDC
->PDev
= PrimarySurface
.PDev
;
879 NewDC
->GDIDevice
= (HDEV
)&PrimarySurface
;
880 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
881 NewDC
->w
.hBitmap
= PrimarySurface
.Handle
;
883 NewDC
->w
.bitsPerPixel
= NewDC
->GDIInfo
->cBitsPixel
* NewDC
->GDIInfo
->cPlanes
;
884 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
888 NewDC
->PalIndexed
= NtGdiGetStockObject(DEFAULT_PALETTE
);
889 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
890 NewDC
->w
.ROPmode
= R2_COPYPEN
;
892 DC_UnlockDc( NewDC
);
894 hVisRgn
= NtGdiCreateRectRgn(0, 0, NewDC
->GDIInfo
->ulHorzRes
,
895 NewDC
->GDIInfo
->ulVertRes
);
896 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
897 NtGdiDeleteObject(hVisRgn
);
899 /* Initialize the DC state */
901 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
902 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
903 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
904 NtGdiSetBkMode(hNewDC
, OPAQUE
);
908 DC_UnlockDc( NewDC
);
915 NtGdiCreateDC(PUNICODE_STRING Driver
,
916 PUNICODE_STRING Device
,
917 PUNICODE_STRING Output
,
918 CONST PDEVMODEW InitData
)
920 UNICODE_STRING SafeDriver
, SafeDevice
;
921 DEVMODEW SafeInitData
;
923 NTSTATUS Status
= STATUS_SUCCESS
;
929 ProbeForRead(InitData
,
932 RtlCopyMemory(&SafeInitData
,
938 Status
= _SEH_GetExceptionCode();
942 if(!NT_SUCCESS(Status
))
944 SetLastNtError(Status
);
947 /* FIXME - InitData can have some more bytes! */
952 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
953 if(!NT_SUCCESS(Status
))
955 SetLastNtError(Status
);
962 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
963 if(!NT_SUCCESS(Status
))
965 RtlFreeUnicodeString(&SafeDriver
);
966 SetLastNtError(Status
);
971 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
972 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
973 NULL
== InitData
? NULL
: &SafeInitData
, FALSE
);
979 NtGdiCreateIC(PUNICODE_STRING Driver
,
980 PUNICODE_STRING Device
,
981 PUNICODE_STRING Output
,
982 CONST PDEVMODEW InitData
)
984 UNICODE_STRING SafeDriver
, SafeDevice
;
985 DEVMODEW SafeInitData
;
987 NTSTATUS Status
= STATUS_SUCCESS
;
993 ProbeForRead(InitData
,
996 RtlCopyMemory(&SafeInitData
,
1002 Status
= _SEH_GetExceptionCode();
1005 if(!NT_SUCCESS(Status
))
1007 SetLastNtError(Status
);
1010 /* FIXME - InitData can have some more bytes! */
1015 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
1016 if(!NT_SUCCESS(Status
))
1018 SetLastNtError(Status
);
1025 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
1026 if(!NT_SUCCESS(Status
))
1028 RtlFreeUnicodeString(&SafeDriver
);
1029 SetLastNtError(Status
);
1034 Ret
= IntGdiCreateDC(NULL
== Driver
? NULL
: &SafeDriver
,
1035 NULL
== Device
? NULL
: &SafeDevice
, NULL
,
1036 NULL
== InitData
? NULL
: &SafeInitData
, TRUE
);
1042 NtGdiDeleteObjectApp(HANDLE DCHandle
)
1046 if (!GDIOBJ_OwnedByCurrentProcess(GdiHandleTable
, DCHandle
))
1048 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1052 DCToDelete
= DC_LockDc(DCHandle
);
1053 if (DCToDelete
== NULL
)
1055 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1059 /* First delete all saved DCs */
1060 while (DCToDelete
->saveLevel
)
1065 savedHDC
= DC_GetNextDC (DCToDelete
);
1066 savedDC
= DC_LockDc (savedHDC
);
1067 if (savedDC
== NULL
)
1071 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
1072 DCToDelete
->saveLevel
--;
1073 DC_UnlockDc( savedDC
);
1074 NtGdiDeleteObjectApp (savedHDC
);
1077 /* Free GDI resources allocated to this DC */
1078 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
1081 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
1082 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
1083 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
1084 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
1085 if (DCToDelete
->w
.flags
& DC_MEMORY
)
1087 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
1089 if (DCToDelete
->XlateBrush
!= NULL
)
1090 EngDeleteXlate(DCToDelete
->XlateBrush
);
1091 if (DCToDelete
->XlatePen
!= NULL
)
1092 EngDeleteXlate(DCToDelete
->XlatePen
);
1094 if (DCToDelete
->w
.hClipRgn
)
1096 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
1098 if (DCToDelete
->w
.hVisRgn
)
1100 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
1102 if (NULL
!= DCToDelete
->CombinedClip
)
1104 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
1106 if (DCToDelete
->w
.hGCClipRgn
)
1108 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
1111 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
1113 DC_UnlockDc( DCToDelete
);
1114 DC_FreeDC ( DCHandle
);
1125 IN OPTIONAL LPSTR pjIn
)
1137 OUT OPTIONAL PVOID pvBuf
)
1143 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
1144 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
1145 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
1146 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
1149 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
1154 /* From Wine: GetCurrentObject does not SetLastError() on a null object */
1155 if(!hDC
) return NULL
;
1157 if(!(dc
= DC_LockDc(hDC
)))
1159 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1166 SelObject
= dc
->w
.hPen
;
1169 SelObject
= dc
->w
.hBrush
;
1172 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
1176 SelObject
= dc
->w
.hFont
;
1179 SelObject
= dc
->w
.hBitmap
;
1181 case OBJ_COLORSPACE
:
1182 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
1187 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1195 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
1198 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
1200 Point
->x
= dc
->w
.DCOrgX
;
1201 Point
->y
= dc
->w
.DCOrgY
;
1207 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1212 NTSTATUS Status
= STATUS_SUCCESS
;
1216 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1220 dc
= DC_LockDc(hDC
);
1223 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1227 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1231 ProbeForWrite(Point
,
1238 Status
= _SEH_GetExceptionCode();
1242 if(!NT_SUCCESS(Status
))
1244 SetLastNtError(Status
);
1254 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1260 if (!(dc
= DC_LockDc(hDC
)))
1262 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1266 oldColor
= dc
->w
.backgroundColor
;
1267 dc
->w
.backgroundColor
= color
;
1268 hBrush
= dc
->w
.hBrush
;
1270 NtGdiSelectObject(hDC
, hBrush
);
1275 NtGdiGetDCState(HDC hDC
)
1280 dc
= DC_LockDc(hDC
);
1283 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1287 hnewdc
= DC_AllocDC(NULL
);
1293 newdc
= DC_LockDc( hnewdc
);
1294 /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
1297 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1298 newdc
->w
.hPen
= dc
->w
.hPen
;
1299 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1300 newdc
->w
.hFont
= dc
->w
.hFont
;
1301 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1302 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1304 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1306 newdc
->PalIndexed
= dc
->PalIndexed
;
1307 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1308 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1309 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1310 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1311 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1312 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1313 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1314 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1315 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1316 newdc
->w
.textColor
= dc
->w
.textColor
;
1317 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1318 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1319 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1320 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1321 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1322 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1323 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1324 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1325 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1326 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1328 /* Apparently, the DC origin is not changed by [GS]etDCState */
1329 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1330 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1332 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1333 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1334 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1335 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1336 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1337 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1338 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1339 newdc
->wndOrgX
= dc
->wndOrgX
;
1340 newdc
->wndOrgY
= dc
->wndOrgY
;
1341 newdc
->wndExtX
= dc
->wndExtX
;
1342 newdc
->wndExtY
= dc
->wndExtY
;
1343 newdc
->vportOrgX
= dc
->vportOrgX
;
1344 newdc
->vportOrgY
= dc
->vportOrgY
;
1345 newdc
->vportExtX
= dc
->vportExtX
;
1346 newdc
->vportExtY
= dc
->vportExtY
;
1348 newdc
->hSelf
= hnewdc
;
1349 newdc
->saveLevel
= 0;
1350 newdc
->IsIC
= dc
->IsIC
;
1353 PATH_InitGdiPath( &newdc
->w
.path
);
1356 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1358 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1361 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1362 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1364 DC_UnlockDc( newdc
);
1372 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1376 dc
= DC_LockDc ( hDC
);
1379 dcs
= DC_LockDc ( hDCSave
);
1382 if ( dcs
->w
.flags
& DC_SAVED
)
1384 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1386 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1389 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1392 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1393 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1394 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1395 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1396 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1397 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1398 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1399 dc
->w
.textColor
= dcs
->w
.textColor
;
1400 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1401 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1402 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1403 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1404 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1405 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1406 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1407 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1408 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1409 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1411 /* Apparently, the DC origin is not changed by [GS]etDCState */
1412 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1413 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1415 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1416 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1417 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1419 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1420 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1421 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1422 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1424 dc
->wndOrgX
= dcs
->wndOrgX
;
1425 dc
->wndOrgY
= dcs
->wndOrgY
;
1426 dc
->wndExtX
= dcs
->wndExtX
;
1427 dc
->wndExtY
= dcs
->wndExtY
;
1428 dc
->vportOrgX
= dcs
->vportOrgX
;
1429 dc
->vportOrgY
= dcs
->vportOrgY
;
1430 dc
->vportExtX
= dcs
->vportExtX
;
1431 dc
->vportExtY
= dcs
->vportExtY
;
1432 dc
->PalIndexed
= dcs
->PalIndexed
;
1434 if (!(dc
->w
.flags
& DC_MEMORY
))
1436 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1440 if (dcs
->w
.hClipRgn
)
1442 if (!dc
->w
.hClipRgn
)
1444 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1446 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1452 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1459 res
= CLIPPING_UpdateGCRegion( dc
);
1460 ASSERT ( res
!= ERROR
);
1465 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1468 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1469 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1470 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1471 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1472 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1473 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1475 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1478 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1483 DC_UnlockDc ( dcs
);
1486 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1490 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1494 IntGdiGetDeviceCaps(PDC dc
, INT Index
)
1499 /* Retrieve capability */
1503 ret
= dc
->GDIInfo
->ulVersion
;
1507 ret
= dc
->GDIInfo
->ulTechnology
;
1511 ret
= dc
->GDIInfo
->ulHorzSize
;
1515 ret
= dc
->GDIInfo
->ulVertSize
;
1519 ret
= dc
->GDIInfo
->ulHorzRes
;
1523 ret
= dc
->GDIInfo
->ulVertRes
;
1527 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1531 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1535 ret
= dc
->GDIInfo
->cBitsPixel
;
1539 ret
= dc
->GDIInfo
->cPlanes
;
1543 UNIMPLEMENTED
; /* FIXME */
1547 UNIMPLEMENTED
; /* FIXME */
1551 UNIMPLEMENTED
; /* FIXME */
1555 ret
= dc
->GDIInfo
->ulNumColors
;
1559 ret
= dc
->GDIInfo
->ulAspectX
;
1563 ret
= dc
->GDIInfo
->ulAspectY
;
1567 ret
= dc
->GDIInfo
->ulAspectXY
;
1571 UNIMPLEMENTED
; /* FIXME */
1575 UNIMPLEMENTED
; /* FIXME */
1579 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1587 UNIMPLEMENTED
; /* FIXME */
1591 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1601 case PHYSICALHEIGHT
:
1602 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1612 case PHYSICALOFFSETX
:
1613 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1623 case PHYSICALOFFSETY
:
1624 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1635 UNIMPLEMENTED
; /* FIXME */
1638 case SCALINGFACTORX
:
1639 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1649 case SCALINGFACTORY
:
1650 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1661 ret
= dc
->GDIInfo
->flRaster
;
1665 UNIMPLEMENTED
; /* FIXME */
1669 UNIMPLEMENTED
; /* FIXME */
1673 UNIMPLEMENTED
; /* FIXME */
1677 ret
= dc
->GDIInfo
->flTextCaps
;
1689 NtGdiGetDeviceCaps(HDC hDC
,
1695 dc
= DC_LockDc(hDC
);
1698 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1702 ret
= IntGdiGetDeviceCaps(dc
, Index
);
1704 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1710 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1711 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1714 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1720 GdiObject
= GDIOBJ_LockObj(GdiHandleTable
, Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1721 if (NULL
== GdiObject
)
1723 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1727 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1731 case GDI_OBJECT_TYPE_PEN
:
1732 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1734 case GDI_OBJECT_TYPE_BRUSH
:
1735 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1738 case GDI_OBJECT_TYPE_BITMAP
:
1739 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1741 case GDI_OBJECT_TYPE_FONT
:
1742 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1744 // Fix the LOGFONT structure for the stock fonts
1745 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1747 FixStockFontSizeW(Handle
, Count
, Buffer
);
1752 case GDI_OBJECT_TYPE_PALETTE
:
1753 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1757 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1761 GDIOBJ_UnlockObjByPtr(GdiHandleTable
, GdiObject
);
1767 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1771 NTSTATUS Status
= STATUS_SUCCESS
;
1773 /* From Wine: GetObject does not SetLastError() on a null object */
1774 if (!handle
) return 0;
1783 ProbeForWrite(buffer
,
1789 Status
= _SEH_GetExceptionCode();
1793 if(!NT_SUCCESS(Status
))
1795 SetLastNtError(Status
);
1799 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1802 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1806 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1810 /* pointer already probed! */
1811 RtlCopyMemory(buffer
,
1817 Status
= _SEH_GetExceptionCode();
1821 ExFreePool(SafeBuf
);
1822 if(!NT_SUCCESS(Status
))
1824 SetLastNtError(Status
);
1832 NtGdiGetObjectType(HANDLE handle
)
1838 ptr
= GDIOBJ_LockObj(GdiHandleTable
, handle
, GDI_OBJECT_TYPE_DONTCARE
);
1841 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1845 objectType
= GDIOBJ_GetObjectType(handle
);
1848 case GDI_OBJECT_TYPE_PEN
:
1851 case GDI_OBJECT_TYPE_BRUSH
:
1854 case GDI_OBJECT_TYPE_BITMAP
:
1855 result
= OBJ_BITMAP
;
1857 case GDI_OBJECT_TYPE_FONT
:
1860 case GDI_OBJECT_TYPE_PALETTE
:
1863 case GDI_OBJECT_TYPE_REGION
:
1864 result
= OBJ_REGION
;
1866 case GDI_OBJECT_TYPE_DC
:
1869 case GDI_OBJECT_TYPE_METADC
:
1870 result
= OBJ_METADC
;
1872 case GDI_OBJECT_TYPE_METAFILE
:
1873 result
= OBJ_METAFILE
;
1875 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1876 result
= OBJ_ENHMETAFILE
;
1878 case GDI_OBJECT_TYPE_ENHMETADC
:
1879 result
= OBJ_ENHMETADC
;
1881 case GDI_OBJECT_TYPE_EXTPEN
:
1882 result
= OBJ_EXTPEN
;
1884 case GDI_OBJECT_TYPE_MEMDC
:
1889 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1893 GDIOBJ_UnlockObjByPtr(GdiHandleTable
, ptr
);
1897 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1898 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1899 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1900 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1901 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1902 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1903 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1904 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1905 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1912 OUT PBOOL pbBanding
,
1913 IN OPTIONAL VOID
*pDriverInfo2
,
1914 OUT VOID
*ppUMdhpdev
)
1921 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1926 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1928 dc
= DC_LockDc(hDC
);
1931 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1935 if (SaveLevel
== -1)
1936 SaveLevel
= dc
->saveLevel
;
1938 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1945 while (dc
->saveLevel
>= SaveLevel
)
1947 HDC hdcs
= DC_GetNextDC (dc
);
1949 dcs
= DC_LockDc (hdcs
);
1955 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1956 if (--dc
->saveLevel
< SaveLevel
)
1960 NtGdiSetDCState(hDC
, hdcs
);
1962 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1964 /* FIXME: This might not be quite right, since we're
1965 * returning FALSE but still destroying the saved DC state */
1969 dc
= DC_LockDc(hDC
);
1979 NtGdiDeleteObjectApp (hdcs
);
1986 NtGdiSaveDC(HDC hDC
)
1992 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
1994 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1999 dcs
= DC_LockDc (hdcs
);
2002 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2005 dc
= DC_LockDc (hDC
);
2009 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2014 /* Copy path. The reason why path saving / restoring is in SaveDC/
2015 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
2016 * functions are only in Win16 (which doesn't have paths) and that
2017 * SetDCState doesn't allow us to signal an error (which can happen
2018 * when copying paths).
2020 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
2022 NtGdiDeleteObjectApp (hdcs
);
2027 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
2028 DC_SetNextDC (dc
, hdcs
);
2029 ret
= ++dc
->saveLevel
;
2038 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
2040 HGDIOBJ objOrg
= NULL
; // default to failure
2050 if (!hDC
|| !hGDIObj
)
2053 * SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE.
2054 * Note: Under XP at least invalid ptrs can also be passed, not just NULL;
2055 * Don't test that here in case it crashes earlier win versions.
2057 if (!hDC
) SetLastWin32Error(ERROR_INVALID_HANDLE
);
2061 dc
= DC_LockDc(hDC
);
2064 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2068 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
2072 case GDI_OBJECT_TYPE_PEN
:
2073 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
2076 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2080 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
2081 PENOBJ_UnlockPen(pen
);
2084 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2088 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
2089 dc
->w
.hPen
= hGDIObj
;
2090 if (dc
->XlatePen
!= NULL
)
2091 EngDeleteXlate(dc
->XlatePen
);
2092 dc
->XlatePen
= XlateObj
;
2095 case GDI_OBJECT_TYPE_BRUSH
:
2096 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
2099 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2103 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
2104 BRUSHOBJ_UnlockBrush(brush
);
2107 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2111 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
2112 dc
->w
.hBrush
= hGDIObj
;
2113 if (dc
->XlateBrush
!= NULL
)
2114 EngDeleteXlate(dc
->XlateBrush
);
2115 dc
->XlateBrush
= XlateObj
;
2118 case GDI_OBJECT_TYPE_FONT
:
2119 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
2121 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
2122 dc
->w
.hFont
= (HFONT
) hGDIObj
;
2126 case GDI_OBJECT_TYPE_BITMAP
:
2127 // must be memory dc to select bitmap
2128 if (!(dc
->w
.flags
& DC_MEMORY
))
2133 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
2136 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2140 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
2142 /* Release the old bitmap, lock the new one and convert it to a SURF */
2143 dc
->w
.hBitmap
= hGDIObj
;
2145 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
2148 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
2149 dc
->w
.hPalette
= pb
->hDIBPalette
;
2153 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
2154 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
2157 /* Reselect brush and pen to regenerate the XLATEOBJs. */
2158 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
2159 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
2162 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
2163 BITMAPOBJ_UnlockBitmap( pb
);
2164 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
2165 NtGdiDeleteObject ( hVisRgn
);
2169 case GDI_OBJECT_TYPE_REGION
:
2172 * The return value is one of the following values:
2177 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
2187 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
2190 DC
*dc
= DC_LockDc(hDC
);
2194 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2198 wRet
= dc
->w
.flags
& DC_DIRTY
;
2200 /* "Undocumented Windows" info is slightly confusing.
2203 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
2205 if (Flags
& DCHF_INVALIDATEVISRGN
)
2207 dc
->w
.flags
|= DC_DIRTY
;
2209 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
2211 dc
->w
.flags
&= ~DC_DIRTY
;
2219 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
2220 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
2221 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
2222 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
2223 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
2225 // ---------------------------------------------------- Private Interface
2228 DC_AllocDC(PUNICODE_STRING Driver
)
2236 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
2241 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
2244 hDC
= (HDC
) GDIOBJ_AllocObj(GdiHandleTable
, GDI_OBJECT_TYPE_DC
);
2254 NewDC
= DC_LockDc(hDC
);
2255 /* FIXME - Handle NewDC == NULL! */
2259 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2260 NewDC
->DriverName
.Buffer
= Buf
;
2263 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2264 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2265 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2266 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2267 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2268 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2269 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2270 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2271 NewDC
->w
.vport2WorldValid
= TRUE
;
2272 NewDC
->w
.MapMode
= MM_TEXT
;
2273 NewDC
->wndExtX
= 1.0f
;
2274 NewDC
->wndExtY
= 1.0f
;
2275 NewDC
->vportExtX
= 1.0f
;
2276 NewDC
->vportExtY
= 1.0f
;
2277 NewDC
->w
.textColor
= 0;
2278 NewDC
->w
.backgroundColor
= 0xffffff;
2280 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2281 TextIntRealizeFont(NewDC
->w
.hFont
);
2283 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2291 DC_FindOpenDC(PUNICODE_STRING Driver
)
2297 * Initialize some common fields in the Device Context structure.
2300 DC_InitDC(HDC DCHandle
)
2302 // NtGdiRealizeDefaultPalette(DCHandle);
2304 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2305 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2306 //NtGdiSelectObject(DCHandle, hFont);
2311 res = CLIPPING_UpdateGCRegion(DCToInit);
2312 ASSERT ( res != ERROR );
2318 DC_FreeDC(HDC DCToFree
)
2320 if (!GDIOBJ_FreeObj(GdiHandleTable
, DCToFree
, GDI_OBJECT_TYPE_DC
))
2322 DPRINT("DC_FreeDC failed\n");
2327 DC_Cleanup(PVOID ObjectBody
)
2329 PDC pDC
= (PDC
)ObjectBody
;
2330 RtlFreeUnicodeString(&pDC
->DriverName
);
2335 DC_GetNextDC (PDC pDC
)
2341 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2343 pDC
->hNext
= hNextDC
;
2347 DC_UpdateXforms(PDC dc
)
2349 XFORM xformWnd2Vport
;
2350 FLOAT scaleX
, scaleY
;
2352 /* Construct a transformation to do the window-to-viewport conversion */
2353 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2354 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2355 xformWnd2Vport
.eM11
= scaleX
;
2356 xformWnd2Vport
.eM12
= 0.0;
2357 xformWnd2Vport
.eM21
= 0.0;
2358 xformWnd2Vport
.eM22
= scaleY
;
2359 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2360 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2362 /* Combine with the world transformation */
2363 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2365 /* Create inverse of world-to-viewport transformation */
2366 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2370 DC_InvertXform(const XFORM
*xformSrc
,
2375 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2376 if (determinant
> -1e-12 && determinant
< 1e-12)
2381 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2382 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2383 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2384 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2385 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2386 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2392 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2396 GDIOBJ_SetOwnership(GdiHandleTable
, hDC
, Owner
);
2397 DC
= DC_LockDc(hDC
);
2400 if (NULL
!= DC
->w
.hClipRgn
)
2402 GDIOBJ_CopyOwnership(GdiHandleTable
, hDC
, DC
->w
.hClipRgn
);
2404 if (NULL
!= DC
->w
.hVisRgn
)
2406 GDIOBJ_CopyOwnership(GdiHandleTable
, hDC
, DC
->w
.hVisRgn
);
2408 if (NULL
!= DC
->w
.hGCClipRgn
)
2410 GDIOBJ_CopyOwnership(GdiHandleTable
, hDC
, DC
->w
.hGCClipRgn
);
2417 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2419 if (PrimarySurface
.Handle
== NULL
)
2423 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2427 * Returns the color of the brush or pen that is currently selected into the DC.
2428 * This function is called from GetDCBrushColor() and GetDCPenColor()
2431 IntGetDCColor(HDC hDC
, ULONG Object
)
2434 * The previous implementation was completly incorrect. It modified the
2435 * brush that was currently selected into the device context, but in fact
2436 * the DC pen/brush color should be stored directly in the device context
2437 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2438 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2439 * into the device context and BRUSHOBJ for drawing is composed (belongs
2440 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2441 * the implementation should be moved to user mode GDI32.dll when UM
2442 * mapped GDI objects will be implemented.
2445 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2446 return 0xFFFFFF; /* The default DC color. */
2450 * Changes the color of the brush or pen that is currently selected into the DC.
2451 * This function is called from SetDCBrushColor() and SetDCPenColor()
2454 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2456 /* See the comment in IntGetDCColor. */
2458 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2462 #define SIZEOF_DEVMODEW_300 188
2463 #define SIZEOF_DEVMODEW_400 212
2464 #define SIZEOF_DEVMODEW_500 220
2466 /*! \brief Enumerate possible display settings for the given display...
2468 * \todo Make thread safe!?
2469 * \todo Don't ignore pDeviceName
2470 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2473 IntEnumDisplaySettings(
2474 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2476 IN OUT LPDEVMODEW pDevMode
,
2479 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2480 static DWORD SizeOfCachedDevModes
= 0;
2481 PDEVMODEW CachedMode
= NULL
;
2484 ULONG DisplayNumber
= 0; /* only default display supported */
2486 DPRINT("DevMode->dmSize = %d\n", pDevMode
->dmSize
);
2487 DPRINT("DevMode->dmExtraSize = %d\n", pDevMode
->dmDriverExtra
);
2488 if (pDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2489 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2490 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2492 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2496 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2498 CachedMode
= &PrimarySurface
.DMW
;
2499 ASSERT(CachedMode
->dmSize
> 0);
2501 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2503 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2504 DevMode
.dmSize
= sizeof (DevMode
);
2505 DevMode
.dmDriverExtra
= 0;
2506 if (SetupDevMode(&DevMode
, DisplayNumber
))
2507 CachedMode
= &DevMode
;
2510 SetLastWin32Error(0); /* FIXME: use error code */
2513 /* FIXME: Maybe look for the matching devmode supplied by the
2514 * driver so we can provide driver private/extra data?
2519 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2521 BOOL PrimarySurfaceCreated
= FALSE
;
2522 UNICODE_STRING DriverFileNames
;
2524 DRVENABLEDATA DrvEnableData
;
2526 /* Retrieve DDI driver names from registry */
2527 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2528 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2530 DPRINT1("FindDriverFileNames failed\n");
2534 if (!HalQueryDisplayOwnership())
2536 IntCreatePrimarySurface();
2537 PrimarySurfaceCreated
= TRUE
;
2541 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2542 * scan all of them until a good one found.
2544 CurrentName
= DriverFileNames
.Buffer
;
2545 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2546 CurrentName
+= wcslen(CurrentName
) + 1)
2549 PGD_ENABLEDRIVER GDEnableDriver
;
2551 /* Get the DDI driver's entry point */
2552 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2553 if (NULL
== GDEnableDriver
)
2555 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2559 /* Call DDI driver's EnableDriver function */
2560 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2562 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2564 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2568 CachedDevModesEnd
= CachedDevModes
;
2570 /* find DrvGetModes function */
2571 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2573 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2574 PGD_GETMODES GetModes
;
2575 INT SizeNeeded
, SizeUsed
;
2577 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2580 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2582 /* make sure we have enough memory to hold the modes */
2583 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2584 if (SizeNeeded
<= 0)
2586 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2590 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2591 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2595 SizeOfCachedDevModes
+= SizeNeeded
;
2596 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2597 if (NewBuffer
== NULL
)
2600 ExFreePool(CachedDevModes
);
2601 SizeOfCachedDevModes
= 0;
2602 CachedDevModes
= NULL
;
2603 CachedDevModesEnd
= NULL
;
2604 if (PrimarySurfaceCreated
)
2606 IntDestroyPrimarySurface();
2608 SetLastWin32Error(STATUS_NO_MEMORY
);
2611 if (CachedDevModes
!= NULL
)
2613 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2614 ExFreePool(CachedDevModes
);
2616 CachedDevModes
= NewBuffer
;
2617 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2621 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2622 SizeOfCachedDevModes
- SizeUsed
,
2624 if (SizeNeeded
<= 0)
2626 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2630 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2636 if (PrimarySurfaceCreated
)
2638 IntDestroyPrimarySurface();
2641 RtlFreeUnicodeString(&DriverFileNames
);
2644 /* return cached info */
2645 CachedMode
= CachedDevModes
;
2646 if (CachedMode
>= CachedDevModesEnd
)
2648 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2651 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2653 assert(CachedMode
->dmSize
> 0);
2654 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2656 if (CachedMode
>= CachedDevModesEnd
)
2658 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2663 ASSERT(CachedMode
!= NULL
);
2665 Size
= OldSize
= pDevMode
->dmSize
;
2666 if (Size
> CachedMode
->dmSize
)
2667 Size
= CachedMode
->dmSize
;
2668 RtlCopyMemory(pDevMode
, CachedMode
, Size
);
2669 RtlZeroMemory((PCHAR
)pDevMode
+ Size
, OldSize
- Size
);
2670 pDevMode
->dmSize
= OldSize
;
2672 Size
= OldSize
= pDevMode
->dmDriverExtra
;
2673 if (Size
> CachedMode
->dmDriverExtra
)
2674 Size
= CachedMode
->dmDriverExtra
;
2675 RtlCopyMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
,
2676 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2677 RtlZeroMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
+ Size
, OldSize
- Size
);
2678 pDevMode
->dmDriverExtra
= OldSize
;
2683 static NTSTATUS FASTCALL
2685 OUT PUNICODE_STRING VideoDeviceName
,
2686 IN PCUNICODE_STRING DisplayDevice
) /* ex: "\.\DISPLAY1" or "\??\DISPLAY1" */
2688 UNICODE_STRING Prefix
= RTL_CONSTANT_STRING(L
"\\??\\");
2689 UNICODE_STRING ObjectName
;
2690 UNICODE_STRING KernelModeName
= { 0, };
2691 OBJECT_ATTRIBUTES ObjectAttributes
;
2694 HANDLE LinkHandle
= NULL
;
2697 RtlInitUnicodeString(VideoDeviceName
, NULL
);
2699 /* Get device name (DisplayDevice is "\.\xxx") */
2700 for (LastSlash
= DisplayDevice
->Length
/ sizeof(WCHAR
); LastSlash
> 0; LastSlash
--)
2702 if (DisplayDevice
->Buffer
[LastSlash
- 1] == L
'\\')
2708 DPRINT1("Invalid device name '%wZ'\n", DisplayDevice
);
2709 Status
= STATUS_OBJECT_NAME_INVALID
;
2712 ObjectName
= *DisplayDevice
;
2713 ObjectName
.Length
-= LastSlash
* sizeof(WCHAR
);
2714 ObjectName
.MaximumLength
-= LastSlash
* sizeof(WCHAR
);
2715 ObjectName
.Buffer
+= LastSlash
;
2717 /* Create "\??\xxx" (ex: "\??\DISPLAY1") */
2718 KernelModeName
.MaximumLength
= Prefix
.Length
+ ObjectName
.Length
+ sizeof(UNICODE_NULL
);
2719 KernelModeName
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
2720 KernelModeName
.MaximumLength
,
2722 if (!KernelModeName
.Buffer
)
2724 Status
= STATUS_NO_MEMORY
;
2727 RtlCopyUnicodeString(&KernelModeName
, &Prefix
);
2728 Status
= RtlAppendUnicodeStringToString(&KernelModeName
, &ObjectName
);
2729 if (!NT_SUCCESS(Status
))
2732 /* Open \??\xxx (ex: "\??\DISPLAY1") */
2733 InitializeObjectAttributes(&ObjectAttributes
,
2738 Status
= ZwOpenSymbolicLinkObject(&LinkHandle
,
2741 if (!NT_SUCCESS(Status
))
2743 DPRINT1("Unable to open symbolic link %wZ (Status 0x%08lx)\n", &KernelModeName
, Status
);
2744 Status
= STATUS_NO_SUCH_DEVICE
;
2748 Status
= ZwQuerySymbolicLinkObject(LinkHandle
, VideoDeviceName
, &Length
);
2749 if (!NT_SUCCESS(Status
) && Status
!= STATUS_BUFFER_TOO_SMALL
)
2751 DPRINT1("Unable to query symbolic link %wZ (Status 0x%08lx)\n", &KernelModeName
, Status
);
2752 Status
= STATUS_NO_SUCH_DEVICE
;
2755 VideoDeviceName
->MaximumLength
= Length
;
2756 VideoDeviceName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
2757 VideoDeviceName
->MaximumLength
+ sizeof(UNICODE_NULL
),
2759 if (!VideoDeviceName
->Buffer
)
2761 Status
= STATUS_NO_MEMORY
;
2764 Status
= ZwQuerySymbolicLinkObject(LinkHandle
, VideoDeviceName
, NULL
);
2765 VideoDeviceName
->Buffer
[VideoDeviceName
->MaximumLength
/ sizeof(WCHAR
) - 1] = UNICODE_NULL
;
2766 if (!NT_SUCCESS(Status
))
2768 DPRINT1("Unable to query symbolic link %wZ (Status 0x%08lx)\n", &KernelModeName
, Status
);
2769 Status
= STATUS_NO_SUCH_DEVICE
;
2772 Status
= STATUS_SUCCESS
;
2775 if (!NT_SUCCESS(Status
) && VideoDeviceName
->Buffer
)
2776 ExFreePoolWithTag(VideoDeviceName
->Buffer
, TAG_DC
);
2777 if (KernelModeName
.Buffer
)
2778 ExFreePoolWithTag(KernelModeName
.Buffer
, TAG_DC
);
2780 ZwClose(LinkHandle
);
2784 static NTSTATUS FASTCALL
2785 GetVideoRegistryKey(
2786 OUT PUNICODE_STRING RegistryPath
,
2787 IN PCUNICODE_STRING DeviceName
) /* ex: "\Device\Video0" */
2789 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2792 RtlInitUnicodeString(RegistryPath
, NULL
);
2793 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
2794 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
2795 QueryTable
[0].Name
= DeviceName
->Buffer
;
2796 QueryTable
[0].EntryContext
= RegistryPath
;
2798 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
2803 if (!NT_SUCCESS(Status
))
2805 DPRINT1("No %wZ value in DEVICEMAP\\VIDEO found (Status 0x%08lx)\n", DeviceName
, Status
);
2806 return STATUS_NO_SUCH_DEVICE
;
2809 DPRINT("RegistryPath %wZ\n", RegistryPath
);
2810 return STATUS_SUCCESS
;
2815 IntChangeDisplaySettings(
2816 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2817 IN LPDEVMODEW DevMode
,
2819 IN PVOID lParam OPTIONAL
)
2821 BOOLEAN Global
= FALSE
;
2822 BOOLEAN NoReset
= FALSE
;
2823 BOOLEAN Reset
= FALSE
;
2824 BOOLEAN SetPrimary
= FALSE
;
2828 DPRINT1("display flag : %x\n",dwflags
);
2830 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2832 /* Check global, reset and noreset flags */
2833 if ((dwflags
& CDS_GLOBAL
) == CDS_GLOBAL
)
2835 if ((dwflags
& CDS_NORESET
) == CDS_NORESET
)
2837 dwflags
&= ~(CDS_GLOBAL
| CDS_NORESET
);
2839 if ((dwflags
& CDS_RESET
) == CDS_RESET
)
2841 if ((dwflags
& CDS_SET_PRIMARY
) == CDS_SET_PRIMARY
)
2843 dwflags
&= ~(CDS_RESET
| CDS_SET_PRIMARY
);
2845 if (Reset
&& NoReset
)
2846 return DISP_CHANGE_BADFLAGS
;
2850 /* Dynamically change graphics mode */
2851 DPRINT1("flag 0 UNIMPLEMENT \n");
2852 return DISP_CHANGE_FAILED
;
2855 if ((dwflags
& CDS_TEST
) == CDS_TEST
)
2857 /* Test reslution */
2858 dwflags
&= ~CDS_TEST
;
2859 DPRINT1("flag CDS_TEST UNIMPLEMENT");
2860 Ret
= DISP_CHANGE_FAILED
;
2863 if ((dwflags
& CDS_FULLSCREEN
) == CDS_FULLSCREEN
)
2867 dwflags
&= ~CDS_FULLSCREEN
;
2868 DPRINT1("flag CDS_FULLSCREEN partially implemented");
2869 Ret
= DISP_CHANGE_FAILED
;
2871 lpDevMode
.dmBitsPerPel
=0;
2872 lpDevMode
.dmPelsWidth
=0;
2873 lpDevMode
.dmPelsHeight
=0;
2874 lpDevMode
.dmDriverExtra
=0;
2876 lpDevMode
.dmSize
= sizeof(DEVMODE
);
2877 Status
= IntEnumDisplaySettings(pDeviceName
, ENUM_CURRENT_SETTINGS
, &lpDevMode
, 0);
2878 if (!NT_SUCCESS(Status
)) return DISP_CHANGE_FAILED
;
2880 DPRINT1("Req Mode : %d x %d x %d\n", DevMode
->dmPelsWidth
,DevMode
->dmPelsHeight
,DevMode
->dmBitsPerPel
);
2881 DPRINT1("Current Mode : %d x %d x %d\n", lpDevMode
.dmPelsWidth
,lpDevMode
.dmPelsHeight
, lpDevMode
.dmBitsPerPel
);
2884 if ((lpDevMode
.dmBitsPerPel
== DevMode
->dmBitsPerPel
) &&
2885 (lpDevMode
.dmPelsWidth
== DevMode
->dmPelsWidth
) &&
2886 (lpDevMode
.dmPelsHeight
== DevMode
->dmPelsHeight
))
2887 Ret
= DISP_CHANGE_SUCCESSFUL
;
2890 if ((dwflags
& CDS_VIDEOPARAMETERS
) == CDS_VIDEOPARAMETERS
)
2892 dwflags
&= ~CDS_VIDEOPARAMETERS
;
2894 Ret
=DISP_CHANGE_BADPARAM
;
2897 DPRINT1("flag CDS_VIDEOPARAMETERS UNIMPLEMENT");
2898 Ret
= DISP_CHANGE_FAILED
;
2903 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2906 UNICODE_STRING DeviceName
;
2907 UNICODE_STRING RegistryKey
;
2908 OBJECT_ATTRIBUTES ObjectAttributes
;
2909 HANDLE DevInstRegKey
;
2912 DPRINT1("set CDS_UPDATEREGISTRY \n");
2914 dwflags
&= ~CDS_UPDATEREGISTRY
;
2916 Status
= GetVideoDeviceName(&DeviceName
, pDeviceName
);
2917 if (!NT_SUCCESS(Status
))
2919 DPRINT1("Unable to get destination of '%wZ' (Status 0x%08lx)\n", pDeviceName
, Status
);
2920 return DISP_CHANGE_FAILED
;
2922 Status
= GetVideoRegistryKey(&RegistryKey
, &DeviceName
);
2923 if (!NT_SUCCESS(Status
))
2925 DPRINT1("Unable to get registry key for '%wZ' (Status 0x%08lx)\n", &DeviceName
, Status
);
2926 ExFreePoolWithTag(DeviceName
.Buffer
, TAG_DC
);
2927 return DISP_CHANGE_FAILED
;
2929 ExFreePoolWithTag(DeviceName
.Buffer
, TAG_DC
);
2931 InitializeObjectAttributes(&ObjectAttributes
, &RegistryKey
,
2932 OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
2933 Status
= ZwOpenKey(&DevInstRegKey
, GENERIC_READ
| GENERIC_WRITE
, &ObjectAttributes
);
2934 if (!NT_SUCCESS(Status
))
2936 DPRINT1("Unable to open registry key %wZ (Status 0x%08lx)\n", &RegistryKey
, Status
);
2937 ExFreePoolWithTag(RegistryKey
.Buffer
, TAG_DC
);
2938 return DISP_CHANGE_FAILED
;
2940 ExFreePoolWithTag(RegistryKey
.Buffer
, TAG_DC
);
2942 /* Update needed fields */
2943 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_BITSPERPEL
)
2945 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.BitsPerPel");
2946 NewValue
= DevMode
->dmBitsPerPel
;
2947 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2950 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSWIDTH
)
2952 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.XResolution");
2953 NewValue
= DevMode
->dmPelsWidth
;
2954 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2957 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSHEIGHT
)
2959 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.YResolution");
2960 NewValue
= DevMode
->dmPelsHeight
;
2961 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2964 ZwClose(DevInstRegKey
);
2965 if (NT_SUCCESS(Status
))
2966 Ret
= DISP_CHANGE_RESTART
;
2968 /* return DISP_CHANGE_NOTUPDATED when we can save to reg only valid for NT */
2969 Ret
= DISP_CHANGE_NOTUPDATED
;
2973 Ret
= DISP_CHANGE_BADFLAGS
;