Skip to content

Commit

Permalink
win-capture: added new signal CaptureHook_Frame that gets set when ne…
Browse files Browse the repository at this point in the history
…w frame is rendered

also: bumped hook version to 1.9 due to that new feature
  • Loading branch information
lostmsu committed Apr 24, 2023
1 parent 51fc325 commit 2db38e1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions plugins/win-capture/graphics-hook-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define EVENT_CAPTURE_RESTART L"CaptureHook_Restart"
#define EVENT_CAPTURE_STOP L"CaptureHook_Stop"

#define EVENT_NEW_FRAME L"CaptureHook_Frame"

#define EVENT_HOOK_READY L"CaptureHook_HookReady"

#define EVENT_HOOK_INIT L"CaptureHook_Initialize"
Expand Down
2 changes: 1 addition & 1 deletion plugins/win-capture/graphics-hook-ver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* THIS IS YOUR ONLY WARNING. */

#define HOOK_VER_MAJOR 1
#define HOOK_VER_MINOR 8
#define HOOK_VER_MINOR 9
#define HOOK_VER_PATCH 0

#ifndef STRINGIFY
Expand Down
1 change: 1 addition & 0 deletions plugins/win-capture/graphics-hook/d3d8-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static void d3d8_capture(IDirect3DDevice8 *device,
}
if (capture_ready()) {
d3d8_shmem_capture(device, backbuffer);
signal_frame_ready();
}
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/win-capture/graphics-hook/d3d9-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ static void d3d9_capture(IDirect3DDevice9 *device,
d3d9_shtex_capture(backbuffer);
else
d3d9_shmem_capture(backbuffer);

signal_frame_ready();
}
}

Expand Down
4 changes: 4 additions & 0 deletions plugins/win-capture/graphics-hook/dxgi-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ static HRESULT STDMETHODCALLTYPE hook_present(IDXGISwapChain *swap,

if (backbuffer) {
data.capture(swap, backbuffer);
signal_frame_ready();
backbuffer->Release();
}
}
Expand All @@ -250,6 +251,7 @@ static HRESULT STDMETHODCALLTYPE hook_present(IDXGISwapChain *swap,

if (backbuffer) {
data.capture(swap, backbuffer);
signal_frame_ready();
backbuffer->Release();
}
}
Expand Down Expand Up @@ -291,6 +293,7 @@ hook_present1(IDXGISwapChain1 *swap, UINT sync_interval, UINT flags,

if (backbuffer) {
data.capture(swap, backbuffer);
signal_frame_ready();
backbuffer->Release();
}
}
Expand All @@ -308,6 +311,7 @@ hook_present1(IDXGISwapChain1 *swap, UINT sync_interval, UINT flags,

if (backbuffer) {
data.capture(swap, backbuffer);
signal_frame_ready();
backbuffer->Release();
}
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/win-capture/graphics-hook/gl-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ static void gl_shtex_capture(void)

jimglDXUnlockObjectsNV(data.gl_device, 1, &data.gl_dxobj);

signal_frame_ready();

IDXGISwapChain_Present(data.dxgi_swap, 0, 0);
}

Expand All @@ -648,6 +650,8 @@ static void gl_shmem_capture_copy(int i)
if (buffer) {
data.texture_mapped[i] = true;
shmem_copy_data(i, buffer);

signal_frame_ready();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions plugins/win-capture/graphics-hook/graphics-hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct thread_data {

ipc_pipe_client_t pipe = {0};
HANDLE signal_restart = NULL;
HANDLE signal_frame = NULL;
HANDLE signal_stop = NULL;
HANDLE signal_ready = NULL;
static HANDLE signal_init = NULL;
Expand Down Expand Up @@ -100,6 +101,11 @@ static inline bool init_signals(void)
return false;
}

signal_frame = init_event(EVENT_NEW_FRAME, pid);
if (!signal_frame) {
return false;
}

signal_stop = init_event(EVENT_CAPTURE_STOP, pid);
if (!signal_stop) {
return false;
Expand Down Expand Up @@ -270,6 +276,7 @@ static void free_hook(void)
close_handle(&signal_ready);
close_handle(&signal_stop);
close_handle(&signal_restart);
close_handle(&signal_frame);
close_handle(&dup_hook_mutex);
ipc_pipe_client_free(&pipe);
}
Expand Down
9 changes: 9 additions & 0 deletions plugins/win-capture/graphics-hook/graphics-hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ extern ipc_pipe_client_t pipe;
extern HANDLE signal_restart;
extern HANDLE signal_stop;
extern HANDLE signal_ready;
extern HANDLE signal_frame;
extern HANDLE tex_mutexes[2];
extern char system_path[MAX_PATH];
extern char process_name[MAX_PATH];
Expand Down Expand Up @@ -163,6 +164,14 @@ static inline bool capture_active(void)
return active;
}

static inline void signal_frame_ready()
{
if (!SetEvent(signal_frame)) {
hlog("signal_frame_ready: Failed to signal new frame: %d",
GetLastError());
}
}

/** Called to throttle frames to the desired framerate
*
* @param interval The desired interval between frames (nanoseconds).
Expand Down
4 changes: 3 additions & 1 deletion plugins/win-capture/graphics-hook/vulkan-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,10 @@ static void vk_shtex_capture(struct vk_data *data,
debug_res("QueueSubmit", res);
#endif

if (res == VK_SUCCESS)
if (res == VK_SUCCESS) {
frame_data->cmd_buffer_busy = true;
signal_frame_ready();
}
}

static inline bool valid_rect(struct vk_swap_data *swap)
Expand Down

0 comments on commit 2db38e1

Please sign in to comment.