Commit 1c3a94aa by Geoff Lang Committed by Commit Bot

WGL: Update the Renderer to own the native GL context.

Adds a RendererWGL which owns the native WGL GL context. Adds a ContextWGL which owns the RendererWGL and communicates the native WGL context back to DisplayWGL for making current. BUG=angleproject:2464 Change-Id: Ideb11c164da2c304f860c544a56450d0ad8fafac Reviewed-on: https://chromium-review.googlesource.com/1038131 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent d3ab3078
......@@ -45,7 +45,7 @@ class RendererGL : angle::NonCopyable
{
public:
RendererGL(std::unique_ptr<FunctionsGL> functions, const egl::AttributeMap &attribMap);
~RendererGL();
virtual ~RendererGL();
gl::Error flush();
gl::Error finish();
......
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "libANGLE/renderer/gl/wgl/ContextWGL.h"
namespace rx
{
ContextWGL::ContextWGL(const gl::ContextState &state, const std::shared_ptr<RendererWGL> &renderer)
: ContextGL(state, renderer), mRenderer(renderer)
{
}
ContextWGL::~ContextWGL()
{
}
HGLRC ContextWGL::getContext() const
{
return mRenderer->getContext();
}
}
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ContextWGL.h: Context class for GL on Windows. Wraps a RendererWGL.
#ifndef LIBANGLE_RENDERER_GL_WGL_CONTEXTWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_CONTEXTWGL_H_
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/wgl/RendererWGL.h"
namespace rx
{
class ContextWGL : public ContextGL
{
public:
ContextWGL(const gl::ContextState &state, const std::shared_ptr<RendererWGL> &renderer);
~ContextWGL() override;
HGLRC getContext() const;
private:
std::shared_ptr<RendererWGL> mRenderer;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_WGL_RENDERERWGL_H_
......@@ -10,15 +10,18 @@
#include "common/debug.h"
#include "libANGLE/Config.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/renderergl_utils.h"
#include "libANGLE/renderer/gl/wgl/ContextWGL.h"
#include "libANGLE/renderer/gl/wgl/D3DTextureSurfaceWGL.h"
#include "libANGLE/renderer/gl/wgl/DXGISwapChainWindowSurfaceWGL.h"
#include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
#include "libANGLE/renderer/gl/wgl/PbufferSurfaceWGL.h"
#include "libANGLE/renderer/gl/wgl/RendererWGL.h"
#include "libANGLE/renderer/gl/wgl/WindowSurfaceWGL.h"
#include "libANGLE/renderer/gl/wgl/wgl_utils.h"
......@@ -63,6 +66,7 @@ DisplayWGL::DisplayWGL(const egl::DisplayState &state)
: DisplayGL(state),
mRenderer(nullptr),
mCurrentDC(nullptr),
mCurrentGLRC(nullptr),
mOpenGLModule(nullptr),
mFunctionsWGL(nullptr),
mHasWGLCreateContextRobustness(false),
......@@ -71,7 +75,6 @@ DisplayWGL::DisplayWGL(const egl::DisplayState &state)
mWindow(nullptr),
mDeviceContext(nullptr),
mPixelFormat(0),
mWGLContext(nullptr),
mUseDXGISwapChains(false),
mHasDXInterop(false),
mDxgiModule(nullptr),
......@@ -248,7 +251,7 @@ egl::Error DisplayWGL::initializeImpl(egl::Display *display)
<< "Failed to set the pixel format on the intermediate OpenGL window.";
}
ANGLE_TRY(createRenderer(&mRenderer, &mWGLContext));
ANGLE_TRY(createRenderer(&mRenderer));
const FunctionsGL *functionsGL = mRenderer->getFunctions();
mHasRobustness = functionsGL->getGraphicsResetStatus != nullptr;
......@@ -317,22 +320,18 @@ void DisplayWGL::destroy()
{
releaseD3DDevice(mD3D11DeviceHandle);
mRenderer.reset();
if (mFunctionsWGL)
{
if (mDeviceContext)
{
mFunctionsWGL->makeCurrent(mDeviceContext, nullptr);
}
if (mWGLContext)
{
mFunctionsWGL->deleteContext(mWGLContext);
}
}
mCurrentDC = nullptr;
mWGLContext = nullptr;
SafeDelete(mFunctionsWGL);
mRenderer.reset();
if (mDeviceContext)
{
......@@ -441,7 +440,7 @@ SurfaceImpl *DisplayWGL::createPixmapSurface(const egl::SurfaceState &state,
ContextImpl *DisplayWGL::createContext(const gl::ContextState &state)
{
return new ContextGL(state, mRenderer);
return new ContextWGL(state, mRenderer);
}
DeviceImpl *DisplayWGL::createDevice()
......@@ -665,19 +664,29 @@ egl::Error DisplayWGL::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context)
{
HDC newDC = mCurrentDC;
if (drawSurface)
{
SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface);
HDC dc = drawSurfaceWGL->getDC();
if (dc != mCurrentDC)
newDC = drawSurfaceWGL->getDC();
}
HGLRC newContext = mCurrentGLRC;
if (context)
{
ContextWGL *contextWGL = GetImplAs<ContextWGL>(context);
newContext = contextWGL->getContext();
}
if (newDC != mCurrentDC || newContext != mCurrentGLRC)
{
if (!mFunctionsWGL->makeCurrent(newDC, newContext))
{
if (!mFunctionsWGL->makeCurrent(dc, mWGLContext))
{
// TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
mCurrentDC = dc;
// TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
mCurrentDC = newDC;
mCurrentGLRC = newContext;
}
return DisplayGL::makeCurrent(drawSurface, readSurface, context);
......@@ -736,6 +745,11 @@ gl::Version DisplayWGL::getMaxSupportedESVersion() const
return mRenderer->getMaxSupportedESVersion();
}
void DisplayWGL::destroyNativeContext(HGLRC context)
{
mFunctionsWGL->deleteContext(context);
}
HGLRC DisplayWGL::initializeContextAttribs(const egl::AttributeMap &eglAttributes) const
{
EGLint requestedDisplayType = static_cast<EGLint>(
......@@ -812,7 +826,7 @@ HGLRC DisplayWGL::createContextAttribs(const gl::Version &version, int profileMa
return mFunctionsWGL->createContextAttribsARB(mDeviceContext, nullptr, &attribs[0]);
}
egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererGL> *outRenderer, HGLRC *outContext)
egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererWGL> *outRenderer)
{
HGLRC context = nullptr;
if (mFunctionsWGL->createContextAttribsARB)
......@@ -838,13 +852,13 @@ egl::Error DisplayWGL::createRenderer(std::shared_ptr<RendererGL> *outRenderer,
return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current.";
}
mCurrentDC = mDeviceContext;
mCurrentGLRC = context;
std::unique_ptr<FunctionsGL> functionsGL(
new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress));
functionsGL->initialize(mDisplayAttributes);
outRenderer->reset(new RendererGL(std::move(functionsGL), mDisplayAttributes));
*outContext = context;
outRenderer->reset(new RendererWGL(std::move(functionsGL), mDisplayAttributes, this, context));
return egl::NoError();
}
......
......@@ -17,6 +17,7 @@ namespace rx
{
class FunctionsWGL;
class RendererWGL;
class DisplayWGL : public DisplayGL
{
......@@ -70,6 +71,8 @@ class DisplayWGL : public DisplayGL
gl::Version getMaxSupportedESVersion() const override;
void destroyNativeContext(HGLRC context);
private:
egl::Error initializeImpl(egl::Display *display);
void destroy();
......@@ -84,11 +87,12 @@ class DisplayWGL : public DisplayGL
HGLRC initializeContextAttribs(const egl::AttributeMap &eglAttributes) const;
HGLRC createContextAttribs(const gl::Version &version, int profileMask) const;
egl::Error createRenderer(std::shared_ptr<RendererGL> *outRenderer, HGLRC *outContext);
egl::Error createRenderer(std::shared_ptr<RendererWGL> *outRenderer);
std::shared_ptr<RendererGL> mRenderer;
std::shared_ptr<RendererWGL> mRenderer;
HDC mCurrentDC;
HGLRC mCurrentGLRC;
HMODULE mOpenGLModule;
......@@ -103,7 +107,6 @@ class DisplayWGL : public DisplayGL
HWND mWindow;
HDC mDeviceContext;
int mPixelFormat;
HGLRC mWGLContext;
bool mUseDXGISwapChains;
bool mHasDXInterop;
......
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "libANGLE/renderer/gl/wgl/RendererWGL.h"
#include "libANGLE/renderer/gl/wgl/DisplayWGL.h"
namespace rx
{
RendererWGL::RendererWGL(std::unique_ptr<FunctionsGL> functionsGL,
const egl::AttributeMap &attribMap,
DisplayWGL *display,
HGLRC context)
: RendererGL(std::move(functionsGL), attribMap), mDisplay(display), mContext(context)
{
}
RendererWGL::~RendererWGL()
{
mDisplay->destroyNativeContext(mContext);
mContext = nullptr;
}
HGLRC RendererWGL::getContext() const
{
return mContext;
}
} // namespace rx
//
// Copyright (c) 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RendererWGL.h: Renderer class for GL on Windows. Owns a WGL context object.
#ifndef LIBANGLE_RENDERER_GL_WGL_RENDERERWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_RENDERERWGL_H_
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/wgl/FunctionsWGL.h"
namespace rx
{
class DisplayWGL;
class RendererWGL : public RendererGL
{
public:
RendererWGL(std::unique_ptr<FunctionsGL> functionsGL,
const egl::AttributeMap &attribMap,
DisplayWGL *display,
HGLRC context);
~RendererWGL() override;
HGLRC getContext() const;
private:
DisplayWGL *mDisplay;
HGLRC mContext;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_WGL_RENDERERWGL_H_
......@@ -677,6 +677,8 @@
],
'libangle_gl_wgl_sources':
[
'libANGLE/renderer/gl/wgl/ContextWGL.cpp',
'libANGLE/renderer/gl/wgl/ContextWGL.h',
'libANGLE/renderer/gl/wgl/D3DTextureSurfaceWGL.cpp',
'libANGLE/renderer/gl/wgl/D3DTextureSurfaceWGL.h',
'libANGLE/renderer/gl/wgl/DisplayWGL.cpp',
......@@ -687,6 +689,8 @@
'libANGLE/renderer/gl/wgl/FunctionsWGL.h',
'libANGLE/renderer/gl/wgl/PbufferSurfaceWGL.cpp',
'libANGLE/renderer/gl/wgl/PbufferSurfaceWGL.h',
'libANGLE/renderer/gl/wgl/RendererWGL.cpp',
'libANGLE/renderer/gl/wgl/RendererWGL.h',
'libANGLE/renderer/gl/wgl/SurfaceWGL.h',
'libANGLE/renderer/gl/wgl/WindowSurfaceWGL.cpp',
'libANGLE/renderer/gl/wgl/WindowSurfaceWGL.h',
......
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