[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / reactos / subsystems / win32 / win32k / eng / copybits.c
index f0d8646..afb2f16 100644 (file)
@@ -12,9 +12,9 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 /*
  * COPYRIGHT:        See COPYING in the top level directory
@@ -26,7 +26,7 @@
  *        8/18/1999: Created
  */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
 /*
  * @implemented
  */
-BOOL STDCALL
-EngCopyBits(SURFOBJ *Dest,
-           SURFOBJ *Source,
-           CLIPOBJ *Clip,
-           XLATEOBJ *ColorTranslation,
-           RECTL *DestRect,
-           POINTL *SourcePoint)
+BOOL APIENTRY
+EngCopyBits(SURFOBJ *psoDest,
+            SURFOBJ *psoSource,
+            CLIPOBJ *Clip,
+            XLATEOBJ *ColorTranslation,
+            RECTL *DestRect,
+            POINTL *SourcePoint)
 {
-  BOOLEAN   ret;
-  BYTE      clippingType;
-  RECT_ENUM RectEnum;
-  BOOL      EnumMore;
-  BLTINFO   BltInfo;
-  BITMAPOBJ *DestObj = NULL;
-  BITMAPOBJ *SourceObj;
-
-  ASSERT(Dest != NULL && Source != NULL && DestRect != NULL && SourcePoint != NULL);
-
-  SourceObj = CONTAINING_RECORD(Source, BITMAPOBJ, SurfObj);
-  BITMAPOBJ_LockBitmapBits(SourceObj);
-  MouseSafetyOnDrawStart(Source, SourcePoint->x, SourcePoint->y,
-                         (SourcePoint->x + abs(DestRect->right - DestRect->left)),
-                         (SourcePoint->y + abs(DestRect->bottom - DestRect->top)));
-  if (Dest != Source)
+    BOOL      ret;
+    BYTE      clippingType;
+    RECT_ENUM RectEnum;
+    BOOL      EnumMore;
+    BLTINFO   BltInfo;
+    SURFACE *psurfDest;
+    SURFACE *psurfSource;
+
+    ASSERT(psoDest != NULL && psoSource != NULL && DestRect != NULL && SourcePoint != NULL);
+
+    psurfSource = CONTAINING_RECORD(psoSource, SURFACE, SurfObj);
+    psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
+
+    // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
+    //        mark the copy block function to be DrvCopyBits instead of the
+    //        GDI's copy bit function so as to remove clipping from the
+    //        driver's responsibility
+
+    // If one of the surfaces isn't managed by the GDI
+    if ((psoDest->iType!=STYPE_BITMAP) || (psoSource->iType!=STYPE_BITMAP))
     {
-    DestObj = CONTAINING_RECORD(Dest, BITMAPOBJ, SurfObj);
-    BITMAPOBJ_LockBitmapBits(DestObj);
-    }
-  MouseSafetyOnDrawStart(Dest, DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
-
-  // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
-  //        mark the copy block function to be DrvCopyBits instead of the
-  //        GDI's copy bit function so as to remove clipping from the
-  //        driver's responsibility
-
-  // If one of the surfaces isn't managed by the GDI
-  if((Dest->iType!=STYPE_BITMAP) || (Source->iType!=STYPE_BITMAP))
-  {
-    // Destination surface is device managed
-    if(Dest->iType!=STYPE_BITMAP)
-    {
-      /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
-      /* FIXME: Remove typecast. */
-      if (((BITMAPOBJ*)Dest)->flHooks & HOOK_COPYBITS)
-      {
-        ret = GDIDEVFUNCS(Dest).CopyBits(
-          Dest, Source, Clip, ColorTranslation, DestRect, SourcePoint);
-
-        MouseSafetyOnDrawEnd(Dest);
-        if (Dest != Source)
-          {
-          BITMAPOBJ_UnlockBitmapBits(DestObj);
-          }
-        MouseSafetyOnDrawEnd(Source);
-        BITMAPOBJ_UnlockBitmapBits(SourceObj);
-
-        return ret;
-      }
-    }
-
-    // Source surface is device managed
-    if(Source->iType!=STYPE_BITMAP)
-    {
-      /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
-      /* FIXME: Remove typecast. */
-      if (((BITMAPOBJ*)Source)->flHooks & HOOK_COPYBITS)
-      {
-        ret = GDIDEVFUNCS(Source).CopyBits(
-          Dest, Source, Clip, ColorTranslation, DestRect, SourcePoint);
-
-        MouseSafetyOnDrawEnd(Dest);
-        if (Dest != Source)
-          {
-          BITMAPOBJ_UnlockBitmapBits(DestObj);
-          }
-        MouseSafetyOnDrawEnd(Source);
-        BITMAPOBJ_UnlockBitmapBits(SourceObj);
-
-        return ret;
-      }
-    }
+        // Destination surface is device managed
+        if (psoDest->iType!=STYPE_BITMAP)
+        {
+            /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
+            if (psurfDest->flags & HOOK_COPYBITS)
+            {
+                ret = GDIDEVFUNCS(psoDest).CopyBits(
+                          psoDest, psoSource, Clip, ColorTranslation, DestRect, SourcePoint);
 
-    // If CopyBits wasn't hooked, BitBlt must be
-    ret = IntEngBitBlt(Dest, Source,
-                       NULL, Clip, ColorTranslation, DestRect, SourcePoint,
-                       NULL, NULL, NULL, ROP3_TO_ROP4(SRCCOPY));
+                goto cleanup;
+            }
+        }
 
-    MouseSafetyOnDrawEnd(Dest);
-    if (Dest != Source)
-      {
-      BITMAPOBJ_UnlockBitmapBits(DestObj);
-      }
-    MouseSafetyOnDrawEnd(Source);
-    BITMAPOBJ_UnlockBitmapBits(SourceObj);
+        // Source surface is device managed
+        if (psoSource->iType!=STYPE_BITMAP)
+        {
+            /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
+            if (psurfSource->flags & HOOK_COPYBITS)
+            {
+                ret = GDIDEVFUNCS(psoSource).CopyBits(
+                          psoDest, psoSource, Clip, ColorTranslation, DestRect, SourcePoint);
 
-    return ret;
-  }
-
-  // Determine clipping type
-  if (Clip == (CLIPOBJ *) NULL)
-  {
-    clippingType = DC_TRIVIAL;
-  } else {
-    clippingType = Clip->iDComplexity;
-  }
-
-  BltInfo.DestSurface = Dest;
-  BltInfo.SourceSurface = Source;
-  BltInfo.PatternSurface = NULL;
-  BltInfo.XlateSourceToDest = ColorTranslation;
-  BltInfo.XlatePatternToDest = NULL;
-  BltInfo.Rop4 = SRCCOPY;
-
-  switch(clippingType)
-    {
-      case DC_TRIVIAL:
-        BltInfo.DestRect = *DestRect;
-        BltInfo.SourcePoint = *SourcePoint;
+                goto cleanup;
+            }
+        }
 
-        DibFunctionsForBitmapFormat[Dest->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo);
+        // If CopyBits wasn't hooked, BitBlt must be
+        ret = IntEngBitBlt(psoDest, psoSource,
+                           NULL, Clip, ColorTranslation, DestRect, SourcePoint,
+                           NULL, NULL, NULL, ROP3_TO_ROP4(SRCCOPY));
 
-        MouseSafetyOnDrawEnd(Dest);
-        if (Dest != Source)
-          {
-          BITMAPOBJ_UnlockBitmapBits(DestObj);
-          }
-        MouseSafetyOnDrawEnd(Source);
-        BITMAPOBJ_UnlockBitmapBits(SourceObj);
+        goto cleanup;
+    }
 
-        return(TRUE);
+    // Determine clipping type
+    if (!Clip)
+    {
+        clippingType = DC_TRIVIAL;
+    }
+    else
+    {
+        clippingType = Clip->iDComplexity;
+    }
 
-      case DC_RECT:
-        // Clip the blt to the clip rectangle
-        EngIntersectRect(&BltInfo.DestRect, DestRect, &Clip->rclBounds);
+    BltInfo.DestSurface = psoDest;
+    BltInfo.SourceSurface = psoSource;
+    BltInfo.PatternSurface = NULL;
+    BltInfo.XlateSourceToDest = ColorTranslation;
+    BltInfo.Rop4 = SRCCOPY;
 
-        BltInfo.SourcePoint.x = SourcePoint->x + BltInfo.DestRect.left - DestRect->left;
-        BltInfo.SourcePoint.y = SourcePoint->y + BltInfo.DestRect.top  - DestRect->top;
+    switch (clippingType)
+    {
+        case DC_TRIVIAL:
+            BltInfo.DestRect = *DestRect;
+            BltInfo.SourcePoint = *SourcePoint;
 
-        DibFunctionsForBitmapFormat[Dest->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo);
+            ret = DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo);
+            break;
 
-        MouseSafetyOnDrawEnd(Dest);
-        if (Dest != Source)
-          {
-          BITMAPOBJ_UnlockBitmapBits(DestObj);
-          }
-        MouseSafetyOnDrawEnd(Source);
-        BITMAPOBJ_UnlockBitmapBits(SourceObj);
+        case DC_RECT:
+            // Clip the blt to the clip rectangle
+            RECTL_bIntersectRect(&BltInfo.DestRect, DestRect, &Clip->rclBounds);
 
-        return(TRUE);
+            BltInfo.SourcePoint.x = SourcePoint->x + BltInfo.DestRect.left - DestRect->left;
+            BltInfo.SourcePoint.y = SourcePoint->y + BltInfo.DestRect.top  - DestRect->top;
 
-      case DC_COMPLEX:
+            ret = DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo);
+            break;
 
-        CLIPOBJ_cEnumStart(Clip, FALSE, CT_RECTANGLES, CD_ANY, 0);
+        case DC_COMPLEX:
 
-        do {
-          EnumMore = CLIPOBJ_bEnum(Clip,(ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
+            CLIPOBJ_cEnumStart(Clip, FALSE, CT_RECTANGLES, CD_ANY, 0);
 
-          if (RectEnum.c > 0)
-          {
-            RECTL* prclEnd = &RectEnum.arcl[RectEnum.c];
-            RECTL* prcl    = &RectEnum.arcl[0];
+            do
+            {
+                EnumMore = CLIPOBJ_bEnum(Clip,(ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
 
-            do {
-              EngIntersectRect(&BltInfo.DestRect, prcl, DestRect);
+                if (RectEnum.c > 0)
+                {
+                    RECTL* prclEnd = &RectEnum.arcl[RectEnum.c];
+                    RECTL* prcl    = &RectEnum.arcl[0];
 
-              BltInfo.SourcePoint.x = SourcePoint->x + prcl->left - DestRect->left;
-              BltInfo.SourcePoint.y = SourcePoint->y + prcl->top - DestRect->top;
+                    do
+                    {
+                        RECTL_bIntersectRect(&BltInfo.DestRect, prcl, DestRect);
 
-              if(!DibFunctionsForBitmapFormat[Dest->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo))
-                return FALSE;
+                        BltInfo.SourcePoint.x = SourcePoint->x + prcl->left - DestRect->left;
+                        BltInfo.SourcePoint.y = SourcePoint->y + prcl->top - DestRect->top;
 
-              prcl++;
+                        if (!DibFunctionsForBitmapFormat[psoDest->iBitmapFormat].DIB_BitBltSrcCopy(&BltInfo))
+                        {
+                            ret = FALSE;
+                            goto cleanup;
+                        }
 
-              } while (prcl < prclEnd);
-            }
+                        prcl++;
 
-          } while(EnumMore);
+                    } while (prcl < prclEnd);
+                }
 
-          MouseSafetyOnDrawEnd(Dest);
-          if (Dest != Source)
-            {
-            BITMAPOBJ_UnlockBitmapBits(DestObj);
-            }
-          MouseSafetyOnDrawEnd(Source);
-          BITMAPOBJ_UnlockBitmapBits(SourceObj);
+            } while (EnumMore);
+            ret = TRUE;
+            break;
 
-          return(TRUE);
+        default:
+            ASSERT(FALSE);
+            ret = FALSE;
+            break;
     }
 
-  MouseSafetyOnDrawEnd(Dest);
-  if (Dest != Source)
-    {
-    BITMAPOBJ_UnlockBitmapBits(DestObj);
-    }
-  MouseSafetyOnDrawEnd(Source);
-  BITMAPOBJ_UnlockBitmapBits(SourceObj);
+cleanup:
+    return ret;
+}
 
-  return FALSE;
+BOOL APIENTRY
+IntEngCopyBits(
+    SURFOBJ *psoDest,
+    SURFOBJ *psoSource,
+    CLIPOBJ *pco,
+    XLATEOBJ *pxlo,
+    RECTL *prclDest,
+    POINTL *ptlSource)
+{
+    return EngCopyBits(psoDest, psoSource, pco, pxlo, prclDest, ptlSource);
 }
 
+
 /* EOF */