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.

1860 lines
66 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 the 'blt??.c' files.
  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. #include "precomp.h"
  23. /******************************Public*Table********************************\
  24. * BYTE gajLeftMask[] and BYTE gajRightMask[]
  25. *
  26. * Edge tables for vXferScreenTo1bpp.
  27. \**************************************************************************/
  28. BYTE gajLeftMask[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
  29. BYTE gajRightMask[] = { 0xff, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe };
  30. /******************************Public*Routine******************************\
  31. * VOID vXferNativeSrccopy
  32. *
  33. * Does a SRCCOPY transfer of a bitmap to the screen using the frame
  34. * buffer, because on the Cirrus chips it's faster than using the data
  35. * transfer register.
  36. *
  37. \**************************************************************************/
  38. VOID vXferNativeSrccopy( // Type FNXFER
  39. PDEV* ppdev,
  40. LONG c, // Count of rectangles, can't be zero
  41. RECTL* prcl, // List of destination rectangles, in relative
  42. // coordinates
  43. ULONG rop4, // Not used
  44. SURFOBJ* psoSrc, // Source surface
  45. POINTL* pptlSrc, // Original unclipped source point
  46. RECTL* prclDst, // Original unclipped destination rectangle
  47. XLATEOBJ* pxlo) // Not used
  48. {
  49. LONG xOffset;
  50. LONG yOffset;
  51. LONG dx;
  52. LONG dy;
  53. RECTL rclDst;
  54. POINTL ptlSrc;
  55. ASSERTDD((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL),
  56. "Can handle trivial xlate only");
  57. ASSERTDD(psoSrc->iBitmapFormat == ppdev->iBitmapFormat,
  58. "Source must be same colour depth as screen");
  59. ASSERTDD(c > 0, "Can't handle zero rectangles");
  60. ASSERTDD(rop4 == 0xcccc, "Must be a SRCCOPY rop");
  61. xOffset = ppdev->xOffset;
  62. yOffset = ppdev->yOffset;
  63. dx = pptlSrc->x - prclDst->left;
  64. dy = pptlSrc->y - prclDst->top; // Add to destination to get source
  65. while (TRUE)
  66. {
  67. ptlSrc.x = prcl->left + dx;
  68. ptlSrc.y = prcl->top + dy;
  69. // 'ppdev->pfnPutBits' takes only absolute coordinates, so add in the
  70. // off-screen bitmap offset here:
  71. rclDst.left = prcl->left + xOffset;
  72. rclDst.right = prcl->right + xOffset;
  73. rclDst.top = prcl->top + yOffset;
  74. rclDst.bottom = prcl->bottom + yOffset;
  75. ppdev->pfnPutBits(ppdev, psoSrc, &rclDst, &ptlSrc);
  76. if (--c == 0)
  77. return;
  78. prcl++;
  79. }
  80. }
  81. /******************************Public*Routine******************************\
  82. * VOID vXferScreenTo1bpp
  83. *
  84. * Performs a SRCCOPY transfer from the screen (when it's 8bpp) to a 1bpp
  85. * bitmap.
  86. *
  87. \**************************************************************************/
  88. #if defined(_X86_)
  89. VOID vXferScreenTo1bpp( // Type FNXFER
  90. PDEV* ppdev,
  91. LONG c, // Count of rectangles, can't be zero
  92. RECTL* prcl, // List of destination rectangles, in relative
  93. // coordinates
  94. ULONG ulHwMix, // Not used
  95. SURFOBJ* psoDst, // Destination surface
  96. POINTL* pptlSrc, // Original unclipped source point
  97. RECTL* prclDst, // Original unclipped destination rectangle
  98. XLATEOBJ* pxlo) // Provides colour-compressions information
  99. {
  100. LONG cBpp;
  101. VOID* pfnCompute;
  102. SURFOBJ soTmp;
  103. ULONG* pulXlate;
  104. ULONG ulForeColor;
  105. POINTL ptlSrc;
  106. RECTL rclTmp;
  107. BYTE* pjDst;
  108. BYTE jLeftMask;
  109. BYTE jRightMask;
  110. BYTE jNotLeftMask;
  111. BYTE jNotRightMask;
  112. LONG cjMiddle;
  113. LONG lDstDelta;
  114. LONG lSrcDelta;
  115. LONG cyTmpScans;
  116. LONG cyThis;
  117. LONG cyToGo;
  118. ASSERTDD(c > 0, "Can't handle zero rectangles");
  119. ASSERTDD(psoDst->iBitmapFormat == BMF_1BPP, "Only 1bpp destinations");
  120. ASSERTDD(TMP_BUFFER_SIZE >= PELS_TO_BYTES(ppdev->cxMemory),
  121. "Temp buffer has to be larger than widest possible scan");
  122. // When the destination is a 1bpp bitmap, the foreground colour
  123. // maps to '1', and any other colour maps to '0'.
  124. if (ppdev->iBitmapFormat == BMF_8BPP)
  125. {
  126. // When the source is 8bpp or less, we find the forground colour
  127. // by searching the translate table for the only '1':
  128. pulXlate = pxlo->pulXlate;
  129. while (*pulXlate != 1)
  130. pulXlate++;
  131. ulForeColor = pulXlate - pxlo->pulXlate;
  132. }
  133. else
  134. {
  135. ASSERTDD((ppdev->iBitmapFormat == BMF_16BPP) ||
  136. (ppdev->iBitmapFormat == BMF_32BPP),
  137. "This routine only supports 8, 16 or 32bpp");
  138. // When the source has a depth greater than 8bpp, the foreground
  139. // colour will be the first entry in the translate table we get
  140. // from calling 'piVector':
  141. pulXlate = XLATEOBJ_piVector(pxlo);
  142. ulForeColor = 0;
  143. if (pulXlate != NULL) // This check isn't really needed...
  144. ulForeColor = pulXlate[0];
  145. }
  146. // We use the temporary buffer to keep a copy of the source
  147. // rectangle:
  148. soTmp.pvScan0 = ppdev->pvTmpBuffer;
  149. do {
  150. // ptlSrc points to the upper-left corner of the screen rectangle
  151. // for the current batch:
  152. ptlSrc.x = prcl->left + (pptlSrc->x - prclDst->left);
  153. ptlSrc.y = prcl->top + (pptlSrc->y - prclDst->top);
  154. // ppdev->pfnGetBits takes absolute coordinates for the source point:
  155. ptlSrc.x += ppdev->xOffset;
  156. ptlSrc.y += ppdev->yOffset;
  157. pjDst = (BYTE*) psoDst->pvScan0 + (prcl->top * psoDst->lDelta)
  158. + (prcl->left >> 3);
  159. cBpp = ppdev->cBpp;
  160. soTmp.lDelta = PELS_TO_BYTES(((prcl->right + 7L) & ~7L) - (prcl->left & ~7L));
  161. // Our temporary buffer, into which we read a copy of the source,
  162. // may be smaller than the source rectangle. In that case, we
  163. // process the source rectangle in batches.
  164. //
  165. // cyTmpScans is the number of scans we can do in each batch.
  166. // cyToGo is the total number of scans we have to do for this
  167. // rectangle.
  168. //
  169. // We take the buffer size less four so that the right edge case
  170. // can safely read one dword past the end:
  171. cyTmpScans = (TMP_BUFFER_SIZE - 4) / soTmp.lDelta;
  172. cyToGo = prcl->bottom - prcl->top;
  173. ASSERTDD(cyTmpScans > 0, "Buffer too small for largest possible scan");
  174. // Initialize variables that don't change within the batch loop:
  175. rclTmp.top = 0;
  176. rclTmp.left = prcl->left & 7L;
  177. rclTmp.right = (prcl->right - prcl->left) + rclTmp.left;
  178. // Note that we have to be careful with the right mask so that it
  179. // isn't zero. A right mask of zero would mean that we'd always be
  180. // touching one byte past the end of the scan (even though we
  181. // wouldn't actually be modifying that byte), and we must never
  182. // access memory past the end of the bitmap (because we can access
  183. // violate if the bitmap end is exactly page-aligned).
  184. jLeftMask = gajLeftMask[rclTmp.left & 7];
  185. jRightMask = gajRightMask[rclTmp.right & 7];
  186. cjMiddle = ((rclTmp.right - 1) >> 3) - (rclTmp.left >> 3) - 1;
  187. if (cjMiddle < 0)
  188. {
  189. // The blt starts and ends in the same byte:
  190. jLeftMask &= jRightMask;
  191. jRightMask = 0;
  192. cjMiddle = 0;
  193. }
  194. jNotLeftMask = ~jLeftMask;
  195. jNotRightMask = ~jRightMask;
  196. lDstDelta = psoDst->lDelta - cjMiddle - 2;
  197. // Delta from the end of the destination
  198. // to the start on the next scan, accounting
  199. // for 'left' and 'right' bytes
  200. lSrcDelta = soTmp.lDelta - PELS_TO_BYTES(8 * (cjMiddle + 2));
  201. // Compute source delta for special cases
  202. // like when cjMiddle gets bumped up to '0',
  203. // and to correct aligned cases
  204. do {
  205. // This is the loop that breaks the source rectangle into
  206. // manageable batches.
  207. cyThis = cyTmpScans;
  208. cyToGo -= cyThis;
  209. if (cyToGo < 0)
  210. cyThis += cyToGo;
  211. rclTmp.bottom = cyThis;
  212. ppdev->pfnGetBits(ppdev, &soTmp, &rclTmp, &ptlSrc);
  213. ptlSrc.y += cyThis; // Get ready for next batch loop
  214. _asm {
  215. mov eax,ulForeColor ;eax = foreground colour
  216. ;ebx = temporary storage
  217. ;ecx = count of middle dst bytes
  218. ;dl = destination byte accumulator
  219. ;dh = temporary storage
  220. mov esi,soTmp.pvScan0 ;esi = source pointer
  221. mov edi,pjDst ;edi = destination pointer
  222. ; Figure out the appropriate compute routine:
  223. mov ebx,cBpp
  224. mov pfnCompute,offset Compute_Destination_Byte_From_8bpp
  225. dec ebx
  226. jz short Do_Left_Byte
  227. mov pfnCompute,offset Compute_Destination_Byte_From_16bpp
  228. dec ebx
  229. jz short Do_Left_Byte
  230. mov pfnCompute,offset Compute_Destination_Byte_From_32bpp
  231. Do_Left_Byte:
  232. call pfnCompute
  233. and dl,jLeftMask
  234. mov dh,jNotLeftMask
  235. and dh,[edi]
  236. or dh,dl
  237. mov [edi],dh
  238. inc edi
  239. mov ecx,cjMiddle
  240. dec ecx
  241. jl short Do_Right_Byte
  242. Do_Middle_Bytes:
  243. call pfnCompute
  244. mov [edi],dl
  245. inc edi
  246. dec ecx
  247. jge short Do_Middle_Bytes
  248. Do_Right_Byte:
  249. call pfnCompute
  250. and dl,jRightMask
  251. mov dh,jNotRightMask
  252. and dh,[edi]
  253. or dh,dl
  254. mov [edi],dh
  255. inc edi
  256. add edi,lDstDelta
  257. add esi,lSrcDelta
  258. dec cyThis
  259. jnz short Do_Left_Byte
  260. mov pjDst,edi ;save for next batch
  261. jmp All_Done
  262. Compute_Destination_Byte_From_8bpp:
  263. mov bl,[esi]
  264. sub bl,al
  265. cmp bl,1
  266. adc dl,dl ;bit 0
  267. mov bl,[esi+1]
  268. sub bl,al
  269. cmp bl,1
  270. adc dl,dl ;bit 1
  271. mov bl,[esi+2]
  272. sub bl,al
  273. cmp bl,1
  274. adc dl,dl ;bit 2
  275. mov bl,[esi+3]
  276. sub bl,al
  277. cmp bl,1
  278. adc dl,dl ;bit 3
  279. mov bl,[esi+4]
  280. sub bl,al
  281. cmp bl,1
  282. adc dl,dl ;bit 4
  283. mov bl,[esi+5]
  284. sub bl,al
  285. cmp bl,1
  286. adc dl,dl ;bit 5
  287. mov bl,[esi+6]
  288. sub bl,al
  289. cmp bl,1
  290. adc dl,dl ;bit 6
  291. mov bl,[esi+7]
  292. sub bl,al
  293. cmp bl,1
  294. adc dl,dl ;bit 7
  295. add esi,8 ;advance the source
  296. ret
  297. Compute_Destination_Byte_From_16bpp:
  298. mov bx,[esi]
  299. sub bx,ax
  300. cmp bx,1
  301. adc dl,dl ;bit 0
  302. mov bx,[esi+2]
  303. sub bx,ax
  304. cmp bx,1
  305. adc dl,dl ;bit 1
  306. mov bx,[esi+4]
  307. sub bx,ax
  308. cmp bx,1
  309. adc dl,dl ;bit 2
  310. mov bx,[esi+6]
  311. sub bx,ax
  312. cmp bx,1
  313. adc dl,dl ;bit 3
  314. mov bx,[esi+8]
  315. sub bx,ax
  316. cmp bx,1
  317. adc dl,dl ;bit 4
  318. mov bx,[esi+10]
  319. sub bx,ax
  320. cmp bx,1
  321. adc dl,dl ;bit 5
  322. mov bx,[esi+12]
  323. sub bx,ax
  324. cmp bx,1
  325. adc dl,dl ;bit 6
  326. mov bx,[esi+14]
  327. sub bx,ax
  328. cmp bx,1
  329. adc dl,dl ;bit 7
  330. add esi,16 ;advance the source
  331. ret
  332. Compute_Destination_Byte_From_32bpp:
  333. mov ebx,[esi]
  334. sub ebx,eax
  335. cmp ebx,1
  336. adc dl,dl ;bit 0
  337. mov ebx,[esi+4]
  338. sub ebx,eax
  339. cmp ebx,1
  340. adc dl,dl ;bit 1
  341. mov ebx,[esi+8]
  342. sub ebx,eax
  343. cmp ebx,1
  344. adc dl,dl ;bit 2
  345. mov ebx,[esi+12]
  346. sub ebx,eax
  347. cmp ebx,1
  348. adc dl,dl ;bit 3
  349. mov ebx,[esi+16]
  350. sub ebx,eax
  351. cmp ebx,1
  352. adc dl,dl ;bit 4
  353. mov ebx,[esi+20]
  354. sub ebx,eax
  355. cmp ebx,1
  356. adc dl,dl ;bit 5
  357. mov ebx,[esi+24]
  358. sub ebx,eax
  359. cmp ebx,1
  360. adc dl,dl ;bit 6
  361. mov ebx,[esi+28]
  362. sub ebx,eax
  363. cmp ebx,1
  364. adc dl,dl ;bit 7
  365. add esi,32 ;advance the source
  366. ret
  367. All_Done:
  368. }
  369. } while (cyToGo > 0);
  370. prcl++;
  371. } while (--c != 0);
  372. }
  373. #endif // i386
  374. /******************************Public*Routine******************************\
  375. * BOOL bPuntBlt
  376. *
  377. * Has GDI do any drawing operations that we don't specifically handle
  378. * in the driver.
  379. *
  380. \**************************************************************************/
  381. BOOL bPuntBlt(
  382. SURFOBJ* psoDst,
  383. SURFOBJ* psoSrc,
  384. SURFOBJ* psoMsk,
  385. CLIPOBJ* pco,
  386. XLATEOBJ* pxlo,
  387. RECTL* prclDst,
  388. POINTL* pptlSrc,
  389. POINTL* pptlMsk,
  390. BRUSHOBJ* pbo,
  391. POINTL* pptlBrush,
  392. ROP4 rop4)
  393. {
  394. PDEV* ppdev;
  395. if (psoDst->dhsurf != NULL)
  396. ppdev = (PDEV*) psoDst->dhpdev;
  397. else
  398. ppdev = (PDEV*) psoSrc->dhpdev;
  399. #if DBG
  400. {
  401. //////////////////////////////////////////////////////////////////////
  402. // Diagnostics
  403. //
  404. // Since calling the engine to do any drawing can be rather painful,
  405. // particularly when the source is an off-screen DFB (since GDI will
  406. // have to allocate a DIB and call us to make a temporary copy before
  407. // it can even start drawing), we'll try to avoid it as much as
  408. // possible.
  409. //
  410. // Here we simply spew out information describing the blt whenever
  411. // this routine gets called (checked builds only, of course):
  412. ULONG ulClip;
  413. ulClip = (pco == NULL) ? DC_TRIVIAL : pco->iDComplexity;
  414. DISPDBG((4, ">> Punt << Dst format: %li Dst type: %li Clip: %li Rop: %lx",
  415. psoDst->iBitmapFormat, psoDst->iType, ulClip, rop4));
  416. if (psoSrc != NULL)
  417. {
  418. DISPDBG((4, " << Src format: %li Src type: %li",
  419. psoSrc->iBitmapFormat, psoSrc->iType));
  420. if (psoSrc->iBitmapFormat == BMF_1BPP)
  421. {
  422. DISPDBG((4, " << Foreground: %lx Background: %lx",
  423. pxlo->pulXlate[1], pxlo->pulXlate[0]));
  424. }
  425. }
  426. if ((pxlo != NULL) && !(pxlo->flXlate & XO_TRIVIAL) && (psoSrc != NULL))
  427. {
  428. if (((psoSrc->dhsurf == NULL) &&
  429. (psoSrc->iBitmapFormat != ppdev->iBitmapFormat)) ||
  430. ((psoDst->dhsurf == NULL) &&
  431. (psoDst->iBitmapFormat != ppdev->iBitmapFormat)))
  432. {
  433. // Don't bother printing the 'xlate' message when the source
  434. // is a different bitmap format from the destination -- in
  435. // those cases we know there always has to be a translate.
  436. }
  437. else
  438. {
  439. DISPDBG((4, " << With xlate"));
  440. }
  441. }
  442. // If the rop4 requires a pattern, and it's a non-solid brush...
  443. if (((((rop4 >> 4) ^ (rop4)) & 0x0f0f) != 0) &&
  444. (pbo->iSolidColor == -1))
  445. {
  446. if (pbo->pvRbrush == NULL)
  447. DISPDBG((4, " << With brush -- Not created"));
  448. else
  449. DISPDBG((4, " << With brush -- Created Ok"));
  450. }
  451. }
  452. #endif
  453. if (DIRECT_ACCESS(ppdev))
  454. {
  455. //////////////////////////////////////////////////////////////////////
  456. // Banked Framebuffer bPuntBlt
  457. //
  458. // This section of code handles a PuntBlt when GDI can directly draw
  459. // on the framebuffer, but the drawing has to be done in banks:
  460. BANK bnk;
  461. BOOL b;
  462. HSURF hsurfTmp;
  463. SURFOBJ* psoTmp;
  464. SIZEL sizl;
  465. POINTL ptlSrc;
  466. RECTL rclTmp;
  467. RECTL rclDst;
  468. if (ppdev->bLinearMode)
  469. {
  470. DSURF* pdsurfDst;
  471. DSURF* pdsurfSrc;
  472. OH* pohSrc;
  473. OH* pohDst;
  474. if (psoDst->dhsurf != NULL)
  475. {
  476. pdsurfDst = (DSURF*) psoDst->dhsurf;
  477. psoDst = ppdev->psoPunt;
  478. psoDst->pvScan0 = pdsurfDst->poh->pvScan0;
  479. if (psoSrc != NULL)
  480. {
  481. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  482. if ((pdsurfSrc != NULL) &&
  483. (pdsurfSrc != pdsurfDst))
  484. {
  485. // If we're doing a BitBlt between different off-screen
  486. // surfaces, we have to be sure to give GDI different
  487. // surfaces, otherwise it may get confused when it has
  488. // to do screen-to-screen blts with a translate...
  489. pohSrc = pdsurfSrc->poh;
  490. pohDst = pdsurfDst->poh;
  491. psoSrc = ppdev->psoPunt2;
  492. psoSrc->pvScan0 = pohSrc->pvScan0;
  493. // Undo the source pointer adjustment we did earlier:
  494. ptlSrc.x = pptlSrc->x + (pohDst->x - pohSrc->x);
  495. ptlSrc.y = pptlSrc->y + (pohDst->y - pohSrc->y);
  496. pptlSrc = &ptlSrc;
  497. }
  498. }
  499. }
  500. else
  501. {
  502. ppdev = (PDEV*) psoSrc->dhpdev;
  503. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  504. psoSrc = ppdev->psoPunt;
  505. psoSrc->pvScan0 = pdsurfSrc->poh->pvScan0;
  506. }
  507. ppdev->pfnBankSelectMode(ppdev, BANK_ON);
  508. return(EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, prclDst, pptlSrc,
  509. pptlMsk, pbo, pptlBrush, rop4));
  510. }
  511. // We copy the original destination rectangle, and use that in every
  512. // GDI call-back instead of the original because sometimes GDI is
  513. // sneaky and points 'prclDst' to '&pco->rclBounds'. Because we
  514. // modify 'rclBounds', that would affect 'prclDst', which we don't
  515. // want to happen:
  516. rclDst = *prclDst;
  517. if ((psoSrc == NULL) || (psoSrc->iType == STYPE_BITMAP))
  518. {
  519. ASSERTDD(psoDst->iType != STYPE_BITMAP,
  520. "Dest should be the screen when given a DIB source");
  521. // Do a memory-to-screen blt:
  522. vBankStart(ppdev, &rclDst, pco, &bnk);
  523. b = TRUE;
  524. do {
  525. b &= EngBitBlt(bnk.pso, psoSrc, psoMsk, bnk.pco, pxlo,
  526. &rclDst, pptlSrc, pptlMsk, pbo, pptlBrush,
  527. rop4);
  528. } while (bBankEnum(&bnk));
  529. }
  530. else
  531. {
  532. b = FALSE; // Assume failure
  533. // The screen is the source (it may be the destination too...)
  534. ptlSrc.x = pptlSrc->x + ppdev->xOffset;
  535. ptlSrc.y = pptlSrc->y + ppdev->yOffset;
  536. if ((pco != NULL) && (pco->iDComplexity != DC_TRIVIAL))
  537. {
  538. // We have to intersect the destination rectangle with
  539. // the clip bounds if there is one (consider the case
  540. // where the app asked to blt a really, really big
  541. // rectangle from the screen -- prclDst would be really,
  542. // really big but pco->rclBounds would be the actual
  543. // area of interest):
  544. rclDst.left = max(rclDst.left, pco->rclBounds.left);
  545. rclDst.top = max(rclDst.top, pco->rclBounds.top);
  546. rclDst.right = min(rclDst.right, pco->rclBounds.right);
  547. rclDst.bottom = min(rclDst.bottom, pco->rclBounds.bottom);
  548. // Correspondingly, we have to offset the source point:
  549. ptlSrc.x += (rclDst.left - prclDst->left);
  550. ptlSrc.y += (rclDst.top - prclDst->top);
  551. }
  552. // We're now either going to do a screen-to-screen or screen-to-DIB
  553. // blt. In either case, we're going to create a temporary copy of
  554. // the source. (Why do we do this when GDI could do it for us?
  555. // GDI would create a temporary copy of the DIB for every bank
  556. // call-back!)
  557. sizl.cx = rclDst.right - rclDst.left;
  558. sizl.cy = rclDst.bottom - rclDst.top;
  559. // Don't forget to convert from relative to absolute coordinates
  560. // on the source! (vBankStart takes care of that for the
  561. // destination.)
  562. rclTmp.right = sizl.cx;
  563. rclTmp.bottom = sizl.cy;
  564. rclTmp.left = 0;
  565. rclTmp.top = 0;
  566. // GDI does guarantee us that the blt extents have already been
  567. // clipped to the surface boundaries (we don't have to worry
  568. // here about trying to read where there isn't video memory).
  569. // Let's just assert to make sure:
  570. ASSERTDD((ptlSrc.x >= 0) &&
  571. (ptlSrc.y >= 0) &&
  572. (ptlSrc.x + sizl.cx <= ppdev->cxMemory) &&
  573. (ptlSrc.y + sizl.cy <= ppdev->cyMemory),
  574. "Source rectangle out of bounds!");
  575. hsurfTmp = (HSURF) EngCreateBitmap(sizl,
  576. 0, // Let GDI choose ulWidth
  577. ppdev->iBitmapFormat,
  578. 0, // Don't need any options
  579. NULL);// Let GDI allocate
  580. if (hsurfTmp != 0)
  581. {
  582. psoTmp = EngLockSurface(hsurfTmp);
  583. if (psoTmp != NULL)
  584. {
  585. ppdev->pfnGetBits(ppdev, psoTmp, &rclTmp, &ptlSrc);
  586. if (psoDst->iType == STYPE_BITMAP)
  587. {
  588. // It was a Screen-to-DIB blt; now it's a DIB-to-DIB
  589. // blt. Note that the source point is (0, 0) in our
  590. // temporary surface:
  591. b = EngBitBlt(psoDst, psoTmp, psoMsk, pco, pxlo,
  592. &rclDst, (POINTL*) &rclTmp, pptlMsk,
  593. pbo, pptlBrush, rop4);
  594. }
  595. else
  596. {
  597. // It was a Screen-to-Screen blt; now it's a DIB-to-
  598. // screen blt. Note that the source point is (0, 0)
  599. // in our temporary surface:
  600. vBankStart(ppdev, &rclDst, pco, &bnk);
  601. b = TRUE;
  602. do {
  603. b &= EngBitBlt(bnk.pso, psoTmp, psoMsk, bnk.pco,
  604. pxlo, &rclDst, (POINTL*) &rclTmp,
  605. pptlMsk, pbo, pptlBrush, rop4);
  606. } while (bBankEnum(&bnk));
  607. }
  608. EngUnlockSurface(psoTmp);
  609. }
  610. EngDeleteSurface(hsurfTmp);
  611. }
  612. }
  613. return(b);
  614. }
  615. #if !defined(_X86_)
  616. else
  617. {
  618. //////////////////////////////////////////////////////////////////////
  619. // Really Slow bPuntBlt
  620. //
  621. // Here we handle a PuntBlt when GDI can't draw directly on the
  622. // framebuffer (as on the Alpha, which can't do it because of its
  623. // 32 bit bus). If you thought the banked version was slow, just
  624. // look at this one. Guaranteed, there will be at least one bitmap
  625. // allocation and extra copy involved; there could be two if it's a
  626. // screen-to-screen operation.
  627. POINTL ptlSrc;
  628. RECTL rclDst;
  629. SIZEL sizl;
  630. BOOL bSrcIsScreen;
  631. HSURF hsurfSrc;
  632. RECTL rclTmp;
  633. BOOL b;
  634. LONG lDelta;
  635. BYTE* pjBits;
  636. BYTE* pjScan0;
  637. HSURF hsurfDst;
  638. RECTL rclScreen;
  639. b = FALSE; // For error cases, assume we'll fail
  640. rclDst = *prclDst;
  641. if (pptlSrc != NULL)
  642. ptlSrc = *pptlSrc;
  643. if ((pco != NULL) && (pco->iDComplexity != DC_TRIVIAL))
  644. {
  645. // We have to intersect the destination rectangle with
  646. // the clip bounds if there is one (consider the case
  647. // where the app asked to blt a really, really big
  648. // rectangle from the screen -- prclDst would be really,
  649. // really big but pco->rclBounds would be the actual
  650. // area of interest):
  651. rclDst.left = max(rclDst.left, pco->rclBounds.left);
  652. rclDst.top = max(rclDst.top, pco->rclBounds.top);
  653. rclDst.right = min(rclDst.right, pco->rclBounds.right);
  654. rclDst.bottom = min(rclDst.bottom, pco->rclBounds.bottom);
  655. ptlSrc.x += (rclDst.left - prclDst->left);
  656. ptlSrc.y += (rclDst.top - prclDst->top);
  657. }
  658. sizl.cx = rclDst.right - rclDst.left;
  659. sizl.cy = rclDst.bottom - rclDst.top;
  660. // We only need to make a copy from the screen if the source is
  661. // the screen, and the source is involved in the rop. Note that
  662. // we have to check the rop before dereferencing 'psoSrc'
  663. // (because 'psoSrc' may be NULL if the source isn't involved):
  664. bSrcIsScreen = (((((rop4 >> 2) ^ (rop4)) & 0x3333) != 0) &&
  665. (psoSrc->iType != STYPE_BITMAP));
  666. if (bSrcIsScreen)
  667. {
  668. // We need to create a copy of the source rectangle:
  669. hsurfSrc = (HSURF) EngCreateBitmap(sizl, 0, ppdev->iBitmapFormat,
  670. 0, NULL);
  671. if (hsurfSrc == 0)
  672. goto Error_0;
  673. psoSrc = EngLockSurface(hsurfSrc);
  674. if (psoSrc == NULL)
  675. goto Error_1;
  676. rclTmp.left = 0;
  677. rclTmp.top = 0;
  678. rclTmp.right = sizl.cx;
  679. rclTmp.bottom = sizl.cy;
  680. // ppdev->pfnGetBits takes absolute coordinates for the source point:
  681. ptlSrc.x += ppdev->xOffset;
  682. ptlSrc.y += ppdev->yOffset;
  683. ppdev->pfnGetBits(ppdev, psoSrc, &rclTmp, &ptlSrc);
  684. // The source will now come from (0, 0) of our temporary source
  685. // surface:
  686. ptlSrc.x = 0;
  687. ptlSrc.y = 0;
  688. }
  689. if (psoDst->iType == STYPE_BITMAP)
  690. {
  691. b = EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, &rclDst, &ptlSrc,
  692. pptlMsk, pbo, pptlBrush, rop4);
  693. }
  694. else
  695. {
  696. // We need to create a temporary work buffer. We have to do
  697. // some fudging with the offsets so that the upper-left corner
  698. // of the (relative coordinates) clip object bounds passed to
  699. // GDI will be transformed to the upper-left corner of our
  700. // temporary bitmap.
  701. // The alignment doesn't have to be as tight as this at 16bpp
  702. // and 32bpp, but it won't hurt:
  703. lDelta = PELS_TO_BYTES(((rclDst.right + 3) & ~3L) -
  704. ((rclDst.left) & ~3L));
  705. // We're actually only allocating a bitmap that is 'sizl.cx' x
  706. // 'sizl.cy' in size:
  707. pjBits = EngAllocMem(0, lDelta * sizl.cy, ALLOC_TAG);
  708. if (pjBits == NULL)
  709. goto Error_2;
  710. // We now adjust the surface's 'pvScan0' so that when GDI thinks
  711. // it's writing to pixel (rclDst.top, rclDst.left), it will
  712. // actually be writing to the upper-left pixel of our temporary
  713. // bitmap:
  714. pjScan0 = pjBits - (rclDst.top * lDelta)
  715. - (PELS_TO_BYTES(rclDst.left & ~3L));
  716. ASSERTDD((((ULONG_PTR)pjScan0) & 3) == 0,
  717. "pvScan0 must be dword aligned!");
  718. // The checked build of GDI sometimes checks on blts that
  719. // prclDst->right <= pso->sizl.cx, so we lie to it about
  720. // the size of our bitmap:
  721. sizl.cx = rclDst.right;
  722. sizl.cy = rclDst.bottom;
  723. hsurfDst = (HSURF) EngCreateBitmap(
  724. sizl, // Bitmap covers rectangle
  725. lDelta, // Use this delta
  726. ppdev->iBitmapFormat, // Same colour depth
  727. BMF_TOPDOWN, // Must have a positive delta
  728. pjScan0); // Where (0, 0) would be
  729. if ((hsurfDst == 0) ||
  730. (!EngAssociateSurface(hsurfDst, ppdev->hdevEng, 0)))
  731. goto Error_3;
  732. psoDst = EngLockSurface(hsurfDst);
  733. if (psoDst == NULL)
  734. goto Error_4;
  735. // Make sure that the rectangle we Get/Put from/to the screen
  736. // is in absolute coordinates:
  737. rclScreen.left = rclDst.left + ppdev->xOffset;
  738. rclScreen.right = rclDst.right + ppdev->xOffset;
  739. rclScreen.top = rclDst.top + ppdev->yOffset;
  740. rclScreen.bottom = rclDst.bottom + ppdev->yOffset;
  741. // It would be nice to get a copy of the destination rectangle
  742. // only when the ROP involves the destination (or when the source
  743. // is an RLE), but we can't do that. If the brush is truly NULL,
  744. // GDI will immediately return TRUE from EngBitBlt, without
  745. // modifying the temporary bitmap -- and we would proceed to
  746. // copy the uninitialized temporary bitmap back to the screen.
  747. ppdev->pfnGetBits(ppdev, psoDst, &rclDst, (POINTL*) &rclScreen);
  748. b = EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, &rclDst, &ptlSrc,
  749. pptlMsk, pbo, pptlBrush, rop4);
  750. ppdev->pfnPutBits(ppdev, psoDst, &rclScreen, (POINTL*) &rclDst);
  751. EngUnlockSurface(psoDst);
  752. Error_4:
  753. EngDeleteSurface(hsurfDst);
  754. Error_3:
  755. EngFreeMem(pjBits);
  756. }
  757. Error_2:
  758. if (bSrcIsScreen)
  759. {
  760. EngUnlockSurface(psoSrc);
  761. Error_1:
  762. EngDeleteSurface(hsurfSrc);
  763. }
  764. Error_0:
  765. return(b);
  766. }
  767. #endif
  768. }
  769. /******************************Public*Routine******************************\
  770. * BOOL DrvBitBlt
  771. *
  772. * Implements the workhorse routine of a display driver.
  773. *
  774. \**************************************************************************/
  775. BOOL DrvBitBlt(
  776. SURFOBJ* psoDst,
  777. SURFOBJ* psoSrc,
  778. SURFOBJ* psoMsk,
  779. CLIPOBJ* pco,
  780. XLATEOBJ* pxlo,
  781. RECTL* prclDst,
  782. POINTL* pptlSrc,
  783. POINTL* pptlMsk,
  784. BRUSHOBJ* pbo,
  785. POINTL* pptlBrush,
  786. ROP4 rop4)
  787. {
  788. PDEV* ppdev;
  789. DSURF* pdsurfDst;
  790. DSURF* pdsurfSrc;
  791. POINTL ptlSrc;
  792. BYTE jClip;
  793. OH* poh;
  794. BOOL bMore;
  795. CLIPENUM ce;
  796. LONG c;
  797. RECTL rcl;
  798. BYTE rop3;
  799. FNFILL* pfnFill;
  800. RBRUSH_COLOR rbc; // Realized brush or solid colour
  801. FNXFER* pfnXfer;
  802. ULONG iSrcBitmapFormat;
  803. ULONG iDir;
  804. BOOL bRet;
  805. XLATECOLORS xlc;
  806. XLATEOBJ xlo;
  807. bRet = TRUE; // Assume success
  808. pdsurfDst = (DSURF*) psoDst->dhsurf; // May be NULL
  809. if (psoSrc == NULL)
  810. {
  811. ///////////////////////////////////////////////////////////////////
  812. // Fills
  813. ///////////////////////////////////////////////////////////////////
  814. // Fills are this function's "raison d'etre", so we handle them
  815. // as quickly as possible:
  816. ASSERTDD(pdsurfDst != NULL,
  817. "Expect only device destinations when no source");
  818. if (pdsurfDst->dt == DT_SCREEN)
  819. {
  820. ppdev = (PDEV*) psoDst->dhpdev;
  821. poh = pdsurfDst->poh;
  822. ppdev->xOffset = poh->x;
  823. ppdev->yOffset = poh->y;
  824. ppdev->xyOffset = poh->xy;
  825. // Make sure it doesn't involve a mask (i.e., it's really a
  826. // Rop3):
  827. rop3 = (BYTE) rop4;
  828. if ((BYTE) (rop4 >> 8) == rop3)
  829. {
  830. // Since 'psoSrc' is NULL, the rop3 had better not indicate
  831. // that we need a source.
  832. ASSERTDD((((rop4 >> 2) ^ (rop4)) & 0x33) == 0,
  833. "Need source but GDI gave us a NULL 'psoSrc'");
  834. // Fill_It:
  835. pfnFill = ppdev->pfnFillSolid; // Default to solid fill
  836. if ((((rop3 >> 4) ^ (rop3)) & 0xf) != 0)
  837. {
  838. // The rop says that a pattern is truly required
  839. // (blackness, for instance, doesn't need one):
  840. rbc.iSolidColor = pbo->iSolidColor;
  841. if (rbc.iSolidColor == -1)
  842. {
  843. if (ppdev->cBpp > 3)
  844. {
  845. // [HWBUG]
  846. goto Punt_It;
  847. }
  848. // Try and realize the pattern brush; by doing
  849. // this call-back, GDI will eventually call us
  850. // again through DrvRealizeBrush:
  851. rbc.prb = pbo->pvRbrush;
  852. if (rbc.prb == NULL)
  853. {
  854. rbc.prb = BRUSHOBJ_pvGetRbrush(pbo);
  855. if (rbc.prb == NULL)
  856. {
  857. // If we couldn't realize the brush, punt
  858. // the call (it may have been a non 8x8
  859. // brush or something, which we can't be
  860. // bothered to handle, so let GDI do the
  861. // drawing):
  862. goto Punt_It;
  863. }
  864. }
  865. pfnFill = ppdev->pfnFillPat;
  866. }
  867. }
  868. // Note that these 2 'if's are more efficient than
  869. // a switch statement:
  870. if ((pco == NULL) || (pco->iDComplexity == DC_TRIVIAL))
  871. {
  872. pfnFill(ppdev, 1, prclDst, rop4, rbc, pptlBrush);
  873. goto All_Done;
  874. }
  875. else if (pco->iDComplexity == DC_RECT)
  876. {
  877. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  878. pfnFill(ppdev, 1, &rcl, rop4, rbc, pptlBrush);
  879. goto All_Done;
  880. }
  881. else
  882. {
  883. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_ANY, 0);
  884. do {
  885. bMore = CLIPOBJ_bEnum(pco, sizeof(ce), (ULONG*) &ce);
  886. c = cIntersect(prclDst, ce.arcl, ce.c);
  887. if (c != 0)
  888. pfnFill(ppdev, c, ce.arcl, rop4, rbc, pptlBrush);
  889. } while (bMore);
  890. goto All_Done;
  891. }
  892. }
  893. }
  894. }
  895. jClip = (pco == NULL) ? DC_TRIVIAL : pco->iDComplexity;
  896. if ((psoSrc != NULL) && (psoSrc->dhsurf != NULL))
  897. {
  898. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  899. if (pdsurfSrc->dt == DT_DIB)
  900. {
  901. // Here we consider putting a DIB DFB back into off-screen
  902. // memory. If there's a translate, it's probably not worth
  903. // moving since we won't be able to use the hardware to do
  904. // the blt (a similar argument could be made for weird rops
  905. // and stuff that we'll only end up having GDI simulate, but
  906. // those should happen infrequently enough that I don't care).
  907. if ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL))
  908. {
  909. ppdev = (PDEV*) psoSrc->dhpdev;
  910. // See 'DrvCopyBits' for some more comments on how this
  911. // moving-it-back-into-off-screen-memory thing works:
  912. if (pdsurfSrc->iUniq == ppdev->iHeapUniq)
  913. {
  914. if (--pdsurfSrc->cBlt == 0)
  915. {
  916. if (bMoveDibToOffscreenDfbIfRoom(ppdev, pdsurfSrc))
  917. goto Continue_It;
  918. }
  919. }
  920. else
  921. {
  922. // Some space was freed up in off-screen memory,
  923. // so reset the counter for this DFB:
  924. pdsurfSrc->iUniq = ppdev->iHeapUniq;
  925. pdsurfSrc->cBlt = HEAP_COUNT_DOWN;
  926. }
  927. }
  928. psoSrc = pdsurfSrc->pso;
  929. // Handle the case where the source is a DIB DFB and the
  930. // destination is a regular bitmap:
  931. if (psoDst->dhsurf == NULL)
  932. goto EngBitBlt_It;
  933. }
  934. }
  935. Continue_It:
  936. if (pdsurfDst != NULL)
  937. {
  938. if (pdsurfDst->dt == DT_DIB)
  939. {
  940. psoDst = pdsurfDst->pso;
  941. // If the destination is a DIB, we can only handle this
  942. // call if the source is not a DIB:
  943. if ((psoSrc == NULL) || (psoSrc->dhsurf == NULL))
  944. goto EngBitBlt_It;
  945. }
  946. }
  947. // At this point, we know that either the source or the destination is
  948. // not a DIB. Check for a DFB to screen, DFB to DFB, or screen to DFB
  949. // case:
  950. if ((psoSrc != NULL) &&
  951. (psoDst->dhsurf != NULL) &&
  952. (psoSrc->dhsurf != NULL))
  953. {
  954. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  955. pdsurfDst = (DSURF*) psoDst->dhsurf;
  956. ASSERTDD(pdsurfSrc->dt == DT_SCREEN, "Expected screen source");
  957. ASSERTDD(pdsurfDst->dt == DT_SCREEN, "Expected screen destination");
  958. ptlSrc.x = pptlSrc->x - (pdsurfDst->poh->x - pdsurfSrc->poh->x);
  959. ptlSrc.y = pptlSrc->y - (pdsurfDst->poh->y - pdsurfSrc->poh->y);
  960. pptlSrc = &ptlSrc;
  961. }
  962. if (psoDst->dhsurf != NULL)
  963. {
  964. pdsurfDst = (DSURF*) psoDst->dhsurf;
  965. ppdev = (PDEV*) psoDst->dhpdev;
  966. ppdev->xOffset = pdsurfDst->poh->x;
  967. ppdev->yOffset = pdsurfDst->poh->y;
  968. ppdev->xyOffset = pdsurfDst->poh->xy;
  969. }
  970. else
  971. {
  972. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  973. ppdev = (PDEV*) psoSrc->dhpdev;
  974. ppdev->xOffset = pdsurfSrc->poh->x;
  975. ppdev->yOffset = pdsurfSrc->poh->y;
  976. ppdev->xyOffset = pdsurfSrc->poh->xy;
  977. }
  978. if (((rop4 >> 8) & 0xff) == (rop4 & 0xff))
  979. {
  980. // Since we've already handled the cases where the ROP4 is really
  981. // a ROP3 and no source is required, we can assert...
  982. ASSERTDD((psoSrc != NULL) && (pptlSrc != NULL),
  983. "Expected no-source case to already have been handled");
  984. ///////////////////////////////////////////////////////////////////
  985. // Bitmap transfers
  986. ///////////////////////////////////////////////////////////////////
  987. // Since the foreground and background ROPs are the same, we
  988. // don't have to worry about no stinking masks (it's a simple
  989. // Rop3).
  990. rop3 = (BYTE) rop4; // Make it into a Rop3 (we keep the rop4
  991. // around in case we decide to punt)
  992. if (psoDst->dhsurf != NULL)
  993. {
  994. // The destination is the screen:
  995. if ((rop3 >> 4) == (rop3 & 0xf))
  996. {
  997. // The ROP3 doesn't require a pattern:
  998. if (psoSrc->dhsurf == NULL)
  999. {
  1000. //////////////////////////////////////////////////
  1001. // DIB-to-screen blt
  1002. if (HOST_XFERS_DISABLED(ppdev))
  1003. {
  1004. goto Punt_It;
  1005. }
  1006. iSrcBitmapFormat = psoSrc->iBitmapFormat;
  1007. if (iSrcBitmapFormat == BMF_1BPP)
  1008. {
  1009. if (rop3 == 0xcc)
  1010. {
  1011. //
  1012. // 542x and 5446 family chips will hang when doing
  1013. // monochrome expansion. We have seen this problem
  1014. // extremely infrequently in stress testing. Often
  1015. // on 32x16 blts with the 2x chips. We were unable
  1016. // to programmatically reproduce it with the exact
  1017. // machine that was causing the problem. We even
  1018. // wrote some testing program to excessively test
  1019. // this function while running stress. The test
  1020. // run several weeks and we couldn't repro it.
  1021. //
  1022. // So, for the sake of boosting stress success rate,
  1023. // we just ask GDI do the work for us
  1024. //
  1025. if ( ( ppdev->flCaps & CAPS_IS_542x ) // 542x
  1026. ||( ppdev->ulChipID == 0xB8) ) // 5446
  1027. {
  1028. //
  1029. // For chips like 542x, 5446, it will cause
  1030. // hang from time to time when doing stress
  1031. // testing. So we have to let GDI to do it
  1032. //
  1033. goto Punt_It;
  1034. }
  1035. else
  1036. {
  1037. // [HWBUG]
  1038. // This driver can't handle a monochrome
  1039. // expansion with a foreground rop other
  1040. // than SRCCOPY. The reason is that we
  1041. // separately blt the opaque part first and
  1042. // then blt the foreground over it. The
  1043. // destination bits are no longer valid to
  1044. // be used in a rop requiring them.
  1045. pfnXfer = ppdev->pfnXfer1bpp;
  1046. goto Xfer_It;
  1047. }// if 542x or 5446 chips
  1048. }
  1049. }
  1050. else if ((iSrcBitmapFormat == ppdev->iBitmapFormat) &&
  1051. ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL)))
  1052. {
  1053. if ((rop3 & 0xf) != 0xc)
  1054. {
  1055. pfnXfer = ppdev->pfnXferNative;
  1056. }
  1057. else
  1058. {
  1059. // Plain SRCCOPY blts will be somewhat faster
  1060. // if we go through the memory aperture:
  1061. pfnXfer = vXferNativeSrccopy;
  1062. }
  1063. goto Xfer_It;
  1064. }
  1065. else if ((iSrcBitmapFormat == BMF_4BPP) &&
  1066. (ppdev->iBitmapFormat == BMF_8BPP))
  1067. {
  1068. pfnXfer = ppdev->pfnXfer4bpp;
  1069. goto Xfer_It;
  1070. }
  1071. }
  1072. else // psoSrc->dhsurf != NULL
  1073. {
  1074. if ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL))
  1075. {
  1076. //////////////////////////////////////////////////
  1077. // Screen-to-screen blt with no translate
  1078. if (jClip == DC_TRIVIAL)
  1079. {
  1080. (ppdev->pfnCopyBlt)(ppdev, 1, prclDst, rop4,
  1081. pptlSrc, prclDst);
  1082. goto All_Done;
  1083. }
  1084. else if (jClip == DC_RECT)
  1085. {
  1086. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  1087. {
  1088. (ppdev->pfnCopyBlt)(ppdev, 1, &rcl, rop4,
  1089. pptlSrc, prclDst);
  1090. }
  1091. goto All_Done;
  1092. }
  1093. else
  1094. {
  1095. // Don't forget that we'll have to draw the
  1096. // rectangles in the correct direction:
  1097. if (pptlSrc->y >= prclDst->top)
  1098. {
  1099. if (pptlSrc->x >= prclDst->left)
  1100. iDir = CD_RIGHTDOWN;
  1101. else
  1102. iDir = CD_LEFTDOWN;
  1103. }
  1104. else
  1105. {
  1106. if (pptlSrc->x >= prclDst->left)
  1107. iDir = CD_RIGHTUP;
  1108. else
  1109. iDir = CD_LEFTUP;
  1110. }
  1111. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES,
  1112. iDir, 0);
  1113. do {
  1114. bMore = CLIPOBJ_bEnum(pco, sizeof(ce),
  1115. (ULONG*) &ce);
  1116. c = cIntersect(prclDst, ce.arcl, ce.c);
  1117. if (c != 0)
  1118. {
  1119. (ppdev->pfnCopyBlt)(ppdev, c, ce.arcl,
  1120. rop4, pptlSrc, prclDst);
  1121. }
  1122. } while (bMore);
  1123. goto All_Done;
  1124. }
  1125. }
  1126. }
  1127. }
  1128. else if (psoSrc->iBitmapFormat == BMF_1BPP)
  1129. {
  1130. if (HOST_XFERS_DISABLED(ppdev))
  1131. {
  1132. goto Punt_It;
  1133. }
  1134. if ((rop4 == 0xE2E2) &&
  1135. (pbo->iSolidColor != 0xffffffff) &&
  1136. //pxlo must be non NULL since the rop is E2E2
  1137. (pxlo->pulXlate[0] == 0) &&
  1138. (pxlo->pulXlate[1] == (ULONG)((1<<PELS_TO_BYTES(8)) - 1)))
  1139. {
  1140. if ( (ppdev->flCaps & CAPS_IS_542x)
  1141. ||(ppdev->ulChipID == 0xB8) )
  1142. {
  1143. //
  1144. // For chips like 542x, 5446, it will cause
  1145. // hang from time to time when doing stress
  1146. // testing. We have seen this problem
  1147. // extremely infrequently in stress testing. Often
  1148. // on 32x16 blts with the 2x chips. We were unable
  1149. // to programmatically reproduce it with the exact
  1150. // machine that was causing the problem. We even
  1151. // wrote some testing program to excessively test
  1152. // this function while running stress. The test
  1153. // run several weeks and we couldn't repro it.
  1154. //
  1155. // So, for the sake of boosting stress success rate,
  1156. // we just ask GDI do the work for us
  1157. //
  1158. goto Punt_It;
  1159. }
  1160. else
  1161. {
  1162. //
  1163. // A BitBlt with the rop E2E2 (DSPDxax), a monochrome
  1164. // source, a foreground color of white, and a background
  1165. //color of black is equivalent to a monochrome expansion
  1166. // with transparency. All ones in the source expand to
  1167. //the brush color, and all zeros in the source expand to
  1168. // the destination color.
  1169. //
  1170. xlo.pulXlate = (ULONG*) &xlc;
  1171. xlc.iForeColor = pbo->iSolidColor;
  1172. xlc.iBackColor = 0;
  1173. pxlo = &xlo;
  1174. rop4 = 0xCCAA;
  1175. pfnXfer = ppdev->pfnXfer1bpp;
  1176. goto Xfer_It;
  1177. }// if 542x or 5446 chips
  1178. }
  1179. }
  1180. }
  1181. else
  1182. {
  1183. #if defined(_X86_)
  1184. {
  1185. // We special case screen to monochrome blts because they
  1186. // happen fairly often. We only handle SRCCOPY rops and
  1187. // monochrome destinations (to handle a true 1bpp DIB
  1188. // destination, we would have to do near-colour searches
  1189. // on every colour; as it is, the foreground colour gets
  1190. // mapped to '1', and everything else gets mapped to '0'):
  1191. if ((psoDst->iBitmapFormat == BMF_1BPP) &&
  1192. (rop3 == 0xcc) &&
  1193. (pxlo->flXlate & XO_TO_MONO) &&
  1194. (ppdev->iBitmapFormat != BMF_24BPP))
  1195. {
  1196. pfnXfer = vXferScreenTo1bpp;
  1197. psoSrc = psoDst; // A misnomer, I admit
  1198. goto Xfer_It;
  1199. }
  1200. }
  1201. #endif // i386
  1202. }
  1203. }
  1204. #if 0
  1205. // [WORK] - Implement transparent brushes and then uncomment this block
  1206. // and the Fill_It label above.
  1207. else if ((psoMsk == NULL) &&
  1208. (rop4 & 0xff00) == (0xaa00) &&
  1209. ((((rop4 >> 2) ^ (rop4)) & 0x33) == 0))
  1210. {
  1211. // The only time GDI will ask us to do a true rop4 using the brush
  1212. // mask is when the brush is 1bpp, and the background rop is AA
  1213. // (meaning it's a NOP):
  1214. rop3 = (BYTE) rop4;
  1215. goto Fill_It;
  1216. }
  1217. #endif
  1218. // Just fall through to Punt_It...
  1219. Punt_It:
  1220. bRet = bPuntBlt(psoDst,
  1221. psoSrc,
  1222. psoMsk,
  1223. pco,
  1224. pxlo,
  1225. prclDst,
  1226. pptlSrc,
  1227. pptlMsk,
  1228. pbo,
  1229. pptlBrush,
  1230. rop4);
  1231. goto All_Done;
  1232. //////////////////////////////////////////////////////////////////////
  1233. // Common bitmap transfer
  1234. Xfer_It:
  1235. if (jClip == DC_TRIVIAL)
  1236. {
  1237. pfnXfer(ppdev, 1, prclDst, rop4, psoSrc, pptlSrc, prclDst, pxlo);
  1238. goto All_Done;
  1239. }
  1240. else if (jClip == DC_RECT)
  1241. {
  1242. if (bIntersect(prclDst, &pco->rclBounds, &rcl))
  1243. pfnXfer(ppdev, 1, &rcl, rop4, psoSrc, pptlSrc, prclDst, pxlo);
  1244. goto All_Done;
  1245. }
  1246. else
  1247. {
  1248. CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES,
  1249. CD_ANY, 0);
  1250. do {
  1251. bMore = CLIPOBJ_bEnum(pco, sizeof(ce),
  1252. (ULONG*) &ce);
  1253. c = cIntersect(prclDst, ce.arcl, ce.c);
  1254. if (c != 0)
  1255. {
  1256. pfnXfer(ppdev, c, ce.arcl, rop4, psoSrc,
  1257. pptlSrc, prclDst, pxlo);
  1258. }
  1259. } while (bMore);
  1260. goto All_Done;
  1261. }
  1262. ////////////////////////////////////////////////////////////////////////
  1263. // Common DIB blt
  1264. EngBitBlt_It:
  1265. // Our driver doesn't handle any blt's between two DIBs. Normally
  1266. // a driver doesn't have to worry about this, but we do because
  1267. // we have DFBs that may get moved from off-screen memory to a DIB,
  1268. // where we have GDI do all the drawing. GDI does DIB drawing at
  1269. // a reasonable speed (unless one of the surfaces is a device-
  1270. // managed surface...)
  1271. //
  1272. // If either the source or destination surface in an EngBitBlt
  1273. // call-back is a device-managed surface (meaning it's not a DIB
  1274. // that GDI can draw with), GDI will automatically allocate memory
  1275. // and call the driver's DrvCopyBits routine to create a DIB copy
  1276. // that it can use. So this means that this could handle all 'punts',
  1277. // and we could conceivably get rid of bPuntBlt. But this would have
  1278. // a bad performance impact because of the extra memory allocations
  1279. // and bitmap copies -- you really don't want to do this unless you
  1280. // have to (or your surface was created such that GDI can draw
  1281. // directly onto it) -- I've been burned by this because it's not
  1282. // obvious that the performance impact is so bad.
  1283. //
  1284. // That being said, we only call EngBitBlt when all the surfaces
  1285. // are DIBs:
  1286. bRet = EngBitBlt(psoDst, psoSrc, psoMsk, pco, pxlo, prclDst,
  1287. pptlSrc, pptlMsk, pbo, pptlBrush, rop4);
  1288. All_Done:
  1289. return(bRet);
  1290. }
  1291. /******************************Public*Routine******************************\
  1292. * BOOL DrvCopyBits
  1293. *
  1294. * Do fast bitmap copies.
  1295. *
  1296. * Note that GDI will (usually) automatically adjust the blt extents to
  1297. * adjust for any rectangular clipping, so we'll rarely see DC_RECT
  1298. * clipping in this routine (and as such, we don't bother special casing
  1299. * it).
  1300. *
  1301. * I'm not sure if the performance benefit from this routine is actually
  1302. * worth the increase in code size, since SRCCOPY BitBlts are hardly the
  1303. * most common drawing operation we'll get. But what the heck.
  1304. *
  1305. * It's faster to do straight SRCCOPY bitblt's through the memory
  1306. * aperture than to use the data transfer register; as such, this
  1307. * routine is the logical place to put this special case.
  1308. *
  1309. \**************************************************************************/
  1310. BOOL DrvCopyBits(
  1311. SURFOBJ* psoDst,
  1312. SURFOBJ* psoSrc,
  1313. CLIPOBJ* pco,
  1314. XLATEOBJ* pxlo,
  1315. RECTL* prclDst,
  1316. POINTL* pptlSrc)
  1317. {
  1318. PDEV* ppdev;
  1319. DSURF* pdsurfSrc;
  1320. DSURF* pdsurfDst;
  1321. RECTL rcl;
  1322. POINTL ptl;
  1323. OH* pohSrc;
  1324. OH* pohDst;
  1325. // DrvCopyBits is a fast-path for SRCCOPY blts. But it can still be
  1326. // pretty complicated: there can be translates, clipping, RLEs,
  1327. // bitmaps that aren't the same format as the screen, plus
  1328. // screen-to-screen, DIB-to-screen or screen-to-DIB operations,
  1329. // not to mention DFBs (device format bitmaps).
  1330. //
  1331. // Rather than making this routine almost as big as DrvBitBlt, I'll
  1332. // handle here only the speed-critical cases, and punt the rest to
  1333. // our DrvBitBlt routine.
  1334. //
  1335. // We'll try to handle anything that doesn't involve clipping:
  1336. if (((pco == NULL) || (pco->iDComplexity == DC_TRIVIAL)) &&
  1337. ((pxlo == NULL) || (pxlo->flXlate & XO_TRIVIAL)))
  1338. {
  1339. if (psoDst->dhsurf != NULL)
  1340. {
  1341. // We know the destination is either a DFB or the screen:
  1342. ppdev = (PDEV*) psoDst->dhpdev;
  1343. pdsurfDst = (DSURF*) psoDst->dhsurf;
  1344. // See if the source is a plain DIB:
  1345. if (psoSrc->dhsurf != NULL)
  1346. {
  1347. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1348. // Make sure the destination is really the screen or an
  1349. // off-screen DFB (i.e., not a DFB that we've converted
  1350. // to a DIB):
  1351. if (pdsurfDst->dt == DT_SCREEN)
  1352. {
  1353. ASSERTDD(psoSrc->dhsurf != NULL, "Can't be a DIB");
  1354. if (pdsurfSrc->dt == DT_SCREEN)
  1355. {
  1356. Screen_To_Screen:
  1357. //////////////////////////////////////////////////////
  1358. // Screen-to-screen
  1359. ASSERTDD((psoSrc->dhsurf != NULL) &&
  1360. (pdsurfSrc->dt == DT_SCREEN) &&
  1361. (psoDst->dhsurf != NULL) &&
  1362. (pdsurfDst->dt == DT_SCREEN),
  1363. "Should be a screen-to-screen case");
  1364. // pfnCopyBlt takes relative coordinates (relative
  1365. // to the destination surface, that is), so we have
  1366. // to change the start point to be relative to the
  1367. // destination surface too:
  1368. pohSrc = pdsurfSrc->poh;
  1369. pohDst = pdsurfDst->poh;
  1370. ptl.x = pptlSrc->x - (pohDst->x - pohSrc->x);
  1371. ptl.y = pptlSrc->y - (pohDst->y - pohSrc->y);
  1372. ppdev->xOffset = pohDst->x;
  1373. ppdev->yOffset = pohDst->y;
  1374. ppdev->xyOffset = pohDst->xy;
  1375. (ppdev->pfnCopyBlt)(ppdev, 1, prclDst, 0xcccc, &ptl,
  1376. prclDst);
  1377. return(TRUE);
  1378. }
  1379. else // (pdsurfSrc->dt != DT_SCREEN)
  1380. {
  1381. // Ah ha, the source is a DFB that's really a DIB.
  1382. ASSERTDD(psoDst->dhsurf != NULL,
  1383. "Destination can't be a DIB here");
  1384. /////////////////////////////////////////////////////
  1385. // Put It Back Into Off-screen?
  1386. //
  1387. // We take this opportunity to decide if we want to
  1388. // put the DIB back into off-screen memory. This is
  1389. // a pretty good place to do it because we have to
  1390. // copy the bits to some portion of the screen,
  1391. // anyway. So we would incur only an extra screen-to-
  1392. // screen blt at this time, much of which will be
  1393. // over-lapped with the CPU.
  1394. //
  1395. // The simple approach we have taken is to move a DIB
  1396. // back into off-screen memory only if there's already
  1397. // room -- we won't throw stuff out to make space
  1398. // (because it's tough to know what ones to throw out,
  1399. // and it's easy to get into thrashing scenarios).
  1400. //
  1401. // Because it takes some time to see if there's room
  1402. // in off-screen memory, we only check one in
  1403. // HEAP_COUNT_DOWN times if there's room. To bias
  1404. // in favour of bitmaps that are often blt, the
  1405. // counters are reset every time any space is freed
  1406. // up in off-screen memory. We also don't bother
  1407. // checking if no space has been freed since the
  1408. // last time we checked for this DIB.
  1409. if (pdsurfSrc->iUniq == ppdev->iHeapUniq)
  1410. {
  1411. if (--pdsurfSrc->cBlt == 0)
  1412. {
  1413. if (bMoveDibToOffscreenDfbIfRoom(ppdev,
  1414. pdsurfSrc))
  1415. goto Screen_To_Screen;
  1416. }
  1417. }
  1418. else
  1419. {
  1420. // Some space was freed up in off-screen memory,
  1421. // so reset the counter for this DFB:
  1422. pdsurfSrc->iUniq = ppdev->iHeapUniq;
  1423. pdsurfSrc->cBlt = HEAP_COUNT_DOWN;
  1424. }
  1425. // Since the destination is definitely the screen,
  1426. // we don't have to worry about creating a DIB to
  1427. // DIB copy case (for which we would have to call
  1428. // EngCopyBits):
  1429. psoSrc = pdsurfSrc->pso;
  1430. goto DIB_To_Screen;
  1431. }
  1432. }
  1433. else // (pdsurfDst->dt != DT_SCREEN)
  1434. {
  1435. // Because the source is not a DIB, we don't have to
  1436. // worry about creating a DIB to DIB case here (although
  1437. // we'll have to check later to see if the source is
  1438. // really a DIB that's masquerading as a DFB...)
  1439. ASSERTDD(psoSrc->dhsurf != NULL,
  1440. "Source can't be a DIB here");
  1441. psoDst = pdsurfDst->pso;
  1442. goto Screen_To_DIB;
  1443. }
  1444. }
  1445. else if (psoSrc->iBitmapFormat == ppdev->iBitmapFormat)
  1446. {
  1447. // Make sure the destination is really the screen:
  1448. if (pdsurfDst->dt == DT_SCREEN)
  1449. {
  1450. DIB_To_Screen:
  1451. //////////////////////////////////////////////////////
  1452. // DIB-to-screen
  1453. ASSERTDD((psoDst->dhsurf != NULL) &&
  1454. (pdsurfDst->dt == DT_SCREEN) &&
  1455. (psoSrc->dhsurf == NULL) &&
  1456. (psoSrc->iBitmapFormat == ppdev->iBitmapFormat),
  1457. "Should be a DIB-to-screen case");
  1458. // ppdev->pfnPutBits takes absolute screen coordinates, so
  1459. // we have to muck with the destination rectangle:
  1460. pohDst = pdsurfDst->poh;
  1461. rcl.left = prclDst->left + pohDst->x;
  1462. rcl.right = prclDst->right + pohDst->x;
  1463. rcl.top = prclDst->top + pohDst->y;
  1464. rcl.bottom = prclDst->bottom + pohDst->y;
  1465. // We use the memory aperture to do the transfer,
  1466. // because that is supposed to be faster for SRCCOPY
  1467. // blts than using the data-transfer register:
  1468. ppdev->pfnPutBits(ppdev, psoSrc, &rcl, pptlSrc);
  1469. return(TRUE);
  1470. }
  1471. }
  1472. }
  1473. else // (psoDst->dhsurf == NULL)
  1474. {
  1475. Screen_To_DIB:
  1476. pdsurfSrc = (DSURF*) psoSrc->dhsurf;
  1477. ppdev = (PDEV*) psoSrc->dhpdev;
  1478. if (psoDst->iBitmapFormat == ppdev->iBitmapFormat)
  1479. {
  1480. if (pdsurfSrc->dt == DT_SCREEN)
  1481. {
  1482. //////////////////////////////////////////////////////
  1483. // Screen-to-DIB
  1484. ASSERTDD((psoSrc->dhsurf != NULL) &&
  1485. (pdsurfSrc->dt == DT_SCREEN) &&
  1486. (psoDst->dhsurf == NULL) &&
  1487. (psoDst->iBitmapFormat == ppdev->iBitmapFormat),
  1488. "Should be a screen-to-DIB case");
  1489. // ppdev->pfnGetBits takes absolute screen coordinates, so we have
  1490. // to muck with the source point:
  1491. pohSrc = pdsurfSrc->poh;
  1492. ptl.x = pptlSrc->x + pohSrc->x;
  1493. ptl.y = pptlSrc->y + pohSrc->y;
  1494. ppdev->pfnGetBits(ppdev, psoDst, prclDst, &ptl);
  1495. return(TRUE);
  1496. }
  1497. else
  1498. {
  1499. // The source is a DFB that's really a DIB. Since we
  1500. // know that the destination is a DIB, we've got a DIB
  1501. // to DIB operation, and should call EngCopyBits:
  1502. psoSrc = pdsurfSrc->pso;
  1503. goto EngCopyBits_It;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. // We can't call DrvBitBlt if we've accidentally converted both
  1509. // surfaces to DIBs, because it isn't equipped to handle it:
  1510. ASSERTDD((psoSrc->dhsurf != NULL) ||
  1511. (psoDst->dhsurf != NULL),
  1512. "Accidentally converted both surfaces to DIBs");
  1513. /////////////////////////////////////////////////////////////////
  1514. // A DrvCopyBits is after all just a simplified DrvBitBlt:
  1515. return(DrvBitBlt(psoDst, psoSrc, NULL, pco, pxlo, prclDst, pptlSrc, NULL,
  1516. NULL, NULL, 0x0000CCCC));
  1517. EngCopyBits_It:
  1518. ASSERTDD((psoDst->dhsurf == NULL) &&
  1519. (psoSrc->dhsurf == NULL),
  1520. "Both surfaces should be DIBs to call EngCopyBits");
  1521. return(EngCopyBits(psoDst, psoSrc, pco, pxlo, prclDst, pptlSrc));
  1522. }