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)
14 // FIXME: Windows uses 0x0012009f
15 #define DIRTY_DEFAULT DIRTY_CHARSET|DIRTY_BACKGROUND|DIRTY_TEXT|DIRTY_LINE|DIRTY_FILL
17 PSURFACE psurfDefaultBitmap
= NULL
;
18 PBRUSH pbrDefaultBrush
= NULL
;
20 static const MATRIX gmxWorldToDeviceDefault
=
22 FLOATOBJ_16
, FLOATOBJ_0
,
23 FLOATOBJ_0
, FLOATOBJ_16
,
24 FLOATOBJ_0
, FLOATOBJ_0
,
28 static const MATRIX gmxDeviceToWorldDefault
=
30 FLOATOBJ_1_16
, FLOATOBJ_0
,
31 FLOATOBJ_0
, FLOATOBJ_1_16
,
32 FLOATOBJ_0
, FLOATOBJ_0
,
36 static const MATRIX gmxWorldToPageDefault
=
38 FLOATOBJ_1
, FLOATOBJ_0
,
39 FLOATOBJ_0
, FLOATOBJ_1
,
40 FLOATOBJ_0
, FLOATOBJ_0
,
44 // HACK!! Fix XFORMOBJ then use 1:16 / 16:1
45 #define gmxWorldToDeviceDefault gmxWorldToPageDefault
46 #define gmxDeviceToWorldDefault gmxWorldToPageDefault
48 /** Internal functions ********************************************************/
55 psurfDefaultBitmap
= SURFACE_ShareLockSurface(StockObjects
[DEFAULT_BITMAP
]);
56 if (!psurfDefaultBitmap
)
57 return STATUS_UNSUCCESSFUL
;
59 pbrDefaultBrush
= BRUSH_ShareLockBrush(StockObjects
[BLACK_BRUSH
]);
61 return STATUS_UNSUCCESSFUL
;
63 return STATUS_SUCCESS
;
69 DC_AllocDcWithHandle(GDILOOBJTYPE eDcObjType
)
73 NT_ASSERT((eDcObjType
== GDILoObjType_LO_DC_TYPE
) ||
74 (eDcObjType
== GDILoObjType_LO_ALTDC_TYPE
));
76 /* Allocate the object */
77 pdc
= (PDC
)GDIOBJ_AllocateObject(GDIObjType_DC_TYPE
,
82 DPRINT1("Could not allocate a DC.\n");
86 /* Set the actual DC type */
87 pdc
->BaseObject
.hHmgr
= UlongToHandle(eDcObjType
);
89 pdc
->pdcattr
= &pdc
->dcattr
;
91 /* Insert the object */
92 if (!GDIOBJ_hInsertObject(&pdc
->BaseObject
, GDI_OBJ_HMGR_POWNED
))
94 /// FIXME: this is broken, since the DC is not initialized yet...
95 DPRINT1("Could not insert DC into handle table.\n");
96 GDIOBJ_vFreeObject(&pdc
->BaseObject
);
107 if (defaultDCstate
== NULL
)
109 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
110 ASSERT(defaultDCstate
);
111 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
112 defaultDCstate
->pdcattr
= &defaultDCstate
->dcattr
;
113 DC_vCopyState(pdc
, defaultDCstate
, TRUE
);
116 TextIntRealizeFont(pdc
->pdcattr
->hlfntNew
,NULL
);
117 pdc
->pdcattr
->iCS_CP
= ftGdiGetTextCharsetInfo(pdc
,NULL
,0);
119 /* This should never fail */
120 ASSERT(pdc
->dclevel
.ppal
);
130 /* Setup some basic fields */
131 pdc
->dctype
= dctype
;
133 pdc
->dhpdev
= ppdev
->dhpdev
;
134 pdc
->hsem
= ppdev
->hsemDevLock
;
135 pdc
->flGraphicsCaps
= ppdev
->devinfo
.flGraphicsCaps
;
136 pdc
->flGraphicsCaps2
= ppdev
->devinfo
.flGraphicsCaps2
;
137 pdc
->fs
= DC_DIRTY_RAO
;
139 /* Setup dc attribute */
140 pdc
->pdcattr
= &pdc
->dcattr
;
141 pdc
->dcattr
.pvLDC
= NULL
;
142 pdc
->dcattr
.ulDirty_
= DIRTY_DEFAULT
;
143 if (ppdev
== gppdevPrimary
)
144 pdc
->dcattr
.ulDirty_
|= DC_PRIMARY_DISPLAY
;
146 /* Setup the DC size */
147 if (dctype
== DCTYPE_MEMORY
)
149 /* Memory DCs have a 1 x 1 bitmap by default */
150 pdc
->dclevel
.sizl
.cx
= 1;
151 pdc
->dclevel
.sizl
.cy
= 1;
155 /* Other DC's are as big as the related PDEV */
156 pdc
->dclevel
.sizl
.cx
= ppdev
->gdiinfo
.ulHorzRes
;
157 pdc
->dclevel
.sizl
.cy
= ppdev
->gdiinfo
.ulVertRes
;
160 /* Setup Window rect based on DC size */
161 pdc
->erclWindow
.left
= 0;
162 pdc
->erclWindow
.top
= 0;
163 pdc
->erclWindow
.right
= pdc
->dclevel
.sizl
.cx
;
164 pdc
->erclWindow
.bottom
= pdc
->dclevel
.sizl
.cy
;
166 if (dctype
== DCTYPE_DIRECT
)
168 /* Direct DCs get the surface from the PDEV */
169 pdc
->dclevel
.pSurface
= PDEVOBJ_pSurface(ppdev
);
171 pdc
->erclBounds
.left
= 0x7fffffff;
172 pdc
->erclBounds
.top
= 0x7fffffff;
173 pdc
->erclBounds
.right
= 0x80000000;
174 pdc
->erclBounds
.bottom
= 0x80000000;
175 pdc
->erclBoundsApp
.left
= 0xffffffff;
176 pdc
->erclBoundsApp
.top
= 0xfffffffc;
177 pdc
->erclBoundsApp
.right
= 0x00007ffc; // FIXME
178 pdc
->erclBoundsApp
.bottom
= 0x00000333; // FIXME
179 pdc
->erclClip
= pdc
->erclBounds
;
180 pdc
->co
= gxcoTrivial
;
184 /* Non-direct DCs don't have a surface by default */
185 pdc
->dclevel
.pSurface
= NULL
;
187 pdc
->erclBounds
.left
= 0;
188 pdc
->erclBounds
.top
= 0;
189 pdc
->erclBounds
.right
= 0;
190 pdc
->erclBounds
.bottom
= 0;
191 pdc
->erclBoundsApp
= pdc
->erclBounds
;
192 pdc
->erclClip
= pdc
->erclWindow
;
193 pdc
->co
= gxcoTrivial
;
196 //pdc->dcattr.VisRectRegion:
198 /* Setup coordinate transformation data */
199 pdc
->dclevel
.mxWorldToDevice
= gmxWorldToDeviceDefault
;
200 pdc
->dclevel
.mxDeviceToWorld
= gmxDeviceToWorldDefault
;
201 pdc
->dclevel
.mxWorldToPage
= gmxWorldToPageDefault
;
202 pdc
->dclevel
.efM11PtoD
= gef16
;
203 pdc
->dclevel
.efM22PtoD
= gef16
;
204 pdc
->dclevel
.efDxPtoD
= gef0
;
205 pdc
->dclevel
.efDyPtoD
= gef0
;
206 pdc
->dclevel
.efM11_TWIPS
= gef0
;
207 pdc
->dclevel
.efM22_TWIPS
= gef0
;
208 pdc
->dclevel
.efPr11
= gef0
;
209 pdc
->dclevel
.efPr22
= gef0
;
210 pdc
->dcattr
.mxWorldToDevice
= pdc
->dclevel
.mxWorldToDevice
;
211 pdc
->dcattr
.mxDeviceToWorld
= pdc
->dclevel
.mxDeviceToWorld
;
212 pdc
->dcattr
.mxWorldToPage
= pdc
->dclevel
.mxWorldToPage
;
213 pdc
->dcattr
.efM11PtoD
= pdc
->dclevel
.efM11PtoD
;
214 pdc
->dcattr
.efM22PtoD
= pdc
->dclevel
.efM22PtoD
;
215 pdc
->dcattr
.efDxPtoD
= pdc
->dclevel
.efDxPtoD
;
216 pdc
->dcattr
.efDyPtoD
= pdc
->dclevel
.efDyPtoD
;
217 pdc
->dcattr
.iMapMode
= MM_TEXT
;
218 pdc
->dcattr
.dwLayout
= 0;
219 pdc
->dcattr
.flXform
= PAGE_TO_DEVICE_SCALE_IDENTITY
|
220 PAGE_TO_DEVICE_IDENTITY
|
221 WORLD_TO_PAGE_IDENTITY
;
223 /* Setup more coordinates */
224 pdc
->ptlDCOrig
.x
= 0;
225 pdc
->ptlDCOrig
.y
= 0;
226 pdc
->dcattr
.lWindowOrgx
= 0;
227 pdc
->dcattr
.ptlWindowOrg
.x
= 0;
228 pdc
->dcattr
.ptlWindowOrg
.y
= 0;
229 pdc
->dcattr
.szlWindowExt
.cx
= 1;
230 pdc
->dcattr
.szlWindowExt
.cy
= 1;
231 pdc
->dcattr
.ptlViewportOrg
.x
= 0;
232 pdc
->dcattr
.ptlViewportOrg
.y
= 0;
233 pdc
->dcattr
.szlViewportExt
.cx
= 1;
234 pdc
->dcattr
.szlViewportExt
.cy
= 1;
235 pdc
->dcattr
.szlVirtualDevicePixel
.cx
= ppdev
->gdiinfo
.ulHorzRes
;
236 pdc
->dcattr
.szlVirtualDevicePixel
.cy
= ppdev
->gdiinfo
.ulVertRes
;
237 pdc
->dcattr
.szlVirtualDeviceMm
.cx
= ppdev
->gdiinfo
.ulHorzSize
;
238 pdc
->dcattr
.szlVirtualDeviceMm
.cy
= ppdev
->gdiinfo
.ulVertSize
;
239 pdc
->dcattr
.szlVirtualDeviceSize
.cx
= 0;
240 pdc
->dcattr
.szlVirtualDeviceSize
.cy
= 0;
245 pdc
->dclevel
.prgnClip
= NULL
;
246 pdc
->dclevel
.prgnMeta
= NULL
;
247 /* Allocate a Vis region */
248 pdc
->prgnVis
= IntSysCreateRectpRgn(0, 0, pdc
->dclevel
.sizl
.cx
, pdc
->dclevel
.sizl
.cy
);
249 ASSERT(pdc
->prgnVis
);
251 /* Initialize Clip object */
252 IntEngInitClipObj(&pdc
->co
);
255 pdc
->dclevel
.hpal
= StockObjects
[DEFAULT_PALETTE
];
256 pdc
->dclevel
.ppal
= PALETTE_ShareLockPalette(pdc
->dclevel
.hpal
);
259 pdc
->dclevel
.hPath
= NULL
;
260 pdc
->dclevel
.flPath
= 0;
261 // pdc->dclevel.lapath:
264 pdc
->dcattr
.crBackgroundClr
= RGB(0xff, 0xff, 0xff);
265 pdc
->dcattr
.ulBackgroundClr
= RGB(0xff, 0xff, 0xff);
266 pdc
->dcattr
.crForegroundClr
= RGB(0, 0, 0);
267 pdc
->dcattr
.ulForegroundClr
= RGB(0, 0, 0);
268 pdc
->dcattr
.crBrushClr
= RGB(0xff, 0xff, 0xff);
269 pdc
->dcattr
.ulBrushClr
= RGB(0xff, 0xff, 0xff);
270 pdc
->dcattr
.crPenClr
= RGB(0, 0, 0);
271 pdc
->dcattr
.ulPenClr
= RGB(0, 0, 0);
273 /* Select the default fill and line brush */
274 pdc
->dcattr
.hbrush
= StockObjects
[WHITE_BRUSH
];
275 pdc
->dcattr
.hpen
= StockObjects
[BLACK_PEN
];
276 pdc
->dclevel
.pbrFill
= BRUSH_ShareLockBrush(pdc
->pdcattr
->hbrush
);
277 pdc
->dclevel
.pbrLine
= PEN_ShareLockPen(pdc
->pdcattr
->hpen
);
278 pdc
->dclevel
.ptlBrushOrigin
.x
= 0;
279 pdc
->dclevel
.ptlBrushOrigin
.y
= 0;
280 pdc
->dcattr
.ptlBrushOrigin
= pdc
->dclevel
.ptlBrushOrigin
;
282 /* Initialize EBRUSHOBJs */
283 EBRUSHOBJ_vInitFromDC(&pdc
->eboFill
, pdc
->dclevel
.pbrFill
, pdc
);
284 EBRUSHOBJ_vInitFromDC(&pdc
->eboLine
, pdc
->dclevel
.pbrLine
, pdc
);
285 EBRUSHOBJ_vInitFromDC(&pdc
->eboText
, pbrDefaultBrush
, pdc
);
286 EBRUSHOBJ_vInitFromDC(&pdc
->eboBackground
, pbrDefaultBrush
, pdc
);
288 /* Setup fill data */
289 pdc
->dcattr
.jROP2
= R2_COPYPEN
;
290 pdc
->dcattr
.jBkMode
= 2;
291 pdc
->dcattr
.lBkMode
= 2;
292 pdc
->dcattr
.jFillMode
= ALTERNATE
;
293 pdc
->dcattr
.lFillMode
= 1;
294 pdc
->dcattr
.jStretchBltMode
= 1;
295 pdc
->dcattr
.lStretchBltMode
= 1;
296 pdc
->ptlFillOrigin
.x
= 0;
297 pdc
->ptlFillOrigin
.y
= 0;
299 /* Setup drawing position */
300 pdc
->dcattr
.ptlCurrent
.x
= 0;
301 pdc
->dcattr
.ptlCurrent
.y
= 0;
302 pdc
->dcattr
.ptfxCurrent
.x
= 0;
303 pdc
->dcattr
.ptfxCurrent
.y
= 0;
306 pdc
->dclevel
.lIcmMode
= 0;
307 pdc
->dcattr
.lIcmMode
= 0;
308 pdc
->dcattr
.hcmXform
= NULL
;
309 pdc
->dcattr
.flIcmFlags
= 0;
310 pdc
->dcattr
.IcmBrushColor
= CLR_INVALID
;
311 pdc
->dcattr
.IcmPenColor
= CLR_INVALID
;
312 pdc
->dcattr
.pvLIcm
= NULL
;
313 pdc
->dcattr
.hColorSpace
= NULL
; // FIXME: 0189001f
314 pdc
->dclevel
.pColorSpace
= NULL
; // FIXME
315 pdc
->pClrxFormLnk
= NULL
;
318 /* Setup font data */
319 pdc
->hlfntCur
= NULL
; // FIXME: 2f0a0cf8
320 pdc
->pPFFList
= NULL
;
321 pdc
->flSimulationFlags
= 0;
322 pdc
->lEscapement
= 0;
324 pdc
->dcattr
.flFontMapper
= 0;
325 pdc
->dcattr
.flTextAlign
= 0;
326 pdc
->dcattr
.lTextAlign
= 0;
327 pdc
->dcattr
.lTextExtra
= 0;
328 pdc
->dcattr
.lRelAbs
= 1;
329 pdc
->dcattr
.lBreakExtra
= 0;
330 pdc
->dcattr
.cBreak
= 0;
331 pdc
->dcattr
.hlfntNew
= StockObjects
[SYSTEM_FONT
];
332 pdc
->dclevel
.plfnt
= LFONT_ShareLockFont(pdc
->dcattr
.hlfntNew
);
338 pdc
->ulCopyCount
= -1;
339 pdc
->ptlDoBanding
.x
= 0;
340 pdc
->ptlDoBanding
.y
= 0;
341 pdc
->dclevel
.lSaveDepth
= 1;
342 pdc
->dclevel
.hdcSave
= NULL
;
343 pdc
->dcattr
.iGraphicsMode
= GM_COMPATIBLE
;
344 pdc
->dcattr
.iCS_CP
= 0;
345 pdc
->pSurfInfo
= NULL
;
350 DC_vCleanup(PVOID ObjectBody
)
352 PDC pdc
= (PDC
)ObjectBody
;
357 /* Delete saved DCs */
358 DC_vRestoreDC(pdc
, 1);
360 /* Deselect dc objects */
361 DC_vSelectSurface(pdc
, NULL
);
362 DC_vSelectFillBrush(pdc
, NULL
);
363 DC_vSelectLineBrush(pdc
, NULL
);
364 DC_vSelectPalette(pdc
, NULL
);
366 /* Cleanup the dc brushes */
367 EBRUSHOBJ_vCleanup(&pdc
->eboFill
);
368 EBRUSHOBJ_vCleanup(&pdc
->eboLine
);
369 EBRUSHOBJ_vCleanup(&pdc
->eboText
);
370 EBRUSHOBJ_vCleanup(&pdc
->eboBackground
);
373 LFONT_ShareUnlockFont(pdc
->dclevel
.plfnt
);
376 if (pdc
->dclevel
.prgnClip
)
377 REGION_Delete(pdc
->dclevel
.prgnClip
);
378 if (pdc
->dclevel
.prgnMeta
)
379 REGION_Delete(pdc
->dclevel
.prgnMeta
);
381 REGION_Delete(pdc
->prgnVis
);
383 REGION_Delete(pdc
->prgnRao
);
385 REGION_Delete(pdc
->prgnAPI
);
387 /* Free CLIPOBJ resources */
388 IntEngFreeClipResources(&pdc
->co
);
390 PATH_Delete(pdc
->dclevel
.hPath
);
392 if(pdc
->dclevel
.pSurface
)
393 SURFACE_ShareUnlockSurface(pdc
->dclevel
.pSurface
);
395 PDEVOBJ_vRelease(pdc
->ppdev
) ;
400 DC_vSetOwner(PDC pdc
, ULONG ulOwner
)
402 if (pdc
->dclevel
.hPath
)
404 GreSetObjectOwner(pdc
->dclevel
.hPath
, ulOwner
);
407 /* Dereference current brush and pen */
408 BRUSH_ShareUnlockBrush(pdc
->dclevel
.pbrFill
);
409 BRUSH_ShareUnlockBrush(pdc
->dclevel
.pbrLine
);
411 /* Select the default fill and line brush */
412 pdc
->dcattr
.hbrush
= StockObjects
[WHITE_BRUSH
];
413 pdc
->dcattr
.hpen
= StockObjects
[BLACK_PEN
];
414 pdc
->dclevel
.pbrFill
= BRUSH_ShareLockBrush(pdc
->pdcattr
->hbrush
);
415 pdc
->dclevel
.pbrLine
= PEN_ShareLockPen(pdc
->pdcattr
->hpen
);
417 /* Mark them as dirty */
418 pdc
->pdcattr
->ulDirty_
|= DIRTY_FILL
|DIRTY_LINE
;
420 /* Allocate or free DC attribute */
421 if (ulOwner
== GDI_OBJ_HMGR_PUBLIC
|| ulOwner
== GDI_OBJ_HMGR_NONE
)
423 if (pdc
->pdcattr
!= &pdc
->dcattr
)
426 else if (ulOwner
== GDI_OBJ_HMGR_POWNED
)
428 if (pdc
->pdcattr
== &pdc
->dcattr
)
429 DC_bAllocDcAttr(pdc
);
432 /* Set the DC's ownership */
433 GDIOBJ_vSetObjectOwner(&pdc
->BaseObject
, ulOwner
);
438 GreSetDCOwner(HDC hdc
, ULONG ulOwner
)
442 pdc
= DC_LockDc(hdc
);
445 DPRINT1("GreSetDCOwner: Could not lock DC\n");
449 /* Call the internal DC function */
450 DC_vSetOwner(pdc
, ulOwner
);
458 DC_vUpdateDC(PDC pdc
)
461 PPDEVOBJ ppdev
= pdc
->ppdev
;
463 pdc
->dhpdev
= ppdev
->dhpdev
;
465 SURFACE_ShareUnlockSurface(pdc
->dclevel
.pSurface
);
466 pdc
->dclevel
.pSurface
= PDEVOBJ_pSurface(ppdev
);
468 PDEVOBJ_sizl(pdc
->ppdev
, &pdc
->dclevel
.sizl
);
470 VisRgn
= IntSysCreateRectpRgn(0, 0, pdc
->dclevel
.sizl
.cx
, pdc
->dclevel
.sizl
.cy
);
472 GdiSelectVisRgn(pdc
->BaseObject
.hHmgr
, VisRgn
);
473 REGION_Delete(VisRgn
);
476 pdc
->flGraphicsCaps
= ppdev
->devinfo
.flGraphicsCaps
;
477 pdc
->flGraphicsCaps2
= ppdev
->devinfo
.flGraphicsCaps2
;
479 /* Mark EBRUSHOBJs as dirty */
480 pdc
->pdcattr
->ulDirty_
|= DIRTY_DEFAULT
;
483 /* Prepare a blit for up to 2 DCs */
484 /* rc1 and rc2 are the rectangles where we want to draw or
485 * from where we take pixels. */
488 DC_vPrepareDCsForBlit(
494 PDC pdcFirst
, pdcSecond
;
495 const RECT
*prcFirst
, *prcSecond
;
498 if (pdcDest
->pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
499 DC_vUpdateFillBrush(pdcDest
);
500 if (pdcDest
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
501 DC_vUpdateLineBrush(pdcDest
);
502 if(pdcDest
->pdcattr
->ulDirty_
& DIRTY_TEXT
)
503 DC_vUpdateTextBrush(pdcDest
);
505 /* Lock them in good order */
508 if((ULONG_PTR
)pdcDest
->ppdev
->hsemDevLock
>=
509 (ULONG_PTR
)pdcSrc
->ppdev
->hsemDevLock
)
532 if (pdcDest
->fs
& DC_FLAG_DIRTY_RAO
)
533 CLIPPING_UpdateGCRegion(pdcDest
);
535 /* Lock and update first DC */
536 if (pdcFirst
->dctype
== DCTYPE_DIRECT
)
538 EngAcquireSemaphore(pdcFirst
->ppdev
->hsemDevLock
);
540 /* Update surface if needed */
541 if (pdcFirst
->ppdev
->pSurface
!= pdcFirst
->dclevel
.pSurface
)
543 DC_vUpdateDC(pdcFirst
);
547 if (pdcFirst
->dctype
== DCTYPE_DIRECT
)
550 prcFirst
= &pdcFirst
->erclClip
;
552 MouseSafetyOnDrawStart(pdcFirst
->ppdev
,
560 pdcFirst
->fs
|= DC_PREPARED
;
566 /* Lock and update second DC */
567 if (pdcSecond
->dctype
== DCTYPE_DIRECT
)
569 EngAcquireSemaphore(pdcSecond
->ppdev
->hsemDevLock
);
571 /* Update surface if needed */
572 if (pdcSecond
->ppdev
->pSurface
!= pdcSecond
->dclevel
.pSurface
)
574 DC_vUpdateDC(pdcSecond
);
578 if (pdcSecond
->dctype
== DCTYPE_DIRECT
)
581 prcSecond
= &pdcSecond
->erclClip
;
582 MouseSafetyOnDrawStart(pdcSecond
->ppdev
,
590 pdcSecond
->fs
|= DC_PREPARED
;
594 /* Finishes a blit for one or two DCs */
597 DC_vFinishBlit(PDC pdc1
, PDC pdc2
)
599 if (pdc1
->dctype
== DCTYPE_DIRECT
)
601 MouseSafetyOnDrawEnd(pdc1
->ppdev
);
602 EngReleaseSemaphore(pdc1
->ppdev
->hsemDevLock
);
605 pdc1
->fs
&= ~DC_PREPARED
;
610 if (pdc2
->dctype
== DCTYPE_DIRECT
)
612 MouseSafetyOnDrawEnd(pdc2
->ppdev
);
613 EngReleaseSemaphore(pdc2
->ppdev
->hsemDevLock
);
616 pdc2
->fs
&= ~DC_PREPARED
;
624 PUNICODE_STRING pustrDevice
,
626 PUNICODE_STRING pustrLogAddr
,
637 DPRINT("GreOpenDCW(%S, iType=%lu)\n",
638 pustrDevice
? pustrDevice
->Buffer
: NULL
, iType
);
640 /* Get a PDEVOBJ for the device */
641 ppdev
= EngpGetPDEV(pustrDevice
);
644 DPRINT1("Didn't find a suitable PDEV\n");
648 DPRINT("GreOpenDCW - ppdev = %p\n", ppdev
);
650 pdc
= DC_AllocDcWithHandle(GDILoObjType_LO_DC_TYPE
);
653 DPRINT1("Could not Allocate a DC\n");
654 PDEVOBJ_vRelease(ppdev
);
657 hdc
= pdc
->BaseObject
.hHmgr
;
659 /* Lock ppdev and initialize the new DC */
660 DC_vInitDc(pdc
, iType
, ppdev
);
664 DC_bAllocDcAttr(pdc
);
668 DPRINT("Returning hdc = %p\n", hdc
);
677 _In_opt_ PUNICODE_STRING pustrDevice
,
678 _In_ DEVMODEW
*pdmInit
,
679 _In_ PUNICODE_STRING pustrLogAddr
,
682 _In_opt_ HANDLE hspool
,
683 _In_opt_ DRIVER_INFO_2W
*pDriverInfo2
,
684 _At_((PUMDHPDEV
*)pUMdhpdev
, _Out_
) PVOID pUMdhpdev
)
686 UNICODE_STRING ustrDevice
;
687 WCHAR awcDevice
[CCHDEVICENAME
];
692 /* Only if a devicename is given, we need any data */
695 /* Initialize destination string */
696 RtlInitEmptyUnicodeString(&ustrDevice
, awcDevice
, sizeof(awcDevice
));
700 /* Probe the UNICODE_STRING and the buffer */
701 ProbeForRead(pustrDevice
, sizeof(UNICODE_STRING
), 1);
702 ProbeForRead(pustrDevice
->Buffer
, pustrDevice
->Length
, 1);
704 /* Copy the string */
705 RtlCopyUnicodeString(&ustrDevice
, pustrDevice
);
709 /* FIXME: could be larger */
710 /* According to a comment in Windows SDK the size of the buffer for
711 pdm is (pdm->dmSize + pdm->dmDriverExtra) */
712 ProbeForRead(pdmInit
, sizeof(DEVMODEW
), 1);
713 RtlCopyMemory(&dmInit
, pdmInit
, sizeof(DEVMODEW
));
718 ProbeForWrite(pUMdhpdev
, sizeof(HANDLE
), 1);
721 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
723 SetLastNtError(_SEH2_GetExceptionCode());
724 _SEH2_YIELD(return NULL
);
737 UNICODE_STRING ustrDISPLAY
= RTL_CONSTANT_STRING(L
"DISPLAY");
738 if (RtlEqualUnicodeString(&ustrDevice
, &ustrDISPLAY
, TRUE
))
744 /* Call the internal function */
745 hdc
= GreOpenDCW(pustrDevice
? &ustrDevice
: NULL
,
746 pdmInit
? &dmInit
: NULL
,
747 NULL
, // FIXME: pwszLogAddress
751 NULL
, // FIXME: pDriverInfo2
752 pUMdhpdev
? &dhpdev
: NULL
);
754 /* If we got a HDC and a UM dhpdev is requested,... */
755 if (hdc
&& pUMdhpdev
)
757 /* Copy dhpdev to caller (FIXME: use dhpdev?) */
760 /* Pointer was already probed */
761 *(HANDLE
*)pUMdhpdev
= dhpdev
;
763 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
777 GreCreateCompatibleDC(HDC hdc
, BOOL bAltDc
)
779 GDILOOBJTYPE eDcObjType
;
784 DPRINT("NtGdiCreateCompatibleDC(0x%p)\n", hdc
);
786 /* Did the caller provide a DC? */
789 /* Yes, try to lock it */
790 pdc
= DC_LockDc(hdc
);
793 DPRINT1("Could not lock source DC %p\n", hdc
);
797 /* Get the pdev from the DC */
799 InterlockedIncrement(&ppdev
->cPdevRefs
);
801 /* Unlock the source DC */
806 /* No DC given, get default device */
807 ppdev
= EngpGetPDEV(NULL
);
812 DPRINT1("Didn't find a suitable PDEV\n");
816 /* Allocate a new DC */
817 eDcObjType
= bAltDc
? GDILoObjType_LO_ALTDC_TYPE
: GDILoObjType_LO_DC_TYPE
;
818 pdcNew
= DC_AllocDcWithHandle(eDcObjType
);
821 DPRINT1("Could not allocate a new DC\n");
822 PDEVOBJ_vRelease(ppdev
);
825 hdcNew
= pdcNew
->BaseObject
.hHmgr
;
827 /* Lock ppdev and initialize the new DC */
828 DC_vInitDc(pdcNew
, bAltDc
? DCTYPE_INFO
: DCTYPE_MEMORY
, ppdev
);
832 /* Allocate a dc attribute */
833 DC_bAllocDcAttr(pdcNew
);
837 DPRINT("Leave NtGdiCreateCompatibleDC hdcNew = %p\n", hdcNew
);
844 NtGdiCreateCompatibleDC(HDC hdc
)
846 /* Call the internal function to create a normal memory DC */
847 return GreCreateCompatibleDC(hdc
, FALSE
);
852 IntGdiDeleteDC(HDC hDC
, BOOL Force
)
854 PDC DCToDelete
= DC_LockDc(hDC
);
856 if (DCToDelete
== NULL
)
858 EngSetLastError(ERROR_INVALID_HANDLE
);
864 /* Windows permits NtGdiDeleteObjectApp to delete a permanent DC
865 * For some reason, it's still a valid handle, pointing to some kernel data.
866 * Not sure if this is a bug, a feature, some cache stuff... Who knows?
867 * See NtGdiDeleteObjectApp test for details */
868 if (DCToDelete
->fs
& DC_FLAG_PERMANENT
)
870 DC_UnlockDc(DCToDelete
);
871 if(UserReleaseDC(NULL
, hDC
, FALSE
))
873 /* ReactOS feature: Call UserReleaseDC
874 * I don't think Windows does it.
875 * Still, complain, no one should ever call DeleteDC
877 DPRINT1("No, you naughty application!\n");
882 /* This is not a window owned DC.
883 * Force its deletion */
884 return IntGdiDeleteDC(hDC
, TRUE
);
889 DC_UnlockDc(DCToDelete
);
891 if (GreIsHandleValid(hDC
))
893 if (!GreDeleteObject(hDC
))
895 DPRINT1("DC_FreeDC failed\n");
901 DPRINT1("Attempted to Delete 0x%p currently being destroyed!!!\n", hDC
);
910 NtGdiDeleteObjectApp(HANDLE hobj
)
912 /* Complete all pending operations */
913 NtGdiFlushUserBatch(); // FIXME: We shouldn't need this
915 if (GDI_HANDLE_IS_STOCKOBJ(hobj
)) return TRUE
;
917 if (GreGetObjectOwner(hobj
) != GDI_OBJ_HMGR_POWNED
)
919 EngSetLastError(ERROR_INVALID_HANDLE
);
923 if (GDI_HANDLE_GET_TYPE(hobj
) != GDI_OBJECT_TYPE_DC
)
924 return GreDeleteObject(hobj
);
926 // FIXME: Everything should be callback based
927 return IntGdiDeleteDC(hobj
, FALSE
);
932 MakeInfoDC(PDC pdc
, BOOL bSet
)
937 /* Can not be a display DC. */
938 if (pdc
->fs
& DC_FLAG_DISPLAY
) return FALSE
;
941 if (pdc
->fs
& DC_FLAG_TEMPINFODC
|| pdc
->dctype
== DC_TYPE_DIRECT
)
944 pSurface
= pdc
->dclevel
.pSurface
;
945 pdc
->fs
|= DC_FLAG_TEMPINFODC
;
946 pdc
->pSurfInfo
= pSurface
;
947 pdc
->dctype
= DC_TYPE_INFO
;
948 pdc
->dclevel
.pSurface
= NULL
;
950 PDEVOBJ_sizl(pdc
->ppdev
, &sizl
);
952 if ( sizl
.cx
== pdc
->dclevel
.sizl
.cx
&&
953 sizl
.cy
== pdc
->dclevel
.sizl
.cy
)
956 pdc
->dclevel
.sizl
.cx
= sizl
.cx
;
957 pdc
->dclevel
.sizl
.cy
= sizl
.cy
;
961 if (!(pdc
->fs
& DC_FLAG_TEMPINFODC
) || pdc
->dctype
!= DC_TYPE_INFO
)
964 pSurface
= pdc
->pSurfInfo
;
965 pdc
->fs
&= ~DC_FLAG_TEMPINFODC
;
966 pdc
->dclevel
.pSurface
= pSurface
;
967 pdc
->dctype
= DC_TYPE_DIRECT
;
968 pdc
->pSurfInfo
= NULL
;
971 (pSurface
->SurfObj
.sizlBitmap
.cx
== pdc
->dclevel
.sizl
.cx
&&
972 pSurface
->SurfObj
.sizlBitmap
.cy
== pdc
->dclevel
.sizl
.cy
) )
975 pdc
->dclevel
.sizl
.cx
= pSurface
->SurfObj
.sizlBitmap
.cx
;
976 pdc
->dclevel
.sizl
.cy
= pSurface
->SurfObj
.sizlBitmap
.cy
;
978 return IntSetDefaultRegion(pdc
);
991 PDC pdc
= DC_LockDc(hdc
);
994 Ret
= MakeInfoDC(pdc
, bSet
);
1004 PUNICODE_STRING Driver
,
1005 PUNICODE_STRING pustrDevice
,
1007 CONST PDEVMODEW pdmInit
,
1012 hdc
= GreOpenDCW(pustrDevice
,
1015 CreateAsIC
? DCTYPE_INFO
:
1016 (Driver
? DC_TYPE_DIRECT
: DC_TYPE_DIRECT
),
1026 IntGdiCreateDisplayDC(HDEV hDev
, ULONG DcType
, BOOL EmptyDC
)
1032 if (DcType
== DC_TYPE_MEMORY
)
1033 hDC
= NtGdiCreateCompatibleDC(NULL
); // OH~ Yuck! I think I taste vomit in my mouth!
1035 hDC
= IntGdiCreateDC(NULL
, NULL
, NULL
, NULL
, (DcType
== DC_TYPE_INFO
));