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.125 2004/03/23 19:46:50 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>
56 #include <include/text.h>
59 #include <win32k/debug1.h>
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
= hNewDC
;
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
, ULONG DisplayNumber
)
245 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
246 WCHAR DeviceNameBuffer
[20];
249 swprintf(DeviceNameBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
250 RtlInitUnicodeString(RegistryPath
, NULL
);
251 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
252 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
253 QueryTable
[0].Name
= DeviceNameBuffer
;
254 QueryTable
[0].EntryContext
= RegistryPath
;
256 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
261 if (! NT_SUCCESS(Status
))
263 DPRINT1("No \\Device\\Video%d value in DEVICEMAP\\VIDEO found\n", DisplayNumber
);
267 DPRINT("RegistryPath %S\n", RegistryPath
->Buffer
);
273 FindDriverFileNames(PUNICODE_STRING DriverFileNames
, ULONG DisplayNumber
)
275 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
276 UNICODE_STRING RegistryPath
;
279 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
281 DPRINT("GetRegistryPath failed\n");
285 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
286 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
| RTL_QUERY_REGISTRY_DIRECT
;
287 QueryTable
[0].Name
= L
"InstalledDisplayDrivers";
288 QueryTable
[0].EntryContext
= DriverFileNames
;
290 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
295 RtlFreeUnicodeString(&RegistryPath
);
296 if (! NT_SUCCESS(Status
))
298 DPRINT1("No InstalledDisplayDrivers value in service entry found\n");
302 DPRINT("DriverFileNames %S\n", DriverFileNames
->Buffer
);
307 static NTSTATUS STDCALL
308 DevModeCallback(IN PWSTR ValueName
,
311 IN ULONG ValueLength
,
313 IN PVOID EntryContext
)
315 PDEVMODEW DevMode
= (PDEVMODEW
) Context
;
317 DPRINT("Found registry value for name %S: type %d, length %d\n",
318 ValueName
, ValueType
, ValueLength
);
320 if (REG_DWORD
== ValueType
&& sizeof(DWORD
) == ValueLength
)
322 if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.BitsPerPel"))
324 DevMode
->dmBitsPerPel
= *((DWORD
*) ValueData
);
326 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.Flags"))
328 DevMode
->dmDisplayFlags
= *((DWORD
*) ValueData
);
330 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.VRefresh"))
332 DevMode
->dmDisplayFrequency
= *((DWORD
*) ValueData
);
334 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XPanning"))
336 DevMode
->dmPanningWidth
= *((DWORD
*) ValueData
);
338 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.XResolution"))
340 DevMode
->dmPelsWidth
= *((DWORD
*) ValueData
);
342 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YPanning"))
344 DevMode
->dmPanningHeight
= *((DWORD
*) ValueData
);
346 else if (0 == _wcsicmp(ValueName
, L
"DefaultSettings.YResolution"))
348 DevMode
->dmPelsHeight
= *((DWORD
*) ValueData
);
352 return STATUS_SUCCESS
;
356 SetupDevMode(PDEVMODEW DevMode
, ULONG DisplayNumber
)
358 static WCHAR RegistryMachineSystem
[] = L
"\\REGISTRY\\MACHINE\\SYSTEM\\";
359 static WCHAR CurrentControlSet
[] = L
"CURRENTCONTROLSET\\";
360 static WCHAR ControlSet
[] = L
"CONTROLSET";
361 static WCHAR Insert
[] = L
"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
362 UNICODE_STRING RegistryPath
;
364 PWCHAR AfterControlSet
;
366 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
369 if (! GetRegistryPath(&RegistryPath
, DisplayNumber
))
371 DPRINT("GetRegistryPath failed\n");
375 Valid
= (0 == _wcsnicmp(RegistryPath
.Buffer
, RegistryMachineSystem
,
376 wcslen(RegistryMachineSystem
)));
379 AfterControlSet
= RegistryPath
.Buffer
+ wcslen(RegistryMachineSystem
);
380 if (0 == _wcsnicmp(AfterControlSet
, CurrentControlSet
, wcslen(CurrentControlSet
)))
382 AfterControlSet
+= wcslen(CurrentControlSet
);
384 else if (0 == _wcsnicmp(AfterControlSet
, ControlSet
, wcslen(ControlSet
)))
386 AfterControlSet
+= wcslen(ControlSet
);
387 while (L
'0' <= *AfterControlSet
&& L
'9' <= *AfterControlSet
)
391 Valid
= (L
'\\' == *AfterControlSet
);
402 ProfilePath
= ExAllocatePoolWithTag(PagedPool
,
403 (wcslen(RegistryPath
.Buffer
) +
404 wcslen(Insert
) + 1) * sizeof(WCHAR
),
406 if (NULL
!= ProfilePath
)
408 wcsncpy(ProfilePath
, RegistryPath
.Buffer
, AfterControlSet
- RegistryPath
.Buffer
);
409 wcscpy(ProfilePath
+ (AfterControlSet
- RegistryPath
.Buffer
), Insert
);
410 wcscat(ProfilePath
, AfterControlSet
);
412 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
413 QueryTable
[0].QueryRoutine
= DevModeCallback
;
414 QueryTable
[0].Flags
= 0;
415 QueryTable
[0].Name
= NULL
;
416 QueryTable
[0].EntryContext
= NULL
;
417 QueryTable
[0].DefaultType
= REG_NONE
;
418 QueryTable
[0].DefaultData
= NULL
;
419 QueryTable
[0].DefaultLength
= 0;
421 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
426 if (! NT_SUCCESS(Status
))
428 DPRINT("RtlQueryRegistryValues for %S failed with status 0x%08x\n",
429 ProfilePath
, Status
);
434 DPRINT("dmBitsPerPel %d dmDisplayFrequency %d dmPelsWidth %d dmPelsHeight %d\n",
435 DevMode
->dmBitsPerPel
, DevMode
->dmDisplayFrequency
,
436 DevMode
->dmPelsWidth
, DevMode
->dmPelsHeight
);
437 if (0 == DevMode
->dmBitsPerPel
|| 0 == DevMode
->dmDisplayFrequency
438 || 0 == DevMode
->dmPelsWidth
|| 0 == DevMode
->dmPelsHeight
)
440 DPRINT("Not all required devmode members are set\n");
445 ExFreePool(ProfilePath
);
454 DPRINT1("Unparsable registry path %S in DEVICEMAP\\VIDEO0", RegistryPath
.Buffer
);
457 RtlFreeUnicodeString(&RegistryPath
);
461 RtlZeroMemory(DevMode
, sizeof(DEVMODEW
));
468 IntCreatePrimarySurface()
470 PGD_ENABLEDRIVER GDEnableDriver
;
474 UNICODE_STRING DriverFileNames
;
480 for (DisplayNumber
= 0; ; DisplayNumber
++)
482 DPRINT("Trying to load display driver no. %d\n", DisplayNumber
);
484 RtlZeroMemory(&PrimarySurface
, sizeof(PrimarySurface
));
485 ExInitializeFastMutex(&PrimarySurface
.DriverLock
);
487 PrimarySurface
.VideoFileObject
= DRIVER_FindMPDriver(DisplayNumber
);
489 /* Open the miniport driver */
490 if (PrimarySurface
.VideoFileObject
== NULL
)
492 DPRINT1("FindMPDriver failed\n");
496 /* Retrieve DDI driver names from registry */
497 RtlInitUnicodeString(&DriverFileNames
, NULL
);
498 if (!FindDriverFileNames(&DriverFileNames
, DisplayNumber
))
500 DPRINT1("FindDriverFileNames failed\n");
506 * DriverFileNames may be a list of drivers in REG_SZ_MULTI format,
507 * scan all of them until a good one found.
509 CurrentName
= DriverFileNames
.Buffer
;
512 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
514 /* Get the DDI driver's entry point */
515 GDEnableDriver
= DRIVER_FindDDIDriver(CurrentName
);
516 if (NULL
== GDEnableDriver
)
518 DPRINT("FindDDIDriver failed for %S\n", CurrentName
);
522 /* Call DDI driver's EnableDriver function */
523 RtlZeroMemory(&DED
, sizeof(DED
));
525 if (! GDEnableDriver(DDI_DRIVER_VERSION
, sizeof(DED
), &DED
))
527 DPRINT("DrvEnableDriver failed for %S\n", CurrentName
);
537 /* Skip to the next name but never get past the Unicode string */
538 while (L
'\0' != *CurrentName
&&
539 CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
543 if (CurrentName
< DriverFileNames
.Buffer
+ DriverFileNames
.Length
)
550 RtlFreeUnicodeString(&DriverFileNames
);
554 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
555 DPRINT1("No suitable DDI driver found\n");
560 DPRINT("Display driver %S loaded\n", CurrentName
);
562 DPRINT("Building DDI Functions\n");
564 /* Construct DDI driver function dispatch table */
565 if (!DRIVER_BuildDDIFunctions(&DED
, &PrimarySurface
.DriverFunctions
))
567 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
568 DPRINT1("BuildDDIFunctions failed\n");
572 /* Allocate a phyical device handle from the driver */
573 if (SetupDevMode(&PrimarySurface
.DMW
, DisplayNumber
))
575 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDev(
579 PrimarySurface
.FillPatterns
,
580 sizeof(PrimarySurface
.GDIInfo
),
581 (ULONG
*) &PrimarySurface
.GDIInfo
,
582 sizeof(PrimarySurface
.DevInfo
),
583 &PrimarySurface
.DevInfo
,
586 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
587 DoDefault
= (NULL
== PrimarySurface
.PDev
);
590 DPRINT1("DrvEnablePDev with registry parameters failed\n");
600 RtlZeroMemory(&(PrimarySurface
.DMW
), sizeof(DEVMODEW
));
601 PrimarySurface
.PDev
= PrimarySurface
.DriverFunctions
.EnablePDev(
605 PrimarySurface
.FillPatterns
,
606 sizeof(PrimarySurface
.GDIInfo
),
607 (ULONG
*) &PrimarySurface
.GDIInfo
,
608 sizeof(PrimarySurface
.DevInfo
),
609 &PrimarySurface
.DevInfo
,
612 (HANDLE
) (PrimarySurface
.VideoFileObject
->DeviceObject
));
614 if (NULL
== PrimarySurface
.PDev
)
616 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
617 DPRINT1("DrvEnablePDEV with default parameters failed\n");
618 DPRINT1("Perhaps DDI driver doesn't match miniport driver?\n");
624 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsX
)
626 DPRINT("Adjusting GDIInfo.ulLogPixelsX\n");
627 PrimarySurface
.GDIInfo
.ulLogPixelsX
= 96;
629 if (0 == PrimarySurface
.GDIInfo
.ulLogPixelsY
)
631 DPRINT("Adjusting GDIInfo.ulLogPixelsY\n");
632 PrimarySurface
.GDIInfo
.ulLogPixelsY
= 96;
635 DPRINT("calling completePDev\n");
637 /* Complete initialization of the physical device */
638 PrimarySurface
.DriverFunctions
.CompletePDev(
642 DPRINT("calling DRIVER_ReferenceDriver\n");
644 DRIVER_ReferenceDriver(L
"DISPLAY");
646 DPRINT("calling EnableSurface\n");
648 /* Enable the drawing surface */
649 PrimarySurface
.Handle
=
650 PrimarySurface
.DriverFunctions
.EnableSurface(PrimarySurface
.PDev
);
651 if (NULL
== PrimarySurface
.Handle
)
653 /* PrimarySurface.DriverFunctions.AssertMode(PrimarySurface.PDev, FALSE);*/
654 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
655 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
656 DPRINT1("DrvEnableSurface failed\n");
661 SurfObj
= (PSURFOBJ
)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
662 SurfObj
->dhpdev
= PrimarySurface
.PDev
;
663 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
665 IntGetActiveDesktop(),
666 SurfGDI
->SurfObj
.sizlBitmap
.cx
,
667 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
675 IntDestroyPrimarySurface()
682 DRIVER_UnreferenceDriver(L
"DISPLAY");
685 DPRINT("Hiding mouse pointer\n" );
686 SurfObj
= (PSURFOBJ
)AccessUserObject((ULONG
) PrimarySurface
.Handle
);
687 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
688 SurfGDI
->SetPointerShape(SurfObj
, NULL
, NULL
, NULL
, 0, 0, 0, 0, 0, 0);
690 DPRINT("Reseting display\n" );
691 PrimarySurface
.DriverFunctions
.AssertMode(PrimarySurface
.PDev
, FALSE
);
692 PrimarySurface
.DriverFunctions
.DisableSurface(PrimarySurface
.PDev
);
693 PrimarySurface
.DriverFunctions
.DisablePDev(PrimarySurface
.PDev
);
697 ObDereferenceObject(PrimarySurface
.VideoFileObject
);
701 IntGdiCreateDC(PUNICODE_STRING Driver
,
702 PUNICODE_STRING Device
,
703 PUNICODE_STRING Output
,
704 CONST PDEVMODEW InitData
)
711 UNICODE_STRING StdDriver
;
713 RtlInitUnicodeString(&StdDriver
, L
"DISPLAY");
715 if (NULL
== Driver
|| 0 == RtlCompareUnicodeString(Driver
, &StdDriver
, TRUE
))
717 if (! IntGraphicsCheck(TRUE
))
719 DPRINT1("Unable to initialize graphics, returning NULL dc\n");
724 /* Check for existing DC object */
725 if ((hNewDC
= DC_FindOpenDC(Driver
)) != NULL
)
728 return NtGdiCreateCompatableDC(hDC
);
731 if (Driver
!= NULL
&& Driver
->Buffer
!= NULL
)
733 DPRINT("NAME: %S\n", Driver
->Buffer
); // FIXME: Should not crash if NULL
736 /* Allocate a DC object */
737 if ((hNewDC
= DC_AllocDC(Driver
)) == NULL
)
742 NewDC
= DC_LockDc( hNewDC
);
745 NewDC
->DMW
= PrimarySurface
.DMW
;
746 NewDC
->DevInfo
= &PrimarySurface
.DevInfo
;
747 NewDC
->GDIInfo
= &PrimarySurface
.GDIInfo
;
748 memcpy(NewDC
->FillPatternSurfaces
, PrimarySurface
.FillPatterns
,
749 sizeof(NewDC
->FillPatternSurfaces
));
750 NewDC
->PDev
= PrimarySurface
.PDev
;
751 NewDC
->Surface
= PrimarySurface
.Handle
;
752 NewDC
->GDIDevice
= &PrimarySurface
;
753 NewDC
->DriverFunctions
= PrimarySurface
.DriverFunctions
;
755 NewDC
->DMW
.dmSize
= sizeof(NewDC
->DMW
);
756 NewDC
->DMW
.dmFields
= 0x000fc000;
758 /* FIXME: get mode selection information from somewhere */
760 NewDC
->DMW
.dmLogPixels
= 96;
761 SurfGDI
= (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
);
762 NewDC
->DMW
.dmBitsPerPel
= SurfGDI
->BitsPerPixel
;
763 NewDC
->DMW
.dmPelsWidth
= SurfGDI
->SurfObj
.sizlBitmap
.cx
;
764 NewDC
->DMW
.dmPelsHeight
= SurfGDI
->SurfObj
.sizlBitmap
.cy
;
765 NewDC
->DMW
.dmDisplayFlags
= 0;
766 NewDC
->DMW
.dmDisplayFrequency
= 0;
768 NewDC
->w
.bitsPerPixel
= SurfGDI
->BitsPerPixel
; // FIXME: set this here??
770 NewDC
->w
.hPalette
= NewDC
->DevInfo
->hpalDefault
;
772 DPRINT("Bits per pel: %u\n", NewDC
->w
.bitsPerPixel
);
774 DC_UnlockDc( hNewDC
);
776 hVisRgn
= NtGdiCreateRectRgn(0, 0, SurfGDI
->SurfObj
.sizlBitmap
.cx
,
777 SurfGDI
->SurfObj
.sizlBitmap
.cy
);
778 NtGdiSelectVisRgn(hNewDC
, hVisRgn
);
779 NtGdiDeleteObject(hVisRgn
);
781 /* Initialize the DC state */
783 NtGdiSetTextColor(hNewDC
, RGB(0, 0, 0));
784 NtGdiSetTextAlign(hNewDC
, TA_TOP
);
785 NtGdiSetBkColor(hNewDC
, RGB(255, 255, 255));
786 NtGdiSetBkMode(hNewDC
, OPAQUE
);
792 NtGdiCreateDC(PUNICODE_STRING Driver
,
793 PUNICODE_STRING Device
,
794 PUNICODE_STRING Output
,
795 CONST PDEVMODEW InitData
)
797 UNICODE_STRING SafeDriver
, SafeDevice
;
798 DEVMODEW SafeInitData
;
804 Status
= MmCopyFromCaller(&SafeInitData
, InitData
, sizeof(DEVMODEW
));
805 if(!NT_SUCCESS(Status
))
807 SetLastNtError(Status
);
810 /* FIXME - InitData can have some more bytes! */
815 Status
= IntSafeCopyUnicodeString(&SafeDriver
, Driver
);
816 if(!NT_SUCCESS(Status
))
818 SetLastNtError(Status
);
825 Status
= IntSafeCopyUnicodeString(&SafeDevice
, Device
);
826 if(!NT_SUCCESS(Status
))
828 RtlFreeUnicodeString(&SafeDriver
);
829 SetLastNtError(Status
);
834 Ret
= IntGdiCreateDC(&SafeDriver
, &SafeDevice
, NULL
, &SafeInitData
);
840 NtGdiCreateIC(PUNICODE_STRING Driver
,
841 PUNICODE_STRING Device
,
842 PUNICODE_STRING Output
,
843 CONST PDEVMODEW DevMode
)
845 /* FIXME: this should probably do something else... */
846 return NtGdiCreateDC(Driver
, Device
, Output
, DevMode
);
850 NtGdiDeleteDC(HDC DCHandle
)
854 DCToDelete
= DC_LockDc(DCHandle
);
855 if (DCToDelete
== NULL
)
859 DPRINT( "Deleting DC\n" );
861 /* First delete all saved DCs */
862 while (DCToDelete
->saveLevel
)
867 savedHDC
= DC_GetNextDC (DCToDelete
);
868 savedDC
= DC_LockDc (savedHDC
);
873 DC_SetNextDC (DCToDelete
, DC_GetNextDC (savedDC
));
874 DCToDelete
->saveLevel
--;
875 DC_UnlockDc( savedHDC
);
876 NtGdiDeleteDC (savedHDC
);
879 /* Free GDI resources allocated to this DC */
880 if (!(DCToDelete
->w
.flags
& DC_SAVED
))
883 NtGdiSelectObject (DCHandle, STOCK_BLACK_PEN);
884 NtGdiSelectObject (DCHandle, STOCK_WHITE_BRUSH);
885 NtGdiSelectObject (DCHandle, STOCK_SYSTEM_FONT);
886 DC_LockDC (DCHandle); NtGdiSelectObject does not recognize stock objects yet */
887 if (DCToDelete
->w
.flags
& DC_MEMORY
)
889 EngDeleteSurface (DCToDelete
->Surface
);
890 NtGdiDeleteObject (DCToDelete
->w
.hFirstBitmap
);
893 if (DCToDelete
->w
.hClipRgn
)
895 NtGdiDeleteObject (DCToDelete
->w
.hClipRgn
);
897 if (DCToDelete
->w
.hVisRgn
)
899 NtGdiDeleteObject (DCToDelete
->w
.hVisRgn
);
901 if (NULL
!= DCToDelete
->CombinedClip
)
903 IntEngDeleteClipRegion(DCToDelete
->CombinedClip
);
905 if (DCToDelete
->w
.hGCClipRgn
)
907 NtGdiDeleteObject (DCToDelete
->w
.hGCClipRgn
);
910 PATH_DestroyGdiPath (&DCToDelete
->w
.path
);
912 DC_UnlockDc( DCHandle
);
913 DC_FreeDC ( DCHandle
);
919 NtGdiDrawEscape(HDC hDC
,
928 NtGdiEnumObjects(HDC hDC
,
930 GOBJENUMPROC ObjectFunc
,
936 DC_GET_VAL( COLORREF
, NtGdiGetBkColor
, w
.backgroundColor
)
937 DC_GET_VAL( INT
, NtGdiGetBkMode
, w
.backgroundMode
)
938 DC_GET_VAL_EX( NtGdiGetBrushOrgEx
, IntGetBrushOrgEx
, w
.brushOrgX
, w
.brushOrgY
, POINT
)
939 DC_GET_VAL( HRGN
, NtGdiGetClipRgn
, w
.hClipRgn
)
942 NtGdiGetCurrentObject(HDC hDC
, UINT ObjectType
)
947 DC_GET_VAL_EX ( NtGdiGetCurrentPositionEx
, IntGetCurrentPositionEx
, w
.CursPosX
, w
.CursPosY
, POINT
)
950 IntGdiGetDCOrgEx(DC
*dc
, LPPOINT Point
)
952 Point
->x
= dc
->w
.DCOrgX
;
953 Point
->y
= dc
->w
.DCOrgY
;
959 NtGdiGetDCOrgEx(HDC hDC
, LPPOINT Point
)
968 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
975 SetLastWin32Error(ERROR_INVALID_HANDLE
);
979 Ret
= IntGdiGetDCOrgEx(dc
, &SafePoint
);
981 Status
= MmCopyToCaller(Point
, &SafePoint
, sizeof(POINT
));
982 if(!NT_SUCCESS(Status
))
984 SetLastNtError(Status
);
994 NtGdiSetBkColor(HDC hDC
, COLORREF color
)
997 PDC dc
= DC_LockDc(hDC
);
1002 oldColor
= dc
->w
.backgroundColor
;
1003 dc
->w
.backgroundColor
= color
;
1004 DC_UnlockDc ( hDC
);
1009 NtGdiGetDCState(HDC hDC
)
1014 dc
= DC_LockDc(hDC
);
1020 hnewdc
= DC_AllocDC(NULL
);
1026 newdc
= DC_LockDc( hnewdc
);
1029 newdc
->w
.flags
= dc
->w
.flags
| DC_SAVED
;
1030 newdc
->w
.hPen
= dc
->w
.hPen
;
1031 newdc
->w
.hBrush
= dc
->w
.hBrush
;
1032 newdc
->w
.hFont
= dc
->w
.hFont
;
1033 newdc
->w
.hBitmap
= dc
->w
.hBitmap
;
1034 newdc
->w
.hFirstBitmap
= dc
->w
.hFirstBitmap
;
1036 newdc
->w
.hDevice
= dc
->w
.hDevice
;
1037 newdc
->w
.hPalette
= dc
->w
.hPalette
;
1039 newdc
->w
.totalExtent
= dc
->w
.totalExtent
;
1040 newdc
->w
.bitsPerPixel
= dc
->w
.bitsPerPixel
;
1041 newdc
->w
.ROPmode
= dc
->w
.ROPmode
;
1042 newdc
->w
.polyFillMode
= dc
->w
.polyFillMode
;
1043 newdc
->w
.stretchBltMode
= dc
->w
.stretchBltMode
;
1044 newdc
->w
.relAbsMode
= dc
->w
.relAbsMode
;
1045 newdc
->w
.backgroundMode
= dc
->w
.backgroundMode
;
1046 newdc
->w
.backgroundColor
= dc
->w
.backgroundColor
;
1047 newdc
->w
.textColor
= dc
->w
.textColor
;
1048 newdc
->w
.brushOrgX
= dc
->w
.brushOrgX
;
1049 newdc
->w
.brushOrgY
= dc
->w
.brushOrgY
;
1050 newdc
->w
.textAlign
= dc
->w
.textAlign
;
1051 newdc
->w
.charExtra
= dc
->w
.charExtra
;
1052 newdc
->w
.breakTotalExtra
= dc
->w
.breakTotalExtra
;
1053 newdc
->w
.breakCount
= dc
->w
.breakCount
;
1054 newdc
->w
.breakExtra
= dc
->w
.breakExtra
;
1055 newdc
->w
.breakRem
= dc
->w
.breakRem
;
1056 newdc
->w
.MapMode
= dc
->w
.MapMode
;
1057 newdc
->w
.GraphicsMode
= dc
->w
.GraphicsMode
;
1059 /* Apparently, the DC origin is not changed by [GS]etDCState */
1060 newdc
->w
.DCOrgX
= dc
->w
.DCOrgX
;
1061 newdc
->w
.DCOrgY
= dc
->w
.DCOrgY
;
1063 newdc
->w
.CursPosX
= dc
->w
.CursPosX
;
1064 newdc
->w
.CursPosY
= dc
->w
.CursPosY
;
1065 newdc
->w
.ArcDirection
= dc
->w
.ArcDirection
;
1066 newdc
->w
.xformWorld2Wnd
= dc
->w
.xformWorld2Wnd
;
1067 newdc
->w
.xformWorld2Vport
= dc
->w
.xformWorld2Vport
;
1068 newdc
->w
.xformVport2World
= dc
->w
.xformVport2World
;
1069 newdc
->w
.vport2WorldValid
= dc
->w
.vport2WorldValid
;
1070 newdc
->wndOrgX
= dc
->wndOrgX
;
1071 newdc
->wndOrgY
= dc
->wndOrgY
;
1072 newdc
->wndExtX
= dc
->wndExtX
;
1073 newdc
->wndExtY
= dc
->wndExtY
;
1074 newdc
->vportOrgX
= dc
->vportOrgX
;
1075 newdc
->vportOrgY
= dc
->vportOrgY
;
1076 newdc
->vportExtX
= dc
->vportExtX
;
1077 newdc
->vportExtY
= dc
->vportExtY
;
1079 newdc
->hSelf
= hnewdc
;
1080 newdc
->saveLevel
= 0;
1083 PATH_InitGdiPath( &newdc
->w
.path
);
1086 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
1089 newdc
->w
.hGCClipRgn
= newdc
->w
.hVisRgn
= 0;
1093 newdc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1094 NtGdiCombineRgn( newdc
->w
.hClipRgn
, dc
->w
.hClipRgn
, 0, RGN_COPY
);
1098 newdc
->w
.hClipRgn
= 0;
1100 DC_UnlockDc( hnewdc
);
1108 NtGdiSetDCState ( HDC hDC
, HDC hDCSave
)
1112 dc
= DC_LockDc ( hDC
);
1115 dcs
= DC_LockDc ( hDCSave
);
1118 if ( dcs
->w
.flags
& DC_SAVED
)
1120 dc
->w
.flags
= dcs
->w
.flags
& ~DC_SAVED
;
1122 dc
->w
.hFirstBitmap
= dcs
->w
.hFirstBitmap
;
1125 dc
->w
.hDevice
= dcs
->w
.hDevice
;
1128 dc
->w
.totalExtent
= dcs
->w
.totalExtent
;
1129 dc
->w
.ROPmode
= dcs
->w
.ROPmode
;
1130 dc
->w
.polyFillMode
= dcs
->w
.polyFillMode
;
1131 dc
->w
.stretchBltMode
= dcs
->w
.stretchBltMode
;
1132 dc
->w
.relAbsMode
= dcs
->w
.relAbsMode
;
1133 dc
->w
.backgroundMode
= dcs
->w
.backgroundMode
;
1134 dc
->w
.backgroundColor
= dcs
->w
.backgroundColor
;
1135 dc
->w
.textColor
= dcs
->w
.textColor
;
1136 dc
->w
.brushOrgX
= dcs
->w
.brushOrgX
;
1137 dc
->w
.brushOrgY
= dcs
->w
.brushOrgY
;
1138 dc
->w
.textAlign
= dcs
->w
.textAlign
;
1139 dc
->w
.charExtra
= dcs
->w
.charExtra
;
1140 dc
->w
.breakTotalExtra
= dcs
->w
.breakTotalExtra
;
1141 dc
->w
.breakCount
= dcs
->w
.breakCount
;
1142 dc
->w
.breakExtra
= dcs
->w
.breakExtra
;
1143 dc
->w
.breakRem
= dcs
->w
.breakRem
;
1144 dc
->w
.MapMode
= dcs
->w
.MapMode
;
1145 dc
->w
.GraphicsMode
= dcs
->w
.GraphicsMode
;
1147 /* Apparently, the DC origin is not changed by [GS]etDCState */
1148 dc
->w
.DCOrgX
= dcs
->w
.DCOrgX
;
1149 dc
->w
.DCOrgY
= dcs
->w
.DCOrgY
;
1151 dc
->w
.CursPosX
= dcs
->w
.CursPosX
;
1152 dc
->w
.CursPosY
= dcs
->w
.CursPosY
;
1153 dc
->w
.ArcDirection
= dcs
->w
.ArcDirection
;
1155 dc
->w
.xformWorld2Wnd
= dcs
->w
.xformWorld2Wnd
;
1156 dc
->w
.xformWorld2Vport
= dcs
->w
.xformWorld2Vport
;
1157 dc
->w
.xformVport2World
= dcs
->w
.xformVport2World
;
1158 dc
->w
.vport2WorldValid
= dcs
->w
.vport2WorldValid
;
1160 dc
->wndOrgX
= dcs
->wndOrgX
;
1161 dc
->wndOrgY
= dcs
->wndOrgY
;
1162 dc
->wndExtX
= dcs
->wndExtX
;
1163 dc
->wndExtY
= dcs
->wndExtY
;
1164 dc
->vportOrgX
= dcs
->vportOrgX
;
1165 dc
->vportOrgY
= dcs
->vportOrgY
;
1166 dc
->vportExtX
= dcs
->vportExtX
;
1167 dc
->vportExtY
= dcs
->vportExtY
;
1169 if (!(dc
->w
.flags
& DC_MEMORY
))
1171 dc
->w
.bitsPerPixel
= dcs
->w
.bitsPerPixel
;
1175 if (dcs
->w
.hClipRgn
)
1177 if (!dc
->w
.hClipRgn
)
1179 dc
->w
.hClipRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1181 NtGdiCombineRgn( dc
->w
.hClipRgn
, dcs
->w
.hClipRgn
, 0, RGN_COPY
);
1187 NtGdiDeleteObject( dc
->w
.hClipRgn
);
1192 CLIPPING_UpdateGCRegion( dc
);
1193 DC_UnlockDc ( hDC
);
1195 DC_UnlockDc ( hDC
);
1196 NtGdiSelectClipRgn(hDC
, dcs
->w
.hClipRgn
);
1199 NtGdiSelectObject( hDC
, dcs
->w
.hBitmap
);
1200 NtGdiSelectObject( hDC
, dcs
->w
.hBrush
);
1201 NtGdiSelectObject( hDC
, dcs
->w
.hFont
);
1202 NtGdiSelectObject( hDC
, dcs
->w
.hPen
);
1203 NtGdiSetBkColor( hDC
, dcs
->w
.backgroundColor
);
1204 NtGdiSetTextColor( hDC
, dcs
->w
.textColor
);
1207 GDISelectPalette16( hDC
, dcs
->w
.hPalette
, FALSE
);
1212 DC_UnlockDc ( hDCSave
);
1214 DC_UnlockDc ( hDC
);
1220 NtGdiGetDeviceCaps(HDC hDC
,
1227 dc
= DC_LockDc(hDC
);
1233 /* Retrieve capability */
1237 ret
= dc
->GDIInfo
->ulVersion
;
1241 ret
= dc
->GDIInfo
->ulTechnology
;
1245 ret
= dc
->GDIInfo
->ulHorzSize
;
1249 ret
= dc
->GDIInfo
->ulVertSize
;
1253 ret
= dc
->GDIInfo
->ulHorzRes
;
1257 ret
= dc
->GDIInfo
->ulVertRes
;
1261 ret
= dc
->GDIInfo
->ulLogPixelsX
;
1265 ret
= dc
->GDIInfo
->ulLogPixelsY
;
1269 ret
= dc
->GDIInfo
->cBitsPixel
;
1273 ret
= dc
->GDIInfo
->cPlanes
;
1277 UNIMPLEMENTED
; /* FIXME */
1281 UNIMPLEMENTED
; /* FIXME */
1285 UNIMPLEMENTED
; /* FIXME */
1289 ret
= dc
->GDIInfo
->ulNumColors
;
1293 ret
= dc
->GDIInfo
->ulAspectX
;
1297 ret
= dc
->GDIInfo
->ulAspectY
;
1301 ret
= dc
->GDIInfo
->ulAspectXY
;
1305 UNIMPLEMENTED
; /* FIXME */
1309 UNIMPLEMENTED
; /* FIXME */
1313 ret
= dc
->GDIInfo
->ulNumPalReg
; /* FIXME not sure */
1321 UNIMPLEMENTED
; /* FIXME */
1325 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1335 case PHYSICALHEIGHT
:
1336 if(NtGdiEscape(hDC
, GETPHYSPAGESIZE
, 0, NULL
, (LPVOID
)&pt
) > 0)
1346 case PHYSICALOFFSETX
:
1347 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1357 case PHYSICALOFFSETY
:
1358 if(NtGdiEscape(hDC
, GETPRINTINGOFFSET
, 0, NULL
, (LPVOID
)&pt
) > 0)
1369 UNIMPLEMENTED
; /* FIXME */
1372 case SCALINGFACTORX
:
1373 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1383 case SCALINGFACTORY
:
1384 if(NtGdiEscape(hDC
, GETSCALINGFACTOR
, 0, NULL
, (LPVOID
)&pt
) > 0)
1395 ret
= dc
->GDIInfo
->flRaster
;
1399 UNIMPLEMENTED
; /* FIXME */
1403 UNIMPLEMENTED
; /* FIXME */
1407 UNIMPLEMENTED
; /* FIXME */
1411 ret
= dc
->GDIInfo
->flTextCaps
;
1419 DPRINT("(%04x,%d): returning %d\n", hDC
, Index
, ret
);
1425 DC_GET_VAL( INT
, NtGdiGetMapMode
, w
.MapMode
)
1426 DC_GET_VAL( INT
, NtGdiGetPolyFillMode
, w
.polyFillMode
)
1429 IntGdiGetObject(HANDLE Handle
, INT Count
, LPVOID Buffer
)
1431 PGDIOBJHDR GdiObject
;
1435 GdiObject
= GDIOBJ_LockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1436 if (NULL
== GdiObject
)
1441 ObjectType
= GDIOBJ_GetObjectType(Handle
);
1445 case GDI_OBJECT_TYPE_PEN
:
1446 Result
= PEN_GetObject((PENOBJ
*) GdiObject
, Count
, Buffer
);
1448 case GDI_OBJECT_TYPE_BRUSH
:
1449 Result
= BRUSH_GetObject((BRUSHOBJ
*) GdiObject
, Count
, Buffer
);
1452 case GDI_OBJECT_TYPE_BITMAP
:
1453 Result
= BITMAP_GetObject((BITMAPOBJ
*) GdiObject
, Count
, Buffer
);
1455 case GDI_OBJECT_TYPE_FONT
:
1456 Result
= FontGetObject((PTEXTOBJ
) GdiObject
, Count
, Buffer
);
1458 // Fix the LOGFONT structure for the stock fonts
1459 if (FIRST_STOCK_HANDLE
<= Handle
&& Handle
<= LAST_STOCK_HANDLE
)
1461 FixStockFontSizeW(Handle
, Count
, Buffer
);
1466 case GDI_OBJECT_TYPE_PALETTE
:
1467 Result
= PALETTE_GetObject((PALETTEOBJ
*) GdiObject
, Count
, Buffer
);
1471 DPRINT1("GDI object type 0x%08x not implemented\n", ObjectType
);
1475 GDIOBJ_UnlockObj(Handle
, GDI_OBJECT_TYPE_DONTCARE
);
1481 NtGdiGetObject(HANDLE handle
, INT count
, LPVOID buffer
)
1492 SafeBuf
= ExAllocatePoolWithTag(NonPagedPool
, count
, TAG_GDIOBJ
);
1495 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1499 Ret
= IntGdiGetObject(handle
, count
, SafeBuf
);
1501 Status
= MmCopyToCaller(buffer
, SafeBuf
, count
);
1502 ExFreePool(SafeBuf
);
1503 if(!NT_SUCCESS(Status
))
1505 SetLastNtError(Status
);
1513 NtGdiGetObjectType(HANDLE handle
)
1519 ptr
= GDIOBJ_LockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1523 objectType
= GDIOBJ_GetObjectType(handle
);
1526 case GDI_OBJECT_TYPE_PEN
:
1529 case GDI_OBJECT_TYPE_BRUSH
:
1532 case GDI_OBJECT_TYPE_BITMAP
:
1533 result
= OBJ_BITMAP
;
1535 case GDI_OBJECT_TYPE_FONT
:
1538 case GDI_OBJECT_TYPE_PALETTE
:
1541 case GDI_OBJECT_TYPE_REGION
:
1542 result
= OBJ_REGION
;
1544 case GDI_OBJECT_TYPE_DC
:
1547 case GDI_OBJECT_TYPE_METADC
:
1548 result
= OBJ_METADC
;
1550 case GDI_OBJECT_TYPE_METAFILE
:
1551 result
= OBJ_METAFILE
;
1553 case GDI_OBJECT_TYPE_ENHMETAFILE
:
1554 result
= OBJ_ENHMETAFILE
;
1556 case GDI_OBJECT_TYPE_ENHMETADC
:
1557 result
= OBJ_ENHMETADC
;
1559 case GDI_OBJECT_TYPE_EXTPEN
:
1560 result
= OBJ_EXTPEN
;
1562 case GDI_OBJECT_TYPE_MEMDC
:
1566 DPRINT1("Magic 0x%08x not implemented\n", objectType
);
1569 GDIOBJ_UnlockObj(handle
, GDI_OBJECT_TYPE_DONTCARE
);
1573 DC_GET_VAL( INT
, NtGdiGetRelAbs
, w
.relAbsMode
)
1574 DC_GET_VAL( INT
, NtGdiGetROP2
, w
.ROPmode
)
1575 DC_GET_VAL( INT
, NtGdiGetStretchBltMode
, w
.stretchBltMode
)
1576 DC_GET_VAL( UINT
, NtGdiGetTextAlign
, w
.textAlign
)
1577 DC_GET_VAL( COLORREF
, NtGdiGetTextColor
, w
.textColor
)
1578 DC_GET_VAL_EX( NtGdiGetViewportExtEx
, IntGetViewportExtEx
, vportExtX
, vportExtY
, SIZE
)
1579 DC_GET_VAL_EX( NtGdiGetViewportOrgEx
, IntGetViewportOrgEx
, vportOrgX
, vportOrgY
, POINT
)
1580 DC_GET_VAL_EX( NtGdiGetWindowExtEx
, IntGetWindowExtEx
, wndExtX
, wndExtY
, SIZE
)
1581 DC_GET_VAL_EX( NtGdiGetWindowOrgEx
, IntGetWindowOrgEx
, wndOrgX
, wndOrgY
, POINT
)
1584 NtGdiResetDC(HDC hDC
, CONST DEVMODEW
*InitData
)
1590 NtGdiRestoreDC(HDC hDC
, INT SaveLevel
)
1595 dc
= DC_LockDc(hDC
);
1601 if (SaveLevel
== -1)
1603 SaveLevel
= dc
->saveLevel
;
1606 if ((SaveLevel
< 1) || (SaveLevel
> dc
->saveLevel
))
1612 while (dc
->saveLevel
>= SaveLevel
)
1614 HDC hdcs
= DC_GetNextDC (dc
);
1616 dcs
= DC_LockDc (hdcs
);
1621 DC_SetNextDC (dcs
, DC_GetNextDC (dcs
));
1622 if (--dc
->saveLevel
< SaveLevel
)
1625 DC_UnlockDc( hdcs
);
1626 NtGdiSetDCState(hDC
, hdcs
);
1628 if (!PATH_AssignGdiPath( &dc
->w
.path
, &dcs
->w
.path
))
1630 /* FIXME: This might not be quite right, since we're
1631 * returning FALSE but still destroying the saved DC state */
1635 dc
= DC_LockDc(hDC
);
1643 DC_UnlockDc( hdcs
);
1645 NtGdiDeleteDC (hdcs
);
1652 NtGdiSaveDC(HDC hDC
)
1658 if (!(hdcs
= NtGdiGetDCState(hDC
)))
1663 dcs
= DC_LockDc (hdcs
);
1668 dc
= DC_LockDc (hDC
);
1676 /* Copy path. The reason why path saving / restoring is in SaveDC/
1677 * RestoreDC and not in GetDCState/SetDCState is that the ...DCState
1678 * functions are only in Win16 (which doesn't have paths) and that
1679 * SetDCState doesn't allow us to signal an error (which can happen
1680 * when copying paths).
1682 if (!PATH_AssignGdiPath (&dcs
->w
.path
, &dc
->w
.path
))
1684 NtGdiDeleteDC (hdcs
);
1689 DC_SetNextDC (dcs
, DC_GetNextDC (dc
));
1690 DC_SetNextDC (dc
, hdcs
);
1691 ret
= ++dc
->saveLevel
;
1692 DC_UnlockDc( hdcs
);
1700 NtGdiSelectObject(HDC hDC
, HGDIOBJ hGDIObj
)
1702 HGDIOBJ objOrg
= NULL
; // default to failure
1711 COLORREF MonoColorMap
[2];
1712 ULONG NumColors
, Index
;
1716 if(!hDC
|| !hGDIObj
) return NULL
;
1718 dc
= DC_LockDc(hDC
);
1721 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1725 objectType
= GDIOBJ_GetObjectType(hGDIObj
);
1729 case GDI_OBJECT_TYPE_PEN
:
1731 /* Convert the color of the pen to the format of the DC */
1732 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1735 Mode
= PalGDI
->Mode
;
1736 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1737 XlateObj
= (PXLATEOBJ
)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1738 if (NULL
!= XlateObj
)
1740 pen
= PENOBJ_LockPen((HPEN
) hGDIObj
);
1743 pen
->iSolidColor
= XLATEOBJ_iXlate(XlateObj
, pen
->logpen
.lopnColor
);
1744 PENOBJ_UnlockPen((HPEN
) hGDIObj
);
1745 objOrg
= (HGDIOBJ
)dc
->w
.hPen
;
1746 dc
->w
.hPen
= hGDIObj
;
1750 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1752 EngDeleteXlate(XlateObj
);
1756 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1761 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1765 case GDI_OBJECT_TYPE_BRUSH
:
1767 /* Convert the color of the brush to the format of the DC */
1768 PalGDI
= PALETTE_LockPalette(dc
->w
.hPalette
);
1771 Mode
= PalGDI
->Mode
;
1772 PALETTE_UnlockPalette(dc
->w
.hPalette
);
1773 XlateObj
= (PXLATEOBJ
)IntEngCreateXlate(Mode
, PAL_RGB
, dc
->w
.hPalette
, NULL
);
1774 if (NULL
!= XlateObj
)
1776 brush
= BRUSHOBJ_LockBrush((HBRUSH
) hGDIObj
);
1779 brush
->iSolidColor
= XLATEOBJ_iXlate(XlateObj
, brush
->logbrush
.lbColor
);
1780 BRUSHOBJ_UnlockBrush((HBRUSH
) hGDIObj
);
1781 objOrg
= (HGDIOBJ
)dc
->w
.hBrush
;
1782 dc
->w
.hBrush
= (HBRUSH
) hGDIObj
;
1786 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1788 EngDeleteXlate(XlateObj
);
1792 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
1797 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1801 case GDI_OBJECT_TYPE_FONT
:
1802 objOrg
= (HGDIOBJ
)dc
->w
.hFont
;
1803 dc
->w
.hFont
= (HFONT
) hGDIObj
;
1804 TextIntRealizeFont(dc
->w
.hFont
);
1807 case GDI_OBJECT_TYPE_BITMAP
:
1808 // must be memory dc to select bitmap
1809 if (!(dc
->w
.flags
& DC_MEMORY
))
1814 pb
= BITMAPOBJ_LockBitmap(hGDIObj
);
1817 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1821 objOrg
= (HGDIOBJ
)dc
->w
.hBitmap
;
1823 /* Release the old bitmap, lock the new one and convert it to a SURF */
1824 EngDeleteSurface(dc
->Surface
);
1825 dc
->w
.hBitmap
= hGDIObj
;
1826 dc
->Surface
= BitmapToSurf(pb
, dc
->GDIDevice
);
1828 // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
1831 dc
->w
.bitsPerPixel
= pb
->dib
->dsBmih
.biBitCount
;
1833 if(pb
->dib
->dsBmih
.biBitCount
<= 8)
1835 if(pb
->dib
->dsBmih
.biBitCount
== 1) { NumColors
= 2; } else
1836 if(pb
->dib
->dsBmih
.biBitCount
== 4) { NumColors
= 16; } else
1837 if(pb
->dib
->dsBmih
.biBitCount
== 8) { NumColors
= 256; }
1839 ColorMap
= ExAllocatePoolWithTag(PagedPool
, sizeof(COLORREF
) * NumColors
, TAG_DC
);
1841 for (Index
= 0; Index
< NumColors
; Index
++)
1843 ColorMap
[Index
] = RGB(pb
->ColorMap
[Index
].rgbRed
,
1844 pb
->ColorMap
[Index
].rgbGreen
,
1845 pb
->ColorMap
[Index
].rgbBlue
);
1847 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, NumColors
, (ULONG
*) ColorMap
, 0, 0, 0);
1848 ExFreePool(ColorMap
);
1850 else if ( 16 == pb
->dib
->dsBmih
.biBitCount
)
1852 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_BITFIELDS
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0x7c00, 0x03e0, 0x001f);
1854 else if(pb
->dib
->dsBmih
.biBitCount
>= 24)
1856 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_RGB
, pb
->dib
->dsBmih
.biClrUsed
, NULL
, 0, 0, 0);
1861 dc
->w
.bitsPerPixel
= pb
->bitmap
.bmBitsPixel
;
1862 if (1 == dc
->w
.bitsPerPixel
)
1864 MonoColorMap
[0] = RGB(0, 0, 0);
1865 MonoColorMap
[1] = RGB(255, 255, 255);
1866 dc
->w
.hPalette
= PALETTE_AllocPalette(PAL_INDEXED
, 2, MonoColorMap
, 0, 0, 0);
1870 dc
->w
.hPalette
= dc
->DevInfo
->hpalDefault
;
1874 DC_UnlockDc ( hDC
);
1875 hVisRgn
= NtGdiCreateRectRgn ( 0, 0, pb
->bitmap
.bmWidth
, pb
->bitmap
.bmHeight
);
1876 NtGdiSelectVisRgn ( hDC
, hVisRgn
);
1877 NtGdiDeleteObject ( hVisRgn
);
1878 BITMAPOBJ_UnlockBitmap(hGDIObj
);
1883 case GDI_OBJECT_TYPE_REGION
:
1884 DC_UnlockDc ( hDC
);
1885 SelectClipRgn(hDC
, (HRGN
)hGDIObj
);
1896 NtGdiSetHookFlags(HDC hDC
, WORD Flags
)
1899 DC
*dc
= DC_LockDc(hDC
);
1906 wRet
= dc
->w
.flags
& DC_DIRTY
;
1908 /* "Undocumented Windows" info is slightly confusing.
1911 DPRINT("DC %p, Flags %04x\n", hDC
, Flags
);
1913 if (Flags
& DCHF_INVALIDATEVISRGN
)
1915 dc
->w
.flags
|= DC_DIRTY
;
1917 else if (Flags
& DCHF_VALIDATEVISRGN
|| 0 == Flags
)
1919 dc
->w
.flags
&= ~DC_DIRTY
;
1927 DC_SET_MODE( NtGdiSetBkMode
, w
.backgroundMode
, TRANSPARENT
, OPAQUE
)
1928 DC_SET_MODE( NtGdiSetPolyFillMode
, w
.polyFillMode
, ALTERNATE
, WINDING
)
1929 // DC_SET_MODE( NtGdiSetRelAbs, w.relAbsMode, ABSOLUTE, RELATIVE )
1930 DC_SET_MODE( NtGdiSetROP2
, w
.ROPmode
, R2_BLACK
, R2_WHITE
)
1931 DC_SET_MODE( NtGdiSetStretchBltMode
, w
.stretchBltMode
, BLACKONWHITE
, HALFTONE
)
1933 // ---------------------------------------------------- Private Interface
1936 DC_AllocDC(PUNICODE_STRING Driver
)
1944 Buf
= ExAllocatePoolWithTag(PagedPool
, Driver
->MaximumLength
, TAG_DC
);
1949 RtlCopyMemory(Buf
, Driver
->Buffer
, Driver
->MaximumLength
);
1952 hDC
= (HDC
) GDIOBJ_AllocObj(sizeof(DC
), GDI_OBJECT_TYPE_DC
, (GDICLEANUPPROC
) DC_InternalDeleteDC
);
1962 NewDC
= DC_LockDc(hDC
);
1966 RtlCopyMemory(&NewDC
->DriverName
, Driver
, sizeof(UNICODE_STRING
));
1967 NewDC
->DriverName
.Buffer
= Buf
;
1970 NewDC
->w
.xformWorld2Wnd
.eM11
= 1.0f
;
1971 NewDC
->w
.xformWorld2Wnd
.eM12
= 0.0f
;
1972 NewDC
->w
.xformWorld2Wnd
.eM21
= 0.0f
;
1973 NewDC
->w
.xformWorld2Wnd
.eM22
= 1.0f
;
1974 NewDC
->w
.xformWorld2Wnd
.eDx
= 0.0f
;
1975 NewDC
->w
.xformWorld2Wnd
.eDy
= 0.0f
;
1976 NewDC
->w
.xformWorld2Vport
= NewDC
->w
.xformWorld2Wnd
;
1977 NewDC
->w
.xformVport2World
= NewDC
->w
.xformWorld2Wnd
;
1978 NewDC
->w
.vport2WorldValid
= TRUE
;
1979 NewDC
->w
.MapMode
= MM_TEXT
;
1981 NewDC
->w
.hFont
= NtGdiGetStockObject(SYSTEM_FONT
);
1982 TextIntRealizeFont(NewDC
->w
.hFont
);
1990 DC_FindOpenDC(PUNICODE_STRING Driver
)
1996 * Initialize some common fields in the Device Context structure.
1999 DC_InitDC(HDC DCHandle
)
2001 // NtGdiRealizeDefaultPalette(DCHandle);
2003 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( WHITE_BRUSH
));
2004 NtGdiSelectObject(DCHandle
, NtGdiGetStockObject( BLACK_PEN
));
2005 //NtGdiSelectObject(DCHandle, hFont);
2007 // CLIPPING_UpdateGCRegion(DCToInit);
2012 DC_FreeDC(HDC DCToFree
)
2014 if (!GDIOBJ_FreeObj(DCToFree
, GDI_OBJECT_TYPE_DC
, GDIOBJFLAG_DEFAULT
))
2016 DPRINT("DC_FreeDC failed\n");
2021 DC_InternalDeleteDC( PDC DCToDelete
)
2024 RtlFreeUnicodeString(&DCToDelete
->DriverName
);
2029 DC_GetNextDC (PDC pDC
)
2035 DC_SetNextDC (PDC pDC
, HDC hNextDC
)
2037 pDC
->hNext
= hNextDC
;
2041 DC_UpdateXforms(PDC dc
)
2043 XFORM xformWnd2Vport
;
2044 FLOAT scaleX
, scaleY
;
2046 /* Construct a transformation to do the window-to-viewport conversion */
2047 scaleX
= (dc
->wndExtX
? (FLOAT
)dc
->vportExtX
/ (FLOAT
)dc
->wndExtX
: 0.0);
2048 scaleY
= (dc
->wndExtY
? (FLOAT
)dc
->vportExtY
/ (FLOAT
)dc
->wndExtY
: 0.0);
2049 xformWnd2Vport
.eM11
= scaleX
;
2050 xformWnd2Vport
.eM12
= 0.0;
2051 xformWnd2Vport
.eM21
= 0.0;
2052 xformWnd2Vport
.eM22
= scaleY
;
2053 xformWnd2Vport
.eDx
= (FLOAT
)dc
->vportOrgX
- scaleX
* (FLOAT
)dc
->wndOrgX
;
2054 xformWnd2Vport
.eDy
= (FLOAT
)dc
->vportOrgY
- scaleY
* (FLOAT
)dc
->wndOrgY
;
2056 /* Combine with the world transformation */
2057 IntGdiCombineTransform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformWorld2Wnd
, &xformWnd2Vport
);
2059 /* Create inverse of world-to-viewport transformation */
2060 dc
->w
.vport2WorldValid
= DC_InvertXform(&dc
->w
.xformWorld2Vport
, &dc
->w
.xformVport2World
);
2064 DC_InvertXform(const XFORM
*xformSrc
,
2069 determinant
= xformSrc
->eM11
*xformSrc
->eM22
- xformSrc
->eM12
*xformSrc
->eM21
;
2070 if (determinant
> -1e-12 && determinant
< 1e-12)
2075 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
2076 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
2077 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
2078 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
2079 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
- xformSrc
->eDy
* xformDest
->eM21
;
2080 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
- xformSrc
->eDy
* xformDest
->eM22
;
2086 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
2090 GDIOBJ_SetOwnership(hDC
, Owner
);
2091 DC
= DC_LockDc(hDC
);
2094 if (NULL
!= DC
->w
.hClipRgn
)
2096 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hClipRgn
);
2098 if (NULL
!= DC
->w
.hVisRgn
)
2100 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hVisRgn
);
2102 if (NULL
!= DC
->w
.hGCClipRgn
)
2104 GDIOBJ_CopyOwnership(hDC
, DC
->w
.hGCClipRgn
);
2111 IntIsPrimarSurface(PSURFGDI SurfGDI
)
2113 if (PrimarySurface
.Handle
== NULL
)
2117 return SurfGDI
== (PSURFGDI
)AccessInternalObject((ULONG
) PrimarySurface
.Handle
) ? TRUE
: FALSE
;