[WIN32K]
[reactos.git] / subsystems / win32 / win32k / eng / mouse.c
index d96e8dd..5a96086 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;
 
@@ -88,7 +82,7 @@ MouseSafetyOnDrawStart(
             && 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,7 @@ 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;
 
@@ -385,7 +372,7 @@ EngSetPointerShape(
     pgp->HotSpot.y = yHot;
 
     /* Calculate lDelta for our surfaces. */
-    lDelta = DIB_GetDIBWidthBytes(pgp->Size.cx, 
+    lDelta = DIB_GetDIBWidthBytes(pgp->Size.cx,
                                   BitsPerFormat(pso->iBitmapFormat));
 
     rcl.left = 0;
@@ -526,7 +513,7 @@ 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;
@@ -540,12 +527,11 @@ IntEngMovePointer(
     IN LONG y,
     IN RECTL *prcl)
 {
-    SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
     PPDEVOBJ ppdev = (PPDEVOBJ)pso->hdev;
+    if(ppdev->SafetyRemoveLevel)
+        return ;
 
-    SURFACE_LockBitmapBits(psurf);
     ppdev->pfnMovePointer(pso, x, y, prcl);
-    SURFACE_UnlockBitmapBits(psurf);
 }
 
 ULONG APIENTRY
@@ -562,13 +548,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,
@@ -606,8 +590,6 @@ IntEngSetPointerShape(
         ppdev->pfnMovePointer = EngMovePointer;
     }
 
-    SURFACE_UnlockBitmapBits(psurf);
-
     return ulResult;
 }
 
@@ -635,10 +617,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;
     }
@@ -654,7 +640,7 @@ GreSetPointerShape(
     {
         /* We have one, lock it */
         psurfColor = SURFACE_ShareLockSurface(hbmColor);
-        
+
         if (psurfColor)
         {
             /* Create an XLATEOBJ, no mono support */
@@ -686,6 +672,8 @@ GreSetPointerShape(
     if (psurfMask)
         SURFACE_ShareUnlockSurface(psurfMask);
 
+    EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
+
     /* Unlock the DC */
     DC_UnlockDc(pdc);
 
@@ -710,13 +698,16 @@ GreMovePointer(
         DPRINT1("Failed to lock the DC.\n");
         return;
     }
+    ASSERT(pdc->dctype == DCTYPE_DIRECT);
 
+    EngAcquireSemaphore(pdc->ppdev->hsemDevLock);
     /* Store the cursor exclude position in the PDEV */
     prcl = &pdc->ppdev->Pointer.Exclude;
 
     /* Call Eng/Drv function */
-    IntEngMovePointer(&pdc->dclevel.pSurface->SurfObj, x, y, prcl);
+    IntEngMovePointer(&pdc->ppdev->pSurface->SurfObj, x, y, prcl);
 
+    EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
     /* Unlock the DC */
     DC_UnlockDc(pdc);
 }