gdi32: Directly use ntdll in dib.c.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-09-17 13:45:10 +02:00 committed by Alexandre Julliard
parent 82f29bff47
commit ac6458844a
1 changed files with 30 additions and 19 deletions

View File

@ -1531,33 +1531,40 @@ HBITMAP WINAPI NtGdiCreateDIBSection( HDC hdc, HANDLE section, DWORD offset, con
if (section) if (section)
{ {
DWORD mapOffset; LARGE_INTEGER map_offset;
INT mapSize; SIZE_T map_size;
mapOffset = offset - (offset % system_info.AllocationGranularity); map_offset.QuadPart = offset - (offset % system_info.AllocationGranularity);
mapSize = bmp->dib.dsBmih.biSizeImage + (offset - mapOffset); map_size = bmp->dib.dsBmih.biSizeImage + (offset - map_offset.QuadPart);
mapBits = MapViewOfFile( section, FILE_MAP_ALL_ACCESS, 0, mapOffset, mapSize ); if (NtMapViewOfSection( section, GetCurrentProcess(), &mapBits, 0, 0, &map_offset,
if (mapBits) bmp->dib.dsBm.bmBits = (char *)mapBits + (offset - mapOffset); &map_size, ViewShare, 0, PAGE_READWRITE ))
goto error;
bmp->dib.dsBm.bmBits = (char *)mapBits + (offset - map_offset.QuadPart);
} }
else else
{ {
SIZE_T size = bmp->dib.dsBmih.biSizeImage;
offset = 0; offset = 0;
bmp->dib.dsBm.bmBits = VirtualAlloc( NULL, bmp->dib.dsBmih.biSizeImage, if (NtAllocateVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, 0, &size,
MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE ); MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE ))
goto error;
} }
bmp->dib.dshSection = section; bmp->dib.dshSection = section;
bmp->dib.dsOffset = offset; bmp->dib.dsOffset = offset;
if (!bmp->dib.dsBm.bmBits) goto error; if ((ret = alloc_gdi_handle( &bmp->obj, NTGDI_OBJ_BITMAP, &dib_funcs )))
{
if (!(ret = alloc_gdi_handle( &bmp->obj, NTGDI_OBJ_BITMAP, &dib_funcs ))) goto error; if (bits) *bits = bmp->dib.dsBm.bmBits;
return ret;
if (bits) *bits = bmp->dib.dsBm.bmBits; }
return ret;
if (section) NtUnmapViewOfSection( GetCurrentProcess(), mapBits );
else
{
SIZE_T size = 0;
NtFreeVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, &size, MEM_RELEASE );
}
error: error:
if (section) UnmapViewOfFile( mapBits );
else VirtualFree( bmp->dib.dsBm.bmBits, 0, MEM_RELEASE );
HeapFree( GetProcessHeap(), 0, bmp->color_table ); HeapFree( GetProcessHeap(), 0, bmp->color_table );
HeapFree( GetProcessHeap(), 0, bmp ); HeapFree( GetProcessHeap(), 0, bmp );
return 0; return 0;
@ -1739,10 +1746,14 @@ static BOOL DIB_DeleteObject( HGDIOBJ handle )
if (bmp->dib.dshSection) if (bmp->dib.dshSection)
{ {
UnmapViewOfFile( (char *)bmp->dib.dsBm.bmBits - NtUnmapViewOfSection( GetCurrentProcess(), (char *)bmp->dib.dsBm.bmBits -
(bmp->dib.dsOffset % system_info.AllocationGranularity) ); (bmp->dib.dsOffset % system_info.AllocationGranularity) );
}
else
{
SIZE_T size = 0;
NtFreeVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, &size, MEM_RELEASE );
} }
else VirtualFree( bmp->dib.dsBm.bmBits, 0, MEM_RELEASE );
HeapFree(GetProcessHeap(), 0, bmp->color_table); HeapFree(GetProcessHeap(), 0, bmp->color_table);
HeapFree( GetProcessHeap(), 0, bmp ); HeapFree( GetProcessHeap(), 0, bmp );