[CMAKE]
[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 InputPoint.x = InputPoint.y = 0;
374 InputRect.left = 0;
375 InputRect.right = DestRect->right - DestRect->left;
376 InputRect.top = 0;
377 InputRect.bottom = DestRect->bottom - DestRect->top;
378 }
379
380 if (NULL != ClipRegion)
381 {
382 if (OutputRect.left < ClipRegion->rclBounds.left)
383 {
384 InputRect.left += ClipRegion->rclBounds.left - OutputRect.left;
385 InputPoint.x += ClipRegion->rclBounds.left - OutputRect.left;
386 OutputRect.left = ClipRegion->rclBounds.left;
387 }
388 if (ClipRegion->rclBounds.right < OutputRect.right)
389 {
390 InputRect.right -= OutputRect.right - ClipRegion->rclBounds.right;
391 OutputRect.right = ClipRegion->rclBounds.right;
392 }
393 if (OutputRect.top < ClipRegion->rclBounds.top)
394 {
395 InputRect.top += ClipRegion->rclBounds.top - OutputRect.top;
396 InputPoint.y += ClipRegion->rclBounds.top - OutputRect.top;
397 OutputRect.top = ClipRegion->rclBounds.top;
398 }
399 if (ClipRegion->rclBounds.bottom < OutputRect.bottom)
400 {
401 InputRect.bottom -= OutputRect.bottom - ClipRegion->rclBounds.bottom;
402 OutputRect.bottom = ClipRegion->rclBounds.bottom;
403 }
404 }
405
406 /* Check for degenerate case: if height or width of OutputRect is 0 pixels
407 there's nothing to do */
408 if (OutputRect.right <= OutputRect.left ||
409 OutputRect.bottom <= OutputRect.top)
410 {
411 return TRUE;
412 }
413
414 OutputObj = DestObj;
415
416 if (BrushOrigin)
417 {
418 AdjustedBrushOrigin.x = BrushOrigin->x;
419 AdjustedBrushOrigin.y = BrushOrigin->y;
420 }
421 else
422 {
423 AdjustedBrushOrigin.x = 0;
424 AdjustedBrushOrigin.y = 0;
425 }
426
427 /* Determine clipping type */
428 if (ClipRegion == (CLIPOBJ *) NULL)
429 {
430 clippingType = DC_TRIVIAL;
431 }
432 else
433 {
434 clippingType = ClipRegion->iDComplexity;
435 }
436
437 if (R4_MASK == rop4)
438 {
439 BltRectFunc = BltMask;
440 }
441 else if (ROP3_TO_ROP4(PATCOPY) == rop4)
442 {
443 if (pbo && pbo->iSolidColor == 0xFFFFFFFF)
444 BltRectFunc = CallDibBitBlt;
445 else
446 BltRectFunc = BltPatCopy;
447 }
448 else
449 {
450 BltRectFunc = CallDibBitBlt;
451 }
452
453
454 switch (clippingType)
455 {
456 case DC_TRIVIAL:
457 Ret = (*BltRectFunc)(OutputObj, InputObj, Mask, ColorTranslation,
458 &OutputRect, &InputPoint, MaskOrigin, pbo,
459 &AdjustedBrushOrigin, rop4);
460 break;
461 case DC_RECT:
462 /* Clip the blt to the clip rectangle */
463 ClipRect.left = ClipRegion->rclBounds.left;
464 ClipRect.right = ClipRegion->rclBounds.right;
465 ClipRect.top = ClipRegion->rclBounds.top;
466 ClipRect.bottom = ClipRegion->rclBounds.bottom;
467 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
468 {
469 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
470 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
471 Ret = (*BltRectFunc)(OutputObj, InputObj, Mask, ColorTranslation,
472 &CombinedRect, &Pt, MaskOrigin, pbo,
473 &AdjustedBrushOrigin, rop4);
474 }
475 break;
476 case DC_COMPLEX:
477 Ret = TRUE;
478 if (OutputObj == InputObj)
479 {
480 if (OutputRect.top < InputPoint.y)
481 {
482 Direction = OutputRect.left < InputPoint.x ?
483 CD_RIGHTDOWN : CD_LEFTDOWN;
484 }
485 else
486 {
487 Direction = OutputRect.left < InputPoint.x ?
488 CD_RIGHTUP : CD_LEFTUP;
489 }
490 }
491 else
492 {
493 Direction = CD_ANY;
494 }
495 CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, Direction, 0);
496 do
497 {
498 EnumMore = CLIPOBJ_bEnum(ClipRegion,(ULONG) sizeof(RectEnum),
499 (PVOID) &RectEnum);
500
501 for (i = 0; i < RectEnum.c; i++)
502 {
503 ClipRect.left = RectEnum.arcl[i].left;
504 ClipRect.right = RectEnum.arcl[i].right;
505 ClipRect.top = RectEnum.arcl[i].top;
506 ClipRect.bottom = RectEnum.arcl[i].bottom;
507 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
508 {
509 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
510 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
511 Ret = (*BltRectFunc)(OutputObj, InputObj, Mask,
512 ColorTranslation, &CombinedRect, &Pt,
513 MaskOrigin, pbo, &AdjustedBrushOrigin,
514 rop4) && Ret;
515 }
516 }
517 }
518 while (EnumMore);
519 break;
520 }
521
522 return Ret;
523 }
524
525 BOOL APIENTRY
526 IntEngBitBlt(
527 SURFOBJ *psoTrg,
528 SURFOBJ *psoSrc,
529 SURFOBJ *psoMask,
530 CLIPOBJ *pco,
531 XLATEOBJ *pxlo,
532 RECTL *prclTrg,
533 POINTL *pptlSrc,
534 POINTL *pptlMask,
535 BRUSHOBJ *pbo,
536 POINTL *pptlBrush,
537 ROP4 rop4)
538 {
539 SURFACE *psurfTrg;
540 SURFACE *psurfSrc = NULL;
541 BOOL bResult;
542 RECTL rclClipped;
543 RECTL rclSrc;
544 // INTENG_ENTER_LEAVE EnterLeaveSource;
545 // INTENG_ENTER_LEAVE EnterLeaveDest;
546 PFN_DrvBitBlt pfnBitBlt;
547
548 ASSERT(psoTrg);
549 psurfTrg = CONTAINING_RECORD(psoTrg, SURFACE, SurfObj);
550
551 /* FIXME: Should we really allow to pass non-well-ordered rects? */
552 rclClipped = *prclTrg;
553 RECTL_vMakeWellOrdered(&rclClipped);
554
555 /* Clip target rect against the bounds of the clipping region */
556 if (pco)
557 {
558 if (!RECTL_bIntersectRect(&rclClipped, &rclClipped, &pco->rclBounds))
559 {
560 /* Nothing left */
561 return TRUE;
562 }
563
564 /* Don't pass a clipobj with only a single rect */
565 if (pco->iDComplexity == DC_RECT)
566 pco = NULL;
567 }
568
569 if (ROP4_USES_SOURCE(rop4))
570 {
571 ASSERT(psoSrc);
572 psurfSrc = CONTAINING_RECORD(psoSrc, SURFACE, SurfObj);
573
574 /* Calculate source rect */
575 rclSrc.left = pptlSrc->x + rclClipped.left - prclTrg->left;
576 rclSrc.top = pptlSrc->y + rclClipped.top - prclTrg->top;
577 rclSrc.right = rclSrc.left + rclClipped.right - rclClipped.left;
578 rclSrc.bottom = rclSrc.top + rclClipped.bottom - rclClipped.top;
579 }
580 else
581 {
582 psoSrc = NULL;
583 psurfSrc = NULL;
584 }
585
586 /* Is the target surface device managed? */
587 if (psurfTrg->flags & HOOK_BITBLT)
588 {
589 /* Is the source a different device managed surface? */
590 if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flags & HOOK_BITBLT)
591 {
592 DPRINT1("Need to copy to standard bitmap format!\n");
593 ASSERT(FALSE);
594 }
595
596 pfnBitBlt = GDIDEVFUNCS(psoTrg).BitBlt;
597 }
598
599 /* Is the source surface device managed? */
600 else if (psoSrc && psurfSrc->flags & HOOK_BITBLT)
601 {
602 pfnBitBlt = GDIDEVFUNCS(psoSrc).BitBlt;
603 }
604 else
605 {
606 pfnBitBlt = EngBitBlt;
607 }
608
609 bResult = pfnBitBlt(psoTrg,
610 psoSrc,
611 psoMask,
612 pco,
613 pxlo,
614 &rclClipped,
615 (POINTL*)&rclSrc,
616 pptlMask,
617 pbo,
618 pptlBrush,
619 rop4);
620
621 // FIXME: cleanup temp surface!
622
623 return bResult;
624 }
625
626
627 /**** REACTOS FONT RENDERING CODE *********************************************/
628
629 /* renders the alpha mask bitmap */
630 static BOOLEAN APIENTRY
631 AlphaBltMask(SURFOBJ* psoDest,
632 SURFOBJ* psoSource, // unused
633 SURFOBJ* psoMask,
634 XLATEOBJ* pxloRGB2Dest,
635 XLATEOBJ* pxloBrush,
636 RECTL* prclDest,
637 POINTL* pptlSource, // unused
638 POINTL* pptlMask,
639 BRUSHOBJ* pbo,
640 POINTL* pptlBrush)
641 {
642 LONG i, j, dx, dy;
643 int r, g, b;
644 ULONG Background, BrushColor, NewColor;
645 BYTE *tMask, *lMask;
646
647 ASSERT(psoSource == NULL);
648 ASSERT(pptlSource == NULL);
649
650 dx = prclDest->right - prclDest->left;
651 dy = prclDest->bottom - prclDest->top;
652
653 if (psoMask != NULL)
654 {
655 BrushColor = XLATEOBJ_iXlate(pxloBrush, pbo ? pbo->iSolidColor : 0);
656 r = (int)GetRValue(BrushColor);
657 g = (int)GetGValue(BrushColor);
658 b = (int)GetBValue(BrushColor);
659
660 tMask = (PBYTE)psoMask->pvScan0 + (pptlMask->y * psoMask->lDelta) + pptlMask->x;
661 for (j = 0; j < dy; j++)
662 {
663 lMask = tMask;
664 for (i = 0; i < dx; i++)
665 {
666 if (*lMask > 0)
667 {
668 if (*lMask == 0xff)
669 {
670 DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
671 psoDest, prclDest->left + i, prclDest->top + j, pbo ? pbo->iSolidColor : 0);
672 }
673 else
674 {
675 Background = DIB_GetSource(psoDest, prclDest->left + i, prclDest->top + j,
676 pxloBrush);
677
678 NewColor =
679 RGB((*lMask * (r - GetRValue(Background)) >> 8) + GetRValue(Background),
680 (*lMask * (g - GetGValue(Background)) >> 8) + GetGValue(Background),
681 (*lMask * (b - GetBValue(Background)) >> 8) + GetBValue(Background));
682
683 Background = XLATEOBJ_iXlate(pxloRGB2Dest, NewColor);
684 DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
685 psoDest, prclDest->left + i, prclDest->top + j, Background);
686 }
687 }
688 lMask++;
689 }
690 tMask += psoMask->lDelta;
691 }
692 return TRUE;
693 }
694 else
695 {
696 return FALSE;
697 }
698 }
699
700 static
701 BOOL APIENTRY
702 EngMaskBitBlt(SURFOBJ *psoDest,
703 SURFOBJ *psoMask,
704 CLIPOBJ *ClipRegion,
705 XLATEOBJ *DestColorTranslation,
706 XLATEOBJ *SourceColorTranslation,
707 RECTL *DestRect,
708 POINTL *pptlMask,
709 BRUSHOBJ *pbo,
710 POINTL *BrushOrigin)
711 {
712 BYTE clippingType;
713 RECTL CombinedRect;
714 RECT_ENUM RectEnum;
715 BOOL EnumMore;
716 POINTL InputPoint;
717 RECTL InputRect;
718 RECTL OutputRect;
719 POINTL Translate;
720 INTENG_ENTER_LEAVE EnterLeaveSource;
721 INTENG_ENTER_LEAVE EnterLeaveDest;
722 SURFOBJ* psoInput;
723 SURFOBJ* psoOutput;
724 BOOLEAN Ret = TRUE;
725 RECTL ClipRect;
726 unsigned i;
727 POINTL Pt;
728 ULONG Direction;
729 POINTL AdjustedBrushOrigin;
730
731 ASSERT(psoMask);
732
733 if (pptlMask)
734 {
735 InputRect.left = pptlMask->x;
736 InputRect.right = pptlMask->x + (DestRect->right - DestRect->left);
737 InputRect.top = pptlMask->y;
738 InputRect.bottom = pptlMask->y + (DestRect->bottom - DestRect->top);
739 }
740 else
741 {
742 InputRect.left = 0;
743 InputRect.right = DestRect->right - DestRect->left;
744 InputRect.top = 0;
745 InputRect.bottom = DestRect->bottom - DestRect->top;
746 }
747
748 OutputRect = *DestRect;
749 if (NULL != ClipRegion)
750 {
751 if (OutputRect.left < ClipRegion->rclBounds.left)
752 {
753 InputRect.left += ClipRegion->rclBounds.left - OutputRect.left;
754 OutputRect.left = ClipRegion->rclBounds.left;
755 }
756 if (ClipRegion->rclBounds.right < OutputRect.right)
757 {
758 InputRect.right -= OutputRect.right - ClipRegion->rclBounds.right;
759 OutputRect.right = ClipRegion->rclBounds.right;
760 }
761 if (OutputRect.top < ClipRegion->rclBounds.top)
762 {
763 InputRect.top += ClipRegion->rclBounds.top - OutputRect.top;
764 OutputRect.top = ClipRegion->rclBounds.top;
765 }
766 if (ClipRegion->rclBounds.bottom < OutputRect.bottom)
767 {
768 InputRect.bottom -= OutputRect.bottom - ClipRegion->rclBounds.bottom;
769 OutputRect.bottom = ClipRegion->rclBounds.bottom;
770 }
771 }
772
773 if (! IntEngEnter(&EnterLeaveSource, psoMask, &InputRect, TRUE, &Translate, &psoInput))
774 {
775 return FALSE;
776 }
777
778 InputPoint.x = InputRect.left + Translate.x;
779 InputPoint.y = InputRect.top + Translate.y;
780
781 /* Check for degenerate case: if height or width of OutputRect is 0 pixels there's
782 nothing to do */
783 if (OutputRect.right <= OutputRect.left || OutputRect.bottom <= OutputRect.top)
784 {
785 IntEngLeave(&EnterLeaveSource);
786 return TRUE;
787 }
788
789 if (! IntEngEnter(&EnterLeaveDest, psoDest, &OutputRect, FALSE, &Translate, &psoOutput))
790 {
791 IntEngLeave(&EnterLeaveSource);
792 return FALSE;
793 }
794
795 OutputRect.left = DestRect->left + Translate.x;
796 OutputRect.right = DestRect->right + Translate.x;
797 OutputRect.top = DestRect->top + Translate.y;
798 OutputRect.bottom = DestRect->bottom + Translate.y;
799
800 if (BrushOrigin)
801 {
802 AdjustedBrushOrigin.x = BrushOrigin->x + Translate.x;
803 AdjustedBrushOrigin.y = BrushOrigin->y + Translate.y;
804 }
805 else
806 AdjustedBrushOrigin = Translate;
807
808 // Determine clipping type
809 if (ClipRegion == (CLIPOBJ *) NULL)
810 {
811 clippingType = DC_TRIVIAL;
812 } else {
813 clippingType = ClipRegion->iDComplexity;
814 }
815
816 switch (clippingType)
817 {
818 case DC_TRIVIAL:
819 if (psoMask->iBitmapFormat == BMF_8BPP)
820 Ret = AlphaBltMask(psoOutput, NULL , psoInput, DestColorTranslation, SourceColorTranslation,
821 &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin);
822 else
823 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
824 &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin,
825 R4_MASK);
826 break;
827 case DC_RECT:
828 // Clip the blt to the clip rectangle
829 ClipRect.left = ClipRegion->rclBounds.left + Translate.x;
830 ClipRect.right = ClipRegion->rclBounds.right + Translate.x;
831 ClipRect.top = ClipRegion->rclBounds.top + Translate.y;
832 ClipRect.bottom = ClipRegion->rclBounds.bottom + Translate.y;
833 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
834 {
835 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
836 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
837 if (psoMask->iBitmapFormat == BMF_8BPP)
838 {
839 Ret = AlphaBltMask(psoOutput, NULL, psoInput, DestColorTranslation, SourceColorTranslation,
840 &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin);
841 }
842 else
843 {
844 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
845 &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin, R4_MASK);
846 }
847 }
848 break;
849 case DC_COMPLEX:
850 Ret = TRUE;
851 if (psoOutput == psoInput)
852 {
853 if (OutputRect.top < InputPoint.y)
854 {
855 Direction = OutputRect.left < InputPoint.x ? CD_RIGHTDOWN : CD_LEFTDOWN;
856 }
857 else
858 {
859 Direction = OutputRect.left < InputPoint.x ? CD_RIGHTUP : CD_LEFTUP;
860 }
861 }
862 else
863 {
864 Direction = CD_ANY;
865 }
866 CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, Direction, 0);
867 do
868 {
869 EnumMore = CLIPOBJ_bEnum(ClipRegion,(ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
870
871 for (i = 0; i < RectEnum.c; i++)
872 {
873 ClipRect.left = RectEnum.arcl[i].left + Translate.x;
874 ClipRect.right = RectEnum.arcl[i].right + Translate.x;
875 ClipRect.top = RectEnum.arcl[i].top + Translate.y;
876 ClipRect.bottom = RectEnum.arcl[i].bottom + Translate.y;
877 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
878 {
879 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
880 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
881 if (psoMask->iBitmapFormat == BMF_8BPP)
882 {
883 Ret = AlphaBltMask(psoOutput, NULL, psoInput,
884 DestColorTranslation,
885 SourceColorTranslation,
886 &CombinedRect, NULL, &Pt, pbo,
887 &AdjustedBrushOrigin) && Ret;
888 }
889 else
890 {
891 Ret = BltMask(psoOutput, NULL, psoInput,
892 DestColorTranslation, &CombinedRect, NULL,
893 &Pt, pbo, &AdjustedBrushOrigin,
894 R4_MASK) && Ret;
895 }
896 }
897 }
898 }
899 while (EnumMore);
900 break;
901 }
902
903
904 IntEngLeave(&EnterLeaveDest);
905 IntEngLeave(&EnterLeaveSource);
906
907 return Ret;
908 }
909
910 BOOL APIENTRY
911 IntEngMaskBlt(SURFOBJ *psoDest,
912 SURFOBJ *psoMask,
913 CLIPOBJ *ClipRegion,
914 XLATEOBJ *DestColorTranslation,
915 XLATEOBJ *SourceColorTranslation,
916 RECTL *DestRect,
917 POINTL *pptlMask,
918 BRUSHOBJ *pbo,
919 POINTL *BrushOrigin)
920 {
921 BOOLEAN ret;
922 RECTL OutputRect;
923 POINTL InputPoint;
924 SURFACE *psurfDest;
925
926 ASSERT(psoMask);
927
928 if (pptlMask)
929 {
930 InputPoint = *pptlMask;
931 }
932
933 /* Clip against the bounds of the clipping region so we won't try to write
934 * outside the surface */
935 if (NULL != ClipRegion)
936 {
937 if (!RECTL_bIntersectRect(&OutputRect, DestRect, &ClipRegion->rclBounds))
938 {
939 return TRUE;
940 }
941 InputPoint.x += OutputRect.left - DestRect->left;
942 InputPoint.y += OutputRect.top - DestRect->top;
943 }
944 else
945 {
946 OutputRect = *DestRect;
947 }
948
949 /* No success yet */
950 ret = FALSE;
951 ASSERT(psoDest);
952 psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
953
954 /* Dummy BitBlt to let driver know that it should flush its changes.
955 This should really be done using a call to DrvSynchronizeSurface,
956 but the VMware driver doesn't hook that call. */
957 IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
958 DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
959 R4_NOOP);
960
961 ret = EngMaskBitBlt(psoDest, psoMask, ClipRegion, DestColorTranslation, SourceColorTranslation,
962 &OutputRect, &InputPoint, pbo, BrushOrigin);
963
964 /* Dummy BitBlt to let driver know that something has changed. */
965 IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
966 DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
967 R4_NOOP);
968
969 return ret;
970 }
971
972 /* EOF */