2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Functions for saving and restoring dc states
5 * FILE: subsystem/win32/win32k/objects/dcstate.c
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@rectos.org)
16 DC_vCopyState(PDC pdcSrc
, PDC pdcDst
)
18 /* Copy full DC attribute */
19 *pdcDst
->pdcattr
= *pdcSrc
->pdcattr
;
21 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
22 /* The VisRectRegion field needs to be set to a valid state */
24 /* Mark some fields as dirty */
25 pdcDst
->pdcattr
->ulDirty_
|= 0x0012001f;
28 pdcDst
->dclevel
.pColorSpace
= pdcSrc
->dclevel
.pColorSpace
;
29 pdcDst
->dclevel
.lSaveDepth
= pdcSrc
->dclevel
.lSaveDepth
;
30 pdcDst
->dclevel
.hdcSave
= pdcSrc
->dclevel
.hdcSave
;
31 pdcDst
->dclevel
.laPath
= pdcSrc
->dclevel
.laPath
;
32 pdcDst
->dclevel
.ca
= pdcSrc
->dclevel
.ca
;
33 pdcDst
->dclevel
.mxWorldToDevice
= pdcSrc
->dclevel
.mxWorldToDevice
;
34 pdcDst
->dclevel
.mxDeviceToWorld
= pdcSrc
->dclevel
.mxDeviceToWorld
;
35 pdcDst
->dclevel
.mxWorldToPage
= pdcSrc
->dclevel
.mxWorldToPage
;
36 pdcDst
->dclevel
.efM11PtoD
= pdcSrc
->dclevel
.efM11PtoD
;
37 pdcDst
->dclevel
.efM22PtoD
= pdcSrc
->dclevel
.efM22PtoD
;
38 pdcDst
->dclevel
.sizl
= pdcSrc
->dclevel
.sizl
;
39 pdcDst
->dclevel
.hpal
= pdcSrc
->dclevel
.hpal
;
41 /* Handle references here correctly */
42 DC_vSelectSurface(pdcDst
, pdcSrc
->dclevel
.pSurface
);
43 DC_vSelectFillBrush(pdcDst
, pdcSrc
->dclevel
.pbrFill
);
44 DC_vSelectLineBrush(pdcDst
, pdcSrc
->dclevel
.pbrLine
);
45 DC_vSelectPalette(pdcDst
, pdcSrc
->dclevel
.ppal
);
48 pdcDst
->dclevel
.plfnt
= pdcSrc
->dclevel
.plfnt
;
51 if (pdcDst
->dctype
!= DC_TYPE_MEMORY
)
53 pdcDst
->rosdc
.bitsPerPixel
= pdcSrc
->rosdc
.bitsPerPixel
;
56 GdiExtSelectClipRgn(pdcDst
, pdcSrc
->rosdc
.hClipRgn
, RGN_COPY
);
62 IntGdiCleanDC(HDC hDC
)
65 if (!hDC
) return FALSE
;
67 if (!dc
) return FALSE
;
69 if (defaultDCstate
) DC_vCopyState(defaultDCstate
, dc
);
71 if (dc
->dctype
!= DC_TYPE_MEMORY
)
73 dc
->rosdc
.bitsPerPixel
= defaultDCstate
->rosdc
.bitsPerPixel
;
88 IN OPTIONAL VOID
*pDriverInfo2
,
104 PEPROCESS pepCurrentProcess
;
106 DPRINT("NtGdiRestoreDC(%lx, %d)\n", hdc
, iSaveLevel
);
108 /* Lock the original DC */
109 pdc
= DC_LockDc(hdc
);
112 SetLastWin32Error(ERROR_INVALID_HANDLE
);
116 ASSERT(pdc
->dclevel
.lSaveDepth
> 0);
118 /* Negative values are relative to the stack top */
120 iSaveLevel
= pdc
->dclevel
.lSaveDepth
+ iSaveLevel
;
122 /* Check if we have a valid instance */
123 if (iSaveLevel
<= 0 || iSaveLevel
>= pdc
->dclevel
.lSaveDepth
)
125 DPRINT("Illegal save level, requested: %ld, current: %ld\n",
126 iSaveLevel
, pdc
->dclevel
.lSaveDepth
);
128 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
132 /* Get current process */
133 pepCurrentProcess
= PsGetCurrentProcess();
135 /* Loop the save levels */
136 while (pdc
->dclevel
.lSaveDepth
> iSaveLevel
)
138 hdcSave
= pdc
->dclevel
.hdcSave
;
140 /* Set us as the owner */
141 if (!GDIOBJ_SetOwnership(hdcSave
, pepCurrentProcess
))
143 /* Could not get ownership. That's bad! */
144 DPRINT1("Could not get ownership of saved DC (%p) for dc %p!\n",
149 /* Lock the saved dc */
150 pdcSave
= DC_LockDc(hdcSave
);
153 /* WTF? Internal error! */
154 DPRINT1("Could not lock the saved DC (%p) for dc %p!\n",
160 /* Remove the saved dc from the queue */
161 pdc
->dclevel
.hdcSave
= pdcSave
->dclevel
.hdcSave
;
163 /* Decrement save level */
164 pdc
->dclevel
.lSaveDepth
--;
166 /* Is this the state we want? */
167 if (pdc
->dclevel
.lSaveDepth
== iSaveLevel
)
169 /* Copy the state back */
170 DC_vCopyState(pdcSave
, pdc
);
172 // Restore Path by removing it, if the Save flag is set.
173 // BeginPath will takecare of the rest.
174 if (pdc
->dclevel
.hPath
&& pdc
->dclevel
.flPath
& DCPATH_SAVE
)
176 PATH_Delete(pdc
->dclevel
.hPath
);
177 pdc
->dclevel
.hPath
= 0;
178 pdc
->dclevel
.flPath
&= ~DCPATH_SAVE
;
182 /* Delete the saved dc */
183 GreDeleteObject(hdcSave
);
188 DPRINT("Leaving NtGdiRestoreDC\n");
202 DPRINT("NtGdiSaveDC(%lx)\n", hDC
);
204 /* Lock the original dc */
205 pdc
= DC_LockDc(hDC
);
208 DPRINT("Could not lock DC\n");
209 SetLastWin32Error(ERROR_INVALID_HANDLE
);
213 /* Allocate a new dc */
214 pdcSave
= DC_AllocDC(NULL
);
217 DPRINT("Could not allocate a new DC\n");
221 hdcSave
= pdcSave
->BaseObject
.hHmgr
;
223 /* Make it a kernel handle
224 (FIXME: windows handles this different, see wiki)*/
225 GDIOBJ_SetOwnership(hdcSave
, NULL
);
227 /* Copy the current state */
228 DC_vCopyState(pdc
, pdcSave
);
230 /* Copy path. FIXME: why this way? */
231 pdcSave
->dclevel
.hPath
= pdc
->dclevel
.hPath
;
232 pdcSave
->dclevel
.flPath
= pdc
->dclevel
.flPath
| DCPATH_SAVESTATE
;
233 if (pdcSave
->dclevel
.hPath
) pdcSave
->dclevel
.flPath
|= DCPATH_SAVE
;
235 /* Set new dc as save dc */
236 pdc
->dclevel
.hdcSave
= hdcSave
;
238 /* Increase save depth, return old value */
239 lSaveDepth
= pdc
->dclevel
.lSaveDepth
++;
241 /* Cleanup and return */
242 DC_UnlockDc(pdcSave
);
245 DPRINT("Leave NtGdiSaveDC: %ld\n", lSaveDepth
);