[CMAKE]
[reactos.git] / subsystems / win32 / win32k / objects / cliprgn.c
index 63b629a..532d766 100644 (file)
@@ -26,64 +26,54 @@ int FASTCALL
 CLIPPING_UpdateGCRegion(DC* Dc)
 {
    PROSRGNDATA CombinedRegion;
-   HRGN hRgnVis = Dc->prgnVis->BaseObject.hHmgr;
-
-   /* Experiment with API region based on wine.. */
-   if (Dc->rosdc.hClipRgn && Dc->dclevel.prgnMeta)
-   {
-      PROSRGNDATA pClipRgn;
-
-      if ((pClipRgn = RGNOBJAPI_Lock(Dc->rosdc.hClipRgn, NULL)))
-      {
-         if (!Dc->prgnAPI) Dc->prgnAPI = IntSysCreateRectpRgn( 0, 0, 0, 0 );
-
-         IntGdiCombineRgn( Dc->prgnAPI,
-                           pClipRgn,
-                           Dc->dclevel.prgnMeta,
-                           RGN_AND );
-         RGNOBJAPI_Unlock(pClipRgn);
-      }
-   }
-   else
-   {
-      if (Dc->prgnAPI)
-         GreDeleteObject(((PROSRGNDATA)Dc->prgnAPI)->BaseObject.hHmgr);
-      Dc->prgnAPI = NULL;
-   }
+   HRGN hRgnVis;
+   PREGION prgnClip, prgnGCClip;
 
+    // would prefer this, but the rest of the code sucks
+//    ASSERT(Dc->rosdc.hGCClipRgn);
+//    ASSERT(Dc->rosdc.hClipRgn);
+   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);
+      IntGdiCombineRgn(prgnGCClip, Dc->prgnVis, NULL, RGN_COPY);
    else
-      NtGdiCombineRgn(Dc->rosdc.hGCClipRgn, Dc->rosdc.hClipRgn, hRgnVis, RGN_AND);
+   {
+      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)))
-    {
-        CLIPOBJ *CombinedClip;
-      
-        CombinedClip = IntEngCreateClipRegion(CombinedRegion->rdh.nCount,
-                                              CombinedRegion->Buffer,
-                                              &CombinedRegion->rdh.rcBound);
+   if((CombinedRegion = RGNOBJAPI_Lock(Dc->rosdc.hGCClipRgn, NULL)))
+   {
+     CLIPOBJ *CombinedClip;
 
-        RGNOBJAPI_Unlock(CombinedRegion);
+     CombinedClip = IntEngCreateClipRegion(CombinedRegion->rdh.nCount,
+        CombinedRegion->Buffer,
+        &CombinedRegion->rdh.rcBound);
 
-        if (!CombinedClip)
-        {
-            DPRINT1("IntEngCreateClipRegion() failed\n");
-            return ERROR;
-        }
+     RGNOBJAPI_Unlock(CombinedRegion);
 
-        if (Dc->rosdc.CombinedClip != NULL)
-            IntEngDeleteClipRegion(Dc->rosdc.CombinedClip);
+     if ( !CombinedClip )
+     {
+       DPRINT1("IntEngCreateClipRegion() failed\n");
+       return ERROR;
+     }
 
-        Dc->rosdc.CombinedClip = CombinedClip;
-    }
+     if(Dc->rosdc.CombinedClip != NULL)
+       IntEngDeleteClipRegion(Dc->rosdc.CombinedClip);
 
+      Dc->rosdc.CombinedClip = CombinedClip ;
+   }
 
    return NtGdiOffsetRgn(Dc->rosdc.hGCClipRgn, -Dc->ptlDCOrig.x, -Dc->ptlDCOrig.y);
 }
@@ -93,15 +83,16 @@ 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;
   }
 
@@ -109,13 +100,14 @@ GdiSelectVisRgn(HDC hdc, HRGN hrgn)
 
   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 )
   {
-    NtGdiOffsetRgn(dc->prgnVis->BaseObject.hHmgr, -dc->ptlDCOrig.x, -dc->ptlDCOrig.y);
+    IntGdiOffsetRgn(dc->prgnVis, -dc->ptlDCOrig.x, -dc->ptlDCOrig.y);
     CLIPPING_UpdateGCRegion(dc);
   }
-
   DC_UnlockDc(dc);
 
   return retval;
@@ -134,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;
     }
   }
@@ -166,6 +158,7 @@ int FASTCALL GdiExtSelectClipRgn(PDC dc,
     else
       NtGdiCombineRgn(dc->rosdc.hClipRgn, dc->rosdc.hClipRgn, hrgn, fnMode);
   }
+
   return CLIPPING_UpdateGCRegion(dc);
 }
 
@@ -179,7 +172,7 @@ int APIENTRY NtGdiExtSelectClipRgn(HDC  hDC,
 
   if (!(dc = DC_LockDc(hDC)))
   {
-       SetLastWin32Error(ERROR_INVALID_HANDLE);
+       EngSetLastError(ERROR_INVALID_HANDLE);
        return ERROR;
   }
 
@@ -211,7 +204,7 @@ GdiGetClipBox(HDC hDC, PRECTL rc)
    {
       pRgn = dc->dclevel.prgnMeta;
    }
-   else
+   else if (dc->rosdc.hClipRgn)
    {
           Unlock = TRUE ;
        pRgn = REGION_LockRgn(dc->rosdc.hClipRgn); // CLIPRGN
@@ -232,7 +225,8 @@ GdiGetClipBox(HDC hDC, PRECTL rc)
 
       retval = REGION_GetRgnBox(pRgnNew, rc);
 
-         REGION_FreeRgnByHandle(pRgnNew->BaseObject.hHmgr);
+         REGION_Delete(pRgnNew);
+
       DC_UnlockDc(dc);
          if(Unlock) REGION_UnlockRgn(pRgn);
       return retval;
@@ -284,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;
    }
 
@@ -300,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;
    }
@@ -310,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);
@@ -343,7 +341,7 @@ int APIENTRY NtGdiIntersectClipRect(HDC  hDC,
 
    if (!dc)
    {
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
+      EngSetLastError(ERROR_INVALID_HANDLE);
       return ERROR;
    }
 
@@ -367,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);
@@ -386,7 +384,7 @@ int APIENTRY NtGdiOffsetClipRgn(HDC  hDC,
 
   if(!(dc = DC_LockDc(hDC)))
   {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    EngSetLastError(ERROR_INVALID_HANDLE);
     return ERROR;
   }
 
@@ -415,7 +413,7 @@ BOOL APIENTRY NtGdiPtVisible(HDC  hDC,
 
   if(!(dc = DC_LockDc(hDC)))
   {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    EngSetLastError(ERROR_INVALID_HANDLE);
     return FALSE;
   }
 
@@ -436,7 +434,7 @@ BOOL APIENTRY NtGdiRectVisible(HDC  hDC,
 
    if (!dc)
    {
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
+      EngSetLastError(ERROR_INVALID_HANDLE);
       return FALSE;
    }
 
@@ -494,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);
 
@@ -529,6 +527,7 @@ IntGdiSetMetaRgn(PDC pDC)
   return Ret;
 }
 
+
 int APIENTRY NtGdiSetMetaRgn(HDC  hDC)
 {
   INT Ret;
@@ -536,7 +535,7 @@ int APIENTRY NtGdiSetMetaRgn(HDC  hDC)
 
   if (!pDC)
   {
-     SetLastWin32Error(ERROR_INVALID_PARAMETER);
+     EngSetLastError(ERROR_INVALID_PARAMETER);
      return ERROR;
   }
   Ret = IntGdiSetMetaRgn(pDC);
@@ -570,7 +569,7 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
      IntGdiCombineRgn( pDC->prgnAPI,
                        pDC->dclevel.prgnClip,
                        pDC->dclevel.prgnMeta,
-                       RGN_AND );
+                       RGN_AND);
   }
   else
   {
@@ -579,43 +578,42 @@ NEW_CLIPPING_UpdateGCRegion(PDC pDC)
         IntGdiCombineRgn( pDC->prgnAPI,
                           pDC->dclevel.prgnClip,
                           NULL,
-                          RGN_COPY );
+                          RGN_COPY);
      }
      else if (pDC->dclevel.prgnMeta)
      {
         IntGdiCombineRgn( pDC->prgnAPI,
                           pDC->dclevel.prgnMeta,
                           NULL,
-                          RGN_COPY );
+                          RGN_COPY);
      }
   }
 
   IntGdiCombineRgn( pDC->prgnRao,
                     pDC->prgnVis,
                     pDC->prgnAPI,
-                    RGN_AND );
+                    RGN_AND);
 
-  RtlCopyMemory( &pDC->erclClip,
-                 &((PROSRGNDATA)pDC->prgnRao)->rdh.rcBound,
-                 sizeof(RECTL));
+  RtlCopyMemory(&pDC->erclClip,
+                &((PROSRGNDATA)pDC->prgnRao)->rdh.rcBound,
+                sizeof(RECTL));
 
   pDC->fs &= ~DC_FLAG_DIRTY_RAO;
 
   IntGdiOffsetRgn(pDC->prgnRao, pDC->ptlDCOrig.x, pDC->ptlDCOrig.y);
 
   // pDC->co should be used. Example, CLIPOBJ_cEnumStart uses XCLIPOBJ to build
-  // the rects from region objects rects in pClipRgn->Buffer. 
+  // the rects from region objects rects in pClipRgn->Buffer.
   // With pDC->co.pClipRgn->Buffer,
   // pDC->co.pClipRgn = pDC->prgnRao ? pDC->prgnRao : pDC->prgnVis;
 
   co = IntEngCreateClipRegion( ((PROSRGNDATA)pDC->prgnRao)->rdh.nCount,
                                ((PROSRGNDATA)pDC->prgnRao)->Buffer,
-                               &pDC->erclClip);
-
+                                 &pDC->erclClip);
   if (co)
   {
     if (pDC->rosdc.CombinedClip != NULL)
-     IntEngDeleteClipRegion(pDC->rosdc.CombinedClip);
+      IntEngDeleteClipRegion(pDC->rosdc.CombinedClip);
 
     pDC->rosdc.CombinedClip = co;
   }