Author: tkreuzer Date: Thu Jan 12 14:42:59 2012 New Revision: 54922
URL: http://svn.reactos.org/svn/reactos?rev=54922&view=rev Log: [WIN32K] - Simplify BITMAP_CopyBitmap, by using the SURFOBJ members directly instead of calling BITMAP_GetObject. - Use RtlCopyMemory directly in BITMAP_CopyBitmap and remove IntSetBitmapBits - Improve prototype of GreCreateBitmap(Ex) by using ULONG instead of INT for the bitmap dimensions (negative values are invalid) - remove a duplicated type definition
Modified: trunk/reactos/subsystems/win32/win32k/include/bitmaps.h trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c
Modified: trunk/reactos/subsystems/win32/win32k/include/bitmaps.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/inc... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/include/bitmaps.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/include/bitmaps.h [iso-8859-1] Thu Jan 12 14:42:59 2012 @@ -4,25 +4,25 @@ HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP hBitmap);
HBITMAP -APIENTRY +NTAPI GreCreateBitmap( - IN INT nWidth, - IN INT nHeight, - IN UINT cPlanes, - IN UINT cBitsPixel, - IN OPTIONAL PVOID pvBits); + _In_ ULONG nWidth, + _In_ ULONG nHeight, + _In_ ULONG cPlanes, + _In_ ULONG cBitsPixel, + _In_opt_ PVOID pvBits);
HBITMAP -APIENTRY +NTAPI GreCreateBitmapEx( - IN INT nWidth, - IN INT nHeight, - IN ULONG cjWidthBytes, - IN ULONG iFormat, - IN USHORT fjBitmap, - IN ULONG cjBits, - IN OPTIONAL PVOID pvBits, - IN FLONG flags); + _In_ ULONG nWidth, + _In_ ULONG nHeight, + _In_ ULONG cjWidthBytes, + _In_ ULONG iFormat, + _In_ USHORT fjBitmap, + _In_ ULONG cjSizeImage, + _In_opt_ PVOID pvBits, + _In_ FLONG flags);
HBITMAP FASTCALL
Modified: trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/obj... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] Thu Jan 12 14:42:59 2012 @@ -3,27 +3,13 @@ * PROJECT: ReactOS kernel * PURPOSE: Bitmap functions * FILE: subsys/win32k/objects/bitmaps.c - * PROGRAMER: Unknown + * PROGRAMER: Timo Kreuzer timo.kreuzer@reactos.org */
#include <win32k.h>
#define NDEBUG #include <debug.h> - -LONG APIENTRY -IntSetBitmapBits( - PSURFACE psurf, - DWORD Bytes, - IN PBYTE Bits) -{ - /* Don't copy more bytes than the buffer has */ - Bytes = min(Bytes, psurf->SurfObj.cjBits); - - RtlCopyMemory(psurf->SurfObj.pvBits, Bits, Bytes); - - return Bytes; -}
void NTAPI @@ -57,16 +43,16 @@ }
HBITMAP -APIENTRY +NTAPI GreCreateBitmapEx( - IN INT nWidth, - IN INT nHeight, - IN ULONG cjWidthBytes, - IN ULONG iFormat, - IN USHORT fjBitmap, - IN ULONG cjSizeImage, - IN OPTIONAL PVOID pvBits, - IN FLONG flags) + _In_ ULONG nWidth, + _In_ ULONG nHeight, + _In_ ULONG cjWidthBytes, + _In_ ULONG iFormat, + _In_ USHORT fjBitmap, + _In_ ULONG cjSizeImage, + _In_opt_ PVOID pvBits, + _In_ FLONG flags) { PSURFACE psurf; HBITMAP hbmp; @@ -134,13 +120,13 @@ * Note that each scanline must be 32bit aligned! */ HBITMAP -APIENTRY +NTAPI GreCreateBitmap( - IN INT nWidth, - IN INT nHeight, - IN UINT cPlanes, - IN UINT cBitsPixel, - IN OPTIONAL PVOID pvBits) + _In_ ULONG nWidth, + _In_ ULONG nHeight, + _In_ ULONG cPlanes, + _In_ ULONG cBitsPixel, + _In_opt_ PVOID pvBits) { /* Call the extended function */ return GreCreateBitmapEx(nWidth, @@ -433,7 +419,7 @@ psurf = dc->dclevel.pSurface; if (psurf) { - pso = &psurf->SurfObj; + pso = &psurf->SurfObj; EXLATEOBJ_vInitialize(&exlo, psurf->ppal, &gpalRGB, 0, 0xffffff, 0); // Check if this DC has a DIB behind it... if (pso->pvScan0) // STYPE_BITMAP == pso->iType @@ -476,8 +462,6 @@ 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);
@@ -503,10 +487,10 @@ FASTCALL UnsafeGetBitmapBits( PSURFACE psurf, - DWORD Bytes, - OUT PBYTE pvBits) -{ - PUCHAR pjDst, pjSrc; + DWORD Bytes, + OUT PBYTE pvBits) +{ + PUCHAR pjDst, pjSrc; LONG lDeltaDst, lDeltaSrc; ULONG nWidth, nHeight, cBitsPixel;
@@ -529,20 +513,24 @@ } }
-LONG APIENTRY +LONG +APIENTRY NtGdiGetBitmapBits( HBITMAP hBitmap, - ULONG Bytes, + ULONG cjBuffer, OUT OPTIONAL PBYTE pUnsafeBits) { PSURFACE psurf; - LONG bmSize, ret; - - if (pUnsafeBits != NULL && Bytes == 0) + ULONG cjSize; + LONG ret; + + /* Check parameters */ + if (pUnsafeBits != NULL && cjBuffer == 0) { return 0; }
+ /* Lock the bitmap */ psurf = SURFACE_ShareLockSurface(hBitmap); if (!psurf) { @@ -550,26 +538,27 @@ return 0; }
- bmSize = WIDTH_BYTES_ALIGN16(psurf->SurfObj.sizlBitmap.cx, - BitsPerFormat(psurf->SurfObj.iBitmapFormat)) * - abs(psurf->SurfObj.sizlBitmap.cy); + /* Calculate the size of the bitmap in bytes */ + cjSize = WIDTH_BYTES_ALIGN16(psurf->SurfObj.sizlBitmap.cx, + BitsPerFormat(psurf->SurfObj.iBitmapFormat)) * + abs(psurf->SurfObj.sizlBitmap.cy);
/* If the bits vector is null, the function should return the read size */ if (pUnsafeBits == NULL) { SURFACE_ShareUnlockSurface(psurf); - return bmSize; + return cjSize; }
/* Don't copy more bytes than the buffer has */ - Bytes = min(Bytes, bmSize); + cjBuffer = min(cjBuffer, cjSize);
// FIXME: Use MmSecureVirtualMemory _SEH2_TRY { - ProbeForWrite(pUnsafeBits, Bytes, 1); - UnsafeGetBitmapBits(psurf, Bytes, pUnsafeBits); - ret = Bytes; + ProbeForWrite(pUnsafeBits, cjBuffer, 1); + UnsafeGetBitmapBits(psurf, cjBuffer, pUnsafeBits); + ret = cjBuffer; } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -776,63 +765,65 @@
/* Internal Functions */
-HBITMAP FASTCALL +HBITMAP +FASTCALL BITMAP_CopyBitmap(HBITMAP hBitmap) { - HBITMAP res; - BITMAP bm; - SURFACE *Bitmap, *resBitmap; - SIZEL Size; - - if (hBitmap == NULL) + HBITMAP hbmNew; + SURFACE *psurfSrc, *psurfNew; + + /* Fail, if no source bitmap is given */ + if (hBitmap == NULL) return 0; + + /* Lock the source bitmap */ + psurfSrc = SURFACE_ShareLockSurface(hBitmap); + if (psurfSrc == NULL) { return 0; }
- Bitmap = SURFACE_ShareLockSurface(hBitmap); - if (Bitmap == NULL) - { - return 0; - } - - BITMAP_GetObject(Bitmap, sizeof(BITMAP), (PVOID)&bm); - bm.bmBits = NULL; - if (Bitmap->SurfObj.lDelta >= 0) - bm.bmHeight = -bm.bmHeight; - - Size.cx = abs(bm.bmWidth); - Size.cy = abs(bm.bmHeight); - res = GreCreateBitmapEx(Size.cx, - Size.cy, - bm.bmWidthBytes, - Bitmap->SurfObj.iBitmapFormat, - Bitmap->SurfObj.fjBitmap, - Bitmap->SurfObj.cjBits, - NULL, - Bitmap->flags); - - - if (res) - { - resBitmap = SURFACE_ShareLockSurface(res); - if (resBitmap) - { - IntSetBitmapBits(resBitmap, Bitmap->SurfObj.cjBits, Bitmap->SurfObj.pvBits); - GDIOBJ_vReferenceObjectByPointer(&Bitmap->ppal->BaseObject); - GDIOBJ_vDereferenceObject(&resBitmap->ppal->BaseObject); - resBitmap->ppal = Bitmap->ppal; - SURFACE_ShareUnlockSurface(resBitmap); + /* Allocate a new bitmap with the same dimensions as the source bmp */ + hbmNew = GreCreateBitmapEx(psurfSrc->SurfObj.sizlBitmap.cx, + psurfSrc->SurfObj.sizlBitmap.cy, + psurfSrc->SurfObj.lDelta, + psurfSrc->SurfObj.iBitmapFormat, + psurfSrc->SurfObj.fjBitmap, + psurfSrc->SurfObj.cjBits, + NULL, + psurfSrc->flags); + + if (hbmNew) + { + /* Lock the new bitmap */ + psurfNew = SURFACE_ShareLockSurface(hbmNew); + if (psurfNew) + { + /* Copy the bitmap bits to the new bitmap buffer */ + RtlCopyMemory(psurfNew->SurfObj.pvBits, + psurfSrc->SurfObj.pvBits, + psurfNew->SurfObj.cjBits); + + /* Dereference the new bitmaps palette, we will use a different */ + GDIOBJ_vDereferenceObject(&psurfNew->ppal->BaseObject); + + /* Reference the palette of the source bitmap and use it */ + GDIOBJ_vReferenceObjectByPointer(&psurfSrc->ppal->BaseObject); + psurfNew->ppal = psurfSrc->ppal; + + /* Unlock the new surface */ + SURFACE_ShareUnlockSurface(psurfNew); } else { - GreDeleteObject(res); - res = NULL; - } - } - - SURFACE_ShareUnlockSurface(Bitmap); - - return res; + /* Failed to lock the bitmap, shouldn't happen */ + GreDeleteObject(hbmNew); + hbmNew = NULL; + } + } + + /* Unlock the source bitmap and return the handle of the new bitmap */ + SURFACE_ShareUnlockSurface(psurfSrc); + return hbmNew; }
INT APIENTRY @@ -850,15 +841,15 @@ pBitmap->bmHeight = psurf->SurfObj.sizlBitmap.cy; pBitmap->bmPlanes = 1; pBitmap->bmBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat); - pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN16(pBitmap->bmWidth, pBitmap->bmBitsPixel); + pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN16(pBitmap->bmWidth, pBitmap->bmBitsPixel);
/* Check for DIB section */ if (psurf->hSecure) { /* Set bmBits in this case */ pBitmap->bmBits = psurf->SurfObj.pvBits; - /* DIBs data are 32 bits aligned */ - pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN32(pBitmap->bmWidth, pBitmap->bmBitsPixel); + /* DIBs data are 32 bits aligned */ + pBitmap->bmWidthBytes = WIDTH_BYTES_ALIGN32(pBitmap->bmWidth, pBitmap->bmBitsPixel);
if (Count >= sizeof(DIBSECTION)) {