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