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
DisplayWGL::DisplayWGL(const egl::DisplayState &state)
: DisplayGL(state),
mRenderer(nullptr),
mCurrentDC(nullptr),
mCurrentGLRC(nullptr),
mCurrentData(),
mOpenGLModule(nullptr),
mFunctionsWGL(nullptr),
mHasWGLCreateContextRobustness(false),
......@@ -329,7 +328,7 @@ void DisplayWGL::destroy()
mFunctionsWGL->makeCurrent(mDeviceContext, nullptr);
}
}
mCurrentDC = nullptr;
mCurrentData.clear();
SafeDelete(mFunctionsWGL);
......@@ -664,29 +663,31 @@ egl::Error DisplayWGL::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context)
{
HDC newDC = mCurrentDC;
CurrentNativeContext &currentContext = mCurrentData[std::this_thread::get_id()];
HDC newDC = currentContext.dc;
if (drawSurface)
{
SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface);
newDC = drawSurfaceWGL->getDC();
}
HGLRC newContext = mCurrentGLRC;
HGLRC newContext = currentContext.glrc;
if (context)
{
ContextWGL *contextWGL = GetImplAs<ContextWGL>(context);
newContext = contextWGL->getContext();
}
if (newDC != mCurrentDC || newContext != mCurrentGLRC)
if (newDC != currentContext.dc || newContext != currentContext.glrc)
{
if (!mFunctionsWGL->makeCurrent(newDC, newContext))
{
// TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
mCurrentDC = newDC;
mCurrentGLRC = newContext;
currentContext.dc = newDC;
currentContext.glrc = newContext;
}
return DisplayGL::makeCurrent(drawSurface, readSurface, context);
......@@ -851,8 +852,9 @@ egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererWGL> *outRenderer)
{
return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current.";
}
mCurrentDC = mDeviceContext;
mCurrentGLRC = context;
CurrentNativeContext &currentContext = mCurrentData[std::this_thread::get_id()];
currentContext.dc = mDeviceContext;
currentContext.glrc = context;
std::unique_ptr<FunctionsGL> functionsGL(
new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress));
......
......@@ -13,6 +13,9 @@
#include <GL/wglext.h>
#include <thread>
#include <unordered_map>
namespace rx
{
......@@ -91,8 +94,12 @@ class DisplayWGL : public DisplayGL
std::shared_ptr<RendererWGL> mRenderer;
HDC mCurrentDC;
HGLRC mCurrentGLRC;
struct CurrentNativeContext
{
HDC dc = nullptr;
HGLRC glrc = nullptr;
};
std::unordered_map<std::thread::id, CurrentNativeContext> mCurrentData;
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