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.

659 lines
20 KiB

  1. //
  2. // Sent Bitmap Cache
  3. //
  4. #ifndef _H_SBC
  5. #define _H_SBC
  6. #include <oa.h>
  7. #include <shm.h>
  8. #include <osi.h>
  9. #include <ch.h>
  10. #include <bmc.h>
  11. //
  12. //
  13. // Constants
  14. //
  15. //
  16. #define SBC_NUM_THRASHERS 8 // The number of bitmaps we monitor for
  17. // "thrashiness" at any given time.
  18. #define SBC_THRASH_INTERVAL 50 // The interval (in centi-seconds) at
  19. // which bitmaps have to change in
  20. // order to be classified as thrashers
  21. //
  22. // Eviction categories
  23. //
  24. #define SBC_NUM_CATEGORIES 3
  25. //
  26. // Specific values for OSI escape codes
  27. //
  28. #define SBC_ESC(code) (OSI_SBC_ESC_FIRST + code)
  29. #define SBC_ESC_NEW_CAPABILITIES SBC_ESC(0)
  30. //
  31. // Value indicating that a bitmap should not be fast pathed
  32. //
  33. #define SBC_DONT_FASTPATH 0xffffffff
  34. //
  35. // Index into sbcTileWorkInfo at which the data for various tile sizes is
  36. // stored.
  37. //
  38. #define SBC_MEDIUM_TILE_INDEX SHM_MEDIUM_TILE_INDEX
  39. #define SBC_LARGE_TILE_INDEX SHM_LARGE_TILE_INDEX
  40. #define SBC_NUM_TILE_SIZES SHM_NUM_TILE_SIZES
  41. //
  42. //
  43. // Macros
  44. //
  45. //
  46. //
  47. // Calculate the number of bytes required for a tile entry of the given
  48. // dimensions.
  49. //
  50. #define SBC_BYTES_PER_TILE(WIDTH, HEIGHT, BPP) \
  51. (BYTES_IN_BITMAP((WIDTH), (HEIGHT), (BPP)) \
  52. + sizeof(SBC_TILE_DATA)) \
  53. //
  54. // SBC_TILE_TYPE
  55. //
  56. // Given an SBC tile Id, return the tile type.
  57. //
  58. // Returns one of:
  59. // SBC_SMALL_TILE
  60. // SBC_LARGE_TILE
  61. //
  62. // The top bit of the Id is clear for small tiles, and set for large tiles.
  63. //
  64. #define SBC_TILE_TYPE(TILEID) \
  65. (((TILEID) & 0x8000) ? SBC_LARGE_TILE_INDEX : SBC_MEDIUM_TILE_INDEX)
  66. //
  67. //
  68. // Structures
  69. //
  70. //
  71. //
  72. // Structure: SBC_SHM_CACHE_INFO
  73. //
  74. // Description: Structure which is used to pass information about a bitmap
  75. // cache from the share core to the display driver.
  76. //
  77. //
  78. typedef struct tagSBC_SHM_CACHE_INFO
  79. {
  80. WORD cEntries; // The number of entries in this cache.
  81. WORD cCellSize; // The maximum bytes available for each cache entry.
  82. }
  83. SBC_SHM_CACHE_INFO;
  84. typedef SBC_SHM_CACHE_INFO FAR * LPSBC_SHM_CACHE_INFO;
  85. //
  86. // Structure: SBC_TILE_DATA
  87. //
  88. // Description: Structure used to pass the DIB bits for tile in a MEMBLT
  89. // order from the driver to the share core. There is an array of these
  90. // structures in each SBC shunt buffer.
  91. //
  92. // Notes: The inUse field should only be set to TRUE by the driver when it
  93. // has finished filling in the entry, and to FALSE by the share core when
  94. // it has finished processing the data held in the entry. When inUse is
  95. // FALSE, the remaining data is not valid, and should not be accessed by
  96. // the share core.
  97. //
  98. // The width and height fields give the dimensions of the data which is
  99. // held in the bitData field. If the tile is set up to hold a maximum
  100. // of 32x32, the scanlines in bitData will always be 32 even if width is
  101. // set to less than 32 - there will just be unused data at the end of each
  102. // scanline.
  103. //
  104. //
  105. typedef struct tagSBC_TILE_DATA
  106. {
  107. WORD inUse; // Is this entry in use?
  108. WORD tileId; // An identifier for this entry. This
  109. // matches an ID stored in the
  110. // cacheId field of a MEMBLT order
  111. // passed from the driver to the
  112. // share core in the order buffer.
  113. DWORD bytesUsed; // The number of bytes of data in
  114. // bitData which is actually used for
  115. // this entry.
  116. WORD srcX; // The source coordinates of the Mem(3)Blt
  117. WORD srcY;
  118. WORD width; // The dimensions of the data in bitData
  119. WORD height;
  120. WORD tilingWidth; // The dimensions at which tiling was
  121. WORD tilingHeight; // carried out. This is not
  122. // necessarily the same as the
  123. // dimensions of the tiles in this
  124. // shunt buffer.
  125. DWORD_PTR majorCacheInfo; // Information which the share core can
  126. DWORD minorCacheInfo; // use to optimize cache handling.
  127. // A value of SBC_DONT_FASTPATH for
  128. // majorCacheInfo indicates that the
  129. // optimization should not be used.
  130. //
  131. DWORD_PTR majorPalette; // Palette information for the fast
  132. DWORD minorPalette; // pathing. These two fields
  133. // uniquely identify the colour
  134. // conversion object associated with
  135. // the bitmap.
  136. BYTE bitData[4]; // Start of the bit data. The total
  137. // number of bits is given by the
  138. // numBits field of the
  139. // SBC_SHUNT_BUFFER structure at the
  140. // head of the shunt buffer which
  141. // this entry is placed in.
  142. } SBC_TILE_DATA;
  143. typedef SBC_TILE_DATA FAR * LPSBC_TILE_DATA;
  144. //
  145. // Structure: SBC_SHUNT_BUFFER
  146. //
  147. // Description: Structure placed at the head of a shunt buffer used to pass
  148. // bit data from the driver to the share core. It is followed by an array
  149. // of SBC_TILE_DATA structures.
  150. //
  151. // Note: The SBC_TILE_DATA structures are all the same size, but the size
  152. // is not fixed at compile time (there are a variable number of bits), so
  153. // do not use array notation to reference them.
  154. //
  155. //
  156. typedef struct tagSBC_SHUNT_BUFFER
  157. {
  158. DWORD numBytes; // The number of bytes in the bitData
  159. // fields of the SBC_TILE_DATA stryct
  160. DWORD structureSize; // The total size of each SBC_TILE_DATA
  161. // structure
  162. DWORD numEntries; // The number of SBC_TILE_DATA
  163. // structures in the shunt buffer
  164. SBC_TILE_DATA firstEntry; // The first SBC_TILE_DATA entry
  165. } SBC_SHUNT_BUFFER;
  166. typedef SBC_SHUNT_BUFFER FAR * LPSBC_SHUNT_BUFFER;
  167. //
  168. // Structure: SBC_NEW_CAPABILITIES
  169. //
  170. // Description:
  171. //
  172. // Structure to pass new capabilities down to the display driver from the
  173. // Share Core.
  174. //
  175. //
  176. typedef struct tagSBC_NEW_CAPABILITIES
  177. {
  178. OSI_ESCAPE_HEADER header; // Common header
  179. DWORD sendingBpp; // Bpp at which bitmaps are sent
  180. LPSBC_SHM_CACHE_INFO cacheInfo; // Caching details
  181. } SBC_NEW_CAPABILITIES;
  182. typedef SBC_NEW_CAPABILITIES FAR * LPSBC_NEW_CAPABILITIES;
  183. //
  184. // Structure: SBC_ORDER_INFO
  185. //
  186. // Description: This structure holds all the information SBC needs about
  187. // the two internal orders which it stores to hold data color table and bit
  188. // data for a MEMBLT order.
  189. //
  190. // pColorTableOrder is allocated with enough color table entries for
  191. // usrSendingbpp bitmaps.
  192. //
  193. // pBitmapBitsOrder is allocated with enough room for the maximum tile size
  194. // which we will send out at usrSendingbpp.
  195. //
  196. // If sentColorTable is TRUE, the data in pColorTableOrder may not be
  197. // valid.
  198. //
  199. // If sentBitmapBits is TRUE, the data in pBitmapBitsOrder may not be
  200. // valid.
  201. //
  202. //
  203. typedef struct tagSBC_ORDER_INFO
  204. {
  205. LPINT_ORDER pColorTableOrder; // Pointer to a color table order.
  206. LPINT_ORDER pBitmapBitsOrder; // Pointer to a bitmap bits order.
  207. DWORD bitmapBitsDataSize; // The number of bytes allocated
  208. // for the data field of the
  209. // bitmap bits order.
  210. LPINT_ORDER pOrder; // Pointer to the MEMBLT order for
  211. // which we currently hold data.
  212. // DO NOT DEREFERENCE THIS - IT
  213. // IS FOR NUMERICAL COMPARISON
  214. // ONLY
  215. DWORD validData; // Do we have valid data for
  216. // pOrder ?
  217. DWORD sentColorTable; // Has the color table been sent
  218. // over the wire ?
  219. DWORD sentBitmapBits; // Have the bitmap bits been sent
  220. // over the wire ?
  221. DWORD sentMemBlt; // Has the MEMBLT order itself been
  222. // sent over the wire ?
  223. }
  224. SBC_ORDER_INFO, FAR * LPSBC_ORDER_INFO;
  225. //
  226. // Structure: SBC_TILE_WORK_INFO
  227. //
  228. // Description: This structure contains all the elements required for
  229. // manipulating tiles of a given size. There should be an array of these
  230. // structures - one per tile size.
  231. //
  232. //
  233. typedef struct tagSBC_TILE_WORK_INFO
  234. {
  235. LPSBC_SHUNT_BUFFER pShuntBuffer; // Pointer to the shunt buffer to
  236. // containing tiles of this tile
  237. // size.
  238. UINT mruIndex; // The last entry accessed in
  239. // the shunt buffer pointed to by
  240. // pShuntBuffer.
  241. HBITMAP workBitmap; // The bitmap to use for processing
  242. // this tile size. This is
  243. // tileWidth x tileHeight at
  244. // native bpp.
  245. #ifndef DLL_DISP
  246. LPBYTE pWorkBitmapBits;// Pointer to the start of the bits
  247. #endif // DLL_DISP
  248. // in the bitmap.
  249. UINT tileWidth; // The width of workBitmap.
  250. UINT tileHeight; // The height of workBitmap.
  251. } SBC_TILE_WORK_INFO, FAR * LPSBC_TILE_WORK_INFO;
  252. //
  253. // Structure: SBC_FASTPATH_ENTRY
  254. //
  255. // Description: Structure holding one entry in the SBC fast path.
  256. //
  257. //
  258. typedef struct tagSBC_FASTPATH_ENTRY
  259. {
  260. BASEDLIST list; // Offsets to the next / prev entries in
  261. // the fast path
  262. DWORD_PTR majorInfo; // Major cache info field passed up in the
  263. // shunt buffer for this cache entry
  264. DWORD minorInfo; // Minor cache info field passed up in the
  265. // shunt buffer for this cache entry
  266. DWORD_PTR majorPalette; // Major palette info from the shunt buffer
  267. // This is the pointer to the XLATEOBJ
  268. DWORD minorPalette; // Minor palette info from the shunt buffer
  269. // This is the iUniq of the XLATEOBJ
  270. LONG srcX; // The coordinate in the source bitmap of
  271. LONG srcY; // the source of the MemBlt
  272. DWORD width; // The width / height of the entry in the
  273. DWORD height; // cache.
  274. WORD cache; // The cache and index at which the bitmap
  275. WORD cacheIndex; // stored.
  276. WORD colorIndex;
  277. WORD pad;
  278. } SBC_FASTPATH_ENTRY, FAR * LPSBC_FASTPATH_ENTRY;
  279. //
  280. // Structure: SBC_FASTPATH
  281. //
  282. // Description: Structure holding the SBC fast pathing information.
  283. //
  284. //
  285. #define SBC_FASTPATH_ENTRIES 100
  286. typedef struct tagSBC_FASTPATH
  287. {
  288. STRUCTURE_STAMP
  289. BASEDLIST usedList; // Offsets to the first / last used
  290. // entries in the fast path.
  291. BASEDLIST freeList; // Offsets to the first / last free
  292. // entries in the fast path.
  293. SBC_FASTPATH_ENTRY entry[SBC_FASTPATH_ENTRIES];
  294. }
  295. SBC_FASTPATH;
  296. typedef SBC_FASTPATH FAR * LPSBC_FASTPATH;
  297. #ifdef DLL_DISP
  298. // Structure: SBC_THRASHERS
  299. //
  300. // Description: Structure which is used to hold information about when a
  301. // source surface (bitmap) last changed, in order to determine whether the
  302. // surface will cause thrashing in the bitmap cache.
  303. //
  304. typedef struct tagSBC_THRASHERS
  305. {
  306. #ifdef IS_16
  307. HBITMAP hsurf;
  308. #else
  309. HSURF hsurf; // The hsurf of the surface object being
  310. // monitored.
  311. DWORD iUniq; // The last noted iUniq field from the
  312. // surface object being monitored.
  313. #endif // IS_16
  314. DWORD tickCount; // The system tick count (in centi-seconds)
  315. // at which we last saw this surface
  316. // change
  317. } SBC_THRASHERS;
  318. typedef SBC_THRASHERS FAR * LPSBC_THRASHERS;
  319. //
  320. //
  321. // Function prototypes
  322. //
  323. //
  324. void SBCDDSetNewCapabilities(LPSBC_NEW_CAPABILITIES pRequest);
  325. BOOL SBCDDGetNextFreeTile(int tileSize, LPSBC_TILE_DATA FAR * ppTileData);
  326. DWORD SBCDDGetTickCount(void);
  327. #ifdef IS_16
  328. BOOL SBCDDCreateShuntBuffers(void);
  329. #else
  330. BOOL SBCDDCreateShuntBuffers(LPOSI_PDEV ppDev, LPBYTE psbcMem, DWORD sbcMem);
  331. #endif
  332. #ifndef IS_16
  333. BOOL SBCDDIsBitmapThrasher(SURFOBJ * pSurfObj);
  334. #endif // !IS_16
  335. #endif // DLL_DISP
  336. //
  337. // SBC_TILE_PTR_FROM_INDEX
  338. //
  339. // Given a pointer to a shunt buffer and a tile index, return a pointer to
  340. // the tile at the given index.
  341. //
  342. // Get a pointer to the first entry in the shunt buffer, and add INDEX
  343. // times the size of each entry.
  344. //
  345. __inline LPSBC_TILE_DATA SBCTilePtrFromIndex(LPSBC_SHUNT_BUFFER pBuffer, UINT index)
  346. {
  347. LPSBC_TILE_DATA lpsbc;
  348. lpsbc = (LPSBC_TILE_DATA)((LPBYTE)&pBuffer->firstEntry +
  349. index * pBuffer->structureSize);
  350. return(lpsbc);
  351. }
  352. #ifdef DLL_DISP
  353. //
  354. //
  355. // Typedefs
  356. //
  357. //
  358. #ifdef IS_16
  359. typedef struct tagMEMBLT_ORDER_EXTRA_INFO
  360. {
  361. HDC hdcSrc;
  362. UINT fuColorUse;
  363. LPVOID lpBits;
  364. LPBITMAPINFO lpbmi;
  365. HPALETTE hpalDst;
  366. UINT uPad;
  367. } MEMBLT_ORDER_EXTRA_INFO, FAR* LPMEMBLT_ORDER_EXTRA_INFO;
  368. #else
  369. //
  370. // Structure: MEMBLT_ORDER_EXTRA_INFO
  371. //
  372. // Description: Extra information required by SBC to process a MEMBLT
  373. // order.
  374. //
  375. //
  376. typedef struct tagMEMBLT_ORDER_EXTRA_INFO
  377. {
  378. SURFOBJ* pSource; // Pointer to the source surface of the
  379. // MemBlt
  380. SURFOBJ* pDest; // Pointer to the destination surface of
  381. // the MemBlt
  382. XLATEOBJ* pXlateObj; // Pointer to the XlateObj used in the
  383. // MemBlt
  384. } MEMBLT_ORDER_EXTRA_INFO, FAR * LPMEMBLT_ORDER_EXTRA_INFO;
  385. #endif // !IS_16
  386. //
  387. // Name: SBC_DDProcessRequest
  388. //
  389. // Purpose: Process a request from the share core
  390. //
  391. // Returns: TRUE if the request is processed successfully,
  392. // FALSE otherwise.
  393. //
  394. // Params: IN pso - Pointer to surface object for our driver
  395. // IN cjIn - Size of the input data
  396. // IN pvIn - Pointer to the input data
  397. // IN cjOut - Size of the output data
  398. // IN/OUT pvOut - Pointer to the output data
  399. //
  400. #ifdef IS_16
  401. BOOL SBC_DDProcessRequest(UINT fnEscape, LPOSI_ESCAPE_HEADER pResult, DWORD cbResult);
  402. void SBC_DDTossFromCache(HBITMAP);
  403. #else
  404. BOOL SBC_DDProcessRequest(SURFOBJ* pso, DWORD fnEscape,
  405. LPOSI_ESCAPE_HEADER pRequest, LPOSI_ESCAPE_HEADER pResult, DWORD cbResult);
  406. #endif
  407. //
  408. // Name: SBC_DDInit
  409. //
  410. // Purpose: Initialize the device driver SBC specific "stuff".
  411. //
  412. #ifdef IS_16
  413. BOOL SBC_DDInit(HDC hdc, LPDWORD ppShuntBuffers, LPDWORD pBitmasks);
  414. #else
  415. BOOL SBC_DDInit(LPOSI_PDEV ppDev, LPBYTE pRestOfMemory, DWORD cbRestOfMemory,
  416. LPOSI_INIT_REQUEST pResult);
  417. #endif
  418. //
  419. // Name: SBC_DDTerm
  420. //
  421. // Purpose: Terminate the device driver SBC specific "stuff"
  422. //
  423. // Returns: Nothing
  424. //
  425. // Params: None
  426. //
  427. void SBC_DDTerm(void);
  428. //
  429. // Name: SBC_DDIsMemScreenBltCachable
  430. //
  431. // Purpose: Check to see whether a MemBlt is cachable.
  432. //
  433. // Returns: TRUE if the MemBlt is cachable, FALSE otherwise.
  434. //
  435. // Params: IN pMemBltInfo - Info about the MEMBLT to be cached.
  436. //
  437. // Operation: Note that if this function returns TRUE, it DOES NOT
  438. // guarantee that SBC_DDCacheMemScreenBlt will succeed.
  439. // However, a FALSE return code does guarantee that
  440. // SBC_DDCacheMemScreenBlt would fail.
  441. //
  442. BOOL SBC_DDIsMemScreenBltCachable(LPMEMBLT_ORDER_EXTRA_INFO pMemBltInfo);
  443. //
  444. // Name: SBC_DDCacheMemScreenBlt
  445. //
  446. // Purpose: Try to cache a memory to screen blt operation
  447. //
  448. // Returns: TRUE if the memory to screen blt was handled as an order
  449. // (i.e. the src bitmap could be cached)
  450. //
  451. // FALSE if the memory to screen blt could not be handled as an
  452. // order. In this case the caller should add the destination
  453. // rectangle of the blt into the Screen Data Area.
  454. //
  455. // Params: IN pOrder - Pointer to either a MEMBLT order or a
  456. // MEM3BLT order. This order must be
  457. // initialized before calling this function.
  458. // IN pMemBltInfo - Extra info about the MEMBLT to be cached.
  459. //
  460. // Operation: Before calling this function, the caller should call
  461. // SBC_DDMaybeQueueColorTable() to queue a color table for the
  462. // MemBlt (if required).
  463. //
  464. BOOL SBC_DDCacheMemScreenBlt(LPINT_ORDER pOrder, LPMEMBLT_ORDER_EXTRA_INFO pMemBltInfo);
  465. //
  466. // THIS CAN GO WHEN 2.x COMPAT DOES -- the SEND TILE SIZES WON'T BE
  467. // NEGOTIATED.
  468. //
  469. BOOL SBC_DDQueryBitmapTileSize(UINT bmpWidth, UINT bmpHeight,
  470. UINT * pTileWidth, UINT * pTileHeight);
  471. //
  472. // Name: SBC_DDSyncUpdatesNow
  473. //
  474. // Purpose: Discard any pending orders.
  475. //
  476. // Returns: Nothing
  477. //
  478. // Params: IN ppDev - Pointer to our device PDEV
  479. //
  480. // Operation: This function will mark all entries in the shunt buffers as
  481. // being free. It is vital that this operation is synched with
  482. // the share core operation of removing all orders from the
  483. // order buffer to ensure that there are no MemBlt orders left
  484. // which refer to freed shunt buffer entries.
  485. //
  486. #ifdef IS_16
  487. void SBC_DDSyncUpdatesNow(void);
  488. #else
  489. void SBC_DDSyncUpdatesNow(LPOSI_PDEV ppDev);
  490. #endif // IS_16
  491. //
  492. // Name: SBC_DDOrderSpoiltNotification
  493. //
  494. // Purpose: Called to notify SBC that a Mem(3)Blt order has been spoilt
  495. // before being passed to the share core. This function marks
  496. // the corresponding shunt buffer entry as being free.
  497. //
  498. // Returns: Nothing
  499. //
  500. // Params: IN pOrder - Pointer to the Mem(3)Blt order being spoilt.
  501. //
  502. void SBC_DDOrderSpoiltNotification(LPINT_ORDER pOrder);
  503. //
  504. // Name: SBC_DDMaybeQueueColorTable
  505. //
  506. // Purpose: If our device palette has changed since the last time we
  507. // queued a color table order to the share core, queue a new
  508. // color table order with details of the new palette.
  509. //
  510. // Returns: TRUE if the color table was queued, or no color table was
  511. // required.
  512. //
  513. // FALSE if a color table is required, but could not be queued.
  514. //
  515. // Params: IN ppDev - a pointer to our device PDEV
  516. //
  517. // Operation: This function should be called before SBC_DDCacheMemScreenBlt
  518. // to queue the color table used for the Mem(3)Blt. If this
  519. // function fails (returns FALSE), the caller should not call
  520. // SBC_DDCacheMemScreenBlt, but add the area covered by the
  521. // Mem(3)Blt to the screen data area instead.
  522. //
  523. // This function is required to work round a limitation in the
  524. // order heap which means that we cannot have more than one
  525. // OA_AllocOrderMem outstanding waiting for an OA_AddOrder.
  526. //
  527. // i.e. We cannot queue the color table order from
  528. // SBC_DDCacheMemScreenBlt because this gives the following
  529. // sequence of calls.
  530. //
  531. // OA_AllocOrderMem for Mem(3)Blt
  532. // OA_AllocOrderMem for color table
  533. // OA_AddOrder for color table
  534. // OA_AddOrder for Mem(3)Blt
  535. //
  536. #ifdef IS_16
  537. BOOL SBC_DDMaybeQueueColorTable(void);
  538. #else
  539. BOOL SBC_DDMaybeQueueColorTable(LPOSI_PDEV ppDev);
  540. #endif
  541. #endif // DLL_DISP
  542. #endif // _H_SBC