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.119 2004/01/25 16:47:10 navaraf 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>
57 #include <win32k/debug1.h>
59 #define TAG_DC TAG('D', 'C', 'D', 'C')
61 static GDIDEVICE PrimarySurface
;
63 /* FIXME: DCs should probably be thread safe */
66 * DC device-independent Get/SetXXX functions
67 * (RJJ) swiped from WINE
70 #define DC_GET_VAL( func_type, func_name, dc_field ) \
71 func_type STDCALL func_name( HDC hdc ) \
74 PDC dc = DC_LockDc( hdc ); \
84 /* DC_GET_VAL_EX is used to define functions returning a POINT or a SIZE. It is
85 * important that the function has the right signature, for the implementation
86 * we can do whatever we want.
88 #define DC_GET_VAL_EX( NtGdiFuncName, IntFuncName, ret_x, ret_y, type ) \
89 VOID FASTCALL IntFuncName ( PDC dc, LP##type pt ) \
93 ((LPPOINT)pt)->x = dc->ret_x; \
94 ((LPPOINT)pt)->y = dc->ret_y; \
96 BOOL STDCALL NtGdiFuncName ( HDC hdc, LP##type pt ) \
98 PDC dc = DC_LockDc ( hdc ); \
101 IntFuncName ( dc, pt ); \
102 DC_UnlockDc ( hdc ); \
106 #define DC_SET_MODE( func_name, dc_field, min_val, max_val ) \
107 INT STDCALL func_name( HDC hdc, INT mode ) \
111 if ((mode < min_val) || (mode > max_val)) \
113 dc = DC_LockDc ( hdc ); \
116 prevMode = dc->dc_field; \
117 dc->dc_field = mode; \
118 DC_UnlockDc ( hdc ); \
123 // --------------------------------------------------------- File Statics
125 // ----------------------------------------------------- Public Functions
128 NtGdiCancelDC(HDC hDC
)
134 NtGdiCreateCompatableDC(HDC hDC
)
138 HDC hNewDC
, DisplayDC
;
141 UNICODE_STRING DriverName
;
146 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
147 DisplayDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
);
148 if (NULL
== DisplayDC
)
155 /* Allocate a new DC based on the original DC's device */
156 OrigDC
= DC_LockDc(hDC
);
159 if (NULL
!= DisplayDC
)
161 NtGdiDeleteDC(DisplayDC
);
165 hNewDC
= DC_AllocDC(&OrigDC
->DriverName
);
170 if (NULL
!= DisplayDC
)
172 NtGdiDeleteDC(DisplayDC
);
176 NewDC
= DC_LockDc( hNewDC
);
178 /* Copy information from original DC to new DC */
179 NewDC
->hSelf
= NewDC
;
181 NewDC
->PDev
= OrigDC
->PDev
;
182 NewDC
->DMW
= OrigDC
->DMW
;
183 memcpy(NewDC
->FillPatternSurfaces
,
184 OrigDC
->FillPatternSurfaces
,
185 sizeof OrigDC
->FillPatternSurfaces
);
186 NewDC
->GDIInfo
= OrigDC
->GDIInfo
;
187 NewDC
->DevInfo
= OrigDC
->DevInfo
;
188 NewDC
->w
.bitsPerPixel
= OrigDC
->w
.bitsPerPixel
;
190 /* DriverName is copied in the AllocDC routine */
191 NewDC
->DeviceDriver
= OrigDC
->DeviceDriver
;
192 NewDC
->wndOrgX
= OrigDC
->wndOrgX
;
193 NewDC
->wndOrgY
= OrigDC
->wndOrgY
;
194 NewDC
->wndExtX
= OrigDC
->wndExtX
;
195 NewDC
->wndExtY
= OrigDC
->wndExtY
;
196 NewDC
->vportOrgX
= OrigDC
->vportOrgX
;
197 NewDC
->vportOrgY
= OrigDC
->vportOrgY
;
198 NewDC
->vportExtX
= OrigDC
->vportExtX
;
199 NewDC
->vportExtY
= OrigDC
->vportExtY
;
201 /* Create default bitmap */
202 if (!(hBitmap
= NtGdiCreateBitmap( 1, 1, 1, NewDC
->w
.bitsPerPixel
, NULL
)))
205 DC_UnlockDc( hNewDC
);
207 if (NULL
!= DisplayDC
)
209 NtGdiDeleteDC(DisplayDC
);
213 NewDC
->w
.flags
= DC_MEMORY
;
214 NewDC
->w
.hBitmap
= hBitmap
;
215 NewDC
->w
.hFirstBitmap
= hBitmap
;
216 NewDC
->GDIDevice
= OrigDC
->GDIDevice
;
217 pb
= BITMAPOBJ_LockBitmap(hBitmap
);
218 NewDC
->Surface
= BitmapToSurf(pb
, NewDC
->GDIDevice
);
219 BITMAPOBJ_UnlockBitmap(hBitmap
);
221 NewDC
->w
.hPalette
= OrigDC
->w
.hPalette
;
222 NewDC
->w
.textColor
= OrigDC
->w
.textColor
;
223 NewDC
->w
.textAlign
= OrigDC
->w
.textAlign
;
224 NewDC
->w
.backgroundColor
= OrigDC
->w
.backgroundColor
;
225 NewDC
->w
.backgroundMode
= OrigDC
->w
.backgroundMode
;
227 if (NULL
!= DisplayDC
)
229 NtGdiDeleteDC(DisplayDC
);
233 hVisRgn
= NtGdiCreateRectRgn(0, 0, 1, 1);
234 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
235 NtGdiDeleteObject(hVisRgn
);
243 GetRegistryPath(PUNICODE_STRING RegistryPath
)
245 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
248 RtlInitUnicodeString(RegistryPath
, NULL
);
249 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
250 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
251 QueryTable
[0].Name
= L
"\\Device\\Video0";
252 QueryTable
[0].EntryContext
= RegistryPath
;
254 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
259 if (! NT_SUCCESS(Status
))
261 DPRINT1("No \\Device\\Video0 value in DEVICEMAP\\VIDEO found\n");
265 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
271 FindDriverFileNames(PUNICODE_STRING DriverFileNames
)
273 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
274 UNICODE_STRING RegistryPath
;
277 if (! GetRegistryPath(&RegistryPath
))
279 DPRINT("GetRegistryPath failed\n");
283 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
284 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
285 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
286 QueryTable
[0].EntryContext
= DriverFileNames
;
288 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
293 RtlFreeUnicodeString(&RegistryPath
);
294 if (! NT_SUCCESS(Status
))
296 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
300 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
305 static NTSTATUS STDCALL
306 DevModeCallback(IN PWSTR ValueName
,
309 IN ULONG ValueLength
,
311 IN PVOID EntryContext
)
313 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
315 DPRINT("Found registry value for name %S: type %d, length %d\n",
316 ValueName
, ValueType
, ValueLength
);
318 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
320 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
322 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
324 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
326 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
328 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
330 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
332 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
334 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
336 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
338 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
340 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
342 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
344 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
346 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
350 return STATUS_SUCCESS
;
354 SetupDevMode(PDEVMODEW DevMode
)
356 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
357 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
358 static WCHAR ControlSet
[] = L
"CONTROLSET";
359 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
360 UNICODE_STRING RegistryPath
;
362 PWCHAR AfterControlSet
;
364 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
367 if (! GetRegistryPath(&RegistryPath
))
369 DPRINT("GetRegistryPath failed\n");
373 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
374 wcslen(RegistryMachineSystem
)));
377 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
378 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
380 AfterControlSet
+= wcslen(CurrentControlSet
);
382 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
384 AfterControlSet
+= wcslen(ControlSet
);
385 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
389 Valid
= (L
'\\' == *AfterControlSet
);
400 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
401 (wcslen(RegistryPath
.Buffer
) +
402 wcslen(Insert
) + 1) * sizeof(WCHAR
),
404 if (NULL
!= ProfilePath
)
406 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
407 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
408 wcscat(ProfilePath
, AfterControlSet
);
410 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
411 QueryTable
[0].QueryRoutine
= DevModeCallback
;
412 QueryTable
[0].Flags
= 0;
413 QueryTable
[0].Name
= NULL
;
414 QueryTable
[0].EntryContext
= NULL
;
415 QueryTable
[0].DefaultType
= REG_NONE
;
416 QueryTable
[0].DefaultData
= NULL
;
417 QueryTable
[0].DefaultLength
= 0;
419 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
424 if (! NT_SUCCESS(Status
))
426 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
427 ProfilePath
, Status
);
432 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
433 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
434 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
435 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
436 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
438 DPRINT("Not all required devmode members are set\n");
443 ExFreePool(ProfilePath
);
452 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
455 RtlFreeUnicodeString(&RegistryPath
);
459 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
466 IntCreatePrimarySurface()
468 PGD_ENABLEDRIVER GDEnableDriver
;
472 UNICODE_STRING DriverFileNames
;
477 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
479 ExInitializeFastMutex(&PrimarySurface
.DriverLock
);
481 /* Open the miniport driver */
482 if ((PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(L
"DISPLAY")) == NULL
)
484 DPRINT1("FindMPDriver failed\n");
488 /* Retrieve DDI driver names from registry */
489 RtlInitUnicodeString(&DriverFileNames
, NULL
);
490 if (! FindDriverFileNames(&DriverFileNames
))
492 DPRINT1("FindDriverFileNames failed\n");
496 /* DriverFileNames may be a list of drivers in REG_SZ_MULTI format, scan all of
497 them until a good one found */
498 CurrentName
= DriverFileNames
.Buffer
;
500 while (! GotDriver
&& CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
502 /* Get the DDI driver's entry point */
503 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
504 if (NULL
== GDEnableDriver
)
506 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
510 /* Call DDI driver's EnableDriver function */
511 RtlZeroMemory(&DED
, sizeof(DED
));
513 if (! GDEnableDriver(DDI_DRIVER_VERSION
, sizeof(DED
), &DED
))
515 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
525 /* Skip to the next name but never get past the Unicode string */
526 while (L
'\0' != *CurrentName
&&
527 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
531 if (CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
537 RtlFreeUnicodeString(&DriverFileNames
);
540 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
541 DPRINT1("No suitable DDI driver found\n");
545 DPRINT("Display driver %S loaded\n", CurrentName
);
547 DPRINT("Building DDI Functions\n");
549 /* Construct DDI driver function dispatch table */
550 if (! DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
552 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
553 DPRINT1("BuildDDIFunctions failed\n");
557 /* Allocate a phyical device handle from the driver */
558 if (SetupDevMode(&PrimarySurface
.DMW
))
560 PrimarySurface
.PDev
=
561 PrimarySurface
.DriverFunctions
.EnablePDev(&PrimarySurface
.DMW
,
564 PrimarySurface
.FillPatterns
,
565 sizeof(PrimarySurface
.GDIInfo
),
566 (ULONG
*) &PrimarySurface
.GDIInfo
,
567 sizeof(PrimarySurface
.DevInfo
),
568 &PrimarySurface
.DevInfo
,
571 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
572 DoDefault
= (NULL
== PrimarySurface
.PDev
);
575 DPRINT1("DrvEnablePDev with registry parameters failed\n");
585 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
586 PrimarySurface
.PDev
=
587 PrimarySurface
.DriverFunctions
.EnablePDev(&PrimarySurface
.DMW
,
590 PrimarySurface
.FillPatterns
,
591 sizeof(PrimarySurface
.GDIInfo
),
592 (ULONG
*) &PrimarySurface
.GDIInfo
,
593 sizeof(PrimarySurface
.DevInfo
),
594 &PrimarySurface
.DevInfo
,
597 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
599 if (NULL
== PrimarySurface
.PDev
)
601 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
602 DPRINT1("DrvEnablePDEV with default parameters failed\n");
603 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
608 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
610 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
611 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
613 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
615 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
616 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
619 DPRINT("calling completePDev\n");
621 /* Complete initialization of the physical device */
622 PrimarySurface
.DriverFunctions
.CompletePDev(PrimarySurface
.PDev
,
625 DPRINT("calling DRIVER_ReferenceDriver\n");
627 DRIVER_ReferenceDriver(L
"DISPLAY");
629 DPRINT("calling EnableSurface\n");
631 /* Enable the drawing surface */
632 PrimarySurface
.Handle
=
633 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
634 if (NULL
== PrimarySurface
.Handle
)
636 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
637 DPRINT1("DrvEnableSurface failed\n");
641 SurfObj
= (PSURFOBJ
)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
642 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
643 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
644 IntShowDesktop(IntGetActiveDesktop(),
645 SurfGDI
->SurfObj
.sizlBitmap
.cx
,
646 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
652 IntDestroyPrimarySurface()
659 DRIVER_UnreferenceDriver(L
"DISPLAY");
662 DPRINT("Hiding mouse pointer\n" );
663 SurfObj
= (PSURFOBJ
)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
664 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
665 SurfGDI
->SetPointerShape(SurfObj
, NULL
, NULL
, NULL
, 0, 0, 0, 0, 0, 0);
667 DPRINT("Reseting display\n" );
668 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
669 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
670 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
674 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
678 IntGdiCreateDC(PUNICODE_STRING Driver
,
679 PUNICODE_STRING Device
,
680 PUNICODE_STRING Output
,
681 CONST PDEVMODEW InitData
)
688 UNICODE_STRING StdDriver
;
690 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
692 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
694 if (! IntGraphicsCheck(TRUE
))
696 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
701 /* Check for existing DC object */
702 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
705 return NtGdiCreateCompatableDC(hDC
);
708 DPRINT("NAME: %S\n", Driver
); // FIXME: Should not crash if NULL
710 /* Allocate a DC object */
711 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
716 NewDC
= DC_LockDc( hNewDC
);
719 NewDC
->DMW
= PrimarySurface
.DMW
;
720 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
721 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
722 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
723 sizeof(NewDC
->FillPatternSurfaces
));
724 NewDC
->PDev
= PrimarySurface
.PDev
;
725 NewDC
->Surface
= PrimarySurface
.Handle
;
726 NewDC
->GDIDevice
= &PrimarySurface
;
727 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
729 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
730 NewDC
->DMW
.dmFields
= 0x000fc000;
732 /* FIXME: get mode selection information from somewhere */
734 NewDC
->DMW
.dmLogPixels
= 96;
735 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
736 NewDC
->DMW
.dmBitsPerPel
= SurfGDI
->BitsPerPixel
;
737 NewDC
->DMW
.dmPelsWidth
= SurfGDI
->SurfObj
.sizlBitmap
.cx
;
738 NewDC
->DMW
.dmPelsHeight
= SurfGDI
->SurfObj
.sizlBitmap
.cy
;
739 NewDC
->DMW
.dmDisplayFlags
= 0;
740 NewDC
->DMW
.dmDisplayFrequency
= 0;
742 NewDC
->w
.bitsPerPixel
= SurfGDI
->BitsPerPixel
; // FIXME: set this here??
744 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
746 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
748 DC_UnlockDc( hNewDC
);
750 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfGDI
->SurfObj
.sizlBitmap
.cx
,
751 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
752 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
753 NtGdiDeleteObject(hVisRgn
);
755 /* Initialize the DC state */
757 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
758 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
759 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
760 NtGdiSetBkMode(hNewDC
, OPAQUE
);
766 NtGdiCreateDC(PUNICODE_STRING Driver
,
767 PUNICODE_STRING Device
,
768 PUNICODE_STRING Output
,
769 CONST PDEVMODEW InitData
)
771 UNICODE_STRING SafeDriver
, SafeDevice
;
772 DEVMODEW SafeInitData
;
778 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
779 if(!NT_SUCCESS(Status
))
781 SetLastNtError(Status
);
784 /* FIXME - InitData can have some more bytes! */
789 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
790 if(!NT_SUCCESS(Status
))
792 SetLastNtError(Status
);
799 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
800 if(!NT_SUCCESS(Status
))
802 RtlFreeUnicodeString(&SafeDriver
);
803 SetLastNtError(Status
);
808 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
);
814 NtGdiCreateIC(PUNICODE_STRING Driver
,
815 PUNICODE_STRING Device
,
816 PUNICODE_STRING Output
,
817 CONST PDEVMODEW DevMode
)
819 /* FIXME: this should probably do something else... */
820 return NtGdiCreateDC(Driver
, Device
, Output
, DevMode
);
824 NtGdiDeleteDC(HDC DCHandle
)
828 DCToDelete
= DC_LockDc(DCHandle
);
829 if (DCToDelete
== NULL
)
833 DPRINT( "Deleting DC\n" );
835 /* First delete all saved DCs */
836 while (DCToDelete
->saveLevel
)
841 savedHDC
= DC_GetNextDC (DCToDelete
);
842 savedDC
= DC_LockDc (savedHDC
);
847 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
848 DCToDelete
->saveLevel
--;
849 DC_UnlockDc( savedHDC
);
850 NtGdiDeleteDC (savedHDC
);
853 /* Free GDI resources allocated to this DC */
854 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
857 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
858 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
859 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
860 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
861 if (DCToDelete
->w
.flags
& DC_MEMORY
)
863 EngDeleteSurface (DCToDelete
->Surface
);
864 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
867 if (DCToDelete
->w
.hClipRgn
)
869 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
871 if (DCToDelete
->w
.hVisRgn
)
873 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
875 if (NULL
!= DCToDelete
->CombinedClip
)
877 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
879 if (DCToDelete
->w
.hGCClipRgn
)
881 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
884 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
886 DC_UnlockDc( DCHandle
);
887 DC_FreeDC ( DCHandle
);
893 NtGdiDrawEscape(HDC hDC
,
902 NtGdiEnumObjects(HDC hDC
,
904 GOBJENUMPROC ObjectFunc
,
910 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
911 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
912 DC_GET_VAL_EX( NtGdiGetBrushOrgEx
, IntGetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
)
913 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
916 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
921 DC_GET_VAL_EX ( NtGdiGetCurrentPositionEx
, IntGetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
)
924 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
926 Point
->x
= dc
->w
.DCOrgX
;
927 Point
->y
= dc
->w
.DCOrgY
;
933 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
942 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
949 SetLastWin32Error(ERROR_INVALID_HANDLE
);
953 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
955 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
956 if(!NT_SUCCESS(Status
))
958 SetLastNtError(Status
);
968 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
971 PDC dc
= DC_LockDc(hDC
);
976 oldColor
= dc
->w
.backgroundColor
;
977 dc
->w
.backgroundColor
= color
;
983 NtGdiGetDCState(HDC hDC
)
994 hnewdc
= DC_AllocDC(NULL
);
1000 newdc
= DC_LockDc( hnewdc
);
1003 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1004 newdc
->w
.hPen
= dc
->w
.hPen
;
1005 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1006 newdc
->w
.hFont
= dc
->w
.hFont
;
1007 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1008 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1010 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1011 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1013 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1014 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1015 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1016 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1017 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1018 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1019 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1020 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1021 newdc
->w
.textColor
= dc
->w
.textColor
;
1022 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1023 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1024 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1025 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1026 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1027 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1028 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1029 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1030 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1031 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1033 /* Apparently, the DC origin is not changed by [GS]etDCState */
1034 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1035 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1037 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1038 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1039 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1040 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1041 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1042 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1043 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1044 newdc
->wndOrgX
= dc
->wndOrgX
;
1045 newdc
->wndOrgY
= dc
->wndOrgY
;
1046 newdc
->wndExtX
= dc
->wndExtX
;
1047 newdc
->wndExtY
= dc
->wndExtY
;
1048 newdc
->vportOrgX
= dc
->vportOrgX
;
1049 newdc
->vportOrgY
= dc
->vportOrgY
;
1050 newdc
->vportExtX
= dc
->vportExtX
;
1051 newdc
->vportExtY
= dc
->vportExtY
;
1053 newdc
->hSelf
= hnewdc
;
1054 newdc
->saveLevel
= 0;
1057 PATH_InitGdiPath( &newdc
->w
.path
);
1060 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1063 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1067 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1068 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1072 newdc
->w
.hClipRgn
= 0;
1074 DC_UnlockDc( hnewdc
);
1082 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1086 dc
= DC_LockDc ( hDC
);
1089 dcs
= DC_LockDc ( hDCSave
);
1092 if ( dcs
->w
.flags
& DC_SAVED
)
1094 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1096 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1099 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1102 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1103 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1104 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1105 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1106 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1107 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1108 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1109 dc
->w
.textColor
= dcs
->w
.textColor
;
1110 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1111 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1112 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1113 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1114 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1115 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1116 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1117 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1118 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1119 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1121 /* Apparently, the DC origin is not changed by [GS]etDCState */
1122 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1123 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1125 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1126 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1127 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1129 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1130 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1131 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1132 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1134 dc
->wndOrgX
= dcs
->wndOrgX
;
1135 dc
->wndOrgY
= dcs
->wndOrgY
;
1136 dc
->wndExtX
= dcs
->wndExtX
;
1137 dc
->wndExtY
= dcs
->wndExtY
;
1138 dc
->vportOrgX
= dcs
->vportOrgX
;
1139 dc
->vportOrgY
= dcs
->vportOrgY
;
1140 dc
->vportExtX
= dcs
->vportExtX
;
1141 dc
->vportExtY
= dcs
->vportExtY
;
1143 if (!(dc
->w
.flags
& DC_MEMORY
))
1145 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1149 if (dcs
->w
.hClipRgn
)
1151 if (!dc
->w
.hClipRgn
)
1153 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1155 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1161 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1166 CLIPPING_UpdateGCRegion( dc
);
1167 DC_UnlockDc ( hDC
);
1169 DC_UnlockDc ( hDC
);
1170 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1173 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1174 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1175 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1176 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1177 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1178 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1181 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1186 DC_UnlockDc ( hDCSave
);
1188 DC_UnlockDc ( hDC
);
1194 NtGdiGetDeviceCaps(HDC hDC
,
1201 dc
= DC_LockDc(hDC
);
1207 /* Retrieve capability */
1211 ret
= dc
->GDIInfo
->ulVersion
;
1215 ret
= dc
->GDIInfo
->ulTechnology
;
1219 ret
= dc
->GDIInfo
->ulHorzSize
;
1223 ret
= dc
->GDIInfo
->ulVertSize
;
1227 ret
= dc
->GDIInfo
->ulHorzRes
;
1231 ret
= dc
->GDIInfo
->ulVertRes
;
1235 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1239 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1243 ret
= dc
->GDIInfo
->cBitsPixel
;
1247 ret
= dc
->GDIInfo
->cPlanes
;
1251 UNIMPLEMENTED
; /* FIXME */
1255 UNIMPLEMENTED
; /* FIXME */
1259 UNIMPLEMENTED
; /* FIXME */
1263 ret
= dc
->GDIInfo
->ulNumColors
;
1267 ret
= dc
->GDIInfo
->ulAspectX
;
1271 ret
= dc
->GDIInfo
->ulAspectY
;
1275 ret
= dc
->GDIInfo
->ulAspectXY
;
1279 UNIMPLEMENTED
; /* FIXME */
1283 UNIMPLEMENTED
; /* FIXME */
1287 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1295 UNIMPLEMENTED
; /* FIXME */
1299 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1309 case PHYSICALHEIGHT
:
1310 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1320 case PHYSICALOFFSETX
:
1321 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1331 case PHYSICALOFFSETY
:
1332 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1343 UNIMPLEMENTED
; /* FIXME */
1346 case SCALINGFACTORX
:
1347 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1357 case SCALINGFACTORY
:
1358 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1369 ret
= dc
->GDIInfo
->flRaster
;
1373 UNIMPLEMENTED
; /* FIXME */
1377 UNIMPLEMENTED
; /* FIXME */
1381 UNIMPLEMENTED
; /* FIXME */
1385 ret
= dc
->GDIInfo
->flTextCaps
;
1393 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1399 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1400 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1403 IntGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1405 PGDIOBJHDR gdiObject
;
1409 gdiObject
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1413 objectType
= GDIOBJ_GetObjectType(handle
);
1416 /* case GDI_OBJECT_TYPE_PEN:
1417 result = PEN_GetObject((PENOBJ *)gdiObject, count, buffer);
1419 case GDI_OBJECT_TYPE_BRUSH:
1420 result = BRUSH_GetObject((BRUSHOBJ *)gdiObject, count, buffer);
1422 case GDI_OBJECT_TYPE_BITMAP
:
1423 result
= BITMAP_GetObject((BITMAPOBJ
*)gdiObject
, count
, buffer
);
1425 /* case GDI_OBJECT_TYPE_FONT:
1426 result = FONT_GetObjectW((FONTOBJ *)gdiObject, count, buffer);
1428 // Fix the LOGFONT structure for the stock fonts
1430 if ( (handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE) )
1431 FixStockFontSizeW(handle, count, buffer);
1433 case GDI_OBJECT_TYPE_PALETTE:
1434 result = PALETTE_GetObject((PALETTEOBJ *)gdiObject, count, buffer);
1437 DPRINT1("GDI object type 0x%08x not implemented\n", objectType
);
1441 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1447 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1458 SafeBuf
= ExAllocatePool(NonPagedPool
, count
);
1461 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1465 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1467 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1468 ExFreePool(SafeBuf
);
1469 if(!NT_SUCCESS(Status
))
1471 SetLastNtError(Status
);
1479 NtGdiGetObjectType(HANDLE handle
)
1485 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1489 objectType
= GDIOBJ_GetObjectType(handle
);
1492 case GDI_OBJECT_TYPE_PEN
:
1495 case GDI_OBJECT_TYPE_BRUSH
:
1498 case GDI_OBJECT_TYPE_BITMAP
:
1499 result
= OBJ_BITMAP
;
1501 case GDI_OBJECT_TYPE_FONT
:
1504 case GDI_OBJECT_TYPE_PALETTE
:
1507 case GDI_OBJECT_TYPE_REGION
:
1508 result
= OBJ_REGION
;
1510 case GDI_OBJECT_TYPE_DC
:
1513 case GDI_OBJECT_TYPE_METADC
:
1514 result
= OBJ_METADC
;
1516 case GDI_OBJECT_TYPE_METAFILE
:
1517 result
= OBJ_METAFILE
;
1519 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1520 result
= OBJ_ENHMETAFILE
;
1522 case GDI_OBJECT_TYPE_ENHMETADC
:
1523 result
= OBJ_ENHMETADC
;
1525 case GDI_OBJECT_TYPE_EXTPEN
:
1526 result
= OBJ_EXTPEN
;
1528 case GDI_OBJECT_TYPE_MEMDC
:
1532 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1535 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1539 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1540 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1541 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1542 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1543 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1544 DC_GET_VAL_EX( NtGdiGetViewportExtEx
, IntGetViewportExtEx
, vportExtX
, vportExtY
, SIZE
)
1545 DC_GET_VAL_EX( NtGdiGetViewportOrgEx
, IntGetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
)
1546 DC_GET_VAL_EX( NtGdiGetWindowExtEx
, IntGetWindowExtEx
, wndExtX
, wndExtY
, SIZE
)
1547 DC_GET_VAL_EX( NtGdiGetWindowOrgEx
, IntGetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
)
1550 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1556 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1561 dc
= DC_LockDc(hDC
);
1567 if (SaveLevel
== -1)
1569 SaveLevel
= dc
->saveLevel
;
1572 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1578 while (dc
->saveLevel
>= SaveLevel
)
1580 HDC hdcs
= DC_GetNextDC (dc
);
1582 dcs
= DC_LockDc (hdcs
);
1587 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1588 if (--dc
->saveLevel
< SaveLevel
)
1591 DC_UnlockDc( hdcs
);
1592 NtGdiSetDCState(hDC
, hdcs
);
1594 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1596 /* FIXME: This might not be quite right, since we're
1597 * returning FALSE but still destroying the saved DC state */
1601 dc
= DC_LockDc(hDC
);
1609 DC_UnlockDc( hdcs
);
1611 NtGdiDeleteDC (hdcs
);
1618 NtGdiSaveDC(HDC hDC
)
1624 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1629 dcs
= DC_LockDc (hdcs
);
1634 dc
= DC_LockDc (hDC
);
1642 /* Copy path. The reason why path saving / restoring is in SaveDC/
1643 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1644 * functions are only in Win16 (which doesn't have paths) and that
1645 * SetDCState doesn't allow us to signal an error (which can happen
1646 * when copying paths).
1648 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1650 NtGdiDeleteDC (hdcs
);
1655 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1656 DC_SetNextDC (dc
, hdcs
);
1657 ret
= ++dc
->saveLevel
;
1658 DC_UnlockDc( hdcs
);
1666 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1668 HGDIOBJ objOrg
= NULL
; // default to failure
1677 COLORREF MonoColorMap
[2];
1678 ULONG NumColors
, Index
;
1682 if(!hDC
|| !hGDIObj
) return NULL
;
1684 dc
= DC_LockDc(hDC
);
1687 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1691 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1695 case GDI_OBJECT_TYPE_PEN
:
1697 /* Convert the color of the pen to the format of the DC */
1698 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1701 Mode
= PalGDI
->Mode
;
1702 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1703 XlateObj
= (PXLATEOBJ
)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1704 if (NULL
!= XlateObj
)
1706 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1709 pen
->iSolidColor
= XLATEOBJ_iXlate(XlateObj
, pen
->logpen
.lopnColor
);
1710 PENOBJ_UnlockPen((HPEN
) hGDIObj
);
1711 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1712 dc
->w
.hPen
= hGDIObj
;
1716 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1718 EngDeleteXlate(XlateObj
);
1722 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1727 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1731 case GDI_OBJECT_TYPE_BRUSH
:
1733 /* Convert the color of the brush to the format of the DC */
1734 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1737 Mode
= PalGDI
->Mode
;
1738 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1739 XlateObj
= (PXLATEOBJ
)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1740 if (NULL
!= XlateObj
)
1742 brush
= BRUSHOBJ_LockBrush((HBRUSH
) hGDIObj
);
1745 brush
->iSolidColor
= XLATEOBJ_iXlate(XlateObj
, brush
->logbrush
.lbColor
);
1746 BRUSHOBJ_UnlockBrush((HBRUSH
) hGDIObj
);
1747 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1748 dc
->w
.hBrush
= (HBRUSH
) hGDIObj
;
1752 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1754 EngDeleteXlate(XlateObj
);
1758 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1763 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1767 case GDI_OBJECT_TYPE_FONT
:
1768 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1769 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1770 TextIntRealizeFont(dc
->w
.hFont
);
1773 case GDI_OBJECT_TYPE_BITMAP
:
1774 // must be memory dc to select bitmap
1775 if (!(dc
->w
.flags
& DC_MEMORY
))
1780 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1783 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1787 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1789 /* Release the old bitmap, lock the new one and convert it to a SURF */
1790 EngDeleteSurface(dc
->Surface
);
1791 dc
->w
.hBitmap
= hGDIObj
;
1792 dc
->Surface
= BitmapToSurf(pb
, dc
->GDIDevice
);
1794 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1797 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1799 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1801 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1802 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1803 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1805 ColorMap
= ExAllocatePoolWithTag(PagedPool
, sizeof(COLORREF
) * NumColors
, TAG_DC
);
1807 for (Index
= 0; Index
< NumColors
; Index
++)
1809 ColorMap
[Index
] = RGB(pb
->ColorMap
[Index
].rgbRed
,
1810 pb
->ColorMap
[Index
].rgbGreen
,
1811 pb
->ColorMap
[Index
].rgbBlue
);
1813 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, NumColors
, (ULONG
*) ColorMap
, 0, 0, 0);
1814 ExFreePool(ColorMap
);
1816 else if ( 16 == pb
->dib
->dsBmih
.biBitCount
)
1818 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0x7c00, 0x03e0, 0x001f);
1820 else if(pb
->dib
->dsBmih
.biBitCount
>= 24)
1822 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_RGB
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0, 0, 0);
1827 dc
->w
.bitsPerPixel
= pb
->bitmap
.bmBitsPixel
;
1828 if (1 == dc
->w
.bitsPerPixel
)
1830 MonoColorMap
[0] = RGB(0, 0, 0);
1831 MonoColorMap
[1] = RGB(255, 255, 255);
1832 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, 2, MonoColorMap
, 0, 0, 0);
1836 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1840 DC_UnlockDc ( hDC
);
1841 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->size
.cx
, pb
->size
.cy
);
1842 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1843 NtGdiDeleteObject ( hVisRgn
);
1844 BITMAPOBJ_UnlockBitmap(hGDIObj
);
1849 case GDI_OBJECT_TYPE_REGION
:
1850 DC_UnlockDc ( hDC
);
1851 SelectClipRgn(hDC
, (HRGN
)hGDIObj
);
1862 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1865 DC
*dc
= DC_LockDc(hDC
);
1872 wRet
= dc
->w
.flags
& DC_DIRTY
;
1874 /* "Undocumented Windows" info is slightly confusing.
1877 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1879 if (Flags
& DCHF_INVALIDATEVISRGN
)
1881 dc
->w
.flags
|= DC_DIRTY
;
1883 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1885 dc
->w
.flags
&= ~DC_DIRTY
;
1893 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1894 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1895 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1896 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1897 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
1899 // ---------------------------------------------------- Private Interface
1902 DC_AllocDC(PUNICODE_STRING Driver
)
1910 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
1915 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
1918 hDC
= (HDC
) GDIOBJ_AllocObj(sizeof(DC
), GDI_OBJECT_TYPE_DC
, (GDICLEANUPPROC
) DC_InternalDeleteDC
);
1928 NewDC
= DC_LockDc(hDC
);
1932 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
1933 NewDC
->DriverName
.Buffer
= Buf
;
1936 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1937 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1938 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1939 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1940 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1941 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1942 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
1943 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
1944 NewDC
->w
.vport2WorldValid
= TRUE
;
1945 NewDC
->w
.MapMode
= MM_TEXT
;
1947 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
1948 TextIntRealizeFont(NewDC
->w
.hFont
);
1956 DC_FindOpenDC(PUNICODE_STRING Driver
)
1962 * Initialize some common fields in the Device Context structure.
1965 DC_InitDC(HDC DCHandle
)
1967 // NtGdiRealizeDefaultPalette(DCHandle);
1969 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
1970 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
1971 //NtGdiSelectObject(DCHandle, hFont);
1973 // CLIPPING_UpdateGCRegion(DCToInit);
1978 DC_FreeDC(HDC DCToFree
)
1980 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
, GDIOBJFLAG_DEFAULT
))
1982 DPRINT("DC_FreeDC failed\n");
1987 DC_InternalDeleteDC( PDC DCToDelete
)
1990 RtlFreeUnicodeString(&DCToDelete
->DriverName
);
1995 DC_GetNextDC (PDC pDC
)
2001 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2003 pDC
->hNext
= hNextDC
;
2007 DC_UpdateXforms(PDC dc
)
2009 XFORM xformWnd2Vport
;
2010 FLOAT scaleX
, scaleY
;
2012 /* Construct a transformation to do the window-to-viewport conversion */
2013 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0);
2014 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0);
2015 xformWnd2Vport
.eM11
= scaleX
;
2016 xformWnd2Vport
.eM12
= 0.0;
2017 xformWnd2Vport
.eM21
= 0.0;
2018 xformWnd2Vport
.eM22
= scaleY
;
2019 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2020 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2022 /* Combine with the world transformation */
2023 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2025 /* Create inverse of world-to-viewport transformation */
2026 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2030 DC_InvertXform(const XFORM
*xformSrc
,
2035 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2036 if (determinant
> -1e-12 && determinant
< 1e-12)
2041 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2042 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2043 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2044 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2045 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2046 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2052 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2056 GDIOBJ_SetOwnership(hDC
, Owner
);
2057 DC
= DC_LockDc(hDC
);
2060 if (NULL
!= DC
->w
.hClipRgn
)
2062 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2064 if (NULL
!= DC
->w
.hVisRgn
)
2066 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2068 if (NULL
!= DC
->w
.hGCClipRgn
)
2070 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);