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 NtGdiOpenDCW( PUNICODE_STRING pustrDevice
,
1044 PUNICODE_STRING pustrLogAddr
,
1055 NtGdiDeleteObjectApp(HANDLE DCHandle
)
1059 if (!GDIOBJ_OwnedByCurrentProcess(GdiHandleTable
, DCHandle
))
1061 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1065 DCToDelete
= DC_LockDc(DCHandle
);
1066 if (DCToDelete
== NULL
)
1068 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1072 /* First delete all saved DCs */
1073 while (DCToDelete
->saveLevel
)
1078 savedHDC
= DC_GetNextDC (DCToDelete
);
1079 savedDC
= DC_LockDc (savedHDC
);
1080 if (savedDC
== NULL
)
1084 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
1085 DCToDelete
->saveLevel
--;
1086 DC_UnlockDc( savedDC
);
1087 NtGdiDeleteObjectApp (savedHDC
);
1090 /* Free GDI resources allocated to this DC */
1091 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
1094 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
1095 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
1096 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
1097 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
1098 if (DCToDelete
->w
.flags
& DC_MEMORY
)
1100 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
1102 if (DCToDelete
->XlateBrush
!= NULL
)
1103 EngDeleteXlate(DCToDelete
->XlateBrush
);
1104 if (DCToDelete
->XlatePen
!= NULL
)
1105 EngDeleteXlate(DCToDelete
->XlatePen
);
1107 if (DCToDelete
->w
.hClipRgn
)
1109 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
1111 if (DCToDelete
->w
.hVisRgn
)
1113 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
1115 if (NULL
!= DCToDelete
->CombinedClip
)
1117 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
1119 if (DCToDelete
->w
.hGCClipRgn
)
1121 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
1124 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
1127 if (DCToDelete
->emh
)
1129 EngFreeMem(DCToDelete
->emh
);
1132 DC_UnlockDc( DCToDelete
);
1133 DC_FreeDC ( DCHandle
);
1144 IN OPTIONAL LPSTR pjIn
)
1156 OUT OPTIONAL PVOID pvBuf
)
1162 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
1163 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
1164 DC_GET_VAL_EX( GetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
, x
, y
)
1165 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
1168 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
1173 /* From Wine: GetCurrentObject does not SetLastError() on a null object */
1174 if(!hDC
) return NULL
;
1176 if(!(dc
= DC_LockDc(hDC
)))
1178 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1185 SelObject
= dc
->w
.hPen
;
1188 SelObject
= dc
->w
.hBrush
;
1191 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_PAL not supported yet!\n");
1195 SelObject
= dc
->w
.hFont
;
1198 SelObject
= dc
->w
.hBitmap
;
1200 case OBJ_COLORSPACE
:
1201 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
1206 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1214 DC_GET_VAL_EX ( GetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
, x
, y
)
1217 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
1219 Point
->x
= dc
->w
.DCOrgX
;
1220 Point
->y
= dc
->w
.DCOrgY
;
1226 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
1231 NTSTATUS Status
= STATUS_SUCCESS
;
1235 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1239 dc
= DC_LockDc(hDC
);
1242 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1246 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
1250 ProbeForWrite(Point
,
1257 Status
= _SEH_GetExceptionCode();
1261 if(!NT_SUCCESS(Status
))
1263 SetLastNtError(Status
);
1273 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
1279 if (!(dc
= DC_LockDc(hDC
)))
1281 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1285 oldColor
= dc
->w
.backgroundColor
;
1286 dc
->w
.backgroundColor
= color
;
1287 hBrush
= dc
->w
.hBrush
;
1289 NtGdiSelectObject(hDC
, hBrush
);
1294 NtGdiGetDCState(HDC hDC
)
1299 dc
= DC_LockDc(hDC
);
1302 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1306 hnewdc
= DC_AllocDC(NULL
);
1312 newdc
= DC_LockDc( hnewdc
);
1313 /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
1316 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1317 newdc
->w
.hPen
= dc
->w
.hPen
;
1318 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1319 newdc
->w
.hFont
= dc
->w
.hFont
;
1320 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1321 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1323 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1325 newdc
->PalIndexed
= dc
->PalIndexed
;
1326 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1327 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1328 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1329 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1330 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1331 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1332 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1333 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1334 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1335 newdc
->w
.textColor
= dc
->w
.textColor
;
1336 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1337 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1338 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1339 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1340 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1341 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1342 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1343 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1344 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1345 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1347 /* Apparently, the DC origin is not changed by [GS]etDCState */
1348 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1349 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1351 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1352 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1353 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1354 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1355 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1356 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1357 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1358 newdc
->wndOrgX
= dc
->wndOrgX
;
1359 newdc
->wndOrgY
= dc
->wndOrgY
;
1360 newdc
->wndExtX
= dc
->wndExtX
;
1361 newdc
->wndExtY
= dc
->wndExtY
;
1362 newdc
->vportOrgX
= dc
->vportOrgX
;
1363 newdc
->vportOrgY
= dc
->vportOrgY
;
1364 newdc
->vportExtX
= dc
->vportExtX
;
1365 newdc
->vportExtY
= dc
->vportExtY
;
1367 newdc
->hSelf
= hnewdc
;
1368 newdc
->saveLevel
= 0;
1369 newdc
->IsIC
= dc
->IsIC
;
1372 PATH_InitGdiPath( &newdc
->w
.path
);
1375 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1377 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1380 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1381 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1383 DC_UnlockDc( newdc
);
1391 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1395 dc
= DC_LockDc ( hDC
);
1398 dcs
= DC_LockDc ( hDCSave
);
1401 if ( dcs
->w
.flags
& DC_SAVED
)
1403 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1405 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1408 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1411 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1412 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1413 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1414 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1415 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1416 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1417 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1418 dc
->w
.textColor
= dcs
->w
.textColor
;
1419 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1420 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1421 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1422 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1423 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1424 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1425 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1426 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1427 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1428 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1430 /* Apparently, the DC origin is not changed by [GS]etDCState */
1431 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1432 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1434 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1435 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1436 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1438 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1439 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1440 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1441 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1443 dc
->wndOrgX
= dcs
->wndOrgX
;
1444 dc
->wndOrgY
= dcs
->wndOrgY
;
1445 dc
->wndExtX
= dcs
->wndExtX
;
1446 dc
->wndExtY
= dcs
->wndExtY
;
1447 dc
->vportOrgX
= dcs
->vportOrgX
;
1448 dc
->vportOrgY
= dcs
->vportOrgY
;
1449 dc
->vportExtX
= dcs
->vportExtX
;
1450 dc
->vportExtY
= dcs
->vportExtY
;
1451 dc
->PalIndexed
= dcs
->PalIndexed
;
1453 if (!(dc
->w
.flags
& DC_MEMORY
))
1455 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1459 if (dcs
->w
.hClipRgn
)
1461 if (!dc
->w
.hClipRgn
)
1463 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1465 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1471 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1478 res
= CLIPPING_UpdateGCRegion( dc
);
1479 ASSERT ( res
!= ERROR
);
1484 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1487 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1488 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1489 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1490 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1491 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1492 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1494 NtGdiSelectPalette( hDC
, dcs
->w
.hPalette
, FALSE
);
1497 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1502 DC_UnlockDc ( dcs
);
1505 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1509 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1513 IntGdiGetDeviceCaps(PDC dc
, INT Index
)
1518 /* Retrieve capability */
1522 ret
= dc
->GDIInfo
->ulVersion
;
1526 ret
= dc
->GDIInfo
->ulTechnology
;
1530 ret
= dc
->GDIInfo
->ulHorzSize
;
1534 ret
= dc
->GDIInfo
->ulVertSize
;
1538 ret
= dc
->GDIInfo
->ulHorzRes
;
1542 ret
= dc
->GDIInfo
->ulVertRes
;
1546 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1550 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1554 ret
= dc
->GDIInfo
->cBitsPixel
;
1558 ret
= dc
->GDIInfo
->cPlanes
;
1562 UNIMPLEMENTED
; /* FIXME */
1566 UNIMPLEMENTED
; /* FIXME */
1570 UNIMPLEMENTED
; /* FIXME */
1574 ret
= dc
->GDIInfo
->ulNumColors
;
1578 ret
= dc
->GDIInfo
->ulAspectX
;
1582 ret
= dc
->GDIInfo
->ulAspectY
;
1586 ret
= dc
->GDIInfo
->ulAspectXY
;
1590 UNIMPLEMENTED
; /* FIXME */
1594 UNIMPLEMENTED
; /* FIXME */
1598 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1606 UNIMPLEMENTED
; /* FIXME */
1610 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1620 case PHYSICALHEIGHT
:
1621 if(IntGdiEscape(dc
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1631 case PHYSICALOFFSETX
:
1632 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1642 case PHYSICALOFFSETY
:
1643 if(IntGdiEscape(dc
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1654 UNIMPLEMENTED
; /* FIXME */
1657 case SCALINGFACTORX
:
1658 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1668 case SCALINGFACTORY
:
1669 if(IntGdiEscape(dc
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1680 ret
= dc
->GDIInfo
->flRaster
;
1684 UNIMPLEMENTED
; /* FIXME */
1688 UNIMPLEMENTED
; /* FIXME */
1692 UNIMPLEMENTED
; /* FIXME */
1696 ret
= dc
->GDIInfo
->flTextCaps
;
1708 NtGdiGetDeviceCaps(HDC hDC
,
1714 dc
= DC_LockDc(hDC
);
1717 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1721 ret
= IntGdiGetDeviceCaps(dc
, Index
);
1723 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1729 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1730 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1734 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1740 GdiObject
= GDIOBJ_LockObj(GdiHandleTable
, Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1741 if (NULL
== GdiObject
)
1743 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1747 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1751 case GDI_OBJECT_TYPE_PEN
:
1752 Result
= PEN_GetObject((PGDIBRUSHOBJ
) GdiObject
, Count
, (PLOGPEN
) Buffer
); // IntGdiCreatePenIndirect
1755 case GDI_OBJECT_TYPE_BRUSH
:
1756 Result
= BRUSH_GetObject((PGDIBRUSHOBJ
) GdiObject
, Count
, (LPLOGBRUSH
)Buffer
);
1759 case GDI_OBJECT_TYPE_BITMAP
:
1760 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1762 case GDI_OBJECT_TYPE_FONT
:
1763 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1765 // Fix the LOGFONT structure for the stock fonts
1766 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1768 FixStockFontSizeW(Handle
, Count
, Buffer
);
1773 case GDI_OBJECT_TYPE_PALETTE
:
1774 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1778 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1782 GDIOBJ_UnlockObjByPtr(GdiHandleTable
, GdiObject
);
1788 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1792 NTSTATUS Status
= STATUS_SUCCESS
;
1794 /* From Wine: GetObject does not SetLastError() on a null object */
1795 if (!handle
) return 0;
1804 ProbeForWrite(buffer
,
1810 Status
= _SEH_GetExceptionCode();
1814 if(!NT_SUCCESS(Status
))
1816 SetLastNtError(Status
);
1820 SafeBuf
= ExAllocatePoolWithTag(PagedPool
, count
, TAG_GDIOBJ
);
1823 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1827 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1831 /* pointer already probed! */
1832 RtlCopyMemory(buffer
,
1838 Status
= _SEH_GetExceptionCode();
1842 ExFreePool(SafeBuf
);
1843 if(!NT_SUCCESS(Status
))
1845 SetLastNtError(Status
);
1853 NtGdiGetObjectType(HANDLE handle
)
1859 ptr
= GDIOBJ_LockObj(GdiHandleTable
, handle
, GDI_OBJECT_TYPE_DONTCARE
);
1862 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1866 objectType
= GDIOBJ_GetObjectType(handle
);
1869 case GDI_OBJECT_TYPE_PEN
:
1872 case GDI_OBJECT_TYPE_BRUSH
:
1875 case GDI_OBJECT_TYPE_BITMAP
:
1876 result
= OBJ_BITMAP
;
1878 case GDI_OBJECT_TYPE_FONT
:
1881 case GDI_OBJECT_TYPE_PALETTE
:
1884 case GDI_OBJECT_TYPE_REGION
:
1885 result
= OBJ_REGION
;
1887 case GDI_OBJECT_TYPE_DC
:
1890 case GDI_OBJECT_TYPE_METADC
:
1891 result
= OBJ_METADC
;
1893 case GDI_OBJECT_TYPE_METAFILE
:
1894 result
= OBJ_METAFILE
;
1896 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1897 result
= OBJ_ENHMETAFILE
;
1899 case GDI_OBJECT_TYPE_ENHMETADC
:
1900 result
= OBJ_ENHMETADC
;
1902 case GDI_OBJECT_TYPE_EXTPEN
:
1903 result
= OBJ_EXTPEN
;
1905 case GDI_OBJECT_TYPE_MEMDC
:
1910 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1914 GDIOBJ_UnlockObjByPtr(GdiHandleTable
, ptr
);
1918 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1919 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1920 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1921 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1922 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1923 DC_GET_VAL_EX( GetViewportExtEx
, vportExtX
, vportExtY
, SIZE
, cx
, cy
)
1924 DC_GET_VAL_EX( GetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
, x
, y
)
1925 DC_GET_VAL_EX( GetWindowExtEx
, wndExtX
, wndExtY
, SIZE
, cx
, cy
)
1926 DC_GET_VAL_EX( GetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
, x
, y
)
1933 OUT PBOOL pbBanding
,
1934 IN OPTIONAL VOID
*pDriverInfo2
,
1935 OUT VOID
*ppUMdhpdev
)
1942 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1947 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hDC
, SaveLevel
);
1949 dc
= DC_LockDc(hDC
);
1952 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1956 if(abs(SaveLevel
) > dc
->saveLevel
|| SaveLevel
== 0)
1962 /* FIXME this calc are not 100% correct I think ??*/
1963 if (SaveLevel
< 0) SaveLevel
= dc
->saveLevel
+ SaveLevel
+ 1;
1966 while (dc
->saveLevel
>= SaveLevel
)
1968 HDC hdcs
= DC_GetNextDC (dc
);
1970 dcs
= DC_LockDc (hdcs
);
1977 DC_SetNextDC (dc
, DC_GetNextDC (dcs
));
1980 if (--dc
->saveLevel
< SaveLevel
)
1985 NtGdiSetDCState(hDC
, hdcs
);
1986 //if (!PATH_AssignGdiPath( &dc->path, &dcs->path ))
1987 /* FIXME: This might not be quite right, since we're
1988 * returning FALSE but still destroying the saved DC state
1991 dc
= DC_LockDc(hDC
);
2001 NtGdiDeleteObjectApp (hdcs
);
2009 NtGdiSaveDC(HDC hDC
)
2015 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
2017 if (!(hdcs
= NtGdiGetDCState(hDC
)))
2022 dcs
= DC_LockDc (hdcs
);
2025 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2028 dc
= DC_LockDc (hDC
);
2032 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2037 /* Copy path. The reason why path saving / restoring is in SaveDC/
2038 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
2039 * functions are only in Win16 (which doesn't have paths) and that
2040 * SetDCState doesn't allow us to signal an error (which can happen
2041 * when copying paths).
2043 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
2045 NtGdiDeleteObjectApp (hdcs
);
2050 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
2051 DC_SetNextDC (dc
, hdcs
);
2052 ret
= ++dc
->saveLevel
;
2061 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
2063 HGDIOBJ objOrg
= NULL
; // default to failure
2073 if (!hDC
|| !hGDIObj
)
2076 * SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE.
2077 * Note: Under XP at least invalid ptrs can also be passed, not just NULL;
2078 * Don't test that here in case it crashes earlier win versions.
2080 if (!hDC
) SetLastWin32Error(ERROR_INVALID_HANDLE
);
2084 dc
= DC_LockDc(hDC
);
2087 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2091 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
2095 case GDI_OBJECT_TYPE_PEN
:
2096 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
2099 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2103 XlateObj
= IntGdiCreateBrushXlate(dc
, pen
, &Failed
);
2104 PENOBJ_UnlockPen(pen
);
2107 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2111 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
2112 dc
->w
.hPen
= hGDIObj
;
2113 if (dc
->XlatePen
!= NULL
)
2114 EngDeleteXlate(dc
->XlatePen
);
2115 dc
->XlatePen
= XlateObj
;
2118 case GDI_OBJECT_TYPE_BRUSH
:
2119 brush
= BRUSHOBJ_LockBrush((HPEN
) hGDIObj
);
2122 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2126 XlateObj
= IntGdiCreateBrushXlate(dc
, brush
, &Failed
);
2127 BRUSHOBJ_UnlockBrush(brush
);
2130 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
2134 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
2135 dc
->w
.hBrush
= hGDIObj
;
2136 if (dc
->XlateBrush
!= NULL
)
2137 EngDeleteXlate(dc
->XlateBrush
);
2138 dc
->XlateBrush
= XlateObj
;
2141 case GDI_OBJECT_TYPE_FONT
:
2142 if(NT_SUCCESS(TextIntRealizeFont((HFONT
)hGDIObj
)))
2144 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
2145 dc
->w
.hFont
= (HFONT
) hGDIObj
;
2149 case GDI_OBJECT_TYPE_BITMAP
:
2150 // must be memory dc to select bitmap
2151 if (!(dc
->w
.flags
& DC_MEMORY
))
2156 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
2159 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2163 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
2165 /* Release the old bitmap, lock the new one and convert it to a SURF */
2166 dc
->w
.hBitmap
= hGDIObj
;
2168 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
2171 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
2172 dc
->w
.hPalette
= pb
->hDIBPalette
;
2176 dc
->w
.bitsPerPixel
= BitsPerFormat(pb
->SurfObj
.iBitmapFormat
);
2177 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
2180 /* Reselect brush and pen to regenerate the XLATEOBJs. */
2181 NtGdiSelectObject ( hDC
, dc
->w
.hBrush
);
2182 NtGdiSelectObject ( hDC
, dc
->w
.hPen
);
2185 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->SurfObj
.sizlBitmap
.cx
, pb
->SurfObj
.sizlBitmap
.cy
);
2186 BITMAPOBJ_UnlockBitmap( pb
);
2187 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
2188 NtGdiDeleteObject ( hVisRgn
);
2192 case GDI_OBJECT_TYPE_REGION
:
2195 * The return value is one of the following values:
2200 return (HGDIOBJ
) NtGdiSelectClipRgn(hDC
, (HRGN
) hGDIObj
);
2210 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
2213 DC
*dc
= DC_LockDc(hDC
);
2217 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2221 wRet
= dc
->w
.flags
& DC_DIRTY
;
2223 /* "Undocumented Windows" info is slightly confusing.
2226 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
2228 if (Flags
& DCHF_INVALIDATEVISRGN
)
2230 dc
->w
.flags
|= DC_DIRTY
;
2232 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
2234 dc
->w
.flags
&= ~DC_DIRTY
;
2242 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
2243 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
2244 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
2245 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
2246 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
2248 // ---------------------------------------------------- Private Interface
2251 DC_AllocDC(PUNICODE_STRING Driver
)
2259 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
2264 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
2267 hDC
= (HDC
) GDIOBJ_AllocObj(GdiHandleTable
, GDI_OBJECT_TYPE_DC
);
2277 NewDC
= DC_LockDc(hDC
);
2278 /* FIXME - Handle NewDC == NULL! */
2282 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
2283 NewDC
->DriverName
.Buffer
= Buf
;
2286 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
2287 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
2288 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
2289 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
2290 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
2291 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
2292 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
2293 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
2294 NewDC
->w
.vport2WorldValid
= TRUE
;
2295 NewDC
->w
.MapMode
= MM_TEXT
;
2296 NewDC
->wndExtX
= 1.0f
;
2297 NewDC
->wndExtY
= 1.0f
;
2298 NewDC
->vportExtX
= 1.0f
;
2299 NewDC
->vportExtY
= 1.0f
;
2300 NewDC
->w
.textColor
= 0;
2301 NewDC
->w
.backgroundColor
= 0xffffff;
2303 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
2304 TextIntRealizeFont(NewDC
->w
.hFont
);
2306 NewDC
->w
.hPalette
= NtGdiGetStockObject(DEFAULT_PALETTE
);
2314 DC_FindOpenDC(PUNICODE_STRING Driver
)
2320 * Initialize some common fields in the Device Context structure.
2323 DC_InitDC(HDC DCHandle
)
2325 // NtGdiRealizeDefaultPalette(DCHandle);
2327 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2328 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2329 //NtGdiSelectObject(DCHandle, hFont);
2334 res = CLIPPING_UpdateGCRegion(DCToInit);
2335 ASSERT ( res != ERROR );
2341 DC_FreeDC(HDC DCToFree
)
2343 if (!GDIOBJ_FreeObj(GdiHandleTable
, DCToFree
, GDI_OBJECT_TYPE_DC
))
2345 DPRINT("DC_FreeDC failed\n");
2350 DC_Cleanup(PVOID ObjectBody
)
2352 PDC pDC
= (PDC
)ObjectBody
;
2353 RtlFreeUnicodeString(&pDC
->DriverName
);
2358 DC_GetNextDC (PDC pDC
)
2364 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2366 pDC
->hNext
= hNextDC
;
2370 DC_UpdateXforms(PDC dc
)
2372 XFORM xformWnd2Vport
;
2373 FLOAT scaleX
, scaleY
;
2375 /* Construct a transformation to do the window-to-viewport conversion */
2376 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0f
);
2377 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0f
);
2378 xformWnd2Vport
.eM11
= scaleX
;
2379 xformWnd2Vport
.eM12
= 0.0;
2380 xformWnd2Vport
.eM21
= 0.0;
2381 xformWnd2Vport
.eM22
= scaleY
;
2382 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2383 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2385 /* Combine with the world transformation */
2386 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2388 /* Create inverse of world-to-viewport transformation */
2389 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2393 DC_InvertXform(const XFORM
*xformSrc
,
2398 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2399 if (determinant
> -1e-12 && determinant
< 1e-12)
2404 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2405 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2406 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2407 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2408 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2409 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2415 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2419 GDIOBJ_SetOwnership(GdiHandleTable
, hDC
, Owner
);
2420 DC
= DC_LockDc(hDC
);
2423 if (NULL
!= DC
->w
.hClipRgn
)
2425 GDIOBJ_CopyOwnership(GdiHandleTable
, hDC
, DC
->w
.hClipRgn
);
2427 if (NULL
!= DC
->w
.hVisRgn
)
2429 GDIOBJ_CopyOwnership(GdiHandleTable
, hDC
, DC
->w
.hVisRgn
);
2431 if (NULL
!= DC
->w
.hGCClipRgn
)
2433 GDIOBJ_CopyOwnership(GdiHandleTable
, hDC
, DC
->w
.hGCClipRgn
);
2440 IntIsPrimarySurface(SURFOBJ
*SurfObj
)
2442 if (PrimarySurface
.Handle
== NULL
)
2446 return SurfObj
->hsurf
== PrimarySurface
.Handle
;
2450 * Returns the color of the brush or pen that is currently selected into the DC.
2451 * This function is called from GetDCBrushColor() and GetDCPenColor()
2454 IntGetDCColor(HDC hDC
, ULONG Object
)
2457 * The previous implementation was completly incorrect. It modified the
2458 * brush that was currently selected into the device context, but in fact
2459 * the DC pen/brush color should be stored directly in the device context
2460 * (at address 0x2C of the user mode DC object memory on Windows 2K/XP).
2461 * The actual color is then used when DC_BRUSH/DC_PEN object is selected
2462 * into the device context and BRUSHOBJ for drawing is composed (belongs
2463 * to IntGdiInitBrushInstance in the current ReactOS implementation). Also
2464 * the implementation should be moved to user mode GDI32.dll when UM
2465 * mapped GDI objects will be implemented.
2468 DPRINT("WIN32K:IntGetDCColor is unimplemented\n");
2469 return 0xFFFFFF; /* The default DC color. */
2473 * Changes the color of the brush or pen that is currently selected into the DC.
2474 * This function is called from SetDCBrushColor() and SetDCPenColor()
2477 IntSetDCColor(HDC hDC
, ULONG Object
, COLORREF Color
)
2479 /* See the comment in IntGetDCColor. */
2481 DPRINT("WIN32K:IntSetDCColor is unimplemented\n");
2485 #define SIZEOF_DEVMODEW_300 188
2486 #define SIZEOF_DEVMODEW_400 212
2487 #define SIZEOF_DEVMODEW_500 220
2489 /*! \brief Enumerate possible display settings for the given display...
2491 * \todo Make thread safe!?
2492 * \todo Don't ignore pDeviceName
2493 * \todo Implement non-raw mode (only return settings valid for driver and monitor)
2496 IntEnumDisplaySettings(
2497 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2499 IN OUT LPDEVMODEW pDevMode
,
2502 static DEVMODEW
*CachedDevModes
= NULL
, *CachedDevModesEnd
= NULL
;
2503 static DWORD SizeOfCachedDevModes
= 0;
2504 PDEVMODEW CachedMode
= NULL
;
2507 ULONG DisplayNumber
= 0; /* only default display supported */
2509 DPRINT("DevMode->dmSize = %d\n", pDevMode
->dmSize
);
2510 DPRINT("DevMode->dmExtraSize = %d\n", pDevMode
->dmDriverExtra
);
2511 if (pDevMode
->dmSize
!= SIZEOF_DEVMODEW_300
&&
2512 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_400
&&
2513 pDevMode
->dmSize
!= SIZEOF_DEVMODEW_500
)
2515 SetLastWin32Error(STATUS_INVALID_PARAMETER
);
2519 if (iModeNum
== ENUM_CURRENT_SETTINGS
)
2521 CachedMode
= &PrimarySurface
.DMW
;
2522 ASSERT(CachedMode
->dmSize
> 0);
2524 else if (iModeNum
== ENUM_REGISTRY_SETTINGS
)
2526 RtlZeroMemory(&DevMode
, sizeof (DevMode
));
2527 DevMode
.dmSize
= sizeof (DevMode
);
2528 DevMode
.dmDriverExtra
= 0;
2529 if (SetupDevMode(&DevMode
, DisplayNumber
))
2530 CachedMode
= &DevMode
;
2533 SetLastWin32Error(0); /* FIXME: use error code */
2536 /* FIXME: Maybe look for the matching devmode supplied by the
2537 * driver so we can provide driver private/extra data?
2542 if (iModeNum
== 0 || CachedDevModes
== NULL
) /* query modes from drivers */
2544 UNICODE_STRING DriverFileNames
;
2546 DRVENABLEDATA DrvEnableData
;
2548 /* Retrieve DDI driver names from registry */
2549 RtlInitUnicodeString(&DriverFileNames
, NULL
);
2550 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
2552 DPRINT1("FindDriverFileNames failed\n");
2556 IntPrepareDriverIfNeeded();
2559 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
2560 * scan all of them until a good one found.
2562 CurrentName
= DriverFileNames
.Buffer
;
2563 for (;CurrentName
< DriverFileNames
.Buffer
+ (DriverFileNames
.Length
/ sizeof (WCHAR
));
2564 CurrentName
+= wcslen(CurrentName
) + 1)
2567 PGD_ENABLEDRIVER GDEnableDriver
;
2569 /* Get the DDI driver's entry point */
2570 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
2571 if (NULL
== GDEnableDriver
)
2573 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
2577 /* Call DDI driver's EnableDriver function */
2578 RtlZeroMemory(&DrvEnableData
, sizeof (DrvEnableData
));
2580 if (!GDEnableDriver(DDI_DRIVER_VERSION_NT5_01
, sizeof (DrvEnableData
), &DrvEnableData
))
2582 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
2586 CachedDevModesEnd
= CachedDevModes
;
2588 /* find DrvGetModes function */
2589 for (i
= 0; i
< DrvEnableData
.c
; i
++)
2591 PDRVFN DrvFn
= DrvEnableData
.pdrvfn
+ i
;
2592 PGD_GETMODES GetModes
;
2593 INT SizeNeeded
, SizeUsed
;
2595 if (DrvFn
->iFunc
!= INDEX_DrvGetModes
)
2598 GetModes
= (PGD_GETMODES
)DrvFn
->pfn
;
2600 /* make sure we have enough memory to hold the modes */
2601 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
), 0, NULL
);
2602 if (SizeNeeded
<= 0)
2604 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2608 SizeUsed
= CachedDevModesEnd
- CachedDevModes
;
2609 if (SizeOfCachedDevModes
- SizeUsed
< SizeNeeded
)
2613 SizeOfCachedDevModes
+= SizeNeeded
;
2614 NewBuffer
= ExAllocatePool(PagedPool
, SizeOfCachedDevModes
);
2615 if (NewBuffer
== NULL
)
2618 ExFreePool(CachedDevModes
);
2619 SizeOfCachedDevModes
= 0;
2620 CachedDevModes
= NULL
;
2621 CachedDevModesEnd
= NULL
;
2622 SetLastWin32Error(STATUS_NO_MEMORY
);
2625 if (CachedDevModes
!= NULL
)
2627 RtlCopyMemory(NewBuffer
, CachedDevModes
, SizeUsed
);
2628 ExFreePool(CachedDevModes
);
2630 CachedDevModes
= NewBuffer
;
2631 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)NewBuffer
+ SizeUsed
);
2635 SizeNeeded
= GetModes((HANDLE
)(PrimarySurface
.VideoFileObject
->DeviceObject
),
2636 SizeOfCachedDevModes
- SizeUsed
,
2638 if (SizeNeeded
<= 0)
2640 DPRINT("DrvGetModes failed for %S\n", CurrentName
);
2644 CachedDevModesEnd
= (DEVMODEW
*)((PCHAR
)CachedDevModesEnd
+ SizeNeeded
);
2650 RtlFreeUnicodeString(&DriverFileNames
);
2653 /* return cached info */
2654 CachedMode
= CachedDevModes
;
2655 if (CachedMode
>= CachedDevModesEnd
)
2657 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2660 while (iModeNum
-- > 0 && CachedMode
< CachedDevModesEnd
)
2662 assert(CachedMode
->dmSize
> 0);
2663 CachedMode
= (DEVMODEW
*)((PCHAR
)CachedMode
+ CachedMode
->dmSize
+ CachedMode
->dmDriverExtra
);
2665 if (CachedMode
>= CachedDevModesEnd
)
2667 SetLastWin32Error(STATUS_NO_MORE_ENTRIES
);
2672 ASSERT(CachedMode
!= NULL
);
2674 Size
= OldSize
= pDevMode
->dmSize
;
2675 if (Size
> CachedMode
->dmSize
)
2676 Size
= CachedMode
->dmSize
;
2677 RtlCopyMemory(pDevMode
, CachedMode
, Size
);
2678 RtlZeroMemory((PCHAR
)pDevMode
+ Size
, OldSize
- Size
);
2679 pDevMode
->dmSize
= OldSize
;
2681 Size
= OldSize
= pDevMode
->dmDriverExtra
;
2682 if (Size
> CachedMode
->dmDriverExtra
)
2683 Size
= CachedMode
->dmDriverExtra
;
2684 RtlCopyMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
,
2685 (PCHAR
)CachedMode
+ CachedMode
->dmSize
, Size
);
2686 RtlZeroMemory((PCHAR
)pDevMode
+ pDevMode
->dmSize
+ Size
, OldSize
- Size
);
2687 pDevMode
->dmDriverExtra
= OldSize
;
2692 static NTSTATUS FASTCALL
2694 OUT PUNICODE_STRING VideoDeviceName
,
2695 IN PCUNICODE_STRING DisplayDevice
) /* ex: "\.\DISPLAY1" or "\??\DISPLAY1" */
2697 UNICODE_STRING Prefix
= RTL_CONSTANT_STRING(L
"\\??\\");
2698 UNICODE_STRING ObjectName
;
2699 UNICODE_STRING KernelModeName
= { 0, };
2700 OBJECT_ATTRIBUTES ObjectAttributes
;
2703 HANDLE LinkHandle
= NULL
;
2706 RtlInitUnicodeString(VideoDeviceName
, NULL
);
2708 /* Get device name (DisplayDevice is "\.\xxx") */
2709 for (LastSlash
= DisplayDevice
->Length
/ sizeof(WCHAR
); LastSlash
> 0; LastSlash
--)
2711 if (DisplayDevice
->Buffer
[LastSlash
- 1] == L
'\\')
2717 DPRINT1("Invalid device name '%wZ'\n", DisplayDevice
);
2718 Status
= STATUS_OBJECT_NAME_INVALID
;
2721 ObjectName
= *DisplayDevice
;
2722 ObjectName
.Length
-= LastSlash
* sizeof(WCHAR
);
2723 ObjectName
.MaximumLength
-= LastSlash
* sizeof(WCHAR
);
2724 ObjectName
.Buffer
+= LastSlash
;
2726 /* Create "\??\xxx" (ex: "\??\DISPLAY1") */
2727 KernelModeName
.MaximumLength
= Prefix
.Length
+ ObjectName
.Length
+ sizeof(UNICODE_NULL
);
2728 KernelModeName
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
2729 KernelModeName
.MaximumLength
,
2731 if (!KernelModeName
.Buffer
)
2733 Status
= STATUS_NO_MEMORY
;
2736 RtlCopyUnicodeString(&KernelModeName
, &Prefix
);
2737 Status
= RtlAppendUnicodeStringToString(&KernelModeName
, &ObjectName
);
2738 if (!NT_SUCCESS(Status
))
2741 /* Open \??\xxx (ex: "\??\DISPLAY1") */
2742 InitializeObjectAttributes(&ObjectAttributes
,
2747 Status
= ZwOpenSymbolicLinkObject(&LinkHandle
,
2750 if (!NT_SUCCESS(Status
))
2752 DPRINT1("Unable to open symbolic link %wZ (Status 0x%08lx)\n", &KernelModeName
, Status
);
2753 Status
= STATUS_NO_SUCH_DEVICE
;
2757 Status
= ZwQuerySymbolicLinkObject(LinkHandle
, VideoDeviceName
, &Length
);
2758 if (!NT_SUCCESS(Status
) && Status
!= STATUS_BUFFER_TOO_SMALL
)
2760 DPRINT1("Unable to query symbolic link %wZ (Status 0x%08lx)\n", &KernelModeName
, Status
);
2761 Status
= STATUS_NO_SUCH_DEVICE
;
2764 VideoDeviceName
->MaximumLength
= Length
;
2765 VideoDeviceName
->Buffer
= ExAllocatePoolWithTag(PagedPool
,
2766 VideoDeviceName
->MaximumLength
+ sizeof(UNICODE_NULL
),
2768 if (!VideoDeviceName
->Buffer
)
2770 Status
= STATUS_NO_MEMORY
;
2773 Status
= ZwQuerySymbolicLinkObject(LinkHandle
, VideoDeviceName
, NULL
);
2774 VideoDeviceName
->Buffer
[VideoDeviceName
->MaximumLength
/ sizeof(WCHAR
) - 1] = UNICODE_NULL
;
2775 if (!NT_SUCCESS(Status
))
2777 DPRINT1("Unable to query symbolic link %wZ (Status 0x%08lx)\n", &KernelModeName
, Status
);
2778 Status
= STATUS_NO_SUCH_DEVICE
;
2781 Status
= STATUS_SUCCESS
;
2784 if (!NT_SUCCESS(Status
) && VideoDeviceName
->Buffer
)
2785 ExFreePoolWithTag(VideoDeviceName
->Buffer
, TAG_DC
);
2786 if (KernelModeName
.Buffer
)
2787 ExFreePoolWithTag(KernelModeName
.Buffer
, TAG_DC
);
2789 ZwClose(LinkHandle
);
2793 static NTSTATUS FASTCALL
2794 GetVideoRegistryKey(
2795 OUT PUNICODE_STRING RegistryPath
,
2796 IN PCUNICODE_STRING DeviceName
) /* ex: "\Device\Video0" */
2798 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
2801 RtlInitUnicodeString(RegistryPath
, NULL
);
2802 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
2803 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
2804 QueryTable
[0].Name
= DeviceName
->Buffer
;
2805 QueryTable
[0].EntryContext
= RegistryPath
;
2807 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
2812 if (!NT_SUCCESS(Status
))
2814 DPRINT1("No %wZ value in DEVICEMAP\\VIDEO found (Status 0x%08lx)\n", DeviceName
, Status
);
2815 return STATUS_NO_SUCH_DEVICE
;
2818 DPRINT("RegistryPath %wZ\n", RegistryPath
);
2819 return STATUS_SUCCESS
;
2824 IntChangeDisplaySettings(
2825 IN PUNICODE_STRING pDeviceName OPTIONAL
,
2826 IN LPDEVMODEW DevMode
,
2828 IN PVOID lParam OPTIONAL
)
2830 BOOLEAN Global
= FALSE
;
2831 BOOLEAN NoReset
= FALSE
;
2832 BOOLEAN Reset
= FALSE
;
2833 BOOLEAN SetPrimary
= FALSE
;
2837 DPRINT1("display flag : %x\n",dwflags
);
2839 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2841 /* Check global, reset and noreset flags */
2842 if ((dwflags
& CDS_GLOBAL
) == CDS_GLOBAL
)
2844 if ((dwflags
& CDS_NORESET
) == CDS_NORESET
)
2846 dwflags
&= ~(CDS_GLOBAL
| CDS_NORESET
);
2848 if ((dwflags
& CDS_RESET
) == CDS_RESET
)
2850 if ((dwflags
& CDS_SET_PRIMARY
) == CDS_SET_PRIMARY
)
2852 dwflags
&= ~(CDS_RESET
| CDS_SET_PRIMARY
);
2854 if (Reset
&& NoReset
)
2855 return DISP_CHANGE_BADFLAGS
;
2859 /* Dynamically change graphics mode */
2860 DPRINT1("flag 0 UNIMPLEMENT \n");
2861 return DISP_CHANGE_FAILED
;
2864 if ((dwflags
& CDS_TEST
) == CDS_TEST
)
2866 /* Test reslution */
2867 dwflags
&= ~CDS_TEST
;
2868 DPRINT1("flag CDS_TEST UNIMPLEMENT");
2869 Ret
= DISP_CHANGE_FAILED
;
2872 if ((dwflags
& CDS_FULLSCREEN
) == CDS_FULLSCREEN
)
2876 dwflags
&= ~CDS_FULLSCREEN
;
2877 DPRINT1("flag CDS_FULLSCREEN partially implemented");
2878 Ret
= DISP_CHANGE_FAILED
;
2880 lpDevMode
.dmBitsPerPel
=0;
2881 lpDevMode
.dmPelsWidth
=0;
2882 lpDevMode
.dmPelsHeight
=0;
2883 lpDevMode
.dmDriverExtra
=0;
2885 lpDevMode
.dmSize
= sizeof(DEVMODEW
);
2886 if (!IntEnumDisplaySettings(pDeviceName
, ENUM_CURRENT_SETTINGS
, &lpDevMode
, 0))
2887 return DISP_CHANGE_FAILED
;
2889 DPRINT1("Req Mode : %d x %d x %d\n", DevMode
->dmPelsWidth
,DevMode
->dmPelsHeight
,DevMode
->dmBitsPerPel
);
2890 DPRINT1("Current Mode : %d x %d x %d\n", lpDevMode
.dmPelsWidth
,lpDevMode
.dmPelsHeight
, lpDevMode
.dmBitsPerPel
);
2893 if ((lpDevMode
.dmBitsPerPel
== DevMode
->dmBitsPerPel
) &&
2894 (lpDevMode
.dmPelsWidth
== DevMode
->dmPelsWidth
) &&
2895 (lpDevMode
.dmPelsHeight
== DevMode
->dmPelsHeight
))
2896 Ret
= DISP_CHANGE_SUCCESSFUL
;
2899 if ((dwflags
& CDS_VIDEOPARAMETERS
) == CDS_VIDEOPARAMETERS
)
2901 dwflags
&= ~CDS_VIDEOPARAMETERS
;
2903 Ret
=DISP_CHANGE_BADPARAM
;
2906 DPRINT1("flag CDS_VIDEOPARAMETERS UNIMPLEMENT");
2907 Ret
= DISP_CHANGE_FAILED
;
2912 if ((dwflags
& CDS_UPDATEREGISTRY
) == CDS_UPDATEREGISTRY
)
2915 UNICODE_STRING DeviceName
;
2916 UNICODE_STRING RegistryKey
;
2917 UNICODE_STRING InDeviceName
;
2918 OBJECT_ATTRIBUTES ObjectAttributes
;
2919 HANDLE DevInstRegKey
;
2922 DPRINT1("set CDS_UPDATEREGISTRY \n");
2924 dwflags
&= ~CDS_UPDATEREGISTRY
;
2926 /* Check if pDeviceName is NULL, we need to retrieve it */
2927 if (pDeviceName
== NULL
)
2929 WCHAR szBuffer
[MAX_DRIVER_NAME
];
2931 PWINDOW_OBJECT Wnd
=NULL
;
2935 hWnd
= IntGetDesktopWindow();
2936 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2941 hDC
= (HDC
)UserGetWindowDC(Wnd
);
2943 DC
= DC_LockDc(hDC
);
2948 swprintf (szBuffer
, L
"\\\\.\\DISPLAY%lu", ((GDIDEVICE
*)DC
->GDIDevice
)->DisplayNumber
);
2951 RtlInitUnicodeString(&InDeviceName
, szBuffer
);
2952 pDeviceName
= &InDeviceName
;
2955 Status
= GetVideoDeviceName(&DeviceName
, pDeviceName
);
2956 if (!NT_SUCCESS(Status
))
2958 DPRINT1("Unable to get destination of '%wZ' (Status 0x%08lx)\n", pDeviceName
, Status
);
2959 return DISP_CHANGE_FAILED
;
2961 Status
= GetVideoRegistryKey(&RegistryKey
, &DeviceName
);
2962 if (!NT_SUCCESS(Status
))
2964 DPRINT1("Unable to get registry key for '%wZ' (Status 0x%08lx)\n", &DeviceName
, Status
);
2965 ExFreePoolWithTag(DeviceName
.Buffer
, TAG_DC
);
2966 return DISP_CHANGE_FAILED
;
2968 ExFreePoolWithTag(DeviceName
.Buffer
, TAG_DC
);
2970 InitializeObjectAttributes(&ObjectAttributes
, &RegistryKey
,
2971 OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
2972 Status
= ZwOpenKey(&DevInstRegKey
, GENERIC_READ
| GENERIC_WRITE
, &ObjectAttributes
);
2973 if (!NT_SUCCESS(Status
))
2975 DPRINT1("Unable to open registry key %wZ (Status 0x%08lx)\n", &RegistryKey
, Status
);
2976 ExFreePoolWithTag(RegistryKey
.Buffer
, TAG_DC
);
2977 return DISP_CHANGE_FAILED
;
2979 ExFreePoolWithTag(RegistryKey
.Buffer
, TAG_DC
);
2981 /* Update needed fields */
2982 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_BITSPERPEL
)
2984 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.BitsPerPel");
2985 NewValue
= DevMode
->dmBitsPerPel
;
2986 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2989 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSWIDTH
)
2991 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.XResolution");
2992 NewValue
= DevMode
->dmPelsWidth
;
2993 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
2996 if (NT_SUCCESS(Status
) && DevMode
->dmFields
& DM_PELSHEIGHT
)
2998 RtlInitUnicodeString(&RegistryKey
, L
"DefaultSettings.YResolution");
2999 NewValue
= DevMode
->dmPelsHeight
;
3000 Status
= ZwSetValueKey(DevInstRegKey
, &RegistryKey
, 0, REG_DWORD
, &NewValue
, sizeof(NewValue
));
3003 ZwClose(DevInstRegKey
);
3004 if (NT_SUCCESS(Status
))
3005 Ret
= DISP_CHANGE_RESTART
;
3007 /* return DISP_CHANGE_NOTUPDATED when we can save to reg only valid for NT */
3008 Ret
= DISP_CHANGE_NOTUPDATED
;
3012 Ret
= DISP_CHANGE_BADFLAGS
;