Commit 41b453a4 by Geoff Lang Committed by Commit Bot

WGL: Track current context per thread.

BUG=angleproject:2464 Change-Id: I5cce1f52dc3636478e3e2893f5323345b7f83501 Reviewed-on: https://chromium-review.googlesource.com/1097458 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 1c3a94aa
...@@ -65,8 +65,7 @@ class FunctionsGLWindows : public FunctionsGL ...@@ -65,8 +65,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),
mCurrentDC(nullptr), mCurrentData(),
mCurrentGLRC(nullptr),
mOpenGLModule(nullptr), mOpenGLModule(nullptr),
mFunctionsWGL(nullptr), mFunctionsWGL(nullptr),
mHasWGLCreateContextRobustness(false), mHasWGLCreateContextRobustness(false),
...@@ -329,7 +328,7 @@ void DisplayWGL::destroy() ...@@ -329,7 +328,7 @@ void DisplayWGL::destroy()
mFunctionsWGL->makeCurrent(mDeviceContext, nullptr); mFunctionsWGL->makeCurrent(mDeviceContext, nullptr);
} }
} }
mCurrentDC = nullptr; mCurrentData.clear();
SafeDelete(mFunctionsWGL); SafeDelete(mFunctionsWGL);
...@@ -664,29 +663,31 @@ egl::Error DisplayWGL::makeCurrent(egl::Surface *drawSurface, ...@@ -664,29 +663,31 @@ egl::Error DisplayWGL::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface, egl::Surface *readSurface,
gl::Context *context) gl::Context *context)
{ {
HDC newDC = mCurrentDC; CurrentNativeContext &currentContext = mCurrentData[std::this_thread::get_id()];
HDC newDC = currentContext.dc;
if (drawSurface) if (drawSurface)
{ {
SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface); SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface);
newDC = drawSurfaceWGL->getDC(); newDC = drawSurfaceWGL->getDC();
} }
HGLRC newContext = mCurrentGLRC; HGLRC newContext = currentContext.glrc;
if (context) if (context)
{ {
ContextWGL *contextWGL = GetImplAs<ContextWGL>(context); ContextWGL *contextWGL = GetImplAs<ContextWGL>(context);
newContext = contextWGL->getContext(); newContext = contextWGL->getContext();
} }
if (newDC != mCurrentDC || newContext != mCurrentGLRC) if (newDC != currentContext.dc || newContext != currentContext.glrc)
{ {
if (!mFunctionsWGL->makeCurrent(newDC, newContext)) if (!mFunctionsWGL->makeCurrent(newDC, newContext))
{ {
// TODO(geofflang): What error type here? // TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current."; return egl::EglContextLost() << "Failed to make the WGL context current.";
} }
mCurrentDC = newDC; currentContext.dc = newDC;
mCurrentGLRC = newContext; currentContext.glrc = newContext;
} }
return DisplayGL::makeCurrent(drawSurface, readSurface, context); return DisplayGL::makeCurrent(drawSurface, readSurface, context);
...@@ -851,8 +852,9 @@ egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererWGL> *outRenderer) ...@@ -851,8 +852,9 @@ 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.";
} }
mCurrentDC = mDeviceContext; CurrentNativeContext &currentContext = mCurrentData[std::this_thread::get_id()];
mCurrentGLRC = context; currentContext.dc = mDeviceContext;
currentContext.glrc = context;
std::unique_ptr<FunctionsGL> functionsGL( std::unique_ptr<FunctionsGL> functionsGL(
new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress)); new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress));
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include <GL/wglext.h> #include <GL/wglext.h>
#include <thread>
#include <unordered_map>
namespace rx namespace rx
{ {
...@@ -91,8 +94,12 @@ class DisplayWGL : public DisplayGL ...@@ -91,8 +94,12 @@ class DisplayWGL : public DisplayGL
std::shared_ptr<RendererWGL> mRenderer; std::shared_ptr<RendererWGL> mRenderer;
HDC mCurrentDC; struct CurrentNativeContext
HGLRC mCurrentGLRC; {
HDC dc = nullptr;
HGLRC glrc = nullptr;
};
std::unordered_map<std::thread::id, CurrentNativeContext> mCurrentData;
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