Bug 1268638 - Redo backend selection dance for WebGL. - r=jrmuizel
MozReview-Commit-ID: EW8vDujwn4x
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -638,17 +638,16 @@ static already_AddRefed<gl::GLContext>
CreateGLWithDefault(const gl::SurfaceCaps& caps, gl::CreateContextFlags flags,
WebGLContext* webgl,
std::vector<WebGLContext::FailureReason>* const out_failReasons)
{
const gfx::IntSize dummySize(16, 16);
nsCString failureId;
RefPtr<GLContext> gl = gl::GLContextProvider::CreateOffscreen(dummySize, caps,
flags, &failureId);
-
if (gl && gl->IsANGLE()) {
gl = nullptr;
}
if (!gl) {
out_failReasons->push_back(WebGLContext::FailureReason(
failureId,
"Error during native OpenGL init."
@@ -693,77 +692,82 @@ WebGLContext::CreateAndInitGLWith(FnCrea
return true;
}
bool
WebGLContext::CreateAndInitGL(bool forceEnabled,
std::vector<FailureReason>* const out_failReasons)
{
- bool disableNativeGL = true;
+ const gl::SurfaceCaps baseCaps = BaseCaps(mOptions, this);
+ gl::CreateContextFlags flags = gl::CreateContextFlags::NO_VALIDATION;
+ bool tryNativeGL = true;
+ bool tryANGLE = false;
+
if (forceEnabled) {
- disableNativeGL = false;
- } else if (IsWebGL2()) {
+ flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
+ }
+
+ if (IsWebGL2()) {
+ flags |= gl::CreateContextFlags::PREFER_ES3;
+ } else {
+ flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
+ }
+
+ //////
+
+ const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
+
+#ifdef XP_WIN
+ if (!IsWebGL2()) {
+ // Use only ANGLE on Windows for WebGL 1.
+ tryNativeGL = false;
+ tryANGLE = true;
+ }
+
+ if (gfxPrefs::WebGLDisableWGL()) {
+ tryNativeGL = false;
+ }
+
+ if (gfxPrefs::WebGLDisableANGLE() || PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL") || useEGL) {
+ tryNativeGL = true;
+ tryANGLE = false;
+ }
+#endif
+
+ if (tryNativeGL && !forceEnabled) {
const nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
const auto feature = nsIGfxInfo::FEATURE_WEBGL_OPENGL;
FailureReason reason;
if (IsFeatureInBlacklist(gfxInfo, feature, &reason.key)) {
reason.info = "Refused to create native OpenGL context because of blacklist"
" entry: ";
reason.info.Append(reason.key);
out_failReasons->push_back(reason);
GenerateWarning(reason.info.BeginReading());
- } else {
- disableNativeGL = false;
+ tryNativeGL = false;
}
}
//////
- gl::CreateContextFlags flags = gl::CreateContextFlags::NO_VALIDATION;
-
- if (forceEnabled) flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
- if (!IsWebGL2()) flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
- if (IsWebGL2()) flags |= gl::CreateContextFlags::PREFER_ES3;
-
- const gl::SurfaceCaps baseCaps = BaseCaps(mOptions, this);
-
- //////
-
- if (!disableNativeGL) {
- const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
-
+ if (tryNativeGL) {
if (useEGL)
return CreateAndInitGLWith(CreateGLWithEGL, baseCaps, flags, out_failReasons);
- bool tryNativeGL = true;
-#ifdef XP_WIN
- if (gfxPrefs::WebGLDisableWGL()) {
- tryNativeGL = false;
- }
-#endif
- if (tryNativeGL) {
- if (CreateAndInitGLWith(CreateGLWithDefault, baseCaps, flags, out_failReasons))
- return true;
- }
+ if (CreateAndInitGLWith(CreateGLWithDefault, baseCaps, flags, out_failReasons))
+ return true;
}
//////
- bool useANGLE = false;
-#ifdef XP_WIN
- const bool disableANGLE = (gfxPrefs::WebGLDisableANGLE() ||
- PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL"));
- useANGLE = !disableANGLE;
-#endif
-
- if (useANGLE)
+ if (tryANGLE)
return CreateAndInitGLWith(CreateGLWithANGLE, baseCaps, flags, out_failReasons);
//////
out_failReasons->push_back(FailureReason("FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS",
"Exhausted GL driver options."));
return false;
}