Restrict the total combined size of backdrop filters
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Sep 2018 05:37:01 +0000 (05:37 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Sep 2018 05:37:01 +0000 (05:37 +0000)
commit8efbdf1b4d676e10ee50ba05c55799572c67b40e
treea354c9c8f8750d626a6552a489f6c653c55db0b3
parent45a3c2b24fe0d9c54c1786cb5ab33bb56cb9884b
Restrict the total combined size of backdrop filters
https://bugs.webkit.org/show_bug.cgi?id=189812
<rdar://problem/44532782>

Reviewed by Simon Fraser.

Source/WebCore:

If the total area of all backdrop filters on the page gets
too large, the universe collapses in on itself and we enter
the Quantum Realm (i.e. crash horribly).

Put a hard limit on the total coverage, and ignore any backdrop
filters after the limit. This might break some content, but
such content is likely not doing things in the most optimal manner.
There isn't any reason to have a backdrop larger than the size of
the screen, because you'd be better off applying a foreground
filter to the main content and showing something above it.

Tests: css3/filters/backdrop/resource-use-add-more-layers.html
       css3/filters/backdrop/resource-use-excessive.html
       css3/filters/backdrop/resource-use-ok.html
       css3/filters/backdrop/resource-use-remove-some-layers.html

* platform/graphics/ca/GraphicsLayerCA.cpp: Pick a fairly small maximum size. We
can consider increasing this if necessary, and as devices with less RAM are
upgraded.
(WebCore::GraphicsLayerCA::recursiveCommitChanges): Gather the accumulated size
of backdrop filters into the commit state as we are recursing through the tree.
(WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers): Force any layer
with backdrop filters, or any that is removing backdrop filters, into an update.
(WebCore::GraphicsLayerCA::updateBackdropFilters): Update the logic to first
check if this backdrop layer causes us to exceed the total allowed size, and if
it does, forbid it from getting the GraphicsLayer that composits the backdrop.

* platform/graphics/ca/GraphicsLayerCA.h: Remove const from some parameters so
that we can use the CommitState to hold the accumulated size.

LayoutTests:

Tests that have an acceptable number of backdrops, an excessive
number of backdrops, and then some that add and remove backdrops
at various points in the tree to confirm we do recursive checks
correctly.

* css3/filters/backdrop/layer-tree-as-text.js: Added.
* css3/filters/backdrop/resource-use-add-more-layers-expected.txt: Added.
* css3/filters/backdrop/resource-use-add-more-layers.html: Added.
* css3/filters/backdrop/resource-use-excessive-expected.txt: Added.
* css3/filters/backdrop/resource-use-excessive.html: Added.
* css3/filters/backdrop/resource-use-ok-expected.txt: Added.
* css3/filters/backdrop/resource-use-ok.html: Added.
* css3/filters/backdrop/resource-use-remove-some-layers-expected.txt: Added.
* css3/filters/backdrop/resource-use-remove-some-layers.html: Added.
* css3/filters/backdrop/resource-use.css: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
LayoutTests/ChangeLog
LayoutTests/css3/filters/backdrop/layer-tree-as-text.js [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-add-more-layers-expected.txt [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-add-more-layers.html [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-excessive-expected.txt [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-excessive.html [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-ok-expected.txt [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-ok.html [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-remove-some-layers-expected.txt [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use-remove-some-layers.html [new file with mode: 0644]
LayoutTests/css3/filters/backdrop/resource-use.css [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h