[WIN32K]
authorJérôme Gardou <jerome.gardou@reactos.org>
Mon, 2 Aug 2010 00:53:25 +0000 (00:53 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Mon, 2 Aug 2010 00:53:25 +0000 (00:53 +0000)
  - DDB are 16 bits aligned.
  - Reset hdc field of the unselected bitmap.
  - Lock it too, so it's not messed with when we unselect it.
  - Move Pattern creation of IntGdiCreateDIBBrush to DIB_CreateDIBSection.

svn path=/branches/reactos-yarotows/; revision=48406

subsystems/win32/win32k/eng/surface.c
subsystems/win32/win32k/include/bitmaps.h
subsystems/win32/win32k/objects/bitmaps.c
subsystems/win32/win32k/objects/brush.c
subsystems/win32/win32k/objects/dcobjs.c
subsystems/win32/win32k/objects/dibobj.c

index ab9f0d2..3229bb2 100644 (file)
@@ -200,16 +200,21 @@ SURFACE_bSetBitmapBits(
     cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
 
     /* Is a width in bytes given? */
     cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
 
     /* Is a width in bytes given? */
-    if (ulWidth)
+    if (!ulWidth)
     {
     {
-        /* Align the width (Windows compatibility) */
-        ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 31) & ~31) >> 3;
-    }
-    else
-    {
-        /* Calculate width from the bitmap width in pixels */
-        ulWidth = ((pso->sizlBitmap.cx * cBitsPixel + 31) & ~31) >> 3;
-    }
+               /* Align the width (windows compatibility) */
+               if(psurf->flags & DDB_SURFACE)
+               {
+                       /* DDB are 16 bits aligned */
+                       ulWidth = BITMAP_GetWidthBytes(pso->sizlBitmap.cx, cBitsPixel);
+               }
+               else
+               {
+                       /* Others are 32 bits aligned */
+                       ulWidth = DIB_GetDIBWidthBytes(pso->sizlBitmap.cx, cBitsPixel);
+               }
+       }
+
 
     /* Calculate the bitmap size in bytes */
     pso->cjBits = ulWidth * pso->sizlBitmap.cy;
 
     /* Calculate the bitmap size in bytes */
     pso->cjBits = ulWidth * pso->sizlBitmap.cy;
index 239ee47..8ebcf94 100644 (file)
@@ -32,7 +32,8 @@ GreCreateBitmapEx(
     IN ULONG iFormat,
     IN USHORT fjBitmap,
     IN ULONG cjBits,
     IN ULONG iFormat,
     IN USHORT fjBitmap,
     IN ULONG cjBits,
-    IN OPTIONAL PVOID pvBits);
+    IN OPTIONAL PVOID pvBits,
+       IN FLONG flags);
 
 HBITMAP
 FASTCALL
 
 HBITMAP
 FASTCALL
index 1701e77..f5036a9 100644 (file)
@@ -76,14 +76,14 @@ GreCreateBitmapEx(
     IN ULONG iFormat,
     IN USHORT fjBitmap,
     IN ULONG cjSizeImage,
     IN ULONG iFormat,
     IN USHORT fjBitmap,
     IN ULONG cjSizeImage,
-    IN OPTIONAL PVOID pvBits)
+    IN OPTIONAL PVOID pvBits,
+       IN FLONG flags)
 {
     PSURFACE psurf;
     SURFOBJ *pso;
     HBITMAP hbmp;
     PVOID pvCompressedBits;
     SIZEL sizl;
 {
     PSURFACE psurf;
     SURFOBJ *pso;
     HBITMAP hbmp;
     PVOID pvCompressedBits;
     SIZEL sizl;
-    FLONG fl = 0;
 
     /* Verify format */
     if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
 
     /* Verify format */
     if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
@@ -107,7 +107,7 @@ GreCreateBitmapEx(
         pvCompressedBits = pvBits;
         pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
         Decompress4bpp(sizl, pvCompressedBits, pvBits, pso->lDelta);
         pvCompressedBits = pvBits;
         pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
         Decompress4bpp(sizl, pvCompressedBits, pvBits, pso->lDelta);
-        fl |= BMF_RLE_HACK;
+        fjBitmap |= BMF_RLE_HACK;
     }
     else if (iFormat == BMF_8RLE)
     {
     }
     else if (iFormat == BMF_8RLE)
     {
@@ -115,9 +115,12 @@ GreCreateBitmapEx(
         pvCompressedBits = pvBits;
         pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
         Decompress8bpp(sizl, pvCompressedBits, pvBits, pso->lDelta);
         pvCompressedBits = pvBits;
         pvBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
         Decompress8bpp(sizl, pvCompressedBits, pvBits, pso->lDelta);
-        fl |= BMF_RLE_HACK;
+        fjBitmap |= BMF_RLE_HACK;
     }
 
     }
 
+       /* Mark as API bitmap */
+       psurf->flags |= (flags | API_BITMAP);
+
     /* Set the bitmap bits */
     if (!SURFACE_bSetBitmapBits(psurf, fjBitmap, cjWidthBytes, pvBits))
     {
     /* Set the bitmap bits */
     if (!SURFACE_bSetBitmapBits(psurf, fjBitmap, cjWidthBytes, pvBits))
     {
@@ -127,14 +130,14 @@ GreCreateBitmapEx(
         return NULL;
     }
 
         return NULL;
     }
 
-    /* Mark as API bitmap */
-    psurf->flags |= API_BITMAP;
-
     /* Unlock the surface and return */
     SURFACE_UnlockSurface(psurf);
     return hbmp;
 }
 
     /* Unlock the surface and return */
     SURFACE_UnlockSurface(psurf);
     return hbmp;
 }
 
+/* Creates a DDB surface,
+ * as in CreateCompatibleBitmap or CreateBitmap.
+ */
 HBITMAP
 APIENTRY
 GreCreateBitmap(
 HBITMAP
 APIENTRY
 GreCreateBitmap(
@@ -151,7 +154,8 @@ GreCreateBitmap(
                              BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
                              0, /* no bitmap flags */
                              0, /* auto size */
                              BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
                              0, /* no bitmap flags */
                              0, /* auto size */
-                             pvBits);
+                             pvBits,
+                                                        DDB_SURFACE /* DDB */);
 }
 
 HBITMAP
 }
 
 HBITMAP
@@ -163,10 +167,7 @@ NtGdiCreateBitmap(
     IN UINT cBitsPixel,
     IN OPTIONAL LPBYTE pUnsafeBits)
 {
     IN UINT cBitsPixel,
     IN OPTIONAL LPBYTE pUnsafeBits)
 {
-    PSURFACE psurf;
-    SURFOBJ *pso;
     HBITMAP hbmp;
     HBITMAP hbmp;
-    FLONG fl = 0;
     ULONG cjWidthBytes, iFormat;
 
     /* NOTE: Windows also doesn't store nr. of planes separately! */
     ULONG cjWidthBytes, iFormat;
 
     /* NOTE: Windows also doesn't store nr. of planes separately! */
@@ -185,7 +186,7 @@ NtGdiCreateBitmap(
     }
 
     /* Make sure that cjBits will not overflow */
     }
 
     /* Make sure that cjBits will not overflow */
-    cjWidthBytes = DIB_GetDIBWidthBytes(nWidth, cBitsPixel);
+    cjWidthBytes = BITMAP_GetWidthBytes(nWidth, cBitsPixel);
     if ((ULONGLONG)cjWidthBytes * nHeight >= 0x100000000ULL)
     {
         DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
     if ((ULONGLONG)cjWidthBytes * nHeight >= 0x100000000ULL)
     {
         DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
@@ -194,30 +195,12 @@ NtGdiCreateBitmap(
         return NULL;
     }
 
         return NULL;
     }
 
-    /* Allocate a surface */
-    psurf = SURFACE_AllocSurface(STYPE_BITMAP, nWidth, nHeight, iFormat);
-    if (!psurf)
-    {
-        DPRINT1("SURFACE_AllocSurface failed.\n");
-        EngSetLastError(ERROR_OUTOFMEMORY);
-        return NULL;
-    }
-
-    /* Get the handle for the bitmap and the surfobj */
-    hbmp = (HBITMAP)psurf->SurfObj.hsurf;
-    pso = &psurf->SurfObj;
+       /* cBitsPixel = cBitsPixel * cPlanes now! */
+       hbmp = GreCreateBitmap(nWidth, nHeight, 1, cBitsPixel, NULL);
 
 
-    /* Allocate the bitmap bits */
-    if (!SURFACE_bSetBitmapBits(psurf, fl, 0, NULL))
-    {
-        /* Bail out if that failed */
-        DPRINT1("SURFACE_bSetBitmapBits failed.\n");
-        SURFACE_FreeSurfaceByHandle(hbmp);
-        return NULL;
-    }
-    
     if (pUnsafeBits)
     {
     if (pUnsafeBits)
     {
+               PSURFACE psurf = SURFACE_LockSurface(hbmp);
         _SEH2_TRY
         {
             ProbeForRead(pUnsafeBits, cjWidthBytes * nHeight, 1);
         _SEH2_TRY
         {
             ProbeForRead(pUnsafeBits, cjWidthBytes * nHeight, 1);
@@ -225,17 +208,15 @@ NtGdiCreateBitmap(
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
         }
         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
         {
+                       SURFACE_UnlockSurface(psurf);
             SURFACE_FreeSurfaceByHandle(hbmp);
             _SEH2_YIELD(return NULL;)
         }
         _SEH2_END
             SURFACE_FreeSurfaceByHandle(hbmp);
             _SEH2_YIELD(return NULL;)
         }
         _SEH2_END
-    }
 
 
-    /* Mark as API bitmap */
-    psurf->flags |= API_BITMAP;
+               SURFACE_UnlockSurface(psurf);
+    }
 
 
-    /* Unlock the surface and return */
-    SURFACE_UnlockSurface(psurf);
     return hbmp;
 }
 
     return hbmp;
 }
 
@@ -931,7 +912,8 @@ BITMAP_CopyBitmap(HBITMAP hBitmap)
                                                        Bitmap->SurfObj.iBitmapFormat,
                                                        Bitmap->SurfObj.fjBitmap,
                                                        Bitmap->SurfObj.cjBits,
                                                        Bitmap->SurfObj.iBitmapFormat,
                                                        Bitmap->SurfObj.fjBitmap,
                                                        Bitmap->SurfObj.cjBits,
-                                                       NULL);
+                                                       NULL,
+                                                       Bitmap->flags);
 
 
     if (res)
 
 
     if (res)
@@ -1052,4 +1034,5 @@ NtGdiGetDCforBitmap(
     return hdc;
 }
 
     return hdc;
 }
 
+
 /* EOF */
 /* EOF */
index 41edb11..2704538 100644 (file)
@@ -25,7 +25,7 @@ typedef struct _GDI_OBJ_ATTR_ENTRY
   RGN_ATTR Attr[GDIOBJATTRFREE];
 } GDI_OBJ_ATTR_ENTRY, *PGDI_OBJ_ATTR_ENTRY;
 
   RGN_ATTR Attr[GDIOBJATTRFREE];
 } GDI_OBJ_ATTR_ENTRY, *PGDI_OBJ_ATTR_ENTRY;
 
-static const ULONG HatchBrushes[NB_HATCH_STYLES][8] =
+static const USHORT HatchBrushes[NB_HATCH_STYLES][8] =
 {
     {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF}, /* HS_HORIZONTAL */
     {0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7}, /* HS_VERTICAL   */
 {
     {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF}, /* HS_HORIZONTAL */
     {0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7}, /* HS_VERTICAL   */
@@ -256,8 +256,7 @@ IntGdiCreateDIBBrush(
     PBRUSH pbrush;
     HBITMAP hPattern;
     ULONG_PTR DataPtr;
     PBRUSH pbrush;
     HBITMAP hPattern;
     ULONG_PTR DataPtr;
-    PSURFACE psurfPattern;
-    HPALETTE hpal ;
+    PVOID pvDIBits;
 
     if (BitmapInfo->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
     {
 
     if (BitmapInfo->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
     {
@@ -267,25 +266,17 @@ IntGdiCreateDIBBrush(
 
     DataPtr = (ULONG_PTR)BitmapInfo + DIB_BitmapInfoSize(BitmapInfo, ColorSpec);
 
 
     DataPtr = (ULONG_PTR)BitmapInfo + DIB_BitmapInfoSize(BitmapInfo, ColorSpec);
 
-    hPattern = GreCreateBitmap(BitmapInfo->bmiHeader.biWidth,
-                                  BitmapInfo->bmiHeader.biHeight,
-                                  BitmapInfo->bmiHeader.biPlanes,
-                                  BitmapInfo->bmiHeader.biBitCount,
-                                  (PVOID)DataPtr);
+    hPattern = DIB_CreateDIBSection(NULL, BitmapInfo, ColorSpec, &pvDIBits, NULL, 0, 0);
     if (hPattern == NULL)
     {
         SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
         return NULL;
     }
     if (hPattern == NULL)
     {
         SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
         return NULL;
     }
-
-    psurfPattern = SURFACE_LockSurface(hPattern);
-    ASSERT(psurfPattern != NULL);
-       if(ColorSpec == DIB_PAL_COLORS) DPRINT1("FIXME, unsupported color spec!\n");
-    hpal = BuildDIBPalette(BitmapInfo);
-    psurfPattern->ppal = PALETTE_ShareLockPalette(hpal);
-    /* Lazy delete palette, it will be freed when its shared reference is zeroed */
-    GreDeleteObject(hpal);
-    SURFACE_UnlockSurface(psurfPattern);
+       RtlCopyMemory(pvDIBits,
+                         (PVOID)DataPtr,
+                                 DIB_GetDIBImageBytes(BitmapInfo->bmiHeader.biWidth,
+                                       BitmapInfo->bmiHeader.biHeight,
+                                       BitmapInfo->bmiHeader.biBitCount * BitmapInfo->bmiHeader.biPlanes));
 
     pbrush = BRUSH_AllocBrushWithHandle();
     if (pbrush == NULL)
 
     pbrush = BRUSH_AllocBrushWithHandle();
     if (pbrush == NULL)
index c624836..cac2316 100644 (file)
@@ -284,15 +284,25 @@ NtGdiSelectBitmap(
     }
 
     /* Get the handle for the old bitmap */
     }
 
     /* Get the handle for the old bitmap */
-    psurfOld = pDC->dclevel.pSurface;
-    hOrgBmp = psurfOld ? psurfOld->BaseObject.hHmgr : NULL;
+    ASSERT(pDC->dclevel.pSurface);
+    hOrgBmp = pDC->dclevel.pSurface->BaseObject.hHmgr;
+
+       /* Lock it, to be sure while we mess with it*/
+       psurfOld = SURFACE_LockSurface(hOrgBmp);
+
+       /* Reset hdc, this surface isn't selected anymore */
+       psurfOld->hdc = NULL;
 
     /* Release the old bitmap, reference the new */
     DC_vSelectSurface(pDC, psurfBmp);
 
 
     /* Release the old bitmap, reference the new */
     DC_vSelectSurface(pDC, psurfBmp);
 
+       /* And unlock it, now we're done */
+       SURFACE_UnlockSurface(psurfOld);
+
     // If Info DC this is zero and pSurface is moved to DC->pSurfInfo.
     psurfBmp->hdc = hDC;
 
     // If Info DC this is zero and pSurface is moved to DC->pSurfInfo.
     psurfBmp->hdc = hDC;
 
+
     /* FIXME; improve by using a region without a handle and selecting it */
     hVisRgn = IntSysCreateRectRgn( 0,
                                    0,
     /* FIXME; improve by using a region without a handle and selecting it */
     hVisRgn = IntSysCreateRectRgn( 0,
                                    0,
index 010baff..f46a59c 100644 (file)
@@ -1463,10 +1463,20 @@ DIB_CreateDIBSection(
 
     if (usage == DIB_PAL_COLORS)
     {
 
     if (usage == DIB_PAL_COLORS)
     {
-               PPALETTE pdcPal ;
-        pdcPal = PALETTE_LockPalette(dc->dclevel.hpal);
-               hpal = DIB_MapPaletteColors(pdcPal, bmi);
-               PALETTE_UnlockPalette(pdcPal);
+               if(dc)
+               {
+                       PPALETTE pdcPal ;
+                       pdcPal = PALETTE_LockPalette(dc->dclevel.hpal);
+                       hpal = DIB_MapPaletteColors(pdcPal, bmi);
+                       PALETTE_UnlockPalette(pdcPal);
+               }
+               else
+               {
+                       /* For DIB Brushes */
+                       DPRINT1("FIXME : Unsupported DIB_PAL_COLORS without a DC to map colors.\n");
+                       /* HACK */
+                       hpal = (HPALETTE) 0xFFFFFFFF;
+               }
     }
     else 
        {
     }
     else 
        {
@@ -1475,7 +1485,7 @@ DIB_CreateDIBSection(
 
        if(!hpal)
        {
 
        if(!hpal)
        {
-               DPRINT1("Error : Could not create a aplette for the DIB.\n");
+               DPRINT1("Error : Could not create a palette for the DIB.\n");
                goto cleanup;
        }
 
                goto cleanup;
        }
 
@@ -1489,7 +1499,8 @@ DIB_CreateDIBSection(
                             BMF_DONTCACHE | BMF_USERMEM | BMF_NOZEROINIT |
                               (bi->biHeight < 0 ? BMF_TOPDOWN : 0),
                             bi->biSizeImage,
                             BMF_DONTCACHE | BMF_USERMEM | BMF_NOZEROINIT |
                               (bi->biHeight < 0 ? BMF_TOPDOWN : 0),
                             bi->biSizeImage,
-                            bm.bmBits);
+                            bm.bmBits,
+                                                       0);
     if (!res)
     {
         SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
     if (!res)
     {
         SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
@@ -1512,9 +1523,13 @@ DIB_CreateDIBSection(
     bmp->flags = API_BITMAP;
     bmp->biClrImportant = bi->biClrImportant;
 
     bmp->flags = API_BITMAP;
     bmp->biClrImportant = bi->biClrImportant;
 
-       bmp->ppal = PALETTE_ShareLockPalette(hpal);
-    /* Lazy delete hpal, it will be freed at surface release */
-    GreDeleteObject(hpal);
+       /* HACK */
+       if(hpal != (HPALETTE)0xFFFFFFFF)
+       {
+               bmp->ppal = PALETTE_ShareLockPalette(hpal);
+               /* Lazy delete hpal, it will be freed at surface release */
+               GreDeleteObject(hpal);
+       }
 
     // Clean up in case of errors
 cleanup:
 
     // Clean up in case of errors
 cleanup: