Commit 6e9018bd by Jonah Ryan-Davis Committed by Commit Bot

GL: Clean up Display code related to multithreading

Rename mCurrentData to mCurrentNativeContexts, and clean up some logic to be easier to read. Bug: angleproject:4724 Change-Id: I6fd6d99d4f9a3af808d0baa665edfbdde7fb0500 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2267424Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
parent 5b8dec52
...@@ -148,6 +148,7 @@ DisplayCGL::DisplayCGL(const egl::DisplayState &state) ...@@ -148,6 +148,7 @@ DisplayCGL::DisplayCGL(const egl::DisplayState &state)
: DisplayGL(state), : DisplayGL(state),
mEGLDisplay(nullptr), mEGLDisplay(nullptr),
mContext(nullptr), mContext(nullptr),
mThreadsWithCurrentContext(),
mPixelFormat(nullptr), mPixelFormat(nullptr),
mSupportsGPUSwitching(false), mSupportsGPUSwitching(false),
mCurrentGPUID(0), mCurrentGPUID(0),
......
...@@ -113,6 +113,7 @@ DisplayEGL::DisplayEGL(const egl::DisplayState &state) ...@@ -113,6 +113,7 @@ DisplayEGL::DisplayEGL(const egl::DisplayState &state)
mRenderer(nullptr), mRenderer(nullptr),
mEGL(nullptr), mEGL(nullptr),
mConfig(EGL_NO_CONFIG_KHR), mConfig(EGL_NO_CONFIG_KHR),
mCurrentNativeContexts(),
mHasEXTCreateContextRobustness(false), mHasEXTCreateContextRobustness(false),
mHasNVRobustnessVideoMemoryPurge(false) mHasNVRobustnessVideoMemoryPurge(false)
{} {}
......
...@@ -74,6 +74,7 @@ DisplayGLX::DisplayGLX(const egl::DisplayState &state) ...@@ -74,6 +74,7 @@ DisplayGLX::DisplayGLX(const egl::DisplayState &state)
mVisuals(nullptr), mVisuals(nullptr),
mContext(nullptr), mContext(nullptr),
mSharedContext(nullptr), mSharedContext(nullptr),
mCurrentNativeContexts(),
mInitPbuffer(0), mInitPbuffer(0),
mUsesNewXDisplay(false), mUsesNewXDisplay(false),
mIsMesa(false), mIsMesa(false),
...@@ -264,7 +265,7 @@ egl::Error DisplayGLX::initialize(egl::Display *display) ...@@ -264,7 +265,7 @@ egl::Error DisplayGLX::initialize(egl::Display *display)
} }
ASSERT(mContext); ASSERT(mContext);
mCurrentContexts[std::this_thread::get_id()] = mContext; mCurrentNativeContexts[std::this_thread::get_id()] = mContext;
// FunctionsGL and DisplayGL need to make a few GL calls, for example to // FunctionsGL and DisplayGL need to make a few GL calls, for example to
// query the version of the context so we need to make the context current. // query the version of the context so we need to make the context current.
...@@ -367,7 +368,7 @@ void DisplayGLX::terminate() ...@@ -367,7 +368,7 @@ void DisplayGLX::terminate()
} }
mWorkerPbufferPool.clear(); mWorkerPbufferPool.clear();
mCurrentContexts.clear(); mCurrentNativeContexts.clear();
if (mContext) if (mContext)
{ {
...@@ -407,14 +408,14 @@ egl::Error DisplayGLX::makeCurrent(egl::Display *display, ...@@ -407,14 +408,14 @@ egl::Error DisplayGLX::makeCurrent(egl::Display *display,
newContext = 0; newContext = 0;
} }
if (newDrawable != mCurrentDrawable || if (newDrawable != mCurrentDrawable ||
newContext != mCurrentContexts[std::this_thread::get_id()]) newContext != mCurrentNativeContexts[std::this_thread::get_id()])
{ {
if (mGLX.makeCurrent(newDrawable, newContext) != True) if (mGLX.makeCurrent(newDrawable, newContext) != True)
{ {
return egl::EglContextLost() << "Failed to make the GLX context current"; return egl::EglContextLost() << "Failed to make the GLX context current";
} }
mCurrentContexts[std::this_thread::get_id()] = newContext; mCurrentNativeContexts[std::this_thread::get_id()] = newContext;
mCurrentDrawable = newDrawable; mCurrentDrawable = newDrawable;
} }
return DisplayGL::makeCurrent(display, drawSurface, readSurface, context); return DisplayGL::makeCurrent(display, drawSurface, readSurface, context);
......
...@@ -126,7 +126,8 @@ class DisplayGLX : public DisplayGL ...@@ -126,7 +126,8 @@ class DisplayGLX : public DisplayGL
XVisualInfo *mVisuals; XVisualInfo *mVisuals;
glx::Context mContext; glx::Context mContext;
glx::Context mSharedContext; glx::Context mSharedContext;
angle::HashMap<std::thread::id, glx::Context> mCurrentContexts; angle::HashMap<std::thread::id, glx::Context> mCurrentNativeContexts;
// A pbuffer the context is current on during ANGLE initialization // A pbuffer the context is current on during ANGLE initialization
glx::Pbuffer mInitPbuffer; glx::Pbuffer mInitPbuffer;
......
...@@ -90,7 +90,7 @@ class FunctionsGLWindows : public FunctionsGL ...@@ -90,7 +90,7 @@ class FunctionsGLWindows : public FunctionsGL
DisplayWGL::DisplayWGL(const egl::DisplayState &state) DisplayWGL::DisplayWGL(const egl::DisplayState &state)
: DisplayGL(state), : DisplayGL(state),
mRenderer(nullptr), mRenderer(nullptr),
mCurrentData(), mCurrentNativeContexts(),
mOpenGLModule(nullptr), mOpenGLModule(nullptr),
mFunctionsWGL(nullptr), mFunctionsWGL(nullptr),
mHasWGLCreateContextRobustness(false), mHasWGLCreateContextRobustness(false),
...@@ -354,7 +354,7 @@ void DisplayWGL::destroy() ...@@ -354,7 +354,7 @@ void DisplayWGL::destroy()
mFunctionsWGL->makeCurrent(mDeviceContext, nullptr); mFunctionsWGL->makeCurrent(mDeviceContext, nullptr);
} }
} }
mCurrentData.clear(); mCurrentNativeContexts.clear();
SafeDelete(mFunctionsWGL); SafeDelete(mFunctionsWGL);
...@@ -678,18 +678,14 @@ egl::Error DisplayWGL::makeCurrent(egl::Display *display, ...@@ -678,18 +678,14 @@ egl::Error DisplayWGL::makeCurrent(egl::Display *display,
egl::Surface *readSurface, egl::Surface *readSurface,
gl::Context *context) gl::Context *context)
{ {
CurrentNativeContext &currentContext = mCurrentData[std::this_thread::get_id()]; CurrentNativeContext &currentContext = mCurrentNativeContexts[std::this_thread::get_id()];
HDC newDC = currentContext.dc; HDC newDC = mDeviceContext;
if (drawSurface) if (drawSurface)
{ {
SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface); SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface);
newDC = drawSurfaceWGL->getDC(); newDC = drawSurfaceWGL->getDC();
} }
else
{
newDC = mDeviceContext;
}
HGLRC newContext = currentContext.glrc; HGLRC newContext = currentContext.glrc;
if (context) if (context)
...@@ -911,7 +907,7 @@ egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererWGL> *outRenderer) ...@@ -911,7 +907,7 @@ egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererWGL> *outRenderer)
{ {
return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current."; return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current.";
} }
CurrentNativeContext &currentContext = mCurrentData[std::this_thread::get_id()]; CurrentNativeContext &currentContext = mCurrentNativeContexts[std::this_thread::get_id()];
currentContext.dc = mDeviceContext; currentContext.dc = mDeviceContext;
currentContext.glrc = context; currentContext.glrc = context;
......
...@@ -118,7 +118,7 @@ class DisplayWGL : public DisplayGL ...@@ -118,7 +118,7 @@ class DisplayWGL : public DisplayGL
HDC dc = nullptr; HDC dc = nullptr;
HGLRC glrc = nullptr; HGLRC glrc = nullptr;
}; };
angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentData; angle::HashMap<std::thread::id, CurrentNativeContext> mCurrentNativeContexts;
HMODULE mOpenGLModule; HMODULE mOpenGLModule;
......
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