2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: dc.c,v 1.124 2004/03/15 22:02:31 gvg Exp $
21 * DC.C - Device context functions
25 #undef WIN32_LEAN_AND_MEAN
27 #include <ddk/ntddk.h>
28 #include <ddk/ntddvid.h>
30 #include <internal/safe.h>
31 #include <win32k/bitmaps.h>
32 #include <win32k/brush.h>
33 #include <win32k/cliprgn.h>
34 #include <win32k/coord.h>
35 #include <win32k/driver.h>
36 #include <win32k/dc.h>
37 #include <win32k/misc.h>
38 #include <win32k/print.h>
39 #include <win32k/region.h>
40 #include <win32k/gdiobj.h>
41 #include <win32k/paint.h>
42 #include <win32k/pen.h>
43 #include <win32k/text.h>
44 #include "../eng/clip.h"
45 #include "../eng/handle.h"
46 #include <include/dce.h>
47 #include <include/error.h>
48 #include <include/inteng.h>
49 #include <include/eng.h>
50 #include <include/palette.h>
51 #include <include/guicheck.h>
52 #include <include/desktop.h>
53 #include <include/intgdi.h>
54 #include <include/cleanup.h>
55 #include <include/tags.h>
58 #include <win32k/debug1.h>
60 static GDIDEVICE PrimarySurface
;
62 /* FIXME: DCs should probably be thread safe */
65 * DC device-independent Get/SetXXX functions
66 * (RJJ) swiped from WINE
69 #define DC_GET_VAL( func_type, func_name, dc_field ) \
70 func_type STDCALL func_name( HDC hdc ) \
73 PDC dc = DC_LockDc( hdc ); \
83 /* DC_GET_VAL_EX is used to define functions returning a POINT or a SIZE. It is
84 * important that the function has the right signature, for the implementation
85 * we can do whatever we want.
87 #define DC_GET_VAL_EX( NtGdiFuncName, IntFuncName, ret_x, ret_y, type ) \
88 VOID FASTCALL IntFuncName ( PDC dc, LP##type pt ) \
92 ((LPPOINT)pt)->x = dc->ret_x; \
93 ((LPPOINT)pt)->y = dc->ret_y; \
95 BOOL STDCALL NtGdiFuncName ( HDC hdc, LP##type pt ) \
97 PDC dc = DC_LockDc ( hdc ); \
100 IntFuncName ( dc, pt ); \
101 DC_UnlockDc ( hdc ); \
105 #define DC_SET_MODE( func_name, dc_field, min_val, max_val ) \
106 INT STDCALL func_name( HDC hdc, INT mode ) \
110 if ((mode < min_val) || (mode > max_val)) \
112 dc = DC_LockDc ( hdc ); \
115 prevMode = dc->dc_field; \
116 dc->dc_field = mode; \
117 DC_UnlockDc ( hdc ); \
122 // --------------------------------------------------------- File Statics
124 // ----------------------------------------------------- Public Functions
127 NtGdiCancelDC(HDC hDC
)
133 NtGdiCreateCompatableDC(HDC hDC
)
137 HDC hNewDC
, DisplayDC
;
140 UNICODE_STRING DriverName
;
145 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
146 DisplayDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
);
147 if (NULL
== DisplayDC
)
154 /* Allocate a new DC based on the original DC's device */
155 OrigDC
= DC_LockDc(hDC
);
158 if (NULL
!= DisplayDC
)
160 NtGdiDeleteDC(DisplayDC
);
164 hNewDC
= DC_AllocDC(&OrigDC
->DriverName
);
169 if (NULL
!= DisplayDC
)
171 NtGdiDeleteDC(DisplayDC
);
175 NewDC
= DC_LockDc( hNewDC
);
177 /* Copy information from original DC to new DC */
178 NewDC
->hSelf
= hNewDC
;
180 NewDC
->PDev
= OrigDC
->PDev
;
181 NewDC
->DMW
= OrigDC
->DMW
;
182 memcpy(NewDC
->FillPatternSurfaces
,
183 OrigDC
->FillPatternSurfaces
,
184 sizeof OrigDC
->FillPatternSurfaces
);
185 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
186 NewDC
->DevInfo
= OrigDC
->DevInfo
;
187 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
189 /* DriverName is copied in the AllocDC routine */
190 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
191 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
192 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
193 NewDC
->wndExtX
= OrigDC
->wndExtX
;
194 NewDC
->wndExtY
= OrigDC
->wndExtY
;
195 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
196 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
197 NewDC
->vportExtX
= OrigDC
->vportExtX
;
198 NewDC
->vportExtY
= OrigDC
->vportExtY
;
200 /* Create default bitmap */
201 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
204 DC_UnlockDc( hNewDC
);
206 if (NULL
!= DisplayDC
)
208 NtGdiDeleteDC(DisplayDC
);
212 NewDC
->w
.flags
= DC_MEMORY
;
213 NewDC
->w
.hBitmap
= hBitmap
;
214 NewDC
->w
.hFirstBitmap
= hBitmap
;
215 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
216 pb
= BITMAPOBJ_LockBitmap(hBitmap
);
217 NewDC
->Surface
= BitmapToSurf(pb
, NewDC
->GDIDevice
);
218 BITMAPOBJ_UnlockBitmap(hBitmap
);
220 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
221 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
222 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
223 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
224 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
226 if (NULL
!= DisplayDC
)
228 NtGdiDeleteDC(DisplayDC
);
232 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
233 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
234 NtGdiDeleteObject(hVisRgn
);
242 GetRegistryPath(PUNICODE_STRING RegistryPath
, ULONG DisplayNumber
)
244 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
245 WCHAR DeviceNameBuffer
[20];
248 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
249 RtlInitUnicodeString(RegistryPath
, NULL
);
250 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
251 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
252 QueryTable
[0].Name
= DeviceNameBuffer
;
253 QueryTable
[0].EntryContext
= RegistryPath
;
255 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
260 if (! NT_SUCCESS(Status
))
262 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
266 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
272 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
274 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
275 UNICODE_STRING RegistryPath
;
278 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
280 DPRINT("GetRegistryPath failed\n");
284 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
285 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
286 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
287 QueryTable
[0].EntryContext
= DriverFileNames
;
289 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
294 RtlFreeUnicodeString(&RegistryPath
);
295 if (! NT_SUCCESS(Status
))
297 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
301 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
306 static NTSTATUS STDCALL
307 DevModeCallback(IN PWSTR ValueName
,
310 IN ULONG ValueLength
,
312 IN PVOID EntryContext
)
314 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
316 DPRINT("Found registry value for name %S: type %d, length %d\n",
317 ValueName
, ValueType
, ValueLength
);
319 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
321 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
323 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
325 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
327 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
329 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
331 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
333 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
335 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
337 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
339 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
341 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
343 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
345 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
347 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
351 return STATUS_SUCCESS
;
355 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
357 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
358 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
359 static WCHAR ControlSet
[] = L
"CONTROLSET";
360 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
361 UNICODE_STRING RegistryPath
;
363 PWCHAR AfterControlSet
;
365 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
368 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
370 DPRINT("GetRegistryPath failed\n");
374 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
375 wcslen(RegistryMachineSystem
)));
378 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
379 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
381 AfterControlSet
+= wcslen(CurrentControlSet
);
383 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
385 AfterControlSet
+= wcslen(ControlSet
);
386 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
390 Valid
= (L
'\\' == *AfterControlSet
);
401 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
402 (wcslen(RegistryPath
.Buffer
) +
403 wcslen(Insert
) + 1) * sizeof(WCHAR
),
405 if (NULL
!= ProfilePath
)
407 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
408 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
409 wcscat(ProfilePath
, AfterControlSet
);
411 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
412 QueryTable
[0].QueryRoutine
= DevModeCallback
;
413 QueryTable
[0].Flags
= 0;
414 QueryTable
[0].Name
= NULL
;
415 QueryTable
[0].EntryContext
= NULL
;
416 QueryTable
[0].DefaultType
= REG_NONE
;
417 QueryTable
[0].DefaultData
= NULL
;
418 QueryTable
[0].DefaultLength
= 0;
420 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
425 if (! NT_SUCCESS(Status
))
427 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
428 ProfilePath
, Status
);
433 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
434 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
435 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
436 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
437 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
439 DPRINT("Not all required devmode members are set\n");
444 ExFreePool(ProfilePath
);
453 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
456 RtlFreeUnicodeString(&RegistryPath
);
460 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
467 IntCreatePrimarySurface()
469 PGD_ENABLEDRIVER GDEnableDriver
;
473 UNICODE_STRING DriverFileNames
;
479 for (DisplayNumber
= 0; ; DisplayNumber
++)
481 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
483 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
484 ExInitializeFastMutex(&PrimarySurface
.DriverLock
);
486 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
488 /* Open the miniport driver */
489 if (PrimarySurface
.VideoFileObject
== NULL
)
491 DPRINT1("FindMPDriver failed\n");
495 /* Retrieve DDI driver names from registry */
496 RtlInitUnicodeString(&DriverFileNames
, NULL
);
497 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
499 DPRINT1("FindDriverFileNames failed\n");
505 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
506 * scan all of them until a good one found.
508 CurrentName
= DriverFileNames
.Buffer
;
511 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
513 /* Get the DDI driver's entry point */
514 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
515 if (NULL
== GDEnableDriver
)
517 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
521 /* Call DDI driver's EnableDriver function */
522 RtlZeroMemory(&DED
, sizeof(DED
));
524 if (! GDEnableDriver(DDI_DRIVER_VERSION
, sizeof(DED
), &DED
))
526 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
536 /* Skip to the next name but never get past the Unicode string */
537 while (L
'\0' != *CurrentName
&&
538 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
542 if (CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
549 RtlFreeUnicodeString(&DriverFileNames
);
553 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
554 DPRINT1("No suitable DDI driver found\n");
559 DPRINT("Display driver %S loaded\n", CurrentName
);
561 DPRINT("Building DDI Functions\n");
563 /* Construct DDI driver function dispatch table */
564 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
566 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
567 DPRINT1("BuildDDIFunctions failed\n");
571 /* Allocate a phyical device handle from the driver */
572 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
574 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDev(
578 PrimarySurface
.FillPatterns
,
579 sizeof(PrimarySurface
.GDIInfo
),
580 (ULONG
*) &PrimarySurface
.GDIInfo
,
581 sizeof(PrimarySurface
.DevInfo
),
582 &PrimarySurface
.DevInfo
,
585 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
586 DoDefault
= (NULL
== PrimarySurface
.PDev
);
589 DPRINT1("DrvEnablePDev with registry parameters failed\n");
599 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
600 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDev(
604 PrimarySurface
.FillPatterns
,
605 sizeof(PrimarySurface
.GDIInfo
),
606 (ULONG
*) &PrimarySurface
.GDIInfo
,
607 sizeof(PrimarySurface
.DevInfo
),
608 &PrimarySurface
.DevInfo
,
611 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
613 if (NULL
== PrimarySurface
.PDev
)
615 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
616 DPRINT1("DrvEnablePDEV with default parameters failed\n");
617 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
623 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
625 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
626 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
628 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
630 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
631 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
634 DPRINT("calling completePDev\n");
636 /* Complete initialization of the physical device */
637 PrimarySurface
.DriverFunctions
.CompletePDev(
641 DPRINT("calling DRIVER_ReferenceDriver\n");
643 DRIVER_ReferenceDriver(L
"DISPLAY");
645 DPRINT("calling EnableSurface\n");
647 /* Enable the drawing surface */
648 PrimarySurface
.Handle
=
649 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
650 if (NULL
== PrimarySurface
.Handle
)
652 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
653 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
654 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
655 DPRINT1("DrvEnableSurface failed\n");
660 SurfObj
= (PSURFOBJ
)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
661 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
662 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
664 IntGetActiveDesktop(),
665 SurfGDI
->SurfObj
.sizlBitmap
.cx
,
666 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
674 IntDestroyPrimarySurface()
681 DRIVER_UnreferenceDriver(L
"DISPLAY");
684 DPRINT("Hiding mouse pointer\n" );
685 SurfObj
= (PSURFOBJ
)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
686 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
687 SurfGDI
->SetPointerShape(SurfObj
, NULL
, NULL
, NULL
, 0, 0, 0, 0, 0, 0);
689 DPRINT("Reseting display\n" );
690 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
691 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
692 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
696 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
700 IntGdiCreateDC(PUNICODE_STRING Driver
,
701 PUNICODE_STRING Device
,
702 PUNICODE_STRING Output
,
703 CONST PDEVMODEW InitData
)
710 UNICODE_STRING StdDriver
;
712 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
714 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
716 if (! IntGraphicsCheck(TRUE
))
718 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
723 /* Check for existing DC object */
724 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
727 return NtGdiCreateCompatableDC(hDC
);
730 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
732 DPRINT("NAME: %S\n", Driver
->Buffer
); // FIXME: Should not crash if NULL
735 /* Allocate a DC object */
736 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
741 NewDC
= DC_LockDc( hNewDC
);
744 NewDC
->DMW
= PrimarySurface
.DMW
;
745 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
746 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
747 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
748 sizeof(NewDC
->FillPatternSurfaces
));
749 NewDC
->PDev
= PrimarySurface
.PDev
;
750 NewDC
->Surface
= PrimarySurface
.Handle
;
751 NewDC
->GDIDevice
= &PrimarySurface
;
752 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
754 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
755 NewDC
->DMW
.dmFields
= 0x000fc000;
757 /* FIXME: get mode selection information from somewhere */
759 NewDC
->DMW
.dmLogPixels
= 96;
760 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
761 NewDC
->DMW
.dmBitsPerPel
= SurfGDI
->BitsPerPixel
;
762 NewDC
->DMW
.dmPelsWidth
= SurfGDI
->SurfObj
.sizlBitmap
.cx
;
763 NewDC
->DMW
.dmPelsHeight
= SurfGDI
->SurfObj
.sizlBitmap
.cy
;
764 NewDC
->DMW
.dmDisplayFlags
= 0;
765 NewDC
->DMW
.dmDisplayFrequency
= 0;
767 NewDC
->w
.bitsPerPixel
= SurfGDI
->BitsPerPixel
; // FIXME: set this here??
769 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
771 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
773 DC_UnlockDc( hNewDC
);
775 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfGDI
->SurfObj
.sizlBitmap
.cx
,
776 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
777 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
778 NtGdiDeleteObject(hVisRgn
);
780 /* Initialize the DC state */
782 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
783 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
784 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
785 NtGdiSetBkMode(hNewDC
, OPAQUE
);
791 NtGdiCreateDC(PUNICODE_STRING Driver
,
792 PUNICODE_STRING Device
,
793 PUNICODE_STRING Output
,
794 CONST PDEVMODEW InitData
)
796 UNICODE_STRING SafeDriver
, SafeDevice
;
797 DEVMODEW SafeInitData
;
803 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
804 if(!NT_SUCCESS(Status
))
806 SetLastNtError(Status
);
809 /* FIXME - InitData can have some more bytes! */
814 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
815 if(!NT_SUCCESS(Status
))
817 SetLastNtError(Status
);
824 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
825 if(!NT_SUCCESS(Status
))
827 RtlFreeUnicodeString(&SafeDriver
);
828 SetLastNtError(Status
);
833 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
);
839 NtGdiCreateIC(PUNICODE_STRING Driver
,
840 PUNICODE_STRING Device
,
841 PUNICODE_STRING Output
,
842 CONST PDEVMODEW DevMode
)
844 /* FIXME: this should probably do something else... */
845 return NtGdiCreateDC(Driver
, Device
, Output
, DevMode
);
849 NtGdiDeleteDC(HDC DCHandle
)
853 DCToDelete
= DC_LockDc(DCHandle
);
854 if (DCToDelete
== NULL
)
858 DPRINT( "Deleting DC\n" );
860 /* First delete all saved DCs */
861 while (DCToDelete
->saveLevel
)
866 savedHDC
= DC_GetNextDC (DCToDelete
);
867 savedDC
= DC_LockDc (savedHDC
);
872 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
873 DCToDelete
->saveLevel
--;
874 DC_UnlockDc( savedHDC
);
875 NtGdiDeleteDC (savedHDC
);
878 /* Free GDI resources allocated to this DC */
879 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
882 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
883 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
884 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
885 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
886 if (DCToDelete
->w
.flags
& DC_MEMORY
)
888 EngDeleteSurface (DCToDelete
->Surface
);
889 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
892 if (DCToDelete
->w
.hClipRgn
)
894 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
896 if (DCToDelete
->w
.hVisRgn
)
898 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
900 if (NULL
!= DCToDelete
->CombinedClip
)
902 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
904 if (DCToDelete
->w
.hGCClipRgn
)
906 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
909 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
911 DC_UnlockDc( DCHandle
);
912 DC_FreeDC ( DCHandle
);
918 NtGdiDrawEscape(HDC hDC
,
927 NtGdiEnumObjects(HDC hDC
,
929 GOBJENUMPROC ObjectFunc
,
935 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
936 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
937 DC_GET_VAL_EX( NtGdiGetBrushOrgEx
, IntGetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
)
938 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
941 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
946 DC_GET_VAL_EX ( NtGdiGetCurrentPositionEx
, IntGetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
)
949 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
951 Point
->x
= dc
->w
.DCOrgX
;
952 Point
->y
= dc
->w
.DCOrgY
;
958 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
967 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
974 SetLastWin32Error(ERROR_INVALID_HANDLE
);
978 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
980 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
981 if(!NT_SUCCESS(Status
))
983 SetLastNtError(Status
);
993 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
996 PDC dc
= DC_LockDc(hDC
);
1001 oldColor
= dc
->w
.backgroundColor
;
1002 dc
->w
.backgroundColor
= color
;
1003 DC_UnlockDc ( hDC
);
1008 NtGdiGetDCState(HDC hDC
)
1013 dc
= DC_LockDc(hDC
);
1019 hnewdc
= DC_AllocDC(NULL
);
1025 newdc
= DC_LockDc( hnewdc
);
1028 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1029 newdc
->w
.hPen
= dc
->w
.hPen
;
1030 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1031 newdc
->w
.hFont
= dc
->w
.hFont
;
1032 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1033 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1035 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1036 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1038 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1039 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1040 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1041 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1042 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1043 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1044 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1045 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1046 newdc
->w
.textColor
= dc
->w
.textColor
;
1047 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1048 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1049 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1050 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1051 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1052 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1053 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1054 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1055 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1056 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1058 /* Apparently, the DC origin is not changed by [GS]etDCState */
1059 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1060 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1062 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1063 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1064 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1065 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1066 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1067 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1068 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1069 newdc
->wndOrgX
= dc
->wndOrgX
;
1070 newdc
->wndOrgY
= dc
->wndOrgY
;
1071 newdc
->wndExtX
= dc
->wndExtX
;
1072 newdc
->wndExtY
= dc
->wndExtY
;
1073 newdc
->vportOrgX
= dc
->vportOrgX
;
1074 newdc
->vportOrgY
= dc
->vportOrgY
;
1075 newdc
->vportExtX
= dc
->vportExtX
;
1076 newdc
->vportExtY
= dc
->vportExtY
;
1078 newdc
->hSelf
= hnewdc
;
1079 newdc
->saveLevel
= 0;
1082 PATH_InitGdiPath( &newdc
->w
.path
);
1085 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1088 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1092 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1093 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1097 newdc
->w
.hClipRgn
= 0;
1099 DC_UnlockDc( hnewdc
);
1107 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1111 dc
= DC_LockDc ( hDC
);
1114 dcs
= DC_LockDc ( hDCSave
);
1117 if ( dcs
->w
.flags
& DC_SAVED
)
1119 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1121 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1124 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1127 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1128 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1129 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1130 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1131 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1132 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1133 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1134 dc
->w
.textColor
= dcs
->w
.textColor
;
1135 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1136 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1137 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1138 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1139 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1140 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1141 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1142 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1143 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1144 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1146 /* Apparently, the DC origin is not changed by [GS]etDCState */
1147 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1148 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1150 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1151 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1152 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1154 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1155 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1156 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1157 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1159 dc
->wndOrgX
= dcs
->wndOrgX
;
1160 dc
->wndOrgY
= dcs
->wndOrgY
;
1161 dc
->wndExtX
= dcs
->wndExtX
;
1162 dc
->wndExtY
= dcs
->wndExtY
;
1163 dc
->vportOrgX
= dcs
->vportOrgX
;
1164 dc
->vportOrgY
= dcs
->vportOrgY
;
1165 dc
->vportExtX
= dcs
->vportExtX
;
1166 dc
->vportExtY
= dcs
->vportExtY
;
1168 if (!(dc
->w
.flags
& DC_MEMORY
))
1170 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1174 if (dcs
->w
.hClipRgn
)
1176 if (!dc
->w
.hClipRgn
)
1178 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1180 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1186 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1191 CLIPPING_UpdateGCRegion( dc
);
1192 DC_UnlockDc ( hDC
);
1194 DC_UnlockDc ( hDC
);
1195 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1198 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1199 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1200 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1201 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1202 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1203 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1206 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1211 DC_UnlockDc ( hDCSave
);
1213 DC_UnlockDc ( hDC
);
1219 NtGdiGetDeviceCaps(HDC hDC
,
1226 dc
= DC_LockDc(hDC
);
1232 /* Retrieve capability */
1236 ret
= dc
->GDIInfo
->ulVersion
;
1240 ret
= dc
->GDIInfo
->ulTechnology
;
1244 ret
= dc
->GDIInfo
->ulHorzSize
;
1248 ret
= dc
->GDIInfo
->ulVertSize
;
1252 ret
= dc
->GDIInfo
->ulHorzRes
;
1256 ret
= dc
->GDIInfo
->ulVertRes
;
1260 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1264 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1268 ret
= dc
->GDIInfo
->cBitsPixel
;
1272 ret
= dc
->GDIInfo
->cPlanes
;
1276 UNIMPLEMENTED
; /* FIXME */
1280 UNIMPLEMENTED
; /* FIXME */
1284 UNIMPLEMENTED
; /* FIXME */
1288 ret
= dc
->GDIInfo
->ulNumColors
;
1292 ret
= dc
->GDIInfo
->ulAspectX
;
1296 ret
= dc
->GDIInfo
->ulAspectY
;
1300 ret
= dc
->GDIInfo
->ulAspectXY
;
1304 UNIMPLEMENTED
; /* FIXME */
1308 UNIMPLEMENTED
; /* FIXME */
1312 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1320 UNIMPLEMENTED
; /* FIXME */
1324 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1334 case PHYSICALHEIGHT
:
1335 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1345 case PHYSICALOFFSETX
:
1346 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1356 case PHYSICALOFFSETY
:
1357 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1368 UNIMPLEMENTED
; /* FIXME */
1371 case SCALINGFACTORX
:
1372 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1382 case SCALINGFACTORY
:
1383 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1394 ret
= dc
->GDIInfo
->flRaster
;
1398 UNIMPLEMENTED
; /* FIXME */
1402 UNIMPLEMENTED
; /* FIXME */
1406 UNIMPLEMENTED
; /* FIXME */
1410 ret
= dc
->GDIInfo
->flTextCaps
;
1418 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1424 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1425 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1428 IntGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1430 PGDIOBJHDR gdiObject
;
1434 gdiObject
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1438 objectType
= GDIOBJ_GetObjectType(handle
);
1441 /* case GDI_OBJECT_TYPE_PEN:
1442 result = PEN_GetObject((PENOBJ *)gdiObject, count, buffer);
1444 case GDI_OBJECT_TYPE_BRUSH:
1445 result = BRUSH_GetObject((BRUSHOBJ *)gdiObject, count, buffer);
1447 case GDI_OBJECT_TYPE_BITMAP
:
1448 result
= BITMAP_GetObject((BITMAPOBJ
*)gdiObject
, count
, buffer
);
1450 /* case GDI_OBJECT_TYPE_FONT:
1451 result = FONT_GetObjectW((FONTOBJ *)gdiObject, count, buffer);
1453 // Fix the LOGFONT structure for the stock fonts
1455 if ( (handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE) )
1456 FixStockFontSizeW(handle, count, buffer);
1458 case GDI_OBJECT_TYPE_PALETTE:
1459 result = PALETTE_GetObject((PALETTEOBJ *)gdiObject, count, buffer);
1462 DPRINT1("GDI object type 0x%08x not implemented\n", objectType
);
1466 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1472 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1483 SafeBuf
= ExAllocatePoolWithTag(NonPagedPool
, count
, TAG_GDIOBJ
);
1486 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1490 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1492 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1493 ExFreePool(SafeBuf
);
1494 if(!NT_SUCCESS(Status
))
1496 SetLastNtError(Status
);
1504 NtGdiGetObjectType(HANDLE handle
)
1510 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1514 objectType
= GDIOBJ_GetObjectType(handle
);
1517 case GDI_OBJECT_TYPE_PEN
:
1520 case GDI_OBJECT_TYPE_BRUSH
:
1523 case GDI_OBJECT_TYPE_BITMAP
:
1524 result
= OBJ_BITMAP
;
1526 case GDI_OBJECT_TYPE_FONT
:
1529 case GDI_OBJECT_TYPE_PALETTE
:
1532 case GDI_OBJECT_TYPE_REGION
:
1533 result
= OBJ_REGION
;
1535 case GDI_OBJECT_TYPE_DC
:
1538 case GDI_OBJECT_TYPE_METADC
:
1539 result
= OBJ_METADC
;
1541 case GDI_OBJECT_TYPE_METAFILE
:
1542 result
= OBJ_METAFILE
;
1544 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1545 result
= OBJ_ENHMETAFILE
;
1547 case GDI_OBJECT_TYPE_ENHMETADC
:
1548 result
= OBJ_ENHMETADC
;
1550 case GDI_OBJECT_TYPE_EXTPEN
:
1551 result
= OBJ_EXTPEN
;
1553 case GDI_OBJECT_TYPE_MEMDC
:
1557 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1560 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1564 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1565 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1566 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1567 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1568 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1569 DC_GET_VAL_EX( NtGdiGetViewportExtEx
, IntGetViewportExtEx
, vportExtX
, vportExtY
, SIZE
)
1570 DC_GET_VAL_EX( NtGdiGetViewportOrgEx
, IntGetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
)
1571 DC_GET_VAL_EX( NtGdiGetWindowExtEx
, IntGetWindowExtEx
, wndExtX
, wndExtY
, SIZE
)
1572 DC_GET_VAL_EX( NtGdiGetWindowOrgEx
, IntGetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
)
1575 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1581 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1586 dc
= DC_LockDc(hDC
);
1592 if (SaveLevel
== -1)
1594 SaveLevel
= dc
->saveLevel
;
1597 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1603 while (dc
->saveLevel
>= SaveLevel
)
1605 HDC hdcs
= DC_GetNextDC (dc
);
1607 dcs
= DC_LockDc (hdcs
);
1612 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1613 if (--dc
->saveLevel
< SaveLevel
)
1616 DC_UnlockDc( hdcs
);
1617 NtGdiSetDCState(hDC
, hdcs
);
1619 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1621 /* FIXME: This might not be quite right, since we're
1622 * returning FALSE but still destroying the saved DC state */
1626 dc
= DC_LockDc(hDC
);
1634 DC_UnlockDc( hdcs
);
1636 NtGdiDeleteDC (hdcs
);
1643 NtGdiSaveDC(HDC hDC
)
1649 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1654 dcs
= DC_LockDc (hdcs
);
1659 dc
= DC_LockDc (hDC
);
1667 /* Copy path. The reason why path saving / restoring is in SaveDC/
1668 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1669 * functions are only in Win16 (which doesn't have paths) and that
1670 * SetDCState doesn't allow us to signal an error (which can happen
1671 * when copying paths).
1673 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1675 NtGdiDeleteDC (hdcs
);
1680 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1681 DC_SetNextDC (dc
, hdcs
);
1682 ret
= ++dc
->saveLevel
;
1683 DC_UnlockDc( hdcs
);
1691 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1693 HGDIOBJ objOrg
= NULL
; // default to failure
1702 COLORREF MonoColorMap
[2];
1703 ULONG NumColors
, Index
;
1707 if(!hDC
|| !hGDIObj
) return NULL
;
1709 dc
= DC_LockDc(hDC
);
1712 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1716 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1720 case GDI_OBJECT_TYPE_PEN
:
1722 /* Convert the color of the pen to the format of the DC */
1723 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1726 Mode
= PalGDI
->Mode
;
1727 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1728 XlateObj
= (PXLATEOBJ
)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1729 if (NULL
!= XlateObj
)
1731 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1734 pen
->iSolidColor
= XLATEOBJ_iXlate(XlateObj
, pen
->logpen
.lopnColor
);
1735 PENOBJ_UnlockPen((HPEN
) hGDIObj
);
1736 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1737 dc
->w
.hPen
= hGDIObj
;
1741 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1743 EngDeleteXlate(XlateObj
);
1747 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1752 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1756 case GDI_OBJECT_TYPE_BRUSH
:
1758 /* Convert the color of the brush to the format of the DC */
1759 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1762 Mode
= PalGDI
->Mode
;
1763 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1764 XlateObj
= (PXLATEOBJ
)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1765 if (NULL
!= XlateObj
)
1767 brush
= BRUSHOBJ_LockBrush((HBRUSH
) hGDIObj
);
1770 brush
->iSolidColor
= XLATEOBJ_iXlate(XlateObj
, brush
->logbrush
.lbColor
);
1771 BRUSHOBJ_UnlockBrush((HBRUSH
) hGDIObj
);
1772 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1773 dc
->w
.hBrush
= (HBRUSH
) hGDIObj
;
1777 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1779 EngDeleteXlate(XlateObj
);
1783 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1788 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1792 case GDI_OBJECT_TYPE_FONT
:
1793 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1794 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1795 TextIntRealizeFont(dc
->w
.hFont
);
1798 case GDI_OBJECT_TYPE_BITMAP
:
1799 // must be memory dc to select bitmap
1800 if (!(dc
->w
.flags
& DC_MEMORY
))
1805 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1808 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1812 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1814 /* Release the old bitmap, lock the new one and convert it to a SURF */
1815 EngDeleteSurface(dc
->Surface
);
1816 dc
->w
.hBitmap
= hGDIObj
;
1817 dc
->Surface
= BitmapToSurf(pb
, dc
->GDIDevice
);
1819 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1822 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1824 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1826 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1827 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1828 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1830 ColorMap
= ExAllocatePoolWithTag(PagedPool
, sizeof(COLORREF
) * NumColors
, TAG_DC
);
1832 for (Index
= 0; Index
< NumColors
; Index
++)
1834 ColorMap
[Index
] = RGB(pb
->ColorMap
[Index
].rgbRed
,
1835 pb
->ColorMap
[Index
].rgbGreen
,
1836 pb
->ColorMap
[Index
].rgbBlue
);
1838 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, NumColors
, (ULONG
*) ColorMap
, 0, 0, 0);
1839 ExFreePool(ColorMap
);
1841 else if ( 16 == pb
->dib
->dsBmih
.biBitCount
)
1843 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0x7c00, 0x03e0, 0x001f);
1845 else if(pb
->dib
->dsBmih
.biBitCount
>= 24)
1847 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_RGB
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0, 0, 0);
1852 dc
->w
.bitsPerPixel
= pb
->bitmap
.bmBitsPixel
;
1853 if (1 == dc
->w
.bitsPerPixel
)
1855 MonoColorMap
[0] = RGB(0, 0, 0);
1856 MonoColorMap
[1] = RGB(255, 255, 255);
1857 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, 2, MonoColorMap
, 0, 0, 0);
1861 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1865 DC_UnlockDc ( hDC
);
1866 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->bitmap
.bmWidth
, pb
->bitmap
.bmHeight
);
1867 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1868 NtGdiDeleteObject ( hVisRgn
);
1869 BITMAPOBJ_UnlockBitmap(hGDIObj
);
1874 case GDI_OBJECT_TYPE_REGION
:
1875 DC_UnlockDc ( hDC
);
1876 SelectClipRgn(hDC
, (HRGN
)hGDIObj
);
1887 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1890 DC
*dc
= DC_LockDc(hDC
);
1897 wRet
= dc
->w
.flags
& DC_DIRTY
;
1899 /* "Undocumented Windows" info is slightly confusing.
1902 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1904 if (Flags
& DCHF_INVALIDATEVISRGN
)
1906 dc
->w
.flags
|= DC_DIRTY
;
1908 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1910 dc
->w
.flags
&= ~DC_DIRTY
;
1918 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1919 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1920 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1921 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1922 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
1924 // ---------------------------------------------------- Private Interface
1927 DC_AllocDC(PUNICODE_STRING Driver
)
1935 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
1940 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
1943 hDC
= (HDC
) GDIOBJ_AllocObj(sizeof(DC
), GDI_OBJECT_TYPE_DC
, (GDICLEANUPPROC
) DC_InternalDeleteDC
);
1953 NewDC
= DC_LockDc(hDC
);
1957 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
1958 NewDC
->DriverName
.Buffer
= Buf
;
1961 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1962 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1963 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1964 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1965 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1966 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1967 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
1968 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
1969 NewDC
->w
.vport2WorldValid
= TRUE
;
1970 NewDC
->w
.MapMode
= MM_TEXT
;
1972 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
1973 TextIntRealizeFont(NewDC
->w
.hFont
);
1981 DC_FindOpenDC(PUNICODE_STRING Driver
)
1987 * Initialize some common fields in the Device Context structure.
1990 DC_InitDC(HDC DCHandle
)
1992 // NtGdiRealizeDefaultPalette(DCHandle);
1994 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
1995 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
1996 //NtGdiSelectObject(DCHandle, hFont);
1998 // CLIPPING_UpdateGCRegion(DCToInit);
2003 DC_FreeDC(HDC DCToFree
)
2005 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
, GDIOBJFLAG_DEFAULT
))
2007 DPRINT("DC_FreeDC failed\n");
2012 DC_InternalDeleteDC( PDC DCToDelete
)
2015 RtlFreeUnicodeString(&DCToDelete
->DriverName
);
2020 DC_GetNextDC (PDC pDC
)
2026 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2028 pDC
->hNext
= hNextDC
;
2032 DC_UpdateXforms(PDC dc
)
2034 XFORM xformWnd2Vport
;
2035 FLOAT scaleX
, scaleY
;
2037 /* Construct a transformation to do the window-to-viewport conversion */
2038 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0);
2039 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0);
2040 xformWnd2Vport
.eM11
= scaleX
;
2041 xformWnd2Vport
.eM12
= 0.0;
2042 xformWnd2Vport
.eM21
= 0.0;
2043 xformWnd2Vport
.eM22
= scaleY
;
2044 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2045 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2047 /* Combine with the world transformation */
2048 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2050 /* Create inverse of world-to-viewport transformation */
2051 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2055 DC_InvertXform(const XFORM
*xformSrc
,
2060 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2061 if (determinant
> -1e-12 && determinant
< 1e-12)
2066 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2067 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2068 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2069 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2070 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2071 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2077 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2081 GDIOBJ_SetOwnership(hDC
, Owner
);
2082 DC
= DC_LockDc(hDC
);
2085 if (NULL
!= DC
->w
.hClipRgn
)
2087 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2089 if (NULL
!= DC
->w
.hVisRgn
)
2091 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2093 if (NULL
!= DC
->w
.hGCClipRgn
)
2095 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2102 IntIsPrimarSurface(PSURFGDI SurfGDI
)
2104 if (PrimarySurface
.Handle
== NULL
)
2108 return SurfGDI
== (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
) ? TRUE
: FALSE
;