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.

589 lines
18 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: pathobj.hxx
  3. *
  4. * Path user object
  5. *
  6. * Created: 28-Sep-1990 12:39:30
  7. * Author: Paul Butzi [paulb]
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #ifndef GDIFLAGS_ONLY
  12. // Some forward declarations to reduce included header files:
  13. class RGNOBJ;
  14. class WIDEPATHOBJ;
  15. class EDGE;
  16. typedef EDGE *PEDGE;
  17. // Some useful structures for statically initializing FLOAT_LONG and
  18. // LINEATTRS structures. The regular definitions can only be initialized
  19. // with floats because C only allows union initialization using the first
  20. // union field:
  21. typedef struct _LONGLINEATTRS {
  22. FLONG fl;
  23. ULONG iJoin;
  24. ULONG iEndCap;
  25. LONG_FLOAT leWidth;
  26. FLOATL l_eMiterLimit;
  27. ULONG cstyle;
  28. LONG_FLOAT* pstyle;
  29. LONG_FLOAT leStyleState;
  30. } LONGLINEATTRS;
  31. typedef union {
  32. LONGLINEATTRS lla;
  33. LINEATTRS la;
  34. } LA;
  35. extern LA glaSimpleStroke;
  36. /*********************************Class************************************\
  37. * class PATHRECORD
  38. *
  39. * Public Interface:
  40. *
  41. * History:
  42. * 05-Sep-1990 -by- Paul Butzi [paulb]
  43. * Wrote it.
  44. \**************************************************************************/
  45. /***************************************************************************
  46. * The macro below makes sure that the next PATHRECORD lies on a good
  47. * boundary. This is only needed on some machines. For the x86 and MIPS
  48. * DWORD alignment of the structure suffices, so the macro below would only
  49. * waste RAM. (Save it for later reference.)
  50. *
  51. * #define NEXTPATHREC(ppr) (ppr + (offsetof(PATHRECORD, aptfx) + \
  52. * sizeof(POINTFIX) * ppr->count + \
  53. * sizeof(PATHRECORD) - 1) / sizeof(PATHRECORD))
  54. ***************************************************************************/
  55. #define NEXTPATHREC(ppr) ((PATHRECORD *) ((BYTE *) ppr + \
  56. offsetof(PATHRECORD,aptfx) + \
  57. sizeof(POINTFIX) * ppr->count))
  58. struct _PATHRECORD {
  59. struct _PATHRECORD *pprnext; // ptr to next pathrec in path
  60. struct _PATHRECORD *pprprev; // ptr to previous pathrec in path
  61. FLONG flags; // flags describing content of record
  62. ULONG count; // number of control points in record
  63. POINTFIX aptfx[2]; // variable length array of points
  64. // (we make it size 2 because we'll actually
  65. // be declaring this structure on the
  66. // stack to handle a LineTo, which needs
  67. // two points)
  68. };
  69. typedef struct _PATHRECORD PATHRECORD;
  70. typedef struct _PATHRECORD *PPATHREC;
  71. /*********************************Struct***********************************\
  72. * struct PATHDATAL
  73. *
  74. * Used like a PATHDATA but describes POINTLs not POINTFIXs
  75. *
  76. * History:
  77. * 08-Nov-1990 -by- Paul Butzi [paulb]
  78. * Wrote it.
  79. \**************************************************************************/
  80. struct _PATHDATAL {
  81. FLONG flags;
  82. ULONG count;
  83. PPOINTL pptl;
  84. };
  85. typedef struct _PATHDATAL PATHDATAL;
  86. typedef struct _PATHDATAL *PPATHDATAL;
  87. /*********************************Class************************************\
  88. * class PATHALLOC
  89. *
  90. * The storage for PATHRECs is allocated from the space inside PATHALLOCS.
  91. * The PATHALLOCS for a path are on a singly linked list. The two friend
  92. * functions newpathalloc() and freepathalloc() are used to allocate and
  93. * free pathalloc blocks.
  94. *
  95. * Public Interface:
  96. *
  97. * friend PATHALLOC *newpathalloc() // allocate a new pathalloc
  98. * friend void freepathalloc() // free a pathalloc
  99. *
  100. * History:
  101. * 05-Sep-1990 -by- Paul Butzi [paulb]
  102. * Wrote it.
  103. \**************************************************************************/
  104. class PATHALLOC {
  105. static HSEMAPHORE hsemFreelist; // Semaphore for freelist
  106. static PATHALLOC *freelist; // Free-list of pathallocs
  107. static COUNT cFree; // Count of free pathallocs
  108. static COUNT cAllocated; // Count of pathallocs allocated
  109. public:
  110. PATHALLOC *ppanext; // ptr to next pathalloc in path
  111. PATHRECORD *pprfreestart; // ptr to first free spot in pathalloc
  112. ULONG siztPathAlloc; // Size of path alloc
  113. PATHRECORD apr[1]; // variable length array of pathrecs
  114. friend BOOL bInitPathAlloc(); // initialize the free list
  115. friend PATHALLOC *newpathalloc(); // allocate a new pathalloc
  116. friend VOID freepathalloc(PATHALLOC *); // free a pathalloc
  117. friend VOID vPathDebug(); // Displays debug stats
  118. #ifdef _HYDRA_
  119. friend VOID MultiUserCleanupPathAlloc(); // cleanup memory
  120. #endif
  121. };
  122. typedef PATHALLOC *PPATHALLOC;
  123. #endif // GDIFLAGS_ONLY for gdikdx
  124. #define PATHALLOCSIZE (4096-64)
  125. #define PATHALLOCTHRESHOLD 8
  126. #define FREELIST_MAX 4
  127. // These flags shouldn't interfere with any PD_ DDI flags:
  128. #define PATH_JOURNAL 0x8000
  129. // Flags for flOptions in bStrokeAndOrFill:
  130. #define PATH_STROKE 1
  131. #define PATH_FILL 2
  132. // A private LINEATTRS flag to denote that the pen for a geometric line
  133. // may have zero dimensions. Set in the high word so as not to conflict
  134. // with the LA_ definitions in winddi.h:
  135. #define LA_ALLOW_ZERO_DIMENSIONS 0x10000L
  136. /*********************************Class************************************\
  137. * class PATH
  138. *
  139. * Path structure itself. We never actually use objects of this type,
  140. * instead we use EPATHOBJ's which are derived from this type.
  141. *
  142. * History:
  143. * 05-Sep-1990 -by- Paul Butzi [paulb]
  144. * Wrote it.
  145. \**************************************************************************/
  146. #define PATHTYPE_KEEPMEM 0x0001
  147. #define PATHTYPE_STACK 0x0002
  148. #ifndef GDIFLAGS_ONLY
  149. class PATH : public OBJECT
  150. {
  151. public:
  152. PATH() {}
  153. PATHALLOC *ppachain; // ptr to pathalloc chain
  154. PATHRECORD *pprfirst; // ptr to first record in path
  155. PATHRECORD *pprlast; // ptr to last record in path
  156. // rcfxBoundBox cannot be an ERECTFX because then CFront will insist
  157. // on creating a static constructor for PATH():
  158. RECTFX rcfxBoundBox; // bounding box for path
  159. POINTFIX ptfxSubPathStart; // start of next sub-path
  160. FLONG flags; // flags describing state of path
  161. PATHRECORD *pprEnum; // pointer for Enumeration
  162. FLONG flType; // denotes path type (stack, mem, keep)
  163. FLONG fl; // These are used for saving the PATHOBJ
  164. ULONG cCurves; // accelerator values when the path is
  165. // unlocked.
  166. CLIPLINEENUM cle; // used for enumerating and clipping
  167. };
  168. typedef PATH *PPATH;
  169. /*********************************Class************************************\
  170. * class EPATHOBJ
  171. *
  172. * User object for PATH class that has no constructor or destructor.
  173. *
  174. * Public Interface:
  175. *
  176. * History:
  177. * 17-Oct-1992 -by- J. Andrew Goossen [andrewgo]
  178. * Moved the constructors and destructor to derived XEPATHOBJ.
  179. *
  180. * 05-Apr-1991 -by- Wendy Wu [wendywu]
  181. * Added bInitLines friend function and cTotalPts member function.
  182. * Put in filling support.
  183. *
  184. * 28-Sep-1990 -by- Paul Butzi [paulb]
  185. * Wrote it.
  186. \**************************************************************************/
  187. class EPATHOBJ : public _PATHOBJ /* epo */
  188. {
  189. private:
  190. friend VOID vConstructGET(EPATHOBJ& po, PEDGE pedgeHead, PEDGE pedgeFree,RECTL *pBound);
  191. public:
  192. PPATH ppath;
  193. protected:
  194. BOOL addpoints(EXFORMOBJ *pxfo, PATHDATAL *);
  195. VOID growlastrec(EXFORMOBJ *pxfo,PATHDATAL *,POINTFIX *);
  196. VOID reinit();
  197. BOOL createrec(EXFORMOBJ *xfo,PATHDATAL *,POINTFIX *);
  198. BOOL newpathrec(PATHRECORD **pppr,COUNT *pcMax,COUNT cNeeded);
  199. PATHRECORD *pprFlattenRec(PATHRECORD *ppr);
  200. public:
  201. EPATHOBJ() {}
  202. CLIPOBJ *pco; // save the clipobj for enumeration
  203. PCLIPLINEENUM pcleGet() { return(&ppath->cle); }
  204. HPATH hpath() { return((HPATH) ppath->hGet()); }
  205. RECTFX rcfxBoundBox() { return(ppath->rcfxBoundBox); }
  206. BOOL bValid() { return(ppath != (PATH*) NULL); }
  207. // Path maintenance:
  208. VOID vLock(HPATH hpath)
  209. {
  210. ppath = (PPATH)HmgShareLock((HOBJ)hpath, PATH_TYPE);
  211. }
  212. VOID vDelete();
  213. VOID vFreeBlocks();
  214. BOOL bClone(EPATHOBJ& epo);
  215. ULONGSIZE_T cjSize();
  216. VOID vUpdateCosmeticStyleState(SURFACE*, LINEATTRS*);
  217. // Methods to add world space data to a path:
  218. BOOL bMoveTo(EXFORMOBJ* pxfo, POINTL* pptl);
  219. BOOL bPolyLineTo(EXFORMOBJ* pxfo, POINTL* pptl, ULONG cPts);
  220. BOOL bPolyBezierTo(EXFORMOBJ* pxfo, POINTL* pptl, ULONG cPts);
  221. // Methods to add device space data to a path:
  222. BOOL bMoveTo(POINTFIX* pptfx)
  223. {
  224. return(bMoveTo((EXFORMOBJ*) NULL, (POINTL*) pptfx));
  225. }
  226. BOOL bPolyLineTo(POINTFIX* pptfx, ULONG cPts)
  227. {
  228. return(bPolyLineTo((EXFORMOBJ*) NULL, (POINTL*) pptfx, cPts));
  229. }
  230. BOOL bPolyBezierTo(POINTFIX* pptfx, ULONG cPts)
  231. {
  232. return(bPolyBezierTo((EXFORMOBJ*) NULL, (POINTL*) pptfx, cPts));
  233. }
  234. BOOL bAppend(EPATHOBJ *ppoNew,POINTFIX *pptfxDelta);
  235. // Macro to add a polygon.
  236. BOOL bAddPolygon(EXFORMOBJ *pxo,POINTL *pptl,int c)
  237. {
  238. return(bMoveTo(pxo,pptl)
  239. && bPolyLineTo(pxo,pptl+1,c-1)
  240. && bCloseFigure());
  241. }
  242. // Methods to transform or manipulate a path:
  243. VOID vOffset(EPOINTL &eptl);
  244. // Get path's current point, remembering that if the last path operation
  245. // was a bMoveTo, the CP value is retrieved from ptfxSubPathStart:
  246. POINTFIX ptfxGetCurrent()
  247. {
  248. return((ppath->flags & PD_BEGINSUBPATH)
  249. ? ppath->ptfxSubPathStart
  250. : ppath->pprlast->aptfx[(ppath->pprlast->count) - 1]);
  251. }
  252. BOOL bCloseFigure();
  253. VOID vCloseAllFigures();
  254. BOOL bFlatten();
  255. // Output functions that do pointer exclusion, device locking, etc:
  256. BOOL bStrokeAndOrFill(XDCOBJ &dco,
  257. LINEATTRS *pla,
  258. EXFORMOBJ *pxfo,
  259. FLONG flOptions);
  260. BOOL bStrokeAndFill(XDCOBJ &dco,
  261. LINEATTRS *pla,
  262. EXFORMOBJ *pxfo)
  263. {
  264. return(bStrokeAndOrFill(dco, pla, pxfo, PATH_STROKE|PATH_FILL));
  265. }
  266. BOOL bStroke(XDCOBJ &dco,
  267. LINEATTRS *pla,
  268. EXFORMOBJ *pxfo)
  269. {
  270. return(bStrokeAndOrFill(dco, pla, pxfo, PATH_STROKE));
  271. }
  272. BOOL bFill(XDCOBJ &dco)
  273. {
  274. return(bStrokeAndOrFill(dco,
  275. (LINEATTRS*) NULL,
  276. (EXFORMOBJ*) NULL,
  277. PATH_FILL));
  278. }
  279. // Output functions for when you've done all the setup work and you want
  280. // to take advantage of smart devices:
  281. BOOL
  282. bSimpleFill(FLONG,PDEVOBJ*,SURFACE*,CLIPOBJ*,BRUSHOBJ*,POINTL*,MIX,FLONG);
  283. BOOL
  284. bTextOutSimpleFill(XDCOBJ&,RFONTOBJ&,PDEVOBJ*,SURFACE*,CLIPOBJ*,BRUSHOBJ*,POINTL*,MIX,FLONG);
  285. BOOL
  286. bSimpleStroke(FLONG,PDEVOBJ*,SURFACE*,CLIPOBJ*,XFORMOBJ*,BRUSHOBJ*,POINTL*,LINEATTRS*,MIX);
  287. BOOL
  288. bSimpleStrokeAndFill(FLONG,PDEVOBJ*,SURFACE*,CLIPOBJ*,
  289. XFORMOBJ*,BRUSHOBJ*,LINEATTRS*,
  290. BRUSHOBJ*,POINTL*,MIX,FLONG);
  291. BOOL bSimpleStroke1(FLONG flCaps, // For device graphics caps
  292. PDEVOBJ* plo,
  293. SURFACE* pSurface,
  294. CLIPOBJ* pco,
  295. BRUSHOBJ* pbo,
  296. POINTL* pptlBrushOrg,
  297. MIX mix)
  298. {
  299. // Make a copy of the default LINEATTRS because the driver might
  300. // try to update the style state:
  301. LINEATTRS laTmp = glaSimpleStroke.la;
  302. return(bSimpleStroke(flCaps,
  303. plo,
  304. pSurface,
  305. pco,
  306. (XFORMOBJ*) NULL,
  307. pbo,
  308. pptlBrushOrg,
  309. &laTmp,
  310. mix));
  311. }
  312. BOOL bTextOutSimpleStroke1(XDCOBJ& dco,
  313. RFONTOBJ& rfo,
  314. PDEVOBJ* plo,
  315. SURFACE* pSurface,
  316. CLIPOBJ* pco,
  317. BRUSHOBJ* pbo,
  318. POINTL* pptlBrushOrg,
  319. MIX mix);
  320. // Modification methods:
  321. VOID vBecome(WIDEPATHOBJ&);
  322. VOID vReComputeBounds();
  323. BOOL bComputeWidenedBounds(EPATHOBJ&, XFORMOBJ*, LINEATTRS*);
  324. BOOL bComputeWidenedBounds(XFORMOBJ* pxfo, LINEATTRS* pla)
  325. {
  326. return(bComputeWidenedBounds(*this, pxfo, pla));
  327. }
  328. BOOL bWiden(EPATHOBJ&, XFORMOBJ*, LINEATTRS*);
  329. BOOL bWiden(XFORMOBJ* pxfo, LINEATTRS* pla)
  330. {
  331. return(bWiden(*this, pxfo, pla));
  332. }
  333. VOID vWidenSetupForFrameRgn(XDCOBJ&, LONG, LONG, EXFORMOBJ*, LINEATTRS*);
  334. // Methods to enumerate a path
  335. VOID vEnumStart()
  336. {
  337. fl &= ~PO_ENUM_AS_INTEGERS; // A driver may have left this set
  338. ppath->pprEnum = ppath->pprfirst;
  339. }
  340. BOOL bEnum(PATHDATA *);
  341. BOOL bBeziers() { return(fl & PO_BEZIERS); }
  342. ULONG cTotalPts();
  343. ULONG cTotalCurves();
  344. // For persistent path objects:
  345. VOID vSetppath(PPATH ppath_) { ppath = ppath_; }
  346. // Debug routines:
  347. BOOL bAllClosed();
  348. VOID vPrint();
  349. VOID vDiag();
  350. };
  351. /*********************************Class************************************\
  352. * class XEPATHOBJ
  353. *
  354. * User object for PATH class that has constructors and a destructor.
  355. *
  356. * Public Interface:
  357. *
  358. * History:
  359. * 17-Oct-1992 -by- J. Andrew Goossen [andrewgo]
  360. * Made it from old EPATHOBJ.
  361. \**************************************************************************/
  362. class XEPATHOBJ : public EPATHOBJ
  363. {
  364. public:
  365. XEPATHOBJ() { cCurves = 0; fl = 0; } // Used when creating a new path
  366. XEPATHOBJ(HPATH hpath); // Get path given handle
  367. XEPATHOBJ(XDCOBJ& dco); // Get DC's path
  368. ~XEPATHOBJ();
  369. };
  370. /*********************************Class************************************\
  371. * class PATHMEMOBJ : public EPATHOBJ
  372. *
  373. * Memory object for PATH class.
  374. *
  375. * Public Interface:
  376. *
  377. * PATHMEMOBJ Constructor
  378. * ~PATHMEMOBJ() Destructor
  379. *
  380. * VOID vKeepIt() Make memory object long lived
  381. *
  382. * History:
  383. * 09-Jul-1990 -by- Donald Sidoroff [donalds]
  384. * Wrote it.
  385. \**************************************************************************/
  386. class PATHMEMOBJ : public EPATHOBJ /* pmo */
  387. {
  388. public:
  389. PATHMEMOBJ();
  390. ~PATHMEMOBJ();
  391. VOID vKeepIt() { ppath->flType |= PATHTYPE_KEEPMEM; }
  392. };
  393. #endif // GDIFLAGS_ONLY for gdikdx
  394. /*********************************Class************************************\
  395. * class PATHSTACKOBJ : public EPATHOBJ
  396. *
  397. * Object for creating paths on the stack. It can hold a small number
  398. * of points on the stack; if the path gets too big, it will expand onto
  399. * the heap.
  400. *
  401. * History:
  402. * 22-Mar-1992 -by- J. Andrew Goossen [andrewgo]
  403. * Wrote it.
  404. \**************************************************************************/
  405. // This value must be less than PATHALLOCSIZE, and allow the end of the
  406. // structure to be aligned on the most restrictive boundary:
  407. #define PATHSTACKALLOCSIZE 256
  408. #ifndef GDIFLAGS_ONLY
  409. class PATHSTACKOBJ : public EPATHOBJ /* pso */
  410. {
  411. private:
  412. PATH path;
  413. union {
  414. PATHALLOC pa;
  415. CHAR achBuffer[PATHSTACKALLOCSIZE];
  416. } paBuf;
  417. public:
  418. PATHSTACKOBJ(XDCOBJ& dco, BOOL bUseCP = TRUE);
  419. PATHSTACKOBJ();
  420. ~PATHSTACKOBJ();
  421. };
  422. /*********************************Class************************************\
  423. * class EPATHFONTOBJ : public EPATHOBJ
  424. *
  425. *
  426. *
  427. * History:
  428. * 20-May-92 -by- Paul Butzi
  429. * Wrote it.
  430. \**************************************************************************/
  431. class EPATHFONTOBJ : public EPATHOBJ
  432. {
  433. public:
  434. PATH path;
  435. PATHALLOC pa;
  436. public:
  437. VOID vInit(ULONGSIZE_T);
  438. };
  439. /*********************************Class************************************\
  440. * class LINETOPATHOBJ
  441. *
  442. * Special fast-track path constructor for LineTo's that are done when
  443. * there isn't an active DC path, and is to be drawn with a cosmetic
  444. * pen (can't handle geometric pens because WidenPath might be called,
  445. * and it requires more path structures to be initialized than I wish
  446. * to do here).
  447. *
  448. * History:
  449. * 17-Oct-1992 -by- J. Andrew Goossen [andrewgo]
  450. * Wrote it.
  451. \**************************************************************************/
  452. class LINETOPATHOBJ : public EPATHOBJ
  453. {
  454. public:
  455. PATH path;
  456. PATHRECORD pr;
  457. LINETOPATHOBJ() {}
  458. };
  459. /*********************************Class************************************\
  460. * class RECTANGLEPATHOBJ
  461. *
  462. * Special fast-track path constructor for Rectangles that are done when
  463. * there isn't an active DC path, and is to be drawn with a cosmetic
  464. * pen (can't handle geometric pens because WidenPath might be called,
  465. * and it requires more path structures to be initialized than I wish
  466. * to do here).
  467. *
  468. * History:
  469. * 13-Dec-1992 -by- J. Andrew Goossen [andrewgo]
  470. * Wrote it.
  471. \**************************************************************************/
  472. class RECTANGLEPATHOBJ : public EPATHOBJ
  473. {
  474. protected:
  475. PATH path;
  476. struct {
  477. PATHRECORD pr;
  478. POINTFIX aptfxBuf[2]; // We use this to leave room for the
  479. // additional 2 points we need to
  480. // complete the Rectangle.
  481. } prRect;
  482. public:
  483. RECTANGLEPATHOBJ() {}
  484. VOID vInit(RECTL*, BOOL);
  485. };
  486. #endif // GDIFLAGS_ONLY for gdikdx.