From db7a627a2e4733d8f60774b7b3894db06a73085a Mon Sep 17 00:00:00 2001 From: James Rowe Date: Mon, 16 Sep 2019 20:34:57 -0600 Subject: [PATCH] Add scope acquire context to simplify MakeCurrent and DoneCurrent calls --- src/core/CMakeLists.txt | 2 ++ src/core/frontend/scope_acquire_context.cpp | 17 +++++++++++++++ src/core/frontend/scope_acquire_context.h | 23 +++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/core/frontend/scope_acquire_context.cpp create mode 100644 src/core/frontend/scope_acquire_context.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3a27d8f81..67167fe5d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -106,6 +106,8 @@ add_library(core STATIC frontend/input.h frontend/mic.h frontend/mic.cpp + frontend/scope_acquire_context.cpp + frontend/scope_acquire_context.h gdbstub/gdbstub.cpp gdbstub/gdbstub.h hle/applets/applet.cpp diff --git a/src/core/frontend/scope_acquire_context.cpp b/src/core/frontend/scope_acquire_context.cpp new file mode 100644 index 000000000..3689483af --- /dev/null +++ b/src/core/frontend/scope_acquire_context.cpp @@ -0,0 +1,17 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/frontend/emu_window.h" +#include "core/frontend/scope_acquire_context.h" + +namespace Frontend { + +ScopeAcquireContext::ScopeAcquireContext(Frontend::GraphicsContext& context) : context{context} { + context.MakeCurrent(); +} +ScopeAcquireContext::~ScopeAcquireContext() { + context.DoneCurrent(); +} + +} // namespace Frontend \ No newline at end of file diff --git a/src/core/frontend/scope_acquire_context.h b/src/core/frontend/scope_acquire_context.h new file mode 100644 index 000000000..12ab61ec6 --- /dev/null +++ b/src/core/frontend/scope_acquire_context.h @@ -0,0 +1,23 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Frontend { + +class GraphicsContext; + +/// Helper class to acquire/release window context within a given scope +class ScopeAcquireContext : NonCopyable { +public: + explicit ScopeAcquireContext(Frontend::GraphicsContext& context); + ~ScopeAcquireContext(); + +private: + Frontend::GraphicsContext& context; +}; + +} // namespace Frontend \ No newline at end of file