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.

558 lines
20 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: brush.hxx
  3. *
  4. * This contains the prototypes and constants for the brush class.
  5. *
  6. * Created: 20-May-1991 17:01:25
  7. * Author: Patrick Haluptzok patrickh
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #ifndef _BRUSH_HXX
  12. // The following flags are for the fl field of the BRUSH class
  13. //
  14. // The BR_NEED_ flags are used to flag which colors are needed for the
  15. // physical realization of the brush.
  16. #define BR_NEED_FG_CLR 0x00000001L
  17. #define BR_NEED_BK_CLR 0x00000002L
  18. #define BR_DITHER_OK 0x00000004L
  19. // The BR_IS_ flags just tell us what type of brush was created.
  20. #define BR_IS_SOLID 0x00000010L
  21. #define BR_IS_HATCH 0x00000020L
  22. #define BR_IS_BITMAP 0x00000040L
  23. #define BR_IS_DIB 0x00000080L
  24. #define BR_IS_NULL 0x00000100L
  25. #define BR_IS_GLOBAL 0x00000200L
  26. #define BR_IS_PEN 0x00000400L
  27. #define BR_IS_OLDSTYLEPEN 0x00000800L
  28. #define BR_IS_DIBPALCOLORS 0x00001000L
  29. #define BR_IS_DIBPALINDICES 0x00002000L
  30. #define BR_IS_DEFAULTSTYLE 0x00004000L
  31. #define BR_IS_MASKING 0x00008000L
  32. #define BR_IS_INSIDEFRAME 0x00010000L
  33. #define BR_IS_MONOCHROME 0x00020000L
  34. #define BR_IS_FIXEDSTOCK 0x00040000L
  35. #define BR_IS_MAKENONSTOCK 0x00080000L
  36. // This is for determining what's cached
  37. #define BR_CACHED_ENGINE 0x40000000L
  38. #define BR_CACHED_IS_SOLID 0x80000000L
  39. // define HS_HORIZONTAL 0 /* ----- */
  40. // define HS_VERTICAL 1 /* ||||| */
  41. // define HS_FDIAGONAL 2 /* \\\\\ */
  42. // define HS_BDIAGONAL 3 /* ///// */
  43. // define HS_CROSS 4 /* +++++ */
  44. // define HS_DIAGCROSS 5 /* xxxxx */
  45. // define HS_SOLIDCLR 6 Color as passed in
  46. // define HS_DITHEREDCLR 7 Color as passed in, can dither
  47. // define HS_SOLIDTEXTCLR 8 Color of foreground
  48. // define HS_DITHEREDTEXTCLR 9 Color of foreground, can dither
  49. // define HS_SOLIDBKCLR 10 Color of background
  50. // define HS_DITHEREDBKCLR 11 Color of background, can dither
  51. // define HS_API_MAX 12
  52. #define HS_NULL (HS_API_MAX)
  53. #define HS_PAT (HS_API_MAX + 1)
  54. #define HS_MSK (HS_API_MAX + 2)
  55. #define HS_PATMSK (HS_API_MAX + 3)
  56. #define HS_STYLE_MAX (HS_API_MAX + 4)
  57. // Indicates whether the realization being sought in the cache in the logical
  58. // brush is an engine or driver realization
  59. #define CR_DRIVER_REALIZATION 0
  60. #define CR_ENGINE_REALIZATION 1
  61. #ifndef GDIFLAGS_ONLY // used for gdikdx
  62. typedef struct _ICM_DIB_LIST
  63. {
  64. HANDLE hcmXform;
  65. HBITMAP hDIB;
  66. struct _ICM_DIB_LIST *pNext;
  67. }ICM_DIB_LIST,*PICM_DIB_LIST;
  68. /*********************************Class************************************\
  69. * class BRUSH
  70. *
  71. * Base class for brushes
  72. *
  73. * History:
  74. * 30-Oct-1992 -by- Michael Abrash [mikeab]
  75. * Added caching of the first realization in the logical brush.
  76. *
  77. * Mon 02-Mar-1992 -by- Patrick Haluptzok [patrickh]
  78. * Vastly simplified, remove most fields, rework logic.
  79. *
  80. * Thu 27-Jun-1991 -by- Patrick Haluptzok [patrickh]
  81. * Remove reference counting
  82. *
  83. * Fri 17-May-1991 -by- Patrick Haluptzok [patrickh]
  84. * Lot's of changes
  85. *
  86. * Sun 02-Dec-1990 21:59:00 -by- Walt Moore [waltm]
  87. * Initial version.
  88. \**************************************************************************/
  89. // A brush maintains the original information passed to the create call
  90. // necesary for physical realization.
  91. //
  92. // crColor This is the color passed to the create function.
  93. //
  94. // ulStyle This is the style of brush.
  95. //
  96. //
  97. // The following fields are required for the physical realization of the
  98. // brush, and caching those realizations.
  99. //
  100. // hsurf Either a clone of hsurfOrig, or a bitmap created with the
  101. // DIB information passed to us.
  102. //
  103. // flAttrs Various flags previously defined.
  104. class BRUSH: public OBJECT /* br */
  105. {
  106. public:
  107. // Uniqueness so a logical handle can be reused without having it look like
  108. // the same brush as before. We don't really care where this starts.
  109. static ULONG _ulGlobalBrushUnique;
  110. // Uniqueness for the current brush, to tell it apart from other brushes
  111. // when we do the are-you-really-dirty check at the start of vInitBrush.
  112. ULONG _ulStyle; // style of brush
  113. HBITMAP _hbmPattern; // cloned DIB for brush
  114. HBITMAP _hbmClient; // client handle passed in
  115. FLONG _flAttrs; // Flags as defined above
  116. ULONG _ulBrushUnique;
  117. PBRUSHATTR _pBrushattr;
  118. // ULONG AttrFlags;
  119. // COLORREF lbColor;
  120. BRUSHATTR _Brushattr;
  121. ULONG _iUsage; // iUsage brush created with
  122. PICM_DIB_LIST _pIcmDIBList; // DIB brushes only:
  123. // If ICM is enabled for a DC this
  124. // brush is selected into, then a
  125. // copy of the DIB must be made
  126. // corrected to the DCs color space.
  127. //
  128. //
  129. // Caching info (we cache the first realization in the logical brush).
  130. //
  131. BOOL _bCacheGrabbed;
  132. // FALSE if it's okay to cache a realization in
  133. // this brush, TRUE if it's too late (some other
  134. // realization has been cached or is in the
  135. // process of being cached). Must be set with
  136. // InterlockedExchange. Note that this does not
  137. // mean that the cache ID data is actually set and
  138. // ready to use yet; check for that via psoTarg1,
  139. // which is NULL until all the cache data is ready
  140. // to be used
  141. COLORREF _crFore; // foreground color when cached realization created
  142. // set to BO_NOTCACHED initially, when the logical
  143. // brush is created; set to its proper value only
  144. // after all other cache IDs have been set
  145. COLORREF _crBack; // background color when cached realization created
  146. ULONG _ulPalTime; // DC logical palette sequence # at cached creation
  147. ULONG _ulSurfTime; // surface palette sequence # when cached created
  148. ULONG_PTR _ulRealization; // if solid brush, the cached realized index;
  149. // otherwise, pointer to DBRUSH
  150. HDEV _hdevRealization; // hdev owner of DBRUSH
  151. // (if ulRealization points DBRUSH)
  152. COLORREF _crPalColor; // Quantaized color through DC palette
  153. public:
  154. // Our information for the brush.
  155. //
  156. // ICM (Image Color Matching)
  157. //
  158. BOOL bAddIcmDIB(HANDLE hcmXform,HBITMAP hDIB);
  159. VOID vDeleteIcmDIBs(VOID);
  160. HBITMAP hFindIcmDIB(HANDLE hcmXform);
  161. VOID pIcmDIBList(PICM_DIB_LIST _pidl) {_pIcmDIBList = _pidl;}
  162. PICM_DIB_LIST pIcmDIBList()
  163. {
  164. return(_pIcmDIBList);
  165. }
  166. ULONG ulGlobalBrushUnique()
  167. {
  168. return(ulGetNewUniqueness(_ulGlobalBrushUnique));
  169. }
  170. ULONG iUsage() {return(_iUsage);}
  171. VOID iUsage(ULONG ul) {_iUsage = ul;}
  172. //
  173. // kernel uniqie
  174. //
  175. ULONG ulBrushUnique() { return(_ulBrushUnique); }
  176. ULONG ulBrushUnique(ULONG ulNewUnique)
  177. {
  178. return(_ulBrushUnique = ulNewUnique);
  179. }
  180. //
  181. // user unique
  182. //
  183. BOOL bCachedIsSolid() { return(_flAttrs & BR_CACHED_IS_SOLID); }
  184. BOOL bIsEngine() { return(_flAttrs & BR_CACHED_ENGINE); }
  185. VOID vSetNotCached() { _bCacheGrabbed = FALSE; }
  186. BOOL bGrabCache()
  187. {
  188. return(InterlockedExchange((LPLONG)&_bCacheGrabbed, TRUE) == FALSE);
  189. }
  190. BOOL bCacheGrabbed() { return(_bCacheGrabbed); }
  191. COLORREF crFore() { return(_crFore); }
  192. COLORREF crBack() { return(_crBack); }
  193. ULONG ulPalTime() { return(_ulPalTime); }
  194. ULONG ulSurfTime() { return(_ulSurfTime); }
  195. ULONG_PTR ulRealization() { return(_ulRealization); }
  196. HDEV hdevRealization() { return(_hdevRealization); }
  197. COLORREF crPalColor() { return(_crPalColor); }
  198. VOID SetEngineRealization() { _flAttrs |= BR_CACHED_ENGINE; }
  199. VOID SetDriverRealization() { _flAttrs &= ~BR_CACHED_ENGINE; }
  200. VOID SetSolidRealization() { _flAttrs |= BR_CACHED_IS_SOLID; }
  201. VOID vClearSolidRealization(){ _flAttrs &= ~BR_CACHED_IS_SOLID; }
  202. BOOL bCareAboutFg() { return(_flAttrs & BR_NEED_FG_CLR); }
  203. BOOL bCareAboutBg() { return(_flAttrs & BR_NEED_BK_CLR); }
  204. //
  205. // The following fields should only be set as part of setting up the cache
  206. // fields, and there we need to know that crFore1 is set last, for
  207. // synchronization purposes; that's why we use InterlockedExchange(). Here's
  208. // the exact mechanism:
  209. // 1) When the logical brush is created, bCacheGrabbed1 is set to FALSE, and
  210. // crFore is set to BO_NOTCACHED. Threads check for a cached realization by
  211. // seeing if crFore is BO_NOTCACHED; if it is, there's no cached realization,
  212. // else it contains the foreground color, and the other cache ID fields are
  213. // all set. (Actually, they just see if crFore matches first, which can only
  214. // happen when crFore != BO_NOTCACHED.)
  215. // 2) When a thread finds crFore is BO_NOTCACHED, it realizes the brush, then
  216. // checks whether bCacheGrabbed1 is FALSE. If not, caching has already
  217. // happened. If it is FALSE, the thread attempts to grab bCacheGrabbed1 via
  218. // InterlockedExchange(). If this succeeds (bCacheGrabbed1 was still FALSE),
  219. // then the thread sets the cache ID fields, and then sets crFore to its
  220. // new, cached value last via InterlockedExchange() (so that crFore is set
  221. // after all the cache ID fields). At this point, other threads can use the
  222. // cached realization.
  223. // Note that only the first realization for any given logical brush is cached.
  224. //
  225. COLORREF crFore(COLORREF cr)
  226. {
  227. return(_crFore = cr);
  228. }
  229. COLORREF crForeLocked(COLORREF cr)
  230. {
  231. return((COLORREF)InterlockedExchange((LONG *)&_crFore, (LONG)cr));
  232. }
  233. COLORREF crBack(COLORREF cr)
  234. {
  235. return(_crBack = cr);
  236. }
  237. ULONG ulPalTime(ULONG ul)
  238. {
  239. return(_ulPalTime = ul);
  240. }
  241. ULONG ulSurfTime(ULONG ul)
  242. {
  243. return(_ulSurfTime = ul);
  244. }
  245. ULONG_PTR ulRealization(ULONG_PTR ul)
  246. {
  247. return(_ulRealization = ul);
  248. }
  249. HDEV hdevRealization(HDEV hdev)
  250. {
  251. return(_hdevRealization = hdev);
  252. }
  253. COLORREF crPalColor(COLORREF cr)
  254. {
  255. return(_crPalColor = cr);
  256. }
  257. HBRUSH hbrush() { return((HBRUSH)hGet()); }
  258. FLONG flAttrs() { return(_flAttrs); }
  259. FLONG flAttrs(FLONG flNew) { return(_flAttrs = flNew); }
  260. PBRUSHATTR pBrushattr (PBRUSHATTR p) {return(_pBrushattr = p);}
  261. PBRUSHATTR pBrushattr () {return(_pBrushattr);}
  262. HBITMAP hbmPattern() { return(_hbmPattern); }
  263. HBITMAP hbmPattern(HBITMAP hbrNew) { return((_hbmPattern = hbrNew)); }
  264. HBITMAP hbmClient() { return(_hbmClient); }
  265. HBITMAP hbmClient(HBITMAP hbrNew) { return((_hbmClient = hbrNew)); }
  266. ULONG ulStyle(ULONG ulNew) { return(_ulStyle = ulNew); }
  267. ULONG ulStyle() { return(_ulStyle); }
  268. //
  269. // crColor uses the lbcolor in the Brushattr part of this structure
  270. // because (hungapp) calls this routine from a different process than
  271. // the brush was created in and this cannot reference user-mode
  272. // fields. Brushattr is kept up to date by SetSolidColor(Light)
  273. //
  274. ULONG crColor() { return((ULONG)(_Brushattr.lbColor)); }
  275. COLORREF crColor(COLORREF crNew) { return(_Brushattr.lbColor = (COLORREF)crNew); }
  276. ULONG AttrFlags(ULONG ul) {return(_pBrushattr->AttrFlags=ul);}
  277. ULONG AttrFlags() {return(_pBrushattr->AttrFlags);}
  278. BOOL bIsPen() { return(_flAttrs & BR_IS_PEN); }
  279. BOOL bIsNull() { return(_flAttrs & BR_IS_NULL); }
  280. BOOL bIsGlobal() { return(_flAttrs & BR_IS_GLOBAL); }
  281. BOOL bPalColors() { return(_flAttrs & BR_IS_DIBPALCOLORS); }
  282. BOOL bPalIndices() { return(_flAttrs & BR_IS_DIBPALINDICES); }
  283. BOOL bNeedFore() { return(_flAttrs & BR_NEED_FG_CLR); }
  284. BOOL bNeedBack() { return(_flAttrs & BR_NEED_BK_CLR); }
  285. BOOL bIsMasking() { return(_flAttrs & BR_IS_MASKING); }
  286. BOOL bCanDither() { return(_flAttrs & BR_DITHER_OK); }
  287. BOOL bIsFixedStock() { return(_flAttrs & BR_IS_FIXEDSTOCK); }
  288. BOOL bIsMakeNonStock() { return(_flAttrs & BR_IS_MAKENONSTOCK); }
  289. VOID vEnableDither() { _flAttrs |= BR_DITHER_OK; }
  290. VOID vDisableDither() { _flAttrs &= ~BR_DITHER_OK; }
  291. VOID vSetMakeNonStock() { _flAttrs |= BR_IS_MAKENONSTOCK; }
  292. VOID vClearMakeNonStock(){ _flAttrs &= ~BR_IS_MAKENONSTOCK; }
  293. };
  294. //
  295. // This value is never a valid value for crFore1, so we use it to indicate
  296. // whether the cached data is valid yet, as described above.
  297. //
  298. #define BO_NOTCACHED ((COLORREF)-1)
  299. /*********************************Class************************************\
  300. * class PEN
  301. *
  302. * Base class for pens.
  303. *
  304. * History:
  305. * 3-Feb-1992 -by- J. Andrew Goossen [andrewgo]
  306. * Wrote it.
  307. \**************************************************************************/
  308. class PEN: public BRUSH /* pen */
  309. {
  310. private:
  311. LONG _lWidth; // Width passed in at API
  312. FLOATL _l_eWidth; // Width for geometric lines
  313. FLONG _flStylePen; // Pen style passed in at API
  314. PFLOAT_LONG _pstyle; // Pointer to style array
  315. ULONG _cstyle; // Size of style array
  316. BYTE _iJoin; // Join style for geometric lines
  317. BYTE _iEndCap; // End cap style for geometric lines
  318. LONG _lBrushStyle; // lbstyle
  319. ULONG_PTR _lHatch; // lbHatch
  320. public:
  321. //
  322. // Pen attributes:
  323. //
  324. PFLOAT_LONG pstyle() { return(_pstyle); }
  325. ULONG cstyle() { return(_cstyle); }
  326. LONG lWidthPen() { return(_lWidth); }
  327. FLOATL l_eWidthPen() { return(_l_eWidth); }
  328. ULONG iEndCap() { return((ULONG) _iEndCap); }
  329. ULONG iJoin() { return((ULONG) _iJoin); }
  330. FLONG flStylePen() { return(_flStylePen); }
  331. BOOL bIsGeometric() { return((_flStylePen & PS_TYPE_MASK) ==
  332. PS_GEOMETRIC); }
  333. BOOL bIsCosmetic() { return((_flStylePen & PS_TYPE_MASK) ==
  334. PS_COSMETIC); }
  335. BOOL bIsAlternate() { return((_flStylePen & PS_STYLE_MASK) ==
  336. PS_ALTERNATE); }
  337. BOOL bIsUserStyled() { return((_flStylePen & PS_STYLE_MASK) ==
  338. PS_USERSTYLE); }
  339. BOOL bIsInsideFrame() { return(flAttrs() & BR_IS_INSIDEFRAME); }
  340. BOOL bIsOldStylePen() { return(flAttrs() & BR_IS_OLDSTYLEPEN); }
  341. BOOL bIsDefaultStyle() { return(flAttrs() & BR_IS_DEFAULTSTYLE); }
  342. LONG lBrushStyle() { return(_lBrushStyle);}
  343. ULONG_PTR lHatch() { return(_lHatch);}
  344. // Set pen attributes:
  345. VOID vSetDefaultStyle() { flAttrs(flAttrs() | BR_IS_DEFAULTSTYLE); }
  346. VOID vSetInsideFrame() { flAttrs(flAttrs() | BR_IS_INSIDEFRAME); }
  347. VOID vSetPen() { flAttrs(flAttrs() | BR_IS_PEN); }
  348. VOID vSetOldStylePen()
  349. {
  350. flAttrs(flAttrs() | (BR_IS_OLDSTYLEPEN | BR_IS_PEN));
  351. }
  352. LONG lWidthPen(LONG l) { return(_lWidth = l); }
  353. FLOATL l_eWidthPen(FLOATL e){ return(_l_eWidth = e); }
  354. FLONG flStylePen(FLONG fl) { return(_flStylePen = fl); }
  355. ULONG iEndCap(ULONG ii) { return(_iEndCap = (BYTE) ii); }
  356. ULONG iJoin(ULONG ii) { return(_iJoin = (BYTE) ii); }
  357. ULONG cstyle(ULONG c) { return(_cstyle = c); }
  358. PFLOAT_LONG pstyle(PFLOAT_LONG pel) { return(_pstyle = pel); }
  359. LONG lBrushStyle(LONG l) { return(_lBrushStyle=l);}
  360. ULONG_PTR lHatch(ULONG_PTR l) { return(_lHatch=l);}
  361. };
  362. typedef BRUSH *PBRUSH;
  363. typedef PEN *PPEN;
  364. typedef union _PBRUSHPEN /* pbp */
  365. {
  366. BRUSH *pbr;
  367. PEN *ppen;
  368. } PBRUSHPEN;
  369. #define PBRUSHNULL ((PBRUSH) NULL)
  370. BOOL bDeleteBrush(HBRUSH,BOOL);
  371. BOOL bSyncBrushObj(
  372. PBRUSH pbrush);
  373. //
  374. // foreward reference
  375. //
  376. class DC;
  377. typedef DC *PDC;
  378. BOOL GreSetSolidBrushInternal(HBRUSH,COLORREF,BOOL,BOOL);
  379. BOOL GreSetSolidBrushLight(PBRUSH,COLORREF,BOOL);
  380. HBRUSH GreDCSelectBrush(PDC,HBRUSH);
  381. HPEN GreDCSelectPen(PDC,HPEN);
  382. BOOL bSyncDCBrush (PDC pdc);
  383. BOOL bSyncBrush(HBRUSH hbr);
  384. /*********************************Class************************************\
  385. * class RBRUSH
  386. *
  387. * Base class for brush realizations.
  388. * This is the class that ENGBRUSH and DBRUSH are derived from; this is so we
  389. * can access the reference count field without knowing with which type of
  390. * brush realization we're dealing
  391. *
  392. * History:
  393. * 1-Nov-1993 -by- Michael Abrash [mikeab]
  394. * Wrote it.
  395. \**************************************************************************/
  396. // RBRUSH type: engine or driver
  397. typedef enum {
  398. RB_DRIVER = 0,
  399. RB_ENGINE
  400. } RBTYPE;
  401. // Forward reference
  402. class RBRUSH;
  403. typedef RBRUSH *PRBRUSH;
  404. // Global pointer to the last DBRUSH and ENGBRUSH freed, if any (for one-deep
  405. // caching).
  406. extern PRBRUSH gpCachedDbrush;
  407. extern PRBRUSH gpCachedEngbrush;
  408. class RBRUSH
  409. {
  410. private:
  411. LONG cRef1; // # of places this realization is in use (when this goes
  412. // to 0, the realization is deleted, because at that point
  413. // it is no longer selected into any DC, and the logical
  414. // brush it's cached in, if any, has been deleted)
  415. ULONG ulSize; // # of bytes allocated for the realization in this brush
  416. BOOL _bMultiBrush; // was this realization created by the DDML?
  417. BOOL _bUMPDRBrush; // is this a realization created by user mode printer driver?
  418. public:
  419. LONG cRef(const LONG lval) { return(cRef1 = lval); }
  420. // The following bMultiBrush() methods are only valid for DBRUSHES
  421. BOOL bMultiBrush() { return(_bMultiBrush); }
  422. BOOL bMultiBrush(BOOL bval) { return(_bMultiBrush = bval); }
  423. BOOL bUMPDRBrush() { return(_bUMPDRBrush); }
  424. BOOL bUMPDRBrush(BOOL bval) { return(_bUMPDRBrush = bval); }
  425. ULONG ulSizeGet() { return(ulSize); }
  426. ULONG ulSizeSet(const ULONG ulNewSize)
  427. {
  428. return(ulSize = ulNewSize);
  429. }
  430. VOID vAddRef() { InterlockedIncrement((LPLONG)&cRef1); }
  431. VOID vFreeOrCacheRBrush(RBTYPE rbtype);
  432. VOID vRemoveRef(RBTYPE rbtype)
  433. {
  434. #if DBG
  435. LONG l;
  436. if ((l = InterlockedDecrement((LPLONG)&cRef1)) == 0)
  437. #else
  438. if (InterlockedDecrement((LPLONG)&cRef1) == 0)
  439. #endif
  440. {
  441. vFreeOrCacheRBrush(rbtype);
  442. }
  443. #if DBG
  444. ASSERTGDI(l >= 0, "ERROR brush realization reference counted < 0");
  445. #endif
  446. }
  447. };
  448. class ENGBRUSH : public RBRUSH
  449. {
  450. public:
  451. ULONG cxPatR; // Realized width of pattern
  452. ULONG cxPat; // Actual width of pattern
  453. ULONG cyPat; // Actual height of pattern
  454. LONG lDeltaPat; // Offset to next scan of pattern
  455. PBYTE pjPat; // Pointer to pattern data
  456. ULONG cxMskR; // Realized width of mask
  457. ULONG cxMsk; // Actual width of mask
  458. ULONG cyMsk; // Actual height of mask
  459. PBYTE pjMsk; // Offset to next scan of mask
  460. LONG lDeltaMsk; // Pointer to mask data
  461. ULONG iColorBack; // Background color
  462. ULONG iDitherFormat; // Bitmap color depth
  463. // Not so public
  464. BYTE aj[4];
  465. };
  466. typedef ENGBRUSH *PENGBRUSH;
  467. #endif // GDIFLAGS_ONLY used for gdikdx
  468. #define _BRUSH_HXX
  469. #endif