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.

467 lines
12 KiB

  1. //
  2. // Order Accumulator
  3. //
  4. #ifndef _H_OA
  5. #define _H_OA
  6. #include <osi.h>
  7. //
  8. // Specific values for OSI escape codes
  9. //
  10. #define OA_ESC(code) (OSI_OA_ESC_FIRST + code)
  11. #define OA_ESC_FLOW_CONTROL OA_ESC(0)
  12. //
  13. // Flow control constants for sizes/depths when slow, fast, etc. The
  14. // SLOW/FAST heap sizes are simply for spoiling. OA_HEAP_MAX is really
  15. // the size of the heap.
  16. //
  17. #define OA_FAST_HEAP 50000
  18. #define OA_SLOW_HEAP 20000
  19. //
  20. // NOTE: This is 64K - sizeof OA_SHARED_DATA header
  21. // If you add fields to header, subtract from this value
  22. //
  23. #define OA_HEAP_MAX 65512
  24. //
  25. // Flow control constants for depth of order spoiling
  26. //
  27. #define OA_FAST_SCAN_DEPTH 50
  28. #define OA_SLOW_SCAN_DEPTH 500
  29. //
  30. // Threshold for switching from FAST to SLOW order accum
  31. //
  32. #define OA_FAST_THRESHOLD 20000
  33. //
  34. // Value to indicate that you have reached the end of the order list
  35. //
  36. #define OA_NO_LIST -1
  37. #ifdef DLL_DISP
  38. #define OA_SHM_START_WRITING SHM_StartAccess(SHM_OA_DATA)
  39. #define OA_SHM_STOP_WRITING SHM_StopAccess(SHM_OA_DATA)
  40. #define OA_FST_START_WRITING SHM_StartAccess(SHM_OA_FAST)
  41. #define OA_FST_STOP_WRITING SHM_StopAccess(SHM_OA_FAST)
  42. #else
  43. #define OA_SHM_START_READING g_poaData[\
  44. 1 - g_asSharedMemory->displayToCore.newBuffer]
  45. #define OA_SHM_STOP_READING
  46. #define OA_SHM_START_WRITING g_poaData[\
  47. 1 - g_asSharedMemory->displayToCore.newBuffer]
  48. #define OA_SHM_STOP_WRITING
  49. #define OA_FST_START_READING &g_asSharedMemory->oaFast[\
  50. 1 - g_asSharedMemory->fastPath.newBuffer]
  51. #define OA_FST_STOP_READING
  52. #define OA_FST_START_WRITING &g_asSharedMemory->oaFast[\
  53. 1 - g_asSharedMemory->fastPath.newBuffer]
  54. #define OA_FST_STOP_WRITING
  55. #endif
  56. //
  57. // Maximum memory allowed for variable order data.
  58. //
  59. #define MAX_ADDITIONAL_DATA_BYTES 400000
  60. //
  61. // Invalid value to assign to deallocated order header pointers.
  62. //
  63. #define OA_DEAD_ORDER ((void FAR *)0xffffffff)
  64. //
  65. // Define the space to be reserved at the beginning of the segment
  66. // for heap management.
  67. //
  68. #define RESERVED_HEAP_BYTES 16
  69. //
  70. // Define clip function return codes.
  71. //
  72. #define CR_NO_OVERLAP 1
  73. #define CR_COMPLETE_OVERLAP 2
  74. #define CR_SIMPLE_CLIP 3
  75. #define CR_COMPLEX_OVERLAP 4
  76. #define CR_COMPLEX_CLIP 5
  77. //
  78. // Macros that return the width and height of an order.
  79. //
  80. #define ORDER_WIDTH(pOrder) \
  81. ( pOrder->OrderHeader.Common.rcsDst.right - \
  82. pOrder->OrderHeader.Common.rcsDst.left + 1 )
  83. #define ORDER_HEIGHT(pOrder) \
  84. ( pOrder->OrderHeader.Common.rcsDst.bottom - \
  85. pOrder->OrderHeader.Common.rcsDst.top + 1 )
  86. //
  87. // Define the minimum width and height of an order for us to try to spoil
  88. // previous orders with it. This helps performance, because it saves us
  89. // trying to spoil earlier orders with very small orders. However, if the
  90. // order exceeds the FULL_SPOIL values then we spoil as originally, with
  91. // the proviso that flow control may still prevent it.
  92. //
  93. #define FULL_SPOIL_WIDTH 16
  94. #define FULL_SPOIL_HEIGHT 16
  95. //
  96. // Define a macro that calculates whether a rectangle lies completely
  97. // within another rectangle.
  98. //
  99. #define RECT1_WITHIN_RECT2(rect1, rect2) \
  100. ( (rect1.left >= rect2.left ) && \
  101. (rect1.top >= rect2.top ) && \
  102. (rect1.right <= rect2.right ) && \
  103. (rect1.bottom <= rect2.bottom) )
  104. //
  105. // Structure: OA_NEW_PARAMS
  106. //
  107. // Description:
  108. //
  109. // Structure to pass new OA parameters down to the display driver from the
  110. // Share Core.
  111. //
  112. //
  113. enum
  114. {
  115. OAFLOW_FAST = 0,
  116. OAFLOW_SLOW
  117. };
  118. typedef struct tagOA_FLOW_CONTROL
  119. {
  120. OSI_ESCAPE_HEADER header; // Common header
  121. DWORD oaFlow; // Type -- fast, slow, etc.
  122. }
  123. OA_FLOW_CONTROL;
  124. typedef OA_FLOW_CONTROL FAR * LPOA_FLOW_CONTROL;
  125. //
  126. // Structure used to store orders in the shared memory
  127. //
  128. // totalHeapOrderBytes - Total bytes used in the order heap
  129. //
  130. // totalOrderBytes - Total bytes used by order data
  131. //
  132. // totalAdditionalOrderBytes - Total bytes used as additional order data
  133. //
  134. // nextOrder - Offset for start of next new order
  135. //
  136. // orderListHead - Order list head (uses standard BASEDLIST
  137. // manipulation code)
  138. //
  139. // orderHeap - Order heap
  140. //
  141. typedef struct tagOA_SHARED_DATA
  142. {
  143. DWORD totalHeapOrderBytes;
  144. DWORD totalOrderBytes;
  145. DWORD totalAdditionalOrderBytes;
  146. LONG nextOrder;
  147. BASEDLIST orderListHead;
  148. BYTE orderHeap[OA_HEAP_MAX];
  149. }
  150. OA_SHARED_DATA;
  151. typedef OA_SHARED_DATA FAR * LPOA_SHARED_DATA;
  152. //
  153. // Structure used to store orders in the shared memory
  154. //
  155. // ordersAccumulated - number of orders accumulated in the heap
  156. // since the last double buffer swap.
  157. //
  158. //
  159. typedef struct tagOA_FAST_DATA
  160. {
  161. DWORD ordersAccumulated;
  162. } OA_FAST_DATA;
  163. typedef OA_FAST_DATA FAR * LPOA_FAST_DATA;
  164. //
  165. //
  166. // INT_ORDER_HEADER
  167. //
  168. // This structure contains the Common header (containing the fields which
  169. // are sent over the network) and some additional fields which are only
  170. // used on the host side)
  171. //
  172. // list
  173. // Offset to next and previous orders in the list
  174. // This field does not need to be transmitted across the network.
  175. //
  176. // additionalOrderData
  177. // Offset to the additional data for this order.
  178. // This field does not need to be transmitted across the network.
  179. //
  180. // cbAdditionalOrderData
  181. // Size of the additional data for this order.
  182. // This field does not need to be transmitted across the network.
  183. //
  184. // Common
  185. // Common header (which IS sent over the network)
  186. //
  187. // N.B. If you change this structure, please make sure that you haven't
  188. // broken the code in SBCInitInternalOrders.
  189. //
  190. //
  191. typedef struct INT_ORDER_HEADER
  192. {
  193. BASEDLIST list;
  194. LONG additionalOrderData;
  195. WORD cbAdditionalOrderDataLength;
  196. WORD pad1;
  197. COM_ORDER_HEADER Common;
  198. } INT_ORDER_HEADER;
  199. typedef INT_ORDER_HEADER FAR *LPINT_ORDER_HEADER;
  200. //
  201. // Define an order with the internal only fields defined (this is only used
  202. // on the sending end)
  203. //
  204. typedef struct _INT_ORDER
  205. {
  206. INT_ORDER_HEADER OrderHeader;
  207. BYTE abOrderData[1];
  208. } INT_ORDER;
  209. typedef INT_ORDER FAR *LPINT_ORDER;
  210. // Structure: INT_COLORTABLE_ORDER_xBPP
  211. //
  212. // Description: Internal structures used to pass color table data to the
  213. // share core. These are never sent across the wire.
  214. //
  215. typedef struct tagINT_COLORTABLE_HEADER
  216. {
  217. TSHR_UINT16 type; // holds "CT" - INTORD_COLORTABLE
  218. TSHR_UINT16 bpp; // 1, 4 or 8
  219. } INT_COLORTABLE_HEADER, FAR * LPINT_COLORTABLE_HEADER;
  220. typedef struct tagINT_COLORTABLE_ORDER_1BPP
  221. {
  222. INT_COLORTABLE_HEADER header;
  223. TSHR_RGBQUAD colorData[2];
  224. } INT_COLORTABLE_ORDER_1BPP, FAR * LPINT_COLORTABLE_ORDER_1BPP;
  225. typedef struct tagINT_COLORTABLE_ORDER_4BPP
  226. {
  227. INT_COLORTABLE_HEADER header;
  228. TSHR_RGBQUAD colorData[16];
  229. } INT_COLORTABLE_ORDER_4BPP, FAR * LPINT_COLORTABLE_ORDER_4BPP;
  230. typedef struct tagINT_COLORTABLE_ORDER_8BPP
  231. {
  232. INT_COLORTABLE_HEADER header;
  233. TSHR_RGBQUAD colorData[256];
  234. } INT_COLORTABLE_ORDER_8BPP, FAR * LPINT_COLORTABLE_ORDER_8BPP;
  235. //
  236. // Macro to calculate a basic internal order size (including the Order
  237. // Header).
  238. //
  239. #define INT_ORDER_SIZE(pOrder) \
  240. (pOrder->OrderHeader.Common.cbOrderDataLength + sizeof(INT_ORDER_HEADER))
  241. //
  242. // Macro to calculate the maximum possible size of an order, including
  243. // any Additional Order Data.
  244. //
  245. #define MAX_ORDER_SIZE(pOrder) \
  246. (INT_ORDER_SIZE(pOrder) + (pOrder->OrderHeader.cbAdditionalOrderDataLength))
  247. //
  248. // Macro to determine whether an order is SCRBLT_ORDER.
  249. //
  250. #define ORDER_IS_SCRBLT(pOrder) \
  251. (((LPSCRBLT_ORDER)&pOrder->abOrderData)->type == LOWORD(ORD_SCRBLT))
  252. //
  253. // Macro to determine whether an order is MEMBLT_ORDER.
  254. //
  255. #define ORDER_IS_MEMBLT(pOrder) \
  256. (((LPMEMBLT_ORDER)&pOrder->abOrderData)->type == LOWORD(ORD_MEMBLT) || \
  257. ((LPMEMBLT_ORDER)&pOrder->abOrderData)->type == LOWORD(ORD_MEMBLT_R2))
  258. //
  259. // Macro to determine whether an order is MEM3BLT_ORDER.
  260. //
  261. #define ORDER_IS_MEM3BLT(pOrder) \
  262. (((LPMEM3BLT_ORDER)&pOrder->abOrderData)->type == LOWORD(ORD_MEM3BLT) || \
  263. ((LPMEM3BLT_ORDER)&pOrder->abOrderData)->type == LOWORD(ORD_MEM3BLT_R2))
  264. //
  265. // PROTOTYPES
  266. //
  267. #ifdef DLL_DISP
  268. //
  269. // FUNCTION: OA_DDProcessRequest
  270. //
  271. // DESCRIPTION:
  272. //
  273. // Called by the display driver to process an OA specific request
  274. //
  275. // PARAMETERS: pso - pointer to surface object
  276. // cjIn - (IN) size of request block
  277. // pvIn - (IN) pointer to request block
  278. // cjOut - (IN) size of response block
  279. // pvOut - (OUT) pointer to response block
  280. //
  281. // RETURNS: None
  282. //
  283. //
  284. BOOL OA_DDProcessRequest(UINT fnEscape, LPOSI_ESCAPE_HEADER pResult,
  285. DWORD cbResult);
  286. //
  287. //
  288. // FUNCTION: OA_DDAllocOrderMem
  289. //
  290. // DESCRIPTION:
  291. //
  292. // Allocates memory for an internal order structure from our own private
  293. // Order Heap.
  294. //
  295. // Allocates any Additional Order Memory from global memory. A pointer to
  296. // the Additional Order Memory is stored within the allocated order's
  297. // header (pOrder->OrderHeader.pAdditionalOrderData).
  298. //
  299. //
  300. // PARAMETERS:
  301. //
  302. // cbOrderDataLength - length in bytes of the order data to be allocated
  303. // from the Order Heap.
  304. //
  305. // cbAdditionalOrderDataLength - length in bytes of additional order data
  306. // to be allocated from Global Memory. If this parameter is zero no
  307. // additional order memory is allocated.
  308. //
  309. //
  310. // RETURNS:
  311. //
  312. // A pointer to the allocated order memory. NULL if the memory allocation
  313. // failed.
  314. //
  315. //
  316. //
  317. LPINT_ORDER OA_DDAllocOrderMem(UINT cbOrderDataLength, UINT cbAdditionalOrderDataLength );
  318. //
  319. //
  320. // OA_DDFreeOrderMem(..)
  321. //
  322. // Frees order memory allocated by OA_AllocOrderMem(..).
  323. // Frees order memory from our own private heap.
  324. // Frees any Additional Order Memory associated with this order.
  325. //
  326. // Order memory is normally freed when the order is transmitted.
  327. //
  328. // This will be used if order memory has been allocated, and
  329. // subsequently, before the order is passed to AddOrder(..), the
  330. // allocator decides that the order should not be sent (e.g. if it
  331. // is completely clipped out).
  332. //
  333. //
  334. void OA_DDFreeOrderMem(LPINT_ORDER pOrder);
  335. void OA_DDResetOrderList(void);
  336. LPINT_ORDER OA_DDRemoveListOrder(LPINT_ORDER pCondemnedOrder);
  337. void OA_DDSyncUpdatesNow(void);
  338. //
  339. // Name: OA_DDSpoilOrdersByRect
  340. //
  341. // Purpose: Try to spoil orders by a given rectangle.
  342. //
  343. // Returns: Nothing
  344. //
  345. // Params: IN pRect - Pointer to the spoiling rectangle
  346. //
  347. // Operation: This function will start at the end of the order heap (from
  348. // the newest order) and work towards the start of the heap.
  349. //
  350. void OA_DDSpoilOrdersByRect(LPRECT pRect);
  351. //
  352. //
  353. // OA_DDAddOrder(..)
  354. //
  355. // Adds an order to the queue for transmission.
  356. //
  357. // If the new order is completely covered by the current SDA then
  358. // it is spoilt.
  359. //
  360. // If the order is opaque and overlaps earlier orders it may clip
  361. // or spoil them.
  362. //
  363. // Called by the GDI interception code.
  364. //
  365. //
  366. void OA_DDAddOrder(LPINT_ORDER pNewOrder, void FAR * pExtraInfo);
  367. void OADDAppendToOrderList(LPOA_SHARED_DATA lpoaShared, LPINT_ORDER pNewOrder);
  368. LPINT_ORDER OADDAllocOrderMemInt(LPOA_SHARED_DATA lpoaShared, UINT cbOrderDataLength, UINT cbAdditionalOrderDataLength);
  369. void OADDFreeOrderMemInt(LPOA_SHARED_DATA lpoaShared, LPINT_ORDER pOrder);
  370. void OADDFreeAllOrders(LPOA_SHARED_DATA lpoaShared);
  371. BOOL OADDCompleteOverlapRect(LPTSHR_RECT16 prcsSrc, LPRECT prcsOverlap);
  372. void OATrySpoilingByOrders(void);
  373. void OADDSpoilFromOrder(LPOA_SHARED_DATA lpoaShared, LPINT_ORDER pOrder, LPRECT pRect);
  374. #ifdef DEBUG
  375. void CheckOaHeap(LPOA_SHARED_DATA);
  376. #else
  377. #define CheckOaHeap(lpoaShared)
  378. #endif
  379. #endif // !DLL_DISP
  380. #endif // _H_OA