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.

3949 lines
93 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: umpdeng.c
  3. * This file contains stubs for calls made by umpdeng.c from gdi32.dll
  4. *
  5. * Created: 8/5/97
  6. * Author: Lingyun Wang [lingyunw]
  7. *
  8. * Copyright (c) 1997-1999 Microsoft Corporation
  9. *
  10. \**************************************************************************/
  11. #include "precomp.hxx"
  12. #if !defined(_GDIPLUS_)
  13. //
  14. // Macro for extracting the topmost UMPDOBJS structure
  15. // associated with the current thread.
  16. //
  17. // Put the following line at the beginning of each NtGdi...
  18. // function (after all other local variable declarations):
  19. //
  20. // EXTRACT_THREAD_UMPDOBJS retVal;
  21. //
  22. // where retVal is the error return value. If the function doesn't return
  23. // any value, simply omit the retVal.
  24. //
  25. #define EXTRACT_THREAD_UMPDOBJS \
  26. PUMPDOBJ pUMObjs = (PUMPDOBJ) W32GetCurrentThread()->pUMPDObj; \
  27. if (pUMObjs) \
  28. pUMObjs->vSetFlags(UMPDOBJ_ENGCALL); \
  29. else \
  30. return
  31. #define FIXUP_THREAD_UMPDOBJS \
  32. if (pUMObjs) \
  33. pUMObjs->vClearFlags(UMPDOBJ_ENGCALL);
  34. //
  35. // determine whether a BRUSHOBJ is a pattern brush
  36. //
  37. #define ISPATBRUSH(_pbo) ((_pbo) && (_pbo)->iSolidColor == 0xffffffff)
  38. #define MIXNEEDMASK(_mix) (((_mix) & 0xf) != (((_mix) >> 8) & 0xf))
  39. //
  40. // Map a user-mode BRUSHOBJ to its kernel-mode counterpart
  41. //
  42. #define MAP_UM_BRUSHOBJ(pUMObjs, pbo, pboTemp) \
  43. { \
  44. BRUSHOBJ *tempVar; \
  45. tempVar = (pUMObjs)->GetDDIOBJ(pbo); \
  46. pbo = tempVar ? tempVar : CaptureAndFakeBRUSHOBJ(pbo, pboTemp); \
  47. }
  48. inline BOOL
  49. PROBEDISPATBRUSH(BRUSHOBJ *pbo)
  50. {
  51. BRUSHOBJ tmpBo;
  52. BOOL bRet = FALSE;
  53. __try
  54. {
  55. tmpBo = ProbeAndReadStructure(pbo, BRUSHOBJ);
  56. if (ISPATBRUSH(&tmpBo))
  57. bRet = TRUE;
  58. }
  59. __except(EXCEPTION_EXECUTE_HANDLER)
  60. {
  61. }
  62. return bRet;
  63. }
  64. //
  65. // "Manufacture" a kernel-mode BRUSHOBJ structure using
  66. // the user-mode BRUSHOBJ as template
  67. //
  68. BRUSHOBJ *
  69. CaptureAndFakeBRUSHOBJ(
  70. BRUSHOBJ *pboUm,
  71. BRUSHOBJ *pboKm
  72. )
  73. {
  74. if (pboUm)
  75. {
  76. __try
  77. {
  78. // Copy user-mode BRUSHOBJ structure into kernel-mode memory
  79. *pboKm = ProbeAndReadStructure(pboUm, BRUSHOBJ);
  80. // Succeed only if BRUSHOBJ represents a solid color brush
  81. if (!ISPATBRUSH(pboKm))
  82. pboKm->pvRbrush = NULL;
  83. else
  84. pboKm = NULL;
  85. }
  86. __except(EXCEPTION_EXECUTE_HANDLER)
  87. {
  88. pboKm = NULL;
  89. }
  90. }
  91. else
  92. pboKm = NULL;
  93. return pboKm;
  94. }
  95. //
  96. // Capture a user-mode CLIPOBJ that orignated from EngCreateClip
  97. //
  98. CLIPOBJ *
  99. CaptureAndMungeCLIPOBJ(
  100. CLIPOBJ *pcoUm,
  101. CLIPOBJ *pcoKm,
  102. SIZEL *szLimit
  103. )
  104. {
  105. CLIPOBJ co;
  106. //
  107. // Capture user-mode CLIPOBJ structure into a temporary buffer
  108. //
  109. if (pcoUm)
  110. {
  111. __try
  112. {
  113. co = ProbeAndReadStructure(pcoUm, CLIPOBJ);
  114. }
  115. __except(EXCEPTION_EXECUTE_HANDLER)
  116. {
  117. pcoKm = NULL;
  118. }
  119. //
  120. // Munge the relevant fields in kernel-mode CLIPOBJ
  121. //
  122. if (pcoKm)
  123. {
  124. switch (co.iDComplexity)
  125. {
  126. case DC_RECT:
  127. if (szLimit)
  128. {
  129. co.rclBounds.left = max(0, co.rclBounds.left);
  130. co.rclBounds.top = max(0, co.rclBounds.top);
  131. co.rclBounds.right = min(szLimit->cx, co.rclBounds.right);
  132. co.rclBounds.bottom = min(szLimit->cy, co.rclBounds.bottom);
  133. }
  134. pcoKm->rclBounds = co.rclBounds;
  135. // fall through
  136. case DC_TRIVIAL:
  137. pcoKm->iDComplexity = co.iDComplexity;
  138. break;
  139. default:
  140. WARNING("User-mode CLIPOBJ is not DC_TRIVIAL or DC_RECT\n");
  141. pcoKm = NULL;
  142. break;
  143. }
  144. }
  145. }
  146. else
  147. {
  148. ASSERTGDI(pcoKm == NULL, "CaptureAndMungeCLIPOBJ: invalid pcoKm\n");
  149. }
  150. return pcoKm;
  151. }
  152. /******************************Public*Routine******************************\
  153. * GetSTROBJGlyphMode
  154. *
  155. * helper function to determine the Glyphmode based on strobj
  156. *
  157. * History:
  158. * 26-Sept-1997 -by- Lingyun Wang [lingyunw]
  159. * Wrote it.
  160. \**************************************************************************/
  161. __inline
  162. ULONG GetSTROBJGlyphMode (STROBJ *pstro)
  163. {
  164. return (((ESTROBJ*)pstro)->prfo->prfnt->ulContent);
  165. }
  166. __inline
  167. BOOL bOrder (RECTL *prcl)
  168. {
  169. return ((prcl->left < prcl->right) && (prcl->top < prcl->bottom));
  170. }
  171. /******************************Public*Routine******************************\
  172. * helper functions to copy user memory
  173. *
  174. * CaptureRECTL CapturePOINTL CapturePOINTFIX
  175. * CaptureLINEATTRS CaptureCOLORADJUSTMENT
  176. *
  177. * Note: prclFrom points to the captured rect on the way back
  178. * Note: Needs to be called within try/except
  179. *
  180. * History:
  181. * 26-Sept-1997 -by- Lingyun Wang [lingyunw]
  182. * Wrote it.
  183. \**************************************************************************/
  184. __inline
  185. VOID CaptureRECTL (RECTL **pprclFrom, RECTL *prclTo)
  186. {
  187. if (*pprclFrom)
  188. {
  189. *prclTo = ProbeAndReadStructure(*pprclFrom,RECTL);
  190. //
  191. // repoint pprclFrom to prclTo
  192. //
  193. *pprclFrom = prclTo;
  194. }
  195. return;
  196. }
  197. __inline
  198. VOID CapturePOINTL (POINTL **ppptlFrom, POINTL *pptlTo)
  199. {
  200. if (*ppptlFrom)
  201. {
  202. *pptlTo = ProbeAndReadStructure(*ppptlFrom,POINTL);
  203. *ppptlFrom = pptlTo;
  204. }
  205. return;
  206. }
  207. __inline
  208. VOID CapturePOINTFIX (POINTFIX **ppptfxFrom, POINTFIX *pptfxTo)
  209. {
  210. if (*ppptfxFrom)
  211. {
  212. *pptfxTo = ProbeAndReadStructure(*ppptfxFrom,POINTFIX);
  213. *ppptfxFrom = pptfxTo;
  214. }
  215. return;
  216. }
  217. //
  218. // the calling routine needs to free pStyle
  219. //
  220. // Note: plineFrom will be changed to plineTo upon returning from this routine
  221. // so to save some changes into the lower level calls
  222. //
  223. __inline
  224. BOOL bCaptureLINEATTRS (LINEATTRS **pplineFrom, LINEATTRS *plineTo)
  225. {
  226. BOOL bRet = TRUE;
  227. if (*pplineFrom)
  228. {
  229. PFLOAT_LONG pstyle = NULL;
  230. __try
  231. {
  232. *plineTo = ProbeAndReadStructure(*pplineFrom,LINEATTRS);
  233. if (plineTo->pstyle)
  234. {
  235. if (BALLOC_OVERFLOW1(plineTo->cstyle, FLOAT_LONG))
  236. return FALSE;
  237. ProbeForRead(plineTo->pstyle, plineTo->cstyle*sizeof(FLOAT_LONG), sizeof(BYTE));
  238. pstyle = (PFLOAT_LONG)PALLOCNOZ(plineTo->cstyle*sizeof(FLOAT_LONG), UMPD_MEMORY_TAG);
  239. if (!pstyle)
  240. {
  241. //
  242. // so we won't free it later
  243. //
  244. plineTo->pstyle = NULL;
  245. bRet = FALSE;
  246. }
  247. else
  248. {
  249. RtlCopyMemory(pstyle, plineTo->pstyle, plineTo->cstyle*sizeof(FLOAT_LONG));
  250. plineTo->pstyle = pstyle;
  251. }
  252. }
  253. }
  254. __except(EXCEPTION_EXECUTE_HANDLER)
  255. {
  256. WARNING ("bCaptureLINEATTRS -- exception in try/except \n");
  257. if (pstyle)
  258. VFREEMEM(pstyle);
  259. bRet = FALSE;
  260. }
  261. *pplineFrom = plineTo;
  262. }
  263. return bRet;
  264. }
  265. __inline
  266. VOID CaptureCOLORADJUSTMENT (COLORADJUSTMENT **ppcaFrom, COLORADJUSTMENT *pcaTo)
  267. {
  268. if (*ppcaFrom)
  269. {
  270. *pcaTo = ProbeAndReadStructure(*ppcaFrom,COLORADJUSTMENT);
  271. *ppcaFrom = pcaTo;
  272. }
  273. return;
  274. }
  275. __inline
  276. VOID CaptureDWORD (DWORD **ppdwFrom, DWORD *pdwTo)
  277. {
  278. if (*ppdwFrom)
  279. {
  280. *pdwTo = ProbeAndReadStructure(*ppdwFrom,DWORD);
  281. //
  282. // repoint pprclFrom to prclTo
  283. //
  284. *ppdwFrom = pdwTo;
  285. }
  286. return;
  287. }
  288. __inline
  289. VOID CaptureBits (PVOID pv, PVOID pvTmp, ULONG cj)
  290. {
  291. if (pv && pvTmp)
  292. {
  293. ProbeAndReadBuffer(pv, pvTmp, cj);
  294. }
  295. return;
  296. }
  297. /******************************Public*Routine******************************\
  298. * bSecureBits bSafeReadBits bSafeCopyBits
  299. *
  300. * helper functions to secure or copy user memory
  301. * These donot need to be called from within try/except
  302. *
  303. * History:
  304. * 26-Sept-1997 -by- Lingyun Wang [lingyunw]
  305. * Wrote it.
  306. \**************************************************************************/
  307. __inline
  308. BOOL bSecureBits (PVOID pv, ULONG cj, HANDLE *phSecure)
  309. {
  310. BOOL bRet = TRUE;
  311. *phSecure = 0;
  312. if (pv)
  313. {
  314. __try
  315. {
  316. ProbeForRead(pv,cj,sizeof(BYTE));
  317. *phSecure = MmSecureVirtualMemory(pv, cj, PAGE_READONLY);
  318. if (*phSecure == 0)
  319. {
  320. bRet = FALSE;
  321. }
  322. }
  323. __except(EXCEPTION_EXECUTE_HANDLER)
  324. {
  325. WARNING ("bSecureBits -- exception in try/except \n");
  326. bRet = FALSE;
  327. }
  328. }
  329. return (bRet);
  330. }
  331. __inline
  332. BOOL bSafeCopyBits (PVOID pv, PVOID pvTmp, ULONG cj)
  333. {
  334. BOOL bRet = TRUE;
  335. if (pv && pvTmp)
  336. {
  337. __try
  338. {
  339. ProbeAndWriteBuffer(pv, pvTmp, cj);
  340. }
  341. __except(EXCEPTION_EXECUTE_HANDLER)
  342. {
  343. WARNING ("fail in try/except to write into buffer\n");
  344. bRet = FALSE;
  345. }
  346. }
  347. return bRet;
  348. }
  349. __inline
  350. BOOL bSafeReadBits (PVOID pv, PVOID pvTmp, ULONG cj)
  351. {
  352. BOOL bRet = TRUE;
  353. if (pv && pvTmp)
  354. {
  355. __try
  356. {
  357. ProbeAndReadBuffer(pv, pvTmp, cj);
  358. }
  359. __except(EXCEPTION_EXECUTE_HANDLER)
  360. {
  361. WARNING ("fail in try/except to read from buffer\n");
  362. bRet = FALSE;
  363. }
  364. }
  365. return bRet;
  366. }
  367. /******************************Public*Routine******************************\
  368. * bCheckSurfaceRect bCheckSurfaceRectSize
  369. *
  370. * Check rect and pco against the surface, make sure we are not going to
  371. * draw outside the surface
  372. *
  373. * bCheckSurfacePath
  374. *
  375. * Check the path against the surface, make sure not going to draw outside
  376. * the surface
  377. *
  378. * bCheckSurfacePoint
  379. *
  380. * Check the point against the surface
  381. *
  382. * History:
  383. * 26-Sept-1997 -by- Lingyun Wang [lingyunw]
  384. * Wrote it.
  385. \**************************************************************************/
  386. __inline
  387. BOOL bCheckSurfaceRect(SURFOBJ *pso, RECTL *prcl, CLIPOBJ *pco)
  388. {
  389. BOOL bRet = TRUE;
  390. BOOL bTrivial;
  391. if (pso)
  392. {
  393. if (pco)
  394. {
  395. bTrivial = (pco->iDComplexity == DC_TRIVIAL) ? TRUE : FALSE;
  396. }
  397. else
  398. {
  399. bTrivial = TRUE;
  400. }
  401. //
  402. // if no clipping, check against the rectangle.
  403. //
  404. if (!bTrivial)
  405. {
  406. //
  407. // there is clipping invloved, check against pco->rclBounds.
  408. //
  409. prcl = &(pco->rclBounds);
  410. }
  411. if (prcl)
  412. {
  413. if ((prcl->left > prcl->right) || (prcl->top > prcl->bottom))
  414. {
  415. WARNING ("prcl not well ordered, returing failure\n");
  416. bRet = FALSE;
  417. }
  418. if (bRet && ((prcl->right > pso->sizlBitmap.cx) || (prcl->left < 0)||
  419. (prcl->bottom > pso->sizlBitmap.cy)|| (prcl->top < 0)))
  420. {
  421. WARNING ("we might draw outside the surface, returning failure\n");
  422. bRet = FALSE;
  423. }
  424. }
  425. }
  426. return bRet;
  427. }
  428. __inline
  429. BOOL bCheckSurfaceRectSize(SURFOBJ *pso, RECTL *prcl, CLIPOBJ *pco,
  430. ULONG *pcx, ULONG *pcy, BOOL bOrder = TRUE)
  431. {
  432. BOOL bRet = TRUE;
  433. BOOL bTrivial;
  434. ERECTL rcl(0, 0, 0, 0);
  435. PRECTL prclBounds = NULL;
  436. if (pso)
  437. {
  438. if (pco)
  439. {
  440. bTrivial = (pco->iDComplexity == DC_TRIVIAL) ? TRUE : FALSE;
  441. }
  442. else
  443. {
  444. bTrivial = TRUE;
  445. }
  446. //
  447. // if no clipping, check against the rectangle.
  448. //
  449. if (!bTrivial)
  450. {
  451. //
  452. // there is clipping invloved, check against pco->rclBounds.
  453. //
  454. prclBounds = &(pco->rclBounds);
  455. rcl = *prclBounds;
  456. }
  457. else
  458. {
  459. if (prcl)
  460. {
  461. rcl = *prcl;
  462. }
  463. }
  464. //
  465. // check the rectangle
  466. //
  467. if (bOrder && ((rcl.left > rcl.right) || (rcl.top > rcl.bottom)))
  468. {
  469. WARNING ("rcl not well ordered, returing failure\n");
  470. return FALSE;
  471. }
  472. //
  473. // check that we are not going outside the surface
  474. //
  475. if ((rcl.right > pso->sizlBitmap.cx) || (rcl.left < 0)||
  476. (rcl.bottom > pso->sizlBitmap.cy)|| (rcl.top < 0))
  477. {
  478. WARNING ("we might draw outside the surface, returning failure\n");
  479. return FALSE;
  480. }
  481. //
  482. // figure out the size
  483. //
  484. if (prclBounds && prcl)
  485. {
  486. RECTL rclIntersect;
  487. rclIntersect.left = MAX(prclBounds->left, prcl->left);
  488. rclIntersect.right = MIN(prclBounds->right, prcl->right);
  489. rclIntersect.top = MAX(prclBounds->top, prcl->top);
  490. rclIntersect.bottom = MAX(prclBounds->bottom, prcl->bottom);
  491. *pcx = (rclIntersect.right - rclIntersect.left) > 0 ?
  492. rclIntersect.right - rclIntersect.left : 0;
  493. *pcy = (rclIntersect.bottom - rclIntersect.top) > 0 ?
  494. rclIntersect.bottom - rclIntersect.top : 0 ;
  495. }
  496. else if (prcl)
  497. {
  498. *pcx = (prcl->right - prcl->left) > 0 ?
  499. prcl->right - prcl->left : 0;
  500. *pcy = (prcl->bottom - prcl->top) > 0 ?
  501. prcl->bottom - prcl->top : 0;
  502. }
  503. else if (prclBounds)
  504. {
  505. *pcx = (prclBounds->right - prclBounds->left) > 0 ?
  506. prclBounds->right - prclBounds->left : 0;
  507. *pcy = (prclBounds->bottom - prclBounds->top) > 0 ?
  508. prclBounds->bottom - prclBounds->top : 0;
  509. }
  510. }
  511. return bRet;
  512. }
  513. __inline
  514. BOOL bCheckDestSurfaceOverlap(SURFOBJ *pso, RECTL* prcl)
  515. {
  516. ERECTL ercl = *prcl;
  517. // If we need to mirror do it.
  518. if (ercl.bottom < ercl.top)
  519. {
  520. LONG lTemp = ercl.top;
  521. ercl.top = ercl.bottom;
  522. ercl.bottom = lTemp;
  523. }
  524. if (ercl.right < ercl.left)
  525. {
  526. LONG lTemp = ercl.left;
  527. ercl.left = ercl.right;
  528. ercl.right = lTemp;
  529. }
  530. ERECTL erclTrg(0, 0, pso->sizlBitmap.cx, pso->sizlBitmap.cy);
  531. ercl *= erclTrg;
  532. if (ercl.bEmpty())
  533. return(FALSE);
  534. return(TRUE);
  535. }
  536. __inline
  537. BOOL bCheckSurfacePath(SURFOBJ *pso, PATHOBJ *ppo, CLIPOBJ *pco)
  538. {
  539. BOOL bRet = TRUE;
  540. BOOL bTrivial;
  541. RECTL *prcl;
  542. if (pso && ppo)
  543. {
  544. if (pco)
  545. {
  546. bTrivial = (pco->iDComplexity == DC_TRIVIAL) ? TRUE : FALSE;
  547. }
  548. else
  549. {
  550. bTrivial = TRUE;
  551. }
  552. if (bTrivial)
  553. {
  554. //
  555. // no clipping, check against ppo->rcfxBoundBox.
  556. //
  557. RECTFX rcfx;
  558. rcfx = ((EPATHOBJ *)ppo)->ppath->rcfxBoundBox;
  559. prcl = (RECTL *)&rcfx;
  560. prcl->left = FXTOL(rcfx.xLeft);
  561. prcl->top = FXTOL(rcfx.yTop);
  562. prcl->right = FXTOL(rcfx.xRight);
  563. prcl->bottom = FXTOL(rcfx.yBottom);
  564. }
  565. else
  566. {
  567. //
  568. // there is clipping invloved, check against pco->rclBounds.
  569. //
  570. prcl = &(pco->rclBounds);
  571. }
  572. if (prcl)
  573. {
  574. if ((prcl->left > prcl->right) || (prcl->top > prcl->bottom))
  575. {
  576. WARNING ("prcl not well ordered, returing failure\n");
  577. bRet = FALSE;
  578. }
  579. if (bRet && (prcl->right > pso->sizlBitmap.cx) || (prcl->left < 0) ||
  580. (prcl->bottom > pso->sizlBitmap.cy)|| (prcl->top < 0))
  581. {
  582. bRet = FALSE;
  583. }
  584. }
  585. }
  586. else
  587. {
  588. WARNING("bCheckSurfacePath either pso or ppo is NULL\n");
  589. bRet = FALSE;
  590. }
  591. return bRet;
  592. }
  593. __inline
  594. BOOL bCheckSurfacePoint(SURFOBJ *pso, POINTL *ptl)
  595. {
  596. BOOL bRet = TRUE;
  597. if (pso && ptl)
  598. {
  599. if ((pso->sizlBitmap.cx < ptl->x) || (ptl->x < 0) ||
  600. (pso->sizlBitmap.cy < ptl->y)|| (ptl->y < 0))
  601. {
  602. bRet = FALSE;
  603. }
  604. }
  605. return bRet;
  606. }
  607. __inline
  608. BOOL bCheckMask(SURFOBJ *psoMask, RECTL *prcl)
  609. {
  610. BOOL bRet = TRUE;
  611. if (psoMask)
  612. {
  613. if (psoMask->iBitmapFormat != BMF_1BPP)
  614. bRet = FALSE;
  615. if (bRet)
  616. bRet = bCheckSurfaceRect(psoMask, prcl, NULL);
  617. }
  618. return bRet;
  619. }
  620. //
  621. // Make sure the we are not going to access pulXlate when there is no one
  622. // Any other checks on xlateobj?
  623. //
  624. __inline
  625. BOOL bCheckXlate(SURFOBJ *pso, XLATEOBJ *pxlo)
  626. {
  627. BOOL bRet = TRUE;
  628. if (pso)
  629. {
  630. if (pxlo && !(pxlo->flXlate & XO_TRIVIAL))
  631. {
  632. switch (pso->iBitmapFormat)
  633. {
  634. case BMF_1BPP:
  635. {
  636. bRet = (pxlo->cEntries == 2) ? TRUE : FALSE;
  637. break;
  638. }
  639. case BMF_4BPP:
  640. {
  641. //we can have a halftone palette of 8 entries
  642. bRet = ((pxlo->cEntries == 16) || (pxlo->cEntries == 8)) ? TRUE : FALSE;
  643. break;
  644. }
  645. case BMF_8BPP:
  646. {
  647. // halftone palette can be any combination
  648. bRet = (pxlo->cEntries <= 256) ? TRUE : FALSE;
  649. break;
  650. }
  651. }
  652. }
  653. }
  654. return bRet;
  655. }
  656. __inline
  657. PRECTL pRect(POINTL *pptl, RECTL *prcl, ULONG cx, ULONG cy)
  658. {
  659. PRECTL prclRet;
  660. if (pptl)
  661. {
  662. prcl->left = pptl->x;
  663. prcl->right = pptl->x + cx;
  664. prcl->top = pptl->y;
  665. prcl->bottom = pptl->y + cy;
  666. prclRet = prcl;
  667. }
  668. else
  669. {
  670. prclRet = NULL;
  671. }
  672. return prclRet;
  673. }
  674. //
  675. // check the order of a rectangle
  676. //
  677. __inline
  678. BOOL bCheckRect(RECTL *prcl)
  679. {
  680. BOOL bRet = TRUE;
  681. if (prcl)
  682. {
  683. if ((prcl->left > prcl->right) || (prcl->top > prcl->bottom))
  684. {
  685. WARNING ("prcl not well ordered, returing failure\n");
  686. bRet = FALSE;
  687. }
  688. }
  689. return bRet;
  690. }
  691. //
  692. // Validate an HSURF and make sure it refers to a UMPD surface
  693. //
  694. __inline BOOL
  695. ValidUmpdHsurf(
  696. HSURF hsurf
  697. )
  698. {
  699. SURFREF so(hsurf);
  700. //
  701. // Make sure hsurf is valid and it refers to a UMPD surface
  702. //
  703. return (so.bValid() && so.ps->bUMPD());
  704. }
  705. //
  706. // Validate an HSURF and Unsecure hSecure
  707. //
  708. __inline BOOL
  709. ValidUmpdHsurfAndUnSecure(
  710. HSURF hsurf
  711. )
  712. {
  713. SURFREF so(hsurf);
  714. //
  715. // Make sure hsurf is valid and it refers to a UMPD surface
  716. //
  717. if (so.bValid() && so.ps->bUMPD())
  718. {
  719. if (so.ps->hSecureUMPD)
  720. {
  721. ASSERTGDI(so.ps->iType() == STYPE_BITMAP, "surf type != STYPE_BITMAP\n");
  722. MmUnsecureVirtualMemory(so.ps->hSecureUMPD);
  723. }
  724. return TRUE;
  725. }
  726. else
  727. {
  728. return FALSE;
  729. }
  730. }
  731. //
  732. // Validate an HDEV belongs to us
  733. //
  734. BOOL
  735. ValidUmpdHdev(
  736. HDEV hdev
  737. )
  738. {
  739. BOOL bRet = FALSE;
  740. if (hdev == NULL)
  741. return FALSE;
  742. if (!IS_SYSTEM_ADDRESS(hdev))
  743. return FALSE;
  744. PPDEV ppdev;
  745. GreAcquireSemaphoreEx(ghsemDriverMgmt, SEMORDER_DRIVERMGMT, NULL);
  746. for (ppdev = gppdevList; ppdev != NULL; ppdev = ppdev->ppdevNext)
  747. {
  748. if ((HDEV)ppdev == hdev)
  749. {
  750. bRet = TRUE;
  751. break;
  752. }
  753. }
  754. GreReleaseSemaphoreEx(ghsemDriverMgmt);
  755. return bRet;
  756. }
  757. //
  758. // Make sure for each HOOK_XXX flag set, we actually
  759. // has the driver function in ppfn
  760. //
  761. BOOL
  762. ValidUmpdHooks (
  763. HDEV hdev,
  764. FLONG flHooks
  765. )
  766. {
  767. PDEVOBJ po(hdev);
  768. return (PPFNGET(po, BitBlt, flHooks) &&
  769. PPFNGET(po, StretchBlt, flHooks) &&
  770. PPFNGET(po, PlgBlt, flHooks) &&
  771. PPFNGET(po, TextOut, flHooks) &&
  772. PPFNGET(po, StrokePath, flHooks) &&
  773. PPFNGET(po, FillPath, flHooks) &&
  774. PPFNGET(po, StrokeAndFillPath, flHooks) &&
  775. PPFNGET(po, Paint, flHooks) &&
  776. PPFNGET(po, CopyBits, flHooks) &&
  777. PPFNGET(po, LineTo, flHooks) &&
  778. PPFNGET(po, StretchBltROP, flHooks) &&
  779. PPFNGET(po, TransparentBlt, flHooks) &&
  780. PPFNGET(po, AlphaBlend, flHooks) &&
  781. PPFNGET(po, GradientFill, flHooks));
  782. }
  783. //
  784. // Valid size for bitmap/surface creation
  785. //
  786. BOOL
  787. ValidUmpdSizl(
  788. SIZEL sizl
  789. )
  790. {
  791. if ((sizl.cx <= 0) || (sizl.cy <= 0))
  792. {
  793. WARNING("ValidUmpdSizl failed - cx or cy <=0 \n");
  794. return FALSE;
  795. }
  796. else
  797. {
  798. ULONGLONG cj = ((ULONGLONG)sizl.cx) * sizl.cy;
  799. if (cj > MAXULONG)
  800. {
  801. WARNING("ValidUmpdSizl failed - cx*cy overflow\n");
  802. return FALSE;
  803. }
  804. }
  805. return TRUE;
  806. }
  807. ULONG
  808. ValidUmpdOverflow(LONG cx, LONG cy)
  809. {
  810. ULONGLONG cj = ((ULONGLONG)cx) * cy;
  811. if (cj > MAXULONG)
  812. return FALSE;
  813. else
  814. return (ULONG)cj;
  815. }
  816. BOOL APIENTRY NtGdiEngAssociateSurface(
  817. IN HSURF hsurf,
  818. IN HDEV hdev,
  819. IN FLONG flHooks
  820. )
  821. {
  822. return ValidUmpdHsurf(hsurf) &&
  823. ValidUmpdHdev(hdev) &&
  824. (!(flHooks & ~HOOK_FLAGS))&&
  825. ValidUmpdHooks (hdev, flHooks) &&
  826. EngAssociateSurface(hsurf, hdev, flHooks);
  827. }
  828. BOOL APIENTRY NtGdiEngDeleteSurface(
  829. IN HSURF hsurf
  830. )
  831. {
  832. return ValidUmpdHsurfAndUnSecure(hsurf) &&
  833. EngDeleteSurface(hsurf);
  834. }
  835. BOOL APIENTRY NtGdiEngMarkBandingSurface(
  836. HSURF hsurf
  837. )
  838. {
  839. return ValidUmpdHsurf(hsurf) &&
  840. EngMarkBandingSurface(hsurf);
  841. }
  842. HBITMAP APIENTRY NtGdiEngCreateBitmap(
  843. IN SIZEL sizl,
  844. IN LONG lWidth,
  845. IN ULONG iFormat,
  846. IN FLONG fl,
  847. IN PVOID pvBits
  848. )
  849. {
  850. HBITMAP hbm = NULL;
  851. HANDLE hSecure = NULL;
  852. ULONG cj;
  853. BOOL bSuccess = TRUE;
  854. TRACE_INIT (("Entering NtGdiEngCreateBitmap\n"));
  855. // check sizl.x and y
  856. if (!ValidUmpdSizl(sizl))
  857. return 0;
  858. cj = ValidUmpdOverflow(lWidth, sizl.cy);
  859. //
  860. // set the high bit of iFormat to indicate umpd driver
  861. //
  862. iFormat |= UMPD_FLAG;
  863. if (pvBits)
  864. {
  865. fl &= ~BMF_USERMEM;
  866. __try
  867. {
  868. ProbeForRead(pvBits,cj,sizeof(BYTE));
  869. hSecure = MmSecureVirtualMemory(pvBits, cj, PAGE_READWRITE);
  870. if (!hSecure)
  871. bSuccess = FALSE;
  872. }
  873. __except(EXCEPTION_EXECUTE_HANDLER)
  874. {
  875. WARNING ("EngCreateBitmap -- exception in try/except \n");
  876. bSuccess = FALSE;
  877. }
  878. }
  879. else
  880. {
  881. fl |= BMF_USERMEM;
  882. #if defined(_WIN64)
  883. // wow64 printing
  884. PW32THREAD pw32thread = W32GetCurrentThread();
  885. if (pw32thread->pClientID)
  886. fl |= BMF_UMPDMEM;
  887. #endif
  888. }
  889. if (bSuccess)
  890. {
  891. hbm = EngCreateBitmap(sizl, lWidth, iFormat, fl, pvBits);
  892. }
  893. if (hSecure != NULL)
  894. {
  895. if (hbm != NULL)
  896. {
  897. //
  898. // set hSecure into hSecureUMPD, at EngDeleteSurface time,
  899. // we unsecure it
  900. //
  901. SURFREF so((HSURF) hbm);
  902. if (so.bValid())
  903. {
  904. so.ps->hSecureUMPD = hSecure;
  905. }
  906. else
  907. {
  908. MmUnsecureVirtualMemory(hSecure);
  909. EngDeleteSurface((HSURF)hbm);
  910. hbm = NULL;
  911. }
  912. }
  913. else
  914. {
  915. //
  916. // We secured caller's memory but EngCreateBitmap failed.
  917. //
  918. MmUnsecureVirtualMemory(hSecure);
  919. }
  920. }
  921. return (hbm);
  922. }
  923. BOOL APIENTRY NtGdiEngCopyBits(
  924. IN SURFOBJ *psoDst,
  925. OUT SURFOBJ *psoSrc,
  926. IN CLIPOBJ *pco,
  927. IN XLATEOBJ *pxlo,
  928. IN RECTL *prclDst,
  929. IN POINTL *pptlSrc
  930. )
  931. {
  932. RECTL rcl;
  933. POINTL ptl;
  934. ULONG cx, cy;
  935. BOOL bRet = TRUE;
  936. EXTRACT_THREAD_UMPDOBJS(FALSE);
  937. UMPDSURFOBJ umsoDst(psoDst, pUMObjs);
  938. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  939. psoDst = umsoDst.pso();
  940. psoSrc = umsoSrc.pso();
  941. if (psoDst && psoSrc && (psoDst->iType == STYPE_BITMAP) && prclDst && pptlSrc)
  942. {
  943. __try
  944. {
  945. CaptureRECTL(&prclDst, &rcl);
  946. CapturePOINTL(&pptlSrc, &ptl);
  947. }
  948. __except(EXCEPTION_EXECUTE_HANDLER)
  949. {
  950. WARNING ("NtGdiEngCopyBits failed in try/except\n");
  951. bRet = FALSE;
  952. }
  953. if (bRet && bOrder(prclDst))
  954. {
  955. pco = pUMObjs->GetDDIOBJ(pco, &psoDst->sizlBitmap);
  956. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  957. if (bRet = (bCheckSurfaceRectSize(psoDst, prclDst, pco, &cx, &cy) && bCheckXlate(psoSrc, pxlo)))
  958. {
  959. RECTL rclSrc, *prclSrc;
  960. prclSrc = psoSrc ? pRect(pptlSrc, &rclSrc, cx, cy) : NULL;
  961. if (bRet = bCheckSurfaceRect(psoSrc, prclSrc, NULL))
  962. {
  963. bRet = EngCopyBits(psoDst,
  964. psoSrc,
  965. pco,
  966. pxlo,
  967. prclDst,
  968. pptlSrc);
  969. }
  970. }
  971. }
  972. }
  973. else
  974. {
  975. bRet = FALSE;
  976. }
  977. FIXUP_THREAD_UMPDOBJS;
  978. return (bRet);
  979. }
  980. BOOL APIENTRY NtGdiEngStretchBlt(
  981. SURFOBJ *psoDest,
  982. SURFOBJ *psoSrc,
  983. SURFOBJ *psoMask,
  984. CLIPOBJ *pco,
  985. XLATEOBJ *pxlo,
  986. COLORADJUSTMENT *pca,
  987. POINTL *pptlHTOrg,
  988. RECTL *prclDest,
  989. RECTL *prclSrc,
  990. POINTL *pptlMask,
  991. ULONG iMode
  992. )
  993. {
  994. BOOL bRet = TRUE;
  995. RECTL rclDst, rclSrc;
  996. POINTL ptlMask, ptlHTOrg;
  997. COLORADJUSTMENT ca;
  998. EXTRACT_THREAD_UMPDOBJS(FALSE);
  999. UMPDSURFOBJ umsoDest(psoDest, pUMObjs);
  1000. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  1001. UMPDSURFOBJ umsoMask(psoMask, pUMObjs);
  1002. psoDest = umsoDest.pso();
  1003. psoSrc = umsoSrc.pso();
  1004. psoMask = umsoMask.pso();
  1005. if (!pptlHTOrg && (iMode == HALFTONE))
  1006. {
  1007. WARNING ("pptlHTOrg is NULL for HALFTONE mode\n");
  1008. FIXUP_THREAD_UMPDOBJS;
  1009. return (FALSE);
  1010. }
  1011. if (psoDest && psoSrc && prclDest && prclSrc)
  1012. {
  1013. __try
  1014. {
  1015. CaptureRECTL(&prclDest, &rclDst);
  1016. CapturePOINTL(&pptlMask, &ptlMask);
  1017. CaptureRECTL(&prclSrc, &rclSrc);
  1018. CaptureCOLORADJUSTMENT(&pca, &ca);
  1019. CapturePOINTL(&pptlHTOrg, &ptlHTOrg);
  1020. }
  1021. __except(EXCEPTION_EXECUTE_HANDLER)
  1022. {
  1023. WARNING ("NtGdiEngStretchBlt failed in try/except\n");
  1024. bRet = FALSE;
  1025. }
  1026. if (!bCheckDestSurfaceOverlap(psoDest,prclDest))
  1027. {
  1028. FIXUP_THREAD_UMPDOBJS;
  1029. return(TRUE);
  1030. }
  1031. if (bRet)
  1032. {
  1033. pco = pUMObjs->GetDDIOBJ(pco, &psoDest->sizlBitmap);
  1034. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  1035. //
  1036. // EngStretchBlt does trimming and checking of the dest and src rectangles,
  1037. // but it assumes the src rect is well-ordered. Check here.
  1038. //
  1039. bRet = bOrder(prclSrc) && bCheckXlate(psoSrc, pxlo);
  1040. if (bRet && psoMask)
  1041. {
  1042. RECTL rclMask, *prclMask;
  1043. ULONG cx, cy;
  1044. if (bRet = bCheckSurfaceRectSize(psoSrc, prclSrc, NULL, &cx, &cy))
  1045. {
  1046. prclMask = pRect(pptlMask, &rclMask, cx, cy);
  1047. bRet = bCheckMask(psoMask, prclMask);
  1048. }
  1049. }
  1050. if (bRet)
  1051. bRet = EngStretchBlt(psoDest,
  1052. psoSrc,
  1053. psoMask,
  1054. pco,
  1055. pxlo,
  1056. pca,
  1057. pptlHTOrg,
  1058. prclDest,
  1059. prclSrc,
  1060. pptlMask,
  1061. iMode);
  1062. }
  1063. }
  1064. else
  1065. {
  1066. bRet = FALSE;
  1067. }
  1068. FIXUP_THREAD_UMPDOBJS;
  1069. return (bRet);
  1070. }
  1071. BOOL APIENTRY NtGdiEngStretchBltROP(
  1072. SURFOBJ *psoDest,
  1073. SURFOBJ *psoSrc,
  1074. SURFOBJ *psoMask,
  1075. CLIPOBJ *pco,
  1076. XLATEOBJ *pxlo,
  1077. COLORADJUSTMENT *pca,
  1078. POINTL *pptlHTOrg,
  1079. RECTL *prclDest,
  1080. RECTL *prclSrc,
  1081. POINTL *pptlMask,
  1082. ULONG iMode,
  1083. BRUSHOBJ *pbo,
  1084. DWORD rop4
  1085. )
  1086. {
  1087. BOOL bRet = TRUE;
  1088. RECTL rclDst, rclSrc;
  1089. POINTL ptlMask, ptlHTOrg;
  1090. COLORADJUSTMENT ca;
  1091. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1092. UMPDSURFOBJ umsoDest(psoDest, pUMObjs);
  1093. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  1094. UMPDSURFOBJ umsoMask(psoMask, pUMObjs);
  1095. psoDest = umsoDest.pso();
  1096. psoSrc = umsoSrc.pso();
  1097. psoMask = umsoMask.pso();
  1098. if (!pptlHTOrg && (iMode == HALFTONE))
  1099. {
  1100. WARNING ("pptlHTOrg is NULL for HALFTONE mode\n");
  1101. FIXUP_THREAD_UMPDOBJS;
  1102. return (FALSE);
  1103. }
  1104. if (psoDest && psoSrc && prclDest && prclSrc)
  1105. {
  1106. __try
  1107. {
  1108. CaptureRECTL(&prclDest, &rclDst);
  1109. CaptureRECTL(&prclSrc, &rclSrc);
  1110. CapturePOINTL(&pptlMask, &ptlMask);
  1111. CapturePOINTL(&pptlHTOrg, &ptlHTOrg);
  1112. CaptureCOLORADJUSTMENT(&pca, &ca);
  1113. }
  1114. __except(EXCEPTION_EXECUTE_HANDLER)
  1115. {
  1116. WARNING ("NtGdiEngStretchBltTROP failed in try/except\n");
  1117. bRet = FALSE;
  1118. }
  1119. if (!bCheckDestSurfaceOverlap(psoDest,prclDest))
  1120. {
  1121. FIXUP_THREAD_UMPDOBJS;
  1122. return(TRUE);
  1123. }
  1124. if (bRet)
  1125. {
  1126. ULONG cx, cy;
  1127. BRUSHOBJ boTemp;
  1128. pco = pUMObjs->GetDDIOBJ(pco, &psoDest->sizlBitmap);
  1129. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  1130. //
  1131. // EngStretchBlt does trimming and checking of the rectangles,
  1132. // but it assumes the src rect is well-ordered, check here.
  1133. //
  1134. bRet = (!ROP4NEEDSRC(rop4) || bOrder(prclSrc)) && bCheckXlate(psoSrc, pxlo) &&
  1135. (!ROP4NEEDMASK(rop4) || psoMask || PROBEDISPATBRUSH(pbo));
  1136. if (ROP4NEEDMASK(rop4) && (!psoMask || !pptlMask))
  1137. bRet = FALSE;
  1138. if (bRet && (rop4 == 0XAACC) && psoMask)
  1139. {
  1140. RECTL rclMask, *prclMask;
  1141. ULONG cx, cy;
  1142. if (bRet = bCheckSurfaceRectSize(psoSrc, prclSrc, NULL, &cx, &cy))
  1143. {
  1144. prclMask = pRect(pptlMask, &rclMask, cx, cy);
  1145. bRet = bCheckMask(psoMask, prclMask);
  1146. }
  1147. }
  1148. MAP_UM_BRUSHOBJ(pUMObjs, pbo, &boTemp);
  1149. bRet = bRet &&
  1150. EngStretchBltROP(psoDest,
  1151. psoSrc,
  1152. psoMask,
  1153. pco,
  1154. pxlo,
  1155. pca,
  1156. pptlHTOrg,
  1157. prclDest,
  1158. prclSrc,
  1159. pptlMask,
  1160. iMode,
  1161. pbo,
  1162. rop4);
  1163. }
  1164. }
  1165. else
  1166. {
  1167. bRet = FALSE;
  1168. }
  1169. FIXUP_THREAD_UMPDOBJS;
  1170. return (bRet);
  1171. }
  1172. BOOL APIENTRY NtGdiEngPlgBlt(
  1173. SURFOBJ *psoTrg,
  1174. SURFOBJ *psoSrc,
  1175. SURFOBJ *psoMsk,
  1176. CLIPOBJ *pco,
  1177. XLATEOBJ *pxlo,
  1178. COLORADJUSTMENT *pca,
  1179. POINTL *pptlBrushOrg,
  1180. POINTFIX *pptfxDest,
  1181. RECTL *prclSrc,
  1182. POINTL *pptlMask,
  1183. ULONG iMode
  1184. )
  1185. {
  1186. BOOL bRet = TRUE;
  1187. RECTL rcl;
  1188. POINTL ptl, ptlBrushOrg;
  1189. POINTFIX pptfx[3];
  1190. COLORADJUSTMENT ca;
  1191. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1192. UMPDSURFOBJ umsoTrg(psoTrg, pUMObjs);
  1193. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  1194. UMPDSURFOBJ umsoMsk(psoMsk, pUMObjs);
  1195. psoTrg = umsoTrg.pso();
  1196. psoSrc = umsoSrc.pso();
  1197. psoMsk = umsoMsk.pso();
  1198. if (psoTrg && psoSrc && prclSrc && pptfxDest)
  1199. {
  1200. __try
  1201. {
  1202. CaptureRECTL(&prclSrc, &rcl);
  1203. CaptureCOLORADJUSTMENT(&pca, &ca);
  1204. CapturePOINTL(&pptlMask, &ptl);
  1205. CapturePOINTL(&pptlBrushOrg, &ptlBrushOrg);
  1206. CaptureBits(pptfx, pptfxDest, sizeof(POINTFIX)*3);
  1207. }
  1208. __except(EXCEPTION_EXECUTE_HANDLER)
  1209. {
  1210. WARNING ("NtGdiEngPlgBlt failed in try/except\n");
  1211. bRet = FALSE;
  1212. }
  1213. if (bRet)
  1214. {
  1215. ULONG cx, cy;
  1216. pco = pUMObjs->GetDDIOBJ(pco, &psoTrg->sizlBitmap);
  1217. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  1218. //
  1219. // EngPlgBlt does the rectangle trimming and checking of dest and src
  1220. //
  1221. if (bRet = (bCheckRect(prclSrc) && bCheckXlate(psoSrc, pxlo)))
  1222. {
  1223. if (psoMsk)
  1224. {
  1225. RECTL rclMask, *prclMask;
  1226. ULONG cx, cy;
  1227. if (bRet = bCheckSurfaceRectSize(psoSrc, prclSrc, NULL, &cx, &cy))
  1228. {
  1229. prclMask = pRect(pptlMask, &rclMask, cx, cy);
  1230. bRet = bCheckMask(psoMsk, prclMask);
  1231. }
  1232. }
  1233. if (bRet)
  1234. bRet = EngPlgBlt(psoTrg,
  1235. psoSrc,
  1236. psoMsk,
  1237. pco,
  1238. pxlo,
  1239. pca,
  1240. &ptlBrushOrg,
  1241. pptfx,
  1242. prclSrc,
  1243. pptlMask,
  1244. iMode);
  1245. }
  1246. }
  1247. }
  1248. else
  1249. {
  1250. bRet = FALSE;
  1251. }
  1252. FIXUP_THREAD_UMPDOBJS;
  1253. return (bRet);
  1254. }
  1255. SURFOBJ *APIENTRY NtGdiEngLockSurface(
  1256. IN HSURF hsurf
  1257. )
  1258. {
  1259. EXTRACT_THREAD_UMPDOBJS(NULL);
  1260. SURFOBJ *surfRet = pUMObjs->LockSurface(hsurf);
  1261. FIXUP_THREAD_UMPDOBJS;
  1262. return (surfRet);
  1263. }
  1264. VOID APIENTRY NtGdiEngUnlockSurface(
  1265. IN SURFOBJ *pso
  1266. )
  1267. {
  1268. EXTRACT_THREAD_UMPDOBJS;
  1269. pUMObjs->UnlockSurface(pso);
  1270. FIXUP_THREAD_UMPDOBJS;
  1271. }
  1272. BOOL APIENTRY NtGdiEngBitBlt(
  1273. IN SURFOBJ *psoDst,
  1274. IN SURFOBJ *psoSrc,
  1275. IN SURFOBJ *psoMask,
  1276. IN CLIPOBJ *pco,
  1277. IN XLATEOBJ *pxlo,
  1278. IN RECTL *prclDst,
  1279. IN POINTL *pptlSrc,
  1280. IN POINTL *pptlMask,
  1281. IN BRUSHOBJ *pbo,
  1282. IN POINTL *pptlBrush,
  1283. IN ROP4 rop4
  1284. )
  1285. {
  1286. BOOL bRet = TRUE;
  1287. RECTL rclDst;
  1288. POINTL ptlSrc, ptlMask, ptlBrush;
  1289. BRUSHOBJ boTemp;
  1290. TRACE_INIT (("Entering NtGdiEngBitBlt\n"));
  1291. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1292. UMPDSURFOBJ umsoDst(psoDst, pUMObjs);
  1293. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  1294. UMPDSURFOBJ umsoMask(psoMask, pUMObjs);
  1295. psoDst = umsoDst.pso();
  1296. psoSrc = umsoSrc.pso();
  1297. psoMask = umsoMask.pso();
  1298. MAP_UM_BRUSHOBJ(pUMObjs, pbo, &boTemp);
  1299. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  1300. if (((rop4 & 0xffff0000) != 0) ||
  1301. !prclDst ||
  1302. (ROP4NEEDPAT(rop4) && (!pbo || ISPATBRUSH(pbo) && !pptlBrush)) ||
  1303. (ROP4NEEDSRC(rop4) && !(pptlSrc && psoSrc)) ||
  1304. (ROP4NEEDMASK(rop4) && !(psoMask || ISPATBRUSH(pbo))))
  1305. {
  1306. WARNING ("NtGdiEngBitBlt invalid parameters passed in\n");
  1307. FIXUP_THREAD_UMPDOBJS;
  1308. return FALSE;
  1309. }
  1310. if (psoDst)
  1311. {
  1312. __try
  1313. {
  1314. CaptureRECTL(&prclDst, &rclDst);
  1315. CapturePOINTL(&pptlSrc, &ptlSrc);
  1316. CapturePOINTL(&pptlMask, &ptlMask);
  1317. CapturePOINTL(&pptlBrush, &ptlBrush);
  1318. }
  1319. __except(EXCEPTION_EXECUTE_HANDLER)
  1320. {
  1321. WARNING ("NtGdiEngBitBlt failed in try/except\n");
  1322. bRet = FALSE;
  1323. }
  1324. if (bRet)
  1325. {
  1326. ULONG cx, cy;
  1327. pco = pUMObjs->GetDDIOBJ(pco, &psoDst->sizlBitmap);
  1328. if (bRet = bCheckSurfaceRectSize(psoDst, prclDst, pco, &cx, &cy) &&
  1329. bCheckXlate(psoSrc, pxlo))
  1330. {
  1331. RECTL rclSrc, *prclSrc;
  1332. RECTL rclMask, *prclMask;
  1333. prclSrc = psoSrc ? pRect(pptlSrc, &rclSrc, cx, cy) : NULL;
  1334. prclMask = psoMask ? pRect(pptlMask, &rclMask, cx, cy) : NULL;
  1335. if (bRet = (bCheckSurfaceRect(psoSrc, prclSrc, NULL) &&
  1336. bCheckMask(psoMask, prclMask)))
  1337. {
  1338. bRet = EngBitBlt(psoDst,
  1339. psoSrc,
  1340. psoMask,
  1341. pco,
  1342. pxlo,
  1343. prclDst,
  1344. pptlSrc,
  1345. pptlMask,
  1346. pbo,
  1347. pptlBrush,
  1348. rop4);
  1349. }
  1350. }
  1351. }
  1352. }
  1353. else
  1354. bRet = FALSE;
  1355. FIXUP_THREAD_UMPDOBJS;
  1356. return (bRet);
  1357. }
  1358. BOOL APIENTRY NtGdiEngStrokePath(
  1359. SURFOBJ *pso,
  1360. PATHOBJ *ppo,
  1361. CLIPOBJ *pco,
  1362. XFORMOBJ *pxo,
  1363. BRUSHOBJ *pbo,
  1364. POINTL *pptlBrushOrg,
  1365. LINEATTRS *plineattrs,
  1366. MIX mix
  1367. )
  1368. {
  1369. BOOL bRet = TRUE;
  1370. POINTL ptl;
  1371. LINEATTRS line;
  1372. BRUSHOBJ boTemp;
  1373. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1374. TRACE_INIT (("Entering NtGdiEngStrokePath\n"));
  1375. UMPDSURFOBJ umso(pso, pUMObjs);
  1376. pso = umso.pso();
  1377. ppo = pUMObjs->GetDDIOBJ(ppo);
  1378. MAP_UM_BRUSHOBJ(pUMObjs, pbo, &boTemp);
  1379. if (pso && pbo && ppo && plineattrs && pptlBrushOrg)
  1380. {
  1381. __try
  1382. {
  1383. CapturePOINTL(&pptlBrushOrg, &ptl);
  1384. }
  1385. __except(EXCEPTION_EXECUTE_HANDLER)
  1386. {
  1387. WARNING ("NtGdiEngStrokePath failed in try/except\n");
  1388. bRet = FALSE;
  1389. }
  1390. if (bRet)
  1391. bRet = bCaptureLINEATTRS(&plineattrs, &line);
  1392. if (bRet)
  1393. {
  1394. pco = pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap);
  1395. pxo = pUMObjs->GetDDIOBJ(pxo);
  1396. if ((plineattrs->fl & LA_GEOMETRIC) && pxo == 0)
  1397. bRet = FALSE;
  1398. bRet = bRet && bCheckSurfacePath(pso, ppo, pco) &&
  1399. (!MIXNEEDMASK(mix) || ISPATBRUSH(pbo)) &&
  1400. EngStrokePath(pso,
  1401. ppo,
  1402. pco,
  1403. pxo,
  1404. pbo,
  1405. pptlBrushOrg,
  1406. plineattrs,
  1407. mix);
  1408. if (plineattrs && plineattrs->pstyle)
  1409. VFREEMEM(plineattrs->pstyle);
  1410. }
  1411. }
  1412. else
  1413. bRet = FALSE;
  1414. FIXUP_THREAD_UMPDOBJS;
  1415. return (bRet);
  1416. }
  1417. BOOL APIENTRY NtGdiEngFillPath(
  1418. SURFOBJ *pso,
  1419. PATHOBJ *ppo,
  1420. CLIPOBJ *pco,
  1421. BRUSHOBJ *pbo,
  1422. POINTL *pptlBrushOrg,
  1423. MIX mix,
  1424. FLONG flOptions
  1425. )
  1426. {
  1427. BOOL bRet = FALSE;
  1428. POINTL ptlBrushOrg;
  1429. BRUSHOBJ boTemp;
  1430. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1431. UMPDSURFOBJ umso(pso, pUMObjs);
  1432. pso = umso.pso();
  1433. ppo = pUMObjs->GetDDIOBJ(ppo);
  1434. pco = pso ? pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap) : NULL;
  1435. MAP_UM_BRUSHOBJ(pUMObjs, pbo, &boTemp);
  1436. if (pso && pbo && ppo && pco && (pco->iMode == TC_RECTANGLES) && pptlBrushOrg)
  1437. {
  1438. __try
  1439. {
  1440. CapturePOINTL(&pptlBrushOrg, &ptlBrushOrg);
  1441. bRet = TRUE;
  1442. }
  1443. __except(EXCEPTION_EXECUTE_HANDLER)
  1444. {
  1445. WARNING ("NtGdiEngFillPath failed in try/except\n");
  1446. }
  1447. bRet = bRet &&
  1448. bCheckSurfacePath(pso, ppo, pco) &&
  1449. (!MIXNEEDMASK(mix) || ISPATBRUSH(pbo)) &&
  1450. EngFillPath(pso,
  1451. ppo,
  1452. pco,
  1453. pbo,
  1454. pptlBrushOrg,
  1455. mix,
  1456. flOptions);
  1457. }
  1458. FIXUP_THREAD_UMPDOBJS;
  1459. return (bRet);
  1460. }
  1461. BOOL APIENTRY NtGdiEngStrokeAndFillPath(
  1462. SURFOBJ *pso,
  1463. PATHOBJ *ppo,
  1464. CLIPOBJ *pco,
  1465. XFORMOBJ *pxo,
  1466. BRUSHOBJ *pboStroke,
  1467. LINEATTRS *plineattrs,
  1468. BRUSHOBJ *pboFill,
  1469. POINTL *pptlBrushOrg,
  1470. MIX mixFill,
  1471. FLONG flOptions
  1472. )
  1473. {
  1474. BOOL bRet = FALSE;
  1475. POINTL ptl;
  1476. LINEATTRS line;
  1477. BRUSHOBJ boTempStroke, boTempFill;
  1478. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1479. UMPDSURFOBJ umso(pso, pUMObjs);
  1480. pso = umso.pso();
  1481. ppo = pUMObjs->GetDDIOBJ(ppo);
  1482. pco = pso ? pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap) : NULL;
  1483. MAP_UM_BRUSHOBJ(pUMObjs, pboStroke, &boTempStroke);
  1484. MAP_UM_BRUSHOBJ(pUMObjs, pboFill, &boTempFill);
  1485. if (pso && pboStroke && pboFill && ppo && plineattrs && pco && pptlBrushOrg)
  1486. {
  1487. __try
  1488. {
  1489. CapturePOINTL(&pptlBrushOrg, &ptl);
  1490. bRet = TRUE;
  1491. }
  1492. __except(EXCEPTION_EXECUTE_HANDLER)
  1493. {
  1494. WARNING ("NtGdiEngStrokeAndFillPath failed in try/except\n");
  1495. }
  1496. if (bRet)
  1497. bRet = bCaptureLINEATTRS(&plineattrs, &line);
  1498. if (bRet)
  1499. {
  1500. pxo = pUMObjs->GetDDIOBJ(pxo);
  1501. if ((plineattrs->fl & LA_GEOMETRIC) && pxo == 0)
  1502. bRet = FALSE;
  1503. bRet = bRet && bCheckSurfacePath(pso, ppo, pco) &&
  1504. (!MIXNEEDMASK(mixFill) || ISPATBRUSH(pboFill)) &&
  1505. EngStrokeAndFillPath(pso,
  1506. ppo,
  1507. pco,
  1508. pxo,
  1509. pboStroke,
  1510. plineattrs,
  1511. pboFill,
  1512. pptlBrushOrg,
  1513. mixFill,
  1514. flOptions);
  1515. if (plineattrs && plineattrs->pstyle)
  1516. VFREEMEM(plineattrs->pstyle);
  1517. }
  1518. }
  1519. FIXUP_THREAD_UMPDOBJS;
  1520. return bRet;
  1521. }
  1522. BOOL APIENTRY
  1523. NtGdiEngPaint(
  1524. SURFOBJ *pso,
  1525. CLIPOBJ *pco,
  1526. BRUSHOBJ *pbo,
  1527. POINTL *pptlBrushOrg,
  1528. MIX mix
  1529. )
  1530. {
  1531. POINTL ptlBrushOrg;
  1532. BOOL bRet = TRUE;
  1533. BRUSHOBJ boTemp;
  1534. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1535. UMPDSURFOBJ umso(pso, pUMObjs);
  1536. pso = umso.pso();
  1537. pco = pso ? pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap) : NULL;
  1538. MAP_UM_BRUSHOBJ(pUMObjs, pbo, &boTemp);
  1539. if (pso && pco && (pco->iMode == TC_RECTANGLES) && (mix & 0xff00))
  1540. {
  1541. __try
  1542. {
  1543. CapturePOINTL(&pptlBrushOrg, &ptlBrushOrg);
  1544. }
  1545. __except(EXCEPTION_EXECUTE_HANDLER)
  1546. {
  1547. WARNING ("NtGdiEngPaint failed in try/except\n");
  1548. bRet = FALSE;
  1549. }
  1550. if (bRet && (bRet = bCheckSurfaceRect(pso, NULL, pco)))
  1551. {
  1552. bRet = EngPaint(pso, pco, pbo, pptlBrushOrg, mix);
  1553. }
  1554. }
  1555. else
  1556. bRet = FALSE;
  1557. FIXUP_THREAD_UMPDOBJS;
  1558. return bRet;
  1559. }
  1560. BOOL APIENTRY NtGdiEngLineTo(
  1561. SURFOBJ *pso,
  1562. CLIPOBJ *pco,
  1563. BRUSHOBJ *pbo,
  1564. LONG x1,
  1565. LONG y1,
  1566. LONG x2,
  1567. LONG y2,
  1568. RECTL *prclBounds,
  1569. MIX mix
  1570. )
  1571. {
  1572. BOOL bRet = TRUE;
  1573. RECTL rcl;
  1574. RECTL rclline = {x1,y1,x2,y2};
  1575. BRUSHOBJ boTemp;
  1576. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1577. UMPDSURFOBJ umso(pso, pUMObjs);
  1578. pso = umso.pso();
  1579. MAP_UM_BRUSHOBJ(pUMObjs, pbo, &boTemp);
  1580. if (pso && pbo)
  1581. {
  1582. __try
  1583. {
  1584. CaptureRECTL(&prclBounds, &rcl);
  1585. }
  1586. __except(EXCEPTION_EXECUTE_HANDLER)
  1587. {
  1588. WARNING ("NtGdiEngLineTo failed in try/except\n");
  1589. bRet = FALSE;
  1590. }
  1591. if (bRet)
  1592. {
  1593. pco = pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap);
  1594. if (bRet = bCheckSurfaceRect(pso, &rclline, pco))
  1595. {
  1596. bRet = EngLineTo(pso,
  1597. pco,
  1598. pbo,
  1599. x1,
  1600. y1,
  1601. x2,
  1602. y2,
  1603. prclBounds,
  1604. mix);
  1605. }
  1606. }
  1607. }
  1608. else
  1609. bRet = FALSE;
  1610. FIXUP_THREAD_UMPDOBJS;
  1611. return (bRet);
  1612. }
  1613. BOOL APIENTRY NtGdiEngAlphaBlend(
  1614. SURFOBJ *psoDest,
  1615. SURFOBJ *psoSrc,
  1616. CLIPOBJ *pco,
  1617. XLATEOBJ *pxlo,
  1618. RECTL *prclDest,
  1619. RECTL *prclSrc,
  1620. BLENDOBJ *pBlendObj
  1621. )
  1622. {
  1623. BOOL bRet = TRUE;
  1624. RECTL rclDest, rclSrc;
  1625. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1626. UMPDSURFOBJ umsoDest(psoDest, pUMObjs);
  1627. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  1628. pBlendObj = pUMObjs->GetDDIOBJ(pBlendObj);
  1629. psoDest = umsoDest.pso();
  1630. psoSrc = umsoSrc.pso();
  1631. if (psoDest && psoSrc && pBlendObj && prclDest && prclSrc)
  1632. {
  1633. __try
  1634. {
  1635. CaptureRECTL(&prclSrc, &rclSrc);
  1636. CaptureRECTL(&prclDest, &rclDest);
  1637. }
  1638. __except(EXCEPTION_EXECUTE_HANDLER)
  1639. {
  1640. WARNING ("NtGdiEngAlphaBlend failed in try/except\n");
  1641. bRet = FALSE;
  1642. }
  1643. if (bRet && bOrder(prclSrc) && bOrder(prclDest))
  1644. {
  1645. pco = pUMObjs->GetDDIOBJ(pco, &psoDest->sizlBitmap);
  1646. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  1647. if (bRet = (bCheckSurfaceRect(psoSrc, prclSrc, NULL) && bCheckXlate(psoSrc, pxlo)))
  1648. {
  1649. bRet = EngAlphaBlend(psoDest,
  1650. psoSrc,
  1651. pco,
  1652. pxlo,
  1653. prclDest,
  1654. prclSrc,
  1655. pBlendObj);
  1656. }
  1657. }
  1658. }
  1659. else
  1660. bRet = FALSE;
  1661. FIXUP_THREAD_UMPDOBJS;
  1662. return (bRet);
  1663. }
  1664. //
  1665. // Make sure the Vertex and Mesh data are valid. i.e that they are bounded
  1666. // within each other.
  1667. //
  1668. __inline
  1669. BOOL bValidVertexMeshData(
  1670. TRIVERTEX *pVertex,
  1671. PVOID pMeshIn,
  1672. ULONG nVertex,
  1673. ULONG nMesh,
  1674. ULONG ulMode)
  1675. {
  1676. ULONG ulIndex;
  1677. if (nVertex <= 1)
  1678. return FALSE;
  1679. PTRIVERTEX pTVb = pVertex;
  1680. PTRIVERTEX pTVe = pVertex + nVertex - 1;
  1681. PTRIVERTEX pTV;
  1682. switch (ulMode)
  1683. {
  1684. case GRADIENT_FILL_RECT_H:
  1685. case GRADIENT_FILL_RECT_V:
  1686. {
  1687. PGRADIENT_RECT pMesh = (PGRADIENT_RECT)pMeshIn;
  1688. for (ulIndex = 0; ulIndex < nMesh; ulIndex++)
  1689. {
  1690. pTV = pTVb + pMesh[ulIndex].UpperLeft;
  1691. if (!(pTV >= pTVb && pTV <= pTVe))
  1692. return FALSE;
  1693. pTV = pTVb + pMesh[ulIndex].LowerRight;
  1694. if (!(pTV >= pTVb && pTV <= pTVe))
  1695. return FALSE;
  1696. }
  1697. }
  1698. break;
  1699. case GRADIENT_FILL_TRIANGLE:
  1700. {
  1701. PGRADIENT_TRIANGLE pMesh = (PGRADIENT_TRIANGLE)pMeshIn;
  1702. for (ulIndex = 0; ulIndex < nMesh; ulIndex++)
  1703. {
  1704. pTV = pTVb + pMesh[ulIndex].Vertex1;
  1705. if (!(pTV >= pTVb && pTV <= pTVe))
  1706. return FALSE;
  1707. pTV = pTVb + pMesh[ulIndex].Vertex2;
  1708. if (!(pTV >= pTVb && pTV <= pTVe))
  1709. return FALSE;
  1710. pTV = pTVb + pMesh[ulIndex].Vertex3;
  1711. if (!(pTV >= pTVb && pTV <= pTVe))
  1712. return FALSE;
  1713. }
  1714. }
  1715. break;
  1716. default:
  1717. return FALSE;
  1718. }
  1719. return TRUE;
  1720. }
  1721. BOOL APIENTRY NtGdiEngGradientFill(
  1722. SURFOBJ *psoDest,
  1723. CLIPOBJ *pco,
  1724. XLATEOBJ *pxlo,
  1725. TRIVERTEX *pVertex,
  1726. ULONG nVertex,
  1727. PVOID pMesh,
  1728. ULONG nMesh,
  1729. RECTL *prclExtents,
  1730. POINTL *pptlDitherOrg,
  1731. ULONG ulMode
  1732. )
  1733. {
  1734. BOOL bRet = TRUE;
  1735. RECTL rcl;
  1736. POINTL ptl;
  1737. TRIVERTEX *pVertexTmp = (TRIVERTEX *)NULL;
  1738. PVOID pMeshTmp = NULL;
  1739. ULONG cjMesh;
  1740. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1741. UMPDSURFOBJ umsoDest(psoDest, pUMObjs);
  1742. psoDest = umsoDest.pso();
  1743. switch (ulMode)
  1744. {
  1745. case GRADIENT_FILL_RECT_H:
  1746. case GRADIENT_FILL_RECT_V:
  1747. cjMesh = sizeof(GRADIENT_RECT);
  1748. if (BALLOC_OVERFLOW1(nMesh, GRADIENT_RECT))
  1749. {
  1750. FIXUP_THREAD_UMPDOBJS;
  1751. return FALSE;
  1752. }
  1753. break;
  1754. case GRADIENT_FILL_TRIANGLE:
  1755. cjMesh = sizeof(GRADIENT_TRIANGLE);
  1756. if (BALLOC_OVERFLOW1(nMesh, GRADIENT_TRIANGLE))
  1757. {
  1758. FIXUP_THREAD_UMPDOBJS;
  1759. return FALSE;
  1760. }
  1761. break;
  1762. default:
  1763. WARNING ("Invalid ulMode in DrvGradientFill\n");
  1764. FIXUP_THREAD_UMPDOBJS;
  1765. return FALSE;
  1766. }
  1767. if (nMesh == 0 || nVertex == 0)
  1768. {
  1769. FIXUP_THREAD_UMPDOBJS;
  1770. return TRUE;
  1771. }
  1772. cjMesh *= nMesh;
  1773. if (BALLOC_OVERFLOW1(nVertex, TRIVERTEX))
  1774. {
  1775. FIXUP_THREAD_UMPDOBJS;
  1776. return FALSE;
  1777. }
  1778. pVertexTmp = (TRIVERTEX *)PALLOCNOZ (sizeof(TRIVERTEX)*nVertex, UMPD_MEMORY_TAG);
  1779. pMeshTmp = PALLOCNOZ (cjMesh, UMPD_MEMORY_TAG);
  1780. if (psoDest && pVertex && pMesh && pVertexTmp && pMeshTmp && prclExtents && pptlDitherOrg)
  1781. {
  1782. __try
  1783. {
  1784. CaptureRECTL(&prclExtents, &rcl);
  1785. CapturePOINTL(&pptlDitherOrg, &ptl);
  1786. CaptureBits(pVertexTmp, pVertex, sizeof(TRIVERTEX)*nVertex);
  1787. CaptureBits(pMeshTmp, pMesh, cjMesh);
  1788. }
  1789. __except(EXCEPTION_EXECUTE_HANDLER)
  1790. {
  1791. WARNING ("NtGdiEngAlphaBlend failed in try/except\n");
  1792. bRet = FALSE;
  1793. }
  1794. bRet = bRet && bValidVertexMeshData(pVertexTmp,pMeshTmp,nVertex,nMesh,ulMode);
  1795. if (bRet)
  1796. {
  1797. pco = pUMObjs->GetDDIOBJ(pco, &psoDest->sizlBitmap);
  1798. bRet = EngGradientFill(psoDest,
  1799. pco,
  1800. pUMObjs->GetDDIOBJ(pxlo),
  1801. pVertexTmp,
  1802. nVertex,
  1803. pMeshTmp,
  1804. nMesh,
  1805. prclExtents,
  1806. pptlDitherOrg,
  1807. ulMode);
  1808. }
  1809. }
  1810. else
  1811. bRet = FALSE;
  1812. if (pVertexTmp)
  1813. VFREEMEM(pVertexTmp);
  1814. if (pMeshTmp)
  1815. VFREEMEM(pMeshTmp);
  1816. FIXUP_THREAD_UMPDOBJS;
  1817. return bRet;
  1818. }
  1819. BOOL APIENTRY NtGdiEngTransparentBlt(
  1820. SURFOBJ *psoDst,
  1821. SURFOBJ *psoSrc,
  1822. CLIPOBJ *pco,
  1823. XLATEOBJ *pxlo,
  1824. RECTL *prclDst,
  1825. RECTL *prclSrc,
  1826. ULONG iTransColor,
  1827. ULONG ulReserved
  1828. )
  1829. {
  1830. BOOL bRet = TRUE;
  1831. RECTL rclDst, rclSrc;
  1832. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1833. UMPDSURFOBJ umsoDst(psoDst, pUMObjs);
  1834. UMPDSURFOBJ umsoSrc(psoSrc, pUMObjs);
  1835. psoDst = umsoDst.pso();
  1836. psoSrc = umsoSrc.pso();
  1837. if (psoDst && psoSrc && prclDst && prclSrc)
  1838. {
  1839. __try
  1840. {
  1841. CaptureRECTL(&prclSrc, &rclSrc);
  1842. CaptureRECTL(&prclDst, &rclDst);
  1843. }
  1844. __except(EXCEPTION_EXECUTE_HANDLER)
  1845. {
  1846. WARNING ("NtGdiEngTransparentBlt failed in try/except\n");
  1847. bRet = FALSE;
  1848. }
  1849. if (bRet && bOrder(prclDst) && bOrder(prclSrc))
  1850. {
  1851. pco = pUMObjs->GetDDIOBJ(pco, &psoDst->sizlBitmap);
  1852. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  1853. if (bRet = (bCheckSurfaceRect(psoSrc, prclSrc, NULL) && bCheckXlate(psoSrc, pxlo)))
  1854. {
  1855. bRet = EngTransparentBlt(psoDst,
  1856. psoSrc,
  1857. pco,
  1858. pxlo,
  1859. prclDst,
  1860. prclSrc,
  1861. iTransColor,
  1862. ulReserved);
  1863. }
  1864. }
  1865. }
  1866. else
  1867. bRet = FALSE;
  1868. FIXUP_THREAD_UMPDOBJS;
  1869. return (bRet);
  1870. }
  1871. BOOL APIENTRY NtGdiEngTextOut(
  1872. SURFOBJ *pso,
  1873. STROBJ *pstro,
  1874. FONTOBJ *pfo,
  1875. CLIPOBJ *pco,
  1876. RECTL *prclExtra,
  1877. RECTL *prclOpaque,
  1878. BRUSHOBJ *pboFore,
  1879. BRUSHOBJ *pboOpaque,
  1880. POINTL *pptlOrg,
  1881. MIX mix
  1882. )
  1883. {
  1884. BOOL bRet = TRUE;
  1885. RECTL rclExtra, rclOpaque;
  1886. POINTL ptlOrg;
  1887. BRUSHOBJ boTempFore, boTempOpaque;
  1888. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1889. UMPDSURFOBJ umso(pso, pUMObjs);
  1890. pso = umso.pso();
  1891. pstro = pUMObjs->GetDDIOBJ(pstro);
  1892. pfo = pUMObjs->GetDDIOBJ(pfo);
  1893. MAP_UM_BRUSHOBJ(pUMObjs, pboFore, &boTempFore);
  1894. MAP_UM_BRUSHOBJ(pUMObjs, pboOpaque, &boTempOpaque);
  1895. if (pso && pstro && pfo && pboFore && pptlOrg)
  1896. {
  1897. __try
  1898. {
  1899. CaptureRECTL(&prclExtra, &rclExtra);
  1900. CaptureRECTL(&prclOpaque, &rclOpaque);
  1901. CapturePOINTL(&pptlOrg, &ptlOrg);
  1902. }
  1903. __except(EXCEPTION_EXECUTE_HANDLER)
  1904. {
  1905. WARNING ("NtGdiEngTextOut failed in try/except\n");
  1906. bRet = FALSE;
  1907. }
  1908. if (bRet)
  1909. {
  1910. pco = pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap);
  1911. if (bRet = (!MIXNEEDMASK(mix) || ISPATBRUSH(pboFore)) &&
  1912. bCheckSurfaceRect(pso, prclOpaque, pco))
  1913. {
  1914. RFONTTMPOBJ rfto(PFO_TO_PRF(pfo));
  1915. UMPDAcquireRFONTSem(rfto, pUMObjs, 0, 0, NULL);
  1916. bRet = EngTextOut(pso,
  1917. pstro,
  1918. pfo,
  1919. pco,
  1920. prclExtra,
  1921. prclOpaque,
  1922. pboFore,
  1923. pboOpaque,
  1924. pptlOrg,
  1925. mix);
  1926. UMPDReleaseRFONTSem(rfto, pUMObjs, NULL, NULL, NULL);
  1927. }
  1928. }
  1929. }
  1930. else
  1931. bRet = FALSE;
  1932. FIXUP_THREAD_UMPDOBJS;
  1933. return (bRet);
  1934. }
  1935. HPALETTE APIENTRY NtGdiEngCreatePalette(
  1936. ULONG iMode,
  1937. ULONG cColors,
  1938. ULONG *pulColors,
  1939. FLONG flRed,
  1940. FLONG flGreen,
  1941. FLONG flBlue
  1942. )
  1943. {
  1944. HPALETTE hpal = (HPALETTE)1;
  1945. ULONG pulColorsTmp[256];
  1946. HANDLE hSecure = 0;
  1947. TRACE_INIT (("Entering NtGdiEngCreatePalette\n"));
  1948. //
  1949. // cColors has a limit of 64k
  1950. //
  1951. if (cColors > 64 * 1024)
  1952. return 0;
  1953. if ((iMode == PAL_INDEXED) && cColors)
  1954. {
  1955. if (cColors > 256)
  1956. hpal = (HPALETTE)(ULONG_PTR)bSecureBits(pulColors, cColors*sizeof(ULONG), &hSecure);
  1957. else
  1958. {
  1959. hpal = (HPALETTE)(ULONG_PTR)bSafeReadBits(pulColorsTmp, pulColors, cColors*sizeof(ULONG));
  1960. }
  1961. }
  1962. if (hpal)
  1963. {
  1964. //
  1965. // set the high bit of iMode to indicate umpd driver
  1966. //
  1967. iMode |= UMPD_FLAG;
  1968. hpal = EngCreatePalette(iMode, cColors, pulColors, flRed, flGreen, flBlue);
  1969. }
  1970. if (hSecure)
  1971. {
  1972. MmUnsecureVirtualMemory(hSecure);
  1973. }
  1974. return hpal;
  1975. }
  1976. BOOL APIENTRY NtGdiEngDeletePalette(
  1977. IN HPALETTE hpal
  1978. )
  1979. {
  1980. TRACE_INIT (("Entering NtGdiEngDeletePalette\n"));
  1981. //
  1982. // EngDeletePalette will check if hpal is valid
  1983. // so we don't need to check hpal here
  1984. //
  1985. return (EngDeletePalette(hpal));
  1986. }
  1987. BOOL APIENTRY NtGdiEngEraseSurface(
  1988. IN SURFOBJ *pso,
  1989. IN RECTL *prcl,
  1990. IN ULONG iColor
  1991. )
  1992. {
  1993. BOOL bRet = TRUE;
  1994. RECTL rcl;
  1995. EXTRACT_THREAD_UMPDOBJS(FALSE);
  1996. UMPDSURFOBJ umso(pso, pUMObjs);
  1997. pso = umso.pso();
  1998. if (pso)
  1999. {
  2000. __try
  2001. {
  2002. CaptureRECTL(&prcl, &rcl);
  2003. }
  2004. __except(EXCEPTION_EXECUTE_HANDLER)
  2005. {
  2006. WARNING ("NtGdiEngEraseSurface failed in try/except\n");
  2007. bRet = FALSE;
  2008. }
  2009. if (bRet)
  2010. {
  2011. if (bRet = bCheckSurfaceRect(pso, prcl, NULL))
  2012. {
  2013. bRet = EngEraseSurface(pso, prcl, iColor);
  2014. }
  2015. }
  2016. }
  2017. else
  2018. bRet = FALSE;
  2019. FIXUP_THREAD_UMPDOBJS;
  2020. return bRet;
  2021. }
  2022. PATHOBJ* APIENTRY NtGdiCLIPOBJ_ppoGetPath(
  2023. CLIPOBJ *pco
  2024. )
  2025. {
  2026. EXTRACT_THREAD_UMPDOBJS(NULL);
  2027. PATHOBJ* poRet = pUMObjs->GetCLIPOBJPath(pco);
  2028. FIXUP_THREAD_UMPDOBJS;
  2029. return poRet;
  2030. }
  2031. VOID APIENTRY NtGdiEngDeletePath(
  2032. IN PATHOBJ *ppo
  2033. )
  2034. {
  2035. EXTRACT_THREAD_UMPDOBJS;
  2036. pUMObjs->DeleteCLIPOBJPath(ppo);
  2037. FIXUP_THREAD_UMPDOBJS;
  2038. }
  2039. CLIPOBJ* APIENTRY NtGdiEngCreateClip()
  2040. {
  2041. EXTRACT_THREAD_UMPDOBJS(NULL);
  2042. CLIPOBJ* clipRet = pUMObjs->CreateCLIPOBJ();
  2043. FIXUP_THREAD_UMPDOBJS;
  2044. return clipRet;
  2045. }
  2046. VOID APIENTRY NtGdiEngDeleteClip(
  2047. CLIPOBJ *pco
  2048. )
  2049. {
  2050. EXTRACT_THREAD_UMPDOBJS;
  2051. pUMObjs->DeleteCLIPOBJ(pco);
  2052. FIXUP_THREAD_UMPDOBJS;
  2053. }
  2054. ULONG APIENTRY NtGdiCLIPOBJ_cEnumStart(
  2055. CLIPOBJ *pco,
  2056. BOOL bAll,
  2057. ULONG iType,
  2058. ULONG iDirection,
  2059. ULONG cLimit
  2060. )
  2061. {
  2062. EXTRACT_THREAD_UMPDOBJS(0xffffffff);
  2063. ULONG ulRet = 0xffffffff;
  2064. pco = pUMObjs->GetDDIOBJ(pco);
  2065. if (pco)
  2066. {
  2067. ulRet = CLIPOBJ_cEnumStart(pco,
  2068. bAll,
  2069. iType,
  2070. iDirection,
  2071. cLimit);
  2072. }
  2073. FIXUP_THREAD_UMPDOBJS;
  2074. return ulRet;
  2075. }
  2076. BOOL APIENTRY NtGdiCLIPOBJ_bEnum(
  2077. CLIPOBJ *pco,
  2078. ULONG cj,
  2079. ULONG *pul
  2080. )
  2081. {
  2082. BOOL bRet = DDI_ERROR;
  2083. ULONG *pulTmp;
  2084. EXTRACT_THREAD_UMPDOBJS(FALSE);
  2085. pco = pUMObjs->GetDDIOBJ(pco);
  2086. if (pco)
  2087. {
  2088. pulTmp = (PULONG)PALLOCNOZ(cj, UMPD_MEMORY_TAG);
  2089. if (pulTmp)
  2090. {
  2091. ULONG cjFilled = 0;
  2092. bRet = (*(XCLIPOBJ *)pco).bEnum(cj, pulTmp, &cjFilled);
  2093. if (bRet != DDI_ERROR)
  2094. if (!bSafeCopyBits(pul, pulTmp, cjFilled))
  2095. bRet = DDI_ERROR;
  2096. VFREEMEM(pulTmp);
  2097. }
  2098. }
  2099. FIXUP_THREAD_UMPDOBJS;
  2100. return bRet;
  2101. }
  2102. PVOID APIENTRY NtGdiBRUSHOBJ_pvAllocRbrush(
  2103. BRUSHOBJ *pbo,
  2104. ULONG cj
  2105. )
  2106. {
  2107. EXTRACT_THREAD_UMPDOBJS(NULL);
  2108. PVOID pvRet = ((pbo = pUMObjs->GetDDIOBJ(pbo)) != NULL) ?
  2109. BRUSHOBJ_pvAllocRbrushUMPD(pbo, cj) :
  2110. NULL;
  2111. FIXUP_THREAD_UMPDOBJS;
  2112. return pvRet;
  2113. }
  2114. PVOID APIENTRY NtGdiBRUSHOBJ_pvGetRbrush(
  2115. BRUSHOBJ *pbo
  2116. )
  2117. {
  2118. EXTRACT_THREAD_UMPDOBJS(NULL);
  2119. PVOID pvRet = ((pbo = pUMObjs->GetDDIOBJ(pbo)) != NULL) ?
  2120. BRUSHOBJ_pvGetRbrushUMPD(pbo) :
  2121. NULL;
  2122. FIXUP_THREAD_UMPDOBJS;
  2123. return pvRet;
  2124. }
  2125. ULONG APIENTRY NtGdiBRUSHOBJ_ulGetBrushColor(
  2126. BRUSHOBJ *pbo
  2127. )
  2128. {
  2129. EXTRACT_THREAD_UMPDOBJS(0);
  2130. ULONG ulRet = 0;
  2131. BRUSHOBJ *pbokm;
  2132. if (pbokm = pUMObjs->GetDDIOBJ(pbo))
  2133. {
  2134. if ((pbo->flColorType & BR_ORIGCOLOR) && ((EBRUSHOBJ*)pbokm)->bIsSolid())
  2135. {
  2136. pbokm->flColorType |= BR_ORIGCOLOR;
  2137. }
  2138. ulRet = BRUSHOBJ_ulGetBrushColor(pbokm);
  2139. pbo->flColorType &= ~BR_ORIGCOLOR;
  2140. }
  2141. FIXUP_THREAD_UMPDOBJS;
  2142. return ulRet;
  2143. }
  2144. HANDLE APIENTRY NtGdiBRUSHOBJ_hGetColorTransform(
  2145. BRUSHOBJ *pbo
  2146. )
  2147. {
  2148. EXTRACT_THREAD_UMPDOBJS(NULL);
  2149. HANDLE hRet = ((pbo = pUMObjs->GetDDIOBJ(pbo)) != NULL) ?
  2150. BRUSHOBJ_hGetColorTransform(pbo) :
  2151. NULL;
  2152. FIXUP_THREAD_UMPDOBJS;
  2153. return hRet;
  2154. }
  2155. BOOL APIENTRY NtGdiXFORMOBJ_bApplyXform(
  2156. XFORMOBJ *pxo,
  2157. ULONG iMode,
  2158. ULONG cPoints,
  2159. PVOID pvIn,
  2160. PVOID pvOut
  2161. )
  2162. #define APPLYXFORM_STACK_POINTS 4
  2163. {
  2164. POINTL ptlIn[APPLYXFORM_STACK_POINTS];
  2165. POINTL ptlOut[APPLYXFORM_STACK_POINTS];
  2166. PVOID pvInTmp, pvOutTmp;
  2167. BOOL bRet = FALSE;
  2168. if (BALLOC_OVERFLOW1(cPoints, POINTL))
  2169. return FALSE;
  2170. EXTRACT_THREAD_UMPDOBJS(FALSE);
  2171. pxo = pUMObjs->GetDDIOBJ(pxo);
  2172. if (pxo && pvIn && pvOut && cPoints)
  2173. {
  2174. if (cPoints <= APPLYXFORM_STACK_POINTS)
  2175. {
  2176. pvInTmp = ptlIn;
  2177. pvOutTmp = ptlOut;
  2178. }
  2179. else
  2180. {
  2181. pvInTmp = PALLOCNOZ(sizeof(POINTL)*cPoints, UMPD_MEMORY_TAG);
  2182. pvOutTmp = PALLOCNOZ(sizeof(POINTL)*cPoints, UMPD_MEMORY_TAG);
  2183. }
  2184. if (pvInTmp != NULL &&
  2185. pvOutTmp != NULL &&
  2186. bSafeReadBits(pvInTmp, pvIn, cPoints*sizeof(POINTL)))
  2187. {
  2188. bRet = XFORMOBJ_bApplyXform(pxo, iMode, cPoints, pvInTmp, pvOutTmp) &&
  2189. bSafeCopyBits(pvOut, pvOutTmp, cPoints*sizeof(POINTL));
  2190. }
  2191. if (cPoints > APPLYXFORM_STACK_POINTS)
  2192. {
  2193. if (pvInTmp != NULL)
  2194. VFREEMEM(pvInTmp);
  2195. if (pvOutTmp != NULL)
  2196. VFREEMEM(pvOutTmp);
  2197. }
  2198. }
  2199. FIXUP_THREAD_UMPDOBJS;
  2200. return (bRet);
  2201. }
  2202. ULONG APIENTRY NtGdiXFORMOBJ_iGetXform(
  2203. XFORMOBJ *pxo,
  2204. XFORML *pxform
  2205. )
  2206. {
  2207. ULONG ulRet = DDI_ERROR;
  2208. XFORML xform;
  2209. EXTRACT_THREAD_UMPDOBJS(DDI_ERROR);
  2210. pxo = pUMObjs->GetDDIOBJ(pxo);
  2211. if (pxo)
  2212. {
  2213. ulRet = XFORMOBJ_iGetXform(pxo, pxform? &xform : NULL);
  2214. if ((ulRet != DDI_ERROR) && pxform)
  2215. {
  2216. __try
  2217. {
  2218. ProbeAndWriteStructure (pxform, xform, XFORML);
  2219. }
  2220. __except(EXCEPTION_EXECUTE_HANDLER)
  2221. {
  2222. ulRet = DDI_ERROR;
  2223. }
  2224. }
  2225. }
  2226. FIXUP_THREAD_UMPDOBJS;
  2227. return (ulRet);
  2228. }
  2229. VOID APIENTRY NtGdiFONTOBJ_vGetInfo(
  2230. FONTOBJ *pfo,
  2231. ULONG cjSize,
  2232. FONTINFO *pfi
  2233. )
  2234. {
  2235. FONTINFO *pfiTmp = NULL;
  2236. EXTRACT_THREAD_UMPDOBJS;
  2237. pfo = pUMObjs->GetDDIOBJ(pfo);
  2238. if (pfo)
  2239. {
  2240. if (cjSize && pfi)
  2241. {
  2242. if (pfiTmp = (FONTINFO *)PALLOCNOZ(cjSize, UMPD_MEMORY_TAG))
  2243. {
  2244. FONTOBJ_vGetInfo(pfo, cjSize, pfiTmp);
  2245. bSafeCopyBits(pfi, pfiTmp, cjSize);
  2246. VFREEMEM(pfiTmp);
  2247. }
  2248. }
  2249. }
  2250. FIXUP_THREAD_UMPDOBJS;
  2251. }
  2252. //
  2253. // FONTOBJ_cGetGlyphs is a service to the font consumer that translates glyph handles into
  2254. // pointers to glyph data. These pointers are valid until the next call to FONTOBJ_cGetGlyphs.
  2255. // this means that we only need to attache one ppvGlyph onto the thread at any time.
  2256. //
  2257. // Note: another way to do this is to pre-allocate a reasonable size of User memory and
  2258. // use that memory for all temporary data buffers, and grow it when we are reaching the limit
  2259. // Thus we save the memory allocation calls.
  2260. //
  2261. ULONG APIENTRY NtGdiFONTOBJ_cGetGlyphs(
  2262. FONTOBJ *pfo,
  2263. ULONG iMode,
  2264. ULONG cGlyph,
  2265. HGLYPH *phg,
  2266. PVOID *ppvGlyph
  2267. )
  2268. {
  2269. GLYPHDATA *pgd, *pgdkm;
  2270. HGLYPH hg;
  2271. ULONG ulRet = 1;
  2272. EXTRACT_THREAD_UMPDOBJS(0);
  2273. if ((pfo = pUMObjs->GetDDIOBJ(pfo)) == NULL ||
  2274. (iMode != FO_GLYPHBITS && iMode != FO_PATHOBJ))
  2275. {
  2276. WARNING("Invalid parameter passed to NtGdiFONTOBJ_cGetGlyphs\n");
  2277. FIXUP_THREAD_UMPDOBJS;
  2278. return 0;
  2279. }
  2280. //
  2281. // Call the engine to retrive glyph data
  2282. //
  2283. // NOTE: DDK documentation is bogus.
  2284. // Font driver only supports cGlyph == 1 case.
  2285. //
  2286. __try
  2287. {
  2288. CaptureDWORD (&phg, &hg);
  2289. }
  2290. __except(EXCEPTION_EXECUTE_HANDLER)
  2291. {
  2292. WARNING ("NtGdiFONTOBJ_cGetGlyphs failed in try/except\n");
  2293. ulRet = 0;
  2294. }
  2295. if (ulRet)
  2296. {
  2297. RFONTTMPOBJ rfto(PFO_TO_PRF(pfo));
  2298. UMPDAcquireRFONTSem(rfto, pUMObjs, 0, 0, NULL);
  2299. if ((ulRet = FONTOBJ_cGetGlyphs(pfo, iMode, 1, phg, (PVOID *) &pgd)) == 1)
  2300. {
  2301. //
  2302. // Thunk GLYPHDATA structure
  2303. //
  2304. pgdkm = pgd;
  2305. if (!pUMObjs->ThunkMemBlock((PVOID *) &pgd, sizeof(GLYPHDATA)))
  2306. {
  2307. WARNING("Couldn't thunk GLYPHDATA structure\n");
  2308. ulRet = 0;
  2309. }
  2310. else if (iMode == FO_GLYPHBITS)
  2311. {
  2312. //
  2313. // Thunk GLYPHBITS structure
  2314. //
  2315. if (pgdkm->gdf.pgb != NULL &&
  2316. (pgd->gdf.pgb = pUMObjs->CacheGlyphBits(pgdkm->gdf.pgb)) == NULL)
  2317. {
  2318. WARNING("Couldn't thunk GLYPHBITS structure\n");
  2319. ulRet = 0;
  2320. }
  2321. }
  2322. else
  2323. {
  2324. //
  2325. // Thunk PATHOBJ
  2326. //
  2327. if (pgdkm->gdf.ppo != NULL &&
  2328. (pgd->gdf.ppo = pUMObjs->CacheGlyphPath(pgdkm->gdf.ppo)) == NULL)
  2329. {
  2330. WARNING("Couldn't thunk PATHOBJ structure\n");
  2331. ulRet = 0;
  2332. }
  2333. }
  2334. }
  2335. UMPDReleaseRFONTSem(rfto, pUMObjs, NULL, NULL, NULL);
  2336. if (ulRet != 0)
  2337. {
  2338. __try
  2339. {
  2340. ProbeAndWriteStructure (ppvGlyph, (PVOID)pgd, PVOID);
  2341. }
  2342. __except(EXCEPTION_EXECUTE_HANDLER)
  2343. {
  2344. WARNING ("fail to write in ppvGlyph\n");
  2345. ulRet = 0;
  2346. }
  2347. }
  2348. }
  2349. FIXUP_THREAD_UMPDOBJS;
  2350. return ulRet;
  2351. }
  2352. ULONG APIENTRY NtGdiFONTOBJ_cGetAllGlyphHandles(
  2353. IN FONTOBJ *pfo,
  2354. OUT HGLYPH *phg
  2355. )
  2356. {
  2357. ULONG ulCount = 0;
  2358. HGLYPH *phgTmp = NULL;
  2359. ULONG ulRet = 0;
  2360. EXTRACT_THREAD_UMPDOBJS(0);
  2361. pfo = pUMObjs->GetDDIOBJ(pfo);
  2362. if (pfo)
  2363. {
  2364. if (phg)
  2365. {
  2366. if (ulCount = FONTOBJ_cGetAllGlyphHandles(pfo, NULL))
  2367. {
  2368. // we are a little bit over cautious here,well...
  2369. if (BALLOC_OVERFLOW1(ulCount, HGLYPH))
  2370. {
  2371. FIXUP_THREAD_UMPDOBJS;
  2372. return NULL;
  2373. }
  2374. phgTmp = (HGLYPH *)PALLOCNOZ(ulCount*sizeof(HGLYPH), UMPD_MEMORY_TAG);
  2375. }
  2376. }
  2377. ulRet = FONTOBJ_cGetAllGlyphHandles(pfo, phgTmp);
  2378. ASSERTGDI(phg == NULL || ulRet == ulCount, "NtGdiFONTOBJ_cGetAllGlyphHandles: inconsistent return values from FONTOBJ_cGetAllGlyphHandles\n");
  2379. if (ulRet && phg && phgTmp)
  2380. {
  2381. if (!bSafeCopyBits(phg, phgTmp, ulCount * sizeof(HGLYPH)))
  2382. ulRet = NULL;
  2383. }
  2384. if (phgTmp)
  2385. {
  2386. VFREEMEM(phgTmp);
  2387. }
  2388. }
  2389. FIXUP_THREAD_UMPDOBJS;
  2390. return ulRet;
  2391. }
  2392. XFORMOBJ* APIENTRY NtGdiFONTOBJ_pxoGetXform(
  2393. FONTOBJ *pfo
  2394. )
  2395. {
  2396. EXTRACT_THREAD_UMPDOBJS(NULL);
  2397. XFORMOBJ* xoRet= pUMObjs->GetFONTOBJXform(pfo);
  2398. FIXUP_THREAD_UMPDOBJS;
  2399. return xoRet;
  2400. }
  2401. //
  2402. // If the return value is a system address, we copy it into user memory
  2403. //
  2404. // IMPORTANT!!
  2405. // We assume FD_GLYPHSET information is stored in one contiguous block
  2406. // of memory and FD_GLYPHSET.cjThis field is the size of the entire block.
  2407. // HGLYPH arrays in each WCRUN are part of the block, placed just after
  2408. // FD_GLYPHSET structure itself.
  2409. //
  2410. BOOL
  2411. GreCopyFD_GLYPHSET(
  2412. FD_GLYPHSET *dst,
  2413. FD_GLYPHSET *src,
  2414. ULONG cjSize,
  2415. BOOL bFromKernel
  2416. )
  2417. {
  2418. ULONG size;
  2419. PBYTE phg, pbMax;
  2420. //
  2421. // bFromKernel TRUE: we are copying from kernel mode address(src) to user mode address (dst)
  2422. // the src should contain everything in one chunk of memory
  2423. //
  2424. // FALSE: copying from user mode (src) to kernel mode (dst)
  2425. // glyph indices in src might be stored in a different chunk of memory from src
  2426. //
  2427. size = bFromKernel ? cjSize : offsetof(FD_GLYPHSET, awcrun) + src->cRuns * sizeof(WCRUN);
  2428. RtlCopyMemory(dst, src, size);
  2429. dst->cjThis = cjSize;
  2430. pbMax = (PBYTE)dst + cjSize;
  2431. phg = (PBYTE)dst + size;
  2432. //
  2433. // Patch up memory pointers in each WCRUN structure
  2434. //
  2435. ULONG index, offset;
  2436. for (index=0; index < src->cRuns; index++)
  2437. {
  2438. if (src->awcrun[index].phg != NULL)
  2439. {
  2440. if (bFromKernel)
  2441. {
  2442. offset = (ULONG)((PBYTE) src->awcrun[index].phg - (PBYTE) src);
  2443. if (offset >= cjSize)
  2444. {
  2445. WARNING("GreCopyFD_GLYPHSET failed.\n");
  2446. return FALSE;
  2447. }
  2448. dst->awcrun[index].phg = (HGLYPH*) ((PBYTE) dst + offset);
  2449. }
  2450. else
  2451. {
  2452. size = src->awcrun[index].cGlyphs * sizeof(HGLYPH);
  2453. if (phg + size <= pbMax)
  2454. {
  2455. RtlCopyMemory(phg, src->awcrun[index].phg, size);
  2456. dst->awcrun[index].phg = (HGLYPH*) phg;
  2457. phg += size;
  2458. }
  2459. else
  2460. return FALSE;
  2461. }
  2462. }
  2463. }
  2464. return TRUE;
  2465. }
  2466. FD_GLYPHSET * APIENTRY NtGdiFONTOBJ_pfdg(
  2467. FONTOBJ *pfo
  2468. )
  2469. {
  2470. FD_GLYPHSET *pfdg = NULL, *pfdgTmp;
  2471. ULONG cjSize;
  2472. EXTRACT_THREAD_UMPDOBJS(NULL);
  2473. //
  2474. // Check if this function has already been
  2475. // called during the current DDI entrypoint
  2476. //
  2477. if (! (pfo = pUMObjs->GetDDIOBJ(pfo)) ||
  2478. (pfdg = pUMObjs->pfdg()) != NULL)
  2479. {
  2480. FIXUP_THREAD_UMPDOBJS;
  2481. return pfdg;
  2482. }
  2483. //
  2484. // Call FONTOBJ_pifi and cache the pointer in UMPDOBJ
  2485. //
  2486. RFONTTMPOBJ rfto(PFO_TO_PRF(pfo));
  2487. UMPDAcquireRFONTSem(rfto, pUMObjs, 0, 0, NULL);
  2488. pfdgTmp = NULL;
  2489. if ((pfdg = FONTOBJ_pfdg(pfo)) != NULL)
  2490. {
  2491. if (IS_SYSTEM_ADDRESS(pfdg))
  2492. {
  2493. if ((cjSize = SZ_GLYPHSET(pfdg->cRuns, pfdg->cGlyphsSupported)) &&
  2494. (pfdgTmp = (FD_GLYPHSET *) pUMObjs->AllocUserMem(cjSize)))
  2495. {
  2496. if (GreCopyFD_GLYPHSET(pfdgTmp, pfdg, cjSize, TRUE))
  2497. pUMObjs->pfdg(pfdgTmp);
  2498. else
  2499. pfdgTmp = NULL;
  2500. }
  2501. }
  2502. else
  2503. {
  2504. pfdgTmp = pfdg;
  2505. pUMObjs->pfdg(pfdgTmp);
  2506. }
  2507. }
  2508. UMPDReleaseRFONTSem(rfto, pUMObjs, NULL, NULL, NULL);
  2509. FIXUP_THREAD_UMPDOBJS;
  2510. return pfdgTmp;
  2511. }
  2512. PFD_GLYPHATTR APIENTRY NtGdiFONTOBJ_pQueryGlyphAttrs(
  2513. FONTOBJ *pfo,
  2514. ULONG iMode
  2515. )
  2516. {
  2517. PFD_GLYPHATTR pfdga, pfdgaTmp;
  2518. ULONG i;
  2519. EXTRACT_THREAD_UMPDOBJS(FALSE);
  2520. if ((pfo = pUMObjs->GetDDIOBJ(pfo)) == NULL)
  2521. {
  2522. WARNING("Invalid parameter passed to NtGdiFONTOBJ_pQueryGlyphAttrs\n");
  2523. FIXUP_THREAD_UMPDOBJS;
  2524. return FALSE;
  2525. }
  2526. pfdga = NULL;
  2527. if ((pfdgaTmp = pUMObjs->pfdga()) == NULL)
  2528. {
  2529. RFONTTMPOBJ rfto(PFO_TO_PRF(pfo));
  2530. UMPDAcquireRFONTSem(rfto, pUMObjs, 0, 0, NULL);
  2531. pfdgaTmp = FONTOBJ_pQueryGlyphAttrs(pfo, iMode);
  2532. if (pfdgaTmp)
  2533. {
  2534. ULONG cjSize;
  2535. cjSize = ((PFD_GLYPHATTR)pfdgaTmp)->cjThis;
  2536. pfdga = (PFD_GLYPHATTR) pUMObjs->AllocUserMem(cjSize);
  2537. if (pfdga)
  2538. {
  2539. RtlCopyMemory((PVOID) pfdga, (PVOID) pfdgaTmp, cjSize);
  2540. pUMObjs->pfdga(pfdga);
  2541. }
  2542. }
  2543. UMPDReleaseRFONTSem(rfto, pUMObjs, NULL, NULL, NULL);
  2544. }
  2545. else
  2546. pfdga = pfdgaTmp;
  2547. FIXUP_THREAD_UMPDOBJS;
  2548. return pfdga;
  2549. }
  2550. //
  2551. // if the return value is a system address, we copy it into user memory
  2552. //
  2553. IFIMETRICS * APIENTRY NtGdiFONTOBJ_pifi(
  2554. FONTOBJ *pfo
  2555. )
  2556. {
  2557. IFIMETRICS *pifi = NULL, *pifiTmp;
  2558. EXTRACT_THREAD_UMPDOBJS(NULL);
  2559. //
  2560. // Check if this function has already been
  2561. // called during the current DDI entrypoint
  2562. //
  2563. if (! (pfo = pUMObjs->GetDDIOBJ(pfo)) ||
  2564. (pifi = pUMObjs->pifi()) != NULL)
  2565. {
  2566. FIXUP_THREAD_UMPDOBJS;
  2567. return pifi;
  2568. }
  2569. //
  2570. // Call FONTOBJ_pifi and cache the pointer in UMPDOBJ
  2571. //
  2572. RFONTTMPOBJ rfto(PFO_TO_PRF(pfo));
  2573. UMPDAcquireRFONTSem(rfto, pUMObjs, 0, 0, NULL);
  2574. if ((pifi = FONTOBJ_pifi(pfo)) != NULL &&
  2575. IS_SYSTEM_ADDRESS(pifi))
  2576. {
  2577. pifiTmp = pifi;
  2578. pifi = (PIFIMETRICS) pUMObjs->AllocUserMem(pifi->cjThis);
  2579. if (pifi != NULL)
  2580. {
  2581. RtlCopyMemory (pifi, pifiTmp, pifiTmp->cjThis);
  2582. pUMObjs->pifi(pifi);
  2583. }
  2584. }
  2585. UMPDReleaseRFONTSem(rfto, pUMObjs, NULL, NULL, NULL);
  2586. FIXUP_THREAD_UMPDOBJS;
  2587. return pifi;
  2588. }
  2589. BOOL APIENTRY NtGdiSTROBJ_bEnumInternal(
  2590. STROBJ *pstro,
  2591. ULONG *pc,
  2592. PGLYPHPOS *ppgpos,
  2593. BOOL bPositionsOnly
  2594. )
  2595. {
  2596. GLYPHPOS *pgp, *pgpTmp;
  2597. ULONG c;
  2598. BOOL bRet;
  2599. EXTRACT_THREAD_UMPDOBJS(DDI_ERROR);
  2600. //
  2601. // bRet from STROBJ_bEnum could have 3 different values:
  2602. // TRUE: more glyphs remained to be enumurated
  2603. // FALSE: no more glyphs to be enumrated
  2604. // DDI_ERROR: failure
  2605. //
  2606. if ((pstro = pUMObjs->GetDDIOBJ(pstro)) == NULL ||
  2607. ((bRet = bPositionsOnly ? STROBJ_bEnumPositionsOnly(pstro, &c, &pgp) : STROBJ_bEnum(pstro, &c, &pgp)) == DDI_ERROR))
  2608. {
  2609. FIXUP_THREAD_UMPDOBJS;
  2610. return DDI_ERROR;
  2611. }
  2612. else
  2613. {
  2614. // over cautious here
  2615. if (BALLOC_OVERFLOW1(c, GLYPHPOS) ||
  2616. (!(pgpTmp = (GLYPHPOS *) pUMObjs->AllocUserMem(sizeof(GLYPHPOS) * c))))
  2617. {
  2618. FIXUP_THREAD_UMPDOBJS;
  2619. return DDI_ERROR;
  2620. }
  2621. }
  2622. RtlCopyMemory(pgpTmp, pgp, sizeof(GLYPHPOS)*c);
  2623. __try
  2624. {
  2625. ProbeAndWriteStructure(ppgpos, pgpTmp, PVOID);
  2626. ProbeAndWriteUlong(pc, c);
  2627. }
  2628. __except(EXCEPTION_EXECUTE_HANDLER)
  2629. {
  2630. WARNING("fail to write in ppgpos or pc\n");
  2631. c = 0;
  2632. bRet = FALSE;
  2633. }
  2634. //
  2635. // NULL out GLYPHPOS.pgdf field to force the driver
  2636. // to call FONTOBJ_cGetGlyphs.
  2637. //
  2638. for (ULONG i=0; i < c; i++)
  2639. pgpTmp[i].pgdf = NULL;
  2640. FIXUP_THREAD_UMPDOBJS;
  2641. return bRet;
  2642. }
  2643. BOOL APIENTRY NtGdiSTROBJ_bEnum(
  2644. STROBJ *pstro,
  2645. ULONG *pc,
  2646. PGLYPHPOS *ppgpos
  2647. )
  2648. {
  2649. return NtGdiSTROBJ_bEnumInternal(pstro, pc, ppgpos, FALSE);
  2650. }
  2651. BOOL APIENTRY NtGdiSTROBJ_bEnumPositionsOnly(
  2652. STROBJ *pstro,
  2653. ULONG *pc,
  2654. PGLYPHPOS *ppgpos
  2655. )
  2656. {
  2657. return NtGdiSTROBJ_bEnumInternal(pstro, pc, ppgpos, TRUE);
  2658. }
  2659. BOOL APIENTRY NtGdiSTROBJ_bGetAdvanceWidths(
  2660. STROBJ *pstro,
  2661. ULONG iFirst,
  2662. ULONG c,
  2663. POINTQF *pptqD
  2664. )
  2665. {
  2666. BOOL bRet = FALSE;
  2667. POINTQF *pptqDTmp;
  2668. EXTRACT_THREAD_UMPDOBJS(FALSE);
  2669. if ((pstro = pUMObjs->GetDDIOBJ(pstro)) == NULL ||
  2670. BALLOC_OVERFLOW1(c, POINTQF) ||
  2671. !(pptqDTmp = (POINTQF *) pUMObjs->AllocUserMem(sizeof(POINTQF) * c)))
  2672. {
  2673. FIXUP_THREAD_UMPDOBJS;
  2674. return bRet;
  2675. }
  2676. // kernel mode can not fail
  2677. bRet = STROBJ_bGetAdvanceWidths(pstro, iFirst, c, pptqDTmp);
  2678. if (bRet)
  2679. {
  2680. __try
  2681. {
  2682. ProbeAndWriteAlignedBuffer( pptqD, pptqDTmp, sizeof(POINTQF) * c, sizeof(LARGE_INTEGER));
  2683. }
  2684. __except(EXCEPTION_EXECUTE_HANDLER)
  2685. {
  2686. WARNING("fail to write in ppgpos or pc\n");
  2687. bRet = FALSE;
  2688. }
  2689. }
  2690. FIXUP_THREAD_UMPDOBJS;
  2691. return bRet;
  2692. }
  2693. VOID APIENTRY NtGdiSTROBJ_vEnumStart(
  2694. IN STROBJ *pstro
  2695. )
  2696. {
  2697. EXTRACT_THREAD_UMPDOBJS;
  2698. if ((pstro = pUMObjs->GetDDIOBJ(pstro)) != NULL)
  2699. STROBJ_vEnumStart(pstro);
  2700. FIXUP_THREAD_UMPDOBJS;
  2701. }
  2702. DWORD APIENTRY NtGdiSTROBJ_dwGetCodePage(
  2703. STROBJ *pstro
  2704. )
  2705. {
  2706. EXTRACT_THREAD_UMPDOBJS(0);
  2707. DWORD dwRet = ((pstro = pUMObjs->GetDDIOBJ(pstro)) != NULL) ?
  2708. STROBJ_dwGetCodePage(pstro) :
  2709. 0;
  2710. FIXUP_THREAD_UMPDOBJS;
  2711. return dwRet;
  2712. }
  2713. //
  2714. // private
  2715. //
  2716. DHPDEV NtGdiGetDhpdev(HDEV hdev)
  2717. {
  2718. return ValidUmpdHdev(hdev) ? ((PPDEV)hdev)->dhpdev : NULL;
  2719. }
  2720. BOOL NtGdiSetPUMPDOBJ(
  2721. HUMPD humpd,
  2722. BOOL bStoreID,
  2723. HUMPD *phumpd,
  2724. BOOL *pbWOW64
  2725. )
  2726. {
  2727. UMPDREF umpdRef(humpd);
  2728. if (
  2729. (bStoreID && humpd == NULL) ||
  2730. (bStoreID && umpdRef.pumpdGet() == NULL) ||
  2731. (!bStoreID && phumpd == NULL)
  2732. )
  2733. {
  2734. return FALSE;
  2735. }
  2736. PW32THREAD pw32thread = W32GetCurrentThread();
  2737. HUMPD hSaved = pw32thread->pUMPDObj ? (HUMPD)((PUMPDOBJ)pw32thread->pUMPDObj)->hGet() : 0;
  2738. HUMPD humpdTmp;
  2739. if (!bStoreID)
  2740. {
  2741. __try
  2742. {
  2743. ProbeAndReadBuffer(&humpdTmp,phumpd,sizeof(HUMPD));
  2744. }
  2745. __except(EXCEPTION_EXECUTE_HANDLER)
  2746. {
  2747. WARNING("NtGdiSetPUMPDOBJ probe phumpd failed\n");
  2748. return FALSE;
  2749. }
  2750. }
  2751. if (bStoreID)
  2752. {
  2753. BOOL bWOW64;
  2754. bWOW64 = umpdRef.bWOW64();
  2755. __try
  2756. {
  2757. if (pbWOW64)
  2758. {
  2759. ProbeAndWriteBuffer(pbWOW64, &bWOW64, sizeof(BOOL));
  2760. }
  2761. }
  2762. __except(EXCEPTION_EXECUTE_HANDLER)
  2763. {
  2764. WARNING("NtGdiSetPUMPDOBJ: bad pumpdobj or probe pbWOW64 failed\n");
  2765. return FALSE;
  2766. }
  2767. #if defined(_WIN64)
  2768. if (bWOW64)
  2769. {
  2770. ASSERTGDI(pw32thread->pClientID == NULL, "NtGdiSetPUMPDOBJ: existing non-null pClientID\n");
  2771. if (pw32thread->pClientID == NULL)
  2772. {
  2773. KERNEL_PVOID pclientID = (KERNEL_PVOID)PALLOCMEM(sizeof(PRINTCLIENTID), 'dipG');
  2774. if (pclientID)
  2775. {
  2776. __try
  2777. {
  2778. ((PRINTCLIENTID*)pclientID)->clientTid = umpdRef.clientTid();
  2779. ((PRINTCLIENTID*)pclientID)->clientPid = umpdRef.clientPid();
  2780. pw32thread->pClientID = pclientID;
  2781. ProbeAndWriteBuffer(phumpd, &hSaved, sizeof(HUMPD));
  2782. }
  2783. __except(EXCEPTION_EXECUTE_HANDLER)
  2784. {
  2785. WARNING("NtGdiSetPUMPDOBJ: wow64 failed to access pumpdobj or ppumpdobj\n");
  2786. pw32thread->pClientID = NULL;
  2787. VFREEMEM(pclientID);
  2788. return FALSE;
  2789. }
  2790. }
  2791. else
  2792. {
  2793. WARNING("NtGdiSetPUMPDOBJ: failed to allocate pclientID\n");
  2794. return FALSE;
  2795. }
  2796. }
  2797. else
  2798. {
  2799. WARNING("NtGdiSetPUMPDOBJ: bWOW64 and existing pClientID\n");
  2800. return FALSE;
  2801. }
  2802. }
  2803. else
  2804. #endif
  2805. {
  2806. __try
  2807. {
  2808. ProbeAndWriteBuffer(phumpd, &hSaved, sizeof(HUMPD));
  2809. }
  2810. __except(EXCEPTION_EXECUTE_HANDLER)
  2811. {
  2812. WARNING("NtGdiSetPUMPDOBJ: failed to access ppumpdobj\n");
  2813. return FALSE;
  2814. }
  2815. }
  2816. }
  2817. else
  2818. {
  2819. if (humpdTmp != hSaved)
  2820. {
  2821. WARNING("NtGdiSetPUMPDOBJ: mismatched pumpdobj\n");
  2822. return FALSE;
  2823. }
  2824. #if defined(_WIN64)
  2825. UMPDREF umpdSaved(hSaved);
  2826. ASSERTGDI(umpdSaved.pumpdGet(), "NtGdiSetPUMPDOBJ: saved pumpdobj is NULL\n");
  2827. if (umpdSaved.bWOW64() && pw32thread->pClientID)
  2828. {
  2829. VFREEMEM(pw32thread->pClientID);
  2830. pw32thread->pClientID = NULL;
  2831. }
  2832. #endif
  2833. }
  2834. pw32thread->pUMPDObj = umpdRef.pumpdGet();
  2835. return TRUE;
  2836. }
  2837. //
  2838. // private, called only for WOW64 printing
  2839. //
  2840. BOOL NtGdiBRUSHOBJ_DeleteRbrush(BRUSHOBJ *pbo, BRUSHOBJ *pboB)
  2841. {
  2842. EXTRACT_THREAD_UMPDOBJS(FALSE);
  2843. BRUSHOBJ *pbokm;
  2844. if (pbo)
  2845. {
  2846. pbokm = pUMObjs->GetDDIOBJ(pbo);
  2847. if (pbokm && pbokm->pvRbrush && !IS_SYSTEM_ADDRESS(pbokm->pvRbrush))
  2848. {
  2849. EngFreeUserMem(DBRUSHSTART(pbokm->pvRbrush));
  2850. pbokm->pvRbrush = NULL;
  2851. }
  2852. }
  2853. if (pboB)
  2854. {
  2855. pbokm = pUMObjs->GetDDIOBJ(pboB);
  2856. if (pbokm && pbokm->pvRbrush && !IS_SYSTEM_ADDRESS(pbokm->pvRbrush))
  2857. {
  2858. EngFreeUserMem(DBRUSHSTART(pbokm->pvRbrush));
  2859. pbokm->pvRbrush = NULL;
  2860. }
  2861. }
  2862. FIXUP_THREAD_UMPDOBJS;
  2863. return TRUE;
  2864. }
  2865. // Private, used only for WOW64 printing
  2866. BOOL APIENTRY NtGdiUMPDEngFreeUserMem(KERNEL_PVOID *ppv)
  2867. {
  2868. #if defined(_WIN64)
  2869. PVOID pv = NULL, pvTmp;
  2870. __try
  2871. {
  2872. if (ppv)
  2873. {
  2874. ProbeAndReadBuffer(&pv, ppv, sizeof(PVOID));
  2875. ProbeForRead(pv, sizeof(ULONG), sizeof(ULONG));
  2876. // Winbug 397346
  2877. // We are doing the following probing since EngFreeUserMem
  2878. // does NOT try-except/probe while accessing pvTmp.
  2879. pvTmp = (PBYTE)pv - sizeof(ULONG_PTR)*4;
  2880. ProbeForRead(pvTmp, sizeof(ULONG_PTR)*4, sizeof(ULONG_PTR));
  2881. }
  2882. }
  2883. __except(EXCEPTION_EXECUTE_HANDLER)
  2884. {
  2885. WARNING("NtGdiUMPDEngFreeUserMem: bad input pointer\n");
  2886. return FALSE;
  2887. }
  2888. if (pv)
  2889. EngFreeUserMem(pv);
  2890. #endif
  2891. return TRUE;
  2892. }
  2893. HSURF APIENTRY NtGdiEngCreateDeviceSurface(
  2894. DHSURF dhsurf,
  2895. SIZEL sizl,
  2896. ULONG iFormatCompat
  2897. )
  2898. {
  2899. TRACE_INIT (("Entering NtGdiEngCreateDeviceSurface\n"));
  2900. if ((iFormatCompat > BMF_8RLE) || (iFormatCompat < BMF_1BPP))
  2901. return 0;
  2902. //
  2903. // set high bit of iFormatCompat to indicate umpd driver
  2904. //
  2905. return (EngCreateDeviceSurface(dhsurf, sizl, iFormatCompat|= UMPD_FLAG));
  2906. }
  2907. HBITMAP APIENTRY NtGdiEngCreateDeviceBitmap(
  2908. DHSURF dhsurf,
  2909. SIZEL sizl,
  2910. ULONG iFormatCompat
  2911. )
  2912. {
  2913. if (!ValidUmpdSizl(sizl))
  2914. return 0;
  2915. if ((iFormatCompat > BMF_8RLE) || (iFormatCompat < BMF_1BPP))
  2916. return 0;
  2917. return EngCreateDeviceBitmap(dhsurf, sizl, iFormatCompat | UMPD_FLAG);
  2918. }
  2919. VOID APIENTRY NtGdiPATHOBJ_vGetBounds(
  2920. IN PATHOBJ *ppo,
  2921. OUT PRECTFX prectfx
  2922. )
  2923. {
  2924. RECTFX rectfx;
  2925. EXTRACT_THREAD_UMPDOBJS;
  2926. ppo = pUMObjs->GetDDIOBJ(ppo);
  2927. if (ppo)
  2928. {
  2929. PATHOBJ_vGetBounds(ppo, &rectfx);
  2930. __try
  2931. {
  2932. ProbeAndWriteStructure(prectfx, rectfx, RECTFX);
  2933. }
  2934. __except(EXCEPTION_EXECUTE_HANDLER)
  2935. {
  2936. WARNING("fail to write into prectfx\n");
  2937. }
  2938. }
  2939. FIXUP_THREAD_UMPDOBJS;
  2940. }
  2941. BOOL APIENTRY NtGdiPATHOBJ_bEnum(
  2942. IN PATHOBJ *ppo,
  2943. OUT PATHDATA *ppd
  2944. )
  2945. {
  2946. PATHDATA pathdata;
  2947. BOOL bRet = FALSE;
  2948. PVOID pvTmp = NULL;
  2949. EXTRACT_THREAD_UMPDOBJS(FALSE);
  2950. if (ppo = pUMObjs->GetDDIOBJ(ppo))
  2951. {
  2952. bRet = PATHOBJ_bEnum(ppo, &pathdata);
  2953. // over cautious
  2954. if (BALLOC_OVERFLOW1(pathdata.count, POINTFIX))
  2955. {
  2956. FIXUP_THREAD_UMPDOBJS;
  2957. return FALSE;
  2958. }
  2959. if (pvTmp = pUMObjs->AllocUserMem(sizeof(POINTFX) * pathdata.count))
  2960. {
  2961. RtlCopyMemory(pvTmp, pathdata.pptfx, sizeof(POINTFX) * pathdata.count);
  2962. pathdata.pptfx = (POINTFIX *) pvTmp;
  2963. }
  2964. else
  2965. bRet = FALSE;
  2966. }
  2967. if (pvTmp == NULL)
  2968. RtlZeroMemory(&pathdata, sizeof(pathdata));
  2969. __try
  2970. {
  2971. ProbeAndWriteStructure(ppd, pathdata, PATHDATA);
  2972. }
  2973. __except(EXCEPTION_EXECUTE_HANDLER)
  2974. {
  2975. WARNING("fail to write into ppd\n");
  2976. bRet = FALSE;
  2977. }
  2978. FIXUP_THREAD_UMPDOBJS;
  2979. return bRet;
  2980. }
  2981. VOID APIENTRY NtGdiPATHOBJ_vEnumStart(
  2982. IN PATHOBJ *ppo
  2983. )
  2984. {
  2985. EXTRACT_THREAD_UMPDOBJS;
  2986. if ((ppo = pUMObjs->GetDDIOBJ(ppo)) != NULL)
  2987. PATHOBJ_vEnumStart(ppo);
  2988. FIXUP_THREAD_UMPDOBJS;
  2989. }
  2990. VOID APIENTRY NtGdiPATHOBJ_vEnumStartClipLines(
  2991. PATHOBJ *ppo,
  2992. CLIPOBJ *pco,
  2993. SURFOBJ *pso,
  2994. LINEATTRS *pla
  2995. )
  2996. {
  2997. LINEATTRS lineattrs;
  2998. EXTRACT_THREAD_UMPDOBJS;
  2999. UMPDSURFOBJ umso(pso, pUMObjs);
  3000. pso = umso.pso();
  3001. ppo = pUMObjs->GetDDIOBJ(ppo);
  3002. if (pso && ppo && bCaptureLINEATTRS(&pla, &lineattrs))
  3003. {
  3004. pco = pUMObjs->GetDDIOBJ(pco, &pso->sizlBitmap);
  3005. PATHOBJ_vEnumStartClipLines(ppo, pco, pso, pla);
  3006. if (pla && pla->pstyle)
  3007. VFREEMEM(pla->pstyle);
  3008. }
  3009. FIXUP_THREAD_UMPDOBJS;
  3010. }
  3011. BOOL APIENTRY NtGdiPATHOBJ_bEnumClipLines(
  3012. PATHOBJ *ppo,
  3013. ULONG cb,
  3014. CLIPLINE *pcl
  3015. )
  3016. {
  3017. BOOL bRet = FALSE;
  3018. PVOID pvTmp = NULL;
  3019. EXTRACT_THREAD_UMPDOBJS(FALSE);
  3020. if (cb <= sizeof(CLIPLINE))
  3021. {
  3022. FIXUP_THREAD_UMPDOBJS;
  3023. return(FALSE);
  3024. }
  3025. if ((ppo = pUMObjs->GetDDIOBJ(ppo)) != NULL &&
  3026. (pvTmp = PALLOCNOZ(cb, UMPD_MEMORY_TAG)) != NULL)
  3027. {
  3028. bRet = PATHOBJ_bEnumClipLines(ppo, cb, (CLIPLINE *) pvTmp);
  3029. }
  3030. __try
  3031. {
  3032. ProbeForWrite(pcl, cb, sizeof(ULONG));
  3033. if (pvTmp != NULL)
  3034. RtlCopyMemory(pcl, pvTmp, cb);
  3035. else
  3036. RtlZeroMemory(pcl, cb);
  3037. }
  3038. __except(EXCEPTION_EXECUTE_HANDLER)
  3039. {
  3040. bRet = FALSE;
  3041. }
  3042. if (pvTmp != NULL)
  3043. VFREEMEM(pvTmp);
  3044. FIXUP_THREAD_UMPDOBJS;
  3045. return bRet;
  3046. }
  3047. PVOID APIENTRY NtGdiFONTOBJ_pvTrueTypeFontFile(
  3048. IN FONTOBJ *pfo,
  3049. OUT ULONG *pcjFile
  3050. )
  3051. {
  3052. EXTRACT_THREAD_UMPDOBJS(NULL);
  3053. PVOID pBase, p = NULL;
  3054. ULONG size;
  3055. if ((pfo = pUMObjs->GetDDIOBJ(pfo)) != NULL &&
  3056. (p = pUMObjs->pvFontFile(&size)) == NULL &&
  3057. (p = FONTOBJ_pvTrueTypeFontFileUMPD(pfo, &size, &pBase)) != NULL)
  3058. {
  3059. pUMObjs->pvFontFile(p, pBase, size);
  3060. }
  3061. if (p == NULL)
  3062. size = 0;
  3063. if (pcjFile != NULL)
  3064. {
  3065. __try
  3066. {
  3067. ProbeAndWriteStructure(pcjFile, size, DWORD);
  3068. }
  3069. __except(EXCEPTION_EXECUTE_HANDLER)
  3070. {
  3071. WARNING("fail to write into pcjFilie\n");
  3072. p = NULL;
  3073. }
  3074. }
  3075. FIXUP_THREAD_UMPDOBJS;
  3076. return p;
  3077. }
  3078. HANDLE APIENTRY NtGdiXLATEOBJ_hGetColorTransform(
  3079. XLATEOBJ *pxlo
  3080. )
  3081. {
  3082. EXTRACT_THREAD_UMPDOBJS(NULL);
  3083. HANDLE hRet = ((pxlo = pUMObjs->GetDDIOBJ(pxlo)) != NULL) ?
  3084. XLATEOBJ_hGetColorTransform(pxlo) :
  3085. NULL;
  3086. FIXUP_THREAD_UMPDOBJS;
  3087. return hRet;
  3088. }
  3089. ULONG APIENTRY NtGdiXLATEOBJ_cGetPalette(
  3090. IN XLATEOBJ* pxlo,
  3091. IN ULONG iPal,
  3092. IN ULONG cPal,
  3093. IN ULONG *pPal
  3094. )
  3095. {
  3096. ULONG ulRet = 0;
  3097. ULONG *pPalTmp = NULL;
  3098. EXTRACT_THREAD_UMPDOBJS(0);
  3099. pxlo = pUMObjs->GetDDIOBJ(pxlo);
  3100. if (pxlo)
  3101. {
  3102. if (pPal)
  3103. {
  3104. if (BALLOC_OVERFLOW1(cPal, DWORD))
  3105. {
  3106. FIXUP_THREAD_UMPDOBJS;
  3107. return 0;
  3108. }
  3109. pPalTmp = (PULONG)PALLOCNOZ(sizeof(DWORD)*cPal, UMPD_MEMORY_TAG);
  3110. }
  3111. if (pPalTmp)
  3112. {
  3113. ulRet = XLATEOBJ_cGetPalette(pxlo, iPal, cPal, pPalTmp);
  3114. if (ulRet)
  3115. {
  3116. if (!bSafeCopyBits(pPal, pPalTmp, sizeof(DWORD)*cPal))
  3117. ulRet = 0;
  3118. }
  3119. VFREEMEM(pPalTmp);
  3120. }
  3121. }
  3122. FIXUP_THREAD_UMPDOBJS;
  3123. return ulRet;
  3124. }
  3125. ULONG APIENTRY NtGdiXLATEOBJ_iXlate(
  3126. IN XLATEOBJ *pxlo,
  3127. IN ULONG iColor
  3128. )
  3129. {
  3130. EXTRACT_THREAD_UMPDOBJS(0xffffffff);
  3131. ULONG ulRet = ((pxlo = pUMObjs->GetDDIOBJ(pxlo)) != NULL ? XLATEOBJ_iXlate(pxlo, iColor) : NULL);
  3132. FIXUP_THREAD_UMPDOBJS;
  3133. return ulRet;
  3134. }
  3135. BOOL APIENTRY NtGdiEngCheckAbort(
  3136. SURFOBJ *pso
  3137. )
  3138. {
  3139. EXTRACT_THREAD_UMPDOBJS(TRUE);
  3140. UMPDSURFOBJ umso(pso, pUMObjs);
  3141. pso = umso.pso();
  3142. BOOL bRet = pso ? EngCheckAbort(pso) : TRUE;
  3143. FIXUP_THREAD_UMPDOBJS;
  3144. return bRet;
  3145. }
  3146. //
  3147. // Ported from EngComputeGlyphSet with necessary changes
  3148. //
  3149. FD_GLYPHSET* APIENTRY NtGdiEngComputeGlyphSet(
  3150. INT nCodePage,
  3151. INT nFirstChar,
  3152. INT cChars
  3153. )
  3154. {
  3155. FD_GLYPHSET *pGlyphSet, *pGlyphSetTmp = NULL;
  3156. ULONG cjSize;
  3157. EXTRACT_THREAD_UMPDOBJS(NULL);
  3158. //
  3159. // Call kernel-mode EngComputeGlyphSet first and then copy
  3160. // the FD_GLYPHSET structure into a temporary user-mode buffer
  3161. //
  3162. if ((pGlyphSet = EngComputeGlyphSet(nCodePage, nFirstChar, cChars)) &&
  3163. (cjSize = pGlyphSet->cjThis) &&
  3164. (pGlyphSetTmp = (PFD_GLYPHSET) pUMObjs->AllocUserMem(cjSize)))
  3165. {
  3166. if (!GreCopyFD_GLYPHSET(pGlyphSetTmp, pGlyphSet, cjSize, TRUE))
  3167. pGlyphSetTmp = NULL;
  3168. }
  3169. //
  3170. // Free the kernel copy of the FD_GLYPHSET structure right away
  3171. //
  3172. if (pGlyphSet)
  3173. EngFreeMem(pGlyphSet);
  3174. FIXUP_THREAD_UMPDOBJS;
  3175. return (pGlyphSetTmp);
  3176. }
  3177. LONG APIENTRY NtGdiHT_Get8BPPFormatPalette(
  3178. LPPALETTEENTRY pPaletteEntry,
  3179. USHORT RedGamma,
  3180. USHORT GreenGamma,
  3181. USHORT BlueGamma
  3182. )
  3183. {
  3184. if (pPaletteEntry)
  3185. {
  3186. LPPALETTEENTRY pPal = NULL;
  3187. ULONG ulRet = 0;
  3188. ULONG c = HT_Get8BPPFormatPalette(NULL, RedGamma, GreenGamma, BlueGamma);
  3189. if (c)
  3190. {
  3191. if (BALLOC_OVERFLOW1(c, PALETTEENTRY))
  3192. return 0;
  3193. pPal = (LPPALETTEENTRY)PALLOCNOZ(c*sizeof(PALETTEENTRY), UMPD_MEMORY_TAG);
  3194. }
  3195. if (pPal)
  3196. {
  3197. ulRet = HT_Get8BPPFormatPalette(pPal, RedGamma, GreenGamma, BlueGamma);
  3198. if (!bSafeCopyBits(pPaletteEntry, pPal, c*sizeof(PALETTEENTRY)))
  3199. ulRet = 0;
  3200. VFREEMEM(pPal);
  3201. }
  3202. return ulRet;
  3203. }
  3204. else
  3205. return HT_Get8BPPFormatPalette(NULL, RedGamma, GreenGamma, BlueGamma);
  3206. }
  3207. LONG APIENTRY NtGdiHT_Get8BPPMaskPalette(
  3208. LPPALETTEENTRY pPaletteEntry,
  3209. BOOL Use8BPPMaskPal,
  3210. BYTE CMYMask,
  3211. USHORT RedGamma,
  3212. USHORT GreenGamma,
  3213. USHORT BlueGamma
  3214. )
  3215. {
  3216. LONG c = HT_Get8BPPMaskPalette(NULL, Use8BPPMaskPal, CMYMask, RedGamma, GreenGamma, BlueGamma);
  3217. if (pPaletteEntry) {
  3218. LPPALETTEENTRY pPal = NULL;
  3219. LONG cbPal;
  3220. if (((cbPal = c * sizeof(PALETTEENTRY)) > 0) &&
  3221. (!BALLOC_OVERFLOW1(c, PALETTEENTRY)) &&
  3222. (pPal = (LPPALETTEENTRY)PALLOCNOZ(cbPal, UMPD_MEMORY_TAG)) &&
  3223. (bSafeReadBits(pPal, pPaletteEntry, cbPal)) &&
  3224. (c = HT_Get8BPPMaskPalette(pPal,
  3225. Use8BPPMaskPal,
  3226. CMYMask,
  3227. RedGamma,
  3228. GreenGamma,
  3229. BlueGamma)) &&
  3230. (bSafeCopyBits(pPaletteEntry, pPal, cbPal))) {
  3231. NULL;
  3232. } else {
  3233. c = 0;
  3234. }
  3235. if (pPal) {
  3236. VFREEMEM(pPal);
  3237. }
  3238. }
  3239. return(c);
  3240. }
  3241. #endif // !_GDIPLUS_