Skip to content

Commit 3cd3cc6

Browse files
committed
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
1 parent a9d7165 commit 3cd3cc6

File tree

6 files changed

+64
-8
lines changed

6 files changed

+64
-8
lines changed

dom/bindings/GenerateCSS2PropertiesWebIDL.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ def generate(output, idlFilename, dataFile):
2323
# (e.g. on nsComputedDOMStyle).
2424
extendedAttrs = ["CEReactions", "Throws",
2525
"SetterNeedsSubjectPrincipal=NonSystem"]
26+
2627
if p.pref != "":
27-
extendedAttrs.append('Pref="%s"' % p.pref)
28+
# BackdropFilter is a special case where we want WebIDL to check
29+
# a function instead of checking the pref directly.
30+
if p.method == "BackdropFilter":
31+
extendedAttrs.append('Func="nsCSSProps::IsBackdropFilterAvailable"')
32+
else:
33+
extendedAttrs.append('Pref="%s"' % p.pref)
2834

2935
prop = p.method
3036

gfx/thebes/gfxPlatform.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ static void FrameRatePrefChanged(const char* aPref, void*) {
807807
}
808808
}
809809

810+
static void RecomputeBackdropFilterEnabledState() {
811+
NS_DispatchToMainThread(NS_NewRunnableFunction("RecomputeEnabledState", [] {
812+
nsCSSProps::RecomputeEnabledState("layout.css.backdrop-filter.enabled");
813+
}));
814+
}
815+
810816
void gfxPlatform::Init() {
811817
MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
812818
MOZ_RELEASE_ASSERT(!XRE_IsRDDProcess(), "GFX: Not allowed in RDD process.");
@@ -1078,6 +1084,8 @@ void gfxPlatform::Init() {
10781084
if (obs) {
10791085
obs->NotifyObservers(nullptr, "gfx-features-ready", nullptr);
10801086
}
1087+
1088+
RecomputeBackdropFilterEnabledState();
10811089
}
10821090

10831091
void gfxPlatform::ReportTelemetry() {
@@ -3278,8 +3286,9 @@ void gfxPlatform::NotifyGPUProcessDisabled() {
32783286
FeatureStatus::Unavailable, "GPU Process is disabled",
32793287
NS_LITERAL_CSTRING("FEATURE_FAILURE_GPU_PROCESS_DISABLED"));
32803288
gfxVars::SetUseWebRender(false);
3281-
}
32823289

3290+
RecomputeBackdropFilterEnabledState();
3291+
}
32833292
gfxVars::SetRemoteCanvasEnabled(false);
32843293
}
32853294

layout/style/nsCSSProps.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include "mozilla/ArrayUtils.h"
1515
#include "mozilla/Casting.h"
1616

17+
#include "gfxPlatform.h"
1718
#include "nsLayoutUtils.h"
1819
#include "nsIWidget.h"
1920
#include "nsStyleConsts.h" // For system widget appearance types
2021

2122
#include "mozilla/dom/Animation.h"
2223
#include "mozilla/dom/AnimationEffectBinding.h" // for PlaybackDirection
24+
#include "mozilla/gfx/gfxVars.h" // for UseWebRender
2325
#include "mozilla/LookAndFeel.h" // for system colors
2426

2527
#include "nsString.h"
@@ -63,12 +65,19 @@ static nsStaticCaseInsensitiveNameTable* CreateStaticTable(
6365
}
6466

6567
void nsCSSProps::RecomputeEnabledState(const char* aPref, void*) {
68+
bool foundPref = false;
6669
for (const PropertyPref* pref = kPropertyPrefTable;
6770
pref->mPropID != eCSSProperty_UNKNOWN; pref++) {
6871
if (!aPref || !strcmp(aPref, pref->mPref)) {
72+
foundPref = true;
6973
gPropertyEnabled[pref->mPropID] = Preferences::GetBool(pref->mPref);
74+
if (pref->mPropID == eCSSProperty_backdrop_filter) {
75+
gPropertyEnabled[pref->mPropID] &=
76+
gfxPlatform::Initialized() && gfx::gfxVars::UseWebRender();
77+
}
7078
}
7179
}
80+
MOZ_ASSERT(foundPref);
7281
}
7382

7483
void nsCSSProps::AddRefTable(void) {

layout/style/nsCSSProps.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ class nsCSSProps {
117117
}
118118

119119
private:
120+
// A table for shorthand properties. The appropriate index is the
121+
// property ID minus eCSSProperty_COUNT_no_shorthands.
122+
static const nsCSSPropertyID* const
123+
kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
124+
125+
public:
126+
/**
127+
* Returns true if the backdrop-filter pref and WebRender are enabled.
128+
*/
129+
static bool IsBackdropFilterAvailable(JSContext*, JSObject*) {
130+
return IsEnabled(eCSSProperty_backdrop_filter);
131+
}
132+
120133
/**
121134
* Recoumputes the enabled state of a pref. If aPrefName is nullptr,
122135
* recomputes the state of all prefs in gPropertyEnabled.
@@ -125,12 +138,6 @@ class nsCSSProps {
125138
static void RecomputeEnabledState(const char* aPrefName,
126139
void* aClosure = nullptr);
127140

128-
// A table for shorthand properties. The appropriate index is the
129-
// property ID minus eCSSProperty_COUNT_no_shorthands.
130-
static const nsCSSPropertyID* const
131-
kSubpropertyTable[eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands];
132-
133-
public:
134141
static const nsCSSPropertyID* SubpropertyEntryFor(nsCSSPropertyID aProperty) {
135142
MOZ_ASSERT(eCSSProperty_COUNT_no_shorthands <= aProperty &&
136143
aProperty < eCSSProperty_COUNT,

layout/style/test/mochitest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ support-files = file_animations_with_disabled_properties.html
8585
[test_asyncopen.html]
8686
[test_at_rule_parse_serialize.html]
8787
[test_attribute_selector_eof_behavior.html]
88+
[test_backdrop_filter_enabled_state.html]
8889
[test_background_blend_mode.html]
8990
[test_border_device_pixel_rounding_initial_style.html]
9091
[test_box_size_keywords.html]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE HTML>
2+
<head>
3+
<meta charset=utf-8>
4+
<title>Test Backdrop-Filter Enabled State</title>
5+
<link rel="author" title="Erik Nordin" href="mailto:nordzilla@mozilla.com">
6+
<script src="/tests/SimpleTest/SimpleTest.js"></script>
7+
</head>
8+
<script>
9+
SimpleTest.waitForExplicitFinish();
10+
11+
const webRenderEnabled = SpecialPowers.Cc["@mozilla.org/gfx/info;1"].getService(
12+
SpecialPowers.Ci.nsIGfxInfo
13+
).WebRenderEnabled;
14+
15+
(async function() {
16+
for (let enabled of [true, false]) {
17+
await SpecialPowers.pushPrefEnv({"set": [["layout.css.backdrop-filter.enabled", enabled]]});
18+
is(webRenderEnabled && enabled, CSS.supports("backdrop-filter: initial"),
19+
"backdrop-filter is available only if backdrop-filter pref is set and WebRender is enabled");
20+
}
21+
SimpleTest.finish();
22+
}());
23+
24+
</script>

0 commit comments

Comments
 (0)