[WIN32K]
[reactos.git] / reactos / subsystems / win32 / win32k / eng / bitblt.c
index 0f28b1b..029f55e 100644 (file)
@@ -9,7 +9,7 @@
  *        2/10/1999: Created
  */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -48,8 +48,11 @@ BltMask(SURFOBJ* psoDest,
     LONG PatternX0 = 0, PatternX = 0, PatternY = 0;
     PFN_DIB_PutPixel fnDest_PutPixel = NULL;
     PFN_DIB_GetPixel fnPattern_GetPixel = NULL;
-    XLATEOBJ *XlateObj;
     ULONG Pattern = 0;
+    HBITMAP hbmPattern;
+
+    ASSERT(psoSource == NULL);
+    ASSERT(pptlSource == NULL);
 
     if (psoMask == NULL)
     {
@@ -60,14 +63,15 @@ BltMask(SURFOBJ* psoDest,
     {
         pebo = CONTAINING_RECORD(pbo, EBRUSHOBJ, BrushObject);
 
-        psurfPattern = SURFACE_LockSurface(pebo->pbrush->hbmPattern);
+        hbmPattern = EBRUSHOBJ_pvGetEngBrush(pebo);
+        psurfPattern = SURFACE_LockSurface(hbmPattern);
         if (psurfPattern != NULL)
         {
             psoPattern = &psurfPattern->SurfObj;
             PatternWidth = psoPattern->sizlBitmap.cx;
             PatternHeight = psoPattern->sizlBitmap.cy;
+            fnPattern_GetPixel = DibFunctionsForBitmapFormat[psoPattern->iBitmapFormat].DIB_GetPixel;
         }
-        fnPattern_GetPixel = DibFunctionsForBitmapFormat[psoPattern->iBitmapFormat].DIB_GetPixel;
     }
     else
         psurfPattern = NULL;
@@ -78,7 +82,6 @@ BltMask(SURFOBJ* psoDest,
     fnDest_PutPixel = DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel;
     if (psurfPattern)
     {
-        XlateObj = pebo ? pebo->XlateObject : NULL;
         PatternY = (prclDest->top - pptlBrush->y) % PatternHeight;
         if (PatternY < 0)
         {
@@ -101,8 +104,7 @@ BltMask(SURFOBJ* psoDest,
                 if (*pjMskCurrent & fjMaskBit)
                 {
                     fnDest_PutPixel(psoDest, x, y,
-                        XLATEOBJ_iXlate(XlateObj, 
-                            fnPattern_GetPixel(psoPattern, PatternX, PatternY)));
+                        fnPattern_GetPixel(psoPattern, PatternX, PatternY));
                 }
                 fjMaskBit = _rotr8(fjMaskBit, 1);
                 pjMskCurrent += (fjMaskBit >> 7);
@@ -177,6 +179,7 @@ CallDibBitBlt(SURFOBJ* OutputObj,
     PEBRUSHOBJ GdiBrush = NULL;
     SURFACE *psurfPattern;
     BOOLEAN Result;
+    HBITMAP hbmPattern;
 
     BltInfo.DestSurface = OutputObj;
     BltInfo.SourceSurface = InputObj;
@@ -188,7 +191,6 @@ CallDibBitBlt(SURFOBJ* OutputObj,
     if (ROP3_TO_ROP4(SRCCOPY) == Rop4)
         return DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo);
 
-    BltInfo.XlatePatternToDest = NULL;
     BltInfo.Brush = pbo;
     BltInfo.BrushOrigin = *BrushOrigin;
     BltInfo.Rop4 = Rop4;
@@ -197,7 +199,9 @@ CallDibBitBlt(SURFOBJ* OutputObj,
     if (ROP4_USES_PATTERN(Rop4) && pbo && pbo->iSolidColor == 0xFFFFFFFF)
     {
         GdiBrush = CONTAINING_RECORD(pbo, EBRUSHOBJ, BrushObject);
-        if ((psurfPattern = SURFACE_LockSurface(GdiBrush->pbrush->hbmPattern)))
+        hbmPattern = EBRUSHOBJ_pvGetEngBrush(GdiBrush);
+        psurfPattern = SURFACE_LockSurface(hbmPattern);
+        if (psurfPattern)
         {
             BltInfo.PatternSurface = &psurfPattern->SurfObj;
         }
@@ -205,7 +209,6 @@ CallDibBitBlt(SURFOBJ* OutputObj,
         {
             /* FIXME - What to do here? */
         }
-        BltInfo.XlatePatternToDest = GdiBrush->XlateObject;
     }
     else
     {
@@ -215,7 +218,7 @@ CallDibBitBlt(SURFOBJ* OutputObj,
     Result = DibFunctionsForBitmapFormat[OutputObj->iBitmapFormat].DIB_BitBlt(&BltInfo);
 
     /* Pattern brush */
-    if (psurfPattern != NULL)
+    if (psurfPattern)
     {
         SURFACE_UnlockSurface(psurfPattern);
     }
@@ -304,11 +307,9 @@ EngBitBlt(SURFOBJ *DestObj,
     POINTL             Pt;
     ULONG              Direction;
     BOOL               UsesSource;
-    BOOL               UsesPattern;
     POINTL             AdjustedBrushOrigin;
 
     UsesSource = ROP4_USES_SOURCE(rop4);
-    UsesPattern = ROP4_USES_PATTERN(rop4);
     if (R4_NOOP == rop4)
     {
         /* Copy destination onto itself: nop */
@@ -369,6 +370,7 @@ EngBitBlt(SURFOBJ *DestObj,
     }
     else
     {
+        InputPoint.x = InputPoint.y = 0;
         InputRect.left = 0;
         InputRect.right = DestRect->right - DestRect->left;
         InputRect.top = 0;
@@ -521,7 +523,7 @@ EngBitBlt(SURFOBJ *DestObj,
 }
 
 BOOL APIENTRY
-IntEngBitBltEx(
+IntEngBitBlt(
     SURFOBJ *psoTrg,
     SURFOBJ *psoSrc,
     SURFOBJ *psoMask,
@@ -532,16 +534,13 @@ IntEngBitBltEx(
     POINTL *pptlMask,
     BRUSHOBJ *pbo,
     POINTL *pptlBrush,
-    ROP4 rop4,
-    BOOL bRemoveMouse)
+    ROP4 rop4)
 {
     SURFACE *psurfTrg;
     SURFACE *psurfSrc = NULL;
     BOOL bResult;
     RECTL rclClipped;
     RECTL rclSrc;
-//    INTENG_ENTER_LEAVE EnterLeaveSource;
-//    INTENG_ENTER_LEAVE EnterLeaveDest;
     PFN_DrvBitBlt pfnBitBlt;
 
     ASSERT(psoTrg);
@@ -551,9 +550,9 @@ IntEngBitBltEx(
     rclClipped = *prclTrg;
     RECTL_vMakeWellOrdered(&rclClipped);
 
-    /* Clip target rect against the bounds of the clipping region */
     if (pco)
     {
+        /* Clip target rect against the bounds of the clipping region */
         if (!RECTL_bIntersectRect(&rclClipped, &rclClipped, &pco->rclBounds))
         {
             /* Nothing left */
@@ -582,28 +581,11 @@ IntEngBitBltEx(
         psurfSrc = NULL;
     }
 
-    if (bRemoveMouse)
-    {
-        SURFACE_LockBitmapBits(psurfTrg);
-
-        if (psoSrc)
-        {
-            if (psoSrc != psoTrg)
-            {
-                SURFACE_LockBitmapBits(psurfSrc);
-            }
-            MouseSafetyOnDrawStart(psoSrc, rclSrc.left, rclSrc.top,
-                                   rclSrc.right, rclSrc.bottom);
-        }
-        MouseSafetyOnDrawStart(psoTrg, rclClipped.left, rclClipped.top,
-                               rclClipped.right, rclClipped.bottom);
-    }
-
     /* Is the target surface device managed? */
-    if (psurfTrg->flHooks & HOOK_BITBLT)
+    if (psurfTrg->flags & HOOK_BITBLT)
     {
         /* Is the source a different device managed surface? */
-        if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flHooks & HOOK_BITBLT)
+        if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flags & HOOK_BITBLT)
         {
             DPRINT1("Need to copy to standard bitmap format!\n");
             ASSERT(FALSE);
@@ -613,7 +595,7 @@ IntEngBitBltEx(
     }
 
     /* Is the source surface device managed? */
-    else if (psoSrc && psurfSrc->flHooks & HOOK_BITBLT)
+    else if (psoSrc && psurfSrc->flags & HOOK_BITBLT)
     {
         pfnBitBlt = GDIDEVFUNCS(psoSrc).BitBlt;
     }
@@ -636,21 +618,6 @@ IntEngBitBltEx(
 
     // FIXME: cleanup temp surface!
 
-    if (bRemoveMouse)
-    {
-        MouseSafetyOnDrawEnd(psoTrg);
-        if (psoSrc)
-        {
-            MouseSafetyOnDrawEnd(psoSrc);
-            if (psoSrc != psoTrg)
-            {
-                SURFACE_UnlockBitmapBits(psurfSrc);
-            }
-        }
-
-        SURFACE_UnlockBitmapBits(psurfTrg);
-    }
-
     return bResult;
 }
 
@@ -662,8 +629,8 @@ static BOOLEAN APIENTRY
 AlphaBltMask(SURFOBJ* psoDest,
              SURFOBJ* psoSource, // unused
              SURFOBJ* psoMask,
-             XLATEOBJ* ColorTranslation,
-             XLATEOBJ* SrcColorTranslation,
+             XLATEOBJ* pxloRGB2Dest,
+             XLATEOBJ* pxloBrush,
              RECTL* prclDest,
              POINTL* pptlSource, // unused
              POINTL* pptlMask,
@@ -675,12 +642,15 @@ AlphaBltMask(SURFOBJ* psoDest,
     ULONG Background, BrushColor, NewColor;
     BYTE *tMask, *lMask;
 
+    ASSERT(psoSource == NULL);
+    ASSERT(pptlSource == NULL);
+
     dx = prclDest->right  - prclDest->left;
     dy = prclDest->bottom - prclDest->top;
 
     if (psoMask != NULL)
     {
-        BrushColor = XLATEOBJ_iXlate(SrcColorTranslation, pbo ? pbo->iSolidColor : 0);
+        BrushColor = XLATEOBJ_iXlate(pxloBrush, pbo ? pbo->iSolidColor : 0);
         r = (int)GetRValue(BrushColor);
         g = (int)GetGValue(BrushColor);
         b = (int)GetBValue(BrushColor);
@@ -701,14 +671,14 @@ AlphaBltMask(SURFOBJ* psoDest,
                     else
                     {
                         Background = DIB_GetSource(psoDest, prclDest->left + i, prclDest->top + j,
-                                                   SrcColorTranslation);
+                                                   pxloBrush);
 
                         NewColor =
                             RGB((*lMask * (r - GetRValue(Background)) >> 8) + GetRValue(Background),
                                 (*lMask * (g - GetGValue(Background)) >> 8) + GetGValue(Background),
                                 (*lMask * (b - GetBValue(Background)) >> 8) + GetBValue(Background));
 
-                        Background = XLATEOBJ_iXlate(ColorTranslation, NewColor);
+                        Background = XLATEOBJ_iXlate(pxloRGB2Dest, NewColor);
                         DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_PutPixel(
                             psoDest, prclDest->left + i, prclDest->top + j, Background);
                     }
@@ -846,10 +816,10 @@ EngMaskBitBlt(SURFOBJ *psoDest,
         case DC_TRIVIAL:
             if (psoMask->iBitmapFormat == BMF_8BPP)
                 Ret = AlphaBltMask(psoOutput, NULL , psoInput, DestColorTranslation, SourceColorTranslation,
-                                   &OutputRect, &InputPoint, pptlMask, pbo, &AdjustedBrushOrigin);
+                                   &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin);
             else
                 Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
-                              &OutputRect, &InputPoint, pptlMask, pbo, &AdjustedBrushOrigin,
+                              &OutputRect, NULL, &InputPoint, pbo, &AdjustedBrushOrigin,
                               R4_MASK);
             break;
         case DC_RECT:
@@ -864,13 +834,13 @@ EngMaskBitBlt(SURFOBJ *psoDest,
                 Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
                 if (psoMask->iBitmapFormat == BMF_8BPP)
                 {
-                    Ret = AlphaBltMask(psoOutput, psoInput, psoMask, DestColorTranslation, SourceColorTranslation,
-                                       &CombinedRect, &Pt, pptlMask, pbo, &AdjustedBrushOrigin);
+                    Ret = AlphaBltMask(psoOutput, NULL, psoInput, DestColorTranslation, SourceColorTranslation,
+                                       &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin);
                 }
                 else
                 {
-                    Ret = BltMask(psoOutput, psoInput, psoMask, DestColorTranslation,
-                                  &CombinedRect, &Pt, pptlMask, pbo, &AdjustedBrushOrigin, R4_MASK);
+                    Ret = BltMask(psoOutput, NULL, psoInput, DestColorTranslation,
+                                  &CombinedRect, NULL, &Pt, pbo, &AdjustedBrushOrigin, R4_MASK);
                 }
             }
             break;
@@ -908,17 +878,17 @@ EngMaskBitBlt(SURFOBJ *psoDest,
                         Pt.y = InputPoint.y + CombinedRect.top - OutputRect.top;
                         if (psoMask->iBitmapFormat == BMF_8BPP)
                         {
-                            Ret = AlphaBltMask(psoOutput, psoInput, psoMask,
+                            Ret = AlphaBltMask(psoOutput, NULL, psoInput,
                                                DestColorTranslation,
                                                SourceColorTranslation,
-                                               &CombinedRect, &Pt, pptlMask, pbo,
+                                               &CombinedRect, NULL, &Pt, pbo,
                                                &AdjustedBrushOrigin) && Ret;
                         }
                         else
                         {
-                            Ret = BltMask(psoOutput, psoInput, psoMask,
-                                          DestColorTranslation, &CombinedRect, &Pt,
-                                          pptlMask, pbo, &AdjustedBrushOrigin,
+                            Ret = BltMask(psoOutput, NULL, psoInput,
+                                          DestColorTranslation, &CombinedRect, NULL,
+                                          &Pt, pbo, &AdjustedBrushOrigin,
                                           R4_MASK) && Ret;
                         }
                     }
@@ -979,27 +949,20 @@ IntEngMaskBlt(SURFOBJ *psoDest,
     ASSERT(psoDest);
     psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
 
-    SURFACE_LockBitmapBits(psurfDest);
-    MouseSafetyOnDrawStart(psoDest, OutputRect.left, OutputRect.top,
-                           OutputRect.right, OutputRect.bottom);
-
     /* Dummy BitBlt to let driver know that it should flush its changes.
        This should really be done using a call to DrvSynchronizeSurface,
        but the VMware driver doesn't hook that call. */
-    IntEngBitBltEx(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
+    IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
                    DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
-                   R4_NOOP, FALSE);
+                   R4_NOOP);
 
     ret = EngMaskBitBlt(psoDest, psoMask, ClipRegion, DestColorTranslation, SourceColorTranslation,
                         &OutputRect, &InputPoint, pbo, BrushOrigin);
 
     /* Dummy BitBlt to let driver know that something has changed. */
-    IntEngBitBltEx(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
+    IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
                    DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
-                   R4_NOOP, FALSE);
-
-    MouseSafetyOnDrawEnd(psoDest);
-    SURFACE_UnlockBitmapBits(psurfDest);
+                   R4_NOOP);
 
     return ret;
 }