Commit 5ade8459 by Geoff Lang

Properly check for EGL_KHR_create_context before creating ES3 context.

Mark EGL_KHR_create_context as supported in the DisplayGLs. BUG=angleproject:1149 Change-Id: I20671535680eb2c3b9c08205cee243b3aa5c5821 Reviewed-on: https://chromium-review.googlesource.com/297080Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent e4de307e
...@@ -7,14 +7,16 @@ ...@@ -7,14 +7,16 @@
#include "SampleApplication.h" #include "SampleApplication.h"
#include "EGLWindow.h" #include "EGLWindow.h"
SampleApplication::SampleApplication(const std::string& name, size_t width, size_t height, SampleApplication::SampleApplication(const std::string &name,
EGLint glesMajorVersion, EGLint requestedRenderer) size_t width,
: mName(name), size_t height,
mWidth(width), EGLint glesMajorVersion,
mHeight(height), EGLint glesMinorVersion,
mRunning(false) EGLint requestedRenderer)
: mName(name), mWidth(width), mHeight(height), mRunning(false)
{ {
mEGLWindow.reset(new EGLWindow(glesMajorVersion, EGLPlatformParameters(requestedRenderer))); mEGLWindow.reset(new EGLWindow(glesMajorVersion, glesMinorVersion,
EGLPlatformParameters(requestedRenderer)));
mTimer.reset(CreateTimer()); mTimer.reset(CreateTimer());
mOSWindow.reset(CreateOSWindow()); mOSWindow.reset(CreateOSWindow());
......
...@@ -23,8 +23,12 @@ class EGLWindow; ...@@ -23,8 +23,12 @@ class EGLWindow;
class SampleApplication class SampleApplication
{ {
public: public:
SampleApplication(const std::string& name, size_t width, size_t height, SampleApplication(const std::string &name,
EGLint glesMajorVersion = 2, EGLint requestedRenderer = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE); size_t width,
size_t height,
EGLint glesMajorVersion = 2,
EGLint glesMinorVersion = 0,
EGLint requestedRenderer = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
virtual ~SampleApplication(); virtual ~SampleApplication();
virtual bool initialize(); virtual bool initialize();
......
...@@ -119,7 +119,7 @@ const FunctionsGL *DisplayCGL::getFunctionsGL() const ...@@ -119,7 +119,7 @@ const FunctionsGL *DisplayCGL::getFunctionsGL() const
void DisplayCGL::generateExtensions(egl::DisplayExtensions *outExtensions) const void DisplayCGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{ {
UNIMPLEMENTED(); outExtensions->createContext = true;
} }
void DisplayCGL::generateCaps(egl::Caps *outCaps) const void DisplayCGL::generateCaps(egl::Caps *outCaps) const
......
...@@ -452,7 +452,7 @@ const FunctionsGL *DisplayGLX::getFunctionsGL() const ...@@ -452,7 +452,7 @@ const FunctionsGL *DisplayGLX::getFunctionsGL() const
void DisplayGLX::generateExtensions(egl::DisplayExtensions *outExtensions) const void DisplayGLX::generateExtensions(egl::DisplayExtensions *outExtensions) const
{ {
// UNIMPLEMENTED(); outExtensions->createContext = true;
} }
void DisplayGLX::generateCaps(egl::Caps *outCaps) const void DisplayGLX::generateCaps(egl::Caps *outCaps) const
......
...@@ -466,7 +466,7 @@ const FunctionsGL *DisplayWGL::getFunctionsGL() const ...@@ -466,7 +466,7 @@ const FunctionsGL *DisplayWGL::getFunctionsGL() const
void DisplayWGL::generateExtensions(egl::DisplayExtensions *outExtensions) const void DisplayWGL::generateExtensions(egl::DisplayExtensions *outExtensions) const
{ {
//UNIMPLEMENTED(); outExtensions->createContext = true;
} }
void DisplayWGL::generateCaps(egl::Caps *outCaps) const void DisplayWGL::generateCaps(egl::Caps *outCaps) const
......
...@@ -201,7 +201,8 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi ...@@ -201,7 +201,8 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam<PlatformsWi
EGLWindow *createAndInitEGLWindow(angle::PlatformParameters &param) EGLWindow *createAndInitEGLWindow(angle::PlatformParameters &param)
{ {
EGLWindow *eglWindow = new EGLWindow(param.majorVersion, param.eglParameters); EGLWindow *eglWindow =
new EGLWindow(param.majorVersion, param.minorVersion, param.eglParameters);
bool result = eglWindow->initializeGL(mOSWindow); bool result = eglWindow->initializeGL(mOSWindow);
if (result == false) if (result == false)
{ {
......
...@@ -105,7 +105,8 @@ ANGLERenderTest::~ANGLERenderTest() ...@@ -105,7 +105,8 @@ ANGLERenderTest::~ANGLERenderTest()
void ANGLERenderTest::SetUp() void ANGLERenderTest::SetUp()
{ {
mOSWindow = CreateOSWindow(); mOSWindow = CreateOSWindow();
mEGLWindow = new EGLWindow(mTestParams.majorVersion, mTestParams.eglParameters); mEGLWindow = new EGLWindow(mTestParams.majorVersion, mTestParams.minorVersion,
mTestParams.eglParameters);
mEGLWindow->setSwapInterval(0); mEGLWindow->setSwapInterval(0);
if (!mOSWindow->initialize(mName, mTestParams.windowWidth, mTestParams.windowHeight)) if (!mOSWindow->initialize(mName, mTestParams.windowWidth, mTestParams.windowHeight))
......
...@@ -7,7 +7,8 @@ ANGLETest::ANGLETest() ...@@ -7,7 +7,8 @@ ANGLETest::ANGLETest()
mWidth(0), mWidth(0),
mHeight(0) mHeight(0)
{ {
mEGLWindow = new EGLWindow(GetParam().majorVersion, GetParam().eglParameters); mEGLWindow =
new EGLWindow(GetParam().majorVersion, GetParam().minorVersion, GetParam().eglParameters);
} }
ANGLETest::~ANGLETest() ANGLETest::~ANGLETest()
...@@ -201,7 +202,7 @@ void ANGLETest::setMultisampleEnabled(bool enabled) ...@@ -201,7 +202,7 @@ void ANGLETest::setMultisampleEnabled(bool enabled)
int ANGLETest::getClientVersion() const int ANGLETest::getClientVersion() const
{ {
return mEGLWindow->getClientVersion(); return mEGLWindow->getClientMajorVersion();
} }
EGLWindow *ANGLETest::getEGLWindow() const EGLWindow *ANGLETest::getEGLWindow() const
......
...@@ -63,7 +63,8 @@ bool IsPlatformAvailable(const PlatformParameters &param) ...@@ -63,7 +63,8 @@ bool IsPlatformAvailable(const PlatformParameters &param)
if (result) if (result)
{ {
EGLWindow *eglWindow = new EGLWindow(param.majorVersion, param.eglParameters); EGLWindow *eglWindow =
new EGLWindow(param.majorVersion, param.minorVersion, param.eglParameters);
result = eglWindow->initializeGL(osWindow); result = eglWindow->initializeGL(osWindow);
eglWindow->destroyGL(); eglWindow->destroyGL();
......
...@@ -69,11 +69,14 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b) ...@@ -69,11 +69,14 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b)
(a.deviceType == b.deviceType); (a.deviceType == b.deviceType);
} }
EGLWindow::EGLWindow(EGLint glesMajorVersion, const EGLPlatformParameters &platform) EGLWindow::EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform)
: mDisplay(EGL_NO_DISPLAY), : mDisplay(EGL_NO_DISPLAY),
mSurface(EGL_NO_SURFACE), mSurface(EGL_NO_SURFACE),
mContext(EGL_NO_CONTEXT), mContext(EGL_NO_CONTEXT),
mClientVersion(glesMajorVersion), mClientMajorVersion(glesMajorVersion),
mClientMinorVersion(glesMinorVersion),
mPlatform(platform), mPlatform(platform),
mRedBits(-1), mRedBits(-1),
mGreenBits(-1), mGreenBits(-1),
...@@ -153,6 +156,16 @@ bool EGLWindow::initializeGL(OSWindow *osWindow) ...@@ -153,6 +156,16 @@ bool EGLWindow::initializeGL(OSWindow *osWindow)
return false; return false;
} }
const char *displayExtensions = eglQueryString(mDisplay, EGL_EXTENSIONS);
// EGL_KHR_create_context is required to request a non-ES2 context.
bool hasKHRCreateContext = strstr(displayExtensions, "EGL_KHR_create_context") != nullptr;
if (majorVersion != 2 && minorVersion != 0 && !hasKHRCreateContext)
{
destroyGL();
return false;
}
eglBindAPI(EGL_OPENGL_ES_API); eglBindAPI(EGL_OPENGL_ES_API);
if (eglGetError() != EGL_SUCCESS) if (eglGetError() != EGL_SUCCESS)
{ {
...@@ -187,7 +200,7 @@ bool EGLWindow::initializeGL(OSWindow *osWindow) ...@@ -187,7 +200,7 @@ bool EGLWindow::initializeGL(OSWindow *osWindow)
eglGetConfigAttrib(mDisplay, mConfig, EGL_STENCIL_SIZE, &mStencilBits); eglGetConfigAttrib(mDisplay, mConfig, EGL_STENCIL_SIZE, &mStencilBits);
std::vector<EGLint> surfaceAttributes; std::vector<EGLint> surfaceAttributes;
if (strstr(eglQueryString(mDisplay, EGL_EXTENSIONS), "EGL_NV_post_sub_buffer") != nullptr) if (strstr(displayExtensions, "EGL_NV_post_sub_buffer") != nullptr)
{ {
surfaceAttributes.push_back(EGL_POST_SUB_BUFFER_SUPPORTED_NV); surfaceAttributes.push_back(EGL_POST_SUB_BUFFER_SUPPORTED_NV);
surfaceAttributes.push_back(EGL_TRUE); surfaceAttributes.push_back(EGL_TRUE);
...@@ -203,13 +216,18 @@ bool EGLWindow::initializeGL(OSWindow *osWindow) ...@@ -203,13 +216,18 @@ bool EGLWindow::initializeGL(OSWindow *osWindow)
} }
ASSERT(mSurface != EGL_NO_SURFACE); ASSERT(mSurface != EGL_NO_SURFACE);
EGLint contextAttibutes[] = std::vector<EGLint> contextAttributes;
if (hasKHRCreateContext)
{ {
EGL_CONTEXT_CLIENT_VERSION, mClientVersion, contextAttributes.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
EGL_NONE contextAttributes.push_back(mClientMajorVersion);
};
contextAttributes.push_back(EGL_CONTEXT_MINOR_VERSION_KHR);
contextAttributes.push_back(mClientMinorVersion);
}
contextAttributes.push_back(EGL_NONE);
mContext = eglCreateContext(mDisplay, mConfig, NULL, contextAttibutes); mContext = eglCreateContext(mDisplay, mConfig, nullptr, &contextAttributes[0]);
if (eglGetError() != EGL_SUCCESS) if (eglGetError() != EGL_SUCCESS)
{ {
destroyGL(); destroyGL();
......
...@@ -50,11 +50,12 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b); ...@@ -50,11 +50,12 @@ bool operator==(const EGLPlatformParameters &a, const EGLPlatformParameters &b);
class EGLWindow : angle::NonCopyable class EGLWindow : angle::NonCopyable
{ {
public: public:
EGLWindow(EGLint glesMajorVersion, const EGLPlatformParameters &platform); EGLWindow(EGLint glesMajorVersion,
EGLint glesMinorVersion,
const EGLPlatformParameters &platform);
~EGLWindow(); ~EGLWindow();
void setClientVersion(EGLint glesMajorVersion) { mClientVersion = glesMajorVersion; }
void setConfigRedBits(int bits) { mRedBits = bits; } void setConfigRedBits(int bits) { mRedBits = bits; }
void setConfigGreenBits(int bits) { mGreenBits = bits; } void setConfigGreenBits(int bits) { mGreenBits = bits; }
void setConfigBlueBits(int bits) { mBlueBits = bits; } void setConfigBlueBits(int bits) { mBlueBits = bits; }
...@@ -68,7 +69,8 @@ class EGLWindow : angle::NonCopyable ...@@ -68,7 +69,8 @@ class EGLWindow : angle::NonCopyable
void swap(); void swap();
EGLint getClientVersion() const { return mClientVersion; } EGLint getClientMajorVersion() const { return mClientMajorVersion; }
EGLint getClientMinorVersion() const { return mClientMinorVersion; }
const EGLPlatformParameters &getPlatform() const { return mPlatform; } const EGLPlatformParameters &getPlatform() const { return mPlatform; }
EGLConfig getConfig() const; EGLConfig getConfig() const;
EGLDisplay getDisplay() const; EGLDisplay getDisplay() const;
...@@ -93,7 +95,8 @@ class EGLWindow : angle::NonCopyable ...@@ -93,7 +95,8 @@ class EGLWindow : angle::NonCopyable
EGLSurface mSurface; EGLSurface mSurface;
EGLContext mContext; EGLContext mContext;
EGLint mClientVersion; EGLint mClientMajorVersion;
EGLint mClientMinorVersion;
EGLPlatformParameters mPlatform; EGLPlatformParameters mPlatform;
int mRedBits; int mRedBits;
int mGreenBits; int mGreenBits;
......
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