Bug 1635584 - Make BackdropFilter's Availability Depend on WebRender r=emilio

- Enable BackdropFilter pref by default
  - Add function IsBackdropFilterAavailable()
  - Use IsBackdropFilterAvailable for relevant WebIDL instead of pref
  - Add test for BackdropFilter availability

Differential Revision: https://phabricator.services.mozilla.com/D73967
This commit is contained in:
Erik Nordin 2020-05-08 05:54:26 +00:00
parent 2f59dd5fb1
commit f10166a614
6 changed files with 65 additions and 8 deletions

View File

@ -23,8 +23,14 @@ def generate(output, idlFilename, dataFile):
# (e.g. on nsComputedDOMStyle).
extendedAttrs = ["CEReactions", "Throws",
"SetterNeedsSubjectPrincipal=NonSystem"]
if p.pref != "":
extendedAttrs.append('Pref="%s"' % p.pref)
# BackdropFilter is a special case where we want WebIDL to check
# a function instead of checking the pref directly.
if p.method == "BackdropFilter":
extendedAttrs.append('Func="nsCSSProps::IsBackdropFilterAvailable"')
else:
extendedAttrs.append('Pref="%s"' % p.pref)
prop = p.method

View File

@ -807,6 +807,12 @@ static void FrameRatePrefChanged(const char* aPref, void*) {
}
}
static void RecomputeBackdropFilterEnabledState() {
NS_DispatchToMainThread(NS_NewRunnableFunction("RecomputeEnabledState", [] {
nsCSSProps::RecomputeEnabledState("layout.css.backdrop-filter.enabled");
}));
}
void gfxPlatform::Init() {
MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
MOZ_RELEASE_ASSERT(!XRE_IsRDDProcess(), "GFX: Not allowed in RDD process.");
@ -1078,6 +1084,8 @@ void gfxPlatform::Init() {
if (obs) {
obs->NotifyObservers(nullptr, "gfx-features-ready", nullptr);
}
RecomputeBackdropFilterEnabledState();
}
void gfxPlatform::ReportTelemetry() {
@ -3278,8 +3286,9 @@ void gfxPlatform::NotifyGPUProcessDisabled() {
FeatureStatus::Unavailable, "GPU Process is disabled",
NS_LITERAL_CSTRING("FEATURE_FAILURE_GPU_PROCESS_DISABLED"));
gfxVars::SetUseWebRender(false);
}
RecomputeBackdropFilterEnabledState();
}
gfxVars::SetRemoteCanvasEnabled(false);
}

View File

@ -14,12 +14,14 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/Casting.h"
#include "gfxPlatform.h"
#include "nsLayoutUtils.h"
#include "nsIWidget.h"
#include "nsStyleConsts.h" // For system widget appearance types
#include "mozilla/dom/Animation.h"
#include "mozilla/dom/AnimationEffectBinding.h" // for PlaybackDirection
#include "mozilla/gfx/gfxVars.h" // for UseWebRender
#include "mozilla/LookAndFeel.h" // for system colors
#include "nsString.h"
@ -63,12 +65,19 @@ static nsStaticCaseInsensitiveNameTable* CreateStaticTable(
}
void nsCSSProps::RecomputeEnabledState(const char* aPref, void*) {
DebugOnly<bool> foundPref = false;
for (const PropertyPref* pref = kPropertyPrefTable;
pref->mPropID != eCSSProperty_UNKNOWN; pref++) {
if (!aPref || !strcmp(aPref, pref->mPref)) {
foundPref = true;
gPropertyEnabled[pref->mPropID] = Preferences::GetBool(pref->mPref);
if (pref->mPropID == eCSSProperty_backdrop_filter) {
gPropertyEnabled[pref->mPropID] &=
gfxPlatform::Initialized() && gfx::gfxVars::UseWebRender();
}
}
}
MOZ_ASSERT(foundPref);
}
void nsCSSProps::AddRefTable(void) {

View File

@ -117,6 +117,19 @@ class nsCSSProps {
}
private:
// A table for shorthand properties. The appropriate index is the
// property ID minus eCSSProperty_COUNT_no_shorthands.
static const nsCSSPropertyID* const
kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
public:
/**
* Returns true if the backdrop-filter pref and WebRender are enabled.
*/
static bool IsBackdropFilterAvailable(JSContext*, JSObject*) {
return IsEnabled(eCSSProperty_backdrop_filter);
}
/**
* Recoumputes the enabled state of a pref. If aPrefName is nullptr,
* recomputes the state of all prefs in gPropertyEnabled.
@ -125,12 +138,6 @@ class nsCSSProps {
static void RecomputeEnabledState(const char* aPrefName,
void* aClosure = nullptr);
// A table for shorthand properties. The appropriate index is the
// property ID minus eCSSProperty_COUNT_no_shorthands.
static const nsCSSPropertyID* const
kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
public:
static const nsCSSPropertyID* SubpropertyEntryFor(nsCSSPropertyID aProperty) {
MOZ_ASSERT(eCSSProperty_COUNT_no_shorthands <= aProperty &&
aProperty < eCSSProperty_COUNT,

View File

@ -85,6 +85,7 @@ support-files = file_animations_with_disabled_properties.html
[test_asyncopen.html]
[test_at_rule_parse_serialize.html]
[test_attribute_selector_eof_behavior.html]
[test_backdrop_filter_enabled_state.html]
[test_background_blend_mode.html]
[test_border_device_pixel_rounding_initial_style.html]
[test_box_size_keywords.html]

View File

@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<head>
<meta charset=utf-8>
<title>Test Backdrop-Filter Enabled State</title>
<link rel="author" title="Erik Nordin" href="mailto:nordzilla@mozilla.com">
<script src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<script>
SimpleTest.waitForExplicitFinish();
const webRenderEnabled = SpecialPowers.Cc["@mozilla.org/gfx/info;1"].getService(
SpecialPowers.Ci.nsIGfxInfo
).WebRenderEnabled;
(async function() {
for (let enabled of [true, false]) {
await SpecialPowers.pushPrefEnv({"set": [["layout.css.backdrop-filter.enabled", enabled]]});
is(webRenderEnabled && enabled, CSS.supports("backdrop-filter: initial"),
"backdrop-filter is available only if backdrop-filter pref is set and WebRender is enabled");
}
SimpleTest.finish();
}());
</script>