Sync with trunk head (r48786)
[reactos.git] / subsystems / win32 / win32k / eng / bitblt.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI BitBlt Functions
5 * FILE: subsys/win32k/eng/bitblt.c
6 * PROGRAMER: Jason Filby
7 * Timo Kreuzer
8 * REVISION HISTORY:
9 * 2/10/1999: Created
10 */
11
12 #include <win32k.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 typedef BOOLEAN (APIENTRY *PBLTRECTFUNC)(SURFOBJ* OutputObj,
18 SURFOBJ* InputObj,
19 SURFOBJ* Mask,
20 XLATEOBJ* ColorTranslation,
21 RECTL* OutputRect,
22 POINTL* InputPoint,
23 POINTL* MaskOrigin,
24 BRUSHOBJ* pbo,
25 POINTL* BrushOrigin,
26 ROP4 Rop4);
27
28 static BOOLEAN APIENTRY
29 BltMask(SURFOBJ* psoDest,
30 SURFOBJ* psoSource, // unused
31 SURFOBJ* psoMask,
32 XLATEOBJ* ColorTranslation, // unused
33 RECTL* prclDest,
34 POINTL* pptlSource, // unused
35 POINTL* pptlMask,
36 BRUSHOBJ* pbo,
37 POINTL* pptlBrush,
38 ROP4 Rop4)
39 {
40 LONG x, y;
41 BYTE *pjMskLine, *pjMskCurrent;
42 BYTE fjMaskBit0, fjMaskBit;
43 /* Pattern brushes */
44 PEBRUSHOBJ pebo = NULL;
45 SURFOBJ *psoPattern = NULL;
46 PSURFACE psurfPattern;
47 ULONG PatternWidth = 0, PatternHeight = 0;
48 LONG PatternX0 = 0, PatternX = 0, PatternY = 0;
49 PFN_DIB_PutPixel fnDest_PutPixel = NULL;
50 PFN_DIB_GetPixel fnPattern_GetPixel = NULL;
51 ULONG Pattern = 0;
52 HBITMAP hbmPattern;
53
54 ASSERT(psoSource == NULL);
55 ASSERT(pptlSource == NULL);
56
57 if (psoMask == NULL)
58 {
59 return FALSE;
60 }
61
62 if (pbo && pbo->iSolidColor == 0xFFFFFFFF)
63 {
64 pebo = CONTAINING_RECORD(pbo, EBRUSHOBJ, BrushObject);
65
66 hbmPattern = EBRUSHOBJ_pvGetEngBrush(pebo);
67 psurfPattern = SURFACE_LockSurface(hbmPattern);
68 if (psurfPattern != NULL)
69 {
70 psoPattern = &psurfPattern->SurfObj;
71 PatternWidth = psoPattern->sizlBitmap.cx;
72 PatternHeight = psoPattern->sizlBitmap.cy;
73 fnPattern_GetPixel = DibFunctionsForBitmapFormat[psoPattern->iBitmapFormat].DIB_GetPixel;
74 }
75 }
76 else
77 psurfPattern = NULL;
78
79 pjMskLine = (PBYTE)psoMask->pvScan0 + pptlMask->y * psoMask->lDelta + (pptlMask->x >> 3);
80 fjMaskBit0 = 0x80 >> (pptlMask->x & 0x07);
81
82 fnDest_PutPixel = DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel;
83 if (psurfPattern)
84 {
85 PatternY = (prclDest->top - pptlBrush->y) % PatternHeight;
86 if (PatternY < 0)
87 {
88 PatternY += PatternHeight;
89 }
90 PatternX0 = (prclDest->left - pptlBrush->x) % PatternWidth;
91 if (PatternX0 < 0)
92 {
93 PatternX0 += PatternWidth;
94 }
95
96 for (y = prclDest->top; y < prclDest->bottom; y++)
97 {
98 pjMskCurrent = pjMskLine;
99 fjMaskBit = fjMaskBit0;
100 PatternX = PatternX0;
101
102 for (x = prclDest->left; x < prclDest->right; x++)
103 {
104 if (*pjMskCurrent & fjMaskBit)
105 {
106 fnDest_PutPixel(psoDest, x, y,
107 fnPattern_GetPixel(psoPattern, PatternX, PatternY));
108 }
109 fjMaskBit = _rotr8(fjMaskBit, 1);
110 pjMskCurrent += (fjMaskBit >> 7);
111 PatternX++;
112 PatternX %= PatternWidth;
113 }
114 pjMskLine += psoMask->lDelta;
115 PatternY++;
116 PatternY %= PatternHeight;
117 }
118 }
119 else
120 {
121 Pattern = pbo ? pbo->iSolidColor : 0;
122 for (y = prclDest->top; y < prclDest->bottom; y++)
123 {
124 pjMskCurrent = pjMskLine;
125 fjMaskBit = fjMaskBit0;
126
127 for (x = prclDest->left; x < prclDest->right; x++)
128 {
129 if (*pjMskCurrent & fjMaskBit)
130 {
131 fnDest_PutPixel(psoDest, x, y, Pattern);
132 }
133 fjMaskBit = _rotr8(fjMaskBit, 1);
134 pjMskCurrent += (fjMaskBit >> 7);
135 }
136 pjMskLine += psoMask->lDelta;
137 }
138 }
139
140 if (psurfPattern)
141 SURFACE_UnlockSurface(psurfPattern);
142
143 return TRUE;
144 }
145
146 static BOOLEAN APIENTRY
147 BltPatCopy(SURFOBJ* Dest,
148 SURFOBJ* Source,
149 SURFOBJ* Mask,
150 XLATEOBJ* ColorTranslation,
151 RECTL* DestRect,
152 POINTL* SourcePoint,
153 POINTL* MaskPoint,
154 BRUSHOBJ* pbo,
155 POINTL* BrushPoint,
156 ROP4 Rop4)
157 {
158 // These functions are assigned if we're working with a DIB
159 // The assigned functions depend on the bitsPerPixel of the DIB
160
161 DibFunctionsForBitmapFormat[Dest->iBitmapFormat].DIB_ColorFill(Dest, DestRect, pbo ? pbo->iSolidColor : 0);
162
163 return TRUE;
164 }
165
166 static BOOLEAN APIENTRY
167 CallDibBitBlt(SURFOBJ* OutputObj,
168 SURFOBJ* InputObj,
169 SURFOBJ* Mask,
170 XLATEOBJ* ColorTranslation,
171 RECTL* OutputRect,
172 POINTL* InputPoint,
173 POINTL* MaskOrigin,
174 BRUSHOBJ* pbo,
175 POINTL* BrushOrigin,
176 ROP4 Rop4)
177 {
178 BLTINFO BltInfo;
179 PEBRUSHOBJ GdiBrush = NULL;
180 SURFACE *psurfPattern;
181 BOOLEAN Result;
182 HBITMAP hbmPattern;
183
184 BltInfo.DestSurface = OutputObj;
185 BltInfo.SourceSurface = InputObj;
186 BltInfo.PatternSurface = NULL;
187 BltInfo.XlateSourceToDest = ColorTranslation;
188 BltInfo.DestRect = *OutputRect;
189 BltInfo.SourcePoint = *InputPoint;
190
191 if (ROP3_TO_ROP4(SRCCOPY) == Rop4)
192 return DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo);
193
194 BltInfo.Brush = pbo;
195 BltInfo.BrushOrigin = *BrushOrigin;
196 BltInfo.Rop4 = Rop4;
197
198 /* Pattern brush */
199 if (ROP4_USES_PATTERN(Rop4) && pbo && pbo->iSolidColor == 0xFFFFFFFF)
200 {
201 GdiBrush = CONTAINING_RECORD(pbo, EBRUSHOBJ, BrushObject);
202 hbmPattern = EBRUSHOBJ_pvGetEngBrush(GdiBrush);
203 psurfPattern = SURFACE_LockSurface(hbmPattern);
204 if (psurfPattern)
205 {
206 BltInfo.PatternSurface = &psurfPattern->SurfObj;
207 }
208 else
209 {
210 /* FIXME - What to do here? */
211 }
212 }
213 else
214 {
215 psurfPattern = NULL;
216 }
217
218 Result = DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_BitBlt(&BltInfo);
219
220 /* Pattern brush */
221 if (psurfPattern)
222 {
223 SURFACE_UnlockSurface(psurfPattern);
224 }
225
226 return Result;
227 }
228
229 INT __cdecl abs(INT nm);
230
231
232 /*
233 * @implemented
234 */
235 BOOL APIENTRY
236 NtGdiEngBitBlt(
237 IN SURFOBJ *psoTrg,
238 IN SURFOBJ *psoSrc,
239 IN SURFOBJ *psoMask,
240 IN CLIPOBJ *pco,
241 IN XLATEOBJ *pxlo,
242 IN RECTL *prclTrg,
243 IN POINTL *pptlSrc,
244 IN POINTL *pptlMask,
245 IN BRUSHOBJ *pbo,
246 IN POINTL *pptlBrush,
247 IN ROP4 rop4 )
248 {
249 RECTL rclTrg;
250 POINTL ptlSrc;
251 POINTL ptlMask;
252 POINTL ptlBrush;
253
254 _SEH2_TRY
255 {
256 ProbeForRead(prclTrg, sizeof(RECTL), 1);
257 RtlCopyMemory(&rclTrg,prclTrg, sizeof(RECTL));
258
259 ProbeForRead(pptlSrc, sizeof(POINTL), 1);
260 RtlCopyMemory(&ptlSrc, pptlSrc, sizeof(POINTL));
261
262 ProbeForRead(pptlMask, sizeof(POINTL), 1);
263 RtlCopyMemory(&ptlMask, pptlMask, sizeof(POINTL));
264
265 ProbeForRead(pptlBrush, sizeof(POINTL), 1);
266 RtlCopyMemory(&ptlBrush, pptlBrush, sizeof(POINTL));
267
268 }
269 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
270 {
271 _SEH2_YIELD(return FALSE);
272 }
273 _SEH2_END;
274
275 return EngBitBlt(psoTrg, psoSrc, psoMask, pco, pxlo, &rclTrg, &ptlSrc, &ptlMask, pbo, &ptlBrush, rop4);
276 }
277
278 /*
279 * @implemented
280 */
281 BOOL APIENTRY
282 EngBitBlt(SURFOBJ *DestObj,
283 SURFOBJ *SourceObj,
284 SURFOBJ *Mask,
285 CLIPOBJ *ClipRegion,
286 XLATEOBJ *ColorTranslation,
287 RECTL *DestRect,
288 POINTL *SourcePoint,
289 POINTL *MaskOrigin,
290 BRUSHOBJ *pbo,
291 POINTL *BrushOrigin,
292 ROP4 rop4)
293 {
294 BYTE clippingType;
295 RECTL CombinedRect;
296 RECT_ENUM RectEnum;
297 BOOL EnumMore;
298 POINTL InputPoint;
299 RECTL InputRect;
300 RECTL OutputRect;
301 SURFOBJ* InputObj = 0;
302 SURFOBJ* OutputObj;
303 PBLTRECTFUNC BltRectFunc;
304 BOOLEAN Ret = TRUE;
305 RECTL ClipRect;
306 unsigned i;
307 POINTL Pt;
308 ULONG Direction;
309 BOOL UsesSource;
310 POINTL AdjustedBrushOrigin;
311
312 UsesSource = ROP4_USES_SOURCE(rop4);
313 if (R4_NOOP == rop4)
314 {
315 /* Copy destination onto itself: nop */
316 return TRUE;
317 }
318
319 OutputRect = *DestRect;
320 if (OutputRect.right < OutputRect.left)
321 {
322 OutputRect.left = DestRect->right;
323 OutputRect.right = DestRect->left;
324 }
325 if (OutputRect.bottom < OutputRect.top)
326 {
327 OutputRect.left = DestRect->right;
328 OutputRect.right = DestRect->left;
329 }
330
331 if (UsesSource)
332 {
333 if (NULL == SourcePoint)
334 {
335 return FALSE;
336 }
337
338 /* Make sure we don't try to copy anything outside the valid source
339 region */
340 InputPoint = *SourcePoint;
341 if (InputPoint.x < 0)
342 {
343 OutputRect.left -= InputPoint.x;
344 InputPoint.x = 0;
345 }
346 if (InputPoint.y < 0)
347 {
348 OutputRect.top -= InputPoint.y;
349 InputPoint.y = 0;
350 }
351 if (SourceObj->sizlBitmap.cx < InputPoint.x +
352 OutputRect.right - OutputRect.left)
353 {
354 OutputRect.right = OutputRect.left +
355 SourceObj->sizlBitmap.cx - InputPoint.x;
356 }
357 if (SourceObj->sizlBitmap.cy < InputPoint.y +
358 OutputRect.bottom - OutputRect.top)
359 {
360 OutputRect.bottom = OutputRect.top +
361 SourceObj->sizlBitmap.cy - InputPoint.y;
362 }
363
364 InputRect.left = InputPoint.x;
365 InputRect.right = InputPoint.x + (OutputRect.right - OutputRect.left);
366 InputRect.top = InputPoint.y;
367 InputRect.bottom = InputPoint.y + (OutputRect.bottom - OutputRect.top);
368
369 InputObj = SourceObj;
370 }
371 else
372 {
373 InputRect.left = 0;
374 InputRect.right = DestRect->right - DestRect->left;
375 InputRect.top = 0;
376 InputRect.bottom = DestRect->bottom - DestRect->top;
377 }
378
379 if (NULL != ClipRegion)
380 {
381 if (OutputRect.left < ClipRegion->rclBounds.left)
382 {
383 InputRect.left += ClipRegion->rclBounds.left - OutputRect.left;
384 InputPoint.x += ClipRegion->rclBounds.left - OutputRect.left;
385 OutputRect.left = ClipRegion->rclBounds.left;
386 }
387 if (ClipRegion->rclBounds.right < OutputRect.right)
388 {
389 InputRect.right -= OutputRect.right - ClipRegion->rclBounds.right;
390 OutputRect.right = ClipRegion->rclBounds.right;
391 }
392 if (OutputRect.top < ClipRegion->rclBounds.top)
393 {
394 InputRect.top += ClipRegion->rclBounds.top - OutputRect.top;
395 InputPoint.y += ClipRegion->rclBounds.top - OutputRect.top;
396 OutputRect.top = ClipRegion->rclBounds.top;
397 }
398 if (ClipRegion->rclBounds.bottom < OutputRect.bottom)
399 {
400 InputRect.bottom -= OutputRect.bottom - ClipRegion->rclBounds.bottom;
401 OutputRect.bottom = ClipRegion->rclBounds.bottom;
402 }
403 }
404
405 /* Check for degenerate case: if height or width of OutputRect is 0 pixels
406 there's nothing to do */
407 if (OutputRect.right <= OutputRect.left ||
408 OutputRect.bottom <= OutputRect.top)
409 {
410 return TRUE;
411 }
412
413 OutputObj = DestObj;
414
415 if (BrushOrigin)
416 {
417 AdjustedBrushOrigin.x = BrushOrigin->x;
418 AdjustedBrushOrigin.y = BrushOrigin->y;
419 }
420 else
421 {
422 AdjustedBrushOrigin.x = 0;
423 AdjustedBrushOrigin.y = 0;
424 }
425
426 /* Determine clipping type */
427 if (ClipRegion == (CLIPOBJ *) NULL)
428 {
429 clippingType = DC_TRIVIAL;
430 }
431 else
432 {
433 clippingType = ClipRegion->iDComplexity;
434 }
435
436 if (R4_MASK == rop4)
437 {
438 BltRectFunc = BltMask;
439 }
440 else if (ROP3_TO_ROP4(PATCOPY) == rop4)
441 {
442 if (pbo && pbo->iSolidColor == 0xFFFFFFFF)
443 BltRectFunc = CallDibBitBlt;
444 else
445 BltRectFunc = BltPatCopy;
446 }
447 else
448 {
449 BltRectFunc = CallDibBitBlt;
450 }
451
452
453 switch (clippingType)
454 {
455 case DC_TRIVIAL:
456 Ret = (*BltRectFunc)(OutputObj, InputObj, Mask, ColorTranslation,
457 &OutputRect, &InputPoint, MaskOrigin, pbo,
458 &AdjustedBrushOrigin, rop4);
459 break;
460 case DC_RECT:
461 /* Clip the blt to the clip rectangle */
462 ClipRect.left = ClipRegion->rclBounds.left;
463 ClipRect.right = ClipRegion->rclBounds.right;
464 ClipRect.top = ClipRegion->rclBounds.top;
465 ClipRect.bottom = ClipRegion->rclBounds.bottom;
466 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
467 {
468 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
469 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
470 Ret = (*BltRectFunc)(OutputObj, InputObj, Mask, ColorTranslation,
471 &CombinedRect, &Pt, MaskOrigin, pbo,
472 &AdjustedBrushOrigin, rop4);
473 }
474 break;
475 case DC_COMPLEX:
476 Ret = TRUE;
477 if (OutputObj == InputObj)
478 {
479 if (OutputRect.top < InputPoint.y)
480 {
481 Direction = OutputRect.left < InputPoint.x ?
482 CD_RIGHTDOWN : CD_LEFTDOWN;
483 }
484 else
485 {
486 Direction = OutputRect.left < InputPoint.x ?
487 CD_RIGHTUP : CD_LEFTUP;
488 }
489 }
490 else
491 {
492 Direction = CD_ANY;
493 }
494 CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, Direction, 0);
495 do
496 {
497 EnumMore = CLIPOBJ_bEnum(ClipRegion,(ULONG) sizeof(RectEnum),
498 (PVOID) &RectEnum);
499
500 for (i = 0; i < RectEnum.c; i++)
501 {
502 ClipRect.left = RectEnum.arcl[i].left;
503 ClipRect.right = RectEnum.arcl[i].right;
504 ClipRect.top = RectEnum.arcl[i].top;
505 ClipRect.bottom = RectEnum.arcl[i].bottom;
506 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
507 {
508 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
509 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
510 Ret = (*BltRectFunc)(OutputObj, InputObj, Mask,
511 ColorTranslation, &CombinedRect, &Pt,
512 MaskOrigin, pbo, &AdjustedBrushOrigin,
513 rop4) && Ret;
514 }
515 }
516 }
517 while (EnumMore);
518 break;
519 }
520
521 return Ret;
522 }
523
524 BOOL APIENTRY
525 IntEngBitBlt(
526 SURFOBJ *psoTrg,
527 SURFOBJ *psoSrc,
528 SURFOBJ *psoMask,
529 CLIPOBJ *pco,
530 XLATEOBJ *pxlo,
531 RECTL *prclTrg,
532 POINTL *pptlSrc,
533 POINTL *pptlMask,
534 BRUSHOBJ *pbo,
535 POINTL *pptlBrush,
536 ROP4 rop4)
537 {
538 SURFACE *psurfTrg;
539 SURFACE *psurfSrc = NULL;
540 BOOL bResult;
541 RECTL rclClipped;
542 RECTL rclSrc;
543 // INTENG_ENTER_LEAVE EnterLeaveSource;
544 // INTENG_ENTER_LEAVE EnterLeaveDest;
545 PFN_DrvBitBlt pfnBitBlt;
546
547 ASSERT(psoTrg);
548 psurfTrg = CONTAINING_RECORD(psoTrg, SURFACE, SurfObj);
549
550 /* FIXME: Should we really allow to pass non-well-ordered rects? */
551 rclClipped = *prclTrg;
552 RECTL_vMakeWellOrdered(&rclClipped);
553
554 /* Clip target rect against the bounds of the clipping region */
555 if (pco)
556 {
557 if (!RECTL_bIntersectRect(&rclClipped, &rclClipped, &pco->rclBounds))
558 {
559 /* Nothing left */
560 return TRUE;
561 }
562
563 /* Don't pass a clipobj with only a single rect */
564 if (pco->iDComplexity == DC_RECT)
565 pco = NULL;
566 }
567
568 if (ROP4_USES_SOURCE(rop4))
569 {
570 ASSERT(psoSrc);
571 psurfSrc = CONTAINING_RECORD(psoSrc, SURFACE, SurfObj);
572
573 /* Calculate source rect */
574 rclSrc.left = pptlSrc->x + rclClipped.left - prclTrg->left;
575 rclSrc.top = pptlSrc->y + rclClipped.top - prclTrg->top;
576 rclSrc.right = rclSrc.left + rclClipped.right - rclClipped.left;
577 rclSrc.bottom = rclSrc.top + rclClipped.bottom - rclClipped.top;
578 }
579 else
580 {
581 psoSrc = NULL;
582 psurfSrc = NULL;
583 }
584
585 /* Is the target surface device managed? */
586 if (psurfTrg->flags & HOOK_BITBLT)
587 {
588 /* Is the source a different device managed surface? */
589 if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flags & HOOK_BITBLT)
590 {
591 DPRINT1("Need to copy to standard bitmap format!\n");
592 ASSERT(FALSE);
593 }
594
595 pfnBitBlt = GDIDEVFUNCS(psoTrg).BitBlt;
596 }
597
598 /* Is the source surface device managed? */
599 else if (psoSrc && psurfSrc->flags & HOOK_BITBLT)
600 {
601 pfnBitBlt = GDIDEVFUNCS(psoSrc).BitBlt;
602 }
603 else
604 {
605 pfnBitBlt = EngBitBlt;
606 }
607
608 bResult = pfnBitBlt(psoTrg,
609 psoSrc,
610 psoMask,
611 pco,
612 pxlo,
613 &rclClipped,
614 (POINTL*)&rclSrc,
615 pptlMask,
616 pbo,
617 pptlBrush,
618 rop4);
619
620 // FIXME: cleanup temp surface!
621
622 return bResult;
623 }
624
625
626 /**** REACTOS FONT RENDERING CODE *********************************************/
627
628 /* renders the alpha mask bitmap */
629 static BOOLEAN APIENTRY
630 AlphaBltMask(SURFOBJ* psoDest,
631 SURFOBJ* psoSource, // unused
632 SURFOBJ* psoMask,
633 XLATEOBJ* pxloRGB2Dest,
634 XLATEOBJ* pxloBrush,
635 RECTL* prclDest,
636 POINTL* pptlSource, // unused
637 POINTL* pptlMask,
638 BRUSHOBJ* pbo,
639 POINTL* pptlBrush)
640 {
641 LONG i, j, dx, dy;
642 int r, g, b;
643 ULONG Background, BrushColor, NewColor;
644 BYTE *tMask, *lMask;
645
646 ASSERT(psoSource == NULL);
647 ASSERT(pptlSource == NULL);
648
649 dx = prclDest->right - prclDest->left;
650 dy = prclDest->bottom - prclDest->top;
651
652 if (psoMask != NULL)
653 {
654 BrushColor = XLATEOBJ_iXlate(pxloBrush, pbo ? pbo->iSolidColor : 0);
655 r = (int)GetRValue(BrushColor);
656 g = (int)GetGValue(BrushColor);
657 b = (int)GetBValue(BrushColor);
658
659 tMask = (PBYTE)psoMask->pvScan0 + (pptlMask->y * psoMask->lDelta) + pptlMask->x;
660 for (j = 0; j < dy; j++)
661 {
662 lMask = tMask;
663 for (i = 0; i < dx; i++)
664 {
665 if (*lMask > 0)
666 {
667 if (*lMask == 0xff)
668 {
669 DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
670 psoDest, prclDest->left + i, prclDest->top + j, pbo ? pbo->iSolidColor : 0);
671 }
672 else
673 {
674 Background = DIB_GetSource(psoDest, prclDest->left + i, prclDest->top + j,
675 pxloBrush);
676
677 NewColor =
678 RGB((*lMask * (r - GetRValue(Background)) >> 8) + GetRValue(Background),
679 (*lMask * (g - GetGValue(Background)) >> 8) + GetGValue(Background),
680 (*lMask * (b - GetBValue(Background)) >> 8) + GetBValue(Background));
681
682 Background = XLATEOBJ_iXlate(pxloRGB2Dest, NewColor);
683 DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
684 psoDest, prclDest->left + i, prclDest->top + j, Background);
685 }
686 }
687 lMask++;
688 }
689 tMask += psoMask->lDelta;
690 }
691 return TRUE;
692 }
693 else
694 {
695 return FALSE;
696 }
697 }
698
699 static
700 BOOL APIENTRY
701 EngMaskBitBlt(SURFOBJ *psoDest,
702 SURFOBJ *psoMask,
703 CLIPOBJ *ClipRegion,
704 XLATEOBJ *DestColorTranslation,
705 XLATEOBJ *SourceColorTranslation,
706 RECTL *DestRect,
707 POINTL *pptlMask,
708 BRUSHOBJ *pbo,
709 POINTL *BrushOrigin)
710 {
711 BYTE clippingType;
712 RECTL CombinedRect;
713 RECT_ENUM RectEnum;
714 BOOL EnumMore;
715 POINTL InputPoint;
716 RECTL InputRect;
717 RECTL OutputRect;
718 POINTL Translate;
719 INTENG_ENTER_LEAVE EnterLeaveSource;
720 INTENG_ENTER_LEAVE EnterLeaveDest;
721 SURFOBJ* psoInput;
722 SURFOBJ* psoOutput;
723 BOOLEAN Ret = TRUE;
724 RECTL ClipRect;
725 unsigned i;
726 POINTL Pt;
727 ULONG Direction;
728 POINTL AdjustedBrushOrigin;
729
730 ASSERT(psoMask);
731
732 if (pptlMask)
733 {
734 InputRect.left = pptlMask->x;
735 InputRect.right = pptlMask->x + (DestRect->right - DestRect->left);
736 InputRect.top = pptlMask->y;
737 InputRect.bottom = pptlMask->y + (DestRect->bottom - DestRect->top);
738 }
739 else
740 {
741 InputRect.left = 0;
742 InputRect.right = DestRect->right - DestRect->left;
743 InputRect.top = 0;
744 InputRect.bottom = DestRect->bottom - DestRect->top;
745 }
746
747 OutputRect = *DestRect;
748 if (NULL != ClipRegion)
749 {
750 if (OutputRect.left < ClipRegion->rclBounds.left)
751 {
752 InputRect.left += ClipRegion->rclBounds.left - OutputRect.left;
753 OutputRect.left = ClipRegion->rclBounds.left;
754 }
755 if (ClipRegion->rclBounds.right < OutputRect.right)
756 {
757 InputRect.right -= OutputRect.right - ClipRegion->rclBounds.right;
758 OutputRect.right = ClipRegion->rclBounds.right;
759 }
760 if (OutputRect.top < ClipRegion->rclBounds.top)
761 {
762 InputRect.top += ClipRegion->rclBounds.top - OutputRect.top;
763 OutputRect.top = ClipRegion->rclBounds.top;
764 }
765 if (ClipRegion->rclBounds.bottom < OutputRect.bottom)
766 {
767 InputRect.bottom -= OutputRect.bottom - ClipRegion->rclBounds.bottom;
768 OutputRect.bottom = ClipRegion->rclBounds.bottom;
769 }
770 }
771
772 if (! IntEngEnter(&EnterLeaveSource, psoMask, &InputRect, TRUE, &Translate, &psoInput))
773 {
774 return FALSE;
775 }
776
777 InputPoint.x = InputRect.left + Translate.x;
778 InputPoint.y = InputRect.top + Translate.y;
779
780 /* Check for degenerate case: if height or width of OutputRect is 0 pixels there's
781 nothing to do */
782 if (OutputRect.right <= OutputRect.left || OutputRect.bottom <= OutputRect.top)
783 {
784 IntEngLeave(&EnterLeaveSource);
785 return TRUE;
786 }
787
788 if (! IntEngEnter(&EnterLeaveDest, psoDest, &OutputRect, FALSE, &Translate, &psoOutput))
789 {
790 IntEngLeave(&EnterLeaveSource);
791 return FALSE;
792 }
793
794 OutputRect.left = DestRect->left + Translate.x;
795 OutputRect.right = DestRect->right + Translate.x;
796 OutputRect.top = DestRect->top + Translate.y;
797 OutputRect.bottom = DestRect->bottom + Translate.y;
798
799 if (BrushOrigin)
800 {
801 AdjustedBrushOrigin.x = BrushOrigin->x + Translate.x;
802 AdjustedBrushOrigin.y = BrushOrigin->y + Translate.y;
803 }
804 else
805 AdjustedBrushOrigin = Translate;
806
807 // Determine clipping type
808 if (ClipRegion == (CLIPOBJ *) NULL)
809 {
810 clippingType = DC_TRIVIAL;
811 } else {
812 clippingType = ClipRegion->iDComplexity;
813 }
814
815 switch (clippingType)
816 {
817 case DC_TRIVIAL:
818 if (psoMask->iBitmapFormat == BMF_8BPP)
819 Ret = AlphaBltMask(psoOutput, NULL , psoInput, DestColorTranslation, SourceColorTranslation,
820 &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin);
821 else
822 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
823 &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin,
824 R4_MASK);
825 break;
826 case DC_RECT:
827 // Clip the blt to the clip rectangle
828 ClipRect.left = ClipRegion->rclBounds.left + Translate.x;
829 ClipRect.right = ClipRegion->rclBounds.right + Translate.x;
830 ClipRect.top = ClipRegion->rclBounds.top + Translate.y;
831 ClipRect.bottom = ClipRegion->rclBounds.bottom + Translate.y;
832 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
833 {
834 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
835 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
836 if (psoMask->iBitmapFormat == BMF_8BPP)
837 {
838 Ret = AlphaBltMask(psoOutput, NULL, psoInput, DestColorTranslation, SourceColorTranslation,
839 &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin);
840 }
841 else
842 {
843 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
844 &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin, R4_MASK);
845 }
846 }
847 break;
848 case DC_COMPLEX:
849 Ret = TRUE;
850 if (psoOutput == psoInput)
851 {
852 if (OutputRect.top < InputPoint.y)
853 {
854 Direction = OutputRect.left < InputPoint.x ? CD_RIGHTDOWN : CD_LEFTDOWN;
855 }
856 else
857 {
858 Direction = OutputRect.left < InputPoint.x ? CD_RIGHTUP : CD_LEFTUP;
859 }
860 }
861 else
862 {
863 Direction = CD_ANY;
864 }
865 CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, Direction, 0);
866 do
867 {
868 EnumMore = CLIPOBJ_bEnum(ClipRegion,(ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
869
870 for (i = 0; i < RectEnum.c; i++)
871 {
872 ClipRect.left = RectEnum.arcl[i].left + Translate.x;
873 ClipRect.right = RectEnum.arcl[i].right + Translate.x;
874 ClipRect.top = RectEnum.arcl[i].top + Translate.y;
875 ClipRect.bottom = RectEnum.arcl[i].bottom + Translate.y;
876 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
877 {
878 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
879 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
880 if (psoMask->iBitmapFormat == BMF_8BPP)
881 {
882 Ret = AlphaBltMask(psoOutput, NULL, psoInput,
883 DestColorTranslation,
884 SourceColorTranslation,
885 &CombinedRect, NULL, &Pt, pbo,
886 &AdjustedBrushOrigin) && Ret;
887 }
888 else
889 {
890 Ret = BltMask(psoOutput, NULL, psoInput,
891 DestColorTranslation, &CombinedRect, NULL,
892 &Pt, pbo, &AdjustedBrushOrigin,
893 R4_MASK) && Ret;
894 }
895 }
896 }
897 }
898 while (EnumMore);
899 break;
900 }
901
902
903 IntEngLeave(&EnterLeaveDest);
904 IntEngLeave(&EnterLeaveSource);
905
906 return Ret;
907 }
908
909 BOOL APIENTRY
910 IntEngMaskBlt(SURFOBJ *psoDest,
911 SURFOBJ *psoMask,
912 CLIPOBJ *ClipRegion,
913 XLATEOBJ *DestColorTranslation,
914 XLATEOBJ *SourceColorTranslation,
915 RECTL *DestRect,
916 POINTL *pptlMask,
917 BRUSHOBJ *pbo,
918 POINTL *BrushOrigin)
919 {
920 BOOLEAN ret;
921 RECTL OutputRect;
922 POINTL InputPoint;
923 SURFACE *psurfDest;
924
925 ASSERT(psoMask);
926
927 if (pptlMask)
928 {
929 InputPoint = *pptlMask;
930 }
931
932 /* Clip against the bounds of the clipping region so we won't try to write
933 * outside the surface */
934 if (NULL != ClipRegion)
935 {
936 if (!RECTL_bIntersectRect(&OutputRect, DestRect, &ClipRegion->rclBounds))
937 {
938 return TRUE;
939 }
940 InputPoint.x += OutputRect.left - DestRect->left;
941 InputPoint.y += OutputRect.top - DestRect->top;
942 }
943 else
944 {
945 OutputRect = *DestRect;
946 }
947
948 /* No success yet */
949 ret = FALSE;
950 ASSERT(psoDest);
951 psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
952
953 /* Dummy BitBlt to let driver know that it should flush its changes.
954 This should really be done using a call to DrvSynchronizeSurface,
955 but the VMware driver doesn't hook that call. */
956 IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
957 DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
958 R4_NOOP);
959
960 ret = EngMaskBitBlt(psoDest, psoMask, ClipRegion, DestColorTranslation, SourceColorTranslation,
961 &OutputRect, &InputPoint, pbo, BrushOrigin);
962
963 /* Dummy BitBlt to let driver know that something has changed. */
964 IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
965 DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
966 R4_NOOP);
967
968 return ret;
969 }
970
971 /* EOF */