[FORMATTING]

- apply ansi style formatting with an indentation of 4 spaces
- Add 2 FIXME comments, regarding MmSecureVirtualmemory
- no code change

svn path=/trunk/; revision=40073
This commit is contained in:
Timo Kreuzer 2009-03-17 06:34:09 +00:00
parent 0f06669f19
commit cf3d6a794f

View file

@ -42,6 +42,7 @@ IntGdiCreateBitmap(
HBITMAP hBitmap;
SIZEL Size;
LONG WidthBytes;
PSURFACE psurfBmp;
/* NOTE: Windows also doesn't store nr. of planes separately! */
BitsPixel = BITMAP_GetRealBitsPixel(BitsPixel * Planes);
@ -49,7 +50,8 @@ IntGdiCreateBitmap(
/* Check parameters */
if (BitsPixel == 0 || Width <= 0 || Width >= 0x8000000 || Height == 0)
{
DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", Width, Height, BitsPixel);
DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
Width, Height, BitsPixel);
SetLastWin32Error(ERROR_INVALID_PARAMETER);
return 0;
}
@ -62,7 +64,8 @@ IntGdiCreateBitmap(
/* Make sure that cjBits will not overflow */
if ((ULONGLONG)WidthBytes * Size.cy >= 0x100000000ULL)
{
DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", Width, Height, BitsPixel);
DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
Width, Height, BitsPixel);
SetLastWin32Error(ERROR_INVALID_PARAMETER);
return 0;
}
@ -78,7 +81,7 @@ IntGdiCreateBitmap(
return 0;
}
PSURFACE psurfBmp = SURFACE_LockSurface(hBitmap);
psurfBmp = SURFACE_LockSurface(hBitmap);
if (psurfBmp == NULL)
{
NtGdiDeleteObject(hBitmap);
@ -115,6 +118,7 @@ NtGdiCreateBitmap(
BOOL Hit = FALSE;
UINT cjBits = BITMAP_GetWidthBytes(Width, BitsPixel) * abs(Height);
// FIXME: Use MmSecureVirtualMemory
_SEH2_TRY
{
ProbeForRead(pUnsafeBits, cjBits, 1);
@ -148,7 +152,7 @@ IntCreateCompatibleBitmap(
{
if (Dc->DC_Type != DC_TYPE_MEMORY)
{
Bmp = IntGdiCreateBitmap( abs(Width),
Bmp = IntGdiCreateBitmap(abs(Width),
abs(Height),
IntGdiGetDeviceCaps(Dc,PLANES),
IntGdiGetDeviceCaps(Dc,BITSPIXEL),
@ -158,14 +162,13 @@ IntCreateCompatibleBitmap(
{
DIBSECTION dibs;
INT Count;
PSURFACE psurf = SURFACE_LockSurface( Dc->w.hBitmap );
PSURFACE psurf = SURFACE_LockSurface(Dc->w.hBitmap);
Count = BITMAP_GetObject(psurf, sizeof(dibs), &dibs);
if (Count)
{
if (Count == sizeof(BITMAP))
{
/* We have a bitmap bug!!! W/O the HACK, we have white icons.
MSDN Note: When a memory device context is created, it initially
@ -175,18 +178,17 @@ IntCreateCompatibleBitmap(
the hDC that was used to create the memory device context, as
shown in the following code:
HDC memDC = CreateCompatibleDC ( hDC );
HBITMAP memBM = CreateCompatibleBitmap ( hDC, nWidth, nHeight );
SelectObject ( memDC, memBM );
HDC memDC = CreateCompatibleDC(hDC);
HBITMAP memBM = CreateCompatibleBitmap(hDC, nWidth, nHeight);
SelectObject(memDC, memBM);
*/
Bmp = IntGdiCreateBitmap( abs(Width),
Bmp = IntGdiCreateBitmap(abs(Width),
abs(Height),
dibs.dsBm.bmPlanes,
IntGdiGetDeviceCaps(Dc,BITSPIXEL),//<-- HACK! dibs.dsBm.bmBitsPixel, // <-- Correct!
NULL);
}
else
{
/* A DIB section is selected in the DC */
BITMAPINFO *bi;
@ -196,7 +198,10 @@ IntCreateCompatibleBitmap(
color table. The maximum number of colors in a color table
is 256 which corresponds to a bitmap with depth 8.
Bitmaps with higher depths don't have color tables. */
bi = ExAllocatePoolWithTag(PagedPool, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD), TAG_TEMP);
bi = ExAllocatePoolWithTag(PagedPool,
sizeof(BITMAPINFOHEADER) +
256 * sizeof(RGBQUAD),
TAG_TEMP);
if (bi)
{
@ -226,7 +231,7 @@ IntCreateCompatibleBitmap(
if (!PalGDI)
{
ExFreePoolWithTag(bi, TAG_TEMP);
SURFACE_UnlockSurface( psurf );
SURFACE_UnlockSurface(psurf);
SetLastWin32Error(ERROR_INVALID_HANDLE);
return 0;
}
@ -244,7 +249,7 @@ IntCreateCompatibleBitmap(
}
SURFACE_UnlockSurface(psurf);
Bmp = DIB_CreateDIBSection ( Dc,
Bmp = DIB_CreateDIBSection(Dc,
bi,
DIB_RGB_COLORS,
&Bits,
@ -272,7 +277,7 @@ NtGdiCreateCompatibleBitmap(
HBITMAP Bmp;
PDC Dc;
if ( Width <= 0 || Height <= 0 || (Width * Height) > 0x3FFFFFFF )
if (Width <= 0 || Height <= 0 || (Width * Height) > 0x3FFFFFFF)
{
SetLastWin32Error(ERROR_INVALID_PARAMETER);
return NULL;
@ -283,7 +288,8 @@ NtGdiCreateCompatibleBitmap(
Dc = DC_LockDc(hDC);
DPRINT("NtGdiCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC, Width, Height, ((PGDIDEVICE)Dc->pPDev)->GDIInfo.cBitsPixel);
DPRINT("NtGdiCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n",
hDC, Width, Height, ((PGDIDEVICE)Dc->pPDev)->GDIInfo.cBitsPixel);
if (NULL == Dc)
{
@ -293,7 +299,7 @@ NtGdiCreateCompatibleBitmap(
Bmp = IntCreateCompatibleBitmap(Dc, Width, Height);
DPRINT ("\t\t%04x\n", Bmp);
DPRINT("\t\t%04x\n", Bmp);
DC_UnlockDc(Dc);
return Bmp;
}
@ -344,40 +350,42 @@ NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
XLATEOBJ *XlateObj;
HBITMAP hBmpTmp;
dc = DC_LockDc (hDC);
dc = DC_LockDc(hDC);
if ( !dc )
if (!dc)
{
SetLastWin32Error(ERROR_INVALID_HANDLE);
return Result;
}
if (dc->DC_Type == DC_TYPE_INFO)
{
DC_UnlockDc(dc);
return Result;
}
XPos += dc->ptlDCOrig.x;
YPos += dc->ptlDCOrig.y;
if ( IN_RECT(dc->CombinedClip->rclBounds,XPos,YPos) )
if (IN_RECT(dc->CombinedClip->rclBounds,XPos,YPos))
{
bInRect = TRUE;
psurf = SURFACE_LockSurface(dc->w.hBitmap);
pso = &psurf->SurfObj;
if ( psurf )
if (psurf)
{
Pal = psurf->hDIBPalette;
if (!Pal) Pal = pPrimarySurface->DevInfo.hpalDefault;
/* FIXME: Verify if it shouldn't be PAL_BGR! */
XlateObj = (XLATEOBJ*)IntEngCreateXlate ( PAL_RGB, 0, NULL, Pal );
if ( XlateObj )
XlateObj = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, 0, NULL, Pal);
if (XlateObj)
{
// check if this DC has a DIB behind it...
if ( pso->pvScan0 ) // STYPE_BITMAP == pso->iType
if (pso->pvScan0) // STYPE_BITMAP == pso->iType
{
ASSERT ( pso->lDelta );
ASSERT(pso->lDelta);
Result = XLATEOBJ_iXlate(XlateObj,
DibFunctionsForBitmapFormat[pso->iBitmapFormat].DIB_GetPixel ( pso, XPos, YPos ) );
DibFunctionsForBitmapFormat[pso->iBitmapFormat].DIB_GetPixel(pso, XPos, YPos));
}
EngDeleteXlate(XlateObj);
}
@ -387,15 +395,15 @@ NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
DC_UnlockDc(dc);
// if Result is still CLR_INVALID, then the "quick" method above didn't work
if ( bInRect && Result == CLR_INVALID )
if (bInRect && Result == CLR_INVALID)
{
// FIXME: create a 1x1 32BPP DIB, and blit to it
HDC hDCTmp = NtGdiCreateCompatibleDC(hDC);
if ( hDCTmp )
if (hDCTmp)
{
static const BITMAPINFOHEADER bih = { sizeof(BITMAPINFOHEADER), 1, 1, 1, 32, BI_RGB, 0, 0, 0, 0, 0 };
BITMAPINFO bi;
RtlMoveMemory ( &(bi.bmiHeader), &bih, sizeof(bih) );
RtlMoveMemory(&(bi.bmiHeader), &bih, sizeof(bih));
hBmpTmp = NtGdiCreateDIBitmapInternal(hDC,
bi.bmiHeader.biWidth,
bi.bmiHeader.biHeight,
@ -408,29 +416,29 @@ NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
0,
0);
//HBITMAP hBmpTmp = IntGdiCreateBitmap ( 1, 1, 1, 32, NULL);
if ( hBmpTmp )
//HBITMAP hBmpTmp = IntGdiCreateBitmap(1, 1, 1, 32, NULL);
if (hBmpTmp)
{
HBITMAP hBmpOld = (HBITMAP)NtGdiSelectBitmap ( hDCTmp, hBmpTmp );
if ( hBmpOld )
HBITMAP hBmpOld = (HBITMAP)NtGdiSelectBitmap(hDCTmp, hBmpTmp);
if (hBmpOld)
{
PSURFACE psurf;
NtGdiBitBlt ( hDCTmp, 0, 0, 1, 1, hDC, XPos, YPos, SRCCOPY, 0, 0 );
NtGdiSelectBitmap ( hDCTmp, hBmpOld );
NtGdiBitBlt(hDCTmp, 0, 0, 1, 1, hDC, XPos, YPos, SRCCOPY, 0, 0);
NtGdiSelectBitmap(hDCTmp, hBmpOld);
// our bitmap is no longer selected, so we can access it's stuff...
psurf = SURFACE_LockSurface(hBmpTmp);
if ( psurf )
if (psurf)
{
// Dont you need to convert something here?
Result = *(COLORREF*)psurf->SurfObj.pvScan0;
SURFACE_UnlockSurface(psurf);
}
}
NtGdiDeleteObject ( hBmpTmp );
NtGdiDeleteObject(hBmpTmp);
}
NtGdiDeleteObjectApp ( hDCTmp );
NtGdiDeleteObjectApp(hDCTmp);
}
}
@ -453,12 +461,15 @@ IntGetBitmapBits(
#if 0
/* FIXME: Call DDI CopyBits here if available */
if(psurf->DDBitmap)
if (psurf->DDBitmap)
{
DPRINT("Calling device specific BitmapBits\n");
if(psurf->DDBitmap->funcs->pBitmapBits)
if (psurf->DDBitmap->funcs->pBitmapBits)
{
ret = psurf->DDBitmap->funcs->pBitmapBits(hbitmap, bits, count, DDB_GET);
ret = psurf->DDBitmap->funcs->pBitmapBits(hbitmap,
bits,
count,
DDB_GET);
}
else
{
@ -476,7 +487,8 @@ IntGetBitmapBits(
}
LONG APIENTRY
NtGdiGetBitmapBits(HBITMAP hBitmap,
NtGdiGetBitmapBits(
HBITMAP hBitmap,
ULONG Bytes,
OUT OPTIONAL PBYTE pUnsafeBits)
{
@ -506,6 +518,7 @@ NtGdiGetBitmapBits(HBITMAP hBitmap,
/* Don't copy more bytes than the buffer has */
Bytes = min(Bytes, psurf->SurfObj.cjBits);
// FIXME: use MmSecureVirtualMemory
_SEH2_TRY
{
ProbeForWrite(pUnsafeBits, Bytes, 1);
@ -536,16 +549,19 @@ IntSetBitmapBits(
#if 0
/* FIXME: call DDI specific function here if available */
if(psurf->DDBitmap)
if (psurf->DDBitmap)
{
DPRINT ("Calling device specific BitmapBits\n");
DPRINT("Calling device specific BitmapBits\n");
if (psurf->DDBitmap->funcs->pBitmapBits)
{
ret = psurf->DDBitmap->funcs->pBitmapBits(hBitmap, (void *) Bits, Bytes, DDB_SET);
ret = psurf->DDBitmap->funcs->pBitmapBits(hBitmap,
(void *)Bits,
Bytes,
DDB_SET);
}
else
{
DPRINT ("BitmapBits == NULL??\n");
DPRINT("BitmapBits == NULL??\n");
ret = 0;
}
}
@ -652,15 +668,18 @@ GdiSetPixelV(
if (NewBrush == NULL)
return(FALSE);
OldBrush = NtGdiSelectBrush(hDC, NewBrush);
if (OldBrush == NULL)
{
NtGdiDeleteObject(NewBrush);
return(FALSE);
}
NtGdiPatBlt(hDC, X, Y, 1, 1, PATCOPY);
NtGdiSelectBrush(hDC, OldBrush);
NtGdiDeleteObject(NewBrush);
return TRUE;
}
@ -671,17 +690,17 @@ NtGdiSetPixel(
INT Y,
COLORREF Color)
{
DPRINT("0 NtGdiSetPixel X %ld Y %ld C %ld\n",X,Y,Color);
DPRINT("0 NtGdiSetPixel X %ld Y %ld C %ld\n", X, Y, Color);
if (GdiSetPixelV(hDC,X,Y,Color))
{
Color = NtGdiGetPixel(hDC,X,Y);
DPRINT("1 NtGdiSetPixel X %ld Y %ld C %ld\n",X,Y,Color);
DPRINT("1 NtGdiSetPixel X %ld Y %ld C %ld\n", X, Y, Color);
return Color;
}
Color = ((COLORREF) CLR_INVALID);
DPRINT("2 NtGdiSetPixel X %ld Y %ld C %ld\n",X,Y,Color);
Color = (COLORREF)CLR_INVALID;
DPRINT("2 NtGdiSetPixel X %ld Y %ld C %ld\n", X, Y, Color);
return Color;
}
@ -708,10 +727,10 @@ BITMAP_GetRealBitsPixel(UINT nBitsPixel)
}
INT FASTCALL
BITMAP_GetWidthBytes (INT bmWidth, INT bpp)
BITMAP_GetWidthBytes(INT bmWidth, INT bpp)
{
#if 0
switch(bpp)
switch (bpp)
{
case 1:
return 2 * ((bmWidth+15) >> 4);
@ -773,14 +792,16 @@ BITMAP_CopyBitmap(HBITMAP hBitmap)
(bm.bmHeight < 0 ? BMF_TOPDOWN : 0) | BMF_NOZEROINIT,
NULL);
if(res)
if (res)
{
PBYTE buf;
resBitmap = GDIOBJ_LockObj(res, GDI_OBJECT_TYPE_BITMAP);
if (resBitmap)
{
buf = ExAllocatePoolWithTag (PagedPool, bm.bmWidthBytes * abs(bm.bmHeight), TAG_BITMAP);
buf = ExAllocatePoolWithTag(PagedPool,
bm.bmWidthBytes * abs(bm.bmHeight),
TAG_BITMAP);
if (buf == NULL)
{
GDIOBJ_UnlockObjByPtr((POBJ)resBitmap);
@ -788,9 +809,9 @@ BITMAP_CopyBitmap(HBITMAP hBitmap)
NtGdiDeleteObject(res);
return 0;
}
IntGetBitmapBits (Bitmap, bm.bmWidthBytes * abs(bm.bmHeight), buf);
IntSetBitmapBits (resBitmap, bm.bmWidthBytes * abs(bm.bmHeight), buf);
ExFreePoolWithTag (buf,TAG_BITMAP);
IntGetBitmapBits(Bitmap, bm.bmWidthBytes * abs(bm.bmHeight), buf);
IntSetBitmapBits(resBitmap, bm.bmWidthBytes * abs(bm.bmHeight), buf);
ExFreePoolWithTag(buf,TAG_BITMAP);
resBitmap->flFlags = Bitmap->flFlags;
GDIOBJ_UnlockObjByPtr((POBJ)resBitmap);
}
@ -824,7 +845,7 @@ BITMAP_GetObject(SURFACE *psurf, INT Count, LPVOID buffer)
pBitmap->bmBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
/* Check for DIB section */
if(psurf->hSecure)
if (psurf->hSecure)
{
/* Set bmBits in this case */
pBitmap->bmBits = psurf->SurfObj.pvBits;
@ -856,7 +877,8 @@ BITMAP_GetObject(SURFACE *psurf, INT Count, LPVOID buffer)
}
else
{
pBitmap->bmBits = NULL; /* not set according to wine test, confirmed in win2k */
/* not set according to wine test, confirmed in win2k */
pBitmap->bmBits = NULL;
}
return sizeof(BITMAP);
@ -906,7 +928,7 @@ NtGdiSelectBitmap(
}
pDc_Attr = pDC->pDc_Attr;
if(!pDc_Attr) pDc_Attr = &pDC->Dc_Attr;
if (!pDc_Attr) pDc_Attr = &pDC->Dc_Attr;
/* must be memory dc to select bitmap */
if (pDC->DC_Type != DC_TYPE_MEMORY)
@ -930,8 +952,9 @@ NtGdiSelectBitmap(
pDC->DcLevel.pSurface = psurfBmp;
psurfBmp->hDC = hDC;
// if we're working with a DIB, get the palette [fixme: only create if the selected palette is null]
if(psurfBmp->hSecure)
// if we're working with a DIB, get the palette
// [fixme: only create if the selected palette is null]
if (psurfBmp->hSecure)
{
// pDC->w.bitsPerPixel = psurfBmp->dib->dsBmih.biBitCount; ???
pDC->w.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
@ -941,7 +964,10 @@ NtGdiSelectBitmap(
pDC->w.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat);
}
hVisRgn = NtGdiCreateRectRgn(0, 0, psurfBmp->SurfObj.sizlBitmap.cx, psurfBmp->SurfObj.sizlBitmap.cy);
hVisRgn = NtGdiCreateRectRgn(0,
0,
psurfBmp->SurfObj.sizlBitmap.cx,
psurfBmp->SurfObj.sizlBitmap.cy);
SURFACE_UnlockSurface(psurfBmp);
/* Regenerate the XLATEOBJs. */