2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI Driver Brush Functions
5 * FILE: subsystem/win32/win32k/eng/engbrush.c
6 * PROGRAMER: Jason Filby
15 /** Internal functions ********************************************************/
19 EBRUSHOBJ_vInit(EBRUSHOBJ
*pebo
, PBRUSH pbrush
, PDC pdc
)
29 psurfTrg
= pdc
->dclevel
.pSurface
;
31 pebo
->psurfTrg
= psurfTrg
;
32 pebo
->BrushObject
.flColorType
= 0;
33 pebo
->pbrush
= pbrush
;
34 pebo
->flattrs
= pbrush
->flAttrs
;
35 pebo
->crCurrentText
= pdc
->pdcattr
->crForegroundClr
;
36 pebo
->crCurrentBack
= pdc
->pdcattr
->crBackgroundClr
;
37 pebo
->BrushObject
.pvRbrush
= NULL
;
38 pebo
->pengbrush
= NULL
;
40 if (pbrush
->flAttrs
& GDIBRUSH_IS_NULL
)
42 pebo
->BrushObject
.iSolidColor
= 0;
44 else if (pbrush
->flAttrs
& GDIBRUSH_IS_SOLID
)
46 /* Set the RGB color */
47 pebo
->crRealize
= pbrush
->BrushAttr
.lbColor
;
48 pebo
->ulRGBColor
= pbrush
->BrushAttr
.lbColor
;
50 /* Translate the brush color to the target format */
51 pxlo
= IntCreateBrushXlate(pbrush
, psurfTrg
, pebo
->crCurrentBack
);
52 iSolidColor
= XLATEOBJ_iXlate(pxlo
, pbrush
->BrushAttr
.lbColor
);
53 pebo
->BrushObject
.iSolidColor
= iSolidColor
;
59 /* This is a pattern brush that needs realization */
60 pebo
->BrushObject
.iSolidColor
= 0xFFFFFFFF;
66 EBRUSHOBJ_vSetSolidBrushColor(EBRUSHOBJ
*pebo
, COLORREF crColor
, XLATEOBJ
*pxlo
)
70 /* Never use with non-solid brushes */
71 ASSERT(pebo
->flattrs
& GDIBRUSH_IS_SOLID
);
73 /* Set the RGB color */
74 pebo
->crRealize
= crColor
;
75 pebo
->ulRGBColor
= crColor
;
77 /* Translate the brush color to the target format */
78 iSolidColor
= XLATEOBJ_iXlate(pxlo
, crColor
);
79 pebo
->BrushObject
.iSolidColor
= iSolidColor
;
81 pebo
->BrushObject
.iSolidColor
= iSolidColor
;
86 EBRUSHOBJ_vCleanup(EBRUSHOBJ
*pebo
)
88 /* Check if there's a GDI realisation */
91 EngDeleteSurface(pebo
->pengbrush
);
92 pebo
->pengbrush
= NULL
;
95 /* Check if there's a driver's realisation */
96 if (pebo
->BrushObject
.pvRbrush
)
98 /* Free allocated driver memory */
99 EngFreeMem(pebo
->BrushObject
.pvRbrush
);
100 pebo
->BrushObject
.pvRbrush
= NULL
;
106 EBRUSHOBJ_vUpdate(EBRUSHOBJ
*pebo
, PBRUSH pbrush
, PDC pdc
)
108 /* Cleanup the brush */
109 EBRUSHOBJ_vCleanup(pebo
);
112 EBRUSHOBJ_vInit(pebo
, pbrush
, pdc
);
116 * This function is not exported, because it makes no sense for
117 * The driver to punt back to this function */
131 POINTL ptlSrc
= {0, 0};
135 /* Calculate width in bytes of the realized brush */
136 lWidth
= DIB_GetDIBWidthBytes(psoPattern
->sizlBitmap
.cx
,
137 BitsPerFormat(psoDst
->iBitmapFormat
));
139 /* Allocate a bitmap */
140 hbmpRealize
= EngCreateBitmap(psoPattern
->sizlBitmap
,
142 psoDst
->iBitmapFormat
,
150 /* Lock the bitmap */
151 psoRealize
= EngLockSurface(hbmpRealize
);
154 EngDeleteSurface(hbmpRealize
);
158 /* Copy the bits to the new format bitmap */
159 rclDest
= (RECTL
){0, 0, psoPattern
->sizlBitmap
.cx
, psoPattern
->sizlBitmap
.cy
};
160 EngCopyBits(psoRealize
, psoPattern
, NULL
, pxlo
, &rclDest
, &ptlSrc
);
162 /* Unlock the bitmap again */
163 EngUnlockSurface(psoRealize
);
165 pebo
= CONTAINING_RECORD(pbo
, EBRUSHOBJ
, BrushObject
);
166 pebo
->pengbrush
= (PVOID
)hbmpRealize
;
173 EBRUSHOBJ_bRealizeBrush(EBRUSHOBJ
*pebo
, BOOL bCallDriver
)
176 PFN_DrvRealizeBrush pfnRealzizeBrush
= NULL
;
177 PSURFACE psurfTrg
, psurfPattern
, psurfMask
;
178 PPDEVOBJ ppdev
= NULL
;
181 psurfTrg
= pebo
->psurfTrg
; // FIXME: all EBRUSHOBJs need a surface
184 DPRINT1("Pattern brush has no target surface!\n");
188 ppdev
= (PPDEVOBJ
)psurfTrg
->SurfObj
.hdev
; // FIXME: all SURFACEs need a PDEV
189 if (ppdev
&& bCallDriver
)
190 pfnRealzizeBrush
= ppdev
->DriverFunctions
.RealizeBrush
;
191 if (!pfnRealzizeBrush
)
193 pfnRealzizeBrush
= EngRealizeBrush
;
196 psurfPattern
= SURFACE_LockSurface(pebo
->pbrush
->hbmPattern
);
199 DPRINT1("No pattern, nothing to realize!\n");
203 /* FIXME: implement mask */
206 /* Create xlateobj for the brush */
207 pxlo
= IntCreateBrushXlate(pebo
->pbrush
, psurfTrg
, pebo
->crCurrentBack
);
209 /* Perform the realization */
210 bResult
= pfnRealzizeBrush(&pebo
->BrushObject
,
211 &pebo
->psurfTrg
->SurfObj
,
212 &psurfPattern
->SurfObj
,
213 psurfMask
? &psurfMask
->SurfObj
: NULL
,
215 -1); // FIXME: what about hatch brushes?
217 EngDeleteXlate(pxlo
);
220 SURFACE_UnlockSurface(psurfPattern
);
223 SURFACE_UnlockSurface(psurfMask
);
230 EBRUSHOBJ_pvGetEngBrush(EBRUSHOBJ
*pebo
)
234 if (!pebo
->pengbrush
)
236 bResult
= EBRUSHOBJ_bRealizeBrush(pebo
, FALSE
);
240 EngDeleteSurface(pebo
->pengbrush
);
241 pebo
->pengbrush
= NULL
;
245 return pebo
->pengbrush
;
249 /** Exported DDI functions ****************************************************/
255 BRUSHOBJ_pvAllocRbrush(
259 pbo
->pvRbrush
= EngAllocMem(0, cj
, 'rbdG');
260 return pbo
->pvRbrush
;
267 BRUSHOBJ_pvGetRbrush(
270 EBRUSHOBJ
*pebo
= CONTAINING_RECORD(pbo
, EBRUSHOBJ
, BrushObject
);
275 bResult
= EBRUSHOBJ_bRealizeBrush(pebo
, TRUE
);
280 EngFreeMem(pbo
->pvRbrush
);
281 pbo
->pvRbrush
= NULL
;
286 return pbo
->pvRbrush
;
293 BRUSHOBJ_ulGetBrushColor(
296 EBRUSHOBJ
*pebo
= CONTAINING_RECORD(pbo
, EBRUSHOBJ
, BrushObject
);
297 return pebo
->ulRGBColor
;