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.

947 lines
29 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: engine.h
  3. *
  4. * This is the common include file for all GDI
  5. *
  6. * Copyright (c) 1993-1999 Microsoft Corporation
  7. \**************************************************************************/
  8. #include <stddef.h>
  9. #include <string.h>
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <ntosp.h>
  13. #include <zwapi.h>
  14. #ifndef FAR
  15. #define FAR
  16. #endif
  17. #include "w32p.h"
  18. #include <windef.h>
  19. typedef struct _LDEV LDEV, *PLDEV;
  20. #define SESSION_POOL_MASK 32
  21. extern BOOLEAN gIsTerminalServer;
  22. extern DWORD gSessionPoolMask;
  23. //
  24. // Sundown: in GDI, there are lots of places SIZE_T are used as interchangeable
  25. // as ULONG or UINT or LONG or INT. On 64bit system, SIZE_T is int64 indeed.
  26. // Since we are not making any GDI objects large objects right now, I just
  27. // change all SIZE_T to ULONGSIZE_T here.
  28. //
  29. // The new type used is to easily identify the change later.
  30. //
  31. // Note: Must be defined before "hmgr.h" is included
  32. //
  33. #define ULONGSIZE_T ULONG
  34. #include <winerror.h>
  35. #include <wingdi.h>
  36. #include <w32gdip.h>
  37. // typedefs copied from winbase.h to avoid using nturtl.h
  38. typedef struct _SECURITY_ATTRIBUTES *LPSECURITY_ATTRIBUTES;
  39. #include <winuser.h>
  40. #define _NO_COM // Avoid COM conflicts width ddrawp.h
  41. #include <ddrawp.h>
  42. #include <d3dnthal.h>
  43. #include <dxmini.h>
  44. #include <ddkmapi.h>
  45. #include <ddkernel.h>
  46. #include <winddi.h>
  47. #include "ntgdistr.h"
  48. #include "ntgdi.h"
  49. #include <videoagp.h>
  50. #include <agp.h>
  51. #include "greold.h"
  52. #include "gre.h"
  53. #include "usergdi.h"
  54. #include "debug.h"
  55. #include "hmgshare.h"
  56. #include "hmgr.h"
  57. #include "mapfile.h"
  58. #include "gdisplp.h"
  59. #include "ntgdispl.h"
  60. #if defined(_GDIPLUS_)
  61. #include "usermode.h"
  62. #endif
  63. #ifdef DDI_WATCHDOG
  64. #include "watchdog.h"
  65. //
  66. // Timeout after 10 seconds.
  67. //
  68. #define DDI_TIMEOUT 10000L
  69. //
  70. // We need DevLock and Pointer watchdogs per PDEVOBJ
  71. // (we'll need more for multi-threaded drivers).
  72. //
  73. #define WD_DEVLOCK 0
  74. #define WD_POINTER 1
  75. //
  76. // Number of watchdog objects per PDEVOBJ.
  77. //
  78. #define WD_NUMBER 2
  79. typedef struct _WATCHDOG_DATA
  80. {
  81. PKDPC pDpc;
  82. PDEFERRED_WATCHDOG pWatchdog;
  83. } WATCHDOG_DATA, *PWATCHDOG_DATA;
  84. #endif // DDI_WATCHDOG
  85. // temporary typedef
  86. typedef LPWSTR PWSZ;
  87. /**************************************************************************\
  88. *
  89. * GLOBALS
  90. *
  91. * These are the extern definitions for all the globals defined in globals.c
  92. *
  93. \**************************************************************************/
  94. //
  95. // shared memory
  96. //
  97. extern PGDI_SHARED_MEMORY gpGdiSharedMemory;
  98. extern PDEVCAPS gpGdiDevCaps;
  99. //
  100. // global resources
  101. //
  102. extern HSEMAPHORE ghsemDriverMgmt;
  103. extern HSEMAPHORE ghsemRFONTList;
  104. extern HSEMAPHORE ghsemAtmfdInit;
  105. extern HSEMAPHORE ghsemCLISERV;
  106. extern HSEMAPHORE ghsemPalette;
  107. extern HSEMAPHORE ghsemPublicPFT;
  108. extern HSEMAPHORE ghsemGdiSpool;
  109. extern HSEMAPHORE ghsemWndobj;
  110. extern HSEMAPHORE ghsemGlyphSet;
  111. extern HSEMAPHORE ghsemShareDevLock;
  112. extern HSEMAPHORE ghsemPrintKView;
  113. #define SEMORDER_SHAREDEVLOCK 50
  114. #define SEMORDER_DEVLOCK 100
  115. #define SEMORDER_POINTER 150
  116. #define SEMORDER_DRIVERMGMT 200
  117. #define SEMORDER_PALETTE 300
  118. #define SEMORDER_PUBLICPFT 400
  119. #define SEMORDER_RFONTLIST 500
  120. #define SEMORDER_HMGR 600
  121. //
  122. // Track the creater of semaphores
  123. //
  124. #define OBJ_ENGINE_CREATED 0x0
  125. #define OBJ_DRIVER_CREATED 0x1
  126. //
  127. // drawing
  128. //
  129. extern BYTE gajRop3[];
  130. extern BYTE gaMix[];
  131. extern POINTL gptl00;
  132. extern ULONG gaulConvert[7];
  133. extern HBRUSH ghbrGrayPattern;
  134. //
  135. // font stuff
  136. //
  137. extern UNIVERSAL_FONT_ID gufiLocalType1Rasterizer;
  138. extern USHORT gusLanguageID; // System default language ID.
  139. extern BOOL gbDBCSCodePage; // Is the system code page DBCS?
  140. extern ULONG gcTrueTypeFonts;
  141. extern ULONG gulFontInformation;
  142. extern BYTE gjCurCharset;
  143. extern DWORD gfsCurSignature;
  144. extern BOOL gbGUISetup;
  145. //
  146. // USER global
  147. //
  148. extern PEPROCESS gpepCSRSS;
  149. #define HOBJ_INVALID ((HOBJ) 0)
  150. DECLARE_HANDLE(HDSURF);
  151. DECLARE_HANDLE(HDDB);
  152. DECLARE_HANDLE(HDIB);
  153. DECLARE_HANDLE(HDBRUSH);
  154. DECLARE_HANDLE(HPATH);
  155. DECLARE_HANDLE(HXFB);
  156. DECLARE_HANDLE(HPAL);
  157. DECLARE_HANDLE(HXLATE);
  158. DECLARE_HANDLE(HFDEV);
  159. DECLARE_HANDLE(HRFONT);
  160. DECLARE_HANDLE(HPFT);
  161. DECLARE_HANDLE(HPFEC);
  162. DECLARE_HANDLE(HIDB);
  163. DECLARE_HANDLE(HCACHE);
  164. DECLARE_HANDLE(HEFS);
  165. DECLARE_HANDLE(HPDEV);
  166. #define HSURF_INVALID ((HSURF) HOBJ_INVALID)
  167. #define HDSURF_INVALID ((HDSURF) HOBJ_INVALID)
  168. #define HDDB_INVALID ((HDDB) HOBJ_INVALID)
  169. #define HDIB_INVALID ((HDIB) HOBJ_INVALID)
  170. #define HDBRUSH_INVALID ((HDBRUSH) HOBJ_INVALID)
  171. #define HPATH_INVALID ((HPATH) HOBJ_INVALID)
  172. #define HXFB_INVALID ((HXFB) HOBJ_INVALID)
  173. #define HPAL_INVALID ((HPAL) HOBJ_INVALID)
  174. #define HXLATE_INVALID ((HXLATE) HOBJ_INVALID)
  175. #define HFDEV_INVALID ((HFDEV) HOBJ_INVALID)
  176. #define HLFONT_INVALID ((HLFONT) HOBJ_INVALID)
  177. #define HRFONT_INVALID ((HRFONT) HOBJ_INVALID)
  178. #define HPFEC_INVALID ((HPFEC) HOBJ_INVALID)
  179. #define HPFT_INVALID ((HPFT) HOBJ_INVALID)
  180. #define HIDB_INVALID ((HIDB) HOBJ_INVALID)
  181. #define HBRUSH_INVALID ((HBRUSH) HOBJ_INVALID)
  182. #define HCACHE_INVALID ((HCACHE) HOBJ_INVALID)
  183. #define HPEN_INVALID ((HCACHE) HOBJ_INVALID)
  184. #define HEFS_INVALID ((HEFS) HOBJ_INVALID)
  185. /**************************************************************************\
  186. *
  187. * Versionning macros
  188. *
  189. * The same number must be reflected in winddi.h
  190. *
  191. \**************************************************************************/
  192. //
  193. // Get engine constants.
  194. //
  195. // Engine
  196. // Version Changes
  197. // ------- -------
  198. // 10 Final release, Windows NT 3.1
  199. // 10A Beta DDK release, Windows NT 3.5
  200. // - ulVRefresh added to GDIINFO, and multiple desktops
  201. // implemented for the Display Applet
  202. // 10B Final release, Windows NT 3.5
  203. // - ulDesktop resolutions and ulBltAlignment added to
  204. // GDIINFO
  205. // SUR First BETA, Windows NT SUR
  206. // SP3 NT 4.0, SP3
  207. // - exposes new EngSave/RestoreFloatingPointState, DDML,
  208. // and EngFindImageProcAddress(0) support
  209. // 50 Beta One, Windows NT 5.0
  210. // 51 Beta One, Windows NT 5.1
  211. //
  212. #define ENGINE_VERSION10 0x00010000
  213. #define ENGINE_VERSION10A 0x00010001
  214. #define ENGINE_VERSION10B 0x00010002
  215. #define ENGINE_VERSIONSUR DDI_DRIVER_VERSION_NT4
  216. #define ENGINE_VERSIONSP3 DDI_DRIVER_VERSION_SP3
  217. #define ENGINE_VERSION50 DDI_DRIVER_VERSION_NT5
  218. #define ENGINE_VERSION51 DDI_DRIVER_VERSION_NT5_01
  219. #define ENGINE_VERSION51_SP1 DDI_DRIVER_VERSION_NT5_01_SP1
  220. #define ENGINE_VERSION ENGINE_VERSION51
  221. /**************************************************************************\
  222. *
  223. * Memory allocation macros
  224. *
  225. \**************************************************************************/
  226. VOID FreeObject(PVOID pvFree, ULONG ulType);
  227. PVOID AllocateObject(ULONG cBytes, ULONG ulType, BOOL bZero);
  228. #define ALLOCOBJ(size,objt,b) AllocateObject((size), objt, b)
  229. #define FREEOBJ(pv,objt) FreeObject((pv),objt)
  230. //
  231. // GDI pool allocation
  232. //
  233. //
  234. // Use Win32 pool functions.
  235. //
  236. #define GdiAllocPool Win32AllocPool
  237. #define GdiAllocPoolWithPriority Win32AllocPoolWithPriority
  238. #define GdiAllocPoolNonPaged Win32AllocPoolNonPaged
  239. #define GdiAllocPoolNonPagedWithPriority Win32AllocPoolNonPagedWithPriority
  240. #define GdiFreePool Win32FreePool
  241. #define GdiAllocPoolNonPagedNS Win32AllocPoolNonPagedNS
  242. #define GdiAllocPoolNonPagedNSWithPriority Win32AllocPoolNonPagedNSWithPriority
  243. // MM_POOL_HEADER_SIZE defined in w32\w32inc\usergdi.h
  244. #define GDI_POOL_HEADER_SIZE MM_POOL_HEADER_SIZE
  245. __inline
  246. PVOID
  247. PALLOCMEM(
  248. ULONG size,
  249. ULONG tag)
  250. {
  251. PVOID _pv = (PVOID) NULL;
  252. if (size)
  253. {
  254. _pv = GdiAllocPool(size, (ULONG) tag);
  255. if (_pv)
  256. {
  257. RtlZeroMemory(_pv, size);
  258. }
  259. }
  260. return _pv;
  261. }
  262. #define PALLOCNOZ(size,tag) ((size) ? GdiAllocPool((size), (ULONG) (tag)) : NULL)
  263. #define VFREEMEM(pv) GdiFreePool((PVOID)(pv))
  264. #define PVALLOCTEMPBUFFER(size) AllocFreeTmpBuffer(size)
  265. #define FREEALLOCTEMPBUFFER(pv) FreeTmpBuffer(pv)
  266. //
  267. // Macro to check memory allocation overflow.
  268. //
  269. #define BALLOC_OVERFLOW1(c,st) (c > (MAXIMUM_POOL_ALLOC/sizeof(st)))
  270. #define BALLOC_OVERFLOW2(c,st1,st2) (c > (MAXIMUM_POOL_ALLOC/(sizeof(st1)+sizeof(st2))))
  271. //
  272. //Sundown: this is to ensure we are safe to truncate an int64 into 32bits
  273. //
  274. #if DBG
  275. #define ASSERT4GB(c) ASSERTGDI((ULONGLONG)(c) < ULONG_MAX, "> 4gb\n")
  276. #else
  277. #define ASSERT4GB(c)
  278. #endif
  279. PVOID
  280. AllocFreeTmpBuffer(
  281. ULONG size);
  282. VOID
  283. FreeTmpBuffer(
  284. PVOID pv);
  285. PVOID
  286. AllocThreadBufferWithTag(
  287. ULONG size,
  288. ULONG tag);
  289. VOID
  290. FreeThreadBufferWithTag(
  291. PVOID pv);
  292. __inline
  293. PVOID
  294. PALLOCTHREADMEM(
  295. ULONG size,
  296. ULONG tag)
  297. {
  298. PVOID _pv = (PVOID) NULL;
  299. if (size)
  300. {
  301. _pv = AllocThreadBufferWithTag(size, (ULONG) tag);
  302. if (_pv)
  303. {
  304. RtlZeroMemory(_pv, size);
  305. }
  306. }
  307. return _pv;
  308. }
  309. #define PALLOCTHREADMEMNOZ(size,tag) ((size) ? AllocThreadBufferWithTag((size), (ULONG) (tag)) : NULL)
  310. #define VFREETHREADMEM(pv) FreeThreadBufferWithTag(pv)
  311. #define GDITAG_LDEV ('vdlG') // Gldv
  312. #define GDITAG_GDEVICE ('vdgG') // Ggdv
  313. #define GDITAG_DRVSUP ('srdG') // Gdrs
  314. #define GDITAG_DEVMODE ('vedG') // Gdev
  315. #define GDITAG_TEMP ('pmtG') // Gtmp
  316. #define GDITAG_FULLSCREEN ('lufG') // Gful
  317. #define GDITAG_WATCHDOG ('dwdG') // Gdwd
  318. //
  319. // Error messages
  320. //
  321. #define SAVE_ERROR_CODE(x) EngSetLastError((x))
  322. //
  323. // WINBUG #83023 2-7-2000 bhouse Investigate removal of undef vToUNICODEN
  324. // Old Comment:
  325. // - remove the undef when the define is removed from mapfile.h
  326. //
  327. #undef vToUNICODEN
  328. #define vToUNICODEN( pwszDst, cwch, pszSrc, cch ) \
  329. { \
  330. RtlMultiByteToUnicodeN((LPWSTR)(pwszDst),(ULONG)((cwch)*sizeof(WCHAR)), \
  331. (PULONG)NULL,(PSZ)(pszSrc),(ULONG)(cch)); \
  332. (pwszDst)[(cwch)-1] = 0; \
  333. }
  334. #define vToASCIIN( pszDst, cch, pwszSrc, cwch) \
  335. { \
  336. RtlUnicodeToMultiByteN((PCH)(pszDst), (ULONG)(cch), (PULONG)NULL, \
  337. (LPWSTR)(pwszSrc), (ULONG)((cwch)*sizeof(WCHAR))); \
  338. (pszDst)[(cch)-1] = 0; \
  339. }
  340. #define TEXT_CAPTURE_BUFFER_SIZE 192 // Between 17 and 22 bytes per glyph are
  341. // required for capturing a string, so
  342. // this will allow strings of up to about
  343. // size 8 to require no heap allocation
  344. #define RETURN(x,y) {WARNING((x)); return(y);}
  345. #define DONTUSE(x) x=x
  346. #define MIN(A,B) ((A) < (B) ? (A) : (B))
  347. #define MAX(A,B) ((A) > (B) ? (A) : (B))
  348. #define ABS(A) ((A) < 0 ? -(A) : (A))
  349. #define SIGNUM(A) ((A > 0) - (A < 0))
  350. #define MAX4(a, b, c, d) max(max(max(a,b),c),d)
  351. #define MIN4(a, b, c, d) min(min(min(a,b),c),d)
  352. #define ALIGN4(X) (((X) + 3) & ~3)
  353. #define ALIGN8(X) (((X) + 7) & ~7)
  354. #if defined(_WIN64)
  355. #define ALIGN_PTR(x) ALIGN8(x)
  356. #else
  357. #define ALIGN_PTR(x) ALIGN4(x)
  358. #endif
  359. // SIZEOF_STROBJ_BUFFER(cwc)
  360. //
  361. // Calculates the dword-multiple size of the temporary buffer needed by
  362. // the STROBJ vInit and vInitSimple routines, based on the count of
  363. // characters.
  364. #ifdef FE_SB
  365. // for fontlinking we will also allocate room for the partitioning info
  366. #define SIZEOF_STROBJ_BUFFER(cwc) \
  367. ALIGN_PTR((cwc) * (sizeof(GLYPHPOS)+sizeof(LONG)+sizeof(WCHAR)))
  368. #else
  369. #define SIZEOF_STROBJ_BUFFER(cwc) \
  370. ((cwc) * sizeof(GLYPHPOS))
  371. #endif
  372. //
  373. // FIX point numbers must be 27.4
  374. // The following macro checks that a FIX point number is valid
  375. //
  376. #define FIX_SHIFT 4L
  377. #define FIX_FROM_LONG(x) ((x) << FIX_SHIFT)
  378. #define LONG_FLOOR_OF_FIX(x) ((x) >> FIX_SHIFT)
  379. #define LONG_CEIL_OF_FIX(x) LONG_FLOOR_OF_FIX(FIX_CEIL((x)))
  380. #define FIX_ONE FIX_FROM_LONG(1L)
  381. #define FIX_HALF (FIX_ONE/2)
  382. #define FIX_FLOOR(x) ((x) & ~(FIX_ONE - 1L))
  383. #define FIX_CEIL(x) FIX_FLOOR((x) + FIX_ONE - 1L)
  384. typedef struct _VECTORL
  385. {
  386. LONG x;
  387. LONG y;
  388. } VECTORL, *PVECTORL; /* vecl, pvecl */
  389. typedef struct _VECTORFX
  390. {
  391. FIX x;
  392. FIX y;
  393. } VECTORFX, *PVECTORFX; /* vec, pvec */
  394. #define AVEC_NOT 0x01
  395. #define AVEC_D 0x02
  396. #define AVEC_S 0x04
  397. #define AVEC_P 0x08
  398. #define AVEC_DS 0x10
  399. #define AVEC_DP 0x20
  400. #define AVEC_SP 0x40
  401. #define AVEC_DSP 0x80
  402. #define AVEC_NEED_SOURCE (AVEC_S | AVEC_DS | AVEC_SP | AVEC_DSP)
  403. #define AVEC_NEED_PATTERN (AVEC_P | AVEC_DP | AVEC_SP | AVEC_DSP)
  404. #define ROP4NEEDSRC(rop4) \
  405. ((gajRop3[rop4 & 0x000000FF] | gajRop3[(rop4 >> 8) & 0x000000ff]) & AVEC_NEED_SOURCE)
  406. #define ROP4NEEDPAT(rop4) \
  407. ((gajRop3[rop4 & 0x000000FF] | gajRop3[(rop4 >> 8) & 0x000000ff]) & AVEC_NEED_PATTERN)
  408. #define ROP4NEEDMASK(rop4) \
  409. (((rop4) & 0xff) != (((rop4) >> 8) & 0xff))
  410. typedef BOOL (*PFN_DrvConnect)(HANDLE, PVOID, PVOID, PVOID);
  411. typedef BOOL (*PFN_DrvReconnect)(HANDLE, PVOID);
  412. typedef BOOL (*PFN_DrvDisconnect)(HANDLE, PVOID);
  413. typedef BOOL (*PFN_DrvShadowConnect)(PVOID, ULONG);
  414. typedef BOOL (*PFN_DrvShadowDisconnect)(PVOID, ULONG);
  415. typedef VOID (*PFN_DrvInvalidateRect)(PRECT);
  416. typedef BOOL (*PFN_DrvMovePointerEx)(SURFOBJ*,LONG,LONG,ULONG);
  417. typedef BOOL (*PFN_DrvDisplayIOCtl)(PVOID,ULONG);
  418. BOOL OffStrokePath(PFN_DrvStrokePath,POINTL*,SURFOBJ*,PATHOBJ*,CLIPOBJ*,XFORMOBJ*,BRUSHOBJ*,POINTL*,LINEATTRS*,MIX);
  419. BOOL OffFillPath(PFN_DrvFillPath,POINTL*,SURFOBJ*,PATHOBJ*,CLIPOBJ*,BRUSHOBJ*,POINTL*,MIX,FLONG);
  420. BOOL OffStrokeAndFillPath(PFN_DrvStrokeAndFillPath,POINTL*,SURFOBJ*,PATHOBJ*,CLIPOBJ*,XFORMOBJ*,BRUSHOBJ*,LINEATTRS*,BRUSHOBJ*,POINTL*,MIX,FLONG);
  421. BOOL OffPaint(PFN_DrvPaint,POINTL*,SURFOBJ*,CLIPOBJ*,BRUSHOBJ*,POINTL*,MIX);
  422. BOOL OffBitBlt(PFN_DrvBitBlt,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,RECTL*,POINTL*,POINTL*,BRUSHOBJ*,POINTL*,ROP4);
  423. BOOL OffCopyBits(PFN_DrvCopyBits,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,RECTL*,POINTL*);
  424. BOOL OffStretchBlt(PFN_DrvStretchBlt,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,COLORADJUSTMENT*,POINTL*,RECTL*,RECTL*,POINTL*,ULONG);
  425. BOOL OffStretchBltROP(PFN_DrvStretchBltROP,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,COLORADJUSTMENT*,POINTL*,RECTL*,RECTL*,POINTL*,ULONG,BRUSHOBJ*,DWORD);
  426. BOOL OffTextOut(PFN_DrvTextOut,POINTL*,SURFOBJ*,STROBJ*,FONTOBJ*,CLIPOBJ*,RECTL*,RECTL*,BRUSHOBJ*,BRUSHOBJ*,POINTL*,MIX);
  427. BOOL OffLineTo(PFN_DrvLineTo,POINTL*,SURFOBJ*,CLIPOBJ*,BRUSHOBJ*,LONG,LONG,LONG,LONG,RECTL*,MIX);
  428. BOOL OffTransparentBlt(PFN_DrvTransparentBlt,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,RECTL*,RECTL*,ULONG,ULONG);
  429. BOOL OffAlphaBlend(PFN_DrvAlphaBlend,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,RECTL*,RECTL*,BLENDOBJ*);
  430. BOOL OffPlgBlt(PFN_DrvPlgBlt,POINTL*,SURFOBJ*,POINTL*,SURFOBJ*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,COLORADJUSTMENT*,POINTL*,POINTFIX*,RECTL*,POINTL*,ULONG);
  431. BOOL OffGradientFill(PFN_DrvGradientFill,POINTL*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,TRIVERTEX*,ULONG,VOID*,ULONG,RECTL*,POINTL*,ULONG);
  432. BOOL OffDrawStream(PFN_DrvDrawStream,POINTL*,SURFOBJ*,SURFOBJ*,CLIPOBJ*,XLATEOBJ*,RECTL*,POINTL*,ULONG,PVOID,DSSTATE*);
  433. /**************************************************************************\
  434. *
  435. * random prototypes internal to gdi
  436. *
  437. \**************************************************************************/
  438. HFONT hfontCreate(ENUMLOGFONTEXDVW * pelfw, LFTYPE lft, FLONG fl, PVOID pvCliData);
  439. BOOL EngMapFontFileInternal(ULONG_PTR, PULONG *, ULONG *, BOOL);
  440. BOOL EngMapFontFileFDInternal(ULONG_PTR, PULONG *, ULONG *, BOOL);
  441. BOOL SimBitBlt(SURFOBJ *,SURFOBJ *,SURFOBJ *,
  442. CLIPOBJ *,XLATEOBJ *,
  443. RECTL *,POINTL *,POINTL *,
  444. BRUSHOBJ *,POINTL *,ROP4, PVOID);
  445. BOOL
  446. bDeleteDCInternal(
  447. HDC hdc,
  448. BOOL bForce,
  449. BOOL bProcessCleanup);
  450. ULONG ulGetFontData(HDC, DWORD, DWORD, PVOID, ULONG);
  451. VOID vCleanupSpool();
  452. typedef struct tagREMOTETYPEONENODE REMOTETYPEONENODE;
  453. typedef struct tagREMOTETYPEONENODE
  454. {
  455. PDOWNLOADFONTHEADER pDownloadHeader;
  456. FONTFILEVIEW fvPFB;
  457. FONTFILEVIEW fvPFM;
  458. REMOTETYPEONENODE *pNext;
  459. } REMOTETYPEONENODE,*PREMOTETYPEONENODE;
  460. ULONG
  461. cParseFontResources(
  462. HANDLE hFontFile,
  463. PVOID **ppvResourceBases
  464. );
  465. BOOL
  466. MakeSystemRelativePath(
  467. LPWSTR pOriginalPath,
  468. PUNICODE_STRING pUnicode,
  469. BOOL bAppendDLL
  470. );
  471. BOOL
  472. MakeSystemDriversRelativePath(
  473. LPWSTR pOriginalPath,
  474. PUNICODE_STRING pUnicode,
  475. BOOL bAppendDLL
  476. );
  477. BOOL
  478. GreExtTextOutRect(
  479. HDC hdc,
  480. LPRECT prcl
  481. );
  482. #define HTBLT_SUCCESS 1
  483. #define HTBLT_NOTSUPPORTED 0
  484. #define HTBLT_ERROR -1
  485. int EngHTBlt(
  486. SURFOBJ *psoDst,
  487. SURFOBJ *psoSrc,
  488. SURFOBJ *psoMask,
  489. CLIPOBJ *pco,
  490. XLATEOBJ *pxlo,
  491. COLORADJUSTMENT *pca,
  492. PPOINTL pptlBrushOrg,
  493. PRECTL prclDest,
  494. PRECTL prclSrc,
  495. PPOINTL pptlMask,
  496. ULONG uFlags,
  497. BLENDOBJ *pBlendObj);
  498. typedef struct _DRAWSTREAMINFO
  499. {
  500. DSSTATE dss;
  501. BOOL bCalledFromBitBlt;
  502. PPOINTL pptlDstOffset;
  503. XLATEOBJ * pxloSrcToBGRA;
  504. XLATEOBJ * pxloDstToBGRA;
  505. XLATEOBJ * pxloBGRAToDst;
  506. ULONG ulStreamLength;
  507. PVOID pvStream;
  508. } DRAWSTREAMINFO, *PDRAWSTREAMINFO;
  509. BOOL GreExtTextOutWInternal(
  510. HDC hdc,
  511. int x,
  512. int y,
  513. UINT flOpts,
  514. LPRECT prcl,
  515. LPWSTR pwsz,
  516. int cwc,
  517. LPINT pdx,
  518. PVOID pvBuffer,
  519. DWORD dwCodePage
  520. );
  521. BOOL
  522. bDynamicModeChange(
  523. HDEV hdevOld,
  524. HDEV hdevNew
  525. );
  526. HDEV
  527. DrvGetHDEV(
  528. PUNICODE_STRING pusDeviceName
  529. );
  530. void
  531. DrvReleaseHDEV(
  532. PUNICODE_STRING pusDeviceName
  533. );
  534. BOOL
  535. bUMPD(
  536. HDC hdc
  537. );
  538. HSURF
  539. hsurfCreateCompatibleSurface(
  540. HDEV hdev,
  541. ULONG iFormat,
  542. HPALETTE hpal,
  543. int cx,
  544. int cy,
  545. BOOL bDriverCreatible
  546. );
  547. HBITMAP
  548. hbmSelectBitmap(
  549. HDC hdc,
  550. HBITMAP hbm,
  551. BOOL bDirectDrawOverride
  552. );
  553. __inline ULONG wcslensafe( const WCHAR *pwcString )
  554. {
  555. ULONG Length;
  556. ProbeForRead(pwcString, sizeof(WCHAR), sizeof(WCHAR));
  557. for (Length = 0; *pwcString; Length++)
  558. {
  559. pwcString += 1;
  560. ProbeForRead(pwcString, sizeof(WCHAR), sizeof(WCHAR));
  561. }
  562. return(Length);
  563. }
  564. BOOL
  565. ldevArtificialDecrement(
  566. LPWSTR pwszDriver
  567. );
  568. #define IS_USER_ADDRESS(x) (MM_LOWEST_USER_ADDRESS <= (x) && (x) <= MM_HIGHEST_USER_ADDRESS)
  569. //
  570. // ProbeAndWriteXXX macros to speed up performance [lingyunw]
  571. //
  572. /*
  573. #define ProbeAndWriteBuffer(Dst, Src, Length) { \
  574. if (((ULONG_PTR)Dst + Length <= (ULONG_PTR)Dst) || \
  575. ((ULONG_PTR)Dst >= (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { \
  576. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  577. } \
  578. \
  579. RtlCopyMemory(Dst, Src, Length); \
  580. }
  581. #define ProbeAndWriteAlignedBuffer(Dst, Src, Length, Alignment) { \
  582. \
  583. ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
  584. ((Alignment) == 4) || ((Alignment) == 8) || \
  585. ((Alignment) == 16)); \
  586. \
  587. if (((ULONG_PTR)Dst + Length <= (ULONG_PTR)Dst) || \
  588. ((ULONG_PTR)Dst >= (ULONG_PTR) MM_USER_PROBE_ADDRESS) || \
  589. ((((ULONG_PTR)Dst) & (Alignment - 1)) != 0)) { \
  590. *(volatile ULONG * const)MM_USER_PROBE_ADDRESS = 0; \
  591. } \
  592. \
  593. RtlCopyMemory(Dst, Src, Length); \
  594. }
  595. */
  596. VOID ProbeAndWriteBuffer(PVOID Dst, PVOID Src, ULONG Length);
  597. VOID ProbeAndWriteAlignedBuffer(PVOID Dst, PVOID Src, ULONG Length, ULONG Alignment);
  598. #define ProbeAndReadBuffer(Dst, Src, Length) { \
  599. if (((ULONG_PTR)Src + Length <= (ULONG_PTR)Src) || \
  600. ((ULONG_PTR)Src + Length > (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { \
  601. *(PULONG) Dst = *(volatile ULONG * const)MM_USER_PROBE_ADDRESS; \
  602. } \
  603. \
  604. RtlCopyMemory(Dst, Src, Length); \
  605. }
  606. #define ProbeAndReadAlignedBuffer(Dst, Src, Length, Alignment) { \
  607. \
  608. ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
  609. ((Alignment) == 4) || ((Alignment) == 8) || \
  610. ((Alignment) == 16)); \
  611. \
  612. if (((ULONG_PTR)Src + Length <= (ULONG_PTR)Src) || \
  613. ((ULONG_PTR)Src + Length > (ULONG_PTR)MM_USER_PROBE_ADDRESS) || \
  614. ((((ULONG_PTR)Src) & (Alignment - 1)) != 0)) { \
  615. *(PULONG) Dst = *(volatile ULONG * const)MM_USER_PROBE_ADDRESS; \
  616. } \
  617. \
  618. RtlCopyMemory(Dst, Src, Length); \
  619. }
  620. //
  621. // Cleanup types.
  622. //
  623. // Value Description
  624. // ---------------------- ---------------------------------------------
  625. // CLEANUP_NONE Default. System is not doing cleanup.
  626. //
  627. // CLEANUP_PROCESS Indicates system is doing process cleanup.
  628. //
  629. // CLEANUP_SESSION Indicates system is doing session cleanup
  630. // (i.e., Hydra shutdown).
  631. //
  632. typedef enum {
  633. CLEANUP_NONE,
  634. CLEANUP_PROCESS,
  635. CLEANUP_SESSION
  636. } CLEANUPTYPE;
  637. //
  638. // Gre semaphores
  639. //
  640. // The GreXXXSemaphore functions are analogous to the EngXXXSemaphore functions
  641. // in the DDI. However, this set is meant to be used by internal GDI code.
  642. //
  643. // They manipulate semaphores, which are re-entrant synchronization objects.
  644. //
  645. HSEMAPHORE GreCreateSemaphore();
  646. HSEMAPHORE GreCreateSemaphoreInternal(ULONG CreateFlags);
  647. VOID GreDeleteSemaphore(HSEMAPHORE);
  648. VOID FASTCALL GreAcquireSemaphore(HSEMAPHORE);
  649. VOID FASTCALL GreAcquireSemaphoreShared(HSEMAPHORE);
  650. VOID FASTCALL GreReleaseSemaphore(HSEMAPHORE);
  651. #ifdef CHECK_SEMAPHORE_USAGE
  652. VOID GreCheckSemaphoreUsage();
  653. #endif
  654. #ifdef VALIDATE_LOCKS
  655. VOID FASTCALL GreAcquireSemaphoreEx(HSEMAPHORE, ULONG, HSEMAPHORE);
  656. VOID FASTCALL GreReleaseSemaphoreEx(HSEMAPHORE);
  657. #else
  658. #define GreAcquireSemaphoreEx(hsem, order, parent) GreAcquireSemaphore(hsem)
  659. #define GreReleaseSemaphoreEx(hsem) GreReleaseSemaphore(hsem)
  660. #endif
  661. VOID GreAcquireHmgrSemaphore();
  662. VOID GreReleaseHmgrSemaphore();
  663. // Try not to use these two, okay? They peek into the internals
  664. // of the PERESOURCE/CRITICAL_SECTION
  665. BOOL GreIsSemaphoreOwned(HSEMAPHORE);
  666. BOOL GreIsSemaphoreOwnedByCurrentThread(HSEMAPHORE);
  667. BOOL GreIsSemaphoreSharedByCurrentThread(HSEMAPHORE);
  668. // Non-tracked semaphores, for use by the Hydra cleanup
  669. // semaphore-tracking code.
  670. HSEMAPHORE GreCreateSemaphoreNonTracked();
  671. VOID GreDeleteSemaphoreNonTracked(HSEMAPHORE);
  672. //
  673. // Gre fast mutexes
  674. //
  675. // The GreXXXFastMutex functions handle fast mutexes. These are like
  676. // semaphores, but not re-entrant.
  677. //
  678. DECLARE_HANDLE(HFASTMUTEX);
  679. HFASTMUTEX GreCreateFastMutex();
  680. VOID GreAcquireFastMutex(HFASTMUTEX);
  681. VOID GreReleaseFastMutex(HFASTMUTEX);
  682. VOID GreDeleteFastMutex(HFASTMUTEX);
  683. // Time functions
  684. VOID GreQuerySystemTime(PLARGE_INTEGER);
  685. VOID GreSystemTimeToLocalTime(PLARGE_INTEGER SystemTime, PLARGE_INTEGER LocalTime);
  686. //struct to keep track of kernel views used by printing
  687. typedef struct _FONTFILE_PRINTKVIEW
  688. {
  689. HFF hff;
  690. ULONG iFile;
  691. ULONG cPrint;
  692. PVOID pKView;
  693. ULONG_PTR iTTUniq;
  694. struct _FONTFILE_PRINTKVIEW *pNext;
  695. } FONTFILE_PRINTKVIEW, *PFONTFILE_PRINTKVIEW;
  696. extern FONTFILE_PRINTKVIEW *gpPrintKViewList;
  697. void UnmapPrintKView(HFF hff);
  698. // WINBUG #365390 4-10-2001 jasonha Need to get these constants from a header
  699. // We need these constants but they are not defined in a header that we
  700. // can include here in gre.
  701. #ifndef CP_ACP
  702. #define CP_ACP 0 /* default to ANSI code page */
  703. #define CP_OEMCP 1 /* default to OEM code page */
  704. #define CP_MACCP 2 /* default to MAC code page */
  705. #define CP_SYMBOL 42 /* symbol translation from winnls.h */
  706. #endif
  707. #ifdef DDI_WATCHDOG
  708. PWATCHDOG_DATA
  709. GreCreateWatchdogs(
  710. PDEVICE_OBJECT pDeviceObject,
  711. ULONG ulNumberOfWatchdogs,
  712. LONG lPeriod,
  713. PKDEFERRED_ROUTINE dpcCallback,
  714. PWSTR pwszDriverName,
  715. HANDLE hDriver,
  716. PLDEV *ppldevDriverList
  717. );
  718. VOID
  719. GreDeleteWatchdogs(
  720. PWATCHDOG_DATA pWatchdogData,
  721. ULONG ulNumberOfWatchdogs
  722. );
  723. //
  724. // This lock is used to control access to the watchdog's association list.
  725. //
  726. extern HFASTMUTEX gAssociationListMutex;
  727. //
  728. // Define watchdog macros to monitor time spent in display driver.
  729. // If this time exceeds DDI_TIMEOUT we will blue screen machine with
  730. // bugcheck code 0xEA (THREAD_STUCK_IN_DEVICE_DRIVER).
  731. //
  732. #define GreEnterMonitoredSection(ppdev, n) \
  733. { \
  734. if ((ppdev)->pWatchdogData) \
  735. { \
  736. WdEnterMonitoredSection((ppdev)->pWatchdogData[n].pWatchdog); \
  737. } \
  738. }
  739. #define GreExitMonitoredSection(ppdev, n) \
  740. { \
  741. if ((ppdev)->pWatchdogData) \
  742. { \
  743. WdExitMonitoredSection((ppdev)->pWatchdogData[n].pWatchdog); \
  744. } \
  745. }
  746. #define GreSuspendWatch(ppdev, n) \
  747. { \
  748. if ((ppdev)->pWatchdogData) \
  749. { \
  750. WdSuspendDeferredWatch((ppdev)->pWatchdogData[n].pWatchdog); \
  751. } \
  752. }
  753. #define GreResumeWatch(ppdev, n) \
  754. { \
  755. if ((ppdev)->pWatchdogData) \
  756. { \
  757. WdResumeDeferredWatch((ppdev)->pWatchdogData[n].pWatchdog, TRUE); \
  758. } \
  759. }
  760. #else
  761. #define GreEnterMonitoredSection(ppdev, n) NULL
  762. #define GreExitMonitoredSection(ppdev, n) NULL
  763. #define GreSuspendWatch(ppdev, n) NULL
  764. #define GreResumeWatch(ppdev, n) NULL
  765. #endif // DDI_WATCHDOG
  766. //
  767. // Draw stream prototyping work
  768. //
  769. BOOL GreDrawStream(HDC, ULONG, PVOID);
  770. //
  771. // Max surface width/height used in gre to quickly
  772. // check the width/height overflow
  773. //
  774. #define MAX_SURF_WIDTH ((ULONG_MAX - 15) >> 5)
  775. #define MAX_SURF_HEIGHT (ULONG_MAX >> 5)