branch update for HEAD-2003021201
[reactos.git] / subsys / win32k / objects / region.c
index 161b8ad..e81184d 100644 (file)
@@ -300,10 +300,8 @@ empty:
        return TRUE;
 }
 
-/***********************************************************************
- *           REGION_CropRgn
- *
- *
+/*!
+ * \param
  * hSrc:       Region to crop and offset.
  * lpRect:     Clipping rectangle. Can be NULL (no clipping).
  * lpPt:       Points to offset the cropped region. Can be NULL (no offset).
@@ -312,39 +310,27 @@ empty:
  *       Allowed to be the same region as hSrc in which case everything
  *      will be done in place, with no memory reallocations.
  *
- * Returns: hDst if success, 0 otherwise.
+ * \return     hDst if success, 0 otherwise.
  */
 HRGN REGION_CropRgn(HRGN hDst, HRGN hSrc, const PRECT lpRect, PPOINT lpPt)
 {
-  PROSRGNDATA objSrc = RGNDATA_LockRgn(hSrc);
-  HRGN hNewDst;
+  PROSRGNDATA objSrc, rgnDst;
+  HRGN hNewDst, hRet = NULL;
+  GDIMULTILOCK Lock[2] = {{hDst, 0, GO_REGION_MAGIC}, {hSrc, 0, GO_REGION_MAGIC}};
 
-  if(objSrc)
-  {
-       PROSRGNDATA rgnDst;
-
-    if(hDst)
-    {
-      if(!(rgnDst = RGNDATA_LockRgn(hDst)))
-      {
-        hDst = 0;
-        goto done;
-      }
-    }
-       else{
+  if( !hDst ){
          if( !( hNewDst = RGNDATA_AllocRgn(1) ) ){
-               RGNDATA_UnlockRgn( hSrc );
                return 0;
          }
+         Lock[0].hObj = hNewDst;
+  }
 
-      if(!(rgnDst = RGNDATA_LockRgn(hNewDst)))
-      {
-        RGNDATA_FreeRgn( hNewDst );
-               RGNDATA_UnlockRgn( hSrc );
-        return 0;
-      }
-       }
+  GDIOBJ_LockMultipleObj( &Lock, 2 );
+  rgnDst = Lock[0].pObj;
+  objSrc = Lock[1].pObj;
 
+  if( objSrc && rgnDst )
+  {
     if(rgnDst)
     {
       POINT pt = { 0, 0 };
@@ -354,44 +340,25 @@ HRGN REGION_CropRgn(HRGN hDst, HRGN hSrc, const PRECT lpRect, PPOINT lpPt)
 
       if(REGION_CropAndOffsetRegion(lpPt, lpRect, objSrc, rgnDst) == FALSE)
          { // ve failed cleanup and return
-               RGNDATA_UnlockRgn( hSrc );
-
-               if(hDst) // unlock new region if allocated
-                 RGNDATA_UnlockRgn( hDst );
-               else
-                 RGNDATA_UnlockRgn( hNewDst );
-
-               return 0;
+               hRet = NULL;
       }
       else{ // ve are fine. unlock the correct pointer and return correct handle
-               RGNDATA_UnlockRgn( hSrc );
-
-               if(hDst == 0){
-                       RGNDATA_UnlockRgn( hNewDst );
-                       return hNewDst;
-               }
-               else {
-                       RGNDATA_UnlockRgn( hDst );
-                       return hDst;
-               }
+               hRet = Lock[0].hObj;
          }
     }
-done:
-       RGNDATA_UnlockRgn( hSrc );
   }
-  return 0;
+  GDIOBJ_UnlockMultipleObj( &Lock, 2 );
+  return hRet;
 }
 
-/***********************************************************************
- *           REGION_Coalesce
- *
+/*!
  *      Attempt to merge the rects in the current band with those in the
  *      previous one. Used only by REGION_RegionOp.
  *
  * Results:
  *      The new index for the previous band.
  *
- * Side Effects:
+ * \note Side Effects:
  *      If coalescing takes place:
  *          - rectangles in the previous band will have their bottom fields
  *            altered.
@@ -517,9 +484,7 @@ static INT REGION_Coalesce (
     return (curStart);
 }
 
-/***********************************************************************
- *           REGION_RegionOp
- *
+/*!
  *      Apply an operation to two regions. Called by REGION_Union,
  *      REGION_Inverse, REGION_Subtract, REGION_Intersect...
  *
@@ -529,8 +494,7 @@ static INT REGION_Coalesce (
  * Side Effects:
  *      The new region is overwritten.
  *
- * Notes:
- *      The idea behind this function is to view the two regions as sets.
+ *\note The idea behind this function is to view the two regions as sets.
  *      Together they cover a rectangle of area that this function divides
  *      into horizontal bands where points are covered only by one region
  *      or by both. For the first case, the nonOverlapFunc is called with
@@ -824,15 +788,13 @@ static void REGION_RegionOp(
  ***********************************************************************/
 
 
-/***********************************************************************
- *          REGION_IntersectO
- *
+/*!
  * Handle an overlapping band for REGION_Intersect.
  *
  * Results:
  *      None.
  *
- * Side Effects:
+ * \note Side Effects:
  *      Rectangles may be added to the region.
  *
  */
@@ -919,9 +881,7 @@ static void REGION_IntersectRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1,
  *          Region Union
  ***********************************************************************/
 
-/***********************************************************************
- *          REGION_UnionNonO
- *
+/*!
  *      Handle a non-overlapping band for the union operation. Just
  *      Adds the rectangles into the region. Doesn't have to check for
  *      subsumption or anything.
@@ -929,7 +889,7 @@ static void REGION_IntersectRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1,
  * Results:
  *      None.
  *
- * Side Effects:
+ * \note Side Effects:
  *      pReg->numRects is incremented and the final rectangles overwritten
  *      with the rectangles we're passed.
  *
@@ -955,16 +915,14 @@ static void REGION_UnionNonO (ROSRGNDATA *pReg, RECT *r, RECT *rEnd,
     return;
 }
 
-/***********************************************************************
- *          REGION_UnionO
- *
+/*!
  *      Handle an overlapping band for the union operation. Picks the
  *      left-most rectangle each time and merges it into the region.
  *
  * Results:
  *      None.
  *
- * Side Effects:
+ * \note Side Effects:
  *      Rectangles are overwritten in pReg->rects and pReg->numRects will
  *      be changed.
  *
@@ -1093,16 +1051,14 @@ static void REGION_UnionRegion(ROSRGNDATA *newReg, ROSRGNDATA *reg1,
  *          Region Subtraction
  ***********************************************************************/
 
-/***********************************************************************
- *          REGION_SubtractNonO1
- *
+/*!
  *      Deal with non-overlapping band for subtraction. Any parts from
  *      region 2 we discard. Anything from region 1 we add to the region.
  *
  * Results:
  *      None.
  *
- * Side Effects:
+ * \note Side Effects:
  *      pReg may be affected.
  *
  */
@@ -1128,16 +1084,14 @@ static void REGION_SubtractNonO1 (ROSRGNDATA *pReg, RECT *r, RECT *rEnd,
 }
 
 
-/***********************************************************************
- *          REGION_SubtractO
- *
+/*!
  *      Overlapping band subtraction. x1 is the left-most point not yet
  *      checked.
  *
  * Results:
  *      None.
  *
- * Side Effects:
+ * \note Side Effects:
  *      pReg may have rectangles added to it.
  *
  */
@@ -1256,16 +1210,14 @@ static void REGION_SubtractO (ROSRGNDATA *pReg, RECT *r1, RECT *r1End,
     return;
 }
 
-/***********************************************************************
- *          REGION_SubtractRegion
- *
+/*!
  *      Subtract regS from regM and leave the result in regD.
  *      S stands for subtrahend, M for minuend and D for difference.
  *
  * Results:
  *      TRUE.
  *
- * Side Effects:
+ * \note Side Effects:
  *      regD is overwritten.
  *
  */
@@ -1332,9 +1284,8 @@ static void REGION_XorRegion(ROSRGNDATA *dr, ROSRGNDATA *sra,
 }
 
 
-/***********************************************************************
- *           REGION_UnionRectWithRegion
- *           Adds a rectangle to a WINEREGION
+/*!
+ * Adds a rectangle to a REGION
  */
 static void REGION_UnionRectWithRegion(const RECT *rect, ROSRGNDATA *rgn)
 {
@@ -1451,11 +1402,16 @@ W32kCombineRgn(HRGN  hDest,
                     INT  CombineMode)
 {
   INT result = ERROR;
-  PROSRGNDATA destRgn = RGNDATA_LockRgn(hDest);
+  GDIMULTILOCK Lock[3] = {{hDest, 0, GO_REGION_MAGIC}, {hSrc1, 0, GO_REGION_MAGIC}, {hSrc2, 0, GO_REGION_MAGIC}};
+  PROSRGNDATA destRgn, src1Rgn, src2Rgn;
 
-  if( destRgn ){
-       PROSRGNDATA src1Rgn = RGNDATA_LockRgn(hSrc1);
+  GDIOBJ_LockMultipleObj( &Lock, 3 );
 
+  destRgn = (PROSRGNDATA) Lock[0].pObj;
+  src1Rgn = (PROSRGNDATA) Lock[1].pObj;
+  src2Rgn = (PROSRGNDATA) Lock[2].pObj;
+
+  if( destRgn ){
        if( src1Rgn ){
                if (CombineMode == RGN_COPY)
                {
@@ -1465,7 +1421,6 @@ W32kCombineRgn(HRGN  hDest,
                }
                else
                {
-                 PROSRGNDATA src2Rgn = RGNDATA_LockRgn(hSrc2);
                  if( src2Rgn ){
                          switch (CombineMode)
                          {
@@ -1483,17 +1438,15 @@ W32kCombineRgn(HRGN  hDest,
                              break;
                          }
                          result = destRgn->rdh.iType;
-                         RGNDATA_UnlockRgn( hSrc2 );
                  }
-                 RGNDATA_UnlockRgn( hSrc1 );
                }
-               RGNDATA_UnlockRgn( hDest );
-       }
-       else{
-               DPRINT("W32kCombineRgn: hDest unavailable\n");
-               return ERROR;
        }
   }
+  else{
+      DPRINT("W32kCombineRgn: hDest unavailable\n");
+         result = ERROR;
+  }
+  GDIOBJ_UnlockMultipleObj( &Lock, 3 );
   return result;
 }
 
@@ -1944,9 +1897,7 @@ W32kUnionRectWithRgn(HRGN hDest, const RECT* unsafeRect)
        return hDest;
 }
 
-/***********************************************************************
- *           GetRegionData   (GDI32.@)
- *
+/*!
  * MSDN: GetRegionData, Return Values:
  *
  * "If the function succeeds and dwCount specifies an adequate number of bytes,