[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / reactos / subsystems / win32 / win32k / eng / mouse.c
index 93ab14d..b2db0e6 100644 (file)
@@ -37,23 +37,17 @@ EngSetPointerTag(
  */
 INT INTERNAL_CALL
 MouseSafetyOnDrawStart(
-    SURFOBJ *pso,
+    PPDEVOBJ ppdev,
     LONG HazardX1,
     LONG HazardY1,
     LONG HazardX2,
     LONG HazardY2)
 {
     LONG tmp;
-    PDEVOBJ *ppdev;
     GDIPOINTER *pgp;
 
-    ASSERT(pso != NULL);
-
-    ppdev = GDIDEV(pso);
-    if (ppdev == NULL)
-    {
-        return FALSE;
-    }
+    ASSERT(ppdev != NULL);
+    ASSERT(ppdev->pSurface != NULL);
 
     pgp = &ppdev->Pointer;
 
@@ -83,12 +77,12 @@ MouseSafetyOnDrawStart(
     }
 
     if (pgp->Exclude.right >= HazardX1
-            && pgp->Exclude.left <= HazardX2
-            && pgp->Exclude.bottom >= HazardY1
-            && pgp->Exclude.top <= HazardY2)
+        && pgp->Exclude.left <= HazardX2
+        && pgp->Exclude.bottom >= HazardY1
+        && pgp->Exclude.top <= HazardY2)
     {
         ppdev->SafetyRemoveLevel = ppdev->SafetyRemoveCount;
-        ppdev->pfnMovePointer(pso, -1, -1, NULL);
+        ppdev->pfnMovePointer(&ppdev->pSurface->SurfObj, -1, -1, NULL);
     }
 
     return(TRUE);
@@ -99,19 +93,12 @@ MouseSafetyOnDrawStart(
  */
 INT INTERNAL_CALL
 MouseSafetyOnDrawEnd(
-    SURFOBJ *pso)
+    PPDEVOBJ ppdev)
 {
-    PDEVOBJ *ppdev;
     GDIPOINTER *pgp;
 
-    ASSERT(pso != NULL);
-
-    ppdev = (PDEVOBJ*)pso->hdev;
-
-    if (ppdev == NULL)
-    {
-        return(FALSE);
-    }
+    ASSERT(ppdev != NULL);
+    ASSERT(ppdev->pSurface != NULL);
 
     pgp = &ppdev->Pointer;
 
@@ -125,7 +112,10 @@ MouseSafetyOnDrawEnd(
         return FALSE;
     }
 
-    ppdev->pfnMovePointer(pso, gpsi->ptCursor.x, gpsi->ptCursor.y, &pgp->Exclude);
+    ppdev->pfnMovePointer(&ppdev->pSurface->SurfObj,
+                          gpsi->ptCursor.x,
+                          gpsi->ptCursor.y,
+                          &pgp->Exclude);
 
     ppdev->SafetyRemoveLevel = 0;
 
@@ -175,18 +165,17 @@ IntHideMousePointer(
     ptlSave.x = rclDest.left - pt.x;
     ptlSave.y = rclDest.top - pt.y;
 
-    IntEngBitBltEx(psoDest,
-                   &pgp->psurfSave->SurfObj,
-                   NULL,
-                   NULL,
-                   NULL,
-                   &rclDest,
-                   &ptlSave,
-                   &ptlSave,
-                   NULL,
-                   NULL,
-                   ROP3_TO_ROP4(SRCCOPY),
-                   FALSE);
+    IntEngBitBlt(psoDest,
+                 &pgp->psurfSave->SurfObj,
+                 NULL,
+                 NULL,
+                 NULL,
+                 &rclDest,
+                 &ptlSave,
+                 &ptlSave,
+                 NULL,
+                 NULL,
+                 ROP3_TO_ROP4(SRCCOPY));
 }
 
 VOID
@@ -229,77 +218,72 @@ IntShowMousePointer(PDEVOBJ *ppdev, SURFOBJ *psoDest)
     rclPointer.bottom = min(pgp->Size.cy, psoDest->sizlBitmap.cy - pt.y);
 
     /* Copy the pixels under the cursor to temporary surface. */
-    IntEngBitBltEx(&pgp->psurfSave->SurfObj,
-                   psoDest,
-                   NULL,
-                   NULL,
-                   NULL,
-                   &rclPointer,
-                   (POINTL*)&rclSurf,
-                   NULL,
-                   NULL,
-                   NULL,
-                   ROP3_TO_ROP4(SRCCOPY),
-                   FALSE);
+    IntEngBitBlt(&pgp->psurfSave->SurfObj,
+                 psoDest,
+                 NULL,
+                 NULL,
+                 NULL,
+                 &rclPointer,
+                 (POINTL*)&rclSurf,
+                 NULL,
+                 NULL,
+                 NULL,
+                 ROP3_TO_ROP4(SRCCOPY));
 
     /* Blt the pointer on the screen. */
     if (pgp->psurfColor)
     {
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfMask->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCAND),
-                       FALSE);
-
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfColor->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCINVERT),
-                       FALSE);
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfMask->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCAND));
+
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfColor->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCINVERT));
     }
     else
     {
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfMask->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCAND),
-                       FALSE);
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfMask->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCAND));
 
         rclPointer.top += pgp->Size.cy;
 
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfMask->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCINVERT),
-                       FALSE);
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfMask->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCINVERT));
     }
 }
 
@@ -353,7 +337,7 @@ EngSetPointerShape(
         rectl.bottom = sizel.cy;
 
         /* Calculate lDelta for our surfaces. */
-        lDelta = DIB_GetDIBWidthBytes(sizel.cx, 
+        lDelta = WIDTH_BYTES_ALIGN32(sizel.cx, 
                                       BitsPerFormat(pso->iBitmapFormat));
 
         /* Create a bitmap for saving the pixels under the cursor. */
@@ -373,10 +357,10 @@ EngSetPointerShape(
 
         /* Create a bitmap to copy the color bitmap to */
         hbmColor = EngCreateBitmap(psoColor->sizlBitmap,
-                                   lDelta,
-                                   pso->iBitmapFormat,
-                                   BMF_TOPDOWN | BMF_NOZEROINIT,
-                                   NULL);
+                           lDelta,
+                           pso->iBitmapFormat,
+                           BMF_TOPDOWN | BMF_NOZEROINIT,
+                           NULL);
         psurfColor = SURFACE_ShareLockSurface(hbmColor);
         if (!psurfColor) goto failure;
 
@@ -540,28 +524,13 @@ EngMovePointer(
             prcl->right = prcl->left + pgp->Size.cx;
             prcl->bottom = prcl->top + pgp->Size.cy;
         }
-    } 
+    }
     else if (prcl != NULL)
     {
         prcl->left = prcl->top = prcl->right = prcl->bottom = -1;
     }
 }
 
-VOID APIENTRY
-IntEngMovePointer(
-    IN SURFOBJ *pso,
-    IN LONG x,
-    IN LONG y,
-    IN RECTL *prcl)
-{
-    SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
-    PPDEVOBJ ppdev = (PPDEVOBJ)pso->hdev;
-
-    SURFACE_LockBitmapBits(psurf);
-    ppdev->pfnMovePointer(pso, x, y, prcl);
-    SURFACE_UnlockBitmapBits(psurf);
-}
-
 ULONG APIENTRY
 IntEngSetPointerShape(
    IN SURFOBJ *pso,
@@ -576,13 +545,11 @@ IntEngSetPointerShape(
    IN FLONG fl)
 {
     ULONG ulResult = SPS_DECLINE;
-    SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
     PFN_DrvSetPointerShape pfnSetPointerShape;
     PPDEVOBJ ppdev = GDIDEV(pso);
 
     pfnSetPointerShape = GDIDEVFUNCS(pso).SetPointerShape;
 
-    SURFACE_LockBitmapBits(psurf);
     if (pfnSetPointerShape)
     {
         ulResult = pfnSetPointerShape(pso,
@@ -620,8 +587,6 @@ IntEngSetPointerShape(
         ppdev->pfnMovePointer = EngMovePointer;
     }
 
-    SURFACE_UnlockBitmapBits(psurf);
-
     return ulResult;
 }
 
@@ -649,10 +614,14 @@ GreSetPointerShape(
         return 0;
     }
 
-    psurf = pdc->dclevel.pSurface;
+    ASSERT(pdc->dctype == DCTYPE_DIRECT);
+    EngAcquireSemaphore(pdc->ppdev->hsemDevLock);
+    /* We're not sure DC surface is the good one */
+    psurf = pdc->ppdev->pSurface;
     if (!psurf)
     {
         DPRINT1("DC has no surface.\n");
+        EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
         DC_UnlockDc(pdc);
         return 0;
     }
@@ -668,7 +637,7 @@ GreSetPointerShape(
     {
         /* We have one, lock it */
         psurfColor = SURFACE_ShareLockSurface(hbmColor);
-        
+
         if (psurfColor)
         {
             /* Create an XLATEOBJ, no mono support */
@@ -700,6 +669,8 @@ GreSetPointerShape(
     if (psurfMask)
         SURFACE_ShareUnlockSurface(psurfMask);
 
+    EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
+
     /* Unlock the DC */
     DC_UnlockDc(pdc);
 
@@ -724,12 +695,23 @@ GreMovePointer(
         DPRINT1("Failed to lock the DC.\n");
         return;
     }
+    ASSERT(pdc->dctype == DCTYPE_DIRECT);
+
+    /* Acquire PDEV lock */
+    EngAcquireSemaphore(pdc->ppdev->hsemDevLock);
 
-    /* Store the cursor exclude position in the PDEV */
-    prcl = &pdc->ppdev->Pointer.Exclude;
+    /* Check if we need to move it */
+    if(pdc->ppdev->SafetyRemoveLevel == 0)
+    {
+        /* Store the cursor exclude position in the PDEV */
+        prcl = &pdc->ppdev->Pointer.Exclude;
+
+        /* Call Eng/Drv function */
+        pdc->ppdev->pfnMovePointer(&pdc->ppdev->pSurface->SurfObj, x, y, prcl);
+    }
 
-    /* Call Eng/Drv function */
-    IntEngMovePointer(&pdc->dclevel.pSurface->SurfObj, x, y, prcl);
+    /* Release PDEV lock */
+    EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
 
     /* Unlock the DC */
     DC_UnlockDc(pdc);