Commit 665e4d97 by Geoff Lang Committed by Commit Bot

Perform all wglMakeCurrent calls from DisplayWGL.

Display WGL is the best place to track the currently bound surfaces and contexts and cache them appropriately. This results in a ~40% speed increase in the WebGL Aqarium demo because wglMakeCurrent is now only called once at initialization. BUG=angleproject:1651 Change-Id: I61132bb4a0db8de592600173c20787c67d18e067 Reviewed-on: https://chromium-review.googlesource.com/543583 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 579d8c7d
......@@ -215,12 +215,11 @@ D3DTextureSurfaceWGL::D3DTextureSurfaceWGL(const egl::SurfaceState &state,
EGLenum buftype,
EGLClientBuffer clientBuffer,
DisplayWGL *display,
HGLRC wglContext,
HDC deviceContext,
ID3D11Device *displayD3D11Device,
const FunctionsGL *functionsGL,
const FunctionsWGL *functionsWGL)
: SurfaceGL(state, renderer),
: SurfaceWGL(state, renderer),
mBuftype(buftype),
mClientBuffer(clientBuffer),
mRenderer(renderer),
......@@ -230,7 +229,6 @@ D3DTextureSurfaceWGL::D3DTextureSurfaceWGL(const egl::SurfaceState &state,
mWorkarounds(renderer->getWorkarounds()),
mFunctionsGL(functionsGL),
mFunctionsWGL(functionsWGL),
mWGLContext(wglContext),
mDeviceContext(deviceContext),
mWidth(0),
mHeight(0),
......@@ -341,12 +339,6 @@ egl::Error D3DTextureSurfaceWGL::initialize(const egl::Display *display)
egl::Error D3DTextureSurfaceWGL::makeCurrent()
{
if (!mFunctionsWGL->makeCurrent(mDeviceContext, mWGLContext))
{
// TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
if (!mFunctionsWGL->dxLockObjectsNV(mDeviceHandle, 1, &mBoundObjectRenderbufferHandle))
{
DWORD error = GetLastError();
......@@ -476,4 +468,10 @@ FramebufferImpl *D3DTextureSurfaceWGL::createDefaultFramebuffer(const gl::Frameb
return new FramebufferGL(mFramebufferID, data, mFunctionsGL, mWorkarounds,
mRenderer->getBlitter(), mStateManager);
}
HDC D3DTextureSurfaceWGL::getDC() const
{
return mDeviceContext;
}
} // namespace rx
......@@ -9,7 +9,7 @@
#ifndef LIBANGLE_RENDERER_GL_WGL_D3DTEXTIRESURFACEWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_D3DTEXTIRESURFACEWGL_H_
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/wgl/SurfaceWGL.h"
#include <GL/wglext.h>
......@@ -22,7 +22,7 @@ class DisplayWGL;
class StateManagerGL;
struct WorkaroundsGL;
class D3DTextureSurfaceWGL : public SurfaceGL
class D3DTextureSurfaceWGL : public SurfaceWGL
{
public:
D3DTextureSurfaceWGL(const egl::SurfaceState &state,
......@@ -30,7 +30,6 @@ class D3DTextureSurfaceWGL : public SurfaceGL
EGLenum buftype,
EGLClientBuffer clientBuffer,
DisplayWGL *display,
HGLRC wglContext,
HDC deviceContext,
ID3D11Device *displayD3D11Device,
const FunctionsGL *functionsGL,
......@@ -64,6 +63,8 @@ class D3DTextureSurfaceWGL : public SurfaceGL
FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &data) override;
HDC getDC() const override;
private:
EGLenum mBuftype;
EGLClientBuffer mClientBuffer;
......@@ -78,7 +79,6 @@ class D3DTextureSurfaceWGL : public SurfaceGL
const FunctionsGL *mFunctionsGL;
const FunctionsWGL *mFunctionsWGL;
HGLRC mWGLContext;
HDC mDeviceContext;
size_t mWidth;
......
......@@ -27,12 +27,11 @@ DXGISwapChainWindowSurfaceWGL::DXGISwapChainWindowSurfaceWGL(const egl::SurfaceS
EGLNativeWindowType window,
ID3D11Device *device,
HANDLE deviceHandle,
HGLRC wglContext,
HDC deviceContext,
const FunctionsGL *functionsGL,
const FunctionsWGL *functionsWGL,
EGLint orientation)
: SurfaceGL(state, renderer),
: SurfaceWGL(state, renderer),
mWindow(window),
mStateManager(renderer->getStateManager()),
mWorkarounds(renderer->getWorkarounds()),
......@@ -42,7 +41,6 @@ DXGISwapChainWindowSurfaceWGL::DXGISwapChainWindowSurfaceWGL(const egl::SurfaceS
mDevice(device),
mDeviceHandle(deviceHandle),
mWGLDevice(deviceContext),
mWGLContext(wglContext),
mSwapChainFormat(DXGI_FORMAT_UNKNOWN),
mSwapChainFlags(0),
mDepthBufferFormat(GL_NONE),
......@@ -118,12 +116,6 @@ egl::Error DXGISwapChainWindowSurfaceWGL::initialize(const egl::Display *display
egl::Error DXGISwapChainWindowSurfaceWGL::makeCurrent()
{
if (!mFunctionsWGL->makeCurrent(mWGLDevice, mWGLContext))
{
// TODO: What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
return egl::NoError();
}
......@@ -281,6 +273,11 @@ FramebufferImpl *DXGISwapChainWindowSurfaceWGL::createDefaultFramebuffer(
mRenderer->getBlitter(), mStateManager);
}
HDC DXGISwapChainWindowSurfaceWGL::getDC() const
{
return mWGLDevice;
}
egl::Error DXGISwapChainWindowSurfaceWGL::setObjectsLocked(bool locked)
{
if (mRenderbufferBufferHandle == nullptr)
......
......@@ -10,7 +10,7 @@
#ifndef LIBANGLE_RENDERER_GL_WGL_DXGISWAPCHAINSURFACEWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_DXGISWAPCHAINSURFACEWGL_H_
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/wgl/SurfaceWGL.h"
#include <GL/wglext.h>
......@@ -23,7 +23,7 @@ class DisplayWGL;
class StateManagerGL;
struct WorkaroundsGL;
class DXGISwapChainWindowSurfaceWGL : public SurfaceGL
class DXGISwapChainWindowSurfaceWGL : public SurfaceWGL
{
public:
DXGISwapChainWindowSurfaceWGL(const egl::SurfaceState &state,
......@@ -31,7 +31,6 @@ class DXGISwapChainWindowSurfaceWGL : public SurfaceGL
EGLNativeWindowType window,
ID3D11Device *device,
HANDLE deviceHandle,
HGLRC wglContext,
HDC deviceContext,
const FunctionsGL *functionsGL,
const FunctionsWGL *functionsWGL,
......@@ -60,6 +59,8 @@ class DXGISwapChainWindowSurfaceWGL : public SurfaceGL
FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &data) override;
HDC getDC() const override;
private:
egl::Error setObjectsLocked(bool locked);
egl::Error checkForResize();
......@@ -78,7 +79,6 @@ class DXGISwapChainWindowSurfaceWGL : public SurfaceGL
HANDLE mDeviceHandle;
HDC mWGLDevice;
HGLRC mWGLContext;
DXGI_FORMAT mSwapChainFormat;
UINT mSwapChainFlags;
......
......@@ -60,6 +60,7 @@ class FunctionsGLWindows : public FunctionsGL
DisplayWGL::DisplayWGL(const egl::DisplayState &state)
: DisplayGL(state),
mCurrentDC(nullptr),
mOpenGLModule(nullptr),
mFunctionsWGL(nullptr),
mFunctionsGL(nullptr),
......@@ -270,6 +271,7 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
{
return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current.";
}
mCurrentDC = mDeviceContext;
mFunctionsGL = new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress);
mFunctionsGL->initialize();
......@@ -331,6 +333,7 @@ void DisplayWGL::terminate()
releaseD3DDevice(mD3D11DeviceHandle);
mFunctionsWGL->makeCurrent(mDeviceContext, nullptr);
mCurrentDC = nullptr;
mFunctionsWGL->deleteContext(mWGLContext);
mWGLContext = nullptr;
......@@ -380,13 +383,13 @@ SurfaceImpl *DisplayWGL::createWindowSurface(const egl::SurfaceState &state,
}
return new DXGISwapChainWindowSurfaceWGL(state, getRenderer(), window, mD3D11Device,
mD3D11DeviceHandle, mWGLContext, mDeviceContext,
mFunctionsGL, mFunctionsWGL, orientation);
mD3D11DeviceHandle, mDeviceContext, mFunctionsGL,
mFunctionsWGL, orientation);
}
else
{
return new WindowSurfaceWGL(state, getRenderer(), window, mPixelFormat, mWGLContext,
mFunctionsWGL, orientation);
return new WindowSurfaceWGL(state, getRenderer(), window, mPixelFormat, mFunctionsWGL,
orientation);
}
}
......@@ -400,7 +403,7 @@ SurfaceImpl *DisplayWGL::createPbufferSurface(const egl::SurfaceState &state,
EGLenum textureTarget = static_cast<EGLenum>(attribs.get(EGL_TEXTURE_TARGET, EGL_NO_TEXTURE));
return new PbufferSurfaceWGL(state, getRenderer(), width, height, textureFormat, textureTarget,
largest, mPixelFormat, mDeviceContext, mWGLContext, mFunctionsWGL);
largest, mPixelFormat, mDeviceContext, mFunctionsWGL);
}
SurfaceImpl *DisplayWGL::createPbufferFromClientBuffer(const egl::SurfaceState &state,
......@@ -414,7 +417,7 @@ SurfaceImpl *DisplayWGL::createPbufferFromClientBuffer(const egl::SurfaceState &
return nullptr;
}
return new D3DTextureSurfaceWGL(state, getRenderer(), buftype, clientBuffer, this, mWGLContext,
return new D3DTextureSurfaceWGL(state, getRenderer(), buftype, clientBuffer, this,
mDeviceContext, mD3D11Device, mFunctionsGL, mFunctionsWGL);
}
......@@ -645,6 +648,28 @@ egl::Error DisplayWGL::waitNative(const gl::Context *context, EGLint engine) con
return egl::NoError();
}
egl::Error DisplayWGL::makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context)
{
if (drawSurface)
{
SurfaceWGL *drawSurfaceWGL = GetImplAs<SurfaceWGL>(drawSurface);
HDC dc = drawSurfaceWGL->getDC();
if (dc != mCurrentDC)
{
if (!mFunctionsWGL->makeCurrent(dc, mWGLContext))
{
// TODO(geofflang): What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
mCurrentDC = dc;
}
}
return DisplayGL::makeCurrent(drawSurface, readSurface, context);
}
egl::Error DisplayWGL::registerD3DDevice(IUnknown *device, HANDLE *outHandle)
{
ASSERT(device != nullptr);
......
......@@ -59,6 +59,10 @@ class DisplayWGL : public DisplayGL
egl::Error waitClient(const gl::Context *context) const override;
egl::Error waitNative(const gl::Context *context, EGLint engine) const override;
egl::Error makeCurrent(egl::Surface *drawSurface,
egl::Surface *readSurface,
gl::Context *context) override;
egl::Error registerD3DDevice(IUnknown *device, HANDLE *outHandle);
void releaseD3DDevice(HANDLE handle);
......@@ -75,6 +79,8 @@ class DisplayWGL : public DisplayGL
HGLRC initializeContextAttribs(const egl::AttributeMap &eglAttributes) const;
HGLRC createContextAttribs(const gl::Version &version, int profileMask) const;
HDC mCurrentDC;
HMODULE mOpenGLModule;
FunctionsWGL *mFunctionsWGL;
......
......@@ -25,16 +25,14 @@ PbufferSurfaceWGL::PbufferSurfaceWGL(const egl::SurfaceState &state,
bool largest,
int pixelFormat,
HDC deviceContext,
HGLRC wglContext,
const FunctionsWGL *functions)
: SurfaceGL(state, renderer),
: SurfaceWGL(state, renderer),
mWidth(width),
mHeight(height),
mLargest(largest),
mTextureFormat(textureFormat),
mTextureTarget(textureTarget),
mPixelFormat(pixelFormat),
mShareWGLContext(wglContext),
mParentDeviceContext(deviceContext),
mPbuffer(nullptr),
mPbufferDeviceContext(nullptr),
......@@ -116,12 +114,6 @@ egl::Error PbufferSurfaceWGL::initialize(const egl::Display *display)
egl::Error PbufferSurfaceWGL::makeCurrent()
{
if (!mFunctionsWGL->makeCurrent(mPbufferDeviceContext, mShareWGLContext))
{
// TODO: What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
return egl::NoError();
}
......@@ -202,4 +194,8 @@ EGLint PbufferSurfaceWGL::getSwapBehavior() const
return EGL_BUFFER_PRESERVED;
}
HDC PbufferSurfaceWGL::getDC() const
{
return mPbufferDeviceContext;
}
}
......@@ -9,7 +9,7 @@
#ifndef LIBANGLE_RENDERER_GL_WGL_PBUFFERSURFACEWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_PBUFFERSURFACEWGL_H_
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/wgl/SurfaceWGL.h"
#include <GL/wglext.h>
......@@ -18,7 +18,7 @@ namespace rx
class FunctionsWGL;
class PbufferSurfaceWGL : public SurfaceGL
class PbufferSurfaceWGL : public SurfaceWGL
{
public:
PbufferSurfaceWGL(const egl::SurfaceState &state,
......@@ -30,7 +30,6 @@ class PbufferSurfaceWGL : public SurfaceGL
bool largest,
int pixelFormat,
HDC deviceContext,
HGLRC wglContext,
const FunctionsWGL *functions);
~PbufferSurfaceWGL() override;
......@@ -54,6 +53,8 @@ class PbufferSurfaceWGL : public SurfaceGL
EGLint isPostSubBufferSupported() const override;
EGLint getSwapBehavior() const override;
HDC getDC() const override;
private:
EGLint mWidth;
EGLint mHeight;
......@@ -63,8 +64,6 @@ class PbufferSurfaceWGL : public SurfaceGL
int mPixelFormat;
HGLRC mShareWGLContext;
HDC mParentDeviceContext;
HPBUFFERARB mPbuffer;
......
//
// Copyright (c) 2017 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.
//
// SurfaceWGL.h: Base class for WGL surface types
#ifndef LIBANGLE_RENDERER_GL_WGL_SURFACEWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_SURFACEWGL_H_
#include "libANGLE/renderer/gl/SurfaceGL.h"
namespace rx
{
class SurfaceWGL : public SurfaceGL
{
public:
SurfaceWGL(const egl::SurfaceState &state, RendererGL *renderer) : SurfaceGL(state, renderer) {}
~SurfaceWGL() override {}
virtual HDC getDC() const = 0;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_GL_WGL_SURFACEWGL_H_
......@@ -20,12 +20,10 @@ WindowSurfaceWGL::WindowSurfaceWGL(const egl::SurfaceState &state,
RendererGL *renderer,
EGLNativeWindowType window,
int pixelFormat,
HGLRC wglContext,
const FunctionsWGL *functions,
EGLint orientation)
: SurfaceGL(state, renderer),
: SurfaceWGL(state, renderer),
mPixelFormat(pixelFormat),
mWGLContext(wglContext),
mWindow(window),
mDeviceContext(nullptr),
mFunctionsWGL(functions),
......@@ -95,12 +93,6 @@ egl::Error WindowSurfaceWGL::initialize(const egl::Display *display)
egl::Error WindowSurfaceWGL::makeCurrent()
{
if (!mFunctionsWGL->makeCurrent(mDeviceContext, mWGLContext))
{
// TODO: What error type here?
return egl::EglContextLost() << "Failed to make the WGL context current.";
}
return egl::NoError();
}
......@@ -183,4 +175,8 @@ EGLint WindowSurfaceWGL::getSwapBehavior() const
return mSwapBehavior;
}
HDC WindowSurfaceWGL::getDC() const
{
return mDeviceContext;
}
}
......@@ -9,7 +9,7 @@
#ifndef LIBANGLE_RENDERER_GL_WGL_WINDOWSURFACEWGL_H_
#define LIBANGLE_RENDERER_GL_WGL_WINDOWSURFACEWGL_H_
#include "libANGLE/renderer/gl/SurfaceGL.h"
#include "libANGLE/renderer/gl/wgl/SurfaceWGL.h"
#include <GL/wglext.h>
......@@ -18,14 +18,13 @@ namespace rx
class FunctionsWGL;
class WindowSurfaceWGL : public SurfaceGL
class WindowSurfaceWGL : public SurfaceWGL
{
public:
WindowSurfaceWGL(const egl::SurfaceState &state,
RendererGL *renderer,
EGLNativeWindowType window,
int pixelFormat,
HGLRC wglContext,
const FunctionsWGL *functions,
EGLint orientation);
~WindowSurfaceWGL() override;
......@@ -50,11 +49,11 @@ class WindowSurfaceWGL : public SurfaceGL
EGLint isPostSubBufferSupported() const override;
EGLint getSwapBehavior() const override;
HDC getDC() const override;
private:
int mPixelFormat;
HGLRC mWGLContext;
HWND mWindow;
HDC mDeviceContext;
......
......@@ -588,6 +588,7 @@
'libANGLE/renderer/gl/wgl/FunctionsWGL.h',
'libANGLE/renderer/gl/wgl/PbufferSurfaceWGL.cpp',
'libANGLE/renderer/gl/wgl/PbufferSurfaceWGL.h',
'libANGLE/renderer/gl/wgl/SurfaceWGL.h',
'libANGLE/renderer/gl/wgl/WindowSurfaceWGL.cpp',
'libANGLE/renderer/gl/wgl/WindowSurfaceWGL.h',
'libANGLE/renderer/gl/wgl/functionswgl_typedefs.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