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.

1827 lines
63 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 || !GDI_BANKING
  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. #if DBG
  550. {
  551. //////////////////////////////////////////////////////////////////////
  552. // Diagnostics
  553. //
  554. // Since calling the engine to do any drawing can be rather painful,
  555. // particularly when the source is an off-screen DFB (since GDI will
  556. // have to allocate a DIB and call us to make a temporary copy before
  557. // it can even start drawing), we'll try to avoid it as much as
  558. // possible.
  559. //
  560. // Here we simply spew out information describing the blt whenever
  561. // this routine gets called (checked builds only, of course):
  562. ULONG ulClip;
  563. PDEV* ppdev;
  564. ULONG ulAvec;
  565. if (psoDst->dhpdev != NULL)
  566. ppdev = (PDEV*) psoDst->dhpdev;
  567. else
  568. ppdev = (PDEV*) psoSrc->dhpdev;
  569. ulClip = (pco == NULL) ? DC_TRIVIAL : pco->iDComplexity;
  570. DISPDBG((3, ">> Punt << Dst format: %li Dst type: %li Clip: %li Rop: %lx",
  571. psoDst->iBitmapFormat, psoDst->iType, ulClip, rop4));
  572. if (psoSrc != NULL)
  573. DISPDBG((3, " << Src format: %li Src type: %li",
  574. psoSrc->iBitmapFormat, psoSrc->iType));
  575. if ((pxlo != NULL) && !(pxlo->flXlate & XO_TRIVIAL) && (psoSrc != NULL))
  576. {
  577. if (((psoSrc->dhsurf == NULL) &&
  578. (psoSrc->iBitmapFormat != ppdev->iBitmapFormat)) ||
  579. ((psoDst->dhsurf == NULL) &&
  580. (psoDst->iBitmapFormat != ppdev->iBitmapFormat)))
  581. {
  582. // Don't bother printing the 'xlate' message when the source
  583. // is a different bitmap format from the destination -- in
  584. // those cases we know there always has to be a translate.
  585. }
  586. else
  587. {
  588. DISPDBG((3, " << With xlate"));
  589. }
  590. }
  591. // The high 2 bytes of rop4 is not guaranteed to be zero. So in order
  592. // to get the low 8 bits as index, we have to &ffff before do >>
  593. ulAvec = gajRop3[rop4 & 0xff] | gajRop3[(rop4 & 0xffff) >> 8];
  594. if ((ulAvec & AVEC_NEED_PATTERN) && (pbo->iSolidColor == -1))
  595. {
  596. if (pbo->pvRbrush == NULL)
  597. DISPDBG((3, " << With brush -- Not created"));
  598. else
  599. DISPDBG((3, " << With brush -- Created Ok"));
  600. }
  601. }
  602. #endif
  603. #if GDI_BANKING
  604. {
  605. //////////////////////////////////////////////////////////////////////
  606. // Banked Framebuffer bPuntBlt
  607. //
  608. // This section of code handles a PuntBlt when GDI can directly draw
  609. // on the framebuffer, but the drawing has to be done in banks:
  610. BANK bnk;
  611. PDEV* ppdev;
  612. BOOL b;
  613. HSURF hsurfTmp;
  614. SURFOBJ* psoTmp;
  615. SIZEL sizl;
  616. POINTL ptlSrc;
  617. RECTL rclTmp;
  618. RECTL rclDst;
  619. b = FALSE; // Fore error cases, assume we'll fail
  620. // We copy the original destination rectangle, and use that in every
  621. // GDI call-back instead of the original because sometimes GDI is
  622. // sneaky and points 'prclDst' to '&pco->rclBounds'. Because we
  623. // modify 'rclBounds', that would affect 'prclDst', which we don't
  624. // want to happen:
  625. rclDst = *prclDst;
  626. if ((psoSrc == NULL) || (psoSrc->dhsurf == NULL))
  627. {
  628. ASSERTDD(psoDst->dhsurf != NULL,
  629. "Dest should be the screen when given a DIB source");
  630. // Do a memory-to-screen blt:
  631. ppdev = (PDEV*) psoDst->dhpdev;
  632. vBankStart(ppdev, &rclDst, pco, &bnk);
  633. b = TRUE;
  634. do {
  635. b &= EngBitBlt(bnk.pso, psoSrc, psoMsk, bnk.pco, pxlo,
  636. &rclDst, pptlSrc, pptlMsk, pbo, pptlBrush,
  637. rop4);
  638. } while (bBankEnum(&bnk));
  639. }
  640. else
  641. {
  642. // The screen is the source (it may be the destination too...)
  643. ppdev = (PDEV*) psoSrc->dhpdev;
  644. ptlSrc.x = pptlSrc->x + ppdev->xOffset;
  645. ptlSrc.y = pptlSrc->y + ppdev->yOffset;
  646. if ((pco != NULL) && (pco->iDComplexity != DC_TRIVIAL))
  647. {
  648. // We have to intersect the destination rectangle with
  649. // the clip bounds if there is one (consider the case
  650. // where the app asked to blt a really, really big
  651. // rectangle from the screen -- prclDst would be really,
  652. // really big but pco->rclBounds would be the actual
  653. // area of interest):
  654. rclDst.left = max(rclDst.left, pco->rclBounds.left);
  655. rclDst.top = max(rclDst.top, pco->rclBounds.top);
  656. rclDst.right = min(rclDst.right, pco->rclBounds.right);
  657. rclDst.bottom = min(rclDst.bottom, pco->rclBounds.bottom);
  658. // Correspondingly, we have to offset the source point:
  659. ptlSrc.x += (rclDst.left - prclDst->left);
  660. ptlSrc.y += (rclDst.top - prclDst->top);
  661. }
  662. // We're now either going to do a screen-to-screen or screen-to-DIB
  663. // blt. In either case, we're going to create a temporary copy of
  664. // the source. (Why do we do this when GDI could do it for us?
  665. // GDI would create a temporary copy of the DIB for every bank
  666. // call-back!)
  667. sizl.cx = rclDst.right - rclDst.left;
  668. sizl.cy = rclDst.bottom - rclDst.top;
  669. // Don't forget to convert from relative to absolute coordinates
  670. // on the source! (vBankStart takes care of that for the
  671. // destination.)
  672. rclTmp.right = sizl.cx;
  673. rclTmp.bottom = sizl.cy;
  674. rclTmp.left = 0;
  675. rclTmp.top = 0;
  676. // GDI does guarantee us that the blt extents have already been
  677. // clipped to the surface boundaries (we don't have to worry
  678. // here about trying to read where there isn't video memory).
  679. // Let's just assert to make sure:
  680. ASSERTDD((ptlSrc.x >= 0) &&
  681. (ptlSrc.y >= 0) &&
  682. (ptlSrc.x + sizl.cx <= ppdev->cxMemory) &&
  683. (ptlSrc.y + sizl.cy <= ppdev->cyMemory),
  684. "Source rectangle out of bounds!");
  685. hsurfTmp = (HSURF) EngCreateBitmap(sizl,
  686. 0, // Let GDI choose ulWidth
  687. ppdev->iBitmapFormat,
  688. 0, // Don't need any options
  689. NULL);// Let GDI allocate
  690. if (hsurfTmp != 0)
  691. {
  692. psoTmp = EngLockSurface(hsurfTmp);
  693. if (psoTmp != NULL)
  694. {
  695. vGetBits(ppdev, psoTmp, &rclTmp, &ptlSrc);
  696. if (psoDst->dhsurf == NULL)
  697. {
  698. // It was a Screen-to-DIB blt; now it's a DIB-to-DIB
  699. // blt. Note that the source point is (0, 0) in our
  700. // temporary surface:
  701. b = EngBitBlt(psoDst, psoTmp, psoMsk, pco, pxlo,
  702. &rclDst, (POINTL*) &rclTmp, pptlMsk,
  703. pbo, pptlBrush, rop4);
  704. }
  705. else
  706. {
  707. // It was a Screen-to-Screen blt; now it's a DIB-to-
  708. // screen blt. Note that the source point is (0, 0)
  709. // in our temporary surface:
  710. vBankStart(ppdev, &rclDst, pco, &bnk);
  711. b = TRUE;
  712. do {
  713. b &= EngBitBlt(bnk.pso, psoTmp, psoMsk, bnk.pco,
  714. pxlo, &rclDst, (POINTL*) &rclTmp,
  715. pptlMsk, pbo, pptlBrush, rop4);
  716. } while (bBankEnum(&bnk));
  717. }
  718. EngUnlockSurface(psoTmp);
  719. }
  720. EngDeleteSurface(hsurfTmp);
  721. } // if (hsurfTmp != 0)
  722. else
  723. b = FALSE;
  724. }
  725. return(b);
  726. }
  727. #else
  728. {
  729. //////////////////////////////////////////////////////////////////////
  730. // Really Slow bPuntBlt
  731. //
  732. // Here we handle a PuntBlt when GDI can't draw directly on the
  733. // framebuffer (as on the Alpha, which can't do it because of its
  734. // 32 bit bus). If you thought the banked version was slow, just
  735. // look at this one. Guaranteed, there will be at least one bitmap
  736. // allocation and extra copy involved; there could be two if it's a
  737. // screen-to-screen operation.
  738. PDEV* ppdev;
  739. POINTL ptlSrc;
  740. RECTL rclDst;
  741. SIZEL sizl;
  742. ULONG ulAvec;
  743. BOOL bSrcIsScreen;
  744. HSURF hsurfSrc;
  745. RECTL rclTmp;
  746. BOOL b;
  747. LONG lDelta;
  748. BYTE* pjBits;
  749. BYTE* pjScan0;
  750. HSURF hsurfDst;
  751. RECTL rclScreen;
  752. b = FALSE; // Fore error cases, assume we'll fail
  753. rclDst = *prclDst;
  754. if (pptlSrc != NULL)
  755. ptlSrc = *pptlSrc;
  756. if ((pco != NULL) && (pco->iDComplexity != DC_TRIVIAL))
  757. {
  758. // We have to intersect the destination rectangle with
  759. // the clip bounds if there is one (consider the case
  760. // where the app asked to blt a really, really big
  761. // rectangle from the screen -- prclDst would be really,
  762. // really big but pco->rclBounds would be the actual
  763. // area of interest):
  764. rclDst.left = max(rclDst.left, pco->rclBounds.left);
  765. rclDst.top = max(rclDst.top, pco->rclBounds.top);
  766. rclDst.right = min(rclDst.right, pco->rclBounds.right);
  767. rclDst.bottom = min(rclDst.bottom, pco->rclBounds.bottom);
  768. ptlSrc.x += (rclDst.left - prclDst->left);
  769. ptlSrc.y += (rclDst.top - prclDst->top);
  770. }
  771. sizl.cx = rclDst.right - rclDst.left;
  772. sizl.cy = rclDst.bottom - rclDst.top;
  773. // The high 2 bytes of rop4 is not guaranteed to be zero. So in order
  774. // to get the low 8 bits as index, we have to &ffff before do >>
  775. ulAvec = gajRop3[rop4 & 0xff] | gajRop3[(rop4 & 0xffff) >> 8];
  776. bSrcIsScreen = ((ulAvec & AVEC_NEED_SOURCE) &&
  777. (psoSrc->dhsurf != NULL));
  778. if (bSrcIsScreen)
  779. {
  780. ppdev = (PDEV*) psoSrc->dhpdev;
  781. // We need to create a copy of the source rectangle:
  782. hsurfSrc = (HSURF) EngCreateBitmap(sizl, 0, ppdev->iBitmapFormat,
  783. 0, NULL);
  784. if (hsurfSrc == 0)
  785. goto Error_0;
  786. psoSrc = EngLockSurface(hsurfSrc);
  787. if (psoSrc == NULL)
  788. goto Error_1;
  789. rclTmp.left = 0;
  790. rclTmp.top = 0;
  791. rclTmp.right = sizl.cx;
  792. rclTmp.bottom = sizl.cy;
  793. // vGetBits takes absolute coordinates for the source point:
  794. ptlSrc.x += ppdev->xOffset;
  795. ptlSrc.y += ppdev->yOffset;
  796. vGetBits(ppdev, psoSrc, &rclTmp, &ptlSrc);
  797. // The source will now come from (0, 0) of our temporary source
  798. // surface:
  799. ptlSrc.x = 0;
  800. ptlSrc.y = 0;
  801. }
  802. if (psoDst->dhsurf == NULL)
  803. {
  804. b = EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, &rclDst, &ptlSrc,
  805. pptlMsk, pbo, pptlBrush, rop4);
  806. }
  807. else
  808. {
  809. ppdev = (PDEV*) psoDst->dhpdev;
  810. // We need to create a temporary work buffer. We have to do
  811. // some fudging with the offsets so that the upper-left corner
  812. // of the (relative coordinates) clip object bounds passed to
  813. // GDI will be transformed to the upper-left corner of our
  814. // temporary bitmap.
  815. // The alignment doesn't have to be as tight as this at 16bpp
  816. // and 32bpp, but it won't hurt:
  817. lDelta = (((rclDst.right + 3) & ~3L) - (rclDst.left & ~3L))
  818. << ppdev->cPelSize;
  819. // We're actually only allocating a bitmap that is 'sizl.cx' x
  820. // 'sizl.cy' in size:
  821. pjBits = EngAllocMem(0, lDelta * sizl.cy, ALLOC_TAG);
  822. if (pjBits == NULL)
  823. goto Error_2;
  824. // We now adjust the surface's 'pvScan0' so that when GDI thinks
  825. // it's writing to pixel (rclDst.top, rclDst.left), it will
  826. // actually be writing to the upper-left pixel of our temporary
  827. // bitmap:
  828. pjScan0 = pjBits - (rclDst.top * lDelta)
  829. - ((rclDst.left & ~3L) << ppdev->cPelSize);
  830. ASSERTDD((((ULONG_PTR) pjScan0) & 3) == 0,
  831. "pvScan0 must be dword aligned!");
  832. // The checked build of GDI sometimes checks on blts that
  833. // prclDst->right <= pso->sizl.cx, so we lie to it about
  834. // the size of our bitmap:
  835. sizl.cx = rclDst.right;
  836. sizl.cy = rclDst.bottom;
  837. hsurfDst = (HSURF) EngCreateBitmap(
  838. sizl, // Bitmap covers rectangle
  839. lDelta, // Use this delta
  840. ppdev->iBitmapFormat, // Same colour depth
  841. BMF_TOPDOWN, // Must have a positive delta
  842. pjScan0); // Where (0, 0) would be
  843. if ((hsurfDst == 0) ||
  844. (!EngAssociateSurface(hsurfDst, ppdev->hdevEng, 0)))
  845. goto Error_3;
  846. psoDst = EngLockSurface(hsurfDst);
  847. if (psoDst == NULL)
  848. goto Error_4;
  849. // Make sure that the rectangle we Get/Put from/to the screen
  850. // is in absolute coordinates:
  851. rclScreen.left = rclDst.left + ppdev->xOffset;
  852. rclScreen.right = rclDst.right + ppdev->xOffset;
  853. rclScreen.top = rclDst.top + ppdev->yOffset;
  854. rclScreen.bottom = rclDst.bottom + ppdev->yOffset;
  855. // It would be nice to get a copy of the destination rectangle
  856. // only when the ROP involves the destination (or when the source
  857. // is an RLE), but we can't do that. If the brush is truly NULL,
  858. // GDI will immediately return TRUE from EngBitBlt, without
  859. // modifying the temporary bitmap -- and we would proceed to
  860. // copy the uninitialized temporary bitmap back to the screen.
  861. vGetBits(ppdev, psoDst, &rclDst, (POINTL*) &rclScreen);
  862. b = EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, &rclDst, &ptlSrc,
  863. pptlMsk, pbo, pptlBrush, rop4);
  864. vPutBits(ppdev, psoDst, &rclScreen, (POINTL*) &rclDst);
  865. EngUnlockSurface(psoDst);
  866. Error_4:
  867. EngDeleteSurface(hsurfDst);
  868. Error_3:
  869. EngFreeMem(pjBits);
  870. }
  871. Error_2:
  872. if (bSrcIsScreen)
  873. {
  874. EngUnlockSurface(psoSrc);
  875. Error_1:
  876. EngDeleteSurface(hsurfSrc);
  877. }
  878. Error_0:
  879. return(b);
  880. }
  881. #endif
  882. }
  883. /******************************Public*Routine******************************\
  884. * BOOL DrvBitBlt
  885. *
  886. * Implements the workhorse routine of a display driver.
  887. *
  888. \**************************************************************************/
  889. BOOL DrvBitBlt(
  890. SURFOBJ* psoDst,
  891. SURFOBJ* psoSrc,
  892. SURFOBJ* psoMsk,
  893. CLIPOBJ* pco,
  894. XLATEOBJ* pxlo,
  895. RECTL* prclDst,
  896. POINTL* pptlSrc,
  897. POINTL* pptlMsk,
  898. BRUSHOBJ* pbo,
  899. POINTL* pptlBrush,
  900. ROP4 rop4)
  901. {
  902. PDEV* ppdev;
  903. DSURF* pdsurfDst;
  904. DSURF* pdsurfSrc;
  905. POINTL ptlSrc;
  906. BYTE jClip;
  907. OH* poh;
  908. BOOL bMore;
  909. CLIPENUM ce;
  910. LONG c;
  911. RECTL rcl;
  912. ULONG rop3;
  913. FNFILL* pfnFill;
  914. RBRUSH_COLOR rbc; // Realized brush or solid colour
  915. FNXFER* pfnXfer;
  916. ULONG iSrcBitmapFormat;
  917. ULONG iDir;
  918. jClip = (pco == NULL) ? DC_TRIVIAL : pco->iDComplexity;
  919. pdsurfDst = (DSURF*) psoDst->dhsurf; // May be NULL
  920. if (psoSrc == NULL)
  921. {
  922. ///////////////////////////////////////////////////////////////////
  923. // Fills
  924. ///////////////////////////////////////////////////////////////////
  925. // Fills are this function's "raison d'etre" (which is French
  926. // for "purple armadillo"), so we handle them as quickly as
  927. // possible:
  928. ASSERTDD(pdsurfDst != NULL,
  929. "Expect only device destinations when no source");
  930. if (pdsurfDst->dt == DT_SCREEN)
  931. {
  932. ppdev = (PDEV*) psoDst->dhpdev;
  933. poh = pdsurfDst->poh;
  934. ppdev->xOffset = poh->x;
  935. ppdev->yOffset = poh->y;
  936. // Make sure it doesn't involve a mask (i.e., it's really a
  937. // Rop3):
  938. if (((rop4 >> 8) & 0xff) == (rop4 & 0xff))
  939. {
  940. // Since 'psoSrc' is NULL, the rop3 had better not indicate
  941. // that we need a source.
  942. ASSERTDD((((rop4 >> 2) ^ (rop4)) & 0x33) == 0,
  943. "Need source but GDI gave us a NULL 'psoSrc'");
  944. Fill_It:
  945. pfnFill = ppdev->pfnFillSolid;
  946. if (gabRopNeedsPattern[(rop4 >> 2) & 0xf])
  947. {
  948. rbc.iSolidColor = pbo->iSolidColor;
  949. if (rbc.iSolidColor == -1)
  950. {
  951. // Try and realize the pattern brush; by doing
  952. // this call-back, GDI will eventually call us
  953. // again through DrvRealizeBrush:
  954. rbc.prb = pbo->pvRbrush;
  955. if (rbc.prb == NULL)
  956. {
  957. rbc.prb = BRUSHOBJ_pvGetRbrush(pbo);
  958. if (rbc.prb == NULL)
  959. {
  960. // If we couldn't realize the brush, punt
  961. // the call (it may have been a non 8x8
  962. // brush or something, which we can't be
  963. // bothered to handle, so let GDI do the
  964. // drawing):
  965. goto Punt_It;
  966. }
  967. }
  968. pfnFill = ppdev->pfnFillPat;
  969. }
  970. }
  971. // Note that these 2 'if's are more efficient than
  972. // a switch statement:
  973. if (jClip == DC_TRIVIAL)
  974. {
  975. pfnFill(ppdev, 1, prclDst, rop4, rbc, pptlBrush);
  976. goto All_Done;
  977. }
  978. else if (jClip == DC_RECT)
  979. {
  980. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  981. pfnFill(ppdev, 1, &rcl, rop4, rbc, pptlBrush);
  982. goto All_Done;
  983. }
  984. else
  985. {
  986. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_ANY, 0);
  987. do {
  988. bMore = CLIPOBJ_bEnum(pco, sizeof(ce), (ULONG*) &ce);
  989. c = cIntersect(prclDst, ce.arcl, ce.c);
  990. if (c != 0)
  991. pfnFill(ppdev, c, ce.arcl, rop4, rbc, pptlBrush);
  992. } while (bMore);
  993. goto All_Done;
  994. }
  995. }
  996. }
  997. }
  998. if ((psoSrc != NULL) && (psoSrc->dhsurf != NULL))
  999. {
  1000. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1001. if (pdsurfSrc->dt == DT_DIB)
  1002. {
  1003. // Here we consider putting a DIB DFB back into off-screen
  1004. // memory. If there's a translate, it's probably not worth
  1005. // moving since we won't be able to use the hardware to do
  1006. // the blt (a similar argument could be made for weird rops
  1007. // and stuff that we'll only end up having GDI simulate, but
  1008. // those should happen infrequently enough that I don't care).
  1009. if ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL))
  1010. {
  1011. ppdev = (PDEV*) psoSrc->dhpdev;
  1012. // See 'DrvCopyBits' for some more comments on how this
  1013. // moving-it-back-into-off-screen-memory thing works:
  1014. if (pdsurfSrc->iUniq == ppdev->iHeapUniq)
  1015. {
  1016. if (--pdsurfSrc->cBlt == 0)
  1017. {
  1018. if (bMoveDibToOffscreenDfbIfRoom(ppdev, pdsurfSrc))
  1019. goto Continue_It;
  1020. }
  1021. }
  1022. else
  1023. {
  1024. // Some space was freed up in off-screen memory,
  1025. // so reset the counter for this DFB:
  1026. pdsurfSrc->iUniq = ppdev->iHeapUniq;
  1027. pdsurfSrc->cBlt = HEAP_COUNT_DOWN;
  1028. }
  1029. }
  1030. psoSrc = pdsurfSrc->pso;
  1031. // Handle the case where the source is a DIB DFB and the
  1032. // destination is a regular bitmap:
  1033. if (psoDst->dhsurf == NULL)
  1034. goto EngBitBlt_It;
  1035. }
  1036. }
  1037. Continue_It:
  1038. if (pdsurfDst != NULL)
  1039. {
  1040. if (pdsurfDst->dt == DT_DIB)
  1041. {
  1042. psoDst = pdsurfDst->pso;
  1043. // If the destination is a DIB, we can only handle this
  1044. // call if the source is not a DIB:
  1045. if ((psoSrc == NULL) || (psoSrc->dhsurf == NULL))
  1046. goto EngBitBlt_It;
  1047. }
  1048. }
  1049. // At this point, we know that either the source or the destination is
  1050. // not a DIB. Check for a DFB to screen, DFB to DFB, or screen to DFB
  1051. // case:
  1052. if ((psoSrc != NULL) &&
  1053. (psoDst->dhsurf != NULL) &&
  1054. (psoSrc->dhsurf != NULL))
  1055. {
  1056. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1057. pdsurfDst = (DSURF*) psoDst->dhsurf;
  1058. ASSERTDD(pdsurfSrc->dt == DT_SCREEN, "Expected screen source");
  1059. ASSERTDD(pdsurfDst->dt == DT_SCREEN, "Expected screen destination");
  1060. ptlSrc.x = pptlSrc->x - (pdsurfDst->poh->x - pdsurfSrc->poh->x);
  1061. ptlSrc.y = pptlSrc->y - (pdsurfDst->poh->y - pdsurfSrc->poh->y);
  1062. pptlSrc = &ptlSrc;
  1063. }
  1064. if (psoDst->dhsurf != NULL)
  1065. {
  1066. pdsurfDst = (DSURF*) psoDst->dhsurf;
  1067. ppdev = (PDEV*) psoDst->dhpdev;
  1068. ppdev->xOffset = pdsurfDst->poh->x;
  1069. ppdev->yOffset = pdsurfDst->poh->y;
  1070. }
  1071. else
  1072. {
  1073. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1074. ppdev = (PDEV*) psoSrc->dhpdev;
  1075. ppdev->xOffset = pdsurfSrc->poh->x;
  1076. ppdev->yOffset = pdsurfSrc->poh->y;
  1077. }
  1078. // We bail here if we're running in a high-colour mode:
  1079. if (ppdev->flStat & STAT_UNACCELERATED)
  1080. goto EngBitBlt_It;
  1081. if (((rop4 >> 8) & 0xff) == (rop4 & 0xff))
  1082. {
  1083. // Since we've already handled the cases where the ROP4 is really
  1084. // a ROP3 and no source is required, we can assert...
  1085. ASSERTDD((psoSrc != NULL) && (pptlSrc != NULL),
  1086. "Expected no-source case to already have been handled");
  1087. ///////////////////////////////////////////////////////////////////
  1088. // Bitmap transfers
  1089. ///////////////////////////////////////////////////////////////////
  1090. // Since the foreground and background ROPs are the same, we
  1091. // don't have to worry about no stinking masks (it's a simple
  1092. // Rop3).
  1093. rop3 = (rop4 & 0xff); // Make it into a Rop3 (we keep the rop4
  1094. // around in case we decide to punt)
  1095. if (psoDst->dhsurf != NULL)
  1096. {
  1097. // The destination is the screen:
  1098. if ((rop3 >> 4) == (rop3 & 0xf))
  1099. {
  1100. // The ROP3 doesn't require a pattern:
  1101. if (psoSrc->dhsurf == NULL)
  1102. {
  1103. //////////////////////////////////////////////////
  1104. // DIB-to-screen blt
  1105. // This section handles 1bpp, 4bpp and 8bpp sources.
  1106. iSrcBitmapFormat = psoSrc->iBitmapFormat;
  1107. if (iSrcBitmapFormat == BMF_1BPP)
  1108. {
  1109. pfnXfer = ppdev->pfnXfer1bpp;
  1110. goto Xfer_It;
  1111. }
  1112. }
  1113. else // psoSrc->dhsurf != NULL
  1114. {
  1115. if ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL))
  1116. {
  1117. //////////////////////////////////////////////////
  1118. // Screen-to-screen blt with no translate
  1119. if (jClip == DC_TRIVIAL)
  1120. {
  1121. (ppdev->pfnCopyBlt)(ppdev, 1, prclDst, rop4,
  1122. pptlSrc, prclDst);
  1123. goto All_Done;
  1124. }
  1125. else if (jClip == DC_RECT)
  1126. {
  1127. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  1128. {
  1129. (ppdev->pfnCopyBlt)(ppdev, 1, &rcl, rop4,
  1130. pptlSrc, prclDst);
  1131. }
  1132. goto All_Done;
  1133. }
  1134. else
  1135. {
  1136. // Don't forget that we'll have to draw the
  1137. // rectangles in the correct direction:
  1138. if (pptlSrc->y >= prclDst->top)
  1139. {
  1140. if (pptlSrc->x >= prclDst->left)
  1141. iDir = CD_RIGHTDOWN;
  1142. else
  1143. iDir = CD_LEFTDOWN;
  1144. }
  1145. else
  1146. {
  1147. if (pptlSrc->x >= prclDst->left)
  1148. iDir = CD_RIGHTUP;
  1149. else
  1150. iDir = CD_LEFTUP;
  1151. }
  1152. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES,
  1153. iDir, 0);
  1154. do {
  1155. bMore = CLIPOBJ_bEnum(pco, sizeof(ce),
  1156. (ULONG*) &ce);
  1157. c = cIntersect(prclDst, ce.arcl, ce.c);
  1158. if (c != 0)
  1159. {
  1160. (ppdev->pfnCopyBlt)(ppdev, c, ce.arcl,
  1161. rop4, pptlSrc, prclDst);
  1162. }
  1163. } while (bMore);
  1164. goto All_Done;
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. else
  1171. {
  1172. #if defined(i386)
  1173. {
  1174. // We special case screen to monochrome blts because they
  1175. // happen fairly often. We only handle SRCCOPY rops and
  1176. // monochrome destinations (to handle a true 1bpp DIB
  1177. // destination, we would have to do near-colour searches
  1178. // on every colour; as it is, the foreground colour gets
  1179. // mapped to '1', and everything else gets mapped to '0'):
  1180. if ((psoDst->iBitmapFormat == BMF_1BPP) &&
  1181. (rop3 == 0xcc) &&
  1182. (pxlo->flXlate & XO_TO_MONO) &&
  1183. (ppdev->iBitmapFormat != BMF_24BPP))
  1184. {
  1185. pfnXfer = vXferScreenTo1bpp;
  1186. psoSrc = psoDst; // A misnomer, I admit
  1187. goto Xfer_It;
  1188. }
  1189. }
  1190. #endif // i386
  1191. }
  1192. }
  1193. else if ((psoMsk == NULL) && (rop4 == 0xaacc))
  1194. {
  1195. // The only time GDI will ask us to do a true rop4 using the brush
  1196. // mask is when the brush is 1bpp, and the background rop is AA
  1197. // (meaning it's a NOP):
  1198. goto Fill_It;
  1199. }
  1200. // Just fall through to Punt_It...
  1201. Punt_It:
  1202. return(bPuntBlt(psoDst,
  1203. psoSrc,
  1204. psoMsk,
  1205. pco,
  1206. pxlo,
  1207. prclDst,
  1208. pptlSrc,
  1209. pptlMsk,
  1210. pbo,
  1211. pptlBrush,
  1212. rop4));
  1213. //////////////////////////////////////////////////////////////////////
  1214. // Common bitmap transfer
  1215. Xfer_It:
  1216. if (jClip == DC_TRIVIAL)
  1217. {
  1218. pfnXfer(ppdev, 1, prclDst, rop4, psoSrc, pptlSrc, prclDst, pxlo);
  1219. goto All_Done;
  1220. }
  1221. else if (jClip == DC_RECT)
  1222. {
  1223. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  1224. pfnXfer(ppdev, 1, &rcl, rop4, psoSrc, pptlSrc, prclDst, pxlo);
  1225. goto All_Done;
  1226. }
  1227. else
  1228. {
  1229. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES,
  1230. CD_ANY, 0);
  1231. do {
  1232. bMore = CLIPOBJ_bEnum(pco, sizeof(ce),
  1233. (ULONG*) &ce);
  1234. c = cIntersect(prclDst, ce.arcl, ce.c);
  1235. if (c != 0)
  1236. {
  1237. pfnXfer(ppdev, c, ce.arcl, rop4, psoSrc,
  1238. pptlSrc, prclDst, pxlo);
  1239. }
  1240. } while (bMore);
  1241. goto All_Done;
  1242. }
  1243. ////////////////////////////////////////////////////////////////////////
  1244. // Common DIB blt
  1245. EngBitBlt_It:
  1246. // Our driver doesn't handle any blt's between two DIBs. Normally
  1247. // a driver doesn't have to worry about this, but we do because
  1248. // we have DFBs that may get moved from off-screen memory to a DIB,
  1249. // where we have GDI do all the drawing. GDI does DIB drawing at
  1250. // a reasonable speed (unless one of the surfaces is a device-
  1251. // managed surface...)
  1252. //
  1253. // If either the source or destination surface in an EngBitBlt
  1254. // call-back is a device-managed surface (meaning it's not a DIB
  1255. // that GDI can draw with), GDI will automatically allocate memory
  1256. // and call the driver's DrvCopyBits routine to create a DIB copy
  1257. // that it can use. So this means that this could handle all 'punts',
  1258. // and we could conceivably get rid of bPuntBlt. But this would have
  1259. // a bad performance impact because of the extra memory allocations
  1260. // and bitmap copies -- you really don't want to do this unless you
  1261. // have to (or your surface was created such that GDI can draw
  1262. // directly onto it) -- I've been burned by this because it's not
  1263. // obvious that the performance impact is so bad.
  1264. //
  1265. // That being said, we only call EngBitBlt when all the surfaces
  1266. // are DIBs:
  1267. return(EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, prclDst,
  1268. pptlSrc, pptlMsk, pbo, pptlBrush, rop4));
  1269. All_Done:
  1270. return(TRUE);
  1271. }
  1272. /******************************Public*Routine******************************\
  1273. * BOOL DrvCopyBits
  1274. *
  1275. * Do fast bitmap copies.
  1276. *
  1277. * Note that GDI will (usually) automatically adjust the blt extents to
  1278. * adjust for any rectangular clipping, so we'll rarely see DC_RECT
  1279. * clipping in this routine (and as such, we don't bother special casing
  1280. * it).
  1281. *
  1282. * I'm not sure if the performance benefit from this routine is actually
  1283. * worth the increase in code size, since SRCCOPY BitBlts are hardly the
  1284. * most common drawing operation we'll get. But what the heck.
  1285. *
  1286. \**************************************************************************/
  1287. BOOL DrvCopyBits(
  1288. SURFOBJ* psoDst,
  1289. SURFOBJ* psoSrc,
  1290. CLIPOBJ* pco,
  1291. XLATEOBJ* pxlo,
  1292. RECTL* prclDst,
  1293. POINTL* pptlSrc)
  1294. {
  1295. PDEV* ppdev;
  1296. DSURF* pdsurfSrc;
  1297. DSURF* pdsurfDst;
  1298. RECTL rcl;
  1299. POINTL ptl;
  1300. OH* pohSrc;
  1301. OH* pohDst;
  1302. // DrvCopyBits is a fast-path for SRCCOPY blts. But it can still be
  1303. // pretty complicated: there can be translates, clipping, RLEs,
  1304. // bitmaps that aren't the same format as the screen, plus
  1305. // screen-to-screen, DIB-to-screen or screen-to-DIB operations,
  1306. // not to mention DFBs (device format bitmaps).
  1307. //
  1308. // Rather than making this routine almost as big as DrvBitBlt, I'll
  1309. // handle here only the speed-critical cases, and punt the rest to
  1310. // our DrvBitBlt routine.
  1311. //
  1312. // We'll try to handle anything that doesn't involve clipping:
  1313. if (((pco == NULL) || (pco->iDComplexity == DC_TRIVIAL)) &&
  1314. ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL)))
  1315. {
  1316. if (psoDst->dhsurf != NULL)
  1317. {
  1318. // We know the destination is either a DFB or the screen:
  1319. ppdev = (PDEV*) psoDst->dhpdev;
  1320. pdsurfDst = (DSURF*) psoDst->dhsurf;
  1321. // See if the source is a plain DIB:
  1322. if (psoSrc->dhsurf != NULL)
  1323. {
  1324. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1325. // Make sure the destination is really the screen or an
  1326. // off-screen DFB (i.e., not a DFB that we've converted
  1327. // to a DIB):
  1328. if (pdsurfDst->dt == DT_SCREEN)
  1329. {
  1330. ASSERTDD(psoSrc->dhsurf != NULL, "Can't be a DIB");
  1331. if (pdsurfSrc->dt == DT_SCREEN)
  1332. {
  1333. Screen_To_Screen:
  1334. //////////////////////////////////////////////////////
  1335. // Screen-to-screen
  1336. ASSERTDD((psoSrc->dhsurf != NULL) &&
  1337. (pdsurfSrc->dt == DT_SCREEN) &&
  1338. (psoDst->dhsurf != NULL) &&
  1339. (pdsurfDst->dt == DT_SCREEN),
  1340. "Should be a screen-to-screen case");
  1341. // pfnCopyBlt takes relative coordinates (relative
  1342. // to the destination surface, that is), so we have
  1343. // to change the start point to be relative to the
  1344. // destination surface too:
  1345. pohSrc = pdsurfSrc->poh;
  1346. pohDst = pdsurfDst->poh;
  1347. ptl.x = pptlSrc->x - (pohDst->x - pohSrc->x);
  1348. ptl.y = pptlSrc->y - (pohDst->y - pohSrc->y);
  1349. ppdev->xOffset = pohDst->x;
  1350. ppdev->yOffset = pohDst->y;
  1351. (ppdev->pfnCopyBlt)(ppdev, 1, prclDst, 0xCCCC, &ptl,
  1352. prclDst);
  1353. return(TRUE);
  1354. }
  1355. else // (pdsurfSrc->dt != DT_SCREEN)
  1356. {
  1357. // Ah ha, the source is a DFB that's really a DIB.
  1358. ASSERTDD(psoDst->dhsurf != NULL,
  1359. "Destination can't be a DIB here");
  1360. /////////////////////////////////////////////////////
  1361. // Put It Back Into Off-screen?
  1362. //
  1363. // We take this opportunity to decide if we want to
  1364. // put the DIB back into off-screen memory. This is
  1365. // a pretty good place to do it because we have to
  1366. // copy the bits to some portion of the screen,
  1367. // anyway. So we would incur only an extra screen-to-
  1368. // screen blt at this time, much of which will be
  1369. // over-lapped with the CPU.
  1370. //
  1371. // The simple approach we have taken is to move a DIB
  1372. // back into off-screen memory only if there's already
  1373. // room -- we won't throw stuff out to make space
  1374. // (because it's tough to know what ones to throw out,
  1375. // and it's easy to get into thrashing scenarios).
  1376. //
  1377. // Because it takes some time to see if there's room
  1378. // in off-screen memory, we only check one in
  1379. // HEAP_COUNT_DOWN times if there's room. To bias
  1380. // in favour of bitmaps that are often blt, the
  1381. // counters are reset every time any space is freed
  1382. // up in off-screen memory. We also don't bother
  1383. // checking if no space has been freed since the
  1384. // last time we checked for this DIB.
  1385. if (pdsurfSrc->iUniq == ppdev->iHeapUniq)
  1386. {
  1387. if (--pdsurfSrc->cBlt == 0)
  1388. {
  1389. if (bMoveDibToOffscreenDfbIfRoom(ppdev,
  1390. pdsurfSrc))
  1391. goto Screen_To_Screen;
  1392. }
  1393. }
  1394. else
  1395. {
  1396. // Some space was freed up in off-screen memory,
  1397. // so reset the counter for this DFB:
  1398. pdsurfSrc->iUniq = ppdev->iHeapUniq;
  1399. pdsurfSrc->cBlt = HEAP_COUNT_DOWN;
  1400. }
  1401. // Since the destination is definitely the screen,
  1402. // we don't have to worry about creating a DIB to
  1403. // DIB copy case (for which we would have to call
  1404. // EngCopyBits):
  1405. psoSrc = pdsurfSrc->pso;
  1406. goto DIB_To_Screen;
  1407. }
  1408. }
  1409. else // (pdsurfDst->dt != DT_SCREEN)
  1410. {
  1411. // Because the source is not a DIB, we don't have to
  1412. // worry about creating a DIB to DIB case here (although
  1413. // we'll have to check later to see if the source is
  1414. // really a DIB that's masquerading as a DFB...)
  1415. ASSERTDD(psoSrc->dhsurf != NULL,
  1416. "Source can't be a DIB here");
  1417. psoDst = pdsurfDst->pso;
  1418. goto Screen_To_DIB;
  1419. }
  1420. }
  1421. else if (psoSrc->iBitmapFormat == ppdev->iBitmapFormat)
  1422. {
  1423. // Make sure the destination is really the screen:
  1424. if (pdsurfDst->dt == DT_SCREEN)
  1425. {
  1426. DIB_To_Screen:
  1427. //////////////////////////////////////////////////////
  1428. // DIB-to-screen
  1429. ASSERTDD((psoDst->dhsurf != NULL) &&
  1430. (pdsurfDst->dt == DT_SCREEN) &&
  1431. (psoSrc->dhsurf == NULL) &&
  1432. (psoSrc->iBitmapFormat == ppdev->iBitmapFormat),
  1433. "Should be a DIB-to-screen case");
  1434. // vPutBits takes absolute screen coordinates, so
  1435. // we have to muck with the destination rectangle:
  1436. pohDst = pdsurfDst->poh;
  1437. rcl.left = prclDst->left + pohDst->x;
  1438. rcl.right = prclDst->right + pohDst->x;
  1439. rcl.top = prclDst->top + pohDst->y;
  1440. rcl.bottom = prclDst->bottom + pohDst->y;
  1441. // We use the memory aperture to do the transfer,
  1442. // because that is supposed to be faster for SRCCOPY
  1443. // blts than using the data-transfer register:
  1444. vPutBits(ppdev, psoSrc, &rcl, pptlSrc);
  1445. return(TRUE);
  1446. }
  1447. }
  1448. }
  1449. else // (psoDst->dhsurf == NULL)
  1450. {
  1451. Screen_To_DIB:
  1452. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1453. ppdev = (PDEV*) psoSrc->dhpdev;
  1454. if (psoDst->iBitmapFormat == ppdev->iBitmapFormat)
  1455. {
  1456. if (pdsurfSrc->dt == DT_SCREEN)
  1457. {
  1458. //////////////////////////////////////////////////////
  1459. // Screen-to-DIB
  1460. ASSERTDD((psoSrc->dhsurf != NULL) &&
  1461. (pdsurfSrc->dt == DT_SCREEN) &&
  1462. (psoDst->dhsurf == NULL) &&
  1463. (psoDst->iBitmapFormat == ppdev->iBitmapFormat),
  1464. "Should be a screen-to-DIB case");
  1465. // vGetBits takes absolute screen coordinates, so we have
  1466. // to muck with the source point:
  1467. pohSrc = pdsurfSrc->poh;
  1468. ptl.x = pptlSrc->x + pohSrc->x;
  1469. ptl.y = pptlSrc->y + pohSrc->y;
  1470. vGetBits(ppdev, psoDst, prclDst, &ptl);
  1471. return(TRUE);
  1472. }
  1473. else
  1474. {
  1475. // The source is a DFB that's really a DIB. Since we
  1476. // know that the destination is a DIB, we've got a DIB
  1477. // to DIB operation, and should call EngCopyBits:
  1478. psoSrc = pdsurfSrc->pso;
  1479. goto EngCopyBits_It;
  1480. }
  1481. }
  1482. }
  1483. }
  1484. // We can't call DrvBitBlt if we've accidentally converted both
  1485. // surfaces to DIBs, because it isn't equipped to handle it:
  1486. ASSERTDD((psoSrc->dhsurf != NULL) ||
  1487. (psoDst->dhsurf != NULL),
  1488. "Accidentally converted both surfaces to DIBs");
  1489. /////////////////////////////////////////////////////////////////
  1490. // A DrvCopyBits is after all just a simplified DrvBitBlt:
  1491. return(DrvBitBlt(psoDst, psoSrc, NULL, pco, pxlo, prclDst, pptlSrc, NULL,
  1492. NULL, NULL, 0x0000CCCC));
  1493. EngCopyBits_It:
  1494. ASSERTDD((psoDst->dhsurf == NULL) &&
  1495. (psoSrc->dhsurf == NULL),
  1496. "Both surfaces should be DIBs to call EngCopyBits");
  1497. return(EngCopyBits(psoDst, psoSrc, pco, pxlo, prclDst, pptlSrc));
  1498. }