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:
parent
7cd489d6aa
commit
aac439edb1
Notes:
sideshowbarker
2024-07-17 02:37:08 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/aac439edb1 Pull-request: https://github.com/SerenityOS/serenity/pull/22872 Issue: https://github.com/SerenityOS/serenity/issues/22670 Reviewed-by: https://github.com/awesomekling
2 changed files with 59 additions and 7 deletions
|
@ -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<CGLContextWrapper> 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<CGLContextWrapper>(context);
|
||||
}
|
||||
#else
|
||||
static void make_context_egl()
|
||||
#elif !defined(AK_OS_SERENITY)
|
||||
static NonnullOwnPtr<EGLContextWrapper> 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<EGLContextWrapper>(egl_context);
|
||||
}
|
||||
#endif
|
||||
|
||||
OwnPtr<Context> Context::create()
|
||||
{
|
||||
#ifdef AK_OS_MACOS
|
||||
make_context_cgl();
|
||||
return make_context_cgl();
|
||||
#else
|
||||
make_context_egl();
|
||||
return make_context_egl();
|
||||
#endif
|
||||
|
||||
return make<Context>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,12 @@ public:
|
|||
Context()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Context()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void activate() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue