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.

451 lines
13 KiB

  1. //
  2. // Bounds Accumulation
  3. //
  4. #ifndef _H_BA
  5. #define _H_BA
  6. //
  7. // Number of rectangles used by the SDA.
  8. // NOTE: You can play around with this setting, building the core & the
  9. // display driver. Bumping it up means finer update areas, bumping it down
  10. // means more rect blobs of data.
  11. //
  12. #define BA_NUM_RECTS 10
  13. #define BA_INVALID_RECT_INDEX ((UINT)-1)
  14. //
  15. // Values for OSI escape codes
  16. //
  17. #define BA_ESC(code) (OSI_BA_ESC_FIRST + code)
  18. #define BA_ESC_GET_BOUNDS BA_ESC(0)
  19. #define BA_ESC_RETURN_BOUNDS BA_ESC(1)
  20. //
  21. //
  22. // MACROS
  23. //
  24. //
  25. //
  26. // Macros to access the fast swapping shared memory.
  27. //
  28. #ifdef DLL_DISP
  29. #define BA_FST_START_WRITING SHM_StartAccess(SHM_BA_FAST)
  30. #define BA_FST_STOP_WRITING SHM_StopAccess(SHM_BA_FAST)
  31. #else
  32. #define BA_FST_START_READING &g_asSharedMemory->baFast[\
  33. 1 - g_asSharedMemory->fastPath.newBuffer]
  34. #define BA_FST_STOP_READING
  35. #define BA_FST_START_WRITING &g_asSharedMemory->baFast[\
  36. 1 - g_asSharedMemory->fastPath.newBuffer]
  37. #define BA_FST_STOP_WRITING
  38. #endif // DLL_DISP
  39. //
  40. //
  41. // TYPES
  42. //
  43. //
  44. //
  45. // Structure: BA_BOUNDS_INFO
  46. //
  47. // Description: Structure used to pass bounds information between the
  48. // share core and the driver.
  49. //
  50. //
  51. typedef struct tagBA_BOUNDS_INFO
  52. {
  53. OSI_ESCAPE_HEADER header; // Common header
  54. DWORD numRects; // Num of bounds rects
  55. RECTL rects[BA_NUM_RECTS]; // Rects
  56. }
  57. BA_BOUNDS_INFO;
  58. typedef BA_BOUNDS_INFO FAR * LPBA_BOUNDS_INFO;
  59. //
  60. // Structure: BA_FAST_DATA
  61. //
  62. // Used to pass data from the screen output task to the Share Core on each
  63. // periodic processing.
  64. //
  65. typedef struct tagBA_FAST_DATA
  66. {
  67. DWORD totalSDA;
  68. } BA_FAST_DATA;
  69. typedef BA_FAST_DATA FAR * LPBA_FAST_DATA;
  70. //
  71. //
  72. // OVERVIEW
  73. //
  74. // The bounds code used to be common to the share core and the display
  75. // driver, with the data stored in the double buffered shared memory. This
  76. // is no longer the case.
  77. //
  78. // The display driver now "owns" the bounds - they are no longer stored in
  79. // shared memory - and does all the complex manipulations such as merging
  80. // rectangles. When the share core needs to process bounds, it gets a copy
  81. // from the driver by calling BA_FetchBounds(), sends as much of the data
  82. // as possible, then returns the remaining bounds to the driver by calling
  83. // BA_ReturnBounds().
  84. //
  85. // The nett result of these changes is that all the code which was common
  86. // to the share core and the display driver (in abaapi.c and abaint.c) is
  87. // now only in the driver (in nbaapi.c and nbaint.c). There are vastly
  88. // simplified versions of the functions in the share core.
  89. //
  90. //
  91. //
  92. // BA_ResetBounds
  93. //
  94. #ifdef DLL_DISP
  95. void BA_DDInit(void);
  96. void BA_ResetBounds(void);
  97. #endif // DLL_DISP
  98. //
  99. // Name: BA_ReturnBounds
  100. //
  101. // Purpose: Pass the share core's copy of the bounds to the driver.
  102. //
  103. // Returns: Nothing
  104. //
  105. // Params: None
  106. //
  107. // Operation: This resets the share core's bounds to NULL.
  108. //
  109. void BA_ReturnBounds(void);
  110. //
  111. // Name: BA_CopyBounds
  112. //
  113. // Description: Copies the bounding rectangle list.
  114. //
  115. // Params (IN): pRects - pointer to array of RECTs to fill in.
  116. // (OUT):pNumrects - filled in with number of RECTs copied.
  117. // (IN): reset current rects or just get current state w/o changing
  118. // state.
  119. //
  120. // Returns: TRUE or FALSE
  121. //
  122. // DESCRIPTION
  123. //
  124. // Returns the accumulated bounds for all applications in the bounds
  125. // code's current list of applications. The bounds returned will
  126. // include all updates originating from these applications but they may
  127. // also include updates outside these applications windows and updates
  128. // originating from other applications. Therefore the caller must clip
  129. // the returned bounds to the windows of the applications being
  130. // shadowed.
  131. //
  132. // PARAMETERS
  133. //
  134. // pRects:
  135. //
  136. // A pointer to an array of rectangles in which the bounds will be
  137. // returned. The contents of this array are only valid if *pRegion is NULL
  138. // on return from BA_GetBounds. There must
  139. // be room for maxRects rectangles (as specified in the bndInitialise
  140. // call). pRects may be a NULL pointer if maxRects was set to 0 in the
  141. // bndInitialise call.
  142. //
  143. // pNumRects:
  144. //
  145. // A pointer to a variable where the number of rectangles returned at
  146. // pRects is returned. The contents of this variable are only valid if
  147. // *pRegion is NULL on return from BA_GetBounds.
  148. //
  149. // fReset:
  150. // Whether to reset the core's bounds variables after getting the current
  151. // state or not.
  152. //
  153. //
  154. void BA_CopyBounds(LPRECT pRects, LPUINT pNumRects, BOOL fReset);
  155. #ifdef DLL_DISP
  156. typedef struct tagDD_BOUNDS
  157. {
  158. UINT iNext;
  159. BOOL InUse;
  160. RECT Coord;
  161. DWORD Area;
  162. } DD_BOUNDS;
  163. typedef DD_BOUNDS FAR* LPDD_BOUNDS;
  164. //
  165. // Name: BA_DDProcessRequest
  166. //
  167. // Purpose: Process a request from the share core
  168. //
  169. // Returns: TRUE if the request is processed successfully,
  170. // FALSE otherwise.
  171. //
  172. // Params: IN pso - Pointer to surface object for our driver
  173. // IN cjIn - Size of the input data
  174. // IN pvIn - Pointer to the input data
  175. // IN cjOut - Size of the output data
  176. // IN/OUT pvOut - Pointer to the output data
  177. //
  178. #ifdef IS_16
  179. BOOL BA_DDProcessRequest(UINT fnEscape, LPOSI_ESCAPE_HEADER pResult,
  180. DWORD cbResult);
  181. #else
  182. BOOL BA_DDProcessRequest(DWORD fnEscape, LPOSI_ESCAPE_HEADER pRequest,
  183. DWORD cbRequest, LPOSI_ESCAPE_HEADER pResult, DWORD cbResult);
  184. #endif // !IS_16
  185. //
  186. // Name: BA_QuerySpoilingBounds
  187. //
  188. // Purpose: Return the current spoiling bounds. That is, the bounds
  189. // which the share core is currently processing.
  190. //
  191. // Returns: Nothing
  192. //
  193. // Params: IN/OUT pRects - Pointer to an array of rectangles to
  194. // return the bounds in. There must be at
  195. // least BA_NUM_RECTS entries in this
  196. // array. The first *pNumRects entries are
  197. // valid on return.
  198. // IN/OUT pNumRects - Returns the number of rectangles forming
  199. // the spoiling bounds (can be zero).
  200. //
  201. void BA_QuerySpoilingBounds(LPRECT pRects, LPUINT pNumRects);
  202. //
  203. // Name: BAOverlap
  204. //
  205. // Description: Detects overlap between two rectangles.
  206. //
  207. // - check for no overlap using loose test that lets through
  208. // adjacent/overlapping merges
  209. // - check for adjacent/overlapping merges
  210. // - check for no overlap (using strict test)
  211. // - use outcodes to check internal edge cases
  212. // - use outcodes to check external edge cases
  213. //
  214. // If at each stage the check detects that the two rectangles
  215. // meet the criteria, the function returns the appropriate
  216. // return or outcode combination.
  217. //
  218. // Note that all rectangle coordinates are inclusive, ie
  219. // a rectangle of 0,0,0,0 has an area of 1 pel.
  220. //
  221. // This function does not alter either of the rectangles.
  222. //
  223. // Params (IN): pRect1 - first rectangle
  224. // pRect2 - second rectangle
  225. //
  226. // Returns: One of the overlap return codes or outcode combinations
  227. // defined above.
  228. //
  229. //
  230. //
  231. // Note that bndRectsArray and bndRectsSizeArray must contain space for
  232. // BA_NUM_RECTS+1 rectangles for the merge algorithm.
  233. //
  234. //
  235. // The function will recurse to a maximum level when trying to split
  236. // rectangles up. When this limit is reached it will start merging
  237. // rather than splitting
  238. //
  239. #define ADDR_RECURSE_LIMIT 20
  240. //
  241. // The following constants are used to determine overlaps.
  242. //
  243. // - OL_NONE through OL_MERGE_YMAX are return codes - which need to be
  244. // distinct from all possible outcode combinations - allowing for the
  245. // minus outcodes for enclosed cases.
  246. //
  247. // - EE_XMIN through EE_YMAX are outcodes - which need to be uniquely
  248. // ORable binary constants within a single nibble.
  249. //
  250. // - OL_ENCLOSED through OL_SPLIT_XMAX_YMAX are outcode combinations for
  251. // internal and external edge overlap cases.
  252. //
  253. // See Overlap() for further description.
  254. //
  255. #define OL_NONE -1
  256. #define OL_MERGE_XMIN -2
  257. #define OL_MERGE_YMIN -3
  258. #define OL_MERGE_XMAX -4
  259. #define OL_MERGE_YMAX -5
  260. #define EE_XMIN 0x0001
  261. #define EE_YMIN 0x0002
  262. #define EE_XMAX 0x0004
  263. #define EE_YMAX 0x0008
  264. #define OL_ENCLOSED -(EE_XMIN | EE_YMIN | EE_XMAX | EE_YMAX)
  265. #define OL_PART_ENCLOSED_XMIN -(EE_XMIN | EE_YMIN | EE_YMAX)
  266. #define OL_PART_ENCLOSED_YMIN -(EE_XMIN | EE_YMIN | EE_XMAX)
  267. #define OL_PART_ENCLOSED_XMAX -(EE_YMIN | EE_XMAX | EE_YMAX)
  268. #define OL_PART_ENCLOSED_YMAX -(EE_XMIN | EE_XMAX | EE_YMAX)
  269. #define OL_ENCLOSES EE_XMIN | EE_XMAX | EE_YMIN | EE_YMAX
  270. #define OL_PART_ENCLOSES_XMIN EE_XMAX | EE_YMIN | EE_YMAX
  271. #define OL_PART_ENCLOSES_XMAX EE_XMIN | EE_YMIN | EE_YMAX
  272. #define OL_PART_ENCLOSES_YMIN EE_XMIN | EE_XMAX | EE_YMAX
  273. #define OL_PART_ENCLOSES_YMAX EE_XMIN | EE_XMAX | EE_YMIN
  274. #define OL_SPLIT_X EE_YMIN | EE_YMAX
  275. #define OL_SPLIT_Y EE_XMIN | EE_XMAX
  276. #define OL_SPLIT_XMIN_YMIN EE_XMAX | EE_YMAX
  277. #define OL_SPLIT_XMAX_YMIN EE_XMIN | EE_YMAX
  278. #define OL_SPLIT_XMIN_YMAX EE_XMAX | EE_YMIN
  279. #define OL_SPLIT_XMAX_YMAX EE_XMIN | EE_YMIN
  280. int BAOverlap(LPRECT pRect1, LPRECT pRect2 );
  281. //
  282. // Name: BAAddRectList
  283. //
  284. // Description: Adds a rectangle to the list of accumulated rectangles.
  285. //
  286. // - find a free slot in the array
  287. // - add slot record to list
  288. // - fill slot record with rect and mark as in use.
  289. //
  290. // Params (IN): pRect - rectangle to add
  291. //
  292. // Returns:
  293. //
  294. //
  295. void BAAddRectList(LPRECT pRect);
  296. //
  297. // Name: BA_RemoveRectList
  298. //
  299. // Description: Removes a rectangle from the list of accumulated
  300. // rectangles.
  301. //
  302. // - find the rectangle in the list
  303. // - unlink it from the list and mark the slot as free
  304. //
  305. // Params (IN): pRect - rectangle to remove
  306. //
  307. // Returns:
  308. //
  309. //
  310. void BA_RemoveRectList(LPRECT pRect);
  311. void BA_AddScreenData(LPRECT pRect);
  312. //
  313. // Name: BAAddRect
  314. //
  315. // Description: Accumulates rectangles.
  316. //
  317. // This is a complex routine, with the essential algorithm
  318. // as follows.
  319. //
  320. // - Start with the supplied rectangle as the candidate
  321. // rectangle.
  322. //
  323. // - Compare the candidate against each of the existing
  324. // accumulated rectangles.
  325. //
  326. // - If some form of overlap is detected between the
  327. // candidate and an existing rectangle, this may result in
  328. // one of the following (see the cases of the switch for
  329. // details):
  330. //
  331. // - adjust the candidate or the existing rectangle or both
  332. // - merge the candidate into the existing rectangle
  333. // - discard the candidate as it is enclosed by an existing
  334. // rectangle.
  335. //
  336. // - If the merge or adjustment results in a changed
  337. // candidate, restart the comparisons from the beginning of
  338. // the list with the changed candidate.
  339. //
  340. // - If the adjustment results in a split (giving two
  341. // candidate rectangles), invoke this routine recursively
  342. // with one of the two candidates as its candidate.
  343. //
  344. // - If no overlap is detected against the existing rectangles,
  345. // add the candidate to the list of accumulated rectangles.
  346. //
  347. // - If the add results in more than BA_NUM_RECTS
  348. // accumulated rectangles, do a forced merge of two of the
  349. // accumulate rectangles (which include the newly added
  350. // candidate) - choosing the two rectangles where the merged
  351. // rectangle results in the smallest increase in area over
  352. // the two non-merged rectangles.
  353. //
  354. // - After a forced merge, restart the comparisons from the
  355. // beginning of the list with the newly merged rectangle as
  356. // the candidate.
  357. //
  358. // For a particular call, this process will continue until
  359. // the candidate (whether the supplied rectangle, an adjusted
  360. // version of that rectangle, or a merged rectangle):
  361. //
  362. // - does not find an overlap among the rectangles in the list
  363. // and does not cause a forced merge
  364. // - is discarded becuase it is enclosed within one of the
  365. // rectangles in the list.
  366. //
  367. // Note that all rectangle coordinates are inclusive, ie
  368. // a rectangle of 0,0,0,0 has an area of 1 pel.
  369. //
  370. // Params (IN): pCand - new candidate rectangle
  371. // level - recursion level
  372. //
  373. // Returns: TRUE if rectandle was spoilt due to a complete overlap.
  374. //
  375. //
  376. BOOL BAAddRect( LPRECT pCand, int level );
  377. #endif // DLL_DISP
  378. #endif // _H_BA