2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Functions for creation and destruction of DCs
5 * FILE: subsystem/win32/win32k/objects/dclife.c
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@rectos.org)
15 //FIXME: windows uses 0x0012009f
16 #define DIRTY_DEFAULT DIRTY_CHARSET|DIRTY_BACKGROUND|DIRTY_TEXT|DIRTY_LINE|DIRTY_FILL
18 PSURFACE psurfDefaultBitmap
= NULL
;
19 PBRUSH pbrDefaultBrush
= NULL
;
21 // FIXME: these should go to floatobj.h or something
22 #define FLOATOBJ_0 {0x00000000, 0x00000000}
23 #define FLOATOBJ_1 {0x40000000, 0x00000002}
24 #define FLOATOBJ_16 {0x40000000, 0x00000006}
25 #define FLOATOBJ_1_16 {0x40000000, 0xfffffffe}
27 static const FLOATOBJ gef0
= FLOATOBJ_0
;
28 static const FLOATOBJ gef1
= FLOATOBJ_1
;
29 static const FLOATOBJ gef16
= FLOATOBJ_16
;
31 static const MATRIX gmxWorldToDeviceDefault
=
33 FLOATOBJ_16
, FLOATOBJ_0
,
34 FLOATOBJ_0
, FLOATOBJ_16
,
35 FLOATOBJ_0
, FLOATOBJ_0
,
39 static const MATRIX gmxDeviceToWorldDefault
=
41 FLOATOBJ_1_16
, FLOATOBJ_0
,
42 FLOATOBJ_0
, FLOATOBJ_1_16
,
43 FLOATOBJ_0
, FLOATOBJ_0
,
47 static const MATRIX gmxWorldToPageDefault
=
49 FLOATOBJ_1
, FLOATOBJ_0
,
50 FLOATOBJ_0
, FLOATOBJ_1
,
51 FLOATOBJ_0
, FLOATOBJ_0
,
55 // HACK!! Fix XFORMOBJ then use 1:16 / 16:1
56 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
57 #define gmxDeviceToWorldDefault gmxWorldToPageDefault
59 /** Internal functions ********************************************************/
64 psurfDefaultBitmap
= SURFACE_ShareLockSurface(StockObjects
[DEFAULT_BITMAP
]);
65 if (!psurfDefaultBitmap
)
66 return STATUS_UNSUCCESSFUL
;
68 pbrDefaultBrush
= BRUSH_ShareLockBrush(StockObjects
[BLACK_BRUSH
]);
70 return STATUS_UNSUCCESSFUL
;
72 return STATUS_SUCCESS
;
78 DC_AllocDcWithHandle()
81 pdc
= (PDC
)GDIOBJ_AllocObjWithHandle(GDILoObjType_LO_DC_TYPE
);
83 pdc
->pdcattr
= &pdc
->dcattr
;
94 TextIntRealizeFont(pdc
->pdcattr
->hlfntNew
,NULL
);
95 pdc
->pdcattr
->iCS_CP
= ftGdiGetTextCharsetInfo(pdc
,NULL
,0);
97 /* This should never fail */
98 ASSERT(pdc
->dclevel
.ppal
);
101 // FIXME: too complicated, broken error handling
102 pdc
->rosdc
.hClipRgn
= NULL
;
103 pdc
->rosdc
.hGCClipRgn
= NULL
;
104 hVisRgn
= NtGdiCreateRectRgn(0, 0, pdc
->dclevel
.sizl
.cx
, pdc
->dclevel
.sizl
.cy
);
106 GdiSelectVisRgn(pdc
->BaseObject
.hHmgr
, hVisRgn
);
107 GreDeleteObject(hVisRgn
);
108 ASSERT(pdc
->prgnVis
);
118 if (dctype
== DCTYPE_DIRECT
)
121 EngAcquireSemaphoreShared(ppdev
->hsemDevLock
);
124 /* Setup some basic fields */
125 pdc
->dctype
= dctype
;
127 pdc
->dhpdev
= ppdev
->dhpdev
;
128 pdc
->hsem
= ppdev
->hsemDevLock
;
129 pdc
->flGraphicsCaps
= ppdev
->devinfo
.flGraphicsCaps
;
130 pdc
->flGraphicsCaps2
= ppdev
->devinfo
.flGraphicsCaps2
;
131 pdc
->fs
= DC_DIRTY_RAO
;
133 /* Setup dc attribute */
134 pdc
->pdcattr
= &pdc
->dcattr
;
135 pdc
->dcattr
.pvLDC
= NULL
;
136 pdc
->dcattr
.ulDirty_
= DIRTY_DEFAULT
;
137 if (ppdev
== gppdevPrimary
)
138 pdc
->dcattr
.ulDirty_
|= DC_PRIMARY_DISPLAY
;
140 /* Setup the DC size */
141 if (dctype
== DCTYPE_MEMORY
)
143 /* Memory DCs have a 1 x 1 bitmap by default */
144 pdc
->dclevel
.sizl
.cx
= 1;
145 pdc
->dclevel
.sizl
.cy
= 1;
149 /* Other DC's are as big as the related PDEV */
150 pdc
->dclevel
.sizl
.cx
= ppdev
->gdiinfo
.ulHorzRes
;
151 pdc
->dclevel
.sizl
.cy
= ppdev
->gdiinfo
.ulVertRes
;
154 /* Setup Window rect based on DC size */
155 pdc
->erclWindow
.left
= 0;
156 pdc
->erclWindow
.top
= 0;
157 pdc
->erclWindow
.right
= pdc
->dclevel
.sizl
.cx
;
158 pdc
->erclWindow
.bottom
= pdc
->dclevel
.sizl
.cy
;
160 if (dctype
== DCTYPE_DIRECT
)
162 /* Direct DCs get the surface from the PDEV */
163 pdc
->dclevel
.pSurface
= PDEVOBJ_pSurface(ppdev
);
165 pdc
->erclBounds
.left
= 0x7fffffff;
166 pdc
->erclBounds
.top
= 0x7fffffff;
167 pdc
->erclBounds
.right
= 0x80000000;
168 pdc
->erclBounds
.bottom
= 0x80000000;
169 pdc
->erclBoundsApp
.left
= 0xffffffff;
170 pdc
->erclBoundsApp
.top
= 0xfffffffc;
171 pdc
->erclBoundsApp
.right
= 0x00007ffc; // FIXME
172 pdc
->erclBoundsApp
.bottom
= 0x00000333; // FIXME
173 pdc
->erclClip
= pdc
->erclBounds
;
176 pdc
->fs
|= DC_SYNCHRONIZEACCESS
| DC_ACCUM_APP
| DC_PERMANANT
| DC_DISPLAY
;
180 /* Non-direct DCs don't have a surface by default */
181 pdc
->dclevel
.pSurface
= NULL
;
183 // FIXME: HACK, because our code expects a surface
184 pdc
->dclevel
.pSurface
= SURFACE_ShareLockSurface(StockObjects
[DEFAULT_BITMAP
]);
186 pdc
->erclBounds
.left
= 0;
187 pdc
->erclBounds
.top
= 0;
188 pdc
->erclBounds
.right
= 0;
189 pdc
->erclBounds
.bottom
= 0;
190 pdc
->erclBoundsApp
= pdc
->erclBounds
;
191 pdc
->erclClip
= pdc
->erclWindow
;
195 // pdc->dcattr.VisRectRegion:
197 /* Setup coordinate transformation data */
198 pdc
->dclevel
.mxWorldToDevice
= gmxWorldToDeviceDefault
;
199 pdc
->dclevel
.mxDeviceToWorld
= gmxDeviceToWorldDefault
;
200 pdc
->dclevel
.mxWorldToPage
= gmxWorldToPageDefault
;
201 pdc
->dclevel
.efM11PtoD
= gef16
;
202 pdc
->dclevel
.efM22PtoD
= gef16
;
203 pdc
->dclevel
.efDxPtoD
= gef0
;
204 pdc
->dclevel
.efDyPtoD
= gef0
;
205 pdc
->dclevel
.efM11_TWIPS
= gef0
;
206 pdc
->dclevel
.efM22_TWIPS
= gef0
;
207 pdc
->dclevel
.efPr11
= gef0
;
208 pdc
->dclevel
.efPr22
= gef0
;
209 pdc
->dcattr
.mxWorldToDevice
= pdc
->dclevel
.mxWorldToDevice
;
210 pdc
->dcattr
.mxDeviceToWorld
= pdc
->dclevel
.mxDeviceToWorld
;
211 pdc
->dcattr
.mxWorldToPage
= pdc
->dclevel
.mxWorldToPage
;
212 pdc
->dcattr
.efM11PtoD
= pdc
->dclevel
.efM11PtoD
;
213 pdc
->dcattr
.efM22PtoD
= pdc
->dclevel
.efM22PtoD
;
214 pdc
->dcattr
.efDxPtoD
= pdc
->dclevel
.efDxPtoD
;
215 pdc
->dcattr
.efDyPtoD
= pdc
->dclevel
.efDyPtoD
;
216 pdc
->dcattr
.iMapMode
= MM_TEXT
;
217 pdc
->dcattr
.dwLayout
= 0;
218 pdc
->dcattr
.flXform
= PAGE_TO_DEVICE_SCALE_IDENTITY
|
219 PAGE_TO_DEVICE_IDENTITY
|
220 WORLD_TO_PAGE_IDENTITY
;
222 /* Setup more coordinates */
223 pdc
->ptlDCOrig
.x
= 0;
224 pdc
->ptlDCOrig
.y
= 0;
225 pdc
->dcattr
.lWindowOrgx
= 0;
226 pdc
->dcattr
.ptlWindowOrg
.x
= 0;
227 pdc
->dcattr
.ptlWindowOrg
.y
= 0;
228 pdc
->dcattr
.szlWindowExt
.cx
= 1;
229 pdc
->dcattr
.szlWindowExt
.cy
= 1;
230 pdc
->dcattr
.ptlViewportOrg
.x
= 0;
231 pdc
->dcattr
.ptlViewportOrg
.y
= 0;
232 pdc
->dcattr
.szlViewportExt
.cx
= 1;
233 pdc
->dcattr
.szlViewportExt
.cy
= 1;
234 pdc
->dcattr
.szlVirtualDevicePixel
.cx
= 0;
235 pdc
->dcattr
.szlVirtualDevicePixel
.cy
= 0;
236 pdc
->dcattr
.szlVirtualDeviceMm
.cx
= 0;
237 pdc
->dcattr
.szlVirtualDeviceMm
.cy
= 0;
238 pdc
->dcattr
.szlVirtualDeviceSize
.cx
= 0;
239 pdc
->dcattr
.szlVirtualDeviceSize
.cy
= 0;
243 pdc
->prgnVis
= NULL
; // FIXME
247 pdc
->dclevel
.hpal
= StockObjects
[DEFAULT_PALETTE
];
248 pdc
->dclevel
.ppal
= PALETTE_ShareLockPalette(pdc
->dclevel
.hpal
);
251 pdc
->dclevel
.hPath
= NULL
;
252 pdc
->dclevel
.flPath
= 0;
253 // pdc->dclevel.lapath:
256 pdc
->dcattr
.crBackgroundClr
= RGB(0xff, 0xff, 0xff);
257 pdc
->dcattr
.ulBackgroundClr
= RGB(0xff, 0xff, 0xff);
258 pdc
->dcattr
.crForegroundClr
= RGB(0, 0, 0);
259 pdc
->dcattr
.ulForegroundClr
= RGB(0, 0, 0);
260 pdc
->dcattr
.crBrushClr
= RGB(0xff, 0xff, 0xff);
261 pdc
->dcattr
.ulBrushClr
= RGB(0xff, 0xff, 0xff);
262 pdc
->dcattr
.crPenClr
= RGB(0, 0, 0);
263 pdc
->dcattr
.ulPenClr
= RGB(0, 0, 0);
265 /* Select the default fill and line brush */
266 pdc
->dcattr
.hbrush
= StockObjects
[WHITE_BRUSH
];
267 pdc
->dcattr
.hpen
= StockObjects
[BLACK_PEN
];
268 pdc
->dclevel
.pbrFill
= BRUSH_ShareLockBrush(pdc
->pdcattr
->hbrush
);
269 pdc
->dclevel
.pbrLine
= PEN_ShareLockPen(pdc
->pdcattr
->hpen
);
270 pdc
->dclevel
.ptlBrushOrigin
.x
= 0;
271 pdc
->dclevel
.ptlBrushOrigin
.y
= 0;
272 pdc
->dcattr
.ptlBrushOrigin
= pdc
->dclevel
.ptlBrushOrigin
;
274 /* Initialize EBRUSHOBJs */
275 EBRUSHOBJ_vInit(&pdc
->eboFill
, pdc
->dclevel
.pbrFill
, pdc
);
276 EBRUSHOBJ_vInit(&pdc
->eboLine
, pdc
->dclevel
.pbrLine
, pdc
);
277 EBRUSHOBJ_vInit(&pdc
->eboText
, pbrDefaultBrush
, pdc
);
278 EBRUSHOBJ_vInit(&pdc
->eboBackground
, pbrDefaultBrush
, pdc
);
280 /* Setup fill data */
281 pdc
->dcattr
.jROP2
= R2_COPYPEN
;
282 pdc
->dcattr
.jBkMode
= 2;
283 pdc
->dcattr
.lBkMode
= 2;
284 pdc
->dcattr
.jFillMode
= ALTERNATE
;
285 pdc
->dcattr
.lFillMode
= 1;
286 pdc
->dcattr
.jStretchBltMode
= 1;
287 pdc
->dcattr
.lStretchBltMode
= 1;
288 pdc
->ptlFillOrigin
.x
= 0;
289 pdc
->ptlFillOrigin
.y
= 0;
291 /* Setup drawing position */
292 pdc
->dcattr
.ptlCurrent
.x
= 0;
293 pdc
->dcattr
.ptlCurrent
.y
= 0;
294 pdc
->dcattr
.ptfxCurrent
.x
= 0;
295 pdc
->dcattr
.ptfxCurrent
.y
= 0;
298 pdc
->dclevel
.lIcmMode
= 0;
299 pdc
->dcattr
.lIcmMode
= 0;
300 pdc
->dcattr
.hcmXform
= NULL
;
301 pdc
->dcattr
.flIcmFlags
= 0;
302 pdc
->dcattr
.IcmBrushColor
= CLR_INVALID
;
303 pdc
->dcattr
.IcmPenColor
= CLR_INVALID
;
304 pdc
->dcattr
.pvLIcm
= NULL
;
305 pdc
->dcattr
.hColorSpace
= NULL
; // FIXME: 0189001f
306 pdc
->dclevel
.pColorSpace
= NULL
; // FIXME
307 pdc
->pClrxFormLnk
= NULL
;
310 /* Setup font data */
311 pdc
->hlfntCur
= NULL
; // FIXME: 2f0a0cf8
312 pdc
->pPFFList
= NULL
;
313 pdc
->flSimulationFlags
= 0;
314 pdc
->lEscapement
= 0;
316 pdc
->dcattr
.flFontMapper
= 0;
317 pdc
->dcattr
.flTextAlign
= 0;
318 pdc
->dcattr
.lTextAlign
= 0;
319 pdc
->dcattr
.lTextExtra
= 0;
320 pdc
->dcattr
.lRelAbs
= 1;
321 pdc
->dcattr
.lBreakExtra
= 0;
322 pdc
->dcattr
.cBreak
= 0;
323 pdc
->dcattr
.hlfntNew
= StockObjects
[SYSTEM_FONT
];
324 // pdc->dclevel.pFont = LFONT_ShareLockFont(pdc->dcattr.hlfntNew);
329 pdc
->ipfdDevMax
= 0x0000ffff;
330 pdc
->ulCopyCount
= -1;
331 pdc
->ptlDoBanding
.x
= 0;
332 pdc
->ptlDoBanding
.y
= 0;
333 pdc
->dclevel
.lSaveDepth
= 1;
334 pdc
->dclevel
.hdcSave
= NULL
;
335 pdc
->dcattr
.iGraphicsMode
= GM_COMPATIBLE
;
336 pdc
->dcattr
.iCS_CP
= 0;
337 pdc
->pSurfInfo
= NULL
;
343 DC_Cleanup(PVOID ObjectBody
)
345 PDC pdc
= (PDC
)ObjectBody
;
350 /* Delete saved DCs */
351 DC_vRestoreDC(pdc
, 1);
353 /* Deselect dc objects */
354 DC_vSelectSurface(pdc
, NULL
);
355 DC_vSelectFillBrush(pdc
, NULL
);
356 DC_vSelectLineBrush(pdc
, NULL
);
357 DC_vSelectPalette(pdc
, NULL
);
359 /* Cleanup the dc brushes */
360 EBRUSHOBJ_vCleanup(&pdc
->eboFill
);
361 EBRUSHOBJ_vCleanup(&pdc
->eboLine
);
362 EBRUSHOBJ_vCleanup(&pdc
->eboText
);
363 EBRUSHOBJ_vCleanup(&pdc
->eboBackground
);
366 if (pdc
->rosdc
.hClipRgn
)
367 GreDeleteObject(pdc
->rosdc
.hClipRgn
);
369 REGION_FreeRgnByHandle(pdc
->prgnVis
->BaseObject
.hHmgr
);
370 ASSERT(pdc
->rosdc
.hGCClipRgn
);
371 if (pdc
->rosdc
.hGCClipRgn
)
372 GreDeleteObject(pdc
->rosdc
.hGCClipRgn
);
373 if (NULL
!= pdc
->rosdc
.CombinedClip
)
374 IntEngDeleteClipRegion(pdc
->rosdc
.CombinedClip
);
376 PATH_Delete(pdc
->dclevel
.hPath
);
378 if(pdc
->dclevel
.pSurface
)
379 SURFACE_ShareUnlockSurface(pdc
->dclevel
.pSurface
);
381 PDEVOBJ_vRelease(pdc
->ppdev
) ;
388 DC_SetOwnership(HDC hDC
, PEPROCESS Owner
)
391 PGDI_TABLE_ENTRY Entry
;
395 /* FIXME: This function has broken error handling */
397 if (!GDIOBJ_SetOwnership(hDC
, Owner
))
399 DPRINT1("GDIOBJ_SetOwnership failed\n");
403 pDC
= DC_LockDc(hDC
);
406 DPRINT1("Could not lock DC\n");
412 These regions do not use attribute sections and when allocated, use
413 gdiobj level functions.
415 if (pDC
->rosdc
.hClipRgn
)
417 Index
= GDI_HANDLE_GET_INDEX(pDC
->rosdc
.hClipRgn
);
418 Entry
= &GdiHandleTable
->Entries
[Index
];
419 if (Entry
->UserData
) FreeObjectAttr(Entry
->UserData
);
420 Entry
->UserData
= NULL
;
422 if (!GDIOBJ_SetOwnership(pDC
->rosdc
.hClipRgn
, Owner
)) goto leave
;
426 Index
= GDI_HANDLE_GET_INDEX(pDC
->prgnVis
->BaseObject
.hHmgr
);
427 Entry
= &GdiHandleTable
->Entries
[Index
];
428 if (Entry
->UserData
) FreeObjectAttr(Entry
->UserData
);
429 Entry
->UserData
= NULL
;
431 if (!GDIOBJ_SetOwnership(pDC
->prgnVis
->BaseObject
.hHmgr
, Owner
)) goto leave
;
433 if (pDC
->rosdc
.hGCClipRgn
)
435 Index
= GDI_HANDLE_GET_INDEX(pDC
->rosdc
.hGCClipRgn
);
436 Entry
= &GdiHandleTable
->Entries
[Index
];
437 if (Entry
->UserData
) FreeObjectAttr(Entry
->UserData
);
438 Entry
->UserData
= NULL
;
440 if (!GDIOBJ_SetOwnership(pDC
->rosdc
.hGCClipRgn
, Owner
)) goto leave
;
442 if (pDC
->dclevel
.hPath
)
444 if (!GDIOBJ_SetOwnership(pDC
->dclevel
.hPath
, Owner
)) goto leave
;
454 /* Prepare a blit for up to 2 DCs */
455 /* rc1 and rc2 are the rectangles where we want to draw or
456 * from where we take pixels. */
459 DC_vPrepareDCsForBlit(PDC pdc1
,
464 if(pdc1
->dctype
== DCTYPE_DIRECT
)
466 EngAcquireSemaphore(pdc1
->ppdev
->hsemDevLock
);
467 MouseSafetyOnDrawStart(&pdc1
->dclevel
.pSurface
->SurfObj
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
) ;
469 if(pdc2
&& pdc2
->dctype
== DCTYPE_DIRECT
)
471 EngAcquireSemaphore(pdc2
->ppdev
->hsemDevLock
);
472 MouseSafetyOnDrawStart(&pdc2
->dclevel
.pSurface
->SurfObj
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
) ;
476 /* Finishes a blit for one or two DCs */
479 DC_vFinishBlit(PDC pdc1
, PDC pdc2
)
481 if(pdc1
->dctype
== DCTYPE_DIRECT
)
483 MouseSafetyOnDrawEnd(&pdc1
->dclevel
.pSurface
->SurfObj
);
484 EngReleaseSemaphore(pdc1
->ppdev
->hsemDevLock
);
489 if(pdc2
->dctype
== DCTYPE_DIRECT
)
491 MouseSafetyOnDrawEnd(&pdc2
->dclevel
.pSurface
->SurfObj
);
492 EngReleaseSemaphore(pdc2
->ppdev
->hsemDevLock
);
500 PUNICODE_STRING pustrDevice
,
502 PUNICODE_STRING pustrLogAddr
,
513 DPRINT("GreOpenDCW(%S, iType=%ld)\n",
514 pustrDevice
? pustrDevice
->Buffer
: NULL
, iType
);
516 /* Get a PDEVOBJ for the device */
517 ppdev
= EngpGetPDEV(pustrDevice
);
520 DPRINT1("Didn't find a suitable PDEV\n");
524 DPRINT("GreOpenDCW - ppdev = %p\n", ppdev
);
526 pdc
= DC_AllocDcWithHandle();
529 DPRINT1("Could not Allocate a DC\n");
530 PDEVOBJ_vRelease(ppdev
);
533 hdc
= pdc
->BaseObject
.hHmgr
;
535 /* Lock ppdev and initialize the new DC */
536 DC_vInitDc(pdc
, iType
, ppdev
);
544 DPRINT("returning hdc = %p\n", hdc
);
552 PUNICODE_STRING pustrDevice
,
554 PUNICODE_STRING pustrLogAddr
,
561 UNICODE_STRING ustrDevice
;
562 WCHAR awcDevice
[CCHDEVICENAME
];
567 /* Only if a devicename is given, we need any data */
570 /* Initialize destination string */
571 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
575 /* Probe the UNICODE_STRING and the buffer */
576 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
577 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
579 /* Copy the string */
580 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
584 /* FIXME: could be larger */
585 ProbeForRead(pdmInit
, sizeof(DEVMODEW
), 1);
586 RtlCopyMemory(&dmInit
, pdmInit
, sizeof(DEVMODEW
));
591 ProbeForWrite(pUMdhpdev
, sizeof(HANDLE
), 1);
594 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
596 SetLastNtError(_SEH2_GetExceptionCode());
597 _SEH2_YIELD(return NULL
);
610 UNICODE_STRING ustrDISPLAY
= RTL_CONSTANT_STRING(L
"DISPLAY");
611 if (RtlEqualUnicodeString(&ustrDevice
, &ustrDISPLAY
, TRUE
))
617 /* Call the internal function */
618 hdc
= GreOpenDCW(pustrDevice
? &ustrDevice
: NULL
,
619 pdmInit
? &dmInit
: NULL
,
620 NULL
, // fixme pwszLogAddress
624 NULL
, //FIXME: pDriverInfo2
625 pUMdhpdev
? &dhpdev
: NULL
);
627 /* If we got a HDC and a UM dhpdev is requested,... */
628 if (hdc
&& pUMdhpdev
)
630 /* Copy dhpdev to caller (FIXME: use dhpdev?? */
633 /* Pointer was already probed */
634 *(HANDLE
*)pUMdhpdev
= dhpdev
;
636 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
649 NtGdiCreateCompatibleDC(HDC hdc
)
655 DPRINT("NtGdiCreateCompatibleDC(0x%p)\n", hdc
);
657 /* Did the caller provide a DC? */
660 /* Yes, try to lock it */
661 pdc
= DC_LockDc(hdc
);
664 DPRINT1("Could not lock source DC %p\n", hdc
);
668 /* Get the pdev from the DC */
670 InterlockedIncrement(&ppdev
->cPdevRefs
);
672 /* Unlock the source DC */
677 /* No DC given, get default device */
678 ppdev
= EngpGetPDEV(NULL
);
683 DPRINT1("Didn't find a suitable PDEV\n");
687 /* Allocate a new DC */
688 pdcNew
= DC_AllocDcWithHandle();
691 DPRINT1("Could not allocate a new DC\n");
692 PDEVOBJ_vRelease(ppdev
);
695 hdcNew
= pdcNew
->BaseObject
.hHmgr
;
697 /* Lock ppdev and initialize the new DC */
698 DC_vInitDc(pdcNew
, DCTYPE_MEMORY
, ppdev
);
702 /* Allocate a dc attribute */
703 DC_AllocDcAttr(pdcNew
);
706 DC_vSelectSurface(pdcNew
, psurfDefaultBitmap
);
710 DPRINT("Leave NtGdiCreateCompatibleDC hdcNew = %p\n", hdcNew
);
717 IntGdiDeleteDC(HDC hDC
, BOOL Force
)
719 PDC DCToDelete
= DC_LockDc(hDC
);
721 if (DCToDelete
== NULL
)
723 SetLastWin32Error(ERROR_INVALID_HANDLE
);
729 if (DCToDelete
->fs
& DC_FLAG_PERMANENT
)
731 DPRINT1("No! You Naughty Application!\n");
732 DC_UnlockDc(DCToDelete
);
733 return UserReleaseDC(NULL
, hDC
, FALSE
);
737 DC_UnlockDc(DCToDelete
);
739 if (!IsObjectDead(hDC
))
741 if (!GDIOBJ_FreeObjByHandle(hDC
, GDI_OBJECT_TYPE_DC
))
743 DPRINT1("DC_FreeDC failed\n");
748 DPRINT1("Attempted to Delete 0x%x currently being destroyed!!!\n", hDC
);
756 NtGdiDeleteObjectApp(HANDLE DCHandle
)
758 /* Complete all pending operations */
759 NtGdiFlushUserBatch();
761 if (GDI_HANDLE_IS_STOCKOBJ(DCHandle
)) return TRUE
;
763 if (GDI_HANDLE_GET_TYPE(DCHandle
) != GDI_OBJECT_TYPE_DC
)
764 return GreDeleteObject((HGDIOBJ
) DCHandle
);
766 if (IsObjectDead((HGDIOBJ
)DCHandle
)) return TRUE
;
768 if (!GDIOBJ_OwnedByCurrentProcess(DCHandle
))
770 SetLastWin32Error(ERROR_INVALID_HANDLE
);
774 return IntGdiDeleteDC(DCHandle
, FALSE
);
779 MakeInfoDC(PDC pdc
, BOOL bSet
)
784 /* Can not be a display DC. */
785 if (pdc
->fs
& DC_FLAG_DISPLAY
) return FALSE
;
788 if (pdc
->fs
& DC_FLAG_TEMPINFODC
|| pdc
->dctype
== DC_TYPE_DIRECT
)
791 pSurface
= pdc
->dclevel
.pSurface
;
792 pdc
->fs
|= DC_FLAG_TEMPINFODC
;
793 pdc
->pSurfInfo
= pSurface
;
794 pdc
->dctype
= DC_TYPE_INFO
;
795 pdc
->dclevel
.pSurface
= NULL
;
797 PDEVOBJ_sizl(pdc
->ppdev
, &sizl
);
799 if ( sizl
.cx
== pdc
->dclevel
.sizl
.cx
&&
800 sizl
.cy
== pdc
->dclevel
.sizl
.cy
)
803 pdc
->dclevel
.sizl
.cx
= sizl
.cx
;
804 pdc
->dclevel
.sizl
.cy
= sizl
.cy
;
808 if (!(pdc
->fs
& DC_FLAG_TEMPINFODC
) || pdc
->dctype
!= DC_TYPE_INFO
)
811 pSurface
= pdc
->pSurfInfo
;
812 pdc
->fs
&= ~DC_FLAG_TEMPINFODC
;
813 pdc
->dclevel
.pSurface
= pSurface
;
814 pdc
->dctype
= DC_TYPE_DIRECT
;
815 pdc
->pSurfInfo
= NULL
;
818 (pSurface
->SurfObj
.sizlBitmap
.cx
== pdc
->dclevel
.sizl
.cx
&&
819 pSurface
->SurfObj
.sizlBitmap
.cy
== pdc
->dclevel
.sizl
.cy
) )
822 pdc
->dclevel
.sizl
.cx
= pSurface
->SurfObj
.sizlBitmap
.cx
;
823 pdc
->dclevel
.sizl
.cy
= pSurface
->SurfObj
.sizlBitmap
.cy
;
825 return IntSetDefaultRegion(pdc
);
838 PDC pdc
= DC_LockDc(hdc
);
841 Ret
= MakeInfoDC(pdc
, bSet
);
851 PUNICODE_STRING Driver
,
852 PUNICODE_STRING pustrDevice
,
854 CONST PDEVMODEW pdmInit
,
859 hdc
= GreOpenDCW(pustrDevice
,
862 CreateAsIC
? DCTYPE_INFO
:
863 (Driver
? DC_TYPE_DIRECT
: DC_TYPE_DIRECT
),
873 IntGdiCreateDisplayDC(HDEV hDev
, ULONG DcType
, BOOL EmptyDC
)
879 if (DcType
== DC_TYPE_MEMORY
)
880 hDC
= NtGdiCreateCompatibleDC(NULL
); // OH~ Yuck! I think I taste vomit in my mouth!
882 hDC
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
, (DcType
== DC_TYPE_INFO
));