Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

440 lines
16 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: brushobj.hxx
  3. *
  4. * Creates physical realizations of logical brushes.
  5. *
  6. * Created: 07-Dec-1990 13:14:23
  7. * Author: waltm moore [waltm]
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #ifndef _BRUSHOBJ_HXX
  12. //
  13. // Forward reference to needed classes
  14. //
  15. class EBRUSHOBJ;
  16. /******************************Class***************************************\
  17. * XEBRUSHOBJ
  18. *
  19. * Basic Pen/Brush User Object.
  20. *
  21. * History:
  22. * 8-Sep-1992 -by- Paul Butzi
  23. * Changed the basic hierarchy to something sensible.
  24. *
  25. * Wed 3-Feb-1992 -by- J. Andrew Goossen [andrewgo]
  26. * added extended pen support.
  27. *
  28. * 22-Feb-1992 -by- Patrick Haluptzok patrickh
  29. * Wrote it.
  30. \**************************************************************************/
  31. class XEBRUSHOBJ
  32. {
  33. protected:
  34. PBRUSHPEN pbp; // Pointer to the logical brush
  35. public:
  36. XEBRUSHOBJ() {}
  37. ~XEBRUSHOBJ() {}
  38. PBRUSH pbrush() { return(pbp.pbr); }
  39. HBRUSH hbrush() { return((HBRUSH)pbp.pbr->hGet()); }
  40. BOOL bValid() { return(pbp.pbr != PBRUSHNULL); }
  41. HBITMAP hbmPattern() { return(pbp.pbr->hbmPattern()); }
  42. HBITMAP hbmClient() { return(pbp.pbr->hbmClient()); }
  43. FLONG flAttrs() { return(pbp.pbr->flAttrs()); }
  44. ULONG ulStyle() { return(pbp.pbr->ulStyle()); }
  45. ULONG crColor() { return(pbp.pbr->crColor()); }
  46. COLORREF clrPen() { return(pbp.pbr->crColor()); }
  47. BOOL bIsPen() { return(pbp.pbr->bIsPen()); }
  48. BOOL bIsNull() { return(pbp.pbr->bIsNull()); }
  49. BOOL bIsGlobal() { return(pbp.pbr->bIsGlobal()); }
  50. BOOL bPalColors() { return(pbp.pbr->bPalColors()); }
  51. BOOL bPalIndices() { return(pbp.pbr->bPalIndices()); }
  52. BOOL bNeedFore() { return(pbp.pbr->bNeedFore()); }
  53. BOOL bNeedBack() { return(pbp.pbr->bNeedBack()); }
  54. BOOL bIsMasking() { return(pbp.pbr->bIsMasking()); }
  55. BOOL bCanDither() { return(pbp.pbr->bCanDither()); }
  56. VOID vEnableDither() { pbp.pbr->vEnableDither(); }
  57. VOID vDisableDither() { pbp.pbr->vDisableDither(); }
  58. ULONG iUsage() {return(pbp.pbr->iUsage());}
  59. VOID iUsage(ULONG ul) {pbp.pbr->iUsage(ul);}
  60. // Pen attributes:
  61. PFLOAT_LONG pstyle() { return(pbp.ppen->pstyle()); }
  62. ULONG cstyle() { return(pbp.ppen->cstyle()); }
  63. LONG lWidthPen() { return(pbp.ppen->lWidthPen()); }
  64. FLOATL l_eWidthPen() { return(pbp.ppen->l_eWidthPen()); }
  65. ULONG iEndCap() { return((ULONG) pbp.ppen->iEndCap()); }
  66. ULONG iJoin() { return((ULONG) pbp.ppen->iJoin()); }
  67. FLONG flStylePen() { return(pbp.ppen->flStylePen()); }
  68. BOOL bIsGeometric() { return(pbp.ppen->bIsGeometric()); }
  69. BOOL bIsCosmetic() { return(pbp.ppen->bIsCosmetic()); }
  70. BOOL bIsAlternate() { return(pbp.ppen->bIsAlternate()); }
  71. BOOL bIsUserStyled() { return(pbp.ppen->bIsUserStyled()); }
  72. BOOL bIsInsideFrame() { return(pbp.ppen->bIsInsideFrame()); }
  73. BOOL bIsOldStylePen() { return(pbp.ppen->bIsOldStylePen()); }
  74. BOOL bIsDefaultStyle() { return(pbp.ppen->bIsDefaultStyle()); }
  75. LONG lBrushStyle() { return(pbp.ppen->lBrushStyle());}
  76. ULONG_PTR lHatch() { return(pbp.ppen->lHatch());}
  77. // Set pen attributes:
  78. VOID vSetDefaultStyle() { pbp.ppen->vSetDefaultStyle(); }
  79. VOID vSetInsideFrame() { pbp.ppen->vSetInsideFrame(); }
  80. VOID vSetPen() { pbp.ppen->vSetPen(); }
  81. VOID vSetOldStylePen() { pbp.ppen->vSetOldStylePen(); }
  82. LONG lWidthPen(LONG l) { return(pbp.ppen->lWidthPen(l)); }
  83. FLOATL l_eWidthPen(FLOATL e){ return(pbp.ppen->l_eWidthPen(e)); }
  84. FLONG flStylePen(FLONG fl) { return(pbp.ppen->flStylePen(fl)); }
  85. ULONG iEndCap(ULONG ii) { return(pbp.ppen->iEndCap(ii)); }
  86. ULONG iJoin(ULONG ii) { return(pbp.ppen->iJoin(ii)); }
  87. ULONG cstyle(ULONG c) { return(pbp.ppen->cstyle(c)); }
  88. PFLOAT_LONG pstyle(PFLOAT_LONG pel) { return(pbp.ppen->pstyle(pel)); }
  89. LONG lBrushStyle (LONG l) {return(pbp.ppen->lBrushStyle(l));}
  90. ULONG_PTR lHatch (ULONG_PTR l) {return(pbp.ppen->lHatch(l));}
  91. };
  92. /******************************Class***************************************\
  93. * EBRUSHOBJ
  94. *
  95. * Finds/creates a physical realization of the given logical brush.
  96. *
  97. * History:
  98. * 8-Sep-1992 -by- Paul Butzi
  99. * Changed the basic hierarchy to something sensible.
  100. *
  101. * Wed 3-Feb-1992 -by- J. Andrew Goossen [andrewgo]
  102. * added extended pen support.
  103. *
  104. * 22-Feb-1992 -by- Patrick Haluptzok patrickh
  105. * Wrote it.
  106. \**************************************************************************/
  107. class BBRUSHOBJ : public _BRUSHOBJ /* bbo */
  108. {
  109. protected:
  110. COLORREF crRealize; // Desired Color to use in Realized brush.
  111. COLORREF crPaletteColor; // Quantaized Color after through the DC palette.
  112. public:
  113. BBRUSHOBJ() {
  114. pvRbrush = (PVOID) NULL;
  115. flColorType = 0;
  116. crPaletteColor = 0xffffffff;
  117. }
  118. COLORREF crRealized() { return(crRealize); }
  119. COLORREF crRealized(COLORREF clr) { return(crRealize = clr); }
  120. COLORREF crDCPalColor() { return(crPaletteColor); }
  121. COLORREF crDCPalColor(COLORREF clr) { return(crPaletteColor = clr); }
  122. };
  123. class EBRUSHOBJ : public BBRUSHOBJ /* ebo */
  124. {
  125. protected:
  126. // The following fields are required to realize the brush. We have to
  127. // keep pointers to the passed in objects in case we have to
  128. // realize and cache the brush when the driver calls us.
  129. PENGBRUSH pengbrush1; // pointer to engine's realization
  130. ULONG _ulSurfPalTime; // Surface palette time realization is for.
  131. ULONG _ulDCPalTime; // DC palette time realization is for.
  132. COLORREF crCurrentText1; // Current Text Color of Dest.
  133. COLORREF crCurrentBack1; // Current Background Color of Dest.
  134. COLORADJUSTMENT *pca; // Color adjustment for halftone brushes.
  135. HANDLE _hcmXform; // ICM transform handle
  136. LONG _lIcmMode; // ICM Mode from DC
  137. // The following fields are taken from the passed SURFOBJ, and DCOBJ.
  138. // We could keep pointers to those objects but we really don't want to do that
  139. // at this time
  140. SURFACE *psoTarg1; // Target surface
  141. XEPALOBJ palSurf1; // Target surface's palette
  142. XEPALOBJ palDC1; // Target DC's palette
  143. XEPALOBJ palMeta1; // Meta surface's palette
  144. ULONG _iMetaFormat; // Meta surface's dither format
  145. // In multi monitor system, Meta surface is not
  146. // same as target surface. Target surface (psoTarg1)
  147. // will be related with real target device in DDML.
  148. // Logical brush associated with this ebrushobj
  149. PBRUSH _pbrush;
  150. // useful fields cached from logical brush
  151. FLONG flAttrs; // flags
  152. ULONG _ulUnique; // brush uniqueness
  153. BOOL _bCanDither;
  154. // cache of original solid color before icm color translation
  155. COLORREF crRealizeOrignal; // set if IS_ICM_HOST(_lIcmMode)
  156. // The methods allowed for the brush object
  157. public:
  158. EBRUSHOBJ() {
  159. pengbrush1 = (PENGBRUSH) NULL;
  160. pvRbrush = (PVOID) NULL;
  161. flColorType = 0;
  162. _ulSurfPalTime = 0;
  163. _ulDCPalTime = 0;
  164. }
  165. ~EBRUSHOBJ() { vNuke(); }
  166. VOID vInit()
  167. {
  168. pengbrush1 = (PENGBRUSH) NULL;
  169. pvRbrush = (PVOID) NULL;
  170. flColorType = 0;
  171. }
  172. VOID vNuke();
  173. VOID vInitBrush(PDC,PBRUSH, XEPALOBJ, XEPALOBJ, SURFACE*, BOOL = TRUE);
  174. VOID EBRUSHOBJ::vInitBrushSolidColor(PBRUSH,
  175. COLORREF,
  176. XEPALOBJ,
  177. XEPALOBJ,
  178. SURFACE *,
  179. BOOL = TRUE);
  180. ULONG ulSurfPalTime() { return(_ulSurfPalTime); }
  181. ULONG ulDCPalTime() { return(_ulDCPalTime); }
  182. ULONG ulSurfPalTime(ULONG ul) { return(_ulSurfPalTime = ul); }
  183. ULONG ulDCPalTime(ULONG ul) { return(_ulDCPalTime = ul); }
  184. ULONG ulUnique() { return(_ulUnique); }
  185. VOID vInvalidateUniqueness() { _ulUnique--; }
  186. SURFACE *psoTarg() { return((SURFACE *) psoTarg1); }
  187. SURFACE *psoTarg(SURFACE *pSurf) { return(psoTarg1 = pSurf);}
  188. XEPALOBJ palSurf() { return(palSurf1); }
  189. XEPALOBJ palSurf(XEPALOBJ ppal) { return(palSurf1 = ppal); }
  190. XEPALOBJ palDC() { return(palDC1); }
  191. XEPALOBJ palMeta() { return(palMeta1); }
  192. ULONG iMetaFormat() { return(_iMetaFormat); }
  193. PENGBRUSH pengbrush() { return(pengbrush1); }
  194. PENGBRUSH pengbrush(PENGBRUSH peng) { return(pengbrush1 = peng); }
  195. COLORREF crCurrentText() { return(crCurrentText1); }
  196. COLORREF crCurrentBack() { return(crCurrentBack1); }
  197. COLORREF crOrignal() { return(IS_ICM_HOST(_lIcmMode) ?
  198. crRealizeOrignal : crRealize); }
  199. COLORADJUSTMENT *pColorAdjustment() { return(pca); }
  200. VOID pColorAdjustment(COLORADJUSTMENT *pca_)
  201. {
  202. pca = pca_;
  203. }
  204. // MIX mixBest(jROP2, jBkMode) computes the correct mix mode to
  205. // be passed down to the driver, based on the DC's current ROP2 and
  206. // BkMode setting.
  207. //
  208. // Only when the brush is a hatched brush, and the background mode
  209. // is transparent, should the foreground mix (low byte of the mix)
  210. // ever be different from the background mix (next byte of the mix),
  211. // otherwise the call will inevitably get punted to the BltLinker/
  212. // Stinker, which will do more work than it needs to:
  213. MIX mixBest(BYTE jROP2, BYTE jBkMode)
  214. {
  215. // jROP2 is pulled from the DC's shared attribute cache, which
  216. // since it's mapped writable into the application's address
  217. // space, can be overwritten by the application. Consequently,
  218. // we must do some validation here to ensure that we don't give
  219. // the driver a bogus MIX value. This is required because many
  220. // drivers do table look-ups based on the value.
  221. jROP2 = ((jROP2 - 1) & 0xf) + 1;
  222. // Note that this method can only be applied to a true EBRUSHOBJ
  223. // that has flAttrs set (as opposed to a BRUSHOBJ constructued
  224. // on the stack, for example):
  225. if ((jBkMode == TRANSPARENT) &&
  226. (flAttrs & BR_IS_MASKING))
  227. {
  228. return(((MIX) R2_NOP << 8) | jROP2);
  229. }
  230. else
  231. {
  232. return(((MIX) jROP2 << 8) | jROP2);
  233. }
  234. }
  235. BOOL bIsNull() { return(flAttrs & BR_IS_NULL); }
  236. PBRUSH pbrush() { return _pbrush; }
  237. BOOL bIsInsideFrame() { return(flAttrs & BR_IS_INSIDEFRAME); }
  238. BOOL bIsOldStylePen() { return(flAttrs & BR_IS_OLDSTYLEPEN); }
  239. BOOL bIsDefaultStyle() { return(flAttrs & BR_IS_DEFAULTSTYLE); }
  240. BOOL bIsSolid() { return(flAttrs & BR_IS_SOLID); }
  241. BOOL bIsMasking() { return(flAttrs & BR_IS_MASKING); }
  242. BOOL bIsMonochrome() { return(flAttrs & BR_IS_MONOCHROME); }
  243. BOOL bCareAboutFg() { return(flAttrs & BR_NEED_FG_CLR); }
  244. BOOL bCareAboutBg() { return(flAttrs & BR_NEED_BK_CLR); }
  245. HANDLE hcmXform() { return(_hcmXform); }
  246. VOID hcmXform(HANDLE h) { _hcmXform = h; }
  247. LONG lIcmMode() { return(_lIcmMode); }
  248. VOID lIcmMode(LONG l) { _lIcmMode = l; }
  249. BOOL bIsAppsICM() { return(IS_ICM_OUTSIDEDC(_lIcmMode)); }
  250. BOOL bIsHostICM() { return(IS_ICM_HOST(_lIcmMode)); }
  251. BOOL bIsDeviceICM() { return(IS_ICM_DEVICE(_lIcmMode)); }
  252. BOOL bIsCMYKColor()
  253. {
  254. return(bIsHostICM() &&
  255. (_hcmXform != NULL) &&
  256. (IS_CMYK_COLOR(_lIcmMode)));
  257. }
  258. BOOL bDeviceCalibrate() { return(IS_ICM_DEVICE_CALIBRATE(_lIcmMode)); }
  259. };
  260. /*********************************Class************************************\
  261. * BRUSHSELOBJ
  262. *
  263. * Class used for selecting, saving, restoring logical brushes in a DC.
  264. *
  265. * History:
  266. * 22-Feb-1992 -by- Patrick Haluptzok patrickh
  267. * Derive it off XEBRUSHOBJ.
  268. \**************************************************************************/
  269. class BRUSHSELOBJ : public XEBRUSHOBJ /* bso */
  270. {
  271. public:
  272. BRUSHSELOBJ(HBRUSH hbrush)
  273. {
  274. pbp.pbr = (BRUSH *)HmgShareCheckLock((HOBJ)hbrush, BRUSH_TYPE);
  275. }
  276. ~BRUSHSELOBJ()
  277. {
  278. if (pbp.pbr != PBRUSHNULL)
  279. {
  280. DEC_SHARE_REF_CNT(pbp.pbr);
  281. }
  282. }
  283. VOID vAltCheckLock(HBRUSH hbrush)
  284. {
  285. pbp.pbr = (BRUSH *)HmgShareCheckLock((HOBJ)hbrush, BRUSH_TYPE);
  286. }
  287. BOOL bReset(COLORREF cr, BOOL bPen);
  288. VOID vGlobal()
  289. {
  290. pbp.pbr->flAttrs(pbp.pbr->flAttrs() | BR_IS_GLOBAL | BR_IS_FIXEDSTOCK);
  291. }
  292. };
  293. /*********************************Class************************************\
  294. * BRUSHSELOBJAPI
  295. *
  296. * Class used for holding logical brushes from the API level.
  297. * We take an exclusive lock to prevent other threads from calling this
  298. * API.
  299. * History:
  300. * 05-Dec-2000 -by- Pravin Santiago pravins
  301. * Derive it off XEBRUSHOBJ.
  302. \**************************************************************************/
  303. class BRUSHSELOBJAPI : public XEBRUSHOBJ /* bso */
  304. {
  305. public:
  306. BRUSHSELOBJAPI(HBRUSH hbrush)
  307. {
  308. pbp.pbr = (BRUSH *)HmgLock((HOBJ)hbrush, BRUSH_TYPE);
  309. }
  310. ~BRUSHSELOBJAPI()
  311. {
  312. if (pbp.pbr != PBRUSHNULL)
  313. {
  314. DEC_EXCLUSIVE_REF_CNT(pbp.pbr);
  315. }
  316. }
  317. };
  318. /*********************************Class************************************\
  319. * BRUSHMEMOBJ
  320. *
  321. * Allocates RAM for a logical brush.
  322. *
  323. * History:
  324. * Wed 3-Feb-1992 -by- J. Andrew Goossen [andrewgo]
  325. * added extended pen support.
  326. *
  327. * Tue 21-May-1991 -by- Patrick Haluptzok [patrickh]
  328. * lot's of changes, additions.
  329. *
  330. * Wed 05-Dec-1990 18:02:17 -by- Walt Moore [waltm]
  331. * Added this nifty comment block for initial version.
  332. \**************************************************************************/
  333. class BRUSHMEMOBJ : public XEBRUSHOBJ /* brmo */
  334. {
  335. private:
  336. BOOL bKeep; // Keep object
  337. PBRUSH pbrAllocBrush(BOOL); // Allocates actual brush memory
  338. public:
  339. // Various constructors for the different type brushes
  340. BRUSHMEMOBJ() {pbp.pbr = (PBRUSH) NULL; bKeep = FALSE;}
  341. BRUSHMEMOBJ(COLORREF, ULONG, BOOL, BOOL);
  342. BRUSHMEMOBJ(HBITMAP hbmClone, HBITMAP hbmClient, BOOL bMono, FLONG flDIB, FLONG flType, BOOL bPen);
  343. ~BRUSHMEMOBJ()
  344. {
  345. if (pbp.pbr != PBRUSHNULL)
  346. {
  347. DEC_SHARE_REF_CNT(pbp.pbr);
  348. //
  349. // We always unlock it and then delete it if it's not a keeper.
  350. // This is so we clean up any cloned bitmaps or cached brushes.
  351. //
  352. if (!bKeep)
  353. bDeleteBrush(hbrush(),FALSE);
  354. pbp.pbr = PBRUSHNULL;
  355. }
  356. return;
  357. }
  358. VOID vKeepIt() { bKeep = TRUE; }
  359. VOID vGlobal()
  360. {
  361. pbp.pbr->flAttrs(pbp.pbr->flAttrs() | BR_IS_GLOBAL | BR_IS_FIXEDSTOCK);
  362. HmgSetOwner((HOBJ)hbrush(), OBJECT_OWNER_PUBLIC, BRUSH_TYPE);
  363. HmgMarkUndeletable((HOBJ) hbrush(), BRUSH_TYPE);
  364. }
  365. };
  366. #define _BRUSHOBJ_HXX
  367. #endif