frame_dumper: Switch to std::jthread
This commit is contained in:
@ -13,11 +13,6 @@ FrameDumperOpenGL::FrameDumperOpenGL(VideoDumper::Backend& video_dumper_,
|
|||||||
Frontend::EmuWindow& emu_window)
|
Frontend::EmuWindow& emu_window)
|
||||||
: video_dumper(video_dumper_), context(emu_window.CreateSharedContext()) {}
|
: video_dumper(video_dumper_), context(emu_window.CreateSharedContext()) {}
|
||||||
|
|
||||||
FrameDumperOpenGL::~FrameDumperOpenGL() {
|
|
||||||
if (present_thread.joinable())
|
|
||||||
present_thread.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FrameDumperOpenGL::IsDumping() const {
|
bool FrameDumperOpenGL::IsDumping() const {
|
||||||
return video_dumper.IsDumping();
|
return video_dumper.IsDumping();
|
||||||
}
|
}
|
||||||
@ -27,22 +22,21 @@ Layout::FramebufferLayout FrameDumperOpenGL::GetLayout() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FrameDumperOpenGL::StartDumping() {
|
void FrameDumperOpenGL::StartDumping() {
|
||||||
if (present_thread.joinable())
|
present_thread = std::jthread([&](std::stop_token stop_token) {
|
||||||
present_thread.join();
|
PresentLoop(stop_token);
|
||||||
|
});
|
||||||
present_thread = std::thread(&FrameDumperOpenGL::PresentLoop, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameDumperOpenGL::StopDumping() {
|
void FrameDumperOpenGL::StopDumping() {
|
||||||
stop_requested.store(true, std::memory_order_relaxed);
|
present_thread.request_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameDumperOpenGL::PresentLoop() {
|
void FrameDumperOpenGL::PresentLoop(std::stop_token stop_token) {
|
||||||
const auto scope = context->Acquire();
|
const auto scope = context->Acquire();
|
||||||
InitializeOpenGLObjects();
|
InitializeOpenGLObjects();
|
||||||
|
|
||||||
const auto& layout = GetLayout();
|
const auto& layout = GetLayout();
|
||||||
while (!stop_requested.exchange(false)) {
|
while (!stop_token.stop_requested()) {
|
||||||
auto frame = mailbox->TryGetPresentFrame(200);
|
auto frame = mailbox->TryGetPresentFrame(200);
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -29,7 +29,7 @@ class RendererOpenGL;
|
|||||||
class FrameDumperOpenGL {
|
class FrameDumperOpenGL {
|
||||||
public:
|
public:
|
||||||
explicit FrameDumperOpenGL(VideoDumper::Backend& video_dumper, Frontend::EmuWindow& emu_window);
|
explicit FrameDumperOpenGL(VideoDumper::Backend& video_dumper, Frontend::EmuWindow& emu_window);
|
||||||
~FrameDumperOpenGL();
|
~FrameDumperOpenGL() = default;
|
||||||
|
|
||||||
bool IsDumping() const;
|
bool IsDumping() const;
|
||||||
Layout::FramebufferLayout GetLayout() const;
|
Layout::FramebufferLayout GetLayout() const;
|
||||||
@ -41,12 +41,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
void InitializeOpenGLObjects();
|
void InitializeOpenGLObjects();
|
||||||
void CleanupOpenGLObjects();
|
void CleanupOpenGLObjects();
|
||||||
void PresentLoop();
|
void PresentLoop(std::stop_token stop_token);
|
||||||
|
|
||||||
VideoDumper::Backend& video_dumper;
|
VideoDumper::Backend& video_dumper;
|
||||||
std::unique_ptr<Frontend::GraphicsContext> context;
|
std::unique_ptr<Frontend::GraphicsContext> context;
|
||||||
std::thread present_thread;
|
std::jthread present_thread;
|
||||||
std::atomic_bool stop_requested{false};
|
|
||||||
|
|
||||||
// PBOs used to dump frames faster
|
// PBOs used to dump frames faster
|
||||||
std::array<OGLBuffer, 2> pbos;
|
std::array<OGLBuffer, 2> pbos;
|
||||||
|
Reference in New Issue
Block a user