Author: jgardou
Date: Mon Aug 2 00:53:25 2010
New Revision: 48406
URL:
http://svn.reactos.org/svn/reactos?rev=48406&view=rev
Log:
[WIN32K]
- 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.
Modified:
branches/reactos-yarotows/subsystems/win32/win32k/eng/surface.c
branches/reactos-yarotows/subsystems/win32/win32k/include/bitmaps.h
branches/reactos-yarotows/subsystems/win32/win32k/objects/bitmaps.c
branches/reactos-yarotows/subsystems/win32/win32k/objects/brush.c
branches/reactos-yarotows/subsystems/win32/win32k/objects/dcobjs.c
branches/reactos-yarotows/subsystems/win32/win32k/objects/dibobj.c
Modified: branches/reactos-yarotows/subsystems/win32/win32k/eng/surface.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/eng/surface.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/eng/surface.c [iso-8859-1] Mon Aug
2 00:53:25 2010
@@ -200,16 +200,21 @@
cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
/* Is a width in bytes given? */
- 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;
- }
+ if (!ulWidth)
+ {
+ /* 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;
Modified: branches/reactos-yarotows/subsystems/win32/win32k/include/bitmaps.h
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/include/bitmaps.h [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/include/bitmaps.h [iso-8859-1] Mon
Aug 2 00:53:25 2010
@@ -32,7 +32,8 @@
IN ULONG iFormat,
IN USHORT fjBitmap,
IN ULONG cjBits,
- IN OPTIONAL PVOID pvBits);
+ IN OPTIONAL PVOID pvBits,
+ IN FLONG flags);
HBITMAP
FASTCALL
Modified: branches/reactos-yarotows/subsystems/win32/win32k/objects/bitmaps.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] Mon
Aug 2 00:53:25 2010
@@ -76,14 +76,14 @@
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;
- FLONG fl = 0;
/* Verify format */
if (iFormat < BMF_1BPP || iFormat > BMF_PNG) return NULL;
@@ -107,7 +107,7 @@
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)
{
@@ -115,8 +115,11 @@
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))
@@ -127,14 +130,14 @@
return NULL;
}
- /* Mark as API bitmap */
- psurf->flags |= API_BITMAP;
-
/* Unlock the surface and return */
SURFACE_UnlockSurface(psurf);
return hbmp;
}
+/* Creates a DDB surface,
+ * as in CreateCompatibleBitmap or CreateBitmap.
+ */
HBITMAP
APIENTRY
GreCreateBitmap(
@@ -151,7 +154,8 @@
BitmapFormat(cBitsPixel * cPlanes, BI_RGB),
0, /* no bitmap flags */
0, /* auto size */
- pvBits);
+ pvBits,
+ DDB_SURFACE /* DDB */);
}
HBITMAP
@@ -163,10 +167,7 @@
IN UINT cBitsPixel,
IN OPTIONAL LPBYTE pUnsafeBits)
{
- PSURFACE psurf;
- SURFOBJ *pso;
HBITMAP hbmp;
- FLONG fl = 0;
ULONG cjWidthBytes, iFormat;
/* NOTE: Windows also doesn't store nr. of planes separately! */
@@ -185,7 +186,7 @@
}
/* 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",
@@ -194,30 +195,12 @@
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;
-
- /* 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;
- }
-
+ /* cBitsPixel = cBitsPixel * cPlanes now! */
+ hbmp = GreCreateBitmap(nWidth, nHeight, 1, cBitsPixel, NULL);
+
if (pUnsafeBits)
{
+ PSURFACE psurf = SURFACE_LockSurface(hbmp);
_SEH2_TRY
{
ProbeForRead(pUnsafeBits, cjWidthBytes * nHeight, 1);
@@ -225,17 +208,15 @@
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
+ SURFACE_UnlockSurface(psurf);
SURFACE_FreeSurfaceByHandle(hbmp);
_SEH2_YIELD(return NULL;)
}
_SEH2_END
- }
-
- /* Mark as API bitmap */
- psurf->flags |= API_BITMAP;
-
- /* Unlock the surface and return */
- SURFACE_UnlockSurface(psurf);
+
+ SURFACE_UnlockSurface(psurf);
+ }
+
return hbmp;
}
@@ -931,7 +912,8 @@
Bitmap->SurfObj.iBitmapFormat,
Bitmap->SurfObj.fjBitmap,
Bitmap->SurfObj.cjBits,
- NULL);
+ NULL,
+ Bitmap->flags);
if (res)
@@ -1052,4 +1034,5 @@
return hdc;
}
+
/* EOF */
Modified: branches/reactos-yarotows/subsystems/win32/win32k/objects/brush.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/objects/brush.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/objects/brush.c [iso-8859-1] Mon Aug
2 00:53:25 2010
@@ -25,7 +25,7 @@
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 */
@@ -256,8 +256,7 @@
PBRUSH pbrush;
HBITMAP hPattern;
ULONG_PTR DataPtr;
- PSURFACE psurfPattern;
- HPALETTE hpal ;
+ PVOID pvDIBits;
if (BitmapInfo->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
{
@@ -267,25 +266,17 @@
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;
}
-
- 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)
Modified: branches/reactos-yarotows/subsystems/win32/win32k/objects/dcobjs.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/objects/dcobjs.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/objects/dcobjs.c [iso-8859-1] Mon
Aug 2 00:53:25 2010
@@ -284,14 +284,24 @@
}
/* 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);
+ /* 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;
+
/* FIXME; improve by using a region without a handle and selecting it */
hVisRgn = IntSysCreateRectRgn( 0,
Modified: branches/reactos-yarotows/subsystems/win32/win32k/objects/dibobj.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/objects/dibobj.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/objects/dibobj.c [iso-8859-1] Mon
Aug 2 00:53:25 2010
@@ -1463,10 +1463,20 @@
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
{
@@ -1475,7 +1485,7 @@
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;
}
@@ -1489,7 +1499,8 @@
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);
@@ -1512,9 +1523,13 @@
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: