Bug 1164970 - Implement failIfMajorPerformanceCaveat. r=jgilbert, r=ehsan

--HG--
extra : rebase_source : c609118df9618795a1c84a7f5749979ad8f9aa68
This commit is contained in:
Kyle Fung 2015-05-21 11:51:49 -04:00
Родитель 20e13e1c8b
Коммит 66c7e91d64
5 изменённых файлов: 44 добавлений и 1 удалений

Просмотреть файл

@ -194,6 +194,7 @@ WebGLContextOptions::WebGLContextOptions()
, premultipliedAlpha(true)
, antialias(true)
, preserveDrawingBuffer(false)
, failIfMajorPerformanceCaveat(false)
{
// Set default alpha state based on preference.
if (Preferences::GetBool("webgl.default-no-alpha", false))
@ -431,6 +432,7 @@ WebGLContext::SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options)
newOpts.premultipliedAlpha = attributes.mPremultipliedAlpha;
newOpts.antialias = attributes.mAntialias;
newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer;
newOpts.failIfMajorPerformanceCaveat = attributes.mFailIfMajorPerformanceCaveat;
if (attributes.mAlpha.WasPassed())
newOpts.alpha = attributes.mAlpha.Value();
@ -500,6 +502,30 @@ IsFeatureInBlacklist(const nsCOMPtr<nsIGfxInfo>& gfxInfo, int32_t feature)
return status != nsIGfxInfo::FEATURE_STATUS_OK;
}
static bool
HasAcceleratedLayers(const nsCOMPtr<nsIGfxInfo>& gfxInfo)
{
int32_t status;
gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS, &status);
if (status)
return true;
gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_10_LAYERS, &status);
if (status)
return true;
gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_10_1_LAYERS, &status);
if (status)
return true;
gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS, &status);
if (status)
return true;
gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &status);
if (status)
return true;
return false;
}
static already_AddRefed<GLContext>
CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
bool requireCompatProfile, WebGLContext* webgl)
@ -569,7 +595,6 @@ CreateHeadlessEGL(bool forceEnabled, bool requireCompatProfile,
return gl.forget();
}
static already_AddRefed<GLContext>
CreateHeadlessGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
WebGLContext* webgl)
@ -873,6 +898,18 @@ WebGLContext::SetDimensions(int32_t signedWidth, int32_t signedHeight)
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
bool failIfMajorPerformanceCaveat =
!gfxPrefs::WebGLDisableFailIfMajorPerformanceCaveat() &&
!HasAcceleratedLayers(gfxInfo);
if (failIfMajorPerformanceCaveat) {
Nullable<dom::WebGLContextAttributes> contextAttributes;
this->GetContextAttributes(contextAttributes);
if (contextAttributes.Value().mFailIfMajorPerformanceCaveat) {
return NS_ERROR_FAILURE;
}
}
// Alright, now let's start trying.
bool forceEnabled = Preferences::GetBool("webgl.force-enabled", false);
ScopedGfxFeatureReporter reporter("WebGL", forceEnabled);
@ -1255,6 +1292,7 @@ WebGLContext::GetContextAttributes(Nullable<dom::WebGLContextAttributes>& retval
result.mAntialias = mOptions.antialias;
result.mPremultipliedAlpha = mOptions.premultipliedAlpha;
result.mPreserveDrawingBuffer = mOptions.preserveDrawingBuffer;
result.mFailIfMajorPerformanceCaveat = mOptions.failIfMajorPerformanceCaveat;
}
/* [noscript] DOMString mozGetUnderlyingParamString(in GLenum pname); */

Просмотреть файл

@ -128,6 +128,7 @@ struct WebGLContextOptions
bool premultipliedAlpha;
bool antialias;
bool preserveDrawingBuffer;
bool failIfMajorPerformanceCaveat;
};
// From WebGLContextUtils

Просмотреть файл

@ -41,6 +41,7 @@ dictionary WebGLContextAttributes {
boolean antialias = true;
boolean premultipliedAlpha = true;
boolean preserveDrawingBuffer = false;
boolean failIfMajorPerformanceCaveat = false;
};
interface WebGLBuffer {

Просмотреть файл

@ -368,6 +368,8 @@ private:
DECL_GFX_PREF(Live, "ui.click_hold_context_menus.delay", UiClickHoldContextMenusDelay, int32_t, 500);
DECL_GFX_PREF(Once, "webgl.angle.force-d3d11", WebGLANGLEForceD3D11, bool, false);
DECL_GFX_PREF(Once, "webgl.angle.try-d3d11", WebGLANGLETryD3D11, bool, false);
DECL_GFX_PREF(Live, "webgl.disable-fail-if-major-performance-caveat",
WebGLDisableFailIfMajorPerformanceCaveat, bool, false);
DECL_GFX_PREF(Once, "webgl.force-layers-readback", WebGLForceLayersReadback, bool, false);
// WARNING:

Просмотреть файл

@ -4001,6 +4001,7 @@ pref("webgl.enable-draft-extensions", false);
pref("webgl.enable-privileged-extensions", false);
pref("webgl.bypass-shader-validation", false);
pref("webgl.enable-prototype-webgl2", false);
pref("webgl.disable-fail-if-major-performance-caveat", false);
pref("gl.require-hardware", false);
#ifdef XP_WIN