xref: /reactos/win32ss/gdi/ntgdi/dc.h (revision c2c66aff)
1 #ifndef __WIN32K_DC_H
2 #define __WIN32K_DC_H
3 
4 /* Constants ******************************************************************/
5 
6 /* flFontState */
7 enum _FONT_STATE
8 {
9     DC_DIRTYFONT_XFORM = 1,
10     DC_DIRTYFONT_LFONT = 2,
11     DC_UFI_MAPPING     = 4
12 };
13 
14 /* fl */
15 #define DC_FL_PAL_BACK 1
16 
17 enum _DCFLAGS
18 {
19     DC_DISPLAY           = 0x0001,
20     DC_DIRECT            = 0x0002,
21     DC_CANCELED          = 0x0004,
22     DC_PERMANANT         = 0x0008,
23     DC_DIRTY_RAO         = 0x0010,
24     DC_ACCUM_WMGR        = 0x0020,
25     DC_ACCUM_APP         = 0x0040,
26     DC_RESET             = 0x0080,
27     DC_SYNCHRONIZEACCESS = 0x0100,
28     DC_EPSPRINTINGESCAPE = 0x0200,
29     DC_TEMPINFODC        = 0x0400,
30     DC_FULLSCREEN        = 0x0800,
31     DC_IN_CLONEPDEV      = 0x1000,
32     DC_REDIRECTION       = 0x2000,
33     DC_SHAREACCESS       = 0x4000,
34 #if DBG
35     DC_PREPARED          = 0x8000
36 #endif
37 };
38 
39 typedef enum _DCTYPE
40 {
41     DCTYPE_DIRECT = 0,
42     DCTYPE_MEMORY = 1,
43     DCTYPE_INFO = 2,
44 } DCTYPE;
45 
46 
47 /* Type definitions ***********************************************************/
48 
49 typedef struct _DCLEVEL
50 {
51   HPALETTE          hpal;
52   struct _PALETTE  * ppal;
53   PVOID             pColorSpace; /* COLORSPACE* */
54   LONG              lIcmMode;
55   LONG              lSaveDepth;
56   DWORD             unk1_00000000;
57   HGDIOBJ           hdcSave;
58   POINTL            ptlBrushOrigin;
59   PBRUSH            pbrFill;
60   PBRUSH            pbrLine;
61   _Notnull_ struct _LFONT   * plfnt; /* LFONT* (TEXTOBJ*) */
62   HGDIOBJ           hPath; /* HPATH */
63   FLONG             flPath;
64   LINEATTRS         laPath; /* 0x20 bytes */
65   PREGION           prgnClip;
66   PREGION           prgnMeta;
67   COLORADJUSTMENT   ca;
68   FLONG             flFontState;
69   UNIVERSAL_FONT_ID ufi;
70   UNIVERSAL_FONT_ID ufiLoc[4]; /* Local List. */
71   UNIVERSAL_FONT_ID *pUFI;
72   ULONG             uNumUFIs;
73   BOOL              ufiSet;
74   FLONG             fl;
75   FLONG             flBrush;
76   MATRIX            mxWorldToDevice;
77   MATRIX            mxDeviceToWorld;
78   MATRIX            mxWorldToPage;
79   FLOATOBJ          efM11PtoD;
80   FLOATOBJ          efM22PtoD;
81   FLOATOBJ          efDxPtoD;
82   FLOATOBJ          efDyPtoD;
83   FLOATOBJ          efM11_TWIPS;
84   FLOATOBJ          efM22_TWIPS;
85   FLOATOBJ          efPr11;
86   FLOATOBJ          efPr22;
87   PSURFACE          pSurface;
88   SIZE              sizl;
89 } DCLEVEL, *PDCLEVEL;
90 
91 /* The DC object structure */
92 typedef struct _DC
93 {
94   /* Header for all gdi objects in the handle table.
95      Do not (re)move this. */
96   BASEOBJECT  BaseObject;
97 
98   DHPDEV      dhpdev;   /* <- PDEVOBJ.hPDev DHPDEV for device. */
99   DCTYPE      dctype;
100   INT         fs;
101   PPDEVOBJ    ppdev;
102   PVOID       hsem;   /* PERESOURCE aka HSEMAPHORE */
103   FLONG       flGraphicsCaps;
104   FLONG       flGraphicsCaps2;
105   _Notnull_ PDC_ATTR    pdcattr;
106   DCLEVEL     dclevel;
107   DC_ATTR     dcattr;
108   HDC         hdcNext;
109   HDC         hdcPrev;
110   RECTL       erclClip;
111   POINTL      ptlDCOrig;
112   RECTL       erclWindow;
113   RECTL       erclBounds;
114   RECTL       erclBoundsApp;
115   PREGION     prgnAPI;
116   _Notnull_ PREGION     prgnVis; /* Visible region (must never be 0) */
117   PREGION     prgnRao;
118   POINTL      ptlFillOrigin;
119   EBRUSHOBJ   eboFill;
120   EBRUSHOBJ   eboLine;
121   EBRUSHOBJ   eboText;
122   EBRUSHOBJ   eboBackground;
123   HFONT       hlfntCur;
124   FLONG       flSimulationFlags;
125   LONG        lEscapement;
126   PVOID       prfnt;    /* RFONT* */
127   XCLIPOBJ    co;       /* CLIPOBJ */
128   PVOID       pPFFList; /* PPFF* */
129   PVOID       pClrxFormLnk;
130   INT         ipfdDevMax;
131   ULONG       ulCopyCount;
132   PVOID       pSurfInfo;
133   POINTL      ptlDoBanding;
134 } DC;
135 // typedef struct _DC *PDC;
136 
137 extern PDC defaultDCstate;
138 
139 /* Internal functions *********************************************************/
140 
141 /* dcobjs.c */
142 
143 VOID FASTCALL DC_vUpdateFillBrush(PDC pdc);
144 VOID FASTCALL DC_vUpdateLineBrush(PDC pdc);
145 VOID FASTCALL DC_vUpdateTextBrush(PDC pdc);
146 VOID FASTCALL DC_vUpdateBackgroundBrush(PDC pdc);
147 
148 HFONT
149 NTAPI
150 DC_hSelectFont(
151     _In_ PDC pdc,
152     _In_ HFONT hlfntNew);
153 
154 HPALETTE
155 NTAPI
156 GdiSelectPalette(
157     _In_ HDC hDC,
158     _In_ HPALETTE hpal,
159     _In_ BOOL ForceBackground);
160 
161 /* dcutil.c */
162 
163 COLORREF
164 FASTCALL
165 IntGdiSetBkColor(
166     _In_ HDC hDC,
167     _In_ COLORREF Color);
168 
169 INT FASTCALL IntGdiSetBkMode(HDC  hDC, INT  backgroundMode);
170 COLORREF FASTCALL  IntGdiSetTextColor(HDC hDC, COLORREF color);
171 UINT FASTCALL IntGdiSetTextAlign(HDC  hDC, UINT  Mode);
172 VOID FASTCALL DCU_SetDcUndeletable(HDC);
173 BOOL FASTCALL IntSetDefaultRegion(PDC);
174 ULONG TranslateCOLORREF(PDC pdc, COLORREF crColor);
175 int FASTCALL GreSetStretchBltMode(HDC hdc, int iStretchMode);
176 int FASTCALL GreGetBkMode(HDC);
177 int FASTCALL GreGetMapMode(HDC);
178 COLORREF FASTCALL GreGetTextColor(HDC);
179 COLORREF FASTCALL GreGetBkColor(HDC);
180 COLORREF FASTCALL IntSetDCBrushColor(HDC,COLORREF);
181 COLORREF FASTCALL IntSetDCPenColor(HDC,COLORREF);
182 int FASTCALL GreGetGraphicsMode(HDC);
183 BOOL FASTCALL GreSetBrushOrg(HDC,INT,INT,LPPOINT);
184 
185 INIT_FUNCTION NTSTATUS NTAPI InitDcImpl(VOID);
186 PPDEVOBJ FASTCALL IntEnumHDev(VOID);
187 PDC NTAPI DC_AllocDcWithHandle(GDILOOBJTYPE eDcObjType);
188 BOOL NTAPI DC_bAllocDcAttr(PDC pdc);
189 VOID NTAPI DC_vCleanup(PVOID ObjectBody);
190 BOOL FASTCALL IntGdiDeleteDC(HDC, BOOL);
191 
192 BOOL FASTCALL DC_InvertXform(const XFORM *xformSrc, XFORM *xformDest);
193 VOID FASTCALL DC_vUpdateViewportExt(PDC pdc);
194 VOID FASTCALL DC_vCopyState(PDC pdcSrc, PDC pdcDst, BOOL To);
195 VOID FASTCALL DC_vFinishBlit(PDC pdc1, PDC pdc2);
196 VOID FASTCALL DC_vPrepareDCsForBlit(PDC pdcDest, const RECT* rcDest, PDC pdcSrc, const RECT* rcSrc);
197 
198 VOID NTAPI DC_vRestoreDC(IN PDC pdc, INT iSaveLevel);
199 
200 VOID NTAPI DC_vFreeDcAttr(PDC pdc);
201 VOID NTAPI DC_vInitDc(PDC pdc, DCTYPE dctype, PPDEVOBJ ppdev);
202 
203 VOID FASTCALL IntGdiReferencePdev(PPDEVOBJ pPDev);
204 VOID FASTCALL IntGdiUnreferencePdev(PPDEVOBJ pPDev, DWORD CleanUpType);
205 HDC FASTCALL IntGdiCreateDisplayDC(HDEV hDev, ULONG DcType, BOOL EmptyDC);
206 BOOL FASTCALL IntGdiCleanDC(HDC hDC);
207 VOID FASTCALL IntvGetDeviceCaps(PPDEVOBJ, PDEVCAPS);
208 VOID FASTCALL IntUpdateBoundsRect(PDC,PRECTL);
209 
210 BOOL NTAPI GreSetDCOwner(HDC hdc, ULONG ulOwner);
211 HDC APIENTRY GreCreateCompatibleDC(HDC hdc, BOOL bAltDc);
212 
213 VOID
214 NTAPI
215 DC_vSetBrushOrigin(PDC pdc, LONG x, LONG y);
216 
217 FORCEINLINE
218 PDC
219 DC_LockDc(HDC hdc)
220 {
221     PDC pdc;
222 
223     pdc = (PDC)GDIOBJ_LockObject(hdc, GDIObjType_DC_TYPE);
224     if (pdc)
225     {
226         ASSERT((GDI_HANDLE_GET_TYPE(pdc->BaseObject.hHmgr) == GDILoObjType_LO_DC_TYPE) ||
227                (GDI_HANDLE_GET_TYPE(pdc->BaseObject.hHmgr) == GDILoObjType_LO_ALTDC_TYPE));
228         ASSERT(pdc->dclevel.plfnt != NULL);
229         ASSERT(GDI_HANDLE_GET_TYPE(((POBJ)pdc->dclevel.plfnt)->hHmgr) == GDILoObjType_LO_FONT_TYPE);
230     }
231 
232     return pdc;
233 }
234 
235 FORCEINLINE
236 VOID
237 DC_UnlockDc(PDC pdc)
238 {
239     ASSERT(pdc->dclevel.plfnt != NULL);
240     ASSERT(GDI_HANDLE_GET_TYPE(((POBJ)pdc->dclevel.plfnt)->hHmgr) == GDILoObjType_LO_FONT_TYPE);
241 
242     GDIOBJ_vUnlockObject(&pdc->BaseObject);
243 }
244 
245 FORCEINLINE
246 VOID
247 DC_vSelectSurface(PDC pdc, PSURFACE psurfNew)
248 {
249     PSURFACE psurfOld = pdc->dclevel.pSurface;
250     if (psurfOld)
251     {
252         psurfOld->hdc = NULL;
253         SURFACE_ShareUnlockSurface(psurfOld);
254     }
255     if (psurfNew)
256         GDIOBJ_vReferenceObjectByPointer((POBJ)psurfNew);
257     pdc->dclevel.pSurface = psurfNew;
258 }
259 
260 FORCEINLINE
261 VOID
262 DC_vSelectFillBrush(PDC pdc, PBRUSH pbrFill)
263 {
264     PBRUSH pbrFillOld = pdc->dclevel.pbrFill;
265     if (pbrFillOld)
266         BRUSH_ShareUnlockBrush(pbrFillOld);
267     if (pbrFill)
268         GDIOBJ_vReferenceObjectByPointer((POBJ)pbrFill);
269     pdc->dclevel.pbrFill = pbrFill;
270 }
271 
272 FORCEINLINE
273 VOID
274 DC_vSelectLineBrush(PDC pdc, PBRUSH pbrLine)
275 {
276     PBRUSH pbrLineOld = pdc->dclevel.pbrLine;
277     if (pbrLineOld)
278         BRUSH_ShareUnlockBrush(pbrLineOld);
279     if (pbrLine)
280         GDIOBJ_vReferenceObjectByPointer((POBJ)pbrLine);
281     pdc->dclevel.pbrLine = pbrLine;
282 }
283 
284 FORCEINLINE
285 VOID
286 DC_vSelectPalette(PDC pdc, PPALETTE ppal)
287 {
288     PPALETTE ppalOld = pdc->dclevel.ppal;
289     if (ppalOld)
290         PALETTE_ShareUnlockPalette(ppalOld);
291     if (ppal)
292         GDIOBJ_vReferenceObjectByPointer((POBJ)ppal);
293     pdc->dclevel.ppal = ppal;
294 }
295 
296 extern _Notnull_ PBRUSH pbrDefaultBrush;
297 extern _Notnull_ PSURFACE psurfDefaultBitmap;
298 
299 #define ASSERT_DC_PREPARED(pdc) NT_ASSERT((pdc)->fs & DC_PREPARED)
300 
301 #endif /* not __WIN32K_DC_H */
302