1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:37:44 +00:00

LibAccelGfx: Add method to make context active

In the upcoming changes, the AccelGfx context will be used for WebGL, so
we can no longer assume that the WebContent process has a single global
context.
This commit is contained in:
Aliaksandr Kalenik 2024-01-18 20:24:29 +01:00 committed by Andreas Kling
parent 7cd489d6aa
commit aac439edb1
2 changed files with 59 additions and 7 deletions

View file

@ -17,7 +17,51 @@
namespace AccelGfx { namespace AccelGfx {
#ifdef AK_OS_MACOS #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<CGLContextWrapper> make_context_cgl()
{ {
CGLContextObj context = NULL; CGLContextObj context = NULL;
CGLPixelFormatAttribute attributes[4] = { CGLPixelFormatAttribute attributes[4] = {
@ -45,9 +89,11 @@ static void make_context_cgl()
} }
VERIFY(glGetError() == GL_NO_ERROR); VERIFY(glGetError() == GL_NO_ERROR);
return make<CGLContextWrapper>(context);
} }
#else #elif !defined(AK_OS_SERENITY)
static void make_context_egl() static NonnullOwnPtr<EGLContextWrapper> make_context_egl()
{ {
EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); EGLDisplay egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -91,18 +137,18 @@ static void make_context_egl()
dbgln("eglMakeCurrent failed"); dbgln("eglMakeCurrent failed");
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
return make<EGLContextWrapper>(egl_context);
} }
#endif #endif
OwnPtr<Context> Context::create() OwnPtr<Context> Context::create()
{ {
#ifdef AK_OS_MACOS #ifdef AK_OS_MACOS
make_context_cgl(); return make_context_cgl();
#else #else
make_context_egl(); return make_context_egl();
#endif #endif
return make<Context>();
} }
} }

View file

@ -25,6 +25,12 @@ public:
Context() Context()
{ {
} }
virtual ~Context()
{
}
virtual void activate() = 0;
}; };
} }