Commit 36ccb695 by Geoff Lang Committed by Commit Bot

Ensure a CGL context is current for WindowSurfaceCGL.

WindowSurfaceCGL does quite a bit of emulation using GL textures and renderbuffers but some of these operations need to happen during EGL functions when there may be no native context current. Add a helper that ensures a context is current for operations that manipulate GL objects. Bug: angleproject:5138 Change-Id: Ic9f87aa26fd178a40510836c3aca8814382f92e5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2456051Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a21ef78c
......@@ -24,6 +24,17 @@ namespace rx
class WorkerContext;
struct EnsureCGLContextIsCurrent : angle::NonCopyable
{
public:
EnsureCGLContextIsCurrent(CGLContextObj context);
~EnsureCGLContextIsCurrent();
private:
CGLContextObj mOldContext;
bool mResetContext;
};
class DisplayCGL : public DisplayGL
{
public:
......
......@@ -110,6 +110,23 @@ static void SetGPUByRegistryID(CGLContextObj contextObj,
} // anonymous namespace
EnsureCGLContextIsCurrent::EnsureCGLContextIsCurrent(CGLContextObj context)
: mOldContext(CGLGetCurrentContext()), mResetContext(mOldContext != context)
{
if (mResetContext)
{
CGLSetCurrentContext(context);
}
}
EnsureCGLContextIsCurrent::~EnsureCGLContextIsCurrent()
{
if (mResetContext)
{
CGLSetCurrentContext(mOldContext);
}
}
class FunctionsGLCGL : public FunctionsGL
{
public:
......
......@@ -164,11 +164,13 @@ WindowSurfaceCGL::WindowSurfaceCGL(const egl::SurfaceState &state,
WindowSurfaceCGL::~WindowSurfaceCGL()
{
EnsureCGLContextIsCurrent ensureContextCurrent(mContext);
pthread_mutex_destroy(&mSwapState.mutex);
if (mDSRenderbuffer != 0)
{
mFunctions->deleteRenderbuffers(1, &mDSRenderbuffer);
mStateManager->deleteRenderbuffer(mDSRenderbuffer);
mDSRenderbuffer = 0;
}
......@@ -183,7 +185,7 @@ WindowSurfaceCGL::~WindowSurfaceCGL()
{
if (mSwapState.textures[i].texture != 0)
{
mFunctions->deleteTextures(1, &mSwapState.textures[i].texture);
mStateManager->deleteTexture(mSwapState.textures[i].texture);
mSwapState.textures[i].texture = 0;
}
}
......@@ -191,6 +193,8 @@ WindowSurfaceCGL::~WindowSurfaceCGL()
egl::Error WindowSurfaceCGL::initialize(const egl::Display *display)
{
EnsureCGLContextIsCurrent ensureContextCurrent(mContext);
unsigned width = getWidth();
unsigned height = getHeight();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment