diff --git a/Userland/Libraries/LibAccelGfx/Context.cpp b/Userland/Libraries/LibAccelGfx/Context.cpp index f06e3f264f..b389f76fcc 100644 --- a/Userland/Libraries/LibAccelGfx/Context.cpp +++ b/Userland/Libraries/LibAccelGfx/Context.cpp @@ -17,7 +17,51 @@ namespace AccelGfx { #ifdef AK_OS_MACOS -static void make_context_cgl() +class CGLContextWrapper : public Context { +public: + CGLContextWrapper(CGLContextObj context) + : m_context(context) + { + } + + virtual void activate() override + { + CGLSetCurrentContext(m_context); + } + + ~CGLContextWrapper() + { + CGLReleaseContext(m_context); + } + +private: + CGLContextObj m_context; +}; +#elif !defined(AK_OS_SERENITY) +class EGLContextWrapper : public Context { +public: + EGLContextWrapper(EGLContext context) + : m_context(context) + { + } + + ~EGLContextWrapper() + { + eglDestroyContext(eglGetCurrentDisplay(), m_context); + } + + virtual void activate() override + { + eglMakeCurrent(eglGetCurrentDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, m_context); + } + +private: + EGLContext m_context; +}; +#endif + +#ifdef AK_OS_MACOS +static NonnullOwnPtr make_context_cgl() { CGLContextObj context = NULL; CGLPixelFormatAttribute attributes[4] = { @@ -45,9 +89,11 @@ static void make_context_cgl() } VERIFY(glGetError() == GL_NO_ERROR); + + return make(context); } -#else -static void make_context_egl() +#elif !defined(AK_OS_SERENITY) +static NonnullOwnPtr make_context_egl() { EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); @@ -91,18 +137,18 @@ static void make_context_egl() dbgln("eglMakeCurrent failed"); VERIFY_NOT_REACHED(); } + + return make(egl_context); } #endif OwnPtr Context::create() { #ifdef AK_OS_MACOS - make_context_cgl(); + return make_context_cgl(); #else - make_context_egl(); + return make_context_egl(); #endif - - return make(); } } diff --git a/Userland/Libraries/LibAccelGfx/Context.h b/Userland/Libraries/LibAccelGfx/Context.h index cdfff72da5..bfbe8b61c3 100644 --- a/Userland/Libraries/LibAccelGfx/Context.h +++ b/Userland/Libraries/LibAccelGfx/Context.h @@ -25,6 +25,12 @@ public: Context() { } + + virtual ~Context() + { + } + + virtual void activate() = 0; }; }