Source code of Windows XP (NT5)
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.

503 lines
12 KiB

  1. //
  2. // Cursor Manager
  3. //
  4. #ifndef _H_CM
  5. #define _H_CM
  6. //
  7. //
  8. // CONSTANTS
  9. //
  10. //
  11. //
  12. // Maximum cursor sizes.
  13. //
  14. #define CM_MAX_CURSOR_WIDTH 32
  15. #define CM_MAX_CURSOR_HEIGHT 32
  16. //
  17. // This is the maximum size of the cursor data for the combined 1bpp AND
  18. // mask and n bpp XOR mask. We currently allow for a 32x32 cursor at
  19. // 32bpp. In this case the AND mask consumes 32*32/8 bytes (128) and the
  20. // XOR mask consumes 32*32*4 bytes (4096). Total is 32*4 + 32*32*4, which
  21. // is (32*4)*(1 + 32), which is (32*4)*33
  22. //
  23. #define CM_MAX_CURSOR_DATA_SIZE \
  24. ((CM_MAX_CURSOR_WIDTH/8) * CM_MAX_CURSOR_HEIGHT * 33)
  25. //
  26. // Thresholds for color intensity to distinguish between 24bpp colors which
  27. // map to black, white, or a hatch pattern
  28. //
  29. #define CM_WHITE_THRESHOLD (TSHR_UINT32)120000
  30. #define CM_BLACK_THRESHOLD (TSHR_UINT32)40000
  31. //
  32. // Shadow cursor tag constant declarations.
  33. //
  34. #define NTRUNCLETTERS 5 // For CreateAbbreviatedName - "A. B."
  35. #define MAX_CURSOR_TAG_FONT_NAME_LENGTH 64
  36. #define CURSOR_TAG_FONT_HEIGHT -11
  37. //
  38. // This defines the size of the tag.. careful if you change these
  39. // values... they must define a tag that fits in a hardcoded 32x32 bitmap.
  40. //
  41. #define TAGXOFF 8
  42. #define TAGYOFF 20
  43. #define TAGXSIZ 24
  44. #define TAGYSIZ 12
  45. typedef struct tag_curtaginfo
  46. {
  47. WORD cHeight;
  48. WORD cWidth;
  49. BYTE aAndBits[ 32 * 32 / 8 ];
  50. BITMAPINFO bmInfo; // includes foreground color
  51. RGBQUAD rgbBackground[1]; // describes background color
  52. BYTE aXorBits[ 32 * 32 / 8 ]; // packed bits follow BITMAPINFO, color table
  53. }
  54. CURTAGINFO, * PCURTAGINFO;
  55. typedef struct tagCACHEDCURSOR
  56. {
  57. HCURSOR hCursor;
  58. POINT hotSpot;
  59. }
  60. CACHEDCURSOR;
  61. typedef CACHEDCURSOR * PCACHEDCURSOR;
  62. //
  63. // Information about a remote party's cursor.
  64. //
  65. //
  66. //
  67. //
  68. // Calculates the number of bytes wide a cursor is given the width of the
  69. // cursor in pels. Cursors are 1bpp and word padded.
  70. //
  71. #define CM_BYTES_FROM_WIDTH(width) ((((width)+15)/16)*2)
  72. //
  73. //
  74. // TYPES
  75. //
  76. //
  77. //
  78. // A POINTL has 32-bit coords in both 16-bit and 32-bit code
  79. //
  80. typedef struct tagCM_SHAPE_HEADER
  81. {
  82. POINTL ptHotSpot;
  83. WORD cx;
  84. WORD cy;
  85. WORD cbRowWidth;
  86. BYTE cPlanes;
  87. BYTE cBitsPerPel;
  88. } CM_SHAPE_HEADER;
  89. typedef CM_SHAPE_HEADER FAR * LPCM_SHAPE_HEADER;
  90. typedef struct tagCM_SHAPE
  91. {
  92. CM_SHAPE_HEADER hdr;
  93. BYTE Masks[1]; // 1bpp AND mask, followed by n bpp XOR mask
  94. } CM_SHAPE;
  95. typedef CM_SHAPE FAR * LPCM_SHAPE;
  96. typedef struct tagCM_SHAPE_DATA
  97. {
  98. CM_SHAPE_HEADER hdr;
  99. BYTE data[CM_MAX_CURSOR_DATA_SIZE];
  100. }
  101. CM_SHAPE_DATA;
  102. typedef CM_SHAPE_DATA FAR * LPCM_SHAPE_DATA;
  103. // Structure: CM_FAST_DATA
  104. //
  105. // Description: Shared memory data - cursor description and usage flag
  106. //
  107. // cmCursorStamp - Cursor identifier: an integer written by the
  108. // display driver
  109. // bitmasks - RGB bitmasks for >8bpp cursors
  110. // colorTable - Color table for <= 8bpp cursors
  111. // cmCursorShapeData - Cursor definition (AND, XOR masks, etc)
  112. //
  113. //
  114. //
  115. // Note that a PALETTEENTRY is a DWORD, same in 16-bit and 32-bit code
  116. //
  117. typedef struct tagCM_FAST_DATA
  118. {
  119. DWORD cmCursorStamp;
  120. DWORD bitmasks[3];
  121. PALETTEENTRY colorTable[256];
  122. CM_SHAPE_DATA cmCursorShapeData;
  123. }
  124. CM_FAST_DATA;
  125. typedef CM_FAST_DATA FAR * LPCM_FAST_DATA;
  126. //
  127. //
  128. // MACROS
  129. //
  130. //
  131. #define CURSOR_AND_MASK_SIZE(pCursorShape) \
  132. ((pCursorShape)->hdr.cbRowWidth * (pCursorShape)->hdr.cy)
  133. #define ROW_WORD_PAD(cbUnpaddedRow) \
  134. (((cbUnpaddedRow) + 1) & ~1)
  135. #define CURSOR_XOR_BITMAP_SIZE(pCursorShape) \
  136. (ROW_WORD_PAD(((pCursorShape)->hdr.cx * \
  137. (pCursorShape)->hdr.cBitsPerPel) / 8) * \
  138. (pCursorShape)->hdr.cy)
  139. #define CURSOR_DIB_BITS_SIZE(cx, cy, bpp) \
  140. (ROW_WORD_PAD(((cx) * (bpp))/8) * (cy))
  141. #define CURSORSHAPE_SIZE(pCursorShape) \
  142. sizeof(CM_SHAPE_HEADER) + \
  143. CURSOR_AND_MASK_SIZE(pCursorShape) + \
  144. CURSOR_XOR_BITMAP_SIZE(pCursorShape)
  145. //
  146. // Null cursor indications
  147. //
  148. #define CM_CURSOR_IS_NULL(pCursor) ((((pCursor)->hdr.cPlanes==(BYTE)0xFF) && \
  149. (pCursor)->hdr.cBitsPerPel == (BYTE)0xFF))
  150. #define CM_SET_NULL_CURSOR(pCursor) (pCursor)->hdr.cPlanes = 0xFF; \
  151. (pCursor)->hdr.cBitsPerPel = 0xFF;
  152. //
  153. // Expands a particular bit into a byte. The bits are zero-indexed and
  154. // numbered from the left. The allowable range for pos is 0 to 7
  155. // inclusive.
  156. //
  157. #define BIT_TO_BYTE(cbyte, pos) \
  158. ( (BYTE) ((((cbyte) >> (7 - (pos))) & 0x01) ? 0xFF : 0x00))
  159. //
  160. // Get two bits from a byte. The bits are zero-indexed and numbered from
  161. // the left. The allowable range for pos is 0 to 3 inclusive.
  162. //
  163. #define GET_TWO_BITS(cbyte, pos) \
  164. ( (BYTE) (((cbyte) >> (2 * (3 - (pos)))) & 0x03) )
  165. //
  166. // Return the maximum size of palette (in bytes) required for a DIB at a
  167. // given bpp. This is 2 ^ bpp for bpp < 8, or 0 for > 8 bpp
  168. //
  169. #define PALETTE_SIZE(BPP) (((BPP) > 8) ? 0 : ((1<<(BPP)) * sizeof(RGBQUAD)))
  170. //
  171. // Return a pointer to the actual bitmap bits within a DIB.
  172. //
  173. #define POINTER_TO_DIB_BITS(pDIB) \
  174. ((void *) ((LPBYTE)(pDIB) + DIB_BITS_OFFSET(pDIB)) )
  175. //
  176. // Calculate the offset of the data bits in a DIB.
  177. //
  178. #define DIB_BITS_OFFSET(pDIB) \
  179. (PALETTE_SIZE((pDIB)->bmiHeader.biBitCount) + \
  180. sizeof(BITMAPINFOHEADER))
  181. //
  182. // Trace out info about a DIB. PH is a pointer to a BITMAPINFOHEADER
  183. //
  184. #define CAP_TRACE_DIB_DBG(PH, NAME) \
  185. TRACE_OUT(( "%s: %#.8lx, %ld x %ld, %hd bpp, %s encoded", \
  186. (NAME), (DWORD)(PH), (PH)->biWidth, (PH)->biHeight, (PH)->biBitCount,\
  187. ((PH)->biCompression == BI_RLE8) ? "RLE8" \
  188. : (((PH)->biCompression == BI_RLE4) ? "RLE4" : "not")))
  189. //
  190. // Is the parameter a pointer to a Device Dependant Bitmap?
  191. //
  192. #define IS_DIB(PARAM) (*((LPWORD)(PARAM)) == 0x28)
  193. //
  194. // Driver supports color_cursors and async SetCursor. This value is taken
  195. // from the Win95 DDK.
  196. //
  197. #define C1_COLORCURSOR 0x0800
  198. //
  199. //
  200. // PROTOTYPES
  201. //
  202. //
  203. //
  204. // Specific values for OSI escape codes
  205. //
  206. #define CM_ESC(code) (OSI_CM_ESC_FIRST + code)
  207. #define CM_ESC_XFORM CM_ESC(0)
  208. //
  209. //
  210. // STRUCTURES
  211. //
  212. //
  213. // Structure: CM_DRV_XFORM_INFO
  214. //
  215. // Description: Structure passed from the share core to the display driver
  216. // to pass cursor transform data
  217. //
  218. typedef struct tagCM_DRV_XFORM_INFO
  219. {
  220. OSI_ESCAPE_HEADER header;
  221. //
  222. // Share core -> display driver.
  223. // Pointers to AND mask. Note that this user-space pointer is also
  224. // valid in the display driver realm (ring0 if NT, 16-bit if W95)
  225. //
  226. LPBYTE pANDMask;
  227. DWORD width;
  228. DWORD height;
  229. //
  230. // Driver -> share core.
  231. //
  232. DWORD result;
  233. } CM_DRV_XFORM_INFO;
  234. typedef CM_DRV_XFORM_INFO FAR * LPCM_DRV_XFORM_INFO;
  235. //
  236. //
  237. // PROTOTYPES
  238. //
  239. //
  240. #ifdef DLL_DISP
  241. //
  242. // Name: CM_DDProcessRequest
  243. //
  244. // Purpose: Process CM requests from the Share Core which have been
  245. // to the display driver through the DrvEscape mechanism.
  246. //
  247. // Returns: TRUE if the request is processed successfully,
  248. // FALSE otherwise.
  249. //
  250. // Params: IN pso - Pointer to surface object for our driver
  251. // IN cjIn - Size of the input data
  252. // IN pvIn - Pointer to the input data
  253. // IN cjOut - Size of the output data
  254. // IN/OUT pvOut - Pointer to the output data
  255. //
  256. #ifdef IS_16
  257. BOOL CM_DDProcessRequest(UINT fnEscape, LPOSI_ESCAPE_HEADER pResult,
  258. DWORD cbResult);
  259. #else
  260. ULONG CM_DDProcessRequest(SURFOBJ* pso,
  261. UINT cjIn,
  262. void * pvIn,
  263. UINT cjOut,
  264. void * pvOut);
  265. #endif
  266. #ifdef IS_16
  267. BOOL CM_DDInit(HDC);
  268. #else
  269. BOOL CM_DDInit(LPOSI_PDEV ppDev);
  270. #endif // IS_16
  271. #ifdef IS_16
  272. void CM_DDViewing(BOOL fViewers);
  273. #else
  274. void CM_DDViewing(SURFOBJ * pso, BOOL fViewers);
  275. #endif // IS_16
  276. //
  277. // Name: CM_DDTerm
  278. //
  279. // Purpose: Terminates the display driver component of the cursor
  280. // manager.
  281. //
  282. // Params: None.
  283. //
  284. void CM_DDTerm(void);
  285. #endif // DLL_DISP
  286. typedef void ( *PFNCMCOPYTOMONO) ( LPBYTE pSrc,
  287. LPBYTE pDst,
  288. UINT cx,
  289. UINT cy );
  290. //
  291. // Cursor type (as required by CMMaybeSendCursor). The values are:
  292. //
  293. // DEFAULTCURSOR - standard pointer
  294. // DISPLAYEDCURSOR - displayed (eg. bitmap) cursor
  295. //
  296. #define CM_CT_DEFAULTCURSOR 1
  297. #define CM_CT_DISPLAYEDCURSOR 2
  298. //
  299. // Types of displayed cursor:
  300. //
  301. // UNKNOWN - ONLY to be used by resyncing code
  302. // SYSTEMCURSOR - Standard windows cursor
  303. // BITMAPCURSOR - Displayed cursor
  304. //
  305. #define CM_CD_UNKNOWN 0
  306. #define CM_CD_SYSTEMCURSOR 1
  307. #define CM_CD_BITMAPCURSOR 2
  308. typedef struct tagCURSORDESCRIPTION
  309. {
  310. DWORD type;
  311. DWORD id;
  312. } CURSORDESCRIPTION;
  313. typedef CURSORDESCRIPTION FAR * LPCURSORDESCRIPTION;
  314. typedef struct tagCURSORIMAGE
  315. {
  316. WORD xHotSpot;
  317. WORD yHotSpot;
  318. BITMAPINFOHEADER crHeader;
  319. BYTE crMasks[1];
  320. } CURSORIMAGE;
  321. typedef CURSORIMAGE FAR *LPCURSORIMAGE;
  322. #ifndef DLL_DISP
  323. BOOL CMCreateAbbreviatedName(LPCSTR szTagName, LPSTR szBuf, UINT cbBuf);
  324. //
  325. // BOGUS LAURABU:
  326. // We should use normal GDI StretchBlts to get the bitmap bits, not
  327. // our own whacky pack/unpack code.
  328. //
  329. void CMCopy1bppTo1bpp( LPBYTE pSrc,
  330. LPBYTE pDst,
  331. UINT cx,
  332. UINT cy );
  333. void CMCopy4bppTo1bpp( LPBYTE pSrc,
  334. LPBYTE pDst,
  335. UINT cx,
  336. UINT cy );
  337. void CMCopy8bppTo1bpp( LPBYTE pSrc,
  338. LPBYTE pDst,
  339. UINT cx,
  340. UINT cy );
  341. void CMCopy16bppTo1bpp( LPBYTE pSrc,
  342. LPBYTE pDst,
  343. UINT cx,
  344. UINT cy );
  345. void CMCopy24bppTo1bpp( LPBYTE pSrc,
  346. LPBYTE pDst,
  347. UINT cx,
  348. UINT cy );
  349. BOOL CMGetMonoCursor( LPTSHR_UINT16 pcxWidth,
  350. LPTSHR_UINT16 pcyHeight,
  351. LPTSHR_UINT16 pxHotSpot,
  352. LPTSHR_UINT16 pyHotSpot,
  353. LPBYTE pANDBitmap,
  354. LPBYTE pXORBitmap );
  355. void CMGetCurrentCursor(LPCURSORDESCRIPTION pCursor);
  356. void CMCalculateColorCursorSize( LPCM_SHAPE pCursor,
  357. LPUINT pcbANDMaskSize,
  358. LPUINT pcbXORBitmapSize );
  359. BOOL CMGetMonoCursorDetails( LPCM_SHAPE pCursor,
  360. LPTSHR_UINT16 pcxWidth,
  361. LPTSHR_UINT16 pcyHeight,
  362. LPTSHR_UINT16 pxHotSpot,
  363. LPTSHR_UINT16 pyHotSpot,
  364. LPBYTE pANDBitmap,
  365. LPTSHR_UINT16 pcbANDBitmap,
  366. LPBYTE pXORBitmap,
  367. LPTSHR_UINT16 pcbXORBitmap );
  368. void CMRefreshWindowCursor(HWND window);
  369. BOOL CMGetCursorShape( LPCM_SHAPE * ppCursorShape,
  370. LPUINT pcbCursorDataSize );
  371. HWND CMGetControllingWindow(void);
  372. #define CM_SHM_START_READING &g_asSharedMemory->cmFast[\
  373. 1 - g_asSharedMemory->fastPath.newBuffer]
  374. #define CM_SHM_STOP_READING
  375. #else
  376. #ifdef IS_16
  377. BOOL CMDDSetTransform(LPCM_DRV_XFORM_INFO pResult);
  378. void CMDDJiggleCursor(void);
  379. #else
  380. BOOL CMDDSetTransform(LPOSI_PDEV ppDev, LPCM_DRV_XFORM_INFO pXformInfo);
  381. #endif
  382. #define CM_SHM_START_WRITING SHM_StartAccess(SHM_CM_FAST)
  383. #define CM_SHM_STOP_WRITING SHM_StopAccess(SHM_CM_FAST)
  384. #endif // !DLL_DISP
  385. #endif // _H_CM