Transform correctly the coordinates.
[reactos.git] / reactos / subsys / win32k / objects / brush.c
index 9dee1e9..8b36b4e 100644 (file)
  *
  * $Id$
  */
+
 #include <w32k.h>
 
+#define NDEBUG
+#include <debug.h>
+
 static const USHORT HatchBrushes[NB_HATCH_STYLES][8] =
 {
   {0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00}, /* HS_HORIZONTAL */
@@ -41,7 +45,7 @@ BRUSH_Cleanup(PVOID ObjectBody)
     GDIOBJ_SetOwnership(pBrush->hbmPattern, PsGetCurrentProcess());
     NtGdiDeleteObject(pBrush->hbmPattern);
   }
-  
+
   return TRUE;
 }
 
@@ -77,7 +81,7 @@ IntGdiCreateBrushXlate(PDC Dc, GDIBRUSHOBJ *BrushObj, BOOLEAN *Failed)
          Result = IntEngCreateXlate(0, 0, Dc->w.hPalette, Pattern->hDIBPalette);
       }
 
-      BITMAPOBJ_UnlockBitmap(BrushObj->hbmPattern);
+      BITMAPOBJ_UnlockBitmap(Pattern);
       *Failed = FALSE;
    }
 
@@ -135,7 +139,7 @@ CalculateColorTableSize(
 
    /*
     * At first get some basic parameters from the passed BitmapInfoHeader
-    * structure. It can have one of the following formats: 
+    * structure. It can have one of the following formats:
     * - BITMAPCOREHEADER (the oldest one with totally different layout
     *                     from the others)
     * - BITMAPINFOHEADER (the standard and most common header)
@@ -175,7 +179,7 @@ CalculateColorTableSize(
             *ColorTableSize = 0;
          else
             *ColorTableSize = 3;
-         
+
          return TRUE;
 
       case BI_RGB:
@@ -201,7 +205,7 @@ CalculateColorTableSize(
                *ColorTableSize = ClrUsed;
                return TRUE;
          }
-         
+
       case BI_RLE4:
          if (BitCount == 4)
          {
@@ -224,7 +228,7 @@ CalculateColorTableSize(
          return TRUE;
 
       default:
-         return FALSE;      
+         return FALSE;
    }
 }
 
@@ -241,7 +245,7 @@ IntGdiCreateDIBBrush(
    ULONG_PTR DataPtr;
    UINT PaletteEntryCount;
    PBITMAPOBJ BitmapObject;
-   UINT PaletteType;
+   INT PaletteType;
 
    if (BitmapInfo->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
    {
@@ -276,7 +280,7 @@ IntGdiCreateDIBBrush(
    BitmapObject = BITMAPOBJ_LockBitmap(hPattern);
    ASSERT(BitmapObject != NULL);
    BitmapObject->hDIBPalette = BuildDIBPalette(BitmapInfo, &PaletteType);
-   BITMAPOBJ_UnlockBitmap(hPattern);
+   BITMAPOBJ_UnlockBitmap(BitmapObject);
 
    hBrush = BRUSHOBJ_AllocBrush();
    if (hBrush == NULL)
@@ -295,8 +299,8 @@ IntGdiCreateDIBBrush(
 
    GDIOBJ_SetOwnership(hPattern, NULL);
 
-   BRUSHOBJ_UnlockBrush(hBrush);
-   
+   BRUSHOBJ_UnlockBrush(BrushObject);
+
    return hBrush;
 }
 
@@ -308,13 +312,13 @@ IntGdiCreateHatchBrush(
    HBRUSH hBrush;
    PGDIBRUSHOBJ BrushObject;
    HBITMAP hPattern;
-   
+
    if (Style < 0 || Style >= NB_HATCH_STYLES)
    {
       return 0;
    }
 
-   hPattern = NtGdiCreateBitmap(8, 8, 1, 1, HatchBrushes[Style]);
+   hPattern = NtGdiCreateBitmap(8, 8, 1, 1, (LPBYTE)HatchBrushes[Style]);
    if (hPattern == NULL)
    {
       SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
@@ -338,8 +342,8 @@ IntGdiCreateHatchBrush(
 
    GDIOBJ_SetOwnership(hPattern, NULL);
 
-   BRUSHOBJ_UnlockBrush(hBrush);
-   
+   BRUSHOBJ_UnlockBrush(BrushObject);
+
    return hBrush;
 }
 
@@ -350,14 +354,14 @@ IntGdiCreatePatternBrush(
    HBRUSH hBrush;
    PGDIBRUSHOBJ BrushObject;
    HBITMAP hPattern;
-   
+
    hPattern = BITMAPOBJ_CopyBitmap(hBitmap);
    if (hPattern == NULL)
    {
       SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
       return NULL;
    }
-   
+
    hBrush = BRUSHOBJ_AllocBrush();
    if (hBrush == NULL)
    {
@@ -375,8 +379,8 @@ IntGdiCreatePatternBrush(
 
    GDIOBJ_SetOwnership(hPattern, NULL);
 
-   BRUSHOBJ_UnlockBrush(hBrush);
-   
+   BRUSHOBJ_UnlockBrush(BrushObject);
+
    return hBrush;
 }
 
@@ -386,7 +390,7 @@ IntGdiCreateSolidBrush(
 {
    HBRUSH hBrush;
    PGDIBRUSHOBJ BrushObject;
-   
+
    hBrush = BRUSHOBJ_AllocBrush();
    if (hBrush == NULL)
    {
@@ -401,8 +405,8 @@ IntGdiCreateSolidBrush(
    BrushObject->BrushAttr.lbColor = Color & 0xFFFFFF;
    /* FIXME: Fill in the rest of fields!!! */
 
-   BRUSHOBJ_UnlockBrush(hBrush);
-   
+   BRUSHOBJ_UnlockBrush(BrushObject);
+
    return hBrush;
 }
 
@@ -411,7 +415,7 @@ IntGdiCreateNullBrush(VOID)
 {
    HBRUSH hBrush;
    PGDIBRUSHOBJ BrushObject;
-   
+
    hBrush = BRUSHOBJ_AllocBrush();
    if (hBrush == NULL)
    {
@@ -422,8 +426,8 @@ IntGdiCreateNullBrush(VOID)
    BrushObject = BRUSHOBJ_LockBrush(hBrush);
    ASSERT(BrushObject != NULL);
    BrushObject->flAttrs |= GDIBRUSH_IS_NULL;
-   BRUSHOBJ_UnlockBrush(hBrush);
-   
+   BRUSHOBJ_UnlockBrush(BrushObject);
+
    return hBrush;
 }
 
@@ -475,14 +479,16 @@ IntPatBlt(
          DestRect.top = YLeft + Height + dc->w.DCOrgY + 1;
          DestRect.bottom = YLeft + dc->w.DCOrgY + 1;
       }
-      
+
+      IntLPtoDP(dc, (LPPOINT)&DestRect, 2);
+
       BrushOrigin.x = BrushObj->ptOrigin.x + dc->w.DCOrgX;
       BrushOrigin.y = BrushObj->ptOrigin.y + dc->w.DCOrgY;
 
       IntGdiInitBrushInstance(&BrushInst, BrushObj, dc->XlateBrush);
 
       ret = IntEngBitBlt(
-         BitmapObj,
+         &BitmapObj->SurfObj,
          NULL,
          NULL,
          dc->CombinedClip,
@@ -495,7 +501,7 @@ IntPatBlt(
          ROP3_TO_ROP4(ROP));
    }
 
-   BITMAPOBJ_UnlockBitmap(dc->w.hBitmap);
+   BITMAPOBJ_UnlockBitmap(BitmapObj);
 
    return ret;
 }
@@ -512,7 +518,7 @@ IntGdiPolyPatBlt(
    PPATRECT r;
    PGDIBRUSHOBJ BrushObj;
    DC *dc;
-       
+
    dc = DC_LockDc(hDC);
    if (dc == NULL)
    {
@@ -521,11 +527,11 @@ IntGdiPolyPatBlt(
    }
    if (dc->IsIC)
    {
-      DC_UnlockDc(hDC);
+      DC_UnlockDc(dc);
       /* Yes, Windows really returns TRUE in this case */
       return TRUE;
    }
-       
+
    for (r = pRects, i = 0; i < cRects; i++)
    {
       BrushObj = BRUSHOBJ_LockBrush(r->hBrush);
@@ -539,13 +545,13 @@ IntGdiPolyPatBlt(
            r->r.bottom,
            dwRop,
            BrushObj);
-        BRUSHOBJ_UnlockBrush(r->hBrush);
+        BRUSHOBJ_UnlockBrush(BrushObj);
       }
       r++;
    }
 
-   DC_UnlockDc( hDC );
-       
+   DC_UnlockDc(dc);
+
    return TRUE;
 }
 
@@ -553,13 +559,15 @@ IntGdiPolyPatBlt(
 
 HBRUSH STDCALL
 NtGdiCreateDIBBrush(
-   CONST BITMAPINFO *BitmapInfoAndData,
-   UINT ColorSpec,
-   UINT BitmapInfoSize,
-   CONST VOID *PackedDIB)
+   IN PVOID BitmapInfoAndData,
+   IN FLONG ColorSpec,
+   IN UINT BitmapInfoSize,
+   IN BOOL  b8X8,
+   IN BOOL bPen,
+   IN PVOID PackedDIB)
 {
    BITMAPINFO *SafeBitmapInfoAndData;
-   NTSTATUS Status;
+   NTSTATUS Status = STATUS_SUCCESS;
    HBRUSH hBrush;
 
    SafeBitmapInfoAndData = EngAllocMem(0, BitmapInfoSize, 0);
@@ -569,10 +577,24 @@ NtGdiCreateDIBBrush(
       return NULL;
    }
 
-   Status = MmCopyFromCaller(SafeBitmapInfoAndData, BitmapInfoAndData,
-                             BitmapInfoSize);
+   _SEH_TRY
+   {
+      ProbeForRead(BitmapInfoAndData,
+                   BitmapInfoSize,
+                   1);
+      RtlCopyMemory(SafeBitmapInfoAndData,
+                    BitmapInfoAndData,
+                    BitmapInfoSize);
+   }
+   _SEH_HANDLE
+   {
+      Status = _SEH_GetExceptionCode();
+   }
+   _SEH_END;
+   
    if (!NT_SUCCESS(Status))
    {
+      EngFreeMem(SafeBitmapInfoAndData);
       SetLastNtError(Status);
       return 0;
    }
@@ -601,7 +623,8 @@ NtGdiCreatePatternBrush(
 }
 
 HBRUSH STDCALL
-NtGdiCreateSolidBrush(COLORREF Color)
+NtGdiCreateSolidBrush(COLORREF Color,
+                      IN OPTIONAL HBRUSH hbr)
 {
    return IntGdiCreateSolidBrush(Color);
 }
@@ -610,7 +633,7 @@ NtGdiCreateSolidBrush(COLORREF Color)
  * NtGdiSetBrushOrgEx
  *
  * The NtGdiSetBrushOrgEx function sets the brush origin that GDI assigns to
- * the next brush an application selects into the specified device context. 
+ * the next brush an application selects into the specified device context.
  *
  * Status
  *    @implemented
@@ -628,14 +651,26 @@ NtGdiSetBrushOrgEx(HDC hDC, INT XOrg, INT YOrg, LPPOINT Point)
 
    if (Point != NULL)
    {
-      NTSTATUS Status;
+      NTSTATUS Status = STATUS_SUCCESS;
       POINT SafePoint;
       SafePoint.x = dc->w.brushOrgX;
       SafePoint.y = dc->w.brushOrgY;
-      Status = MmCopyToCaller(Point, &SafePoint, sizeof(POINT));
+      _SEH_TRY
+      {
+         ProbeForWrite(Point,
+                       sizeof(POINT),
+                       1);
+         *Point = SafePoint;
+      }
+      _SEH_HANDLE
+      {
+         Status = _SEH_GetExceptionCode();
+      }
+      _SEH_END;
+
       if(!NT_SUCCESS(Status))
       {
-        DC_UnlockDc(hDC);
+        DC_UnlockDc(dc);
         SetLastNtError(Status);
         return FALSE;
       }
@@ -643,7 +678,7 @@ NtGdiSetBrushOrgEx(HDC hDC, INT XOrg, INT YOrg, LPPOINT Point)
 
    dc->w.brushOrgX = XOrg;
    dc->w.brushOrgY = YOrg;
-   DC_UnlockDc(hDC);
+   DC_UnlockDc(dc);
 
    return TRUE;
 }
@@ -652,14 +687,14 @@ BOOL STDCALL
 NtGdiPolyPatBlt(
    HDC hDC,
    DWORD dwRop,
-   PPATRECT pRects,
-   INT cRects,
-   ULONG Reserved)
+   IN PPOLYPATBLT pRects,
+   IN DWORD cRects,
+   IN DWORD Mode)
 {
    PPATRECT rb = NULL;
-   NTSTATUS Status;
+   NTSTATUS Status = STATUS_SUCCESS;
    BOOL Ret;
-    
+
    if (cRects > 0)
    {
       rb = ExAllocatePoolWithTag(PagedPool, sizeof(PATRECT) * cRects, TAG_PATBLT);
@@ -668,7 +703,21 @@ NtGdiPolyPatBlt(
          SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
          return FALSE;
       }
-      Status = MmCopyFromCaller(rb, pRects, sizeof(PATRECT) * cRects);
+      _SEH_TRY
+      {
+         ProbeForRead(pRects,
+                      cRects * sizeof(PATRECT),
+                      1);
+         RtlCopyMemory(rb,
+                       pRects,
+                       cRects * sizeof(PATRECT));
+      }
+      _SEH_HANDLE
+      {
+         Status = _SEH_GetExceptionCode();
+      }
+      _SEH_END;
+
       if (!NT_SUCCESS(Status))
       {
          ExFreePool(rb);
@@ -676,9 +725,9 @@ NtGdiPolyPatBlt(
          return FALSE;
       }
    }
-    
-   Ret = IntGdiPolyPatBlt(hDC, dwRop, pRects, cRects, Reserved);
-       
+
+   Ret = IntGdiPolyPatBlt(hDC, dwRop, (PPATRECT)pRects, cRects, Mode);
+
    if (cRects > 0)
       ExFreePool(rb);
 
@@ -705,7 +754,7 @@ NtGdiPatBlt(
    }
    if (dc->IsIC)
    {
-      DC_UnlockDc(hDC);
+      DC_UnlockDc(dc);
       /* Yes, Windows really returns TRUE in this case */
       return TRUE;
    }
@@ -714,7 +763,7 @@ NtGdiPatBlt(
    if (BrushObj == NULL)
    {
       SetLastWin32Error(ERROR_INVALID_HANDLE);
-      DC_UnlockDc(hDC);
+      DC_UnlockDc(dc);
       return FALSE;
    }
 
@@ -727,8 +776,8 @@ NtGdiPatBlt(
       ROP,
       BrushObj);
 
-   BRUSHOBJ_UnlockBrush(dc->w.hBrush);
-   DC_UnlockDc(hDC);
+   BRUSHOBJ_UnlockBrush(BrushObj);
+   DC_UnlockDc(dc);
 
    return ret;
 }