[NtGdi]
[reactos.git] / reactos / win32ss / gdi / ntgdi / path.c
index 8d7e34e..61de877 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PROJECT:         ReactOS win32 kernel mode subsystem
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            subsystems/win32/win32k/objects/path.c
+ * FILE:            win32ss/gdi/ntgdi/path.c
  * PURPOSE:         Graphics paths (BeginPath, EndPath etc.)
  * PROGRAMMER:      Copyright 1997, 1998 Martin Boehme
  *                            1999 Huw D M Davies
@@ -1252,6 +1252,7 @@ PATH_PathToRegion(
 
     if (numStrokes == 0)
     {
+        DPRINT1("numStrokes is 0\n");
         return FALSE;
     }
 
@@ -1259,6 +1260,7 @@ PATH_PathToRegion(
     pNumPointsInStroke = ExAllocatePoolWithTag(PagedPool, sizeof(ULONG) * numStrokes, TAG_PATH);
     if (!pNumPointsInStroke)
     {
+        DPRINT1("Failed to allocate %lu strokes\n", numStrokes);
         EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
         return FALSE;
     }
@@ -1280,11 +1282,15 @@ PATH_PathToRegion(
     }
 
     /* Fill the region with the strokes */
-    Ret = IntSetPolyPolygonRgn(pPath->pPoints,
-                               pNumPointsInStroke,
-                               numStrokes,
-                               nPolyFillMode,
-                               Rgn);
+    Ret = REGION_SetPolyPolygonRgn(Rgn,
+                                   pPath->pPoints,
+                                   pNumPointsInStroke,
+                                   numStrokes,
+                                   nPolyFillMode);
+    if (!Ret)
+    {
+        DPRINT1("REGION_SetPolyPolygonRgn failed\n");
+    }
 
     /* Free memory for number-of-points-in-stroke array */
     ExFreePoolWithTag(pNumPointsInStroke, TAG_PATH);
@@ -1638,6 +1644,7 @@ PATH_StrokePath(
                         if (!Realloc)
                         {
                             DPRINT1("Can't allocate pool!\n");
+                            ExFreePoolWithTag(pBzrPts, TAG_BEZIER);
                             goto end;
                         }
 
@@ -1695,7 +1702,7 @@ end:
         POINT pt;
         IntGetCurrentPositionEx(dc, &pt);
         IntDPtoLP(dc, &pt, 1);
-        IntGdiMoveToEx(dc, pt.x, pt.y, NULL, FALSE);
+        IntGdiMoveToEx(dc, pt.x, pt.y, NULL);
     }
     DPRINT("Leave %s, ret=%d\n", __FUNCTION__, ret);
     return ret;
@@ -1736,6 +1743,13 @@ PATH_WidenPath(DC *dc)
     }
 
     elp = ExAllocatePoolWithTag(PagedPool, size, TAG_PATH);
+    if (elp == NULL)
+    {
+        PATH_UnlockPath(pPath);
+        EngSetLastError(ERROR_OUTOFMEMORY);
+        return FALSE;
+    }
+
     GreGetObject(pdcattr->hpen, size, elp);
 
     obj_type = GDI_HANDLE_GET_TYPE(pdcattr->hpen);
@@ -2403,6 +2417,11 @@ NtGdiBeginPath(HDC  hDC)
     /* Make sure that path is empty */
     PATH_EmptyPath(pPath);
 
+    pPath->numEntriesAllocated = NUM_ENTRIES_INITIAL;
+
+    pPath->pPoints = (POINT *)ExAllocatePoolWithTag(PagedPool, NUM_ENTRIES_INITIAL * sizeof(POINT), TAG_PATH);
+    pPath->pFlags  =  (BYTE *)ExAllocatePoolWithTag(PagedPool, NUM_ENTRIES_INITIAL * sizeof(BYTE),  TAG_PATH);
+
     /* Initialize variables for new path */
     pPath->newStroke = TRUE;
     pPath->state = PATH_Open;
@@ -2690,6 +2709,7 @@ NtGdiPathToRegion(HDC  hDC)
     pDc = DC_LockDc(hDC);
     if (!pDc)
     {
+        DPRINT1("Failed to lock DC %p\n", hDC);
         EngSetLastError(ERROR_INVALID_PARAMETER);
         return NULL;
     }
@@ -2699,6 +2719,7 @@ NtGdiPathToRegion(HDC  hDC)
     pPath = PATH_LockPath(pDc->dclevel.hPath);
     if (!pPath)
     {
+        DPRINT1("Failed to lock DC path %p\n", pDc->dclevel.hPath);
         DC_UnlockDc(pDc);
         return NULL;
     }
@@ -2706,6 +2727,7 @@ NtGdiPathToRegion(HDC  hDC)
     if (pPath->state != PATH_Closed)
     {
         // FIXME: Check that setlasterror is being called correctly
+        DPRINT1("Path is not closed!\n");
         EngSetLastError(ERROR_CAN_NOT_COMPLETE);
     }
     else
@@ -2714,21 +2736,24 @@ NtGdiPathToRegion(HDC  hDC)
         Rgn = REGION_AllocUserRgnWithHandle(1);
         if (!Rgn)
         {
+            DPRINT1("Failed to allocate a region\n");
             PATH_UnlockPath(pPath);
             DC_UnlockDc(pDc);
+            return NULL;
         }
         hrgnRval = Rgn->BaseObject.hHmgr;
         /* FIXME: Should we empty the path even if conversion failed? */
         if (PATH_PathToRegion(pPath, pdcattr->jFillMode, Rgn))
         {
             PATH_EmptyPath(pPath);
+            REGION_UnlockRgn(Rgn);
         }
         else
         {
-            GreDeleteObject(hrgnRval);
+            DPRINT1("PATH_PathToRegion failed\n");
+            REGION_Delete(Rgn);
             hrgnRval = NULL;
         }
-        RGNOBJAPI_Unlock(Rgn);
     }
 
     PATH_UnlockPath(pPath);