[CMAKE]
[reactos.git] / subsystems / win32 / win32k / objects / cliprgn.c
index e2971f6..532d766 100644 (file)
@@ -26,28 +26,31 @@ int FASTCALL
 CLIPPING_UpdateGCRegion(DC* Dc)
 {
    PROSRGNDATA CombinedRegion;
-   HRGN hRgnVis = NULL;
+   HRGN hRgnVis;
+   PREGION prgnClip, prgnGCClip;
 
     // would prefer this, but the rest of the code sucks
 //    ASSERT(Dc->rosdc.hGCClipRgn);
 //    ASSERT(Dc->rosdc.hClipRgn);
-   if (!Dc->prgnVis)
-   {
-      DPRINT1("Warning, prgnVis is NULL!\n");
-   }
-   else
-   {
-       hRgnVis = Dc->prgnVis->BaseObject.hHmgr ;
-   }
-
+   ASSERT(Dc->prgnVis);
+   hRgnVis = Dc->prgnVis->BaseObject.hHmgr;
 
    if (Dc->rosdc.hGCClipRgn == NULL)
       Dc->rosdc.hGCClipRgn = IntSysCreateRectRgn(0, 0, 0, 0);
 
+   prgnGCClip = REGION_LockRgn(Dc->rosdc.hGCClipRgn);
+   ASSERT(prgnGCClip);
+
    if (Dc->rosdc.hClipRgn == NULL)
-      NtGdiCombineRgn(Dc->rosdc.hGCClipRgn, hRgnVis, 0, RGN_COPY);
-   else // FYI: Vis == NULL! source of "IntGdiCombineRgn requires hSrc2 != NULL for combine mode 1!"
-      NtGdiCombineRgn(Dc->rosdc.hGCClipRgn, Dc->rosdc.hClipRgn, hRgnVis, RGN_AND);
+      IntGdiCombineRgn(prgnGCClip, Dc->prgnVis, NULL, RGN_COPY);
+   else
+   {
+      prgnClip = REGION_LockRgn(Dc->rosdc.hClipRgn); // FIXME: locking order, ugh
+      IntGdiCombineRgn(prgnGCClip, Dc->prgnVis, prgnClip, RGN_AND);
+      REGION_UnlockRgn(prgnClip);
+   }
+   REGION_UnlockRgn(prgnGCClip);
+
    NtGdiOffsetRgn(Dc->rosdc.hGCClipRgn, Dc->ptlDCOrig.x, Dc->ptlDCOrig.y);
 
    if((CombinedRegion = RGNOBJAPI_Lock(Dc->rosdc.hGCClipRgn, NULL)))
@@ -80,27 +83,26 @@ GdiSelectVisRgn(HDC hdc, HRGN hrgn)
 {
   int retval;
   DC *dc;
+  PREGION prgn;
 
   if (!hrgn)
   {
-       SetLastWin32Error(ERROR_INVALID_PARAMETER);
+       EngSetLastError(ERROR_INVALID_PARAMETER);
        return ERROR;
   }
   if (!(dc = DC_LockDc(hdc)))
   {
-       SetLastWin32Error(ERROR_INVALID_HANDLE);
+       EngSetLastError(ERROR_INVALID_HANDLE);
        return ERROR;
   }
 
   dc->fs &= ~DC_FLAG_DIRTY_RAO;
 
-  if (dc->prgnVis == NULL)
-  {
-    dc->prgnVis = IntSysCreateRectpRgn(0, 0, 0, 0);
-    GDIOBJ_CopyOwnership(hdc, dc->prgnVis->BaseObject.hHmgr);
-  }
+  ASSERT (dc->prgnVis != NULL);
 
-  retval = NtGdiCombineRgn(dc->prgnVis->BaseObject.hHmgr, hrgn, 0, RGN_COPY);
+  prgn = RGNOBJAPI_Lock(hrgn, NULL);
+  retval = prgn ? IntGdiCombineRgn(dc->prgnVis, prgn, NULL, RGN_COPY) : ERROR;
+  RGNOBJAPI_Unlock(prgn);
   if ( retval != ERROR )
   {
     IntGdiOffsetRgn(dc->prgnVis, -dc->ptlDCOrig.x, -dc->ptlDCOrig.y);
@@ -124,13 +126,13 @@ int FASTCALL GdiExtSelectClipRgn(PDC dc,
     {
       if (dc->rosdc.hClipRgn != NULL)
       {
-        REGION_FreeRgnByHandle(dc->rosdc.hClipRgn);
+        GreDeleteObject(dc->rosdc.hClipRgn);
         dc->rosdc.hClipRgn = NULL;
       }
     }
     else
     {
-      SetLastWin32Error(ERROR_INVALID_PARAMETER);
+      EngSetLastError(ERROR_INVALID_PARAMETER);
       return ERROR;
     }
   }
@@ -138,12 +140,10 @@ int FASTCALL GdiExtSelectClipRgn(PDC dc,
   {
     if (!dc->rosdc.hClipRgn)
     {
-      PROSRGNDATA Rgn;
       RECTL rect;
-      if((Rgn = RGNOBJAPI_Lock(dc->prgnVis->BaseObject.hHmgr, NULL)))
+      if(dc->prgnVis)
       {
-        REGION_GetRgnBox(Rgn, &rect);
-        RGNOBJAPI_Unlock(Rgn);
+               REGION_GetRgnBox(dc->prgnVis, &rect);
         dc->rosdc.hClipRgn = IntSysCreateRectRgnIndirect(&rect);
       }
       else
@@ -172,7 +172,7 @@ int APIENTRY NtGdiExtSelectClipRgn(HDC  hDC,
 
   if (!(dc = DC_LockDc(hDC)))
   {
-       SetLastWin32Error(ERROR_INVALID_HANDLE);
+       EngSetLastError(ERROR_INVALID_HANDLE);
        return ERROR;
   }
 
@@ -185,10 +185,10 @@ int APIENTRY NtGdiExtSelectClipRgn(HDC  hDC,
 INT FASTCALL
 GdiGetClipBox(HDC hDC, PRECTL rc)
 {
-   PROSRGNDATA Rgn;
    INT retval;
    PDC dc;
-   HRGN hRgnNew, hRgn = NULL;
+   PROSRGNDATA pRgnNew, pRgn = NULL;
+   BOOL Unlock = FALSE; //Small hack
 
    if (!(dc = DC_LockDc(hDC)))
    {
@@ -198,45 +198,41 @@ GdiGetClipBox(HDC hDC, PRECTL rc)
    /* FIXME! Rao and Vis only! */
    if (dc->prgnAPI) // APIRGN
    {
-      hRgn = ((PROSRGNDATA)dc->prgnAPI)->BaseObject.hHmgr;
+      pRgn = dc->prgnAPI;
    }
    else if (dc->dclevel.prgnMeta) // METARGN
    {
-      hRgn = ((PROSRGNDATA)dc->dclevel.prgnMeta)->BaseObject.hHmgr;
+      pRgn = dc->dclevel.prgnMeta;
    }
-   else
+   else if (dc->rosdc.hClipRgn)
    {
-      hRgn = dc->rosdc.hClipRgn; // CLIPRGN
+          Unlock = TRUE ;
+       pRgn = REGION_LockRgn(dc->rosdc.hClipRgn); // CLIPRGN
    }
 
-   if (hRgn)
+   if (pRgn)
    {
-      hRgnNew = IntSysCreateRectRgn( 0, 0, 0, 0 );
+      pRgnNew = IntSysCreateRectpRgn( 0, 0, 0, 0 );
 
-      NtGdiCombineRgn(hRgnNew, dc->prgnVis->BaseObject.hHmgr, hRgn, RGN_AND);
-
-      if (!(Rgn = RGNOBJAPI_Lock(hRgnNew, NULL)))
+         if (!pRgnNew)
       {
          DC_UnlockDc(dc);
+                if(Unlock) REGION_UnlockRgn(pRgn);
          return ERROR;
       }
 
-      retval = REGION_GetRgnBox(Rgn, rc);
+      IntGdiCombineRgn(pRgnNew, dc->prgnVis, pRgn, RGN_AND);
+
+      retval = REGION_GetRgnBox(pRgnNew, rc);
 
-      REGION_FreeRgnByHandle(hRgnNew);
-      RGNOBJAPI_Unlock(Rgn);
+         REGION_Delete(pRgnNew);
 
       DC_UnlockDc(dc);
+         if(Unlock) REGION_UnlockRgn(pRgn);
       return retval;
    }
 
-   if (!(Rgn = RGNOBJAPI_Lock(dc->prgnVis->BaseObject.hHmgr, NULL)))
-   {
-      DC_UnlockDc(dc);
-      return ERROR;
-   }
-   retval = REGION_GetRgnBox(Rgn, rc);
-   RGNOBJAPI_Unlock(Rgn);
+   retval = REGION_GetRgnBox(dc->prgnVis, rc);
    IntDPtoLP(dc, (LPPOINT)rc, 2);
    DC_UnlockDc(dc);
 
@@ -282,12 +278,12 @@ int APIENTRY NtGdiExcludeClipRect(HDC  hDC,
 {
    INT Result;
    RECTL Rect;
-   HRGN NewRgn;
+   PREGION prgnNew, prgnClip;
    PDC dc = DC_LockDc(hDC);
 
    if (!dc)
    {
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
+      EngSetLastError(ERROR_INVALID_HANDLE);
       return ERROR;
    }
 
@@ -298,8 +294,8 @@ int APIENTRY NtGdiExcludeClipRect(HDC  hDC,
 
    IntLPtoDP(dc, (LPPOINT)&Rect, 2);
 
-   NewRgn = IntSysCreateRectRgnIndirect(&Rect);
-   if (!NewRgn)
+   prgnNew = IntSysCreateRectpRgnIndirect(&Rect);
+   if (!prgnNew)
    {
       Result = ERROR;
    }
@@ -308,14 +304,18 @@ int APIENTRY NtGdiExcludeClipRect(HDC  hDC,
       if (!dc->rosdc.hClipRgn)
       {
          dc->rosdc.hClipRgn = IntSysCreateRectRgn(0, 0, 0, 0);
-         NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->prgnVis->BaseObject.hHmgr, NewRgn, RGN_DIFF);
+         prgnClip = REGION_LockRgn(dc->rosdc.hClipRgn);
+         IntGdiCombineRgn(prgnClip, dc->prgnVis, prgnNew, RGN_DIFF);
+         REGION_UnlockRgn(prgnClip);
          Result = SIMPLEREGION;
       }
       else
       {
-         Result = NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->rosdc.hClipRgn, NewRgn, RGN_DIFF);
+         prgnClip = REGION_LockRgn(dc->rosdc.hClipRgn);
+         Result = IntGdiCombineRgn(prgnClip, prgnClip, prgnNew, RGN_DIFF);
+         REGION_UnlockRgn(prgnClip);
       }
-      REGION_FreeRgnByHandle(NewRgn);
+      REGION_Delete(prgnNew);
    }
    if (Result != ERROR)
       CLIPPING_UpdateGCRegion(dc);
@@ -341,7 +341,7 @@ int APIENTRY NtGdiIntersectClipRect(HDC  hDC,
 
    if (!dc)
    {
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
+      EngSetLastError(ERROR_INVALID_HANDLE);
       return ERROR;
    }
 
@@ -365,7 +365,7 @@ int APIENTRY NtGdiIntersectClipRect(HDC  hDC,
    else
    {
       Result = NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->rosdc.hClipRgn, NewRgn, RGN_AND);
-      REGION_FreeRgnByHandle(NewRgn);
+      GreDeleteObject(NewRgn);
    }
    if (Result != ERROR)
       CLIPPING_UpdateGCRegion(dc);
@@ -384,7 +384,7 @@ int APIENTRY NtGdiOffsetClipRgn(HDC  hDC,
 
   if(!(dc = DC_LockDc(hDC)))
   {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    EngSetLastError(ERROR_INVALID_HANDLE);
     return ERROR;
   }
 
@@ -413,7 +413,7 @@ BOOL APIENTRY NtGdiPtVisible(HDC  hDC,
 
   if(!(dc = DC_LockDc(hDC)))
   {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    EngSetLastError(ERROR_INVALID_HANDLE);
     return FALSE;
   }
 
@@ -434,7 +434,7 @@ BOOL APIENTRY NtGdiRectVisible(HDC  hDC,
 
    if (!dc)
    {
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
+      EngSetLastError(ERROR_INVALID_HANDLE);
       return FALSE;
    }
 
@@ -492,13 +492,13 @@ IntGdiSetMetaRgn(PDC pDC)
                                    RGN_AND);
            if ( Ret )
            {
-              GDIOBJ_ShareUnlockObjByPtr(pDC->dclevel.prgnMeta);
+              GDIOBJ_vDereferenceObject(&pDC->dclevel.prgnMeta->BaseObject);
               if (!((PROSRGNDATA)pDC->dclevel.prgnMeta)->BaseObject.ulShareCount)
                  REGION_Delete(pDC->dclevel.prgnMeta);
 
               pDC->dclevel.prgnMeta = TempRgn;
 
-              GDIOBJ_ShareUnlockObjByPtr(pDC->dclevel.prgnClip);
+              GDIOBJ_vDereferenceObject(&pDC->dclevel.prgnClip->BaseObject);
               if (!((PROSRGNDATA)pDC->dclevel.prgnClip)->BaseObject.ulShareCount)
                  REGION_Delete(pDC->dclevel.prgnClip);
 
@@ -535,7 +535,7 @@ int APIENTRY NtGdiSetMetaRgn(HDC  hDC)
 
   if (!pDC)
   {
-     SetLastWin32Error(ERROR_INVALID_PARAMETER);
+     EngSetLastError(ERROR_INVALID_PARAMETER);
      return ERROR;
   }
   Ret = IntGdiSetMetaRgn(pDC);
@@ -550,7 +550,7 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
   CLIPOBJ * co;
 
   /* Must have VisRgn set to a valid state! */
-  if (!pDC->prgnVis) return ERROR;
+  ASSERT (pDC->prgnVis);
 
   if (pDC->prgnAPI)
   {