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.

1516 lines
52 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: bitblt.c
  3. *
  4. * Contains the high-level DrvBitBlt and DrvCopyBits functions. The low-
  5. * level stuff lives in 'blt.c'.
  6. *
  7. * !!! Change note about 'iType'
  8. *
  9. * Note: Since we've implemented device-bitmaps, any surface that GDI passes
  10. * to us can have 3 values for its 'iType': STYPE_BITMAP, STYPE_DEVICE
  11. * or STYPE_DEVBITMAP. We filter device-bitmaps that we've stored
  12. * as DIBs fairly high in the code, so after we adjust its 'pptlSrc',
  13. * we can treat STYPE_DEVBITMAP surfaces the same as STYPE_DEVICE
  14. * surfaces (e.g., a blt from an off-screen device bitmap to the screen
  15. * gets treated as a normal screen-to-screen blt). So throughout
  16. * this code, we will compare a surface's 'iType' to STYPE_BITMAP:
  17. * if it's equal, we've got a true DIB, and if it's unequal, we have
  18. * a screen-to-screen operation.
  19. *
  20. * Copyright (c) 1992-1995 Microsoft Corporation
  21. *
  22. \**************************************************************************/
  23. #include "precomp.h"
  24. /******************************Public*Data*********************************\
  25. * Rop-needs-pattern table
  26. *
  27. * Determines if a rop2 needs uses a pattern.
  28. *
  29. * Use 'gabRopNeedsPattern[(rop3 >> 2) & 0xf]', but note that this can only
  30. * be done if it is known that the rop3 doesn't use a source.
  31. *
  32. \**************************************************************************/
  33. BYTE gabRopNeedsPattern[] =
  34. {
  35. FALSE, // R2_BLACK
  36. TRUE, // R2_NOTMERGEPEN
  37. TRUE, // R2_MASKNOTPEN
  38. TRUE, // R2_NOTCOPYPEN
  39. TRUE, // R2_MASKPENNOT
  40. FALSE, // R2_NOT
  41. TRUE, // R2_XORPEN
  42. TRUE, // R2_NOTMASKPEN
  43. TRUE, // R2_MASKPEN
  44. TRUE, // R2_NOTXORPEN
  45. FALSE, // R2_NOP
  46. TRUE, // R2_MERGENOTPEN
  47. TRUE, // R2_COPYPEN
  48. TRUE, // R2_MERGEPENNOT
  49. TRUE, // R2_MERGEPEN
  50. FALSE, // R2_WHITE
  51. };
  52. /******************************Public*Data*********************************\
  53. * Mix-needs-pattern table
  54. *
  55. * Determines if a mix uses a pattern.
  56. *
  57. * Use 'gabMixNeedsPattern[mix & 0xf]' or 'gabMixNeedsPattern[mix & 0xff]'.
  58. *
  59. \**************************************************************************/
  60. BYTE gabMixNeedsPattern[] =
  61. {
  62. FALSE, // R2_WHITE - Allow rop = gaRop3FromMix[mix & 0x0F]
  63. FALSE, // R2_BLACK
  64. TRUE, // R2_NOTMERGEPEN
  65. TRUE, // R2_MASKNOTPEN
  66. TRUE, // R2_NOTCOPYPEN
  67. TRUE, // R2_MASKPENNOT
  68. FALSE, // R2_NOT
  69. TRUE, // R2_XORPEN
  70. TRUE, // R2_NOTMASKPEN
  71. TRUE, // R2_MASKPEN
  72. TRUE, // R2_NOTXORPEN
  73. FALSE, // R2_NOP
  74. TRUE, // R2_MERGENOTPEN
  75. TRUE, // R2_COPYPEN
  76. TRUE, // R2_MERGEPENNOT
  77. TRUE, // R2_MERGEPEN
  78. FALSE, // R2_WHITE - Allow rop = gaRop3FromMix[mix & 0xFF]
  79. };
  80. /******************************Public*Data*********************************\
  81. * MIX translation table
  82. *
  83. * Translates a mix 1-16, into an old style Rop 0-255.
  84. *
  85. \**************************************************************************/
  86. BYTE gaRop3FromMix[] =
  87. {
  88. 0xFF, // R2_WHITE - Allow rop = gaRop3FromMix[mix & 0x0F]
  89. 0x00, // R2_BLACK
  90. 0x05, // R2_NOTMERGEPEN
  91. 0x0A, // R2_MASKNOTPEN
  92. 0x0F, // R2_NOTCOPYPEN
  93. 0x50, // R2_MASKPENNOT
  94. 0x55, // R2_NOT
  95. 0x5A, // R2_XORPEN
  96. 0x5F, // R2_NOTMASKPEN
  97. 0xA0, // R2_MASKPEN
  98. 0xA5, // R2_NOTXORPEN
  99. 0xAA, // R2_NOP
  100. 0xAF, // R2_MERGENOTPEN
  101. 0xF0, // R2_COPYPEN
  102. 0xF5, // R2_MERGEPENNOT
  103. 0xFA, // R2_MERGEPEN
  104. 0xFF // R2_WHITE - Allow rop = gaRop3FromMix[mix & 0xFF]
  105. };
  106. #if DBG
  107. // This table is big, so we only use to aid in debugging...
  108. /******************************Public*Data*********************************\
  109. * ROP3 translation table - Use only for debugging
  110. *
  111. * Translates the usual ternary rop into A-vector notation. Each bit in
  112. * this new notation corresponds to a term in a polynomial translation of
  113. * the rop.
  114. *
  115. * Rop(D,S,P) = a + a D + a S + a P + a DS + a DP + a SP + a DSP
  116. * 0 d s p ds dp sp dsp
  117. *
  118. \**************************************************************************/
  119. BYTE gajRop3[] =
  120. {
  121. 0x00, 0xff, 0xb2, 0x4d, 0xd4, 0x2b, 0x66, 0x99,
  122. 0x90, 0x6f, 0x22, 0xdd, 0x44, 0xbb, 0xf6, 0x09,
  123. 0xe8, 0x17, 0x5a, 0xa5, 0x3c, 0xc3, 0x8e, 0x71,
  124. 0x78, 0x87, 0xca, 0x35, 0xac, 0x53, 0x1e, 0xe1,
  125. 0xa0, 0x5f, 0x12, 0xed, 0x74, 0x8b, 0xc6, 0x39,
  126. 0x30, 0xcf, 0x82, 0x7d, 0xe4, 0x1b, 0x56, 0xa9,
  127. 0x48, 0xb7, 0xfa, 0x05, 0x9c, 0x63, 0x2e, 0xd1,
  128. 0xd8, 0x27, 0x6a, 0x95, 0x0c, 0xf3, 0xbe, 0x41,
  129. 0xc0, 0x3f, 0x72, 0x8d, 0x14, 0xeb, 0xa6, 0x59,
  130. 0x50, 0xaf, 0xe2, 0x1d, 0x84, 0x7b, 0x36, 0xc9,
  131. 0x28, 0xd7, 0x9a, 0x65, 0xfc, 0x03, 0x4e, 0xb1,
  132. 0xb8, 0x47, 0x0a, 0xf5, 0x6c, 0x93, 0xde, 0x21,
  133. 0x60, 0x9f, 0xd2, 0x2d, 0xb4, 0x4b, 0x06, 0xf9,
  134. 0xf0, 0x0f, 0x42, 0xbd, 0x24, 0xdb, 0x96, 0x69,
  135. 0x88, 0x77, 0x3a, 0xc5, 0x5c, 0xa3, 0xee, 0x11,
  136. 0x18, 0xe7, 0xaa, 0x55, 0xcc, 0x33, 0x7e, 0x81,
  137. 0x80, 0x7f, 0x32, 0xcd, 0x54, 0xab, 0xe6, 0x19,
  138. 0x10, 0xef, 0xa2, 0x5d, 0xc4, 0x3b, 0x76, 0x89,
  139. 0x68, 0x97, 0xda, 0x25, 0xbc, 0x43, 0x0e, 0xf1,
  140. 0xf8, 0x07, 0x4a, 0xb5, 0x2c, 0xd3, 0x9e, 0x61,
  141. 0x20, 0xdf, 0x92, 0x6d, 0xf4, 0x0b, 0x46, 0xb9,
  142. 0xb0, 0x4f, 0x02, 0xfd, 0x64, 0x9b, 0xd6, 0x29,
  143. 0xc8, 0x37, 0x7a, 0x85, 0x1c, 0xe3, 0xae, 0x51,
  144. 0x58, 0xa7, 0xea, 0x15, 0x8c, 0x73, 0x3e, 0xc1,
  145. 0x40, 0xbf, 0xf2, 0x0d, 0x94, 0x6b, 0x26, 0xd9,
  146. 0xd0, 0x2f, 0x62, 0x9d, 0x04, 0xfb, 0xb6, 0x49,
  147. 0xa8, 0x57, 0x1a, 0xe5, 0x7c, 0x83, 0xce, 0x31,
  148. 0x38, 0xc7, 0x8a, 0x75, 0xec, 0x13, 0x5e, 0xa1,
  149. 0xe0, 0x1f, 0x52, 0xad, 0x34, 0xcb, 0x86, 0x79,
  150. 0x70, 0x8f, 0xc2, 0x3d, 0xa4, 0x5b, 0x16, 0xe9,
  151. 0x08, 0xf7, 0xba, 0x45, 0xdc, 0x23, 0x6e, 0x91,
  152. 0x98, 0x67, 0x2a, 0xd5, 0x4c, 0xb3, 0xfe, 0x01
  153. };
  154. #define AVEC_NOT 0x01
  155. #define AVEC_D 0x02
  156. #define AVEC_S 0x04
  157. #define AVEC_P 0x08
  158. #define AVEC_DS 0x10
  159. #define AVEC_DP 0x20
  160. #define AVEC_SP 0x40
  161. #define AVEC_DSP 0x80
  162. #define AVEC_NEED_SOURCE (AVEC_S | AVEC_DS | AVEC_SP | AVEC_DSP)
  163. #define AVEC_NEED_PATTERN (AVEC_P | AVEC_DP | AVEC_SP | AVEC_DSP)
  164. #define AVEC_NEED_DEST (AVEC_D | AVEC_DS | AVEC_DP | AVEC_DSP)
  165. #endif // DBG
  166. /******************************Public*Table********************************\
  167. * BYTE gajLeftMask[] and BYTE gajRightMask[]
  168. *
  169. * Edge tables for vXferScreenTo1bpp.
  170. \**************************************************************************/
  171. BYTE gajLeftMask[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
  172. BYTE gajRightMask[] = { 0xff, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe };
  173. /******************************Public*Routine******************************\
  174. * BOOL bIntersect
  175. *
  176. * If 'prcl1' and 'prcl2' intersect, has a return value of TRUE and returns
  177. * the intersection in 'prclResult'. If they don't intersect, has a return
  178. * value of FALSE, and 'prclResult' is undefined.
  179. *
  180. \**************************************************************************/
  181. BOOL bIntersect(
  182. RECTL* prcl1,
  183. RECTL* prcl2,
  184. RECTL* prclResult)
  185. {
  186. prclResult->left = max(prcl1->left, prcl2->left);
  187. prclResult->right = min(prcl1->right, prcl2->right);
  188. if (prclResult->left < prclResult->right)
  189. {
  190. prclResult->top = max(prcl1->top, prcl2->top);
  191. prclResult->bottom = min(prcl1->bottom, prcl2->bottom);
  192. if (prclResult->top < prclResult->bottom)
  193. {
  194. return(TRUE);
  195. }
  196. }
  197. return(FALSE);
  198. }
  199. /******************************Public*Routine******************************\
  200. * LONG cIntersect
  201. *
  202. * This routine takes a list of rectangles from 'prclIn' and clips them
  203. * in-place to the rectangle 'prclClip'. The input rectangles don't
  204. * have to intersect 'prclClip'; the return value will reflect the
  205. * number of input rectangles that did intersect, and the intersecting
  206. * rectangles will be densely packed.
  207. *
  208. \**************************************************************************/
  209. LONG cIntersect(
  210. RECTL* prclClip,
  211. RECTL* prclIn, // List of rectangles
  212. LONG c) // Can be zero
  213. {
  214. LONG cIntersections;
  215. RECTL* prclOut;
  216. cIntersections = 0;
  217. prclOut = prclIn;
  218. for (; c != 0; prclIn++, c--)
  219. {
  220. prclOut->left = max(prclIn->left, prclClip->left);
  221. prclOut->right = min(prclIn->right, prclClip->right);
  222. if (prclOut->left < prclOut->right)
  223. {
  224. prclOut->top = max(prclIn->top, prclClip->top);
  225. prclOut->bottom = min(prclIn->bottom, prclClip->bottom);
  226. if (prclOut->top < prclOut->bottom)
  227. {
  228. prclOut++;
  229. cIntersections++;
  230. }
  231. }
  232. }
  233. return(cIntersections);
  234. }
  235. /******************************Public*Routine******************************\
  236. * VOID vXferScreenTo1bpp
  237. *
  238. * Performs a SRCCOPY transfer from the screen (when it's 8bpp) to a 1bpp
  239. * bitmap.
  240. *
  241. \**************************************************************************/
  242. #if defined(i386)
  243. VOID vXferScreenTo1bpp( // Type FNXFER
  244. PDEV* ppdev,
  245. LONG c, // Count of rectangles, can't be zero
  246. RECTL* prcl, // List of destination rectangles, in relative
  247. // coordinates
  248. ULONG ulHwMix, // Not used
  249. SURFOBJ* psoDst, // Destination surface
  250. POINTL* pptlSrc, // Original unclipped source point
  251. RECTL* prclDst, // Original unclipped destination rectangle
  252. XLATEOBJ* pxlo) // Provides colour-compressions information
  253. {
  254. LONG cjPel;
  255. VOID* pfnCompute;
  256. SURFOBJ soTmp;
  257. ULONG* pulXlate;
  258. ULONG ulForeColor;
  259. POINTL ptlSrc;
  260. RECTL rclTmp;
  261. BYTE* pjDst;
  262. BYTE jLeftMask;
  263. BYTE jRightMask;
  264. BYTE jNotLeftMask;
  265. BYTE jNotRightMask;
  266. LONG cjMiddle;
  267. LONG lDstDelta;
  268. LONG lSrcDelta;
  269. LONG cyTmpScans;
  270. LONG cyThis;
  271. LONG cyToGo;
  272. ASSERTDD(c > 0, "Can't handle zero rectangles");
  273. ASSERTDD(psoDst->iBitmapFormat == BMF_1BPP, "Only 1bpp destinations");
  274. ASSERTDD(TMP_BUFFER_SIZE >= (ppdev->cxMemory * ppdev->cjPel),
  275. "Temp buffer has to be larger than widest possible scan");
  276. // When the destination is a 1bpp bitmap, the foreground colour
  277. // maps to '1', and any other colour maps to '0'.
  278. if (ppdev->iBitmapFormat == BMF_8BPP)
  279. {
  280. // When the source is 8bpp or less, we find the forground colour
  281. // by searching the translate table for the only '1':
  282. pulXlate = pxlo->pulXlate;
  283. while (*pulXlate != 1)
  284. pulXlate++;
  285. ulForeColor = pulXlate - pxlo->pulXlate;
  286. }
  287. else
  288. {
  289. ASSERTDD((ppdev->iBitmapFormat == BMF_16BPP) ||
  290. (ppdev->iBitmapFormat == BMF_32BPP),
  291. "This routine only supports 8, 16 or 32bpp");
  292. // When the source has a depth greater than 8bpp, the foreground
  293. // colour will be the first entry in the translate table we get
  294. // from calling 'piVector':
  295. pulXlate = XLATEOBJ_piVector(pxlo);
  296. ulForeColor = 0;
  297. if (pulXlate != NULL) // This check isn't really needed...
  298. ulForeColor = pulXlate[0];
  299. }
  300. // We use the temporary buffer to keep a copy of the source
  301. // rectangle:
  302. soTmp.pvScan0 = ppdev->pvTmpBuffer;
  303. do {
  304. // ptlSrc points to the upper-left corner of the screen rectangle
  305. // for the current batch:
  306. ptlSrc.x = prcl->left + (pptlSrc->x - prclDst->left);
  307. ptlSrc.y = prcl->top + (pptlSrc->y - prclDst->top);
  308. // vGetBits takes absolute coordinates for the source point:
  309. ptlSrc.x += ppdev->xOffset;
  310. ptlSrc.y += ppdev->yOffset;
  311. pjDst = (BYTE*) psoDst->pvScan0 + (prcl->top * psoDst->lDelta)
  312. + (prcl->left >> 3);
  313. cjPel = ppdev->cjPel;
  314. soTmp.lDelta = (((prcl->right + 7L) & ~7L) - (prcl->left & ~7L))
  315. * cjPel;
  316. // Our temporary buffer, into which we read a copy of the source,
  317. // may be smaller than the source rectangle. In that case, we
  318. // process the source rectangle in batches.
  319. //
  320. // cyTmpScans is the number of scans we can do in each batch.
  321. // cyToGo is the total number of scans we have to do for this
  322. // rectangle.
  323. //
  324. // We take the buffer size less four so that the right edge case
  325. // can safely read one dword past the end:
  326. cyTmpScans = (TMP_BUFFER_SIZE - 4) / soTmp.lDelta;
  327. cyToGo = prcl->bottom - prcl->top;
  328. ASSERTDD(cyTmpScans > 0, "Buffer too small for largest possible scan");
  329. // Initialize variables that don't change within the batch loop:
  330. rclTmp.top = 0;
  331. rclTmp.left = prcl->left & 7L;
  332. rclTmp.right = (prcl->right - prcl->left) + rclTmp.left;
  333. // Note that we have to be careful with the right mask so that it
  334. // isn't zero. A right mask of zero would mean that we'd always be
  335. // touching one byte past the end of the scan (even though we
  336. // wouldn't actually be modifying that byte), and we must never
  337. // access memory past the end of the bitmap (because we can access
  338. // violate if the bitmap end is exactly page-aligned).
  339. jLeftMask = gajLeftMask[rclTmp.left & 7];
  340. jRightMask = gajRightMask[rclTmp.right & 7];
  341. cjMiddle = ((rclTmp.right - 1) >> 3) - (rclTmp.left >> 3) - 1;
  342. if (cjMiddle < 0)
  343. {
  344. // The blt starts and ends in the same byte:
  345. jLeftMask &= jRightMask;
  346. jRightMask = 0;
  347. cjMiddle = 0;
  348. }
  349. jNotLeftMask = ~jLeftMask;
  350. jNotRightMask = ~jRightMask;
  351. lDstDelta = psoDst->lDelta - cjMiddle - 2;
  352. // Delta from the end of the destination
  353. // to the start on the next scan, accounting
  354. // for 'left' and 'right' bytes
  355. lSrcDelta = soTmp.lDelta - ((8 * (cjMiddle + 2)) * cjPel);
  356. // Compute source delta for special cases
  357. // like when cjMiddle gets bumped up to '0',
  358. // and to correct aligned cases
  359. do {
  360. // This is the loop that breaks the source rectangle into
  361. // manageable batches.
  362. cyThis = cyTmpScans;
  363. cyToGo -= cyThis;
  364. if (cyToGo < 0)
  365. cyThis += cyToGo;
  366. rclTmp.bottom = cyThis;
  367. vGetBits(ppdev, &soTmp, &rclTmp, &ptlSrc);
  368. ptlSrc.y += cyThis; // Get ready for next batch loop
  369. _asm {
  370. mov eax,ulForeColor ;eax = foreground colour
  371. ;ebx = temporary storage
  372. ;ecx = count of middle dst bytes
  373. ;dl = destination byte accumulator
  374. ;dh = temporary storage
  375. mov esi,soTmp.pvScan0 ;esi = source pointer
  376. mov edi,pjDst ;edi = destination pointer
  377. ; Figure out the appropriate compute routine:
  378. mov ebx,cjPel
  379. mov pfnCompute,offset Compute_Destination_Byte_From_8bpp
  380. dec ebx
  381. jz short Do_Left_Byte
  382. mov pfnCompute,offset Compute_Destination_Byte_From_16bpp
  383. dec ebx
  384. jz short Do_Left_Byte
  385. mov pfnCompute,offset Compute_Destination_Byte_From_32bpp
  386. Do_Left_Byte:
  387. call pfnCompute
  388. and dl,jLeftMask
  389. mov dh,jNotLeftMask
  390. and dh,[edi]
  391. or dh,dl
  392. mov [edi],dh
  393. inc edi
  394. mov ecx,cjMiddle
  395. dec ecx
  396. jl short Do_Right_Byte
  397. Do_Middle_Bytes:
  398. call pfnCompute
  399. mov [edi],dl
  400. inc edi
  401. dec ecx
  402. jge short Do_Middle_Bytes
  403. Do_Right_Byte:
  404. call pfnCompute
  405. and dl,jRightMask
  406. mov dh,jNotRightMask
  407. and dh,[edi]
  408. or dh,dl
  409. mov [edi],dh
  410. inc edi
  411. add edi,lDstDelta
  412. add esi,lSrcDelta
  413. dec cyThis
  414. jnz short Do_Left_Byte
  415. mov pjDst,edi ;save for next batch
  416. jmp All_Done
  417. Compute_Destination_Byte_From_8bpp:
  418. mov bl,[esi]
  419. sub bl,al
  420. cmp bl,1
  421. adc dl,dl ;bit 0
  422. mov bl,[esi+1]
  423. sub bl,al
  424. cmp bl,1
  425. adc dl,dl ;bit 1
  426. mov bl,[esi+2]
  427. sub bl,al
  428. cmp bl,1
  429. adc dl,dl ;bit 2
  430. mov bl,[esi+3]
  431. sub bl,al
  432. cmp bl,1
  433. adc dl,dl ;bit 3
  434. mov bl,[esi+4]
  435. sub bl,al
  436. cmp bl,1
  437. adc dl,dl ;bit 4
  438. mov bl,[esi+5]
  439. sub bl,al
  440. cmp bl,1
  441. adc dl,dl ;bit 5
  442. mov bl,[esi+6]
  443. sub bl,al
  444. cmp bl,1
  445. adc dl,dl ;bit 6
  446. mov bl,[esi+7]
  447. sub bl,al
  448. cmp bl,1
  449. adc dl,dl ;bit 7
  450. add esi,8 ;advance the source
  451. ret
  452. Compute_Destination_Byte_From_16bpp:
  453. mov bx,[esi]
  454. sub bx,ax
  455. cmp bx,1
  456. adc dl,dl ;bit 0
  457. mov bx,[esi+2]
  458. sub bx,ax
  459. cmp bx,1
  460. adc dl,dl ;bit 1
  461. mov bx,[esi+4]
  462. sub bx,ax
  463. cmp bx,1
  464. adc dl,dl ;bit 2
  465. mov bx,[esi+6]
  466. sub bx,ax
  467. cmp bx,1
  468. adc dl,dl ;bit 3
  469. mov bx,[esi+8]
  470. sub bx,ax
  471. cmp bx,1
  472. adc dl,dl ;bit 4
  473. mov bx,[esi+10]
  474. sub bx,ax
  475. cmp bx,1
  476. adc dl,dl ;bit 5
  477. mov bx,[esi+12]
  478. sub bx,ax
  479. cmp bx,1
  480. adc dl,dl ;bit 6
  481. mov bx,[esi+14]
  482. sub bx,ax
  483. cmp bx,1
  484. adc dl,dl ;bit 7
  485. add esi,16 ;advance the source
  486. ret
  487. Compute_Destination_Byte_From_32bpp:
  488. mov ebx,[esi]
  489. sub ebx,eax
  490. cmp ebx,1
  491. adc dl,dl ;bit 0
  492. mov ebx,[esi+4]
  493. sub ebx,eax
  494. cmp ebx,1
  495. adc dl,dl ;bit 1
  496. mov ebx,[esi+8]
  497. sub ebx,eax
  498. cmp ebx,1
  499. adc dl,dl ;bit 2
  500. mov ebx,[esi+12]
  501. sub ebx,eax
  502. cmp ebx,1
  503. adc dl,dl ;bit 3
  504. mov ebx,[esi+16]
  505. sub ebx,eax
  506. cmp ebx,1
  507. adc dl,dl ;bit 4
  508. mov ebx,[esi+20]
  509. sub ebx,eax
  510. cmp ebx,1
  511. adc dl,dl ;bit 5
  512. mov ebx,[esi+24]
  513. sub ebx,eax
  514. cmp ebx,1
  515. adc dl,dl ;bit 6
  516. mov ebx,[esi+28]
  517. sub ebx,eax
  518. cmp ebx,1
  519. adc dl,dl ;bit 7
  520. add esi,32 ;advance the source
  521. ret
  522. All_Done:
  523. }
  524. } while (cyToGo > 0);
  525. prcl++;
  526. } while (--c != 0);
  527. }
  528. #endif // i386
  529. /******************************Public*Routine******************************\
  530. * BOOL bPuntBlt
  531. *
  532. * Has GDI do any drawing operations that we don't specifically handle
  533. * in the driver.
  534. *
  535. \**************************************************************************/
  536. BOOL bPuntBlt(
  537. SURFOBJ* psoDst,
  538. SURFOBJ* psoSrc,
  539. SURFOBJ* psoMsk,
  540. CLIPOBJ* pco,
  541. XLATEOBJ* pxlo,
  542. RECTL* prclDst,
  543. POINTL* pptlSrc,
  544. POINTL* pptlMsk,
  545. BRUSHOBJ* pbo,
  546. POINTL* pptlBrush,
  547. ROP4 rop4)
  548. {
  549. PDEV* ppdev;
  550. DSURF* pdsurfSrc;
  551. DSURF* pdsurfDst;
  552. OH* pohSrc;
  553. OH* pohDst;
  554. POINTL ptlSrc;
  555. #if DBG
  556. {
  557. //////////////////////////////////////////////////////////////////////
  558. // Diagnostics
  559. //
  560. // Since calling the engine to do any drawing can be rather painful,
  561. // particularly when the source is an off-screen DFB (since GDI will
  562. // have to allocate a DIB and call us to make a temporary copy before
  563. // it can even start drawing), we'll try to avoid it as much as
  564. // possible.
  565. //
  566. // Here we simply spew out information describing the blt whenever
  567. // this routine gets called (checked builds only, of course):
  568. ULONG ulClip;
  569. PDEV* ppdev;
  570. ULONG ulAvec;
  571. if (psoDst->dhpdev != NULL)
  572. ppdev = (PDEV*) psoDst->dhpdev;
  573. else
  574. ppdev = (PDEV*) psoSrc->dhpdev;
  575. ulClip = (pco == NULL) ? DC_TRIVIAL : pco->iDComplexity;
  576. DISPDBG((1, ">> Punt << Dst format: %li Dst type: %li Clip: %li Rop: %lx",
  577. psoDst->iBitmapFormat, psoDst->iType, ulClip, rop4));
  578. if (psoSrc != NULL)
  579. DISPDBG((1, " << Src format: %li Src type: %li",
  580. psoSrc->iBitmapFormat, psoSrc->iType));
  581. if ((pxlo != NULL) && !(pxlo->flXlate & XO_TRIVIAL) && (psoSrc != NULL))
  582. {
  583. if (((psoSrc->dhsurf == NULL) &&
  584. (psoSrc->iBitmapFormat != ppdev->iBitmapFormat)) ||
  585. ((psoDst->dhsurf == NULL) &&
  586. (psoDst->iBitmapFormat != ppdev->iBitmapFormat)))
  587. {
  588. // Don't bother printing the 'xlate' message when the source
  589. // is a different bitmap format from the destination -- in
  590. // those cases we know there always has to be a translate.
  591. }
  592. else
  593. {
  594. DISPDBG((1, " << With xlate"));
  595. }
  596. }
  597. // The high 2 bytes of rop4 is not guaranteed to be zero. So in order
  598. // to get the low 8 bits as index, we have to &ffff before do >>
  599. ulAvec = gajRop3[rop4 & 0xff] | gajRop3[(rop4 & 0xffff) >> 8];
  600. if ((ulAvec & AVEC_NEED_PATTERN) && (pbo->iSolidColor == -1))
  601. {
  602. if (pbo->pvRbrush == NULL)
  603. DISPDBG((1, " << With brush -- Not created"));
  604. else
  605. DISPDBG((1, " << With brush -- Created Ok"));
  606. }
  607. }
  608. #endif
  609. if (psoDst->dhsurf != NULL)
  610. {
  611. ppdev = (PDEV*) psoDst->dhpdev;
  612. pdsurfDst = (DSURF*) psoDst->dhsurf;
  613. psoDst = ppdev->psoPunt;
  614. psoDst->pvScan0 = pdsurfDst->poh->pvScan0;
  615. if (psoSrc != NULL)
  616. {
  617. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  618. if ((pdsurfSrc != NULL) &&
  619. (pdsurfSrc != pdsurfDst))
  620. {
  621. // If we're doing a BitBlt between different off-screen
  622. // surfaces, we have to be sure to give GDI different
  623. // surfaces, otherwise it may get confused when it has
  624. // to do screen-to-screen blts with a translate...
  625. pohSrc = pdsurfSrc->poh;
  626. pohDst = pdsurfDst->poh;
  627. psoSrc = ppdev->psoPunt2;
  628. psoSrc->pvScan0 = pohSrc->pvScan0;
  629. // Undo the source pointer adjustment we did earlier:
  630. ptlSrc.x = pptlSrc->x + (pohDst->x - pohSrc->x);
  631. ptlSrc.y = pptlSrc->y + (pohDst->y - pohSrc->y);
  632. pptlSrc = &ptlSrc;
  633. }
  634. }
  635. }
  636. else
  637. {
  638. ppdev = (PDEV*) psoSrc->dhpdev;
  639. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  640. psoSrc = ppdev->psoPunt;
  641. psoSrc->pvScan0 = pdsurfSrc->poh->pvScan0;
  642. }
  643. return(EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, prclDst, pptlSrc,
  644. pptlMsk, pbo, pptlBrush, rop4));
  645. }
  646. /******************************Public*Routine******************************\
  647. * BOOL DrvBitBlt
  648. *
  649. * Implements the workhorse routine of a display driver.
  650. *
  651. \**************************************************************************/
  652. BOOL DrvBitBlt(
  653. SURFOBJ* psoDst,
  654. SURFOBJ* psoSrc,
  655. SURFOBJ* psoMsk,
  656. CLIPOBJ* pco,
  657. XLATEOBJ* pxlo,
  658. RECTL* prclDst,
  659. POINTL* pptlSrc,
  660. POINTL* pptlMsk,
  661. BRUSHOBJ* pbo,
  662. POINTL* pptlBrush,
  663. ROP4 rop4)
  664. {
  665. PDEV* ppdev;
  666. DSURF* pdsurfDst;
  667. DSURF* pdsurfSrc;
  668. POINTL ptlSrc;
  669. BYTE jClip;
  670. OH* poh;
  671. BOOL bMore;
  672. CLIPENUM ce;
  673. LONG c;
  674. RECTL rcl;
  675. ULONG rop3;
  676. FNFILL* pfnFill;
  677. RBRUSH_COLOR rbc; // Realized brush or solid colour
  678. FNXFER* pfnXfer;
  679. ULONG iSrcBitmapFormat;
  680. ULONG iDir;
  681. jClip = (pco == NULL) ? DC_TRIVIAL : pco->iDComplexity;
  682. pdsurfDst = (DSURF*) psoDst->dhsurf; // May be NULL
  683. if (psoSrc == NULL)
  684. {
  685. ///////////////////////////////////////////////////////////////////
  686. // Fills
  687. ///////////////////////////////////////////////////////////////////
  688. // Fills are this function's "raison d'etre" (which is French
  689. // for "purple armadillo"), so we handle them as quickly as
  690. // possible:
  691. ASSERTDD(pdsurfDst != NULL,
  692. "Expect only device destinations when no source");
  693. if (pdsurfDst->dt == DT_SCREEN)
  694. {
  695. ppdev = (PDEV*) psoDst->dhpdev;
  696. poh = pdsurfDst->poh;
  697. ppdev->xOffset = poh->x;
  698. ppdev->yOffset = poh->y;
  699. // Make sure it doesn't involve a mask (i.e., it's really a
  700. // Rop3):
  701. if (((rop4 >> 8) & 0xff) == (rop4 & 0xff))
  702. {
  703. // Since 'psoSrc' is NULL, the rop3 had better not indicate
  704. // that we need a source.
  705. ASSERTDD((((rop4 >> 2) ^ (rop4)) & 0x33) == 0,
  706. "Need source but GDI gave us a NULL 'psoSrc'");
  707. Fill_It:
  708. pfnFill = ppdev->pfnFillSolid;
  709. if (gabRopNeedsPattern[(rop4 >> 2) & 0xf])
  710. {
  711. rbc.iSolidColor = pbo->iSolidColor;
  712. if (rbc.iSolidColor == -1)
  713. {
  714. // Try and realize the pattern brush; by doing
  715. // this call-back, GDI will eventually call us
  716. // again through DrvRealizeBrush:
  717. rbc.prb = pbo->pvRbrush;
  718. if (rbc.prb == NULL)
  719. {
  720. rbc.prb = BRUSHOBJ_pvGetRbrush(pbo);
  721. if (rbc.prb == NULL)
  722. {
  723. // If we couldn't realize the brush, punt
  724. // the call (it may have been a non 8x8
  725. // brush or something, which we can't be
  726. // bothered to handle, so let GDI do the
  727. // drawing):
  728. goto Punt_It;
  729. }
  730. }
  731. pfnFill = ppdev->pfnFillPat;
  732. }
  733. }
  734. // Note that these 2 'if's are more efficient than
  735. // a switch statement:
  736. if (jClip == DC_TRIVIAL)
  737. {
  738. pfnFill(ppdev, 1, prclDst, rop4, rbc, pptlBrush);
  739. goto All_Done;
  740. }
  741. else if (jClip == DC_RECT)
  742. {
  743. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  744. pfnFill(ppdev, 1, &rcl, rop4, rbc, pptlBrush);
  745. goto All_Done;
  746. }
  747. else
  748. {
  749. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_ANY, 0);
  750. do {
  751. bMore = CLIPOBJ_bEnum(pco, sizeof(ce), (ULONG*) &ce);
  752. c = cIntersect(prclDst, ce.arcl, ce.c);
  753. if (c != 0)
  754. pfnFill(ppdev, c, ce.arcl, rop4, rbc, pptlBrush);
  755. } while (bMore);
  756. goto All_Done;
  757. }
  758. }
  759. }
  760. }
  761. if ((psoSrc != NULL) && (psoSrc->dhsurf != NULL))
  762. {
  763. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  764. if (pdsurfSrc->dt == DT_DIB)
  765. {
  766. // Here we consider putting a DIB DFB back into off-screen
  767. // memory. If there's a translate, it's probably not worth
  768. // moving since we won't be able to use the hardware to do
  769. // the blt (a similar argument could be made for weird rops
  770. // and stuff that we'll only end up having GDI simulate, but
  771. // those should happen infrequently enough that I don't care).
  772. if ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL))
  773. {
  774. ppdev = (PDEV*) psoSrc->dhpdev;
  775. // See 'DrvCopyBits' for some more comments on how this
  776. // moving-it-back-into-off-screen-memory thing works:
  777. if (pdsurfSrc->iUniq == ppdev->iHeapUniq)
  778. {
  779. if (--pdsurfSrc->cBlt == 0)
  780. {
  781. if (bMoveDibToOffscreenDfbIfRoom(ppdev, pdsurfSrc))
  782. goto Continue_It;
  783. }
  784. }
  785. else
  786. {
  787. // Some space was freed up in off-screen memory,
  788. // so reset the counter for this DFB:
  789. pdsurfSrc->iUniq = ppdev->iHeapUniq;
  790. pdsurfSrc->cBlt = HEAP_COUNT_DOWN;
  791. }
  792. }
  793. psoSrc = pdsurfSrc->pso;
  794. // Handle the case where the source is a DIB DFB and the
  795. // destination is a regular bitmap:
  796. if (psoDst->dhsurf == NULL)
  797. goto EngBitBlt_It;
  798. }
  799. }
  800. Continue_It:
  801. if (pdsurfDst != NULL)
  802. {
  803. if (pdsurfDst->dt == DT_DIB)
  804. {
  805. psoDst = pdsurfDst->pso;
  806. // If the destination is a DIB, we can only handle this
  807. // call if the source is not a DIB:
  808. if ((psoSrc == NULL) || (psoSrc->dhsurf == NULL))
  809. goto EngBitBlt_It;
  810. }
  811. }
  812. // At this point, we know that either the source or the destination is
  813. // not a DIB. Check for a DFB to screen, DFB to DFB, or screen to DFB
  814. // case:
  815. if ((psoSrc != NULL) &&
  816. (psoDst->dhsurf != NULL) &&
  817. (psoSrc->dhsurf != NULL))
  818. {
  819. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  820. pdsurfDst = (DSURF*) psoDst->dhsurf;
  821. ASSERTDD(pdsurfSrc->dt == DT_SCREEN, "Expected screen source");
  822. ASSERTDD(pdsurfDst->dt == DT_SCREEN, "Expected screen destination");
  823. ptlSrc.x = pptlSrc->x - (pdsurfDst->poh->x - pdsurfSrc->poh->x);
  824. ptlSrc.y = pptlSrc->y - (pdsurfDst->poh->y - pdsurfSrc->poh->y);
  825. pptlSrc = &ptlSrc;
  826. }
  827. if (psoDst->dhsurf != NULL)
  828. {
  829. pdsurfDst = (DSURF*) psoDst->dhsurf;
  830. ppdev = (PDEV*) psoDst->dhpdev;
  831. ppdev->xOffset = pdsurfDst->poh->x;
  832. ppdev->yOffset = pdsurfDst->poh->y;
  833. }
  834. else
  835. {
  836. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  837. ppdev = (PDEV*) psoSrc->dhpdev;
  838. ppdev->xOffset = pdsurfSrc->poh->x;
  839. ppdev->yOffset = pdsurfSrc->poh->y;
  840. }
  841. // We bail here if we're running in a high-colour mode on the P9000:
  842. if (ppdev->flStat & STAT_UNACCELERATED)
  843. goto EngBitBlt_It;
  844. if (((rop4 >> 8) & 0xff) == (rop4 & 0xff))
  845. {
  846. // Since we've already handled the cases where the ROP4 is really
  847. // a ROP3 and no source is required, we can assert...
  848. ASSERTDD((psoSrc != NULL) && (pptlSrc != NULL),
  849. "Expected no-source case to already have been handled");
  850. ///////////////////////////////////////////////////////////////////
  851. // Bitmap transfers
  852. ///////////////////////////////////////////////////////////////////
  853. // Since the foreground and background ROPs are the same, we
  854. // don't have to worry about no stinking masks (it's a simple
  855. // Rop3).
  856. rop3 = (rop4 & 0xff); // Make it into a Rop3 (we keep the rop4
  857. // around in case we decide to punt)
  858. if (psoDst->dhsurf != NULL)
  859. {
  860. // The destination is the screen:
  861. if ((rop3 >> 4) == (rop3 & 0xf))
  862. {
  863. // The ROP3 doesn't require a pattern:
  864. if (psoSrc->dhsurf == NULL)
  865. {
  866. //////////////////////////////////////////////////
  867. // DIB-to-screen blt
  868. // This section handles 1bpp, 4bpp and 8bpp sources.
  869. iSrcBitmapFormat = psoSrc->iBitmapFormat;
  870. if (iSrcBitmapFormat == BMF_1BPP)
  871. {
  872. pfnXfer = ppdev->pfnXfer1bpp;
  873. goto Xfer_It;
  874. }
  875. else if ((iSrcBitmapFormat == ppdev->iBitmapFormat) &&
  876. ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL)))
  877. {
  878. pfnXfer = ppdev->pfnXferNative;
  879. goto Xfer_It;
  880. }
  881. else if ((iSrcBitmapFormat == BMF_4BPP) &&
  882. (ppdev->iBitmapFormat == BMF_8BPP))
  883. {
  884. pfnXfer = ppdev->pfnXfer4bpp;
  885. goto Xfer_It;
  886. }
  887. }
  888. else // psoSrc->dhsurf != NULL
  889. {
  890. if ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL))
  891. {
  892. //////////////////////////////////////////////////
  893. // Screen-to-screen blt with no translate
  894. if (jClip == DC_TRIVIAL)
  895. {
  896. (ppdev->pfnCopyBlt)(ppdev, 1, prclDst, rop4,
  897. pptlSrc, prclDst);
  898. goto All_Done;
  899. }
  900. else if (jClip == DC_RECT)
  901. {
  902. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  903. {
  904. (ppdev->pfnCopyBlt)(ppdev, 1, &rcl, rop4,
  905. pptlSrc, prclDst);
  906. }
  907. goto All_Done;
  908. }
  909. else
  910. {
  911. // Don't forget that we'll have to draw the
  912. // rectangles in the correct direction:
  913. if (pptlSrc->y >= prclDst->top)
  914. {
  915. if (pptlSrc->x >= prclDst->left)
  916. iDir = CD_RIGHTDOWN;
  917. else
  918. iDir = CD_LEFTDOWN;
  919. }
  920. else
  921. {
  922. if (pptlSrc->x >= prclDst->left)
  923. iDir = CD_RIGHTUP;
  924. else
  925. iDir = CD_LEFTUP;
  926. }
  927. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES,
  928. iDir, 0);
  929. do {
  930. bMore = CLIPOBJ_bEnum(pco, sizeof(ce),
  931. (ULONG*) &ce);
  932. c = cIntersect(prclDst, ce.arcl, ce.c);
  933. if (c != 0)
  934. {
  935. (ppdev->pfnCopyBlt)(ppdev, c, ce.arcl,
  936. rop4, pptlSrc, prclDst);
  937. }
  938. } while (bMore);
  939. goto All_Done;
  940. }
  941. }
  942. }
  943. }
  944. }
  945. else
  946. {
  947. #if defined(i386)
  948. {
  949. // We special case screen to monochrome blts because they
  950. // happen fairly often. We only handle SRCCOPY rops and
  951. // monochrome destinations (to handle a true 1bpp DIB
  952. // destination, we would have to do near-colour searches
  953. // on every colour; as it is, the foreground colour gets
  954. // mapped to '1', and everything else gets mapped to '0'):
  955. if ((psoDst->iBitmapFormat == BMF_1BPP) &&
  956. (rop3 == 0xcc) &&
  957. (pxlo->flXlate & XO_TO_MONO) &&
  958. (ppdev->iBitmapFormat != BMF_24BPP))
  959. {
  960. pfnXfer = vXferScreenTo1bpp;
  961. psoSrc = psoDst; // A misnomer, I admit
  962. goto Xfer_It;
  963. }
  964. }
  965. #endif // i386
  966. }
  967. }
  968. else if ((psoMsk == NULL) && (rop4 == 0xaacc))
  969. {
  970. // The only time GDI will ask us to do a true rop4 using the brush
  971. // mask is when the brush is 1bpp, and the background rop is AA
  972. // (meaning it's a NOP):
  973. goto Fill_It;
  974. }
  975. // Just fall through to Punt_It...
  976. Punt_It:
  977. return(bPuntBlt(psoDst,
  978. psoSrc,
  979. psoMsk,
  980. pco,
  981. pxlo,
  982. prclDst,
  983. pptlSrc,
  984. pptlMsk,
  985. pbo,
  986. pptlBrush,
  987. rop4));
  988. //////////////////////////////////////////////////////////////////////
  989. // Common bitmap transfer
  990. Xfer_It:
  991. if (jClip == DC_TRIVIAL)
  992. {
  993. pfnXfer(ppdev, 1, prclDst, rop4, psoSrc, pptlSrc, prclDst, pxlo);
  994. goto All_Done;
  995. }
  996. else if (jClip == DC_RECT)
  997. {
  998. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  999. pfnXfer(ppdev, 1, &rcl, rop4, psoSrc, pptlSrc, prclDst, pxlo);
  1000. goto All_Done;
  1001. }
  1002. else
  1003. {
  1004. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES,
  1005. CD_ANY, 0);
  1006. do {
  1007. bMore = CLIPOBJ_bEnum(pco, sizeof(ce),
  1008. (ULONG*) &ce);
  1009. c = cIntersect(prclDst, ce.arcl, ce.c);
  1010. if (c != 0)
  1011. {
  1012. pfnXfer(ppdev, c, ce.arcl, rop4, psoSrc,
  1013. pptlSrc, prclDst, pxlo);
  1014. }
  1015. } while (bMore);
  1016. goto All_Done;
  1017. }
  1018. ////////////////////////////////////////////////////////////////////////
  1019. // Common DIB blt
  1020. EngBitBlt_It:
  1021. // Our driver doesn't handle any blt's between two DIBs. Normally
  1022. // a driver doesn't have to worry about this, but we do because
  1023. // we have DFBs that may get moved from off-screen memory to a DIB,
  1024. // where we have GDI do all the drawing. GDI does DIB drawing at
  1025. // a reasonable speed (unless one of the surfaces is a device-
  1026. // managed surface...)
  1027. //
  1028. // If either the source or destination surface in an EngBitBlt
  1029. // call-back is a device-managed surface (meaning it's not a DIB
  1030. // that GDI can draw with), GDI will automatically allocate memory
  1031. // and call the driver's DrvCopyBits routine to create a DIB copy
  1032. // that it can use. So this means that this could handle all 'punts',
  1033. // and we could conceivably get rid of bPuntBlt. But this would have
  1034. // a bad performance impact because of the extra memory allocations
  1035. // and bitmap copies -- you really don't want to do this unless you
  1036. // have to (or your surface was created such that GDI can draw
  1037. // directly onto it) -- I've been burned by this because it's not
  1038. // obvious that the performance impact is so bad.
  1039. //
  1040. // That being said, we only call EngBitBlt when all the surfaces
  1041. // are DIBs:
  1042. return(EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, prclDst,
  1043. pptlSrc, pptlMsk, pbo, pptlBrush, rop4));
  1044. All_Done:
  1045. return(TRUE);
  1046. }
  1047. /******************************Public*Routine******************************\
  1048. * BOOL DrvCopyBits
  1049. *
  1050. * Do fast bitmap copies.
  1051. *
  1052. * Note that GDI will (usually) automatically adjust the blt extents to
  1053. * adjust for any rectangular clipping, so we'll rarely see DC_RECT
  1054. * clipping in this routine (and as such, we don't bother special casing
  1055. * it).
  1056. *
  1057. * I'm not sure if the performance benefit from this routine is actually
  1058. * worth the increase in code size, since SRCCOPY BitBlts are hardly the
  1059. * most common drawing operation we'll get. But what the heck.
  1060. *
  1061. \**************************************************************************/
  1062. BOOL DrvCopyBits(
  1063. SURFOBJ* psoDst,
  1064. SURFOBJ* psoSrc,
  1065. CLIPOBJ* pco,
  1066. XLATEOBJ* pxlo,
  1067. RECTL* prclDst,
  1068. POINTL* pptlSrc)
  1069. {
  1070. PDEV* ppdev;
  1071. DSURF* pdsurfSrc;
  1072. DSURF* pdsurfDst;
  1073. POINTL ptl;
  1074. OH* pohSrc;
  1075. OH* pohDst;
  1076. // DrvCopyBits is a fast-path for SRCCOPY blts. But it can still be
  1077. // pretty complicated: there can be translates, clipping, RLEs,
  1078. // bitmaps that aren't the same format as the screen, plus
  1079. // screen-to-screen, DIB-to-screen or screen-to-DIB operations,
  1080. // not to mention DFBs (device format bitmaps).
  1081. //
  1082. // Rather than making this routine almost as big as DrvBitBlt, I'll
  1083. // handle here only the speed-critical cases, and punt the rest to
  1084. // our DrvBitBlt routine.
  1085. //
  1086. // We'll try to handle anything that doesn't involve clipping:
  1087. if (((pco == NULL) || (pco->iDComplexity == DC_TRIVIAL)) &&
  1088. ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL)))
  1089. {
  1090. if (psoDst->dhsurf != NULL)
  1091. {
  1092. // We know the destination is either a DFB or the screen:
  1093. ppdev = (PDEV*) psoDst->dhpdev;
  1094. pdsurfDst = (DSURF*) psoDst->dhsurf;
  1095. // See if the source is a plain DIB:
  1096. if (psoSrc->dhsurf != NULL)
  1097. {
  1098. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1099. // Make sure the destination is really the screen or an
  1100. // off-screen DFB (i.e., not a DFB that we've converted
  1101. // to a DIB):
  1102. if (pdsurfDst->dt == DT_SCREEN)
  1103. {
  1104. ASSERTDD(psoSrc->dhsurf != NULL, "Can't be a DIB");
  1105. if (pdsurfSrc->dt == DT_SCREEN)
  1106. {
  1107. Screen_To_Screen:
  1108. //////////////////////////////////////////////////////
  1109. // Screen-to-screen
  1110. ASSERTDD((psoSrc->dhsurf != NULL) &&
  1111. (pdsurfSrc->dt == DT_SCREEN) &&
  1112. (psoDst->dhsurf != NULL) &&
  1113. (pdsurfDst->dt == DT_SCREEN),
  1114. "Should be a screen-to-screen case");
  1115. // pfnCopyBlt takes relative coordinates (relative
  1116. // to the destination surface, that is), so we have
  1117. // to change the start point to be relative to the
  1118. // destination surface too:
  1119. pohSrc = pdsurfSrc->poh;
  1120. pohDst = pdsurfDst->poh;
  1121. ptl.x = pptlSrc->x - (pohDst->x - pohSrc->x);
  1122. ptl.y = pptlSrc->y - (pohDst->y - pohSrc->y);
  1123. ppdev->xOffset = pohDst->x;
  1124. ppdev->yOffset = pohDst->y;
  1125. (ppdev->pfnCopyBlt)(ppdev, 1, prclDst, 0xCCCC, &ptl,
  1126. prclDst);
  1127. return(TRUE);
  1128. }
  1129. else // (pdsurfSrc->dt != DT_SCREEN)
  1130. {
  1131. // Ah ha, the source is a DFB that's really a DIB.
  1132. ASSERTDD(psoDst->dhsurf != NULL,
  1133. "Destination can't be a DIB here");
  1134. /////////////////////////////////////////////////////
  1135. // Put It Back Into Off-screen?
  1136. //
  1137. // We take this opportunity to decide if we want to
  1138. // put the DIB back into off-screen memory. This is
  1139. // a pretty good place to do it because we have to
  1140. // copy the bits to some portion of the screen,
  1141. // anyway. So we would incur only an extra screen-to-
  1142. // screen blt at this time, much of which will be
  1143. // over-lapped with the CPU.
  1144. //
  1145. // The simple approach we have taken is to move a DIB
  1146. // back into off-screen memory only if there's already
  1147. // room -- we won't throw stuff out to make space
  1148. // (because it's tough to know what ones to throw out,
  1149. // and it's easy to get into thrashing scenarios).
  1150. //
  1151. // Because it takes some time to see if there's room
  1152. // in off-screen memory, we only check one in
  1153. // HEAP_COUNT_DOWN times if there's room. To bias
  1154. // in favour of bitmaps that are often blt, the
  1155. // counters are reset every time any space is freed
  1156. // up in off-screen memory. We also don't bother
  1157. // checking if no space has been freed since the
  1158. // last time we checked for this DIB.
  1159. if (pdsurfSrc->iUniq == ppdev->iHeapUniq)
  1160. {
  1161. if (--pdsurfSrc->cBlt == 0)
  1162. {
  1163. if (bMoveDibToOffscreenDfbIfRoom(ppdev,
  1164. pdsurfSrc))
  1165. goto Screen_To_Screen;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. // Some space was freed up in off-screen memory,
  1171. // so reset the counter for this DFB:
  1172. pdsurfSrc->iUniq = ppdev->iHeapUniq;
  1173. pdsurfSrc->cBlt = HEAP_COUNT_DOWN;
  1174. }
  1175. // Since the destination is definitely the screen,
  1176. // we don't have to worry about creating a DIB to
  1177. // DIB copy case (for which we would have to call
  1178. // EngCopyBits):
  1179. psoSrc = pdsurfSrc->pso;
  1180. goto DIB_To_Screen;
  1181. }
  1182. }
  1183. else // (pdsurfDst->dt != DT_SCREEN)
  1184. {
  1185. // Because the source is not a DIB, we don't have to
  1186. // worry about creating a DIB to DIB case here (although
  1187. // we'll have to check later to see if the source is
  1188. // really a DIB that's masquerading as a DFB...)
  1189. ASSERTDD(psoSrc->dhsurf != NULL,
  1190. "Source can't be a DIB here");
  1191. psoDst = pdsurfDst->pso;
  1192. goto Screen_To_DIB;
  1193. }
  1194. }
  1195. else if (psoSrc->iBitmapFormat == ppdev->iBitmapFormat)
  1196. {
  1197. // Make sure the destination is really the screen:
  1198. if (pdsurfDst->dt == DT_SCREEN)
  1199. {
  1200. DIB_To_Screen:
  1201. //////////////////////////////////////////////////////
  1202. // DIB-to-screen
  1203. ASSERTDD((psoDst->dhsurf != NULL) &&
  1204. (pdsurfDst->dt == DT_SCREEN) &&
  1205. (psoSrc->dhsurf == NULL) &&
  1206. (psoSrc->iBitmapFormat == ppdev->iBitmapFormat),
  1207. "Should be a DIB-to-screen case");
  1208. pohDst = pdsurfDst->poh;
  1209. ppdev->xOffset = pohDst->x;
  1210. ppdev->yOffset = pohDst->y;
  1211. ppdev->pfnXferNative(ppdev, 1, prclDst, 0xCCCC, psoSrc,
  1212. pptlSrc, prclDst, NULL);
  1213. return(TRUE);
  1214. }
  1215. }
  1216. }
  1217. else // (psoDst->dhsurf == NULL)
  1218. {
  1219. Screen_To_DIB:
  1220. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1221. ppdev = (PDEV*) psoSrc->dhpdev;
  1222. if (psoDst->iBitmapFormat == ppdev->iBitmapFormat)
  1223. {
  1224. if (pdsurfSrc->dt == DT_SCREEN)
  1225. {
  1226. //////////////////////////////////////////////////////
  1227. // Screen-to-DIB
  1228. ASSERTDD((psoSrc->dhsurf != NULL) &&
  1229. (pdsurfSrc->dt == DT_SCREEN) &&
  1230. (psoDst->dhsurf == NULL) &&
  1231. (psoDst->iBitmapFormat == ppdev->iBitmapFormat),
  1232. "Should be a screen-to-DIB case");
  1233. // vGetBits takes absolute screen coordinates, so we have
  1234. // to muck with the source point:
  1235. pohSrc = pdsurfSrc->poh;
  1236. ptl.x = pptlSrc->x + pohSrc->x;
  1237. ptl.y = pptlSrc->y + pohSrc->y;
  1238. vGetBits(ppdev, psoDst, prclDst, &ptl);
  1239. return(TRUE);
  1240. }
  1241. else
  1242. {
  1243. // The source is a DFB that's really a DIB. Since we
  1244. // know that the destination is a DIB, we've got a DIB
  1245. // to DIB operation, and should call EngCopyBits:
  1246. psoSrc = pdsurfSrc->pso;
  1247. goto EngCopyBits_It;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. // We can't call DrvBitBlt if we've accidentally converted both
  1253. // surfaces to DIBs, because it isn't equipped to handle it:
  1254. ASSERTDD((psoSrc->dhsurf != NULL) ||
  1255. (psoDst->dhsurf != NULL),
  1256. "Accidentally converted both surfaces to DIBs");
  1257. /////////////////////////////////////////////////////////////////
  1258. // A DrvCopyBits is after all just a simplified DrvBitBlt:
  1259. return(DrvBitBlt(psoDst, psoSrc, NULL, pco, pxlo, prclDst, pptlSrc, NULL,
  1260. NULL, NULL, 0x0000CCCC));
  1261. EngCopyBits_It:
  1262. ASSERTDD((psoDst->dhsurf == NULL) &&
  1263. (psoSrc->dhsurf == NULL),
  1264. "Both surfaces should be DIBs to call EngCopyBits");
  1265. return(EngCopyBits(psoDst, psoSrc, pco, pxlo, prclDst, pptlSrc));
  1266. }