diff --git a/reactos/subsystems/win32/win32k/eng/surface.c b/reactos/subsystems/win32/win32k/eng/surface.c index 5b1a9701655..b5a446c6036 100644 --- a/reactos/subsystems/win32/win32k/eng/surface.c +++ b/reactos/subsystems/win32/win32k/eng/surface.c @@ -93,35 +93,56 @@ ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression) BOOL INTERNAL_CALL SURFACE_Cleanup(PVOID ObjectBody) { - PSURFACE psurf = (PSURFACE)ObjectBody; + PSURFACE psurf = (PSURFACE)ObjectBody; + PVOID pvBits = psurf->SurfObj.pvBits; - if (psurf->SurfObj.pvBits != NULL && - (psurf->flFlags & BITMAPOBJ_IS_APIBITMAP)) - { - if (psurf->dib == NULL) - { - ExFreePool(psurf->SurfObj.pvBits); - } - else - { - EngFreeUserMem(psurf->SurfObj.pvBits); - } - if (psurf->hDIBPalette != NULL) - { - NtGdiDeleteObject(psurf->hDIBPalette); - } - } + /* If this is an API bitmap, free the bits */ + if (pvBits != NULL && + (psurf->flFlags & BITMAPOBJ_IS_APIBITMAP)) + { + /* Check if we have a DIB section */ + if (psurf->hSecure) + { + // FIXME: IMPLEMENT ME! + // MmUnsecureVirtualMemory(psurf->hSecure); + if (psurf->hDIBSection) + { + /* DIB was created from a section */ + NTSTATUS Status; - if (NULL != psurf->BitsLock) - { - ExFreePoolWithTag(psurf->BitsLock, TAG_SURFACE); - psurf->BitsLock = NULL; - } + pvBits = (PVOID)((ULONG_PTR)pvBits - psurf->dwOffset); + Status = ZwUnmapViewOfSection(NtCurrentProcess(), pvBits); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Could not unmap section view!\n"); + // Should we BugCheck here? + } + } + else + { + /* DIB was allocated */ + EngFreeUserMem(pvBits); + } + } + else + { + // FIXME: use TAG + ExFreePool(psurf->SurfObj.pvBits); + } - if (psurf->dib) - ExFreePoolWithTag(psurf->dib, TAG_DIB); + if (psurf->hDIBPalette != NULL) + { + NtGdiDeleteObject(psurf->hDIBPalette); + } + } - return TRUE; + if (NULL != psurf->BitsLock) + { + ExFreePoolWithTag(psurf->BitsLock, TAG_SURFACE); + psurf->BitsLock = NULL; + } + + return TRUE; } BOOL INTERNAL_CALL @@ -408,7 +429,9 @@ IntCreateBitmap(IN SIZEL Size, psurf->flFlags = 0; psurf->dimension.cx = 0; psurf->dimension.cy = 0; - psurf->dib = NULL; + + psurf->hSecure = NULL; + psurf->hDIBSection = NULL; SURFACE_UnlockSurface(psurf); diff --git a/reactos/subsystems/win32/win32k/eng/xlate.c b/reactos/subsystems/win32/win32k/eng/xlate.c index 01fc2cac9f5..f254261c37d 100644 --- a/reactos/subsystems/win32/win32k/eng/xlate.c +++ b/reactos/subsystems/win32/win32k/eng/xlate.c @@ -486,7 +486,7 @@ IntCreateXlateForBlt(PDC pDCDest, PDC pDCSrc, SURFACE* psurfDest, SURFACE* psurf if (psurfSrc->SurfObj.iBitmapFormat == BMF_1BPP) { /* DIB sections need special handling */ - if (psurfSrc->dib) + if (psurfSrc->hSecure) { PPALGDI ppal = PALETTE_LockPalette(psurfSrc->hDIBPalette); if (ppal) diff --git a/reactos/subsystems/win32/win32k/include/bitmaps.h b/reactos/subsystems/win32/win32k/include/bitmaps.h index 7da9d134eb8..2cfd7c49cdb 100644 --- a/reactos/subsystems/win32/win32k/include/bitmaps.h +++ b/reactos/subsystems/win32/win32k/include/bitmaps.h @@ -8,5 +8,8 @@ int APIENTRY DIB_GetDIBImageBytes (INT width, INT height, INT depth); INT FASTCALL DIB_BitmapInfoSize (const BITMAPINFO * info, WORD coloruse); INT APIENTRY BITMAP_GetObject(SURFACE * bmp, INT count, LPVOID buffer); HBITMAP FASTCALL IntCreateBitmap(IN SIZEL Size, IN LONG Width, IN ULONG Format, IN ULONG Flags, IN PVOID Bits); +HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP hBitmap); +UINT FASTCALL BITMAP_GetRealBitsPixel(UINT nBitsPixel); +INT FASTCALL BITMAP_GetWidthBytes (INT bmWidth, INT bpp); #endif diff --git a/reactos/subsystems/win32/win32k/include/surface.h b/reactos/subsystems/win32/win32k/include/surface.h index f600c563834..d83e19accf8 100644 --- a/reactos/subsystems/win32/win32k/include/surface.h +++ b/reactos/subsystems/win32/win32k/include/surface.h @@ -20,9 +20,15 @@ typedef struct _SURFACE the actual bits in the bitmap */ /* For device-independent bitmaps: */ - DIBSECTION *dib; + HANDLE hDIBSection; + HANDLE hSecure; + DWORD dwOffset; + HPALETTE hDIBPalette; HDC hDC; // Doc in "Undocumented Windows", page 546, seems to be supported with XP. + DWORD dsBitfields[3]; // hack, should probably use palette instead + DWORD biClrUsed; + DWORD biClrImportant; } SURFACE, *PSURFACE; #define BITMAPOBJ_IS_APIBITMAP 0x1 @@ -50,9 +56,6 @@ typedef struct _SURFACE BOOL INTERNAL_CALL SURFACE_Cleanup(PVOID ObjectBody); BOOL INTERNAL_CALL SURFACE_InitBitsLock(SURFACE *pBMObj); void INTERNAL_CALL SURFACE_CleanupBitsLock(SURFACE *pBMObj); -INT FASTCALL SURFACE_GetWidthBytes (INT bmWidth, INT bpp); -UINT FASTCALL SURFACE_GetRealBitsPixel(UINT nBitsPixel); -HBITMAP FASTCALL SURFACE_CopyBitmap (HBITMAP hBitmap); #define GDIDEV(SurfObj) ((GDIDEVICE *)((SurfObj)->hdev)) #define GDIDEVFUNCS(SurfObj) ((GDIDEVICE *)((SurfObj)->hdev))->DriverFunctions diff --git a/reactos/subsystems/win32/win32k/ntuser/cursoricon.c b/reactos/subsystems/win32/win32k/ntuser/cursoricon.c index 59b606c2b36..d41f4c82611 100644 --- a/reactos/subsystems/win32/win32k/ntuser/cursoricon.c +++ b/reactos/subsystems/win32/win32k/ntuser/cursoricon.c @@ -567,8 +567,8 @@ NtUserCreateCursorIconHandle(PICONINFO IconInfo OPTIONAL, BOOL Indirect) { if(Indirect) { - CurIcon->IconInfo.hbmMask = SURFACE_CopyBitmap(CurIcon->IconInfo.hbmMask); - CurIcon->IconInfo.hbmColor = SURFACE_CopyBitmap(CurIcon->IconInfo.hbmColor); + CurIcon->IconInfo.hbmMask = BITMAP_CopyBitmap(CurIcon->IconInfo.hbmMask); + CurIcon->IconInfo.hbmColor = BITMAP_CopyBitmap(CurIcon->IconInfo.hbmColor); } if(CurIcon->IconInfo.hbmColor && (psurfBmp = SURFACE_LockSurface(CurIcon->IconInfo.hbmColor))) @@ -651,8 +651,8 @@ NtUserGetIconInfo( RtlCopyMemory(&ii, &CurIcon->IconInfo, sizeof(ICONINFO)); /* Copy bitmaps */ - ii.hbmMask = SURFACE_CopyBitmap(CurIcon->IconInfo.hbmMask); - ii.hbmColor = SURFACE_CopyBitmap(CurIcon->IconInfo.hbmColor); + ii.hbmMask = BITMAP_CopyBitmap(CurIcon->IconInfo.hbmMask); + ii.hbmColor = BITMAP_CopyBitmap(CurIcon->IconInfo.hbmColor); /* Copy fields */ _SEH2_TRY @@ -1244,8 +1244,8 @@ NtUserSetCursorIconData( ProbeForRead(pIconInfo, sizeof(ICONINFO), 1); RtlCopyMemory(&CurIcon->IconInfo, pIconInfo, sizeof(ICONINFO)); - CurIcon->IconInfo.hbmMask = SURFACE_CopyBitmap(pIconInfo->hbmMask); - CurIcon->IconInfo.hbmColor = SURFACE_CopyBitmap(pIconInfo->hbmColor); + CurIcon->IconInfo.hbmMask = BITMAP_CopyBitmap(pIconInfo->hbmMask); + CurIcon->IconInfo.hbmColor = BITMAP_CopyBitmap(pIconInfo->hbmColor); if (CurIcon->IconInfo.hbmColor) { diff --git a/reactos/subsystems/win32/win32k/objects/bitmaps.c b/reactos/subsystems/win32/win32k/objects/bitmaps.c index 0fc4d5e6547..50c2f22adf6 100644 --- a/reactos/subsystems/win32/win32k/objects/bitmaps.c +++ b/reactos/subsystems/win32/win32k/objects/bitmaps.c @@ -44,7 +44,7 @@ IntGdiCreateBitmap( LONG WidthBytes; /* NOTE: Windows also doesn't store nr. of planes separately! */ - BitsPixel = SURFACE_GetRealBitsPixel(BitsPixel * Planes); + BitsPixel = BITMAP_GetRealBitsPixel(BitsPixel * Planes); /* Check parameters */ if (BitsPixel == 0 || Width <= 0 || Width >= 0x8000000 || Height == 0) @@ -54,7 +54,7 @@ IntGdiCreateBitmap( return 0; } - WidthBytes = SURFACE_GetWidthBytes(Width, BitsPixel); + WidthBytes = BITMAP_GetWidthBytes(Width, BitsPixel); Size.cx = Width; Size.cy = abs(Height); @@ -113,7 +113,7 @@ NtGdiCreateBitmap( if (pUnsafeBits) { BOOL Hit = FALSE; - UINT cjBits = SURFACE_GetWidthBytes(Width, BitsPixel) * abs(Height); + UINT cjBits = BITMAP_GetWidthBytes(Width, BitsPixel) * abs(Height); _SEH2_TRY { @@ -689,7 +689,7 @@ NtGdiSetPixel( /* Internal Functions */ UINT FASTCALL -SURFACE_GetRealBitsPixel(UINT nBitsPixel) +BITMAP_GetRealBitsPixel(UINT nBitsPixel) { if (nBitsPixel <= 1) return 1; @@ -708,7 +708,7 @@ SURFACE_GetRealBitsPixel(UINT nBitsPixel) } INT FASTCALL -SURFACE_GetWidthBytes (INT bmWidth, INT bpp) +BITMAP_GetWidthBytes (INT bmWidth, INT bpp) { #if 0 switch(bpp) @@ -742,7 +742,7 @@ SURFACE_GetWidthBytes (INT bmWidth, INT bpp) } HBITMAP FASTCALL -SURFACE_CopyBitmap(HBITMAP hBitmap) +BITMAP_CopyBitmap(HBITMAP hBitmap) { HBITMAP res; BITMAP bm; @@ -807,45 +807,59 @@ SURFACE_CopyBitmap(HBITMAP hBitmap) } INT APIENTRY -BITMAP_GetObject(SURFACE * bmp, INT Count, LPVOID buffer) +BITMAP_GetObject(SURFACE *psurf, INT Count, LPVOID buffer) { + PBITMAP pBitmap; + + if (!buffer) return sizeof(BITMAP); if ((UINT)Count < sizeof(BITMAP)) return 0; - if(bmp->dib) + /* always fill a basic BITMAP structure */ + pBitmap = buffer; + pBitmap->bmType = 0; + pBitmap->bmWidth = psurf->SurfObj.sizlBitmap.cx; + pBitmap->bmHeight = psurf->SurfObj.sizlBitmap.cy; + pBitmap->bmWidthBytes = abs(psurf->SurfObj.lDelta); + pBitmap->bmPlanes = 1; + pBitmap->bmBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat); + + /* Check for DIB section */ + if(psurf->hSecure) { - if((UINT)Count < sizeof(DIBSECTION)) - { - Count = sizeof(BITMAP); - } - else - { - Count = sizeof(DIBSECTION); - } - if (buffer) - { - memcpy(buffer, bmp->dib, Count); - } - return Count; + /* Set bmBits in this case */ + pBitmap->bmBits = psurf->SurfObj.pvBits; + + if (Count >= sizeof(DIBSECTION)) + { + /* Fill rest of DIBSECTION */ + PDIBSECTION pds = buffer; + + pds->dsBmih.biSize = + pds->dsBmih.biWidth = pds->dsBm.bmWidth; + pds->dsBmih.biHeight = pds->dsBm.bmHeight; + pds->dsBmih.biPlanes = pds->dsBm.bmPlanes; + pds->dsBmih.biBitCount = pds->dsBm.bmBitsPixel; + pds->dsBmih.biCompression = 0; // FIXME! + pds->dsBmih.biSizeImage = psurf->SurfObj.cjBits; + pds->dsBmih.biXPelsPerMeter = 0; + pds->dsBmih.biYPelsPerMeter = 0; + pds->dsBmih.biClrUsed = psurf->biClrUsed; + pds->dsBmih.biClrImportant = psurf->biClrImportant; + pds->dsBitfields[0] = psurf->dsBitfields[0]; + pds->dsBitfields[1] = psurf->dsBitfields[1]; + pds->dsBitfields[2] = psurf->dsBitfields[2]; + pds->dshSection = psurf->hDIBSection; + pds->dsOffset = psurf->dwOffset; + + return sizeof(DIBSECTION); + } } else { - Count = sizeof(BITMAP); - if (buffer) - { - BITMAP Bitmap; - - Count = sizeof(BITMAP); - Bitmap.bmType = 0; - Bitmap.bmWidth = bmp->SurfObj.sizlBitmap.cx; - Bitmap.bmHeight = bmp->SurfObj.sizlBitmap.cy; - Bitmap.bmWidthBytes = abs(bmp->SurfObj.lDelta); - Bitmap.bmPlanes = 1; - Bitmap.bmBitsPixel = BitsPerFormat(bmp->SurfObj.iBitmapFormat); - Bitmap.bmBits = NULL; /* not set according to wine test, confirmed in win2k */ - memcpy(buffer, &Bitmap, Count); - } - return Count; + pBitmap->bmBits = NULL; /* not set according to wine test, confirmed in win2k */ } + + return sizeof(BITMAP); } /* @@ -917,9 +931,10 @@ NtGdiSelectBitmap( psurfBmp->hDC = hDC; // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null] - if(psurfBmp->dib) + if(psurfBmp->hSecure) { - pDC->w.bitsPerPixel = psurfBmp->dib->dsBmih.biBitCount; +// pDC->w.bitsPerPixel = psurfBmp->dib->dsBmih.biBitCount; ??? + pDC->w.bitsPerPixel = BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat); } else { diff --git a/reactos/subsystems/win32/win32k/objects/brush.c b/reactos/subsystems/win32/win32k/objects/brush.c index 5af5e1d5199..ccec435e82b 100644 --- a/reactos/subsystems/win32/win32k/objects/brush.c +++ b/reactos/subsystems/win32/win32k/objects/brush.c @@ -437,7 +437,7 @@ IntGdiCreatePatternBrush( PGDIBRUSHOBJ BrushObject; HBITMAP hPattern; - hPattern = SURFACE_CopyBitmap(hBitmap); + hPattern = BITMAP_CopyBitmap(hBitmap); if (hPattern == NULL) { SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY); diff --git a/reactos/subsystems/win32/win32k/objects/dibobj.c b/reactos/subsystems/win32/win32k/objects/dibobj.c index 9f0da9b930a..f94721312a0 100644 --- a/reactos/subsystems/win32/win32k/objects/dibobj.c +++ b/reactos/subsystems/win32/win32k/objects/dibobj.c @@ -76,6 +76,7 @@ IntSetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, CONST RGBQUAD *Color PSURFACE psurf; PPALGDI PalGDI; UINT Index; + ULONG biBitCount; if (!(dc = DC_LockDc(hDC))) return 0; if (dc->DC_Type == DC_TYPE_INFO) @@ -92,7 +93,7 @@ IntSetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, CONST RGBQUAD *Color return 0; } - if (psurf->dib == NULL) + if (psurf->hSecure == NULL) { SURFACE_UnlockSurface(psurf); DC_UnlockDc(dc); @@ -100,11 +101,11 @@ IntSetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, CONST RGBQUAD *Color return 0; } - if (psurf->dib->dsBmih.biBitCount <= 8 && - StartIndex < (1 << psurf->dib->dsBmih.biBitCount)) + biBitCount = BitsPerFormat(psurf->SurfObj.iBitmapFormat); + if (biBitCount <= 8 && StartIndex < (1 << biBitCount)) { - if (StartIndex + Entries > (1 << psurf->dib->dsBmih.biBitCount)) - Entries = (1 << psurf->dib->dsBmih.biBitCount) - StartIndex; + if (StartIndex + Entries > (1 << biBitCount)) + Entries = (1 << biBitCount) - StartIndex; PalGDI = PALETTE_LockPalette(psurf->hDIBPalette); if (PalGDI == NULL) @@ -141,6 +142,7 @@ IntGetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, RGBQUAD *Colors) PSURFACE psurf; PPALGDI PalGDI; UINT Index; + ULONG biBitCount; if (!(dc = DC_LockDc(hDC))) return 0; if (dc->DC_Type == DC_TYPE_INFO) @@ -157,7 +159,7 @@ IntGetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, RGBQUAD *Colors) return 0; } - if (psurf->dib == NULL) + if (psurf->hSecure == NULL) { SURFACE_UnlockSurface(psurf); DC_UnlockDc(dc); @@ -165,11 +167,12 @@ IntGetDIBColorTable(HDC hDC, UINT StartIndex, UINT Entries, RGBQUAD *Colors) return 0; } - if (psurf->dib->dsBmih.biBitCount <= 8 && - StartIndex < (1 << psurf->dib->dsBmih.biBitCount)) + biBitCount = BitsPerFormat(psurf->SurfObj.iBitmapFormat); + if (biBitCount <= 8 && + StartIndex < (1 << biBitCount)) { - if (StartIndex + Entries > (1 << psurf->dib->dsBmih.biBitCount)) - Entries = (1 << psurf->dib->dsBmih.biBitCount) - StartIndex; + if (StartIndex + Entries > (1 << biBitCount)) + Entries = (1 << biBitCount) - StartIndex; PalGDI = PALETTE_LockPalette(psurf->hDIBPalette); if (PalGDI == NULL) @@ -750,7 +753,8 @@ NtGdiGetDIBitsInternal(HDC hDC, case 4: case 8: Info->bmiHeader.biClrUsed = 0; - if ( psurf->dib && psurf->dib->dsBm.bmBitsPixel == Info->bmiHeader.biBitCount) + if ( psurf->hSecure && + BitsPerFormat(psurf->SurfObj.iBitmapFormat) == Info->bmiHeader.biBitCount) { if (Usage == DIB_RGB_COLORS) { @@ -1316,7 +1320,6 @@ DIB_CreateDIBSection( { HBITMAP res = 0; SURFACE *bmp = NULL; - DIBSECTION *dib = NULL; void *mapBits = NULL; PDC_ATTR pDc_Attr; @@ -1327,6 +1330,8 @@ DIB_CreateDIBSection( BITMAP bm; SIZEL Size; RGBQUAD *lpRGB; + HANDLE hSecure; + DWORD dsBitfields[3] = {0}; DPRINT("format (%ld,%ld), planes %d, bpp %d, size %ld, colors %ld (%s)\n", bi->biWidth, bi->biHeight, bi->biPlanes, bi->biBitCount, @@ -1374,7 +1379,7 @@ DIB_CreateDIBSection( } mapOffset = offset - (offset % Sbi.AllocationGranularity); - mapSize = dib->dsBmih.biSizeImage + (offset - mapOffset); + mapSize = bi->biSizeImage + (offset - mapOffset); SectionOffset.LowPart = mapOffset; SectionOffset.HighPart = 0; @@ -1405,44 +1410,44 @@ DIB_CreateDIBSection( bm.bmBits = EngAllocUserMem( totalSize, 0 ); } +// hSecure = MmSecureVirtualMemory(bm.bmBits, totalSize, PAGE_READWRITE); + hSecure = (HANDLE)0x1; // HACK OF UNIMPLEMENTED KERNEL STUFF !!!! + if(usage == DIB_PAL_COLORS) lpRGB = DIB_MapPaletteColors(dc, bmi); else lpRGB = bmi->bmiColors; - // Allocate Memory for DIB and fill structure - if (bm.bmBits) - { - dib = ExAllocatePoolWithTag(PagedPool, sizeof(DIBSECTION), TAG_DIB); - if (dib != NULL) RtlZeroMemory(dib, sizeof(DIBSECTION)); - } - - if (dib) - { - dib->dsBm = bm; /* Set dsBitfields values */ if ( usage == DIB_PAL_COLORS || bi->biBitCount <= 8) { - dib->dsBitfields[0] = dib->dsBitfields[1] = dib->dsBitfields[2] = 0; + dsBitfields[0] = dsBitfields[1] = dsBitfields[2] = 0; } - else switch(bi->biBitCount) + else if (bi->biCompression == BI_RGB) { - case 15: - case 16: - dib->dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)lpRGB : 0x7c00; - dib->dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 1) : 0x03e0; - dib->dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 2) : 0x001f; - break; + switch(bi->biBitCount) + { + case 15: + case 16: + dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)lpRGB : 0x7c00; + dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 1) : 0x03e0; + dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 2) : 0x001f; + break; - case 24: - case 32: - dib->dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)lpRGB : 0xff0000; - dib->dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 1) : 0x00ff00; - dib->dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 2) : 0x0000ff; - break; + case 24: + case 32: + dsBitfields[0] = (bi->biCompression == BI_BITFIELDS) ? *(DWORD *)lpRGB : 0xff0000; + dsBitfields[1] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 1) : 0x00ff00; + dsBitfields[2] = (bi->biCompression == BI_BITFIELDS) ? *((DWORD *)lpRGB + 2) : 0x0000ff; + break; + } + } + else + { + dsBitfields[0] = ((DWORD*)bmi->bmiColors)[0]; + dsBitfields[1] = ((DWORD*)bmi->bmiColors)[1]; + dsBitfields[2] = ((DWORD*)bmi->bmiColors)[2]; } - dib->dshSection = section; - dib->dsOffset = offset; // Create Device Dependent Bitmap and add DIB pointer Size.cx = bm.bmWidth; @@ -1469,12 +1474,19 @@ DIB_CreateDIBSection( { ExFreePoolWithTag(lpRGB, TAG_COLORMAP); } - SetLastWin32Error(ERROR_INVALID_HANDLE); - NtGdiDeleteObject(bmp); - return NULL; + SetLastWin32Error(ERROR_INVALID_HANDLE); + NtGdiDeleteObject(bmp); + return NULL; } - bmp->dib = (DIBSECTION *) dib; + bmp->hDIBSection = section; + bmp->hSecure = hSecure; + bmp->dwOffset = offset; bmp->flFlags = BITMAPOBJ_IS_APIBITMAP; + bmp->dsBitfields[0] = dsBitfields[0]; + bmp->dsBitfields[1] = dsBitfields[1]; + bmp->dsBitfields[2] = dsBitfields[2]; + bmp->biClrUsed = bi->biClrUsed; + bmp->biClrImportant = bi->biClrImportant; /* WINE NOTE: WINE makes use of a colormap, which is a color translation table between the DIB and the X physical device. Obviously, @@ -1490,20 +1502,17 @@ DIB_CreateDIBSection( bmp->hDIBPalette = PALETTE_AllocPaletteIndexedRGB(bi->biClrUsed, lpRGB); else bmp->hDIBPalette = PALETTE_AllocPalette(PAL_BITFIELDS, 0, NULL, - dib->dsBitfields[0], - dib->dsBitfields[1], - dib->dsBitfields[2]); - - dib->dsBmih = *bi; - dib->dsBmih.biSizeImage = totalSize; - } + dsBitfields[0], + dsBitfields[1], + dsBitfields[2]); // Clean up in case of errors - if (!res || !bmp || !dib || !bm.bmBits) + if (!res || !bmp || !bm.bmBits) { - DPRINT("got an error res=%08x, bmp=%p, dib=%p, bm.bmBits=%p\n", res, bmp, dib, bm.bmBits); + DPRINT("got an error res=%08x, bmp=%p, bm.bmBits=%p\n", res, bmp, bm.bmBits); if (bm.bmBits) { + // MmUnsecureVirtualMemory(hSecure); // FIXME: Implement this! if (section) { ZwUnmapViewOfSection(NtCurrentProcess(), mapBits); @@ -1514,7 +1523,6 @@ DIB_CreateDIBSection( EngFreeUserMem(bm.bmBits), bm.bmBits = NULL; } - if (dib) { ExFreePoolWithTag(dib, TAG_DIB); dib = NULL; } if (bmp) { bmp = NULL; } if (res) { SURFACE_FreeSurfaceByHandle(res); res = 0; } }