[CMAKE]
[reactos.git] / subsystems / win32 / win32k / objects / fillshap.c
index 51ddf3a..c1ff201 100644 (file)
@@ -49,7 +49,7 @@ IntGdiPolygon(PDC    dc,
 
     if (!Points || Count < 2 )
     {
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        EngSetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
 
@@ -214,7 +214,7 @@ NtGdiEllipse(
     dc = DC_LockDc(hDC);
     if (dc == NULL)
     {
-       SetLastWin32Error(ERROR_INVALID_HANDLE);
+       EngSetLastError(ERROR_INVALID_HANDLE);
        return FALSE;
     }
     if (dc->dctype == DC_TYPE_INFO)
@@ -248,12 +248,12 @@ NtGdiEllipse(
     if (pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
         DC_vUpdateLineBrush(dc);
 
-    pbrush = PEN_LockPen(pdcattr->hpen);
+    pbrush = PEN_ShareLockPen(pdcattr->hpen);
     if (!pbrush)
     {
         DPRINT1("Ellipse Fail 1\n");
         DC_UnlockDc(dc);
-        SetLastWin32Error(ERROR_INTERNAL_ERROR);
+        EngSetLastError(ERROR_INTERNAL_ERROR);
         return FALSE;
     }
 
@@ -297,11 +297,11 @@ NtGdiEllipse(
     DPRINT("Ellipse 2: XLeft: %d, YLeft: %d, Width: %d, Height: %d\n",
                CenterX - RadiusX, CenterY + RadiusY, RadiusX*2, RadiusY*2);
 
-    pFillBrushObj = BRUSH_LockBrush(pdcattr->hbrush);
+    pFillBrushObj = BRUSH_ShareLockBrush(pdcattr->hbrush);
     if (NULL == pFillBrushObj)
     {
         DPRINT1("FillEllipse Fail\n");
-        SetLastWin32Error(ERROR_INTERNAL_ERROR);
+        EngSetLastError(ERROR_INTERNAL_ERROR);
         ret = FALSE;
     }
     else
@@ -317,7 +317,7 @@ NtGdiEllipse(
                               RadiusX*2, // Width
                               RadiusY*2, // Height
                               &tmpFillBrushObj);
-        BRUSH_UnlockBrush(pFillBrushObj);
+        BRUSH_ShareUnlockBrush(pFillBrushObj);
     }
 
     if (ret)
@@ -329,7 +329,7 @@ NtGdiEllipse(
                              pbrush);
 
     pbrush->ptPenWidth.x = PenOrigWidth;
-    PEN_UnlockPen(pbrush);
+    PEN_ShareUnlockPen(pbrush);
     DC_UnlockDc(dc);
     DPRINT("Ellipse Exit.\n");
     return ret;
@@ -418,7 +418,7 @@ NtGdiPolyPolyDraw( IN HDC hDC,
     if (nInvalid != 0)
     {
         /* If at least one poly count is 0 or 1, fail */
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        EngSetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
 
@@ -428,7 +428,7 @@ NtGdiPolyPolyDraw( IN HDC hDC,
                                   TAG_SHAPE);
     if (!pTemp)
     {
-        SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+        EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
         return FALSE;
     }
 
@@ -465,7 +465,7 @@ NtGdiPolyPolyDraw( IN HDC hDC,
     dc = DC_LockDc(hDC);
     if (!dc)
     {
-        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        EngSetLastError(ERROR_INVALID_HANDLE);
         ExFreePool(pTemp);
         return FALSE;
     }
@@ -506,7 +506,7 @@ NtGdiPolyPolyDraw( IN HDC hDC,
             Ret = IntGdiPolyBezierTo(dc, SafePoints, *SafeCounts);
             break;
         default:
-            SetLastWin32Error(ERROR_INVALID_PARAMETER);
+            EngSetLastError(ERROR_INVALID_PARAMETER);
             Ret = FALSE;
     }
 
@@ -545,10 +545,11 @@ IntRectangle(PDC dc,
         return PATH_Rectangle ( dc, LeftRect, TopRect, RightRect, BottomRect );
     }
 
-    DestRect.left = LeftRect;
-    DestRect.right = RightRect;
-    DestRect.top = TopRect;
-    DestRect.bottom = BottomRect;
+       /* Make sure rectangle is not inverted */
+    DestRect.left   = min(LeftRect, RightRect);
+    DestRect.right  = max(LeftRect, RightRect);
+    DestRect.top    = min(TopRect,  BottomRect);
+    DestRect.bottom = max(TopRect,  BottomRect);
 
     IntLPtoDP(dc, (LPPOINT)&DestRect, 2);
 
@@ -604,7 +605,7 @@ IntRectangle(PDC dc,
                                NULL,
                                &dc->eboFill.BrushObject,
                                &BrushOrigin,
-                               ROP3_TO_ROP4(PATCOPY));
+                               ROP4_FROM_INDEX(R3_OPINDEX_PATCOPY));
         }
     }
 
@@ -667,7 +668,7 @@ NtGdiRectangle(HDC  hDC,
     dc = DC_LockDc(hDC);
     if (!dc)
     {
-        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        EngSetLastError(ERROR_INVALID_HANDLE);
         return FALSE;
     }
     if (dc->dctype == DC_TYPE_INFO)
@@ -713,7 +714,7 @@ IntRoundRect(
     int  yCurveDiameter)
 {
     PDC_ATTR pdcattr;
-    PBRUSH   pbrushLine, pbrushFill;
+    PBRUSH   pbrLine, pbrFill;
     RECTL RectBounds;
     LONG PenWidth, PenOrigWidth;
     BOOL ret = TRUE; // default to success
@@ -747,18 +748,18 @@ IntRoundRect(
     if (pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
         DC_vUpdateLineBrush(dc);
 
-    pbrushLine = PEN_LockPen(pdcattr->hpen);
-    if (!pbrushLine)
+    pbrLine = PEN_ShareLockPen(pdcattr->hpen);
+    if (!pbrLine)
     {
         /* Nothing to do, as we don't have a bitmap */
-        SetLastWin32Error(ERROR_INTERNAL_ERROR);
+        EngSetLastError(ERROR_INTERNAL_ERROR);
         return FALSE;
     }
 
-    PenOrigWidth = PenWidth = pbrushLine->ptPenWidth.x;
-    if (pbrushLine->ulPenStyle == PS_NULL) PenWidth = 0;
+    PenOrigWidth = PenWidth = pbrLine->ptPenWidth.x;
+    if (pbrLine->ulPenStyle == PS_NULL) PenWidth = 0;
 
-    if (pbrushLine->ulPenStyle == PS_INSIDEFRAME)
+    if (pbrLine->ulPenStyle == PS_INSIDEFRAME)
     {
        if (2*PenWidth > (Right - Left)) PenWidth = (Right -Left + 1)/2;
        if (2*PenWidth > (Bottom - Top)) PenWidth = (Bottom -Top + 1)/2;
@@ -769,7 +770,7 @@ IntRoundRect(
     }
 
     if (!PenWidth) PenWidth = 1;
-    pbrushLine->ptPenWidth.x = PenWidth;
+    pbrLine->ptPenWidth.x = PenWidth;
 
     RectBounds.left = Left;
     RectBounds.top = Top;
@@ -783,16 +784,16 @@ IntRoundRect(
     RectBounds.right  += dc->ptlDCOrig.x;
     RectBounds.bottom += dc->ptlDCOrig.y;
 
-    pbrushFill = BRUSH_LockBrush(pdcattr->hbrush);
-    if (NULL == pbrushFill)
+    pbrFill = BRUSH_ShareLockBrush(pdcattr->hbrush);
+    if (!pbrFill)
     {
         DPRINT1("FillRound Fail\n");
-        SetLastWin32Error(ERROR_INTERNAL_ERROR);
+        EngSetLastError(ERROR_INTERNAL_ERROR);
         ret = FALSE;
     }
     else
     {
-        RtlCopyMemory(&brushTemp, pbrushFill, sizeof(brushTemp));
+        RtlCopyMemory(&brushTemp, pbrFill, sizeof(brushTemp));
         brushTemp.ptOrigin.x += RectBounds.left - Left;
         brushTemp.ptOrigin.y += RectBounds.top - Top;
         ret = IntFillRoundRect( dc,
@@ -803,7 +804,7 @@ IntRoundRect(
                                 xCurveDiameter,
                                 yCurveDiameter,
                                 &brushTemp);
-        BRUSH_UnlockBrush(pbrushFill);
+        BRUSH_ShareUnlockBrush(pbrFill);
     }
 
     if (ret)
@@ -814,10 +815,10 @@ IntRoundRect(
                 RectBounds.bottom,
                    xCurveDiameter,
                    yCurveDiameter,
-                   pbrushLine);
+                   pbrLine);
 
-    pbrushLine->ptPenWidth.x = PenOrigWidth;
-    PEN_UnlockPen(pbrushLine);
+    pbrLine->ptPenWidth.x = PenOrigWidth;
+    PEN_ShareUnlockPen(pbrLine);
     return ret;
 }
 
@@ -839,7 +840,7 @@ NtGdiRoundRect(
     if ( !dc )
     {
         DPRINT1("NtGdiRoundRect() - hDC is invalid\n");
-        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        EngSetLastError(ERROR_INVALID_HANDLE);
     }
     else if (dc->dctype == DC_TYPE_INFO)
     {
@@ -885,7 +886,7 @@ GreGradientFill(
                 pTriangle->Vertex2 >= nVertex ||
                 pTriangle->Vertex3 >= nVertex)
             {
-                SetLastWin32Error(ERROR_INVALID_PARAMETER);
+                EngSetLastError(ERROR_INVALID_PARAMETER);
                 return FALSE;
             }
         }
@@ -897,7 +898,7 @@ GreGradientFill(
         {
             if (pRect->UpperLeft >= nVertex || pRect->LowerRight >= nVertex)
             {
-                SetLastWin32Error(ERROR_INVALID_PARAMETER);
+                EngSetLastError(ERROR_INVALID_PARAMETER);
                 return FALSE;
             }
         }
@@ -907,7 +908,7 @@ GreGradientFill(
     pdc = DC_LockDc(hdc);
     if(!pdc)
     {
-        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        EngSetLastError(ERROR_INVALID_HANDLE);
         return FALSE;
     }
 
@@ -991,7 +992,7 @@ NtGdiGradientFill(
     /* Validate parameters */
     if (!pVertex || !nVertex || !pMesh || !nMesh)
     {
-        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        EngSetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
 
@@ -1005,7 +1006,7 @@ NtGdiGradientFill(
             cbMesh = nMesh * sizeof(GRADIENT_TRIANGLE);
             break;
         default:
-            SetLastWin32Error(ERROR_INVALID_PARAMETER);
+            EngSetLastError(ERROR_INVALID_PARAMETER);
             return FALSE;
     }
 
@@ -1020,7 +1021,7 @@ NtGdiGradientFill(
     SafeVertex = ExAllocatePoolWithTag(PagedPool, cbVertex + cbMesh, TAG_SHAPE);
     if(!SafeVertex)
     {
-        SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+        EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
         return FALSE;
     }
 
@@ -1061,7 +1062,6 @@ NtGdiExtFloodFill(
     PDC dc;
     PDC_ATTR   pdcattr;
     SURFACE    *psurf = NULL;
-    PPALETTE   ppal;
     EXLATEOBJ  exlo;
     BOOL       Ret = FALSE;
     RECTL      DestRect;
@@ -1071,7 +1071,7 @@ NtGdiExtFloodFill(
     dc = DC_LockDc(hDC);
     if (!dc)
     {
-        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        EngSetLastError(ERROR_INVALID_HANDLE);
         return FALSE;
     }
     if (dc->dctype == DC_TYPE_INFO)
@@ -1106,16 +1106,7 @@ NtGdiExtFloodFill(
         goto cleanup;
     }
 
-    if (psurf->ppal)
-    {
-        ppal = psurf->ppal;
-        GDIOBJ_IncrementShareCount(&ppal->BaseObject);
-    }
-    else
-        // Destination palette obtained from the hDC
-        ppal = PALETTE_ShareLockPalette(dc->ppdev->devinfo.hpalDefault);
-
-    EXLATEOBJ_vInitialize(&exlo, &gpalRGB, ppal, 0, 0xffffff, 0);
+    EXLATEOBJ_vInitialize(&exlo, &gpalRGB, psurf->ppal, 0, 0xffffff, 0);
 
     /* Only solid fills supported for now
      * How to support pattern brushes and non standard surfaces (not offering dib functions):
@@ -1125,7 +1116,6 @@ NtGdiExtFloodFill(
     Ret = DIB_XXBPP_FloodFillSolid(&psurf->SurfObj, &dc->eboFill.BrushObject, &DestRect, &Pt, ConvColor, FillType);
 
     EXLATEOBJ_vCleanup(&exlo);
-    PALETTE_ShareUnlockPalette(ppal);
 
 cleanup:
     DC_UnlockDc(dc);