Commit 5da6690f by Geoff Lang Committed by Commit Bot

Hold RendererGL objects with a shared_ptr.

To support both virtualized and unvirtualized contexts, the RendererGL object represents the native context. Update ContexGL and the various DisplayGLs to hold RendererGL with a shared_ptr so that deletion of the renderer happens at the correct time. Update RendererGL to take ownership of FunctionsGL. BUG=angleproject:2464 Change-Id: Id040a8053973d73936c0a7ff0ab5edb1a3f16dc6 Reviewed-on: https://chromium-review.googlesource.com/1085851Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent c3907efa
......@@ -31,7 +31,7 @@
namespace rx
{
ContextGL::ContextGL(const gl::ContextState &state, RendererGL *renderer)
ContextGL::ContextGL(const gl::ContextState &state, const std::shared_ptr<RendererGL> &renderer)
: ContextImpl(state), mRenderer(renderer)
{
}
......
......@@ -29,7 +29,7 @@ struct WorkaroundsGL;
class ContextGL : public ContextImpl
{
public:
ContextGL(const gl::ContextState &state, RendererGL *renderer);
ContextGL(const gl::ContextState &state, const std::shared_ptr<RendererGL> &renderer);
~ContextGL() override;
gl::Error initialize() override;
......@@ -208,7 +208,7 @@ class ContextGL : public ContextImpl
gl::Error memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override;
private:
RendererGL *mRenderer;
std::shared_ptr<RendererGL> mRenderer;
};
} // namespace rx
......
......@@ -23,7 +23,7 @@ namespace rx
{
DisplayGL::DisplayGL(const egl::DisplayState &state)
: DisplayImpl(state), mRenderer(nullptr), mCurrentDrawSurface(nullptr)
: DisplayImpl(state), mCurrentDrawSurface(nullptr)
{
}
......@@ -33,20 +33,11 @@ DisplayGL::~DisplayGL()
egl::Error DisplayGL::initialize(egl::Display *display)
{
mRenderer = new RendererGL(getFunctionsGL(), display->getAttributeMap());
const gl::Version &maxVersion = mRenderer->getMaxSupportedESVersion();
if (maxVersion < gl::Version(2, 0))
{
return egl::EglNotInitialized() << "OpenGL ES 2.0 is not supportable.";
}
return egl::NoError();
}
void DisplayGL::terminate()
{
SafeDelete(mRenderer);
}
ImageImpl *DisplayGL::createImage(const egl::ImageState &state,
......@@ -57,12 +48,6 @@ ImageImpl *DisplayGL::createImage(const egl::ImageState &state,
return nullptr;
}
ContextImpl *DisplayGL::createContext(const gl::ContextState &state)
{
ASSERT(mRenderer != nullptr);
return new ContextGL(state, mRenderer);
}
StreamProducerImpl *DisplayGL::createStreamProducerD3DTexture(
egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs)
......@@ -103,12 +88,6 @@ egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface, egl::Surface *readS
}
}
gl::Version DisplayGL::getMaxSupportedESVersion() const
{
ASSERT(mRenderer != nullptr);
return mRenderer->getMaxSupportedESVersion();
}
void DisplayGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
// Advertise robust resource initialization on all OpenGL backends for testing even though it is
......
......@@ -35,26 +35,17 @@ class DisplayGL : public DisplayImpl
EGLenum target,
const egl::AttributeMap &attribs) override;
ContextImpl *createContext(const gl::ContextState &state) override;
StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
const egl::AttributeMap &attribs) override;
egl::Error makeCurrent(egl::Surface *drawSurface, egl::Surface *readSurface, gl::Context *context) override;
gl::Version getMaxSupportedESVersion() const override;
protected:
RendererGL *getRenderer() const { return mRenderer; };
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
private:
virtual const FunctionsGL *getFunctionsGL() const = 0;
virtual egl::Error makeCurrentSurfaceless(gl::Context *context);
RendererGL *mRenderer;
egl::Surface *mCurrentDrawSurface;
};
......
......@@ -164,9 +164,9 @@ static void INTERNAL_GL_APIENTRY LogGLDebugMessage(GLenum source,
namespace rx
{
RendererGL::RendererGL(const FunctionsGL *functions, const egl::AttributeMap &attribMap)
RendererGL::RendererGL(std::unique_ptr<FunctionsGL> functions, const egl::AttributeMap &attribMap)
: mMaxSupportedESVersion(0, 0),
mFunctions(functions),
mFunctions(std::move(functions)),
mStateManager(nullptr),
mBlitter(nullptr),
mMultiviewClearer(nullptr),
......@@ -175,10 +175,10 @@ RendererGL::RendererGL(const FunctionsGL *functions, const egl::AttributeMap &at
mMultiviewImplementationType(MultiviewImplementationTypeGL::UNSPECIFIED)
{
ASSERT(mFunctions);
nativegl_gl::GenerateWorkarounds(mFunctions, &mWorkarounds);
mStateManager = new StateManagerGL(mFunctions, getNativeCaps(), getNativeExtensions());
mBlitter = new BlitGL(functions, mWorkarounds, mStateManager);
mMultiviewClearer = new ClearMultiviewGL(functions, mStateManager);
nativegl_gl::GenerateWorkarounds(mFunctions.get(), &mWorkarounds);
mStateManager = new StateManagerGL(mFunctions.get(), getNativeCaps(), getNativeExtensions());
mBlitter = new BlitGL(mFunctions.get(), mWorkarounds, mStateManager);
mMultiviewClearer = new ClearMultiviewGL(mFunctions.get(), mStateManager);
bool hasDebugOutput = mFunctions->isAtLeastGL(gl::Version(4, 3)) ||
mFunctions->hasGLExtension("GL_KHR_debug") ||
......@@ -543,11 +543,6 @@ GLenum RendererGL::getResetStatus()
return mFunctions->getGraphicsResetStatus();
}
ContextImpl *RendererGL::createContext(const gl::ContextState &state)
{
return new ContextGL(state, this);
}
void RendererGL::insertEventMarker(GLsizei length, const char *marker)
{
}
......@@ -617,8 +612,9 @@ void RendererGL::generateCaps(gl::Caps *outCaps,
gl::Extensions *outExtensions,
gl::Limitations * /* outLimitations */) const
{
nativegl_gl::GenerateCaps(mFunctions, mWorkarounds, outCaps, outTextureCaps, outExtensions,
&mMaxSupportedESVersion, &mMultiviewImplementationType);
nativegl_gl::GenerateCaps(mFunctions.get(), mWorkarounds, outCaps, outTextureCaps,
outExtensions, &mMaxSupportedESVersion,
&mMultiviewImplementationType);
}
GLint RendererGL::getGPUDisjoint()
......@@ -676,7 +672,7 @@ MultiviewImplementationTypeGL RendererGL::getMultiviewImplementationType() const
void RendererGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const
{
ensureCapsInitialized();
nativegl_gl::ApplyWorkarounds(mFunctions, workarounds);
nativegl_gl::ApplyWorkarounds(mFunctions.get(), workarounds);
}
gl::Error RendererGL::dispatchCompute(const gl::Context *context,
......
......@@ -44,11 +44,9 @@ class StateManagerGL;
class RendererGL : angle::NonCopyable
{
public:
RendererGL(const FunctionsGL *functions, const egl::AttributeMap &attribMap);
RendererGL(std::unique_ptr<FunctionsGL> functions, const egl::AttributeMap &attribMap);
~RendererGL();
ContextImpl *createContext(const gl::ContextState &state);
gl::Error flush();
gl::Error finish();
......@@ -165,7 +163,7 @@ class RendererGL : angle::NonCopyable
GLint64 getTimestamp();
const gl::Version &getMaxSupportedESVersion() const;
const FunctionsGL *getFunctions() const { return mFunctions; }
const FunctionsGL *getFunctions() const { return mFunctions.get(); }
StateManagerGL *getStateManager() const { return mStateManager; }
const WorkaroundsGL &getWorkarounds() const { return mWorkarounds; }
BlitGL *getBlitter() const { return mBlitter; }
......@@ -196,7 +194,7 @@ class RendererGL : angle::NonCopyable
mutable gl::Version mMaxSupportedESVersion;
const FunctionsGL *mFunctions;
std::unique_ptr<FunctionsGL> mFunctions;
StateManagerGL *mStateManager;
BlitGL *mBlitter;
......
......@@ -39,6 +39,8 @@ class DisplayCGL : public DisplayGL
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs) override;
ContextImpl *createContext(const gl::ContextState &state) override;
egl::ConfigSet generateConfigs() override;
bool testDeviceLost() override;
......@@ -57,17 +59,19 @@ class DisplayCGL : public DisplayGL
egl::Error waitClient(const gl::Context *context) const override;
egl::Error waitNative(const gl::Context *context, EGLint engine) const override;
gl::Version getMaxSupportedESVersion() const override;
CGLContextObj getCGLContext() const;
private:
const FunctionsGL *getFunctionsGL() const override;
egl::Error makeCurrentSurfaceless(gl::Context *context) override;
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
void generateCaps(egl::Caps *outCaps) const override;
std::shared_ptr<RendererGL> mRenderer;
egl::Display *mEGLDisplay;
FunctionsGL *mFunctions;
CGLContextObj mContext;
};
......
......@@ -14,6 +14,8 @@
#include "common/debug.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/cgl/IOSurfaceSurfaceCGL.h"
#include "libANGLE/renderer/gl/cgl/PbufferSurfaceCGL.h"
#include "libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h"
......@@ -47,7 +49,7 @@ class FunctionsGLCGL : public FunctionsGL
};
DisplayCGL::DisplayCGL(const egl::DisplayState &state)
: DisplayGL(state), mEGLDisplay(nullptr), mFunctions(nullptr), mContext(nullptr)
: DisplayGL(state), mEGLDisplay(nullptr), mContext(nullptr)
{
}
......@@ -92,8 +94,16 @@ egl::Error DisplayCGL::initialize(egl::Display *display)
return egl::EglNotInitialized() << "Could not open the OpenGL Framework.";
}
mFunctions = new FunctionsGLCGL(handle);
mFunctions->initialize(display->getAttributeMap());
std::unique_ptr<FunctionsGL> functionsGL(new FunctionsGLCGL(handle));
functionsGL->initialize(display->getAttributeMap());
mRenderer.reset(new RendererGL(std::move(functionsGL), display->getAttributeMap()));
const gl::Version &maxVersion = mRenderer->getMaxSupportedESVersion();
if (maxVersion < gl::Version(2, 0))
{
return egl::EglNotInitialized() << "OpenGL ES 2.0 is not supportable.";
}
return DisplayGL::initialize(display);
}
......@@ -102,21 +112,21 @@ void DisplayCGL::terminate()
{
DisplayGL::terminate();
mRenderer.reset();
if (mContext != nullptr)
{
CGLSetCurrentContext(nullptr);
CGLReleaseContext(mContext);
mContext = nullptr;
}
SafeDelete(mFunctions);
}
SurfaceImpl *DisplayCGL::createWindowSurface(const egl::SurfaceState &state,
EGLNativeWindowType window,
const egl::AttributeMap &attribs)
{
return new WindowSurfaceCGL(state, this->getRenderer(), window, mFunctions, mContext);
return new WindowSurfaceCGL(state, mRenderer.get(), window, mContext);
}
SurfaceImpl *DisplayCGL::createPbufferSurface(const egl::SurfaceState &state,
......@@ -124,7 +134,7 @@ SurfaceImpl *DisplayCGL::createPbufferSurface(const egl::SurfaceState &state,
{
EGLint width = static_cast<EGLint>(attribs.get(EGL_WIDTH, 0));
EGLint height = static_cast<EGLint>(attribs.get(EGL_HEIGHT, 0));
return new PbufferSurfaceCGL(state, this->getRenderer(), width, height, mFunctions);
return new PbufferSurfaceCGL(state, mRenderer.get(), width, height);
}
SurfaceImpl *DisplayCGL::createPbufferFromClientBuffer(const egl::SurfaceState &state,
......@@ -145,6 +155,11 @@ SurfaceImpl *DisplayCGL::createPixmapSurface(const egl::SurfaceState &state,
return nullptr;
}
ContextImpl *DisplayCGL::createContext(const gl::ContextState &state)
{
return new ContextGL(state, mRenderer);
}
DeviceImpl *DisplayCGL::createDevice()
{
UNIMPLEMENTED();
......@@ -261,11 +276,6 @@ CGLContextObj DisplayCGL::getCGLContext() const
return mContext;
}
const FunctionsGL *DisplayCGL::getFunctionsGL() const
{
return mFunctions;
}
void DisplayCGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->iosurfaceClientBuffer = true;
......@@ -294,6 +304,11 @@ egl::Error DisplayCGL::waitNative(const gl::Context *context, EGLint engine) con
return egl::NoError();
}
gl::Version DisplayCGL::getMaxSupportedESVersion() const
{
return mRenderer->getMaxSupportedESVersion();
}
egl::Error DisplayCGL::makeCurrentSurfaceless(gl::Context *context)
{
// We have nothing to do as mContext is always current, and that CGL is surfaceless by
......
......@@ -26,8 +26,7 @@ class PbufferSurfaceCGL : public SurfaceGL
PbufferSurfaceCGL(const egl::SurfaceState &state,
RendererGL *renderer,
EGLint width,
EGLint height,
const FunctionsGL *functions);
EGLint height);
~PbufferSurfaceCGL() override;
egl::Error initialize(const egl::Display *display) override;
......
......@@ -21,12 +21,11 @@ namespace rx
PbufferSurfaceCGL::PbufferSurfaceCGL(const egl::SurfaceState &state,
RendererGL *renderer,
EGLint width,
EGLint height,
const FunctionsGL *functions)
EGLint height)
: SurfaceGL(state),
mWidth(width),
mHeight(height),
mFunctions(functions),
mFunctions(renderer->getFunctions()),
mStateManager(renderer->getStateManager()),
mColorRenderbuffer(0),
mDSRenderbuffer(0)
......
......@@ -58,7 +58,6 @@ class WindowSurfaceCGL : public SurfaceGL
WindowSurfaceCGL(const egl::SurfaceState &state,
RendererGL *renderer,
EGLNativeWindowType layer,
const FunctionsGL *functions,
CGLContextObj context);
~WindowSurfaceCGL() override;
......
......@@ -146,14 +146,13 @@
WindowSurfaceCGL::WindowSurfaceCGL(const egl::SurfaceState &state,
RendererGL *renderer,
EGLNativeWindowType layer,
const FunctionsGL *functions,
CGLContextObj context)
: SurfaceGL(state),
mSwapLayer(nil),
mCurrentSwapId(0),
mLayer(reinterpret_cast<CALayer *>(layer)),
mContext(context),
mFunctions(functions),
mFunctions(renderer->getFunctions()),
mStateManager(renderer->getStateManager()),
mDSRenderbuffer(0)
{
......
......@@ -16,11 +16,7 @@ namespace rx
#define EGL_NO_CONFIG ((EGLConfig)0)
DisplayEGL::DisplayEGL(const egl::DisplayState &state)
: DisplayGL(state),
mEGL(nullptr),
mConfig(EGL_NO_CONFIG),
mContext(EGL_NO_CONTEXT),
mFunctionsGL(nullptr)
: DisplayGL(state), mEGL(nullptr), mConfig(EGL_NO_CONFIG), mContext(EGL_NO_CONTEXT)
{
}
......@@ -121,8 +117,4 @@ void DisplayEGL::generateCaps(egl::Caps *outCaps) const
outCaps->textureNPOT = true; // Since we request GLES >= 2
}
const FunctionsGL *DisplayEGL::getFunctionsGL() const
{
return mFunctionsGL;
}
} // namespace rx
......@@ -29,13 +29,10 @@ class DisplayEGL : public DisplayGL
FunctionsEGL *mEGL;
EGLConfig mConfig;
EGLContext mContext;
FunctionsGL *mFunctionsGL;
private:
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
void generateCaps(egl::Caps *outCaps) const override;
const FunctionsGL *getFunctionsGL() const override;
};
} // namespace rx
......
......@@ -11,6 +11,8 @@
#include "common/debug.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/egl/FunctionsEGLDL.h"
#include "libANGLE/renderer/gl/egl/PbufferSurfaceEGL.h"
#include "libANGLE/renderer/gl/egl/WindowSurfaceEGL.h"
......@@ -144,8 +146,16 @@ egl::Error DisplayAndroid::initialize(egl::Display *display)
}
mCurrentSurface = mDummyPbuffer;
mFunctionsGL = mEGL->makeFunctionsGL();
mFunctionsGL->initialize(display->getAttributeMap());
std::unique_ptr<FunctionsGL> functionsGL(mEGL->makeFunctionsGL());
functionsGL->initialize(display->getAttributeMap());
mRenderer.reset(new RendererGL(std::move(functionsGL), display->getAttributeMap()));
const gl::Version &maxVersion = mRenderer->getMaxSupportedESVersion();
if (maxVersion < gl::Version(2, 0))
{
return egl::EglNotInitialized() << "OpenGL ES 2.0 is not supportable.";
}
return DisplayGL::initialize(display);
}
......@@ -171,6 +181,7 @@ void DisplayAndroid::terminate()
}
}
mRenderer.reset();
if (mContext != EGL_NO_CONTEXT)
{
success = mEGL->destroyContext(mContext);
......@@ -188,7 +199,6 @@ void DisplayAndroid::terminate()
}
SafeDelete(mEGL);
SafeDelete(mFunctionsGL);
}
SurfaceImpl *DisplayAndroid::createWindowSurface(const egl::SurfaceState &state,
......@@ -245,6 +255,11 @@ ImageImpl *DisplayAndroid::createImage(const egl::ImageState &state,
return DisplayGL::createImage(state, target, attribs);
}
ContextImpl *DisplayAndroid::createContext(const gl::ContextState &state)
{
return new ContextGL(state, mRenderer);
}
template <typename T>
void DisplayAndroid::getConfigAttrib(EGLConfig config, EGLint attribute, T *value) const
{
......@@ -455,6 +470,11 @@ egl::Error DisplayAndroid::makeCurrent(egl::Surface *drawSurface,
return DisplayGL::makeCurrent(drawSurface, readSurface, context);
}
gl::Version DisplayAndroid::getMaxSupportedESVersion() const
{
return mRenderer->getMaxSupportedESVersion();
}
egl::Error DisplayAndroid::makeCurrentSurfaceless(gl::Context *context)
{
// Nothing to do because EGL always uses the same context and the previous surface can be left
......
......@@ -44,6 +44,8 @@ class DisplayAndroid : public DisplayEGL
EGLenum target,
const egl::AttributeMap &attribs) override;
ContextImpl *createContext(const gl::ContextState &state) override;
egl::ConfigSet generateConfigs() override;
bool testDeviceLost() override;
......@@ -60,6 +62,8 @@ class DisplayAndroid : public DisplayEGL
egl::Surface *readSurface,
gl::Context *context) override;
gl::Version getMaxSupportedESVersion() const override;
private:
egl::Error makeCurrentSurfaceless(gl::Context *context) override;
......@@ -73,6 +77,8 @@ class DisplayAndroid : public DisplayEGL
const char *extension,
const U &defaultValue) const;
std::shared_ptr<RendererGL> mRenderer;
std::vector<EGLint> mConfigAttribList;
std::map<EGLint, EGLint> mConfigIds;
EGLSurface mDummyPbuffer;
......
......@@ -22,6 +22,7 @@
#include "libANGLE/Config.h"
#include "libANGLE/Display.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
......@@ -121,7 +122,7 @@ DisplayOzone::Buffer::~Buffer()
{
reset();
FunctionsGL *gl = mDisplay->mFunctionsGL;
const FunctionsGL *gl = mDisplay->mRenderer->getFunctions();
gl->deleteRenderbuffers(1, &mColorBuffer);
mColorBuffer = 0;
gl->deleteRenderbuffers(1, &mDSBuffer);
......@@ -148,7 +149,7 @@ void DisplayOzone::Buffer::reset()
if (mTexture)
{
FunctionsGL *gl = mDisplay->mFunctionsGL;
const FunctionsGL *gl = mDisplay->mRenderer->getFunctions();
gl->deleteTextures(1, &mTexture);
mTexture = 0;
}
......@@ -211,8 +212,8 @@ bool DisplayOzone::Buffer::resize(int32_t width, int32_t height)
return false;
}
FunctionsGL *gl = mDisplay->mFunctionsGL;
StateManagerGL *sm = mDisplay->getRenderer()->getStateManager();
const FunctionsGL *gl = mDisplay->mRenderer->getFunctions();
StateManagerGL *sm = mDisplay->mRenderer->getStateManager();
// Update the storage of the renderbuffers but don't generate new IDs. This will update all
// framebuffers they are bound to.
......@@ -243,15 +244,16 @@ bool DisplayOzone::Buffer::initialize(int width, int height)
void DisplayOzone::Buffer::bindTexImage()
{
mDisplay->mFunctionsGL->eGLImageTargetTexture2DOES(GL_TEXTURE_2D, mImage);
const FunctionsGL *gl = mDisplay->mRenderer->getFunctions();
gl->eGLImageTargetTexture2DOES(GL_TEXTURE_2D, mImage);
}
GLuint DisplayOzone::Buffer::getTexture()
{
// TODO(fjhenigman) Try not to create a new texture every time. That already works on Intel
// and should work on Mali with proper fences.
FunctionsGL *gl = mDisplay->mFunctionsGL;
StateManagerGL *sm = mDisplay->getRenderer()->getStateManager();
const FunctionsGL *gl = mDisplay->mRenderer->getFunctions();
StateManagerGL *sm = mDisplay->mRenderer->getStateManager();
gl->genTextures(1, &mTexture);
sm->bindTexture(gl::TextureType::_2D, mTexture);
......@@ -332,8 +334,8 @@ void DisplayOzone::Buffer::present(const gl::Context *context)
bool DisplayOzone::Buffer::createRenderbuffers()
{
FunctionsGL *gl = mDisplay->mFunctionsGL;
StateManagerGL *sm = mDisplay->getRenderer()->getStateManager();
const FunctionsGL *gl = mDisplay->mRenderer->getFunctions();
StateManagerGL *sm = mDisplay->mRenderer->getStateManager();
gl->genRenderbuffers(1, &mColorBuffer);
sm->bindRenderbuffer(GL_RENDERBUFFER, mColorBuffer);
......@@ -349,6 +351,7 @@ bool DisplayOzone::Buffer::createRenderbuffers()
DisplayOzone::DisplayOzone(const egl::DisplayState &state)
: DisplayEGL(state),
mRenderer(nullptr),
mGBM(nullptr),
mConnector(nullptr),
mMode(nullptr),
......@@ -528,8 +531,15 @@ egl::Error DisplayOzone::initialize(egl::Display *display)
return egl::EglNotInitialized() << "Could not make context current.";
}
mFunctionsGL = mEGL->makeFunctionsGL();
mFunctionsGL->initialize(display->getAttributeMap());
std::unique_ptr<FunctionsGL> functionsGL(mEGL->makeFunctionsGL());
functionsGL->initialize(display->getAttributeMap());
mRenderer.reset(new RendererGL(std::move(functionsGL), display->getAttributeMap()));
const gl::Version &maxVersion = mRenderer->getMaxSupportedESVersion();
if (maxVersion < gl::Version(2, 0))
{
return egl::EglNotInitialized() << "OpenGL ES 2.0 is not supportable.";
}
return DisplayGL::initialize(display);
}
......@@ -606,7 +616,7 @@ void DisplayOzone::presentScreen()
GLuint DisplayOzone::makeShader(GLuint type, const char *src)
{
FunctionsGL *gl = mFunctionsGL;
const FunctionsGL *gl = mRenderer->getFunctions();
GLuint shader = gl->createShader(type);
gl->shaderSource(shader, 1, &src, nullptr);
gl->compileShader(shader);
......@@ -626,8 +636,8 @@ GLuint DisplayOzone::makeShader(GLuint type, const char *src)
void DisplayOzone::drawWithTexture(const gl::Context *context, Buffer *buffer)
{
FunctionsGL *gl = mFunctionsGL;
StateManagerGL *sm = getRenderer()->getStateManager();
const FunctionsGL *gl = mRenderer->getFunctions();
StateManagerGL *sm = mRenderer->getStateManager();
if (!mProgram)
{
......@@ -777,7 +787,8 @@ void DisplayOzone::drawBuffer(const gl::Context *context, Buffer *buffer)
}
}
StateManagerGL *sm = getRenderer()->getStateManager();
const FunctionsGL *gl = mRenderer->getFunctions();
StateManagerGL *sm = mRenderer->getStateManager();
GLuint fbo = mDrawing->createGLFB(context);
sm->bindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
......@@ -786,7 +797,7 @@ void DisplayOzone::drawBuffer(const gl::Context *context, Buffer *buffer)
sm->setScissorTestEnabled(false);
sm->setColorMask(true, true, true, true);
sm->setDepthMask(true);
mFunctionsGL->clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl->clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
sm->deleteFramebuffer(fbo);
}
......@@ -796,7 +807,8 @@ void DisplayOzone::drawBuffer(const gl::Context *context, Buffer *buffer)
void DisplayOzone::flushGL()
{
mFunctionsGL->flush();
const FunctionsGL *gl = mRenderer->getFunctions();
gl->flush();
if (mEGL->hasExtension("EGL_KHR_fence_sync"))
{
const EGLint attrib[] = {EGL_SYNC_CONDITION_KHR,
......@@ -832,11 +844,12 @@ void DisplayOzone::terminate()
if (mProgram)
{
mFunctionsGL->deleteProgram(mProgram);
mFunctionsGL->deleteShader(mVertexShader);
mFunctionsGL->deleteShader(mFragmentShader);
mFunctionsGL->deleteBuffers(1, &mVertexBuffer);
mFunctionsGL->deleteBuffers(1, &mIndexBuffer);
const FunctionsGL *gl = mRenderer->getFunctions();
gl->deleteProgram(mProgram);
gl->deleteShader(mVertexShader);
gl->deleteShader(mFragmentShader);
gl->deleteBuffers(1, &mVertexBuffer);
gl->deleteBuffers(1, &mIndexBuffer);
mProgram = 0;
}
......@@ -851,7 +864,7 @@ void DisplayOzone::terminate()
mContext = nullptr;
}
SafeDelete(mFunctionsGL);
mRenderer.reset();
if (mEGL)
{
......@@ -918,6 +931,11 @@ SurfaceImpl *DisplayOzone::createPixmapSurface(const egl::SurfaceState &state,
return nullptr;
}
ContextImpl *DisplayOzone::createContext(const gl::ContextState &state)
{
return new ContextGL(state, mRenderer);
}
DeviceImpl *DisplayOzone::createDevice()
{
UNIMPLEMENTED();
......@@ -973,6 +991,11 @@ egl::Error DisplayOzone::waitNative(const gl::Context *context, EGLint engine) c
return egl::NoError();
}
gl::Version DisplayOzone::getMaxSupportedESVersion() const
{
return mRenderer->getMaxSupportedESVersion();
}
void DisplayOzone::setSwapInterval(EGLSurface drawable, SwapControlData *data)
{
ASSERT(data != nullptr);
......
......@@ -127,6 +127,8 @@ class DisplayOzone final : public DisplayEGL
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs) override;
ContextImpl *createContext(const gl::ContextState &state) override;
egl::ConfigSet generateConfigs() override;
bool testDeviceLost() override;
......@@ -139,6 +141,8 @@ class DisplayOzone final : public DisplayEGL
egl::Error waitClient(const gl::Context *context) const override;
egl::Error waitNative(const gl::Context *context, EGLint engine) const override;
gl::Version getMaxSupportedESVersion() const override;
// TODO(fjhenigman) Implement this.
// Swap interval can be set globally or per drawable.
// This function will make sure the drawable's swap interval is the
......@@ -161,6 +165,8 @@ class DisplayOzone final : public DisplayEGL
void *data);
void pageFlipHandler(unsigned int sequence, uint64_t tv);
std::shared_ptr<RendererGL> mRenderer;
gbm_device *mGBM;
drmModeConnectorPtr mConnector;
drmModeModeInfoPtr mMode;
......
......@@ -18,6 +18,7 @@
#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/glx/PbufferSurfaceGLX.h"
#include "libANGLE/renderer/gl/glx/WindowSurfaceGLX.h"
......@@ -59,7 +60,6 @@ class FunctionsGLGLX : public FunctionsGL
DisplayGLX::DisplayGLX(const egl::DisplayState &state)
: DisplayGL(state),
mFunctionsGL(nullptr),
mRequestedVisual(-1),
mContextConfig(nullptr),
mContext(nullptr),
......@@ -291,13 +291,13 @@ egl::Error DisplayGLX::initialize(egl::Display *display)
return egl::EglNotInitialized() << "Could not make the dummy pbuffer current.";
}
mFunctionsGL = new FunctionsGLGLX(mGLX.getProc);
mFunctionsGL->initialize(eglAttributes);
std::unique_ptr<FunctionsGL> functionsGL(new FunctionsGLGLX(mGLX.getProc));
functionsGL->initialize(eglAttributes);
// TODO(cwallez, angleproject:1303) Disable the OpenGL ES backend on Linux NVIDIA and Intel as
// it has problems on our automated testing. An OpenGL ES backend might not trigger this test if
// there is no Desktop OpenGL support, but that's not the case in our automated testing.
VendorID vendor = GetVendorID(mFunctionsGL);
VendorID vendor = GetVendorID(functionsGL.get());
bool isOpenGLES =
eglAttributes.get(EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE) ==
EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
......@@ -308,6 +308,13 @@ egl::Error DisplayGLX::initialize(egl::Display *display)
syncXCommands();
mRenderer.reset(new RendererGL(std::move(functionsGL), eglAttributes));
const gl::Version &maxVersion = mRenderer->getMaxSupportedESVersion();
if (maxVersion < gl::Version(2, 0))
{
return egl::EglNotInitialized() << "OpenGL ES 2.0 is not supportable.";
}
return DisplayGL::initialize(display);
}
......@@ -329,7 +336,7 @@ void DisplayGLX::terminate()
mGLX.terminate();
SafeDelete(mFunctionsGL);
mRenderer.reset();
if (mUsesNewXDisplay)
{
......@@ -397,6 +404,11 @@ SurfaceImpl *DisplayGLX::createPixmapSurface(const egl::SurfaceState &state,
return nullptr;
}
ContextImpl *DisplayGLX::createContext(const gl::ContextState &state)
{
return new ContextGL(state, mRenderer);
}
DeviceImpl *DisplayGLX::createDevice()
{
UNIMPLEMENTED();
......@@ -654,7 +666,7 @@ bool DisplayGLX::testDeviceLost()
{
if (mHasARBCreateContextRobustness)
{
return getRenderer()->getResetStatus() != GL_NO_ERROR;
return mRenderer->getResetStatus() != GL_NO_ERROR;
}
return false;
......@@ -726,6 +738,11 @@ egl::Error DisplayGLX::waitNative(const gl::Context *context, EGLint engine) con
return egl::NoError();
}
gl::Version DisplayGLX::getMaxSupportedESVersion() const
{
return mRenderer->getMaxSupportedESVersion();
}
void DisplayGLX::syncXCommands() const
{
if (mUsesNewXDisplay)
......@@ -782,11 +799,6 @@ bool DisplayGLX::isValidWindowVisualId(unsigned long visualId) const
return mRequestedVisual == -1 || static_cast<unsigned long>(mRequestedVisual) == visualId;
}
const FunctionsGL *DisplayGLX::getFunctionsGL() const
{
return mFunctionsGL;
}
void DisplayGLX::generateExtensions(egl::DisplayExtensions *outExtensions) const
{
outExtensions->createContextRobustness = mHasARBCreateContextRobustness;
......
......@@ -61,6 +61,8 @@ class DisplayGLX : public DisplayGL
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs) override;
ContextImpl *createContext(const gl::ContextState &state) override;
egl::ConfigSet generateConfigs() override;
bool testDeviceLost() override;
......@@ -75,6 +77,8 @@ class DisplayGLX : public DisplayGL
egl::Error waitClient(const gl::Context *context) const override;
egl::Error waitNative(const gl::Context *context, EGLint engine) const override;
gl::Version getMaxSupportedESVersion() const override;
// Synchronizes with the X server, if the display has been opened by ANGLE.
// Calling this is required at the end of every functions that does buffered
// X calls (not for glX calls) otherwise there might be race conditions
......@@ -90,8 +94,6 @@ class DisplayGLX : public DisplayGL
bool isValidWindowVisualId(unsigned long visualId) const;
private:
const FunctionsGL *getFunctionsGL() const override;
egl::Error initializeContext(glx::FBConfig config,
const egl::AttributeMap &eglAttributes,
glx::Context *context);
......@@ -107,7 +109,7 @@ class DisplayGLX : public DisplayGL
int profileMask,
glx::Context *context) const;
FunctionsGL *mFunctionsGL;
std::shared_ptr<RendererGL> mRenderer;
std::map<int, glx::FBConfig> configIdToGLXConfig;
......
......@@ -12,6 +12,7 @@
#include "libANGLE/Config.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/D3DTextureSurfaceWGL.h"
......@@ -60,10 +61,10 @@ class FunctionsGLWindows : public FunctionsGL
DisplayWGL::DisplayWGL(const egl::DisplayState &state)
: DisplayGL(state),
mRenderer(nullptr),
mCurrentDC(nullptr),
mOpenGLModule(nullptr),
mFunctionsWGL(nullptr),
mFunctionsGL(nullptr),
mHasWGLCreateContextRobustness(false),
mHasRobustness(false),
mWindowClass(0),
......@@ -98,6 +99,8 @@ egl::Error DisplayWGL::initialize(egl::Display *display)
egl::Error DisplayWGL::initializeImpl(egl::Display *display)
{
mDisplayAttributes = display->getAttributeMap();
mOpenGLModule = LoadLibraryA("opengl32.dll");
if (!mOpenGLModule)
{
......@@ -245,34 +248,10 @@ egl::Error DisplayWGL::initializeImpl(egl::Display *display)
<< "Failed to set the pixel format on the intermediate OpenGL window.";
}
if (mFunctionsWGL->createContextAttribsARB)
{
mWGLContext = initializeContextAttribs(displayAttributes);
}
ANGLE_TRY(createRenderer(&mRenderer, &mWGLContext));
const FunctionsGL *functionsGL = mRenderer->getFunctions();
// If wglCreateContextAttribsARB is unavailable or failed, try the standard wglCreateContext
if (!mWGLContext)
{
// Don't have control over GL versions
mWGLContext = mFunctionsWGL->createContext(mDeviceContext);
}
if (!mWGLContext)
{
return egl::EglNotInitialized()
<< "Failed to create a WGL context for the intermediate OpenGL window.";
}
if (!mFunctionsWGL->makeCurrent(mDeviceContext, mWGLContext))
{
return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current.";
}
mCurrentDC = mDeviceContext;
mFunctionsGL = new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress);
mFunctionsGL->initialize(displayAttributes);
mHasRobustness = mFunctionsGL->getGraphicsResetStatus != nullptr;
mHasRobustness = functionsGL->getGraphicsResetStatus != nullptr;
if (mHasWGLCreateContextRobustness != mHasRobustness)
{
WARN() << "WGL_ARB_create_context_robustness exists but unable to OpenGL context with "
......@@ -280,7 +259,7 @@ egl::Error DisplayWGL::initializeImpl(egl::Display *display)
}
// Intel OpenGL ES drivers are not currently supported due to bugs in the driver and ANGLE
VendorID vendor = GetVendorID(mFunctionsGL);
VendorID vendor = GetVendorID(functionsGL);
if (requestedDisplayType == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE && IsIntel(vendor))
{
return egl::EglNotInitialized() << "Intel OpenGL ES drivers are not supported.";
......@@ -319,6 +298,12 @@ egl::Error DisplayWGL::initializeImpl(egl::Display *display)
}
}
const gl::Version &maxVersion = mRenderer->getMaxSupportedESVersion();
if (maxVersion < gl::Version(2, 0))
{
return egl::EglNotInitialized() << "OpenGL ES 2.0 is not supportable.";
}
return egl::NoError();
}
......@@ -347,7 +332,7 @@ void DisplayWGL::destroy()
mWGLContext = nullptr;
SafeDelete(mFunctionsWGL);
SafeDelete(mFunctionsGL);
mRenderer.reset();
if (mDeviceContext)
{
......@@ -407,9 +392,9 @@ SurfaceImpl *DisplayWGL::createWindowSurface(const egl::SurfaceState &state,
return nullptr;
}
return new DXGISwapChainWindowSurfaceWGL(state, getRenderer()->getStateManager(), window,
mD3D11Device, mD3D11DeviceHandle, mDeviceContext,
mFunctionsGL, mFunctionsWGL, orientation);
return new DXGISwapChainWindowSurfaceWGL(
state, mRenderer->getStateManager(), window, mD3D11Device, mD3D11DeviceHandle,
mDeviceContext, mRenderer->getFunctions(), mFunctionsWGL, orientation);
}
else
{
......@@ -441,8 +426,8 @@ SurfaceImpl *DisplayWGL::createPbufferFromClientBuffer(const egl::SurfaceState &
return nullptr;
}
return new D3DTextureSurfaceWGL(state, getRenderer()->getStateManager(), buftype, clientBuffer,
this, mDeviceContext, mD3D11Device, mFunctionsGL,
return new D3DTextureSurfaceWGL(state, mRenderer->getStateManager(), buftype, clientBuffer,
this, mDeviceContext, mD3D11Device, mRenderer->getFunctions(),
mFunctionsWGL);
}
......@@ -454,6 +439,11 @@ SurfaceImpl *DisplayWGL::createPixmapSurface(const egl::SurfaceState &state,
return nullptr;
}
ContextImpl *DisplayWGL::createContext(const gl::ContextState &state)
{
return new ContextGL(state, mRenderer);
}
DeviceImpl *DisplayWGL::createDevice()
{
UNREACHABLE();
......@@ -541,7 +531,7 @@ bool DisplayWGL::testDeviceLost()
{
if (mHasRobustness)
{
return getRenderer()->getResetStatus() != GL_NO_ERROR;
return mRenderer->getResetStatus() != GL_NO_ERROR;
}
return false;
......@@ -581,11 +571,6 @@ std::string DisplayWGL::getVendorString() const
return "";
}
const FunctionsGL *DisplayWGL::getFunctionsGL() const
{
return mFunctionsGL;
}
egl::Error DisplayWGL::initializeD3DDevice()
{
if (mD3D11Device != nullptr)
......@@ -746,6 +731,11 @@ void DisplayWGL::releaseD3DDevice(HANDLE deviceHandle)
}
}
gl::Version DisplayWGL::getMaxSupportedESVersion() const
{
return mRenderer->getMaxSupportedESVersion();
}
HGLRC DisplayWGL::initializeContextAttribs(const egl::AttributeMap &eglAttributes) const
{
EGLint requestedDisplayType = static_cast<EGLint>(
......@@ -821,4 +811,41 @@ 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)
{
HGLRC context = nullptr;
if (mFunctionsWGL->createContextAttribsARB)
{
context = initializeContextAttribs(mDisplayAttributes);
}
// If wglCreateContextAttribsARB is unavailable or failed, try the standard wglCreateContext
if (!context)
{
// Don't have control over GL versions
context = mFunctionsWGL->createContext(mDeviceContext);
}
if (!context)
{
return egl::EglNotInitialized()
<< "Failed to create a WGL context for the intermediate OpenGL window.";
}
if (!mFunctionsWGL->makeCurrent(mDeviceContext, context))
{
return egl::EglNotInitialized() << "Failed to make the intermediate WGL context current.";
}
mCurrentDC = mDeviceContext;
std::unique_ptr<FunctionsGL> functionsGL(
new FunctionsGLWindows(mOpenGLModule, mFunctionsWGL->getProcAddress));
functionsGL->initialize(mDisplayAttributes);
outRenderer->reset(new RendererGL(std::move(functionsGL), mDisplayAttributes));
*outContext = context;
return egl::NoError();
}
}
......@@ -41,6 +41,8 @@ class DisplayWGL : public DisplayGL
NativePixmapType nativePixmap,
const egl::AttributeMap &attribs) override;
ContextImpl *createContext(const gl::ContextState &state) override;
egl::ConfigSet generateConfigs() override;
bool testDeviceLost() override;
......@@ -66,12 +68,12 @@ class DisplayWGL : public DisplayGL
egl::Error registerD3DDevice(IUnknown *device, HANDLE *outHandle);
void releaseD3DDevice(HANDLE handle);
gl::Version getMaxSupportedESVersion() const override;
private:
egl::Error initializeImpl(egl::Display *display);
void destroy();
const FunctionsGL *getFunctionsGL() const override;
egl::Error initializeD3DDevice();
void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
......@@ -82,16 +84,21 @@ 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);
std::shared_ptr<RendererGL> mRenderer;
HDC mCurrentDC;
HMODULE mOpenGLModule;
FunctionsWGL *mFunctionsWGL;
FunctionsGL *mFunctionsGL;
bool mHasWGLCreateContextRobustness;
bool mHasRobustness;
egl::AttributeMap mDisplayAttributes;
ATOM mWindowClass;
HWND mWindow;
HDC mDeviceContext;
......
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