win-capture: Track gl "swap" invocations to prevent duplicate work
Tested using FTL (steam): SwapBuffers ultimately calls wgl_swap_buffers causing an additional copy which just isn't necessary This also causes game capture to sometimes capture overlays even when not intendedmaster
parent
f8fcba2fa2
commit
4c505e7030
|
@ -30,6 +30,7 @@ static struct func_hook wgl_delete_context;
|
||||||
static bool darkest_dungeon_fix = false;
|
static bool darkest_dungeon_fix = false;
|
||||||
|
|
||||||
struct gl_data {
|
struct gl_data {
|
||||||
|
int swap_recurse;
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
uint32_t base_cx;
|
uint32_t base_cx;
|
||||||
uint32_t base_cy;
|
uint32_t base_cy;
|
||||||
|
@ -773,20 +774,36 @@ static void gl_capture(HDC hdc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void gl_swap_begin(HDC hdc)
|
||||||
|
{
|
||||||
|
if (data.swap_recurse++)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!global_hook_info->capture_overlay)
|
||||||
|
gl_capture(hdc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void gl_swap_end(HDC hdc)
|
||||||
|
{
|
||||||
|
if (--data.swap_recurse)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (global_hook_info->capture_overlay)
|
||||||
|
gl_capture(hdc);
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL WINAPI hook_swap_buffers(HDC hdc)
|
static BOOL WINAPI hook_swap_buffers(HDC hdc)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
if (!global_hook_info->capture_overlay)
|
gl_swap_begin(hdc);
|
||||||
gl_capture(hdc);
|
|
||||||
|
|
||||||
unhook(&swap_buffers);
|
unhook(&swap_buffers);
|
||||||
BOOL (WINAPI *call)(HDC) = swap_buffers.call_addr;
|
BOOL (WINAPI *call)(HDC) = swap_buffers.call_addr;
|
||||||
ret = call(hdc);
|
ret = call(hdc);
|
||||||
rehook(&swap_buffers);
|
rehook(&swap_buffers);
|
||||||
|
|
||||||
if (global_hook_info->capture_overlay)
|
gl_swap_end(hdc);
|
||||||
gl_capture(hdc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -795,16 +812,15 @@ static BOOL WINAPI hook_wgl_swap_buffers(HDC hdc)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
if (!global_hook_info->capture_overlay)
|
gl_swap_begin(hdc);
|
||||||
gl_capture(hdc);
|
|
||||||
|
|
||||||
unhook(&wgl_swap_buffers);
|
unhook(&wgl_swap_buffers);
|
||||||
|
|
||||||
BOOL (WINAPI *call)(HDC) = wgl_swap_buffers.call_addr;
|
BOOL (WINAPI *call)(HDC) = wgl_swap_buffers.call_addr;
|
||||||
ret = call(hdc);
|
ret = call(hdc);
|
||||||
rehook(&wgl_swap_buffers);
|
rehook(&wgl_swap_buffers);
|
||||||
|
|
||||||
if (global_hook_info->capture_overlay)
|
gl_swap_end(hdc);
|
||||||
gl_capture(hdc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -813,16 +829,15 @@ static BOOL WINAPI hook_wgl_swap_layer_buffers(HDC hdc, UINT planes)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
if (!global_hook_info->capture_overlay)
|
gl_swap_begin(hdc);
|
||||||
gl_capture(hdc);
|
|
||||||
|
|
||||||
unhook(&wgl_swap_layer_buffers);
|
unhook(&wgl_swap_layer_buffers);
|
||||||
|
|
||||||
BOOL (WINAPI *call)(HDC, UINT) = wgl_swap_layer_buffers.call_addr;
|
BOOL (WINAPI *call)(HDC, UINT) = wgl_swap_layer_buffers.call_addr;
|
||||||
ret = call(hdc, planes);
|
ret = call(hdc, planes);
|
||||||
rehook(&wgl_swap_layer_buffers);
|
rehook(&wgl_swap_layer_buffers);
|
||||||
|
|
||||||
if (global_hook_info->capture_overlay)
|
gl_swap_end(hdc);
|
||||||
gl_capture(hdc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue