2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: Functions for creation and destruction of DCs
5 * FILE: subsystems/win32/win32k/objects/dcobjs.c
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@rectos.org)
16 DC_vUpdateFillBrush(PDC pdc
)
18 PDC_ATTR pdcattr
= pdc
->pdcattr
;
21 /* Check if the brush handle has changed */
22 if (pdcattr
->hbrush
!= pdc
->dclevel
.pbrFill
->BaseObject
.hHmgr
)
24 /* Try to lock the new brush */
25 pbrFill
= BRUSH_ShareLockBrush(pdcattr
->hbrush
);
28 /* Unlock old brush, set new brush */
29 BRUSH_ShareUnlockBrush(pdc
->dclevel
.pbrFill
);
30 pdc
->dclevel
.pbrFill
= pbrFill
;
32 /* Mark eboFill as dirty */
33 pdcattr
->ulDirty_
|= DIRTY_FILL
;
37 /* Invalid brush handle, restore old one */
38 pdcattr
->hbrush
= pdc
->dclevel
.pbrFill
->BaseObject
.hHmgr
;
42 /* Check if the EBRUSHOBJ needs update */
43 if (pdcattr
->ulDirty_
& DIRTY_FILL
)
46 EBRUSHOBJ_vUpdate(&pdc
->eboFill
, pdc
->dclevel
.pbrFill
, pdc
);
49 /* Check for DC brush */
50 if (pdcattr
->hbrush
== StockObjects
[DC_BRUSH
])
52 /* ROS HACK, should use surf xlate */
53 /* Update the eboFill's solid color */
54 EBRUSHOBJ_vSetSolidBrushColor(&pdc
->eboFill
, pdcattr
->crPenClr
);
58 pdcattr
->ulDirty_
&= ~(DIRTY_FILL
| DC_BRUSH_DIRTY
);
63 DC_vUpdateLineBrush(PDC pdc
)
65 PDC_ATTR pdcattr
= pdc
->pdcattr
;
68 /* Check if the pen handle has changed */
69 if (pdcattr
->hpen
!= pdc
->dclevel
.pbrLine
->BaseObject
.hHmgr
)
71 /* Try to lock the new pen */
72 pbrLine
= PEN_ShareLockPen(pdcattr
->hpen
);
75 /* Unlock old brush, set new brush */
76 BRUSH_ShareUnlockBrush(pdc
->dclevel
.pbrLine
);
77 pdc
->dclevel
.pbrLine
= pbrLine
;
79 /* Mark eboLine as dirty */
80 pdcattr
->ulDirty_
|= DIRTY_LINE
;
84 /* Invalid pen handle, restore old one */
85 pdcattr
->hpen
= pdc
->dclevel
.pbrLine
->BaseObject
.hHmgr
;
89 /* Check if the EBRUSHOBJ needs update */
90 if (pdcattr
->ulDirty_
& DIRTY_LINE
)
93 EBRUSHOBJ_vUpdate(&pdc
->eboLine
, pdc
->dclevel
.pbrLine
, pdc
);
96 /* Check for DC pen */
97 if (pdcattr
->hpen
== StockObjects
[DC_PEN
])
99 /* Update the eboLine's solid color */
100 EBRUSHOBJ_vSetSolidBrushColor(&pdc
->eboLine
, pdcattr
->crPenClr
);
104 pdcattr
->ulDirty_
&= ~(DIRTY_LINE
| DC_PEN_DIRTY
);
109 DC_vUpdateTextBrush(PDC pdc
)
111 PDC_ATTR pdcattr
= pdc
->pdcattr
;
113 /* Timo : The text brush should never be changed.
114 * Jérôme : Yeah, but its palette must be updated anyway! */
115 if(pdcattr
->ulDirty_
& DIRTY_TEXT
)
116 EBRUSHOBJ_vUpdate(&pdc
->eboText
, pbrDefaultBrush
, pdc
);
118 /* Update the eboText's solid color */
119 EBRUSHOBJ_vSetSolidBrushColor(&pdc
->eboText
, pdcattr
->crForegroundClr
);
122 pdcattr
->ulDirty_
&= ~DIRTY_TEXT
;
127 DC_vUpdateBackgroundBrush(PDC pdc
)
129 PDC_ATTR pdcattr
= pdc
->pdcattr
;
131 if(pdcattr
->ulDirty_
& DIRTY_BACKGROUND
)
132 EBRUSHOBJ_vUpdate(&pdc
->eboBackground
, pbrDefaultBrush
, pdc
);
134 /* Update the eboBackground's solid color */
135 EBRUSHOBJ_vSetSolidBrushColor(&pdc
->eboBackground
, pdcattr
->crBackgroundClr
);
138 pdcattr
->ulDirty_
&= ~DIRTY_BACKGROUND
;
146 BOOL ForceBackground
)
149 HPALETTE oldPal
= NULL
;
152 // FIXME: Mark the palette as a [fore\back]ground pal
153 pdc
= DC_LockDc(hDC
);
159 /* Check if this is a valid palette handle */
160 ppal
= PALETTE_ShareLockPalette(hpal
);
167 /* Is this a valid palette for this depth? */
168 if ((BitsPerFormat(pdc
->dclevel
.pSurface
->SurfObj
.iBitmapFormat
) <= 8
169 && (ppal
->flFlags
& PAL_INDEXED
)) ||
170 (BitsPerFormat(pdc
->dclevel
.pSurface
->SurfObj
.iBitmapFormat
) > 8))
172 /* Get old palette, set new one */
173 oldPal
= pdc
->dclevel
.hpal
;
174 pdc
->dclevel
.hpal
= hpal
;
175 DC_vSelectPalette(pdc
, ppal
);
177 /* Mark the brushes invalid */
178 pdc
->pdcattr
->ulDirty_
|= DIRTY_FILL
| DIRTY_LINE
|
179 DIRTY_BACKGROUND
| DIRTY_TEXT
;
182 if(pdc
->dctype
== DCTYPE_MEMORY
)
184 // This didn't work anyway
185 //IntGdiRealizePalette(hDC);
188 PALETTE_ShareUnlockPalette(ppal
);
206 if (hDC
== NULL
|| hBrush
== NULL
) return NULL
;
208 pDC
= DC_LockDc(hDC
);
214 /* Simply return the user mode value, without checking */
215 hOrgBrush
= pDC
->pdcattr
->hbrush
;
216 pDC
->pdcattr
->hbrush
= hBrush
;
217 DC_vUpdateFillBrush(pDC
);
236 if (hDC
== NULL
|| hPen
== NULL
) return NULL
;
238 pDC
= DC_LockDc(hDC
);
244 /* Simply return the user mode value, without checking */
245 hOrgPen
= pDC
->pdcattr
->hpen
;
246 pDC
->pdcattr
->hpen
= hPen
;
247 DC_vUpdateLineBrush(pDC
);
265 PSURFACE psurfNew
, psurfOld
;
270 /* Verify parameters */
271 if (hdc
== NULL
|| hbmp
== NULL
) return NULL
;
273 /* First lock the DC */
274 pdc
= DC_LockDc(hdc
);
280 /* Must be a memory dc to select a bitmap */
281 if (pdc
->dctype
!= DC_TYPE_MEMORY
)
287 /* Save the old bitmap */
288 psurfOld
= pdc
->dclevel
.pSurface
;
290 /* Check if there is a bitmap selected */
293 /* Get the old bitmap's handle */
294 hbmpOld
= psurfOld
->BaseObject
.hHmgr
;
298 /* Use the default bitmap */
299 hbmpOld
= StockObjects
[DEFAULT_BITMAP
];
302 /* Check if the new bitmap is already selected */
305 /* Unlock the DC and return the old bitmap */
310 /* Check if the default bitmap was passed */
311 if (hbmp
== StockObjects
[DEFAULT_BITMAP
])
315 /* Default bitmap is 1x1 pixel */
316 pdc
->dclevel
.sizl
.cx
= 1;
317 pdc
->dclevel
.sizl
.cy
= 1;
320 psurfNew
= SURFACE_ShareLockSurface(hbmp
);
324 /* Reference the new bitmap and check if it's valid */
325 psurfNew
= SURFACE_ShareLockSurface(hbmp
);
332 /* Set the bitmap's hdc and check if it was set before */
333 hdcOld
= InterlockedCompareExchangePointer((PVOID
*)&psurfNew
->hdc
, hdc
, 0);
336 /* The bitmap is already selected into a different DC */
337 ASSERT(hdcOld
!= hdc
);
339 /* Dereference the bitmap, unlock the DC and fail. */
340 SURFACE_ShareUnlockSurface(psurfNew
);
345 /* Copy the bitmap size */
346 pdc
->dclevel
.sizl
= psurfNew
->SurfObj
.sizlBitmap
;
348 /* Check if the bitmap is a dibsection */
349 if(psurfNew
->hSecure
)
351 /* Set DIBSECTION attribute */
352 pdc
->pdcattr
->ulDirty_
|= DC_DIBSECTION
;
356 /* Remove DIBSECTION attribute */
357 pdc
->pdcattr
->ulDirty_
&= ~DC_DIBSECTION
;
361 /* Select the new bitmap */
362 pdc
->dclevel
.pSurface
= psurfNew
;
364 /* Check if there was a bitmap selected before */
367 /* Reset hdc of the old bitmap, it isn't selected anymore */
368 psurfOld
->hdc
= NULL
;
370 /* Dereference the old bitmap */
371 SURFACE_ShareUnlockSurface(psurfOld
);
374 /* Mark the dc brushes invalid */
375 pdc
->pdcattr
->ulDirty_
|= DIRTY_FILL
| DIRTY_LINE
;
377 /* FIXME: Improve by using a region without a handle and selecting it */
378 hVisRgn
= IntSysCreateRectRgn( 0,
380 pdc
->dclevel
.sizl
.cx
,
381 pdc
->dclevel
.sizl
.cy
);
385 GdiSelectVisRgn(hdc
, hVisRgn
);
386 GreDeleteObject(hVisRgn
);
392 /* Return the old bitmap handle */
405 BOOL success
= FALSE
;
409 pdc
= DC_LockDc(hDC
);
412 EngSetLastError(ERROR_INVALID_PARAMETER
);
415 pdcattr
= pdc
->pdcattr
;
417 pPath
= PATH_LockPath(pdc
->dclevel
.hPath
);
424 /* Check that path is closed */
425 if (pPath
->state
!= PATH_Closed
)
427 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
432 /* Construct a region from the path */
433 else if (PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnPath
))
435 success
= GdiExtSelectClipRgn(pdc
, hrgnPath
, Mode
) != ERROR
;
436 GreDeleteObject( hrgnPath
);
440 PATH_EmptyPath(pPath
);
442 /* FIXME: Should this function delete the path even if it failed? */
445 PATH_UnlockPath(pPath
);
453 NtGdiGetDCObject(HDC hDC
, INT ObjectType
)
459 /* From Wine: GetCurrentObject does not SetLastError() on a null object */
460 if(!hDC
) return NULL
;
462 if(!(pdc
= DC_LockDc(hDC
)))
464 EngSetLastError(ERROR_INVALID_HANDLE
);
467 pdcattr
= pdc
->pdcattr
;
469 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
470 DC_vUpdateFillBrush(pdc
);
472 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
473 DC_vUpdateLineBrush(pdc
);
477 case GDI_OBJECT_TYPE_EXTPEN
:
478 case GDI_OBJECT_TYPE_PEN
:
479 SelObject
= pdcattr
->hpen
;
482 case GDI_OBJECT_TYPE_BRUSH
:
483 SelObject
= pdcattr
->hbrush
;
486 case GDI_OBJECT_TYPE_PALETTE
:
487 SelObject
= pdc
->dclevel
.hpal
;
490 case GDI_OBJECT_TYPE_FONT
:
491 SelObject
= pdcattr
->hlfntNew
;
494 case GDI_OBJECT_TYPE_BITMAP
:
496 SURFACE
*psurf
= pdc
->dclevel
.pSurface
;
497 SelObject
= psurf
? psurf
->BaseObject
.hHmgr
: NULL
;
501 case GDI_OBJECT_TYPE_COLORSPACE
:
502 DPRINT1("FIXME: NtGdiGetCurrentObject() ObjectType OBJ_COLORSPACE not supported yet!\n");
503 // SelObject = dc->dclevel.pColorSpace.BaseObject.hHmgr; ?
509 EngSetLastError(ERROR_INVALID_PARAMETER
);
517 /* See WINE, MSDN, OSR and Feng Yuan - Windows Graphics Programming Win32 GDI and DirectDraw
519 * 1st: http://www.codeproject.com/gdi/cliprgnguide.asp is wrong!
521 * The intersection of the clip with the meta region is not Rao it's API!
522 * Go back and read 7.2 Clipping pages 418-19:
524 * 1) The Rao region is the intersection of the API region and the system region,
525 * named after the Microsoft engineer who initially proposed it.
526 * 2) The Rao region can be calculated from the API region and the system region.
529 * API region is the intersection of the meta region and the clipping region,
530 * clearly named after the fact that it is controlled by GDI API calls.
544 pdc
= DC_LockDc(hdc
);
547 EngSetLastError(ERROR_INVALID_PARAMETER
);
554 hrgnSrc
= pdc
->rosdc
.hClipRgn
;
555 // if (pdc->dclevel.prgnClip) hrgnSrc = pdc->dclevel.prgnClip->BaseObject.hHmgr;
558 if (pdc
->dclevel
.prgnMeta
)
559 hrgnSrc
= pdc
->dclevel
.prgnMeta
->BaseObject
.hHmgr
;
562 if (pdc
->prgnAPI
) hrgnSrc
= pdc
->prgnAPI
->BaseObject
.hHmgr
;
563 // else if (pdc->dclevel.prgnClip) hrgnSrc = pdc->dclevel.prgnClip->BaseObject.hHmgr;
564 else if (pdc
->rosdc
.hClipRgn
) hrgnSrc
= pdc
->rosdc
.hClipRgn
;
565 else if (pdc
->dclevel
.prgnMeta
) hrgnSrc
= pdc
->dclevel
.prgnMeta
->BaseObject
.hHmgr
;
570 PREGION prgnDest
= REGION_LockRgn(hrgnDest
);
571 ret
= IntGdiCombineRgn(prgnDest
, pdc
->prgnVis
, 0, RGN_COPY
) == ERROR
? -1 : 1;
572 REGION_UnlockRgn(prgnDest
);
581 ret
= NtGdiCombineRgn(hrgnDest
, hrgnSrc
, 0, RGN_COPY
) == ERROR
? -1 : 1;
586 ptlOrg
= pdc
->ptlDCOrig
;
587 NtGdiOffsetRgn(hrgnDest
, ptlOrg
.x
, ptlOrg
.y
);
601 OUT OPTIONAL PVOID pvBuf
)