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
.left
= rclDest
.top
= 0;
160 rclDest
.right
= psoPattern
->sizlBitmap
.cx
;
161 rclDest
.bottom
= psoPattern
->sizlBitmap
.cy
;
162 EngCopyBits(psoRealize
, psoPattern
, NULL
, pxlo
, &rclDest
, &ptlSrc
);
164 /* Unlock the bitmap again */
165 EngUnlockSurface(psoRealize
);
167 pebo
= CONTAINING_RECORD(pbo
, EBRUSHOBJ
, BrushObject
);
168 pebo
->pengbrush
= (PVOID
)hbmpRealize
;
175 EBRUSHOBJ_bRealizeBrush(EBRUSHOBJ
*pebo
, BOOL bCallDriver
)
178 PFN_DrvRealizeBrush pfnRealzizeBrush
= NULL
;
179 PSURFACE psurfTrg
, psurfPattern
, psurfMask
;
180 PPDEVOBJ ppdev
= NULL
;
183 psurfTrg
= pebo
->psurfTrg
; // FIXME: all EBRUSHOBJs need a surface
186 DPRINT1("Pattern brush has no target surface!\n");
190 ppdev
= (PPDEVOBJ
)psurfTrg
->SurfObj
.hdev
; // FIXME: all SURFACEs need a PDEV
191 if (ppdev
&& bCallDriver
)
192 pfnRealzizeBrush
= ppdev
->DriverFunctions
.RealizeBrush
;
193 if (!pfnRealzizeBrush
)
195 pfnRealzizeBrush
= EngRealizeBrush
;
198 psurfPattern
= SURFACE_LockSurface(pebo
->pbrush
->hbmPattern
);
201 DPRINT1("No pattern, nothing to realize!\n");
205 /* FIXME: implement mask */
208 /* Create xlateobj for the brush */
209 pxlo
= IntCreateBrushXlate(pebo
->pbrush
, psurfTrg
, pebo
->crCurrentBack
);
211 /* Perform the realization */
212 bResult
= pfnRealzizeBrush(&pebo
->BrushObject
,
213 &pebo
->psurfTrg
->SurfObj
,
214 &psurfPattern
->SurfObj
,
215 psurfMask
? &psurfMask
->SurfObj
: NULL
,
217 -1); // FIXME: what about hatch brushes?
219 EngDeleteXlate(pxlo
);
222 SURFACE_UnlockSurface(psurfPattern
);
225 SURFACE_UnlockSurface(psurfMask
);
232 EBRUSHOBJ_pvGetEngBrush(EBRUSHOBJ
*pebo
)
236 if (!pebo
->pengbrush
)
238 bResult
= EBRUSHOBJ_bRealizeBrush(pebo
, FALSE
);
242 EngDeleteSurface(pebo
->pengbrush
);
243 pebo
->pengbrush
= NULL
;
247 return pebo
->pengbrush
;
251 /** Exported DDI functions ****************************************************/
257 BRUSHOBJ_pvAllocRbrush(
261 pbo
->pvRbrush
= EngAllocMem(0, cj
, 'rbdG');
262 return pbo
->pvRbrush
;
269 BRUSHOBJ_pvGetRbrush(
272 EBRUSHOBJ
*pebo
= CONTAINING_RECORD(pbo
, EBRUSHOBJ
, BrushObject
);
277 bResult
= EBRUSHOBJ_bRealizeBrush(pebo
, TRUE
);
282 EngFreeMem(pbo
->pvRbrush
);
283 pbo
->pvRbrush
= NULL
;
288 return pbo
->pvRbrush
;
295 BRUSHOBJ_ulGetBrushColor(
298 EBRUSHOBJ
*pebo
= CONTAINING_RECORD(pbo
, EBRUSHOBJ
, BrushObject
);
299 return pebo
->ulRGBColor
;