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.

1193 lines
36 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: hmgshare.h
  3. *
  4. * Define shared dc attributes
  5. *
  6. * Created: 13-Apr-1995
  7. * Author: Mark Enstrom [marke]
  8. *
  9. * Copyright (c) 1995-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. /******************************WOW64***NOTE********************************\
  12. * Note: Win32k Memory shared with User-Mode and Wow64
  13. *
  14. * For Wow64 (Win32 apps on Win64) we build a 32-bit version
  15. * of user32.dll & gdi32.dll which can run against the 64-bit kernel
  16. * with no changes to the 64-bit kernel code.
  17. *
  18. * For the 32 on 64 bit dlls all data structures which are shared with
  19. * win32k must be 64-bit. These data structures include the shared
  20. * sections, as well as the GDI TEB Batch.
  21. * These shared data structures are now declared so that they can be
  22. * built as 32 bit in a 32 bit dll, 64 bit in a 64 bit dll, and now
  23. * 64 bit in a 32 bit dll.
  24. *
  25. * The following rules should be followed when declaring
  26. * shared data structures:
  27. *
  28. * Pointers in shared data structures use the KPTR_MODIFIER in their
  29. * declaration.
  30. *
  31. * Handles in shared data structures are declared KHxxx.
  32. *
  33. * xxx_PTR changes to KERNEL_xxx_PTR.
  34. *
  35. * Pointers to basic types are declared as KPxxx;
  36. *
  37. * Also on Wow64 every thread has both a 32-bit TEB and a 64-bit TEB.
  38. * GetCurrentTeb() returns the current 32-bit TEB while the kernel
  39. * will allways reference the 64-bit TEB.
  40. *
  41. * All client side references to shared data in the TEB should use
  42. * the new GetCurrentTebShared() macro which returns the 64-bit TEB
  43. * for Wow64 builds and returns GetCurrentTeb() for regular builds.
  44. * The exception to this rule is LastErrorValue, which should allways
  45. * be referenced through GetCurrentTeb().
  46. *
  47. * Ex:
  48. *
  49. * DECLARE_HANDLE(HFOO);
  50. *
  51. * typedef struct _MY_STRUCT * KPTR_MODIFIER PMPTR;
  52. *
  53. * struct _SHARED_STRUCT
  54. * {
  55. * struct _SHARED_STRUCT * pNext;
  56. * PMPTR pmptr;
  57. * HFOO hFoo;
  58. * UINT_PTR cb;
  59. * PBYTE pb;
  60. * PVOID pv;
  61. *
  62. * DWORD dw;
  63. * USHORT us;
  64. * } SHARED_STRUCT;
  65. *
  66. *
  67. * Changes to:
  68. *
  69. *
  70. * DECLARE_HANDLE(HFOO);
  71. * DECLARE_KHANDLE(HFOO);
  72. *
  73. * typedef struct _MY_STRUCT *PMPTR;
  74. *
  75. * struct _SHARED_STRUCT
  76. * {
  77. * struct _SHARED_STRUCT * KPTR_MODIFIER pNext;
  78. * PMPTR pmptr;
  79. * KHFOO hFoo;
  80. * KERNEL_UINT_PTR cb;
  81. * KPBYTE pb;
  82. * KERNEL_PVOID pv;
  83. *
  84. * DWORD dw;
  85. * USHORT us;
  86. * } SHARED_STRUCT;
  87. \***************************************************************************/
  88. #ifndef GDIFLAGS_ONLY // used for gdikdx
  89. #include <w32wow64.h>
  90. //Sundown: offsetof generates truncation warnings in 64bit environment
  91. #undef offsetof
  92. #define offsetof(c,f) FIELD_OFFSET(c,f)
  93. /*********************************Structure********************************\
  94. *
  95. * RGNATTR
  96. *
  97. * Description:
  98. *
  99. * As an accelerator, this rectangular region is kept in the DC and
  100. * represents either a NULL region, a rectangular region, or hte bounding
  101. * box of a complex region. This can be used for a trivial reject clip test.
  102. *
  103. * Fields:
  104. *
  105. * Flags - state flags
  106. * NULLREGION - drawing is allowed anywhere, no trivial clip
  107. * SIMPLEREGION - Rect is the clip region
  108. * COMPLEXREGION - Rect is the bounding box of a complex clip region
  109. * ERROR - this information may not be used
  110. *
  111. * LRFlags - valid and dirty flags
  112. *
  113. * Rect - clip rectangle or bounding rectangle when in use
  114. *
  115. \**************************************************************************/
  116. #endif // GDIFLAGS_ONLY used for gdikdx
  117. #define RREGION_INVALID ERROR
  118. //
  119. // ExtSelectClipRgn iMode extra flag for batching
  120. //
  121. #define REGION_NULL_HRGN 0X8000000
  122. #ifndef GDIFLAGS_ONLY // used for gdikdx
  123. typedef struct _RGNATTR
  124. {
  125. ULONG AttrFlags;
  126. ULONG Flags;
  127. RECTL Rect;
  128. } RGNATTR,*PRGNATTR;
  129. /*******************************STRUCTURE**********************************\
  130. * BRUSHATTR
  131. *
  132. * Fields:
  133. *
  134. * lbColor - Color from CreateSolidBrush
  135. * lflag - Brush operation flags
  136. *
  137. * CACHED - Set only when brush is cached on PEB
  138. * TO_BE_DELETED - Set only after DelteteBrush Called in kernel
  139. * when reference count of brush > 1, this will
  140. * cause the brush to be deleted via lazy delete
  141. * when it is selected out later.
  142. * NEW_COLOR - Set when color changes (retrieve cached brush)
  143. * ATTR_CANT_SELECT - Set when user calls DeleteObject(hbrush),
  144. * brush is marked so can't be seleced in user
  145. * mode. Not deleted until kernel mode DeleteBrush.
  146. * This is not currently implemented.
  147. *
  148. * History:
  149. *
  150. * 6-Feb-1996 -by- Mark Enstrom [marke]
  151. *
  152. \**************************************************************************/
  153. typedef struct _BRUSHATTR
  154. {
  155. ULONG AttrFlags;
  156. COLORREF lbColor;
  157. } BRUSHATTR,*PBRUSHATTR;
  158. #endif // GDIFLAGS_ONLY used for gdikdx
  159. //
  160. // Common flags for dealing with RGN/BRUSH ATTR memory
  161. //
  162. #define ATTR_CACHED 0x00000001
  163. #define ATTR_TO_BE_DELETED 0x00000002
  164. #define ATTR_NEW_COLOR 0x00000004
  165. #define ATTR_CANT_SELECT 0x00000008
  166. #define ATTR_RGN_VALID 0x00000010
  167. #define ATTR_RGN_DIRTY 0x00000020
  168. #ifndef GDIFLAGS_ONLY // used for gdikdx
  169. //
  170. // Define a union so these objects can be managed together
  171. //
  172. typedef union _OBJECTATTR
  173. {
  174. RGNATTR Rgnattr;
  175. BRUSHATTR Brushattr;
  176. }OBJECTATTR,*POBJECTATTR;
  177. /**************************************************************************\
  178. *
  179. * XFORM related structures and macros
  180. *
  181. \**************************************************************************/
  182. //
  183. // These types are used to get things right when C code is passing C++
  184. // defined transform data around.
  185. //
  186. typedef struct _MATRIX_S
  187. {
  188. EFLOAT_S efM11;
  189. EFLOAT_S efM12;
  190. EFLOAT_S efM21;
  191. EFLOAT_S efM22;
  192. EFLOAT_S efDx;
  193. EFLOAT_S efDy;
  194. FIX fxDx;
  195. FIX fxDy;
  196. FLONG flAccel;
  197. } MATRIX_S;
  198. #endif // GDIFLAGS_ONLY used for gdikdx
  199. //
  200. // status and dirty flags
  201. //
  202. #define DIRTY_FILL 0x00000001
  203. #define DIRTY_LINE 0x00000002
  204. #define DIRTY_TEXT 0x00000004
  205. #define DIRTY_BACKGROUND 0x00000008
  206. #define DIRTY_CHARSET 0x00000010
  207. #define SLOW_WIDTHS 0x00000020
  208. #define DC_CACHED_TM_VALID 0x00000040
  209. #define DISPLAY_DC 0x00000080
  210. #define DIRTY_PTLCURRENT 0x00000100
  211. #define DIRTY_PTFXCURRENT 0x00000200
  212. #define DIRTY_STYLESTATE 0x00000400
  213. #define DC_PLAYMETAFILE 0x00000800
  214. #define DC_BRUSH_DIRTY 0x00001000 // cached brush
  215. #define DC_PEN_DIRTY 0x00002000
  216. #define DC_DIBSECTION 0x00004000
  217. #define DC_LAST_CLIPRGN_VALID 0x00008000
  218. #define DC_PRIMARY_DISPLAY 0x00010000
  219. #define DIRTY_COLORTRANSFORM 0x00020000
  220. #define ICM_BRUSH_TRANSLATED 0x00040000
  221. #define ICM_PEN_TRANSLATED 0x00080000
  222. #define DIRTY_COLORSPACE 0x00100000
  223. #define BATCHED_DRAWING 0x00200000
  224. #define BATCHED_TEXT 0x00400000
  225. #ifndef GDIFLAGS_ONLY // used for gdikdx
  226. #define CLEAR_CACHED_TEXT(pdcattr) (pdcattr->ulDirty_ &= ~(SLOW_WIDTHS))
  227. #define DIRTY_BRUSHES (DIRTY_FILL+DIRTY_LINE+DIRTY_TEXT+DIRTY_BACKGROUND)
  228. #define USER_XFORM_DIRTY(pdcattr) (pdcattr->flXform & (PAGE_XLATE_CHANGED | PAGE_EXTENTS_CHANGED | WORLD_XFORM_CHANGED))
  229. #endif // GDIFLAGS_ONLY used for gdikdx
  230. /**************************************************************************\
  231. *
  232. * ICM related structures and macros
  233. *
  234. \**************************************************************************/
  235. //
  236. // ICM flags
  237. //
  238. // DC_ATTR.lIcmMode
  239. //
  240. // 0x0 000 0 0 00
  241. // | | | | + Current ICM Mode (kernel/user)
  242. // | | | + Requested ICM Mode (kernel/user)
  243. // | | + ICM Mode context (user only)
  244. // | + not used
  245. // + Destination color type (kernel/user)
  246. #define DC_ICM_USERMODE_FLAG 0x0000F000
  247. //
  248. // Current ICM mode flags.
  249. //
  250. #define DC_ICM_OFF 0x00000000
  251. #define DC_ICM_HOST 0x00000001
  252. #define DC_ICM_DEVICE 0x00000002
  253. #define DC_ICM_OUTSIDEDC 0x00000004
  254. #define DC_ICM_METAFILING_ON 0x00000008
  255. #define DC_ICM_LAZY_CORRECTION 0x00000010 // alt mode (preserved through icm mode change)
  256. #define DC_ICM_DEVICE_CALIBRATE 0x00000020 // alt mode (preserved through icm mode change)
  257. #define DC_ICM_MODE_MASK 0x000000FF
  258. #define DC_ICM_ALT_MODE_MASK 0x000000F0
  259. #ifndef GDIFLAGS_ONLY // used for gdikdx
  260. #define ICM_MODE(x) ((x) & DC_ICM_MODE_MASK)
  261. #define ICM_ALT_MODE(x) ((x) & DC_ICM_ALT_MODE_MASK)
  262. #define IS_ICM_DEVICE(x) ((x) & DC_ICM_DEVICE)
  263. #define IS_ICM_HOST(x) ((x) & DC_ICM_HOST)
  264. #define IS_ICM_INSIDEDC(x) ((x) & (DC_ICM_DEVICE|DC_ICM_HOST))
  265. #define IS_ICM_OUTSIDEDC(x) ((x) & DC_ICM_OUTSIDEDC)
  266. #define IS_ICM_ON(x) ((x) & (DC_ICM_DEVICE|DC_ICM_HOST|DC_ICM_OUTSIDEDC))
  267. #define IS_ICM_METAFILING_ON(x) ((x) & DC_ICM_METAFILING_ON)
  268. #define IS_ICM_LAZY_CORRECTION(x) ((x) & DC_ICM_LAZY_CORRECTION)
  269. #define IS_ICM_DEVICE_CALIBRATE(x) ((x) & DC_ICM_DEVICE_CALIBRATE)
  270. #endif // GDIFLAGS_ONLY used for gdikdx
  271. //
  272. // Request ICM mode flags
  273. //
  274. #define REQ_ICM_OFF 0x00000000
  275. #define REQ_ICM_HOST 0x00000100
  276. #define REQ_ICM_DEVICE 0x00000200
  277. #define REQ_ICM_OUTSIDEDC 0x00000400
  278. #ifndef GDIFLAGS_ONLY // used for gdikdx
  279. #define REQ_ICM_MODE(x) ((x) & 0x00000F00)
  280. #define IS_ICM_DEVICE_REQUESTED(x) ((x) & REQ_ICM_DEVICE)
  281. //
  282. // Convert Request mode to current ICM mode flags.
  283. //
  284. #define ICM_REQ_TO_MODE(x) ((REQ_ICM_MODE((x))) >> 8)
  285. #endif // GDIFLAGS_ONLY used for gdikdx
  286. //
  287. // Context mode for ICM.
  288. //
  289. #define CTX_ICM_HOST 0x00001000 // Host ICM
  290. #define CTX_ICM_DEVICE 0x00002000 // Device ICM
  291. #define CTX_ICM_METAFILING_OUTSIDEDC 0x00004000 // Metfiling outside DC ICM mode
  292. #define CTX_ICM_PROOFING 0x00008000 // Proofing mode
  293. #ifndef GDIFLAGS_ONLY // used for gdikdx
  294. #define SET_HOST_ICM_DEVMODE(x) ((x) |= CTX_ICM_HOST)
  295. #define SET_DEVICE_ICM_DEVMODE(x) ((x) |= CTX_ICM_DEVICE)
  296. #define SET_ICM_PROOFING(x) ((x) |= CTX_ICM_PROOFING)
  297. #define CLEAR_ICM_PROOFING(x) ((x) &= ~CTX_ICM_PROOFING)
  298. #define IS_DEVICE_ICM_DEVMODE(x) ((x) & CTX_ICM_DEVICE)
  299. #define IS_ICM_PROOFING(x) ((x) & CTX_ICM_PROOFING)
  300. #endif // GDIFLAGS_ONLY used for gdikdx
  301. //
  302. // Destination Color Type
  303. //
  304. #define DC_ICM_CMYK_COLOR 0x10000000
  305. #define DC_ICM_RGB_COLOR 0x20000000
  306. #define DC_ICM_COLORTYPE_MASK 0xF0000000
  307. #ifndef GDIFLAGS_ONLY // used for gdikdx
  308. #define DC_ICM_32BITS_COLOR (DC_ICM_CMYK_COLOR)
  309. #define IS_32BITS_COLOR(x) ((x) & DC_ICM_32BITS_COLOR)
  310. #define IS_CMYK_COLOR(x) ((x) & DC_ICM_CMYK_COLOR)
  311. #define GET_COLORTYPE(x) ((x) & DC_ICM_COLORTYPE_MASK)
  312. #define CLEAR_COLORTYPE(x) ((x) &= ~DC_ICM_COLORTYPE_MASK)
  313. /******************************Structure***********************************\
  314. *
  315. * DC_ATTR: This structure provides a common DC area visible both by in kernel
  316. * and user mode. Since elements in the DC_ATTR are visible and modifiable
  317. * in user-mode, data that must be kept safe must be stored in the kernel
  318. * private DC structure.
  319. *
  320. \**************************************************************************/
  321. typedef struct _DC_ATTR
  322. {
  323. //
  324. // local dc info
  325. //
  326. KERNEL_PVOID pvLDC;
  327. //
  328. // General Purpose Dirty Flags for brushes, fonts, etc.
  329. //
  330. ULONG ulDirty_;
  331. //
  332. // brush handle selected into DCATTR, not neccessarily selected
  333. // into DC
  334. //
  335. KHANDLE hbrush;
  336. KHANDLE hpen;
  337. //
  338. // *** Attribute Bundles ***
  339. //
  340. // When ICM is enabled,
  341. // + cr____Clr color is corrected to DC's color space.
  342. // + ul____Clr keeps original (un-corrected) color.
  343. //
  344. COLORREF crBackgroundClr; // Set/GetBkColor
  345. ULONG ulBackgroundClr; // Set/GetBkColor client attr
  346. COLORREF crForegroundClr; // Set/GetTextColor
  347. ULONG ulForegroundClr; // Set/GetTextColor client attr
  348. //
  349. // *** DC Brush color
  350. //
  351. // When ICM is enabled,
  352. // + cr____Clr color is corrected to DC's color space.
  353. // + ul____Clr keeps original (un-corrected) color.
  354. //
  355. COLORREF crDCBrushClr; // Set/GetDCBrushColor client attr
  356. ULONG ulDCBrushClr; // Set/GetDCBrushColor client attr
  357. COLORREF crDCPenClr; // Set/GetDCPenColor
  358. ULONG ulDCPenClr; // Set/GetDCPenColor client attr
  359. //
  360. // *** Misc. Attrs.
  361. //
  362. DWORD iCS_CP; // LOWORD: code page HIWORD charset
  363. int iGraphicsMode; // Set/GetGraphicsMode
  364. BYTE jROP2; // Set/GetROP2
  365. BYTE jBkMode; // TRANSPARENT/OPAQUE
  366. BYTE jFillMode; // ALTERNATE/WINDING
  367. BYTE jStretchBltMode; // BLACKONWHITE/WHITEONBLACK/
  368. // COLORONCOLOR/HALFTONE
  369. POINTL ptlCurrent; // Current position in logical coordinates
  370. // (invalid if DIRTY_PTLCURRENT set)
  371. POINTL ptfxCurrent; // Current position in device coordinates
  372. // (invalid if DIRTY_PTFXCURRENT set)
  373. //
  374. // original values set by app
  375. //
  376. LONG lBkMode;
  377. LONG lFillMode;
  378. LONG lStretchBltMode;
  379. FLONG flFontMapper; // Font mapper flags
  380. //
  381. // *** ICM attributes
  382. //
  383. LONG lIcmMode; // Currnt ICM mode (DC_ICM_xxxx)
  384. KHANDLE hcmXform; // Handle of Current Color Transform
  385. KHCOLORSPACE hColorSpace; // Handle of Source Color Space
  386. KERNEL_ULONG_PTR dwDIBColorSpace; // Identifier of DIB Color Space Data (when DIB selected)
  387. // Sundown: dwDIBColorSpace actually takes a pointer in,
  388. // change from DWORD to ULONG_PTR
  389. COLORREF IcmBrushColor; // ICM-ed color for the brush selected in this DCATTR (Solid or Hatch)
  390. COLORREF IcmPenColor; // ICM-ed color for the pen selected in this DCATTR
  391. KERNEL_PVOID pvICM; // Pointer to client-side ICM information
  392. //
  393. // *** Text attributes
  394. //
  395. FLONG flTextAlign;
  396. LONG lTextAlign;
  397. LONG lTextExtra; // Inter-character spacing
  398. LONG lRelAbs; // Moved over from client side
  399. LONG lBreakExtra;
  400. LONG cBreak;
  401. KHANDLE hlfntNew; // Log font selected into DC
  402. //
  403. // Transform data.
  404. //
  405. MATRIX_S mxWtoD; // World to Device Transform.
  406. MATRIX_S mxDtoW; // Device to World.
  407. MATRIX_S mxWtoP; // World transform
  408. EFLOAT_S efM11PtoD; // efM11 of the Page transform
  409. EFLOAT_S efM22PtoD; // efM22 of the Page transform
  410. EFLOAT_S efDxPtoD; // efDx of the Page transform
  411. EFLOAT_S efDyPtoD; // efDy of the Page transform
  412. INT iMapMode; // Map mode
  413. DWORD dwLayout; // Layout orientation bits.
  414. LONG lWindowOrgx; // The logical x window origin.
  415. POINTL ptlWindowOrg; // Window origin.
  416. SIZEL szlWindowExt; // Window extents.
  417. POINTL ptlViewportOrg; // Viewport origin.
  418. SIZEL szlViewportExt; // Viewport extents.
  419. FLONG flXform; // Flags for transform component.
  420. SIZEL szlVirtualDevicePixel; // Virtual device size in pels.
  421. SIZEL szlVirtualDeviceMm; // Virtual device size in mm's.
  422. SIZEL szlVirtualDevice; // Virtual device size
  423. POINTL ptlBrushOrigin; // Alignment origin for brushes
  424. //
  425. // dc regions
  426. //
  427. RGNATTR VisRectRegion;
  428. } DC_ATTR,*PDC_ATTR;
  429. //
  430. // conditional system definitions
  431. //
  432. #if !defined(_NTOSP_) && !defined(_USERKDX_)
  433. typedef struct _W32THREAD * KPTR_MODIFIER PW32THREAD;
  434. typedef ULONG W32PID;
  435. DECLARE_HANDLE(HOBJ);
  436. DECLARE_KHANDLE(HOBJ);
  437. #endif
  438. /*****************************Struct***************************************\
  439. *
  440. * BASEOBJECT
  441. *
  442. * Description:
  443. *
  444. * Each GDI object has a BASEOBJECT at the beggining of the object. This
  445. * enables fast references to the handle and back to the entry.
  446. *
  447. * Fields:
  448. *
  449. * hHmgr - object handle
  450. * ulShareCount - the shared reference count on the object
  451. * cExclusiveLock - object exclusive lock count
  452. * BaseFlags - flags representing state of underlying memory
  453. * tid - thread id of exclusive lock owner
  454. *
  455. * Note:
  456. *
  457. * Most of the BASEOBJECT represents state logically associated with the
  458. * object. When objects are swapped (for example, when doing a realloc
  459. * to grow the object), the BASEOBJECT is swapped to preserve the handle
  460. * and locking information.
  461. *
  462. * However, the BaseFlags field was added as an optimization to allow
  463. * allocation from a "lookaside" list of preallocated objects. The
  464. * BaseFlags field is metadata associated with the memory containing
  465. * an object; it is not associated with the object itself.
  466. *
  467. * Current BASEOBJECT swapping code "unswaps" the BaseFlags so that it
  468. * always remains associated with the memory, not the object.
  469. *
  470. * If flags are added to BaseFlags, they must not represent object state.
  471. * If it is necessary to add such flags, the BaseFlags field could be
  472. * reduced to a BYTE field and a new BYTE flags field can be added to
  473. * represent state that is associated with the object.
  474. *
  475. * Currently, BASEOBJECT swapping code is in HmgSwapLockedHandleContents
  476. * and RGNOBJ::bSwap (hmgrapi.cxx and rgnobj.cxx, respectively).
  477. *
  478. \**************************************************************************/
  479. // BASEOBJECT FLAGS
  480. //
  481. // Due to the read-modify-write cycle and the fact that the Alpha can
  482. // load and store a minimum of 32bit values, setting BaseFlags requires
  483. // an InterlockedCompareExchange loop so that it doesn't interfere with the
  484. // cExclusiveLock.
  485. //
  486. // HMGR_LOOKASIDE_ALLOC_FLAG is a 'static' flag - it doesn't change after
  487. // it is set on object allocation. If anyone adds a 'dynamic' flag they
  488. // should probably restructure BASEOBJECT to use a DWORD for the BaseFlags and
  489. // a DWORD for the cExclusiveLock.
  490. //
  491. // If anyone restructures BASEOBJECT they'll have to rewrite all the code
  492. // that uses cExclusiveLock and BaseFlags.
  493. // This includes:
  494. // INC_EXCLUSIVE_REF_CNT and DEC_EXCLUSIVE_REF_CNT
  495. // RGNOBJ::bSwap
  496. //
  497. // Also if anyone adds fields to BASEOBJECT they need to go and fix RGNOBJ::bSwap
  498. // to also copy those fields.
  499. //
  500. //
  501. #endif // GDIFLAGS_ONLY used for gdikdx
  502. #define HMGR_LOOKASIDE_ALLOC_FLAG 0x8000
  503. #ifndef GDIFLAGS_ONLY // used for gdikdx
  504. typedef struct _BASEOBJECT
  505. {
  506. KHANDLE hHmgr;
  507. ULONG ulShareCount;
  508. USHORT cExclusiveLock;
  509. USHORT BaseFlags;
  510. PW32THREAD Tid;
  511. } BASEOBJECT, * KPTR_MODIFIER POBJ;
  512. /*****************************Struct***************************************\
  513. *
  514. * OBJECTOWNER
  515. *
  516. * Description:
  517. *
  518. * This object is used for shared and exclusive object ownership
  519. *
  520. * Fields for shared Object:
  521. *
  522. * Pid : 31
  523. * Lock : 1
  524. *
  525. \**************************************************************************/
  526. //
  527. // The lock and the Pid share the same DWORD.
  528. //
  529. // It seems that this is safe from the word tearing problem on the Alpha architecture
  530. // due to the fact that we always use the InterlockedCompareExchange loop for
  531. // the Lock and we require that the lock is set when setting the Pid.
  532. //
  533. typedef struct _OBJECTOWNER_S
  534. {
  535. ULONG Lock:1;
  536. W32PID Pid_Shifted:31; // The lowest two bits of the PID are
  537. // reserved for application use. However,
  538. // the second bit is used by the
  539. // OBJECT_OWNER_xxxx constants and so we
  540. // use 31 bits for the Pid_Shifted field.
  541. // WARNING: do not access this field directly,
  542. // but rather via the macros below.
  543. }OBJECTOWNER_S,*POBJECTOWNER_S;
  544. #endif // GDIFLAGS_ONLY used for gdikdx
  545. // Note: when accessing the Pid_Shifted field the compiler will shift the
  546. // value by one bit to account for the field being only in the upper 31
  547. // bits of the OBJECTOWNER_S structure. For example, if the OBJECTOWNER_S
  548. // is 8, the Pid_Shifted would be only 4. However, since we are really
  549. // interested in the upper 31 bits of the PID, this shifting is not
  550. // appropriate (we need masking instead). I'm not aware of any compiler
  551. // primitives that will accomplish this and will use the macros below
  552. // instead.
  553. #define LOCK_MASK 0x00000001
  554. #define PID_MASK 0xfffffffe
  555. #define PID_BITS 0xfffffffc // The actual bits used by the PID
  556. #ifndef GDIFLAGS_ONLY // used for gdikdx
  557. #define OBJECTOWNER_PID(ObjectOwner) \
  558. ((W32PID) ((ObjectOwner).ulObj & PID_MASK))
  559. #define SET_OBJECTOWNER_PID(ObjectOwner, Pid) \
  560. ((ObjectOwner).ulObj) = ((ObjectOwner).ulObj & LOCK_MASK) | ((Pid) & PID_MASK);
  561. typedef union _OBJECTOWNER
  562. {
  563. OBJECTOWNER_S Share;
  564. ULONG ulObj;
  565. }OBJECTOWNER,*POBJECTOWNER;
  566. typedef UCHAR OBJTYPE;
  567. typedef union _EINFO
  568. {
  569. POBJ pobj; // Pointer to object
  570. HOBJ hFree; // Next entry in free list
  571. } EINFO;
  572. #endif // GDIFLAGS_ONLY used for gdikdx
  573. /*****************************Struct***************************************\
  574. *
  575. * ENTRY
  576. *
  577. * Description:
  578. *
  579. * This object is allocated for each entry in the handle manager and
  580. * keeps track of object owners, reference counts, pointers, and handle
  581. * objt and iuniq
  582. *
  583. * Fields:
  584. *
  585. * einfo - pointer to object or next free handle
  586. * ObjectOwner - lock object
  587. * ObjectInfo - Object Type, Unique and flags
  588. * pUser - Pointer to user-mode data
  589. *
  590. \**************************************************************************/
  591. // entry.Flags flags
  592. #define HMGR_ENTRY_UNDELETABLE 0x0001
  593. #define HMGR_ENTRY_LAZY_DEL 0x0002
  594. #define HMGR_ENTRY_INVALID_VIS 0x0004
  595. #define HMGR_ENTRY_LOOKASIDE_ALLOC 0x0010
  596. #ifndef GDIFLAGS_ONLY // used for gdikdx
  597. typedef struct _ENTRY
  598. {
  599. EINFO einfo;
  600. OBJECTOWNER ObjectOwner;
  601. USHORT FullUnique;
  602. OBJTYPE Objt;
  603. UCHAR Flags;
  604. KERNEL_PVOID pUser;
  605. } ENTRY, *PENTRY;
  606. typedef union _PENTOBJ
  607. {
  608. PENTRY pent;
  609. POBJ pobj;
  610. } PENTOBJ;
  611. #endif // GDIFLAGS_ONLY used for gdikdx
  612. //
  613. // status flags used by metafile in user and kernel
  614. //
  615. #define MRI_ERROR 0
  616. #define MRI_NULLBOX 1
  617. #define MRI_OK 2
  618. /*******************************STRUCTURE**********************************\
  619. * GDIHANDLECACHE
  620. *
  621. * Cache common handle types, when a handle with user mode attributes is
  622. * deleted, an attempt is made to cache the handle on memory accessable
  623. * in user mode.
  624. *
  625. * Fields:
  626. *
  627. * Lock - CompareExchange used to gain ownership
  628. * pCacheEntr[] - array of offsets to types
  629. * ulBuffer - buffer for storage of all handle cache entries
  630. *
  631. *
  632. * History:
  633. *
  634. * 30-Jan-1996 -by- Mark Enstrom [marke]
  635. *
  636. \**************************************************************************/
  637. //
  638. // defined cached handle types
  639. //
  640. #define GDI_CACHED_HADNLE_TYPES 4
  641. #define CACHE_BRUSH_ENTRIES 10
  642. #define CACHE_PEN_ENTRIES 8
  643. #define CACHE_REGION_ENTRIES 8
  644. #define CACHE_LFONT_ENTRIES 1
  645. #ifndef GDIFLAGS_ONLY // used for gdikdx
  646. typedef enum _HANDLECACHETYPE
  647. {
  648. BrushHandle,
  649. PenHandle,
  650. RegionHandle,
  651. LFontHandle
  652. }HANDLECACHETYPE,*PHANDLECACHETYPE;
  653. typedef struct _GDIHANDLECACHE
  654. {
  655. KERNEL_PVOID Lock;
  656. ULONG ulNumHandles[GDI_CACHED_HADNLE_TYPES];
  657. KHANDLE Handle[CACHE_BRUSH_ENTRIES +
  658. CACHE_PEN_ENTRIES +
  659. CACHE_REGION_ENTRIES +
  660. CACHE_LFONT_ENTRIES];
  661. }GDIHANDLECACHE,*PGDIHANDLECACHE;
  662. /*********************************MACRO************************************\
  663. * Lock handle cache by placing -1 into lock variable using cmp-exchange
  664. *
  665. * Arguments:
  666. *
  667. * p - handle cache pointer
  668. * uLock - Thread specific lock ID (TEB or THREAD)
  669. * bStatus - Lock status
  670. *
  671. * History:
  672. *
  673. * 22-Feb-1996 -by- Mark Enstrom [marke]
  674. *
  675. \**************************************************************************/
  676. #if defined(BUILD_WOW6432)
  677. KERNEL_PVOID
  678. InterlockedCompareExchangeKernelPointer(
  679. KERNEL_PVOID *Destination,
  680. KERNEL_PVOID Exchange,
  681. KERNEL_PVOID Compare
  682. );
  683. #else
  684. #define InterlockedCompareExchangeKernelPointer InterlockedCompareExchangePointer
  685. #endif
  686. #define LOCK_HANDLE_CACHE(p,uLock,bStatus) \
  687. { \
  688. KERNEL_PVOID OldLock = p->Lock; \
  689. bStatus = FALSE; \
  690. \
  691. if (OldLock == NULL) \
  692. { \
  693. if (InterlockedCompareExchangeKernelPointer( \
  694. &p->Lock, \
  695. uLock, \
  696. OldLock) == OldLock) \
  697. { \
  698. bStatus = TRUE; \
  699. } \
  700. } \
  701. }
  702. /*********************************MACRO************************************\
  703. * unlock locked structure by writing null back to lock variable
  704. *
  705. * Arguments:
  706. *
  707. * p - pointer to handle cache
  708. *
  709. * Return Value:
  710. *
  711. * none
  712. *
  713. * History:
  714. *
  715. * 22-Feb-1996 -by- Mark Enstrom [marke]
  716. *
  717. \**************************************************************************/
  718. #if defined(BUILD_WOW6432) && defined(_X86_)
  719. /* It is assumed that p->Lock will be updated atomically. This is true for alpha,
  720. but it is not true for the 32bit x86 dll on wow64 since Lock is a 64bit quantity
  721. which requires 2 mov instructions. So call InterlockedCompareExchangeKernelPointer
  722. to set it.
  723. */
  724. #define UNLOCK_HANDLE_CACHE(p) \
  725. InterlockedCompareExchangeKernelPointer(&p->Lock, NULL, p->Lock);
  726. #else
  727. #define UNLOCK_HANDLE_CACHE(p) \
  728. { \
  729. p->Lock = NULL; \
  730. }
  731. #endif
  732. #endif // GDIFLAGS_ONLY used for gdikdx
  733. /******************************Struct**************************************\
  734. * CFONT
  735. *
  736. * Client side realized font. Contains widths of all ANSI characters.
  737. *
  738. * We keep a free list of CFONT structures for fast allocation. The
  739. * reference count counts pointers to this structure from all LDC and
  740. * LOCALFONT structures. When this count hits zero, the CFONT is freed.
  741. *
  742. * The only "inactive" CFONTs that we keep around are those referenced by
  743. * the LOCALFONT.
  744. *
  745. * (In the future we could expand this to contain UNICODE info as well.)
  746. *
  747. * Mon 11-Jun-1995 00:36:14 -by- Gerrit van Wingerden [gerritv]
  748. * Addapted for kernel mode
  749. * Sun 10-Jan-1993 00:36:14 -by- Charles Whitmer [chuckwh]
  750. * Wrote it.
  751. \**************************************************************************/
  752. #define CFONT_COMPLETE 0x0001
  753. #define CFONT_EMPTY 0x0002
  754. #define CFONT_DBCS 0x0004
  755. #define CFONT_CACHED_METRICS 0x0008 // we have cached the metrics
  756. #define CFONT_CACHED_AVE 0x0010 // we have cached the average width
  757. #define CFONT_CACHED_WIDTHS 0x0020 // if off, no widths have been computed
  758. #define CFONT_PUBLIC 0x0040 // if public font in public cache
  759. #define CFONT_CACHED_RI 0x0080 // if off, RealizationInfo (RI) has not been cached
  760. #ifndef GDIFLAGS_ONLY // used for gdikdx
  761. #define DEC_CFONT_REF(pcf) {if (!((pcf)->fl & CFONT_PUBLIC)) --(pcf)->cRef;}
  762. #define INC_CFONT_REF(pcf) {ASSERTGDI(!((pcf)->fl & CFONT_PUBLIC),"pcfLocate - public font error\n");++(pcf)->cRef;}
  763. typedef struct _CFONT * KPTR_MODIFIER PCFONT;
  764. typedef struct _CFONT
  765. {
  766. PCFONT pcfNext;
  767. KHFONT hf;
  768. ULONG cRef; // Count of all pointers to this CFONT.
  769. FLONG fl;
  770. LONG lHeight; // Precomputed logical height.
  771. // The following are keys to match when looking for a mapping.
  772. KHDC hdc; // HDC of realization. 0 for display.
  773. EFLOAT_S efM11; // efM11 of WtoD of DC of realization
  774. EFLOAT_S efM22; // efM22 of WtoD of DC of realization
  775. EFLOAT_S efDtoWBaseline; // Precomputed back transform. (FXtoL)
  776. EFLOAT_S efDtoWAscent; // Precomputed back transform. (FXtoL)
  777. // various extra width info
  778. WIDTHDATA wd;
  779. // Font info flags.
  780. FLONG flInfo;
  781. // The width table.
  782. USHORT sWidth[256]; // Widths in pels.
  783. // other usefull cached info
  784. ULONG ulAveWidth; // bogus average used by USER
  785. TMW_INTERNAL tmw; // cached metrics
  786. #ifdef LANGPACK
  787. // RealizationInfo for this font
  788. REALIZATION_INFO ri ;
  789. #endif
  790. LONG timeStamp; // to check if cached realization info is updated
  791. } CFONT;
  792. /*******************************STRUCTURE**********************************\
  793. *
  794. * This structure controls the address for allocating and mapping the
  795. * global shared handle table and device caps (primary display) that
  796. * is mapped read-only into all user mode processes
  797. *
  798. * Fields:
  799. *
  800. * aentryHmgr - Handle table
  801. * DevCaps - Cached primary display device caps
  802. *
  803. \**************************************************************************/
  804. #define MAX_PUBLIC_CFONT 16
  805. typedef struct _GDI_SHARED_MEMORY
  806. {
  807. ENTRY aentryHmgr[MAX_HANDLE_COUNT];
  808. DEVCAPS DevCaps;
  809. ULONG iDisplaySettingsUniqueness;
  810. #ifdef LANGPACK
  811. DWORD dwLpkShapingDLLs;
  812. #endif
  813. CFONT acfPublic[MAX_PUBLIC_CFONT];
  814. LONG timeStamp;
  815. } GDI_SHARED_MEMORY, *PGDI_SHARED_MEMORY;
  816. /***********************************Structure******************************\
  817. *
  818. * GDI TEB Batching
  819. *
  820. * Contains the data structures and constants used for the batching of
  821. * GDI calls to avoid kernel mode transition costs.
  822. *
  823. * History:
  824. * 20-Oct-1995 -by- Mark Enstrom [marke]
  825. *
  826. \**************************************************************************/
  827. typedef enum _BATCH_TYPE
  828. {
  829. BatchTypePatBlt,
  830. BatchTypePolyPatBlt,
  831. BatchTypeTextOut,
  832. BatchTypeTextOutRect,
  833. BatchTypeSetBrushOrg,
  834. BatchTypeSelectClip,
  835. BatchTypeSelectFont,
  836. BatchTypeDeleteBrush,
  837. BatchTypeDeleteRegion
  838. } BATCH_TYPE,*PBATCH_TYPE;
  839. typedef struct _BATCHCOMMAND
  840. {
  841. USHORT Length;
  842. USHORT Type;
  843. }BATCHCOMMAND,*PBATCHCOMMAND;
  844. typedef struct _BATCHDELETEBRUSH
  845. {
  846. USHORT Length;
  847. USHORT Type;
  848. KHBRUSH hbrush;
  849. }BATCHDELETEBRUSH,*PBATCHDELETEBRUSH;
  850. typedef struct _BATCHDELETEREGION
  851. {
  852. USHORT Length;
  853. USHORT Type;
  854. KHRGN hregion;
  855. }BATCHDELETEREGION,*PBATCHDELETEREGION;
  856. typedef struct _BATCHSETBRUSHORG
  857. {
  858. USHORT Length;
  859. USHORT Type;
  860. int x;
  861. int y;
  862. }BATCHSETBRUSHORG,*PBATCHSETBRUSHORG;
  863. typedef struct _BATCHPATBLT
  864. {
  865. USHORT Length;
  866. USHORT Type;
  867. LONG x;
  868. LONG y;
  869. LONG cx;
  870. LONG cy;
  871. KHBRUSH hbr;
  872. ULONG rop4;
  873. ULONG TextColor;
  874. ULONG BackColor;
  875. COLORREF DCBrushColor;
  876. COLORREF IcmBrushColor;
  877. POINTL ptlViewportOrg;
  878. ULONG ulTextColor;
  879. ULONG ulBackColor;
  880. ULONG ulDCBrushColor;
  881. }BATCHPATBLT,*PBATCHPATBLT;
  882. typedef struct _BATCHPOLYPATBLT
  883. {
  884. USHORT Length;
  885. USHORT Type;
  886. ULONG rop4;
  887. ULONG Mode;
  888. ULONG Count;
  889. ULONG TextColor;
  890. ULONG BackColor;
  891. COLORREF DCBrushColor;
  892. ULONG ulTextColor;
  893. ULONG ulBackColor;
  894. ULONG ulDCBrushColor;
  895. POINTL ptlViewportOrg;
  896. //
  897. // Variable length buffer for POLYPATBLT struct. Must be naturally
  898. // aligned.
  899. //
  900. KERNEL_PVOID ulBuffer[1];
  901. }BATCHPOLYPATBLT,*PBATCHPOLYPATBLT;
  902. typedef struct _BATCHTEXTOUT
  903. {
  904. USHORT Length;
  905. USHORT Type;
  906. ULONG TextColor;
  907. ULONG BackColor;
  908. ULONG BackMode;
  909. ULONG ulTextColor;
  910. ULONG ulBackColor;
  911. LONG x;
  912. LONG y;
  913. ULONG fl;
  914. RECTL rcl;
  915. DWORD dwCodePage;
  916. ULONG cChar;
  917. ULONG PdxOffset;
  918. KHANDLE hlfntNew;
  919. UINT flTextAlign;
  920. POINTL ptlViewportOrg;
  921. //
  922. // variable length buffer for WCHAR and pdx data
  923. //
  924. ULONG ulBuffer[1];
  925. }BATCHTEXTOUT,*PBATCHTEXTOUT;
  926. typedef struct _BATCHTEXTOUTRECT
  927. {
  928. USHORT Length;
  929. USHORT Type;
  930. ULONG BackColor;
  931. ULONG fl;
  932. RECTL rcl;
  933. POINTL ptlViewportOrg;
  934. ULONG ulBackColor;
  935. }BATCHTEXTOUTRECT,*PBATCHTEXTOUTRECT;
  936. typedef struct _BATCHSELECTCLIP
  937. {
  938. USHORT Length;
  939. USHORT Type;
  940. int iMode;
  941. RECTL rclClip;
  942. }BATCHSELECTCLIP,*PBATCHSELECTCLIP;
  943. typedef struct _BATCHSELECTFONT
  944. {
  945. USHORT Length;
  946. USHORT Type;
  947. KHANDLE hFont;
  948. }BATCHSELECTFONT,*PBATCHSELECTFONT;
  949. //
  950. // GDI_BATCH_BUFFER_SIZE is space (IN BYTES) in TEB allocated
  951. // for GDI batching
  952. //
  953. #if defined(_GDIPLUS_)
  954. #define GDI_BATCH_SIZE 0
  955. #else
  956. #define GDI_BATCH_SIZE 4 * GDI_BATCH_BUFFER_SIZE
  957. #endif
  958. //
  959. // Image32 data
  960. //
  961. typedef enum _IMAGE_TYPE
  962. {
  963. Image_Alpha,
  964. Image_AlphaDIB,
  965. Image_Transparent,
  966. Image_TransparentDIB,
  967. Image_Stretch,
  968. Image_StretchDIB
  969. }IMAGE_TYPE,*PIMAGE_TYPE;
  970. #endif // GDIFLAGS_ONLY used for gdikdx
  971. // these strings are included in both gre\mapfile.c and client\output.c
  972. // so we put them here so that we can manage the changes from
  973. // the unified place.
  974. //
  975. // This rubbish comment is in win95 sources. I leave it here for reference
  976. // [bodind]
  977. //
  978. //
  979. // this static data goes away as soon as we get the correct functionality in
  980. // NLS. (its in build 162, use it in buid 163)
  981. //
  982. #define NCHARSETS 16
  983. #define CHARSET_ARRAYS \
  984. UINT nCharsets = NCHARSETS; \
  985. UINT charsets[] = { \
  986. ANSI_CHARSET, SHIFTJIS_CHARSET, HANGEUL_CHARSET, JOHAB_CHARSET, \
  987. GB2312_CHARSET, CHINESEBIG5_CHARSET, HEBREW_CHARSET, \
  988. ARABIC_CHARSET, GREEK_CHARSET, TURKISH_CHARSET, \
  989. BALTIC_CHARSET, EASTEUROPE_CHARSET, RUSSIAN_CHARSET, THAI_CHARSET, \
  990. VIETNAMESE_CHARSET, SYMBOL_CHARSET}; \
  991. UINT codepages[] ={ 1252, 932, 949, 1361, \
  992. 936, 950, 1255, 1256, \
  993. 1253, 1254, 1257, 1250, \
  994. 1251, 874 , 1258, 42}; \
  995. DWORD fs[] = { FS_LATIN1, FS_JISJAPAN, FS_WANSUNG, FS_JOHAB, \
  996. FS_CHINESESIMP, FS_CHINESETRAD, FS_HEBREW, FS_ARABIC, \
  997. FS_GREEK, FS_TURKISH, FS_BALTIC, FS_LATIN2, \
  998. FS_CYRILLIC, FS_THAI, FS_VIETNAMESE, FS_SYMBOL };