Bug 1347731 - Simplify robustness selection in EGL. - r=daoshengmu
MozReview-Commit-ID: 7iBea17tzRI
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -456,83 +456,78 @@ GLContextEGL::GetWSIInfo(nsCString* cons
// hold a reference to the given surface
// for the lifetime of this context.
void
GLContextEGL::HoldSurface(gfxASurface* aSurf) {
mThebesSurface = aSurf;
}
already_AddRefed<GLContextEGL>
-GLContextEGL::CreateGLContext(CreateContextFlags flags,
- const SurfaceCaps& caps,
- bool isOffscreen,
- EGLConfig config,
- EGLSurface surface,
- nsACString* const out_failureId)
+GLContextEGL::CreateGLContext(CreateContextFlags flags, const SurfaceCaps& caps,
+ bool isOffscreen, EGLConfig config, EGLSurface surface,
+ nsACString* const out_failureId)
{
if (sEGLLibrary.fBindAPI(LOCAL_EGL_OPENGL_ES_API) == LOCAL_EGL_FALSE) {
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_ES");
NS_WARNING("Failed to bind API to GLES!");
return nullptr;
}
std::vector<EGLint> required_attribs;
required_attribs.push_back(LOCAL_EGL_CONTEXT_CLIENT_VERSION);
if (flags & CreateContextFlags::PREFER_ES3) {
required_attribs.push_back(3);
} else {
required_attribs.push_back(2);
}
- std::vector<EGLint> robustness_attribs;
std::vector<EGLint> rbab_attribs; // RBAB: Robust Buffer Access Behavior
- if (flags & CreateContextFlags::PREFER_ROBUSTNESS) {
- if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::EXT_create_context_robustness)) {
- robustness_attribs = required_attribs;
- robustness_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
- robustness_attribs.push_back(LOCAL_EGL_LOSE_CONTEXT_ON_RESET_EXT);
- // Skip EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, since it doesn't help us.
- }
+ if (flags & CreateContextFlags::REQUIRE_ROBUSTNESS) {
+ if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_create_context)) {
+ required_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR);
+ required_attribs.push_back(LOCAL_EGL_LOSE_CONTEXT_ON_RESET_KHR);
- if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_create_context)) {
rbab_attribs = required_attribs;
- rbab_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR);
- rbab_attribs.push_back(LOCAL_EGL_LOSE_CONTEXT_ON_RESET_KHR);
rbab_attribs.push_back(LOCAL_EGL_CONTEXT_FLAGS_KHR);
rbab_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR);
+
+ } else if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::EXT_create_context_robustness)) {
+ required_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
+ required_attribs.push_back(LOCAL_EGL_LOSE_CONTEXT_ON_RESET_EXT);
+
+ rbab_attribs = required_attribs;
+ rbab_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT);
+ rbab_attribs.push_back(LOCAL_EGL_TRUE);
+
+ } else {
+ NS_WARNING("Robustness required, but unavailable");
+#ifndef ANDROID
+ return nullptr;
+#endif
}
}
const auto fnCreate = [&](const std::vector<EGLint>& attribs) {
auto terminated_attribs = attribs;
-
for (const auto& cur : kTerminationAttribs) {
terminated_attribs.push_back(cur);
}
-
return sEGLLibrary.fCreateContext(EGL_DISPLAY(), config, EGL_NO_CONTEXT,
terminated_attribs.data());
};
EGLContext context;
do {
if (rbab_attribs.size()) {
context = fnCreate(rbab_attribs);
if (context)
break;
NS_WARNING("Failed to create EGLContext with rbab_attribs");
}
- if (robustness_attribs.size()) {
- context = fnCreate(robustness_attribs);
- if (context)
- break;
- NS_WARNING("Failed to create EGLContext with robustness_attribs");
- }
-
context = fnCreate(required_attribs);
if (context)
break;
NS_WARNING("Failed to create EGLContext with required_attribs");
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_CREATE");
return nullptr;
} while (false);
@@ -720,20 +715,19 @@ GLContextProviderEGL::CreateWrappingExis
if (!sEGLLibrary.EnsureInitialized(false, &discardFailureId)) {
MOZ_CRASH("GFX: Failed to load EGL library 2!\n");
return nullptr;
}
if (!aContext || !aSurface)
return nullptr;
- SurfaceCaps caps = SurfaceCaps::Any();
- EGLConfig config = EGL_NO_CONFIG;
- RefPtr<GLContextEGL> gl = new GLContextEGL(CreateContextFlags::NONE, caps, false,
- config, (EGLSurface)aSurface,
+ RefPtr<GLContextEGL> gl = new GLContextEGL(CreateContextFlags::NONE,
+ SurfaceCaps::Any(), false, EGL_NO_CONFIG,
+ (EGLSurface)aSurface,
(EGLContext)aContext);
gl->SetIsDoubleBuffered(true);
gl->mOwnsContext = false;
return gl.forget();
}
already_AddRefed<GLContext>