allocate memory with CreateFileMapping
This commit is contained in:
parent
9b5856c496
commit
8a63e2b976
3 changed files with 44 additions and 8 deletions
|
@ -29,6 +29,7 @@ typedef struct IDirectDrawSurfaceImpl
|
||||||
IDirectDrawPaletteImpl* palette;
|
IDirectDrawPaletteImpl* palette;
|
||||||
|
|
||||||
void* surface;
|
void* surface;
|
||||||
|
HANDLE surface_mapping;
|
||||||
DWORD l_pitch;
|
DWORD l_pitch;
|
||||||
DWORD lx_pitch;
|
DWORD lx_pitch;
|
||||||
BOOL custom_surface;
|
BOOL custom_surface;
|
||||||
|
|
|
@ -96,6 +96,9 @@ ULONG __stdcall IDirectDrawSurface__Release(IDirectDrawSurfaceImpl* This)
|
||||||
if (This->bmi)
|
if (This->bmi)
|
||||||
HeapFree(GetProcessHeap(), 0, This->bmi);
|
HeapFree(GetProcessHeap(), 0, This->bmi);
|
||||||
|
|
||||||
|
if (This->surface_mapping)
|
||||||
|
CloseHandle(This->surface_mapping);
|
||||||
|
|
||||||
if (This->backbuffer)
|
if (This->backbuffer)
|
||||||
IDirectDrawSurface_Release(This->backbuffer);
|
IDirectDrawSurface_Release(This->backbuffer);
|
||||||
|
|
||||||
|
|
|
@ -1053,9 +1053,10 @@ HRESULT dd_CreateSurface(
|
||||||
|
|
||||||
DWORD aligned_width = dst_surface->l_pitch / dst_surface->lx_pitch;
|
DWORD aligned_width = dst_surface->l_pitch / dst_surface->lx_pitch;
|
||||||
|
|
||||||
dst_surface->bmi =
|
DWORD bmi_size = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256;
|
||||||
HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
|
DWORD bmp_size = dst_surface->l_pitch * (dst_surface->height + 200);
|
||||||
|
|
||||||
|
dst_surface->bmi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bmi_size);
|
||||||
dst_surface->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
dst_surface->bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
dst_surface->bmi->bmiHeader.biWidth = aligned_width;
|
dst_surface->bmi->bmiHeader.biWidth = aligned_width;
|
||||||
dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height + 200);
|
dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height + 200);
|
||||||
|
@ -1097,18 +1098,49 @@ HRESULT dd_CreateSurface(
|
||||||
}
|
}
|
||||||
|
|
||||||
dst_surface->hdc = CreateCompatibleDC(g_ddraw->render.hdc);
|
dst_surface->hdc = CreateCompatibleDC(g_ddraw->render.hdc);
|
||||||
|
|
||||||
|
dst_surface->surface_mapping =
|
||||||
|
CreateFileMappingA(
|
||||||
|
INVALID_HANDLE_VALUE,
|
||||||
|
NULL,
|
||||||
|
PAGE_READWRITE | SEC_COMMIT,
|
||||||
|
0,
|
||||||
|
bmp_size + 256,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
DWORD map_offset = 0;
|
||||||
|
|
||||||
|
if (dst_surface->surface_mapping)
|
||||||
|
{
|
||||||
|
LPVOID data = MapViewOfFile(dst_surface->surface_mapping, FILE_MAP_READ, 0, 0, 0);
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
while (((DWORD)data + map_offset) % 128) map_offset++;
|
||||||
|
UnmapViewOfFile(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!data || (map_offset % sizeof(DWORD)))
|
||||||
|
{
|
||||||
|
map_offset = 0;
|
||||||
|
CloseHandle(dst_surface->surface_mapping);
|
||||||
|
dst_surface->surface_mapping = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dst_surface->bitmap =
|
dst_surface->bitmap =
|
||||||
CreateDIBSection(dst_surface->hdc, dst_surface->bmi, DIB_RGB_COLORS, (void**)&dst_surface->surface, NULL, 0);
|
CreateDIBSection(
|
||||||
|
dst_surface->hdc,
|
||||||
|
dst_surface->bmi,
|
||||||
|
DIB_RGB_COLORS,
|
||||||
|
(void**)&dst_surface->surface,
|
||||||
|
dst_surface->surface_mapping,
|
||||||
|
map_offset);
|
||||||
|
|
||||||
dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height);
|
dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height);
|
||||||
|
|
||||||
if (!dst_surface->bitmap)
|
if (!dst_surface->bitmap)
|
||||||
{
|
{
|
||||||
dst_surface->surface =
|
dst_surface->surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bmp_size);
|
||||||
HeapAlloc(
|
|
||||||
GetProcessHeap(),
|
|
||||||
HEAP_ZERO_MEMORY,
|
|
||||||
dst_surface->l_pitch * (dst_surface->height + 200));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dst_surface->caps & DDSCAPS_PRIMARYSURFACE)
|
if (dst_surface->caps & DDSCAPS_PRIMARYSURFACE)
|
||||||
|
|
Loading…
Reference in a new issue