[WIN32K]
[reactos.git] / reactos / 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 PFN_DrvBitBlt pfnBitBlt;
545
546 ASSERT(psoTrg);
547 psurfTrg = CONTAINING_RECORD(psoTrg, SURFACE, SurfObj);
548
549 /* FIXME: Should we really allow to pass non-well-ordered rects? */
550 rclClipped = *prclTrg;
551 RECTL_vMakeWellOrdered(&rclClipped);
552
553 if (pco)
554 {
555 /* Clip target rect against the bounds of the clipping region */
556 if (!RECTL_bIntersectRect(&rclClipped, &rclClipped, &pco->rclBounds))
557 {
558 /* Nothing left */
559 return TRUE;
560 }
561
562 /* Don't pass a clipobj with only a single rect */
563 if (pco->iDComplexity == DC_RECT)
564 pco = NULL;
565 }
566
567 if (ROP4_USES_SOURCE(rop4))
568 {
569 ASSERT(psoSrc);
570 psurfSrc = CONTAINING_RECORD(psoSrc, SURFACE, SurfObj);
571
572 /* Calculate source rect */
573 rclSrc.left = pptlSrc->x + rclClipped.left - prclTrg->left;
574 rclSrc.top = pptlSrc->y + rclClipped.top - prclTrg->top;
575 rclSrc.right = rclSrc.left + rclClipped.right - rclClipped.left;
576 rclSrc.bottom = rclSrc.top + rclClipped.bottom - rclClipped.top;
577 }
578 else
579 {
580 psoSrc = NULL;
581 psurfSrc = NULL;
582 }
583
584 /* Is the target surface device managed? */
585 if (psurfTrg->flags & HOOK_BITBLT)
586 {
587 /* Is the source a different device managed surface? */
588 if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flags & HOOK_BITBLT)
589 {
590 DPRINT1("Need to copy to standard bitmap format!\n");
591 ASSERT(FALSE);
592 }
593
594 pfnBitBlt = GDIDEVFUNCS(psoTrg).BitBlt;
595 }
596
597 /* Is the source surface device managed? */
598 else if (psoSrc && psurfSrc->flags & HOOK_BITBLT)
599 {
600 pfnBitBlt = GDIDEVFUNCS(psoSrc).BitBlt;
601 }
602 else
603 {
604 pfnBitBlt = EngBitBlt;
605 }
606
607 bResult = pfnBitBlt(psoTrg,
608 psoSrc,
609 psoMask,
610 pco,
611 pxlo,
612 &rclClipped,
613 (POINTL*)&rclSrc,
614 pptlMask,
615 pbo,
616 pptlBrush,
617 rop4);
618
619 // FIXME: cleanup temp surface!
620
621 return bResult;
622 }
623
624
625 /**** REACTOS FONT RENDERING CODE *********************************************/
626
627 /* renders the alpha mask bitmap */
628 static BOOLEAN APIENTRY
629 AlphaBltMask(SURFOBJ* psoDest,
630 SURFOBJ* psoSource, // unused
631 SURFOBJ* psoMask,
632 XLATEOBJ* pxloRGB2Dest,
633 XLATEOBJ* pxloBrush,
634 RECTL* prclDest,
635 POINTL* pptlSource, // unused
636 POINTL* pptlMask,
637 BRUSHOBJ* pbo,
638 POINTL* pptlBrush)
639 {
640 LONG i, j, dx, dy;
641 int r, g, b;
642 ULONG Background, BrushColor, NewColor;
643 BYTE *tMask, *lMask;
644
645 ASSERT(psoSource == NULL);
646 ASSERT(pptlSource == NULL);
647
648 dx = prclDest->right - prclDest->left;
649 dy = prclDest->bottom - prclDest->top;
650
651 if (psoMask != NULL)
652 {
653 BrushColor = XLATEOBJ_iXlate(pxloBrush, pbo ? pbo->iSolidColor : 0);
654 r = (int)GetRValue(BrushColor);
655 g = (int)GetGValue(BrushColor);
656 b = (int)GetBValue(BrushColor);
657
658 tMask = (PBYTE)psoMask->pvScan0 + (pptlMask->y * psoMask->lDelta) + pptlMask->x;
659 for (j = 0; j < dy; j++)
660 {
661 lMask = tMask;
662 for (i = 0; i < dx; i++)
663 {
664 if (*lMask > 0)
665 {
666 if (*lMask == 0xff)
667 {
668 DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
669 psoDest, prclDest->left + i, prclDest->top + j, pbo ? pbo->iSolidColor : 0);
670 }
671 else
672 {
673 Background = DIB_GetSource(psoDest, prclDest->left + i, prclDest->top + j,
674 pxloBrush);
675
676 NewColor =
677 RGB((*lMask * (r - GetRValue(Background)) >> 8) + GetRValue(Background),
678 (*lMask * (g - GetGValue(Background)) >> 8) + GetGValue(Background),
679 (*lMask * (b - GetBValue(Background)) >> 8) + GetBValue(Background));
680
681 Background = XLATEOBJ_iXlate(pxloRGB2Dest, NewColor);
682 DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
683 psoDest, prclDest->left + i, prclDest->top + j, Background);
684 }
685 }
686 lMask++;
687 }
688 tMask += psoMask->lDelta;
689 }
690 return TRUE;
691 }
692 else
693 {
694 return FALSE;
695 }
696 }
697
698 static
699 BOOL APIENTRY
700 EngMaskBitBlt(SURFOBJ *psoDest,
701 SURFOBJ *psoMask,
702 CLIPOBJ *ClipRegion,
703 XLATEOBJ *DestColorTranslation,
704 XLATEOBJ *SourceColorTranslation,
705 RECTL *DestRect,
706 POINTL *pptlMask,
707 BRUSHOBJ *pbo,
708 POINTL *BrushOrigin)
709 {
710 BYTE clippingType;
711 RECTL CombinedRect;
712 RECT_ENUM RectEnum;
713 BOOL EnumMore;
714 POINTL InputPoint;
715 RECTL InputRect;
716 RECTL OutputRect;
717 POINTL Translate;
718 INTENG_ENTER_LEAVE EnterLeaveSource;
719 INTENG_ENTER_LEAVE EnterLeaveDest;
720 SURFOBJ* psoInput;
721 SURFOBJ* psoOutput;
722 BOOLEAN Ret = TRUE;
723 RECTL ClipRect;
724 unsigned i;
725 POINTL Pt;
726 ULONG Direction;
727 POINTL AdjustedBrushOrigin;
728
729 ASSERT(psoMask);
730
731 if (pptlMask)
732 {
733 InputRect.left = pptlMask->x;
734 InputRect.right = pptlMask->x + (DestRect->right - DestRect->left);
735 InputRect.top = pptlMask->y;
736 InputRect.bottom = pptlMask->y + (DestRect->bottom - DestRect->top);
737 }
738 else
739 {
740 InputRect.left = 0;
741 InputRect.right = DestRect->right - DestRect->left;
742 InputRect.top = 0;
743 InputRect.bottom = DestRect->bottom - DestRect->top;
744 }
745
746 OutputRect = *DestRect;
747 if (NULL != ClipRegion)
748 {
749 if (OutputRect.left < ClipRegion->rclBounds.left)
750 {
751 InputRect.left += ClipRegion->rclBounds.left - OutputRect.left;
752 OutputRect.left = ClipRegion->rclBounds.left;
753 }
754 if (ClipRegion->rclBounds.right < OutputRect.right)
755 {
756 InputRect.right -= OutputRect.right - ClipRegion->rclBounds.right;
757 OutputRect.right = ClipRegion->rclBounds.right;
758 }
759 if (OutputRect.top < ClipRegion->rclBounds.top)
760 {
761 InputRect.top += ClipRegion->rclBounds.top - OutputRect.top;
762 OutputRect.top = ClipRegion->rclBounds.top;
763 }
764 if (ClipRegion->rclBounds.bottom < OutputRect.bottom)
765 {
766 InputRect.bottom -= OutputRect.bottom - ClipRegion->rclBounds.bottom;
767 OutputRect.bottom = ClipRegion->rclBounds.bottom;
768 }
769 }
770
771 if (! IntEngEnter(&EnterLeaveSource, psoMask, &InputRect, TRUE, &Translate, &psoInput))
772 {
773 return FALSE;
774 }
775
776 InputPoint.x = InputRect.left + Translate.x;
777 InputPoint.y = InputRect.top + Translate.y;
778
779 /* Check for degenerate case: if height or width of OutputRect is 0 pixels there's
780 nothing to do */
781 if (OutputRect.right <= OutputRect.left || OutputRect.bottom <= OutputRect.top)
782 {
783 IntEngLeave(&EnterLeaveSource);
784 return TRUE;
785 }
786
787 if (! IntEngEnter(&EnterLeaveDest, psoDest, &OutputRect, FALSE, &Translate, &psoOutput))
788 {
789 IntEngLeave(&EnterLeaveSource);
790 return FALSE;
791 }
792
793 OutputRect.left = DestRect->left + Translate.x;
794 OutputRect.right = DestRect->right + Translate.x;
795 OutputRect.top = DestRect->top + Translate.y;
796 OutputRect.bottom = DestRect->bottom + Translate.y;
797
798 if (BrushOrigin)
799 {
800 AdjustedBrushOrigin.x = BrushOrigin->x + Translate.x;
801 AdjustedBrushOrigin.y = BrushOrigin->y + Translate.y;
802 }
803 else
804 AdjustedBrushOrigin = Translate;
805
806 // Determine clipping type
807 if (ClipRegion == (CLIPOBJ *) NULL)
808 {
809 clippingType = DC_TRIVIAL;
810 } else {
811 clippingType = ClipRegion->iDComplexity;
812 }
813
814 switch (clippingType)
815 {
816 case DC_TRIVIAL:
817 if (psoMask->iBitmapFormat == BMF_8BPP)
818 Ret = AlphaBltMask(psoOutput, NULL , psoInput, DestColorTranslation, SourceColorTranslation,
819 &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin);
820 else
821 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
822 &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin,
823 R4_MASK);
824 break;
825 case DC_RECT:
826 // Clip the blt to the clip rectangle
827 ClipRect.left = ClipRegion->rclBounds.left + Translate.x;
828 ClipRect.right = ClipRegion->rclBounds.right + Translate.x;
829 ClipRect.top = ClipRegion->rclBounds.top + Translate.y;
830 ClipRect.bottom = ClipRegion->rclBounds.bottom + Translate.y;
831 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
832 {
833 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
834 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
835 if (psoMask->iBitmapFormat == BMF_8BPP)
836 {
837 Ret = AlphaBltMask(psoOutput, NULL, psoInput, DestColorTranslation, SourceColorTranslation,
838 &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin);
839 }
840 else
841 {
842 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
843 &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin, R4_MASK);
844 }
845 }
846 break;
847 case DC_COMPLEX:
848 Ret = TRUE;
849 if (psoOutput == psoInput)
850 {
851 if (OutputRect.top < InputPoint.y)
852 {
853 Direction = OutputRect.left < InputPoint.x ? CD_RIGHTDOWN : CD_LEFTDOWN;
854 }
855 else
856 {
857 Direction = OutputRect.left < InputPoint.x ? CD_RIGHTUP : CD_LEFTUP;
858 }
859 }
860 else
861 {
862 Direction = CD_ANY;
863 }
864 CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, Direction, 0);
865 do
866 {
867 EnumMore = CLIPOBJ_bEnum(ClipRegion,(ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
868
869 for (i = 0; i < RectEnum.c; i++)
870 {
871 ClipRect.left = RectEnum.arcl[i].left + Translate.x;
872 ClipRect.right = RectEnum.arcl[i].right + Translate.x;
873 ClipRect.top = RectEnum.arcl[i].top + Translate.y;
874 ClipRect.bottom = RectEnum.arcl[i].bottom + Translate.y;
875 if (RECTL_bIntersectRect(&CombinedRect, &OutputRect, &ClipRect))
876 {
877 Pt.x = InputPoint.x + CombinedRect.left - OutputRect.left;
878 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
879 if (psoMask->iBitmapFormat == BMF_8BPP)
880 {
881 Ret = AlphaBltMask(psoOutput, NULL, psoInput,
882 DestColorTranslation,
883 SourceColorTranslation,
884 &CombinedRect, NULL, &Pt, pbo,
885 &AdjustedBrushOrigin) && Ret;
886 }
887 else
888 {
889 Ret = BltMask(psoOutput, NULL, psoInput,
890 DestColorTranslation, &CombinedRect, NULL,
891 &Pt, pbo, &AdjustedBrushOrigin,
892 R4_MASK) && Ret;
893 }
894 }
895 }
896 }
897 while (EnumMore);
898 break;
899 }
900
901
902 IntEngLeave(&EnterLeaveDest);
903 IntEngLeave(&EnterLeaveSource);
904
905 return Ret;
906 }
907
908 BOOL APIENTRY
909 IntEngMaskBlt(SURFOBJ *psoDest,
910 SURFOBJ *psoMask,
911 CLIPOBJ *ClipRegion,
912 XLATEOBJ *DestColorTranslation,
913 XLATEOBJ *SourceColorTranslation,
914 RECTL *DestRect,
915 POINTL *pptlMask,
916 BRUSHOBJ *pbo,
917 POINTL *BrushOrigin)
918 {
919 BOOLEAN ret;
920 RECTL OutputRect;
921 POINTL InputPoint;
922 SURFACE *psurfDest;
923
924 ASSERT(psoMask);
925
926 if (pptlMask)
927 {
928 InputPoint = *pptlMask;
929 }
930
931 /* Clip against the bounds of the clipping region so we won't try to write
932 * outside the surface */
933 if (NULL != ClipRegion)
934 {
935 if (!RECTL_bIntersectRect(&OutputRect, DestRect, &ClipRegion->rclBounds))
936 {
937 return TRUE;
938 }
939 InputPoint.x += OutputRect.left - DestRect->left;
940 InputPoint.y += OutputRect.top - DestRect->top;
941 }
942 else
943 {
944 OutputRect = *DestRect;
945 }
946
947 /* No success yet */
948 ret = FALSE;
949 ASSERT(psoDest);
950 psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
951
952 /* Dummy BitBlt to let driver know that it should flush its changes.
953 This should really be done using a call to DrvSynchronizeSurface,
954 but the VMware driver doesn't hook that call. */
955 IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
956 DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
957 R4_NOOP);
958
959 ret = EngMaskBitBlt(psoDest, psoMask, ClipRegion, DestColorTranslation, SourceColorTranslation,
960 &OutputRect, &InputPoint, pbo, BrushOrigin);
961
962 /* Dummy BitBlt to let driver know that something has changed. */
963 IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
964 DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
965 R4_NOOP);
966
967 return ret;
968 }
969
970 /* EOF */