diff --git a/inc/dd.h b/inc/dd.h index f504df6..4b54dc6 100644 --- a/inc/dd.h +++ b/inc/dd.h @@ -180,7 +180,6 @@ typedef struct CNCDDRAW DWORD gui_thread_id; BOOL rgb555; BOOL hook_peekmessage; - BOOL dont_emulate_dc; } CNCDDRAW; diff --git a/inc/ddsurface.h b/inc/ddsurface.h index 8a3583c..80e37ae 100644 --- a/inc/ddsurface.h +++ b/inc/ddsurface.h @@ -37,5 +37,6 @@ HRESULT dds_SetSurfaceDesc(IDirectDrawSurfaceImpl* This, LPDDSURFACEDESC2 lpDDSD void* dds_GetBuffer(IDirectDrawSurfaceImpl* This); HRESULT dd_CreateSurface(IDirectDrawImpl* This, LPDDSURFACEDESC lpDDSurfaceDesc, IDirectDrawSurfaceImpl** lpDDSurface, IUnknown FAR* unkOuter); +extern LONG g_dds_gdi_handles; #endif diff --git a/src/IDirectDraw/IDirectDrawSurface.c b/src/IDirectDraw/IDirectDrawSurface.c index 154f73f..973b5ba 100644 --- a/src/IDirectDraw/IDirectDrawSurface.c +++ b/src/IDirectDraw/IDirectDrawSurface.c @@ -92,6 +92,7 @@ ULONG __stdcall IDirectDrawSurface__Release(IDirectDrawSurfaceImpl* This) if (This->bitmap) { DeleteObject(This->bitmap); + InterlockedDecrement(&g_dds_gdi_handles); } else if (This->surface && !This->custom_buf) { @@ -99,7 +100,10 @@ ULONG __stdcall IDirectDrawSurface__Release(IDirectDrawSurfaceImpl* This) } if (This->hdc) + { DeleteDC(This->hdc); + InterlockedDecrement(&g_dds_gdi_handles); + } if (This->bmi) HeapFree(GetProcessHeap(), 0, This->bmi); diff --git a/src/config.c b/src/config.c index a2f224f..afabc83 100644 --- a/src/config.c +++ b/src/config.c @@ -55,7 +55,6 @@ void cfg_load() g_ddraw->opengl_core = cfg_get_bool("opengl_core", FALSE); g_ddraw->rgb555 = cfg_get_bool("rgb555", FALSE); g_ddraw->hook_peekmessage = cfg_get_bool("hook_peekmessage", FALSE); - g_ddraw->dont_emulate_dc = cfg_get_bool("dont_emulate_dc", FALSE); cfg_get_string("screenshotdir", ".\\Screenshots\\", g_ddraw->screenshot_dir, sizeof(g_ddraw->screenshot_dir)); if (g_ddraw->locktopleft) @@ -380,7 +379,6 @@ static void cfg_create_ini() "hook_peekmessage=false\n" "dinput_show_cursor=false\n" "no_dinput_hook=false\n" - "dont_emulate_dc=false\n" "\n" "\n" "\n" @@ -809,10 +807,6 @@ static void cfg_create_ini() "renderer=opengl\n" "noactivateapp=true\n" "\n" - "; Hooligans: Storm over Europe\n" - "[Hooligans]\n" - "dont_emulate_dc=true\n" - "\n" "; Invictus\n" "[Invictus]\n" "adjmouse=true\n" diff --git a/src/ddsurface.c b/src/ddsurface.c index c3e9268..1914d3d 100644 --- a/src/ddsurface.c +++ b/src/ddsurface.c @@ -12,6 +12,8 @@ #include "blt.h" +LONG g_dds_gdi_handles; + HRESULT dds_AddAttachedSurface(IDirectDrawSurfaceImpl* This, IDirectDrawSurfaceImpl* lpDDSurface) { if (lpDDSurface) @@ -1205,6 +1207,7 @@ HRESULT dds_SetSurfaceDesc(IDirectDrawSurfaceImpl* This, LPDDSURFACEDESC2 lpDDSD if (This->bitmap) { DeleteObject(This->bitmap); + InterlockedDecrement(&g_dds_gdi_handles); This->bitmap = NULL; } else if (This->surface && !This->custom_buf) @@ -1216,6 +1219,7 @@ HRESULT dds_SetSurfaceDesc(IDirectDrawSurfaceImpl* This, LPDDSURFACEDESC2 lpDDSD if (This->hdc) { DeleteDC(This->hdc); + InterlockedDecrement(&g_dds_gdi_handles); This->hdc = NULL; } @@ -1432,10 +1436,13 @@ HRESULT dd_CreateSurface( } - if (!g_ddraw->dont_emulate_dc) + if (InterlockedExchangeAdd(&g_dds_gdi_handles, 0) < 4000 || (dst_surface->caps & DDSCAPS_PRIMARYSURFACE)) { dst_surface->hdc = CreateCompatibleDC(g_ddraw->render.hdc); + if (dst_surface->hdc) + InterlockedIncrement(&g_dds_gdi_handles); + dst_surface->mapping = CreateFileMappingA( INVALID_HANDLE_VALUE, @@ -1472,6 +1479,9 @@ HRESULT dd_CreateSurface( (void**)&dst_surface->surface, dst_surface->mapping, map_offset); + + if (dst_surface->bitmap) + InterlockedIncrement(&g_dds_gdi_handles); } dst_surface->bmi->bmiHeader.biHeight = -((int)dst_surface->height); @@ -1489,7 +1499,7 @@ HRESULT dd_CreateSurface( { g_ddraw->primary = dst_surface; FakePrimarySurface = dst_surface->surface; - } + } } if (dst_surface->flags & DDSD_BACKBUFFERCOUNT)