haikuwebkit/LayoutTests/css3
Wenson Hsieh 08017a6bbb REGRESSION (Safari 15): Unable to repaint canvases with software filters when GPU Process is enabled
https://bugs.webkit.org/show_bug.cgi?id=228682
rdar://79699997

Reviewed by Simon Fraser.

Source/WebCore:

In the case where GPU process is enabled for canvas rendering but is not enabled for DOM rendering, canvas
elements with software CSS filters fail to repaint as the canvas' backing image buffer changes. In this
particular scenario, we first paint the canvas' remotely-backed image buffer into the filter's input buffer,
which is backed by an unaccelerated graphics context. The filter is then applied, producing an output image
buffer which we then paint into the page. The bug occurs during the initial step of painting the contents of the
canvas' remote image buffer into the filter's input context, which involves creating a CGImageRef from the
`ImageBufferCGBackend::draw`.

When asking for a CGImageRef from the canvas' image buffer (which is backed by an IOSurface that's drawn into in
the GPU process), QuartzCore caches the resulting CGImageRef corresponding to the IOSurface handle in the web
process. Subsequently, when we try to repaint the canvas, we'll end up using this same initial cached CGImageRef
because the graphics context of the IOSurface handle in the web process hasn't been drawn into (because all the
actual draw calls are made in the GPU process). As such, regardless of the current state of the canvas' image
buffer, the input to the filter will always be the initial native image created from the canvas' image buffer.

We avoid this problem when GPU process is disabled because the calls to update the canvas' 2D context in the
web process will clear out the cached CGImageRef in QuartzCore. Additionally, we avoid this problem when drawing
into accelerated contexts because QuartzCore will draw the cached CGImageRef using a codepath that reads back
the up-to-date contents from the IOSurface. However, in the QuartzCore's unaccelerated (ripc) image drawing
codepath, we copy the contents of the cached image right away, causing us to end up with stale image data that
does not reflect the current state of the IOSurface.

To work around this in Safari 15 (in both Monterey as well as downlevel versions of macOS), we deploy a similar
technique as we'd previously used in r201334 to invalidate QuartzCore's cached image, but only:

1. If the seed value of the backing IOSurface has changed since the last time we've drawn the image buffer, and
2. The destination context we're painting the image buffer into is unaccelerated.

Test: css3/filters/canvas-with-filter-after-repaint.html

* platform/graphics/cg/ImageBufferCGBackend.cpp:
(WebCore::ImageBufferCGBackend::draw):
(WebCore::ImageBufferCGBackend::drawPattern):

Call into `prepareToDrawIntoContext` (see below).

* platform/graphics/cg/ImageBufferCGBackend.cpp:
(WebCore::ImageBufferCGBackend::prepareToDrawIntoContext):
* platform/graphics/cg/ImageBufferCGBackend.h:
* platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
(WebCore::ImageBufferIOSurfaceBackend::prepareToDrawIntoContext):

Add a new subclassable method on ImageBufferCGBackend that's invoked before drawing the contents of the image
buffer into a given destination GraphicsContext. We use this opportunity in ImageBufferIOSurfaceBackend to
notice if the IOSurface seed count has updated since we've last drawn the image buffer, and intentionally emit a
no-op drawing command (i.e. filling an empty rect) in the graphics context to invalidate QuartzCore's cached
CGImageRef. Note that we only deploy this workaround when drawing into unaccelerated contexts (see above for
more details).

(WebCore::ImageBufferIOSurfaceBackend::invalidateCachedNativeImage const):

Pull the no-op drawing command out into a separate helper method, with a comment describing why this exists.

(WebCore::ImageBufferIOSurfaceBackend::drawConsuming):
(WebCore::ImageBufferIOSurfaceBackend::copyCGImageForEncoding const):
* platform/graphics/cg/ImageBufferIOSurfaceBackend.h:
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(WebCore::IOSurface::seed const):

Add a helper method to grab the seed value of an IOSurface.

LayoutTests:

* css3/filters/canvas-with-filter-after-repaint-expected.html: Added.
* css3/filters/canvas-with-filter-after-repaint.html: Added.


Canonical link: https://commits.webkit.org/240170@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@280543 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-08-02 17:44:26 +00:00
..
background
blending WebKit doesn't parse "#" as delimiter for fragment identifier in data URIs 2020-10-05 19:36:22 +00:00
calc calc() simplification for a multiplication should apply the multiplication to each value of an addition 2021-04-15 21:07:13 +00:00
color [Color] Make gradients work with ExtendedColors 2017-04-26 17:34:50 +00:00
color-filters Runtime-disabled CSS features still appear enabled via CSS.supports() 2021-02-24 16:45:08 +00:00
filters REGRESSION (Safari 15): Unable to repaint canvases with software filters when GPU Process is enabled 2021-08-02 17:44:26 +00:00
flexbox Place vertical scrollbars at (inline/block)-end edge in all writing modes. 2021-04-16 23:55:14 +00:00
images
masking Make RenderLayer::hitTestLayer not assume its renderer is a RenderBox 2021-06-17 00:27:58 +00:00
resources [LayoutTests] Delete unused LayoutTests/css3 resources 2021-06-11 23:22:59 +00:00
scroll-snap [css-scroll-snap] Triggering a layout during scroll causes jittery scrolling on Mac when dragging the scrollbar 2021-07-05 09:21:05 +00:00
support
touch-action Many CSS js-tests use waitUntilDone 2017-05-19 21:19:00 +00:00
viewport-percentage-lengths font-size with viewport units in calc() doesn't change when viewport resizes 2021-04-17 01:08:45 +00:00
autoclose-braces-and-parentheses-expected.txt
autoclose-braces-and-parentheses.html Autoclose braces and parentheses at the end of style sheet 2013-06-11 07:10:00 +00:00
bdi-element-expected.html REGRESSION(r101949): css3/bdi-element.html fails on Lion 2011-12-05 23:57:28 +00:00
bdi-element.html
calculated-word-spacing-expected.txt
calculated-word-spacing.html
css-supports-document-parser-context-expected.txt
css-supports-document-parser-context.html CSS.supports("font-variation-settings", "'wght' 500") erroneously returns false 2016-11-03 03:25:28 +00:00
css-variable-definition-expected.html
css-variable-definition.html
escape-dom-api-expected.txt WebKit has too much of its own UTF-8 code and should rely more on ICU's UTF-8 support 2019-05-01 17:33:03 +00:00
escape-dom-api.html
font-feature-font-face-local-expected.html
font-feature-font-face-local.html
font-feature-settings-calc-expected.html
font-feature-settings-calc.html
font-feature-settings-font-face-rendering-expected.html
font-feature-settings-font-face-rendering.html
font-feature-settings-parsing-expected.txt
font-feature-settings-parsing.html
font-feature-settings-rendering-expected.html Test font-variant-* and font-feature-settings on Yosemite and Mavericks 2015-10-12 19:00:47 +00:00
font-feature-settings-rendering.html
font-feature-settings-stylistic-set-expected-mismatch.html
font-feature-settings-stylistic-set.html
font-synthesis-small-caps-expected.html [Cocoa] Implement font-synthesis: small-caps 2016-12-15 22:12:21 +00:00
font-synthesis-small-caps.html
font-variant-all-expected.html
font-variant-all.html
font-variant-font-face-override-expected.html
font-variant-font-face-override.html
font-variant-parsing-expected.txt CSSOM test for serializing font-variant fails 2021-06-21 18:18:55 +00:00
font-variant-parsing.html CSSOM test for serializing font-variant fails 2021-06-21 18:18:55 +00:00
font-variant-petite-caps-synthesis-expected.html [Font Features] TrueType fonts trigger real features even when synthesis is applied 2015-12-15 21:55:34 +00:00
font-variant-petite-caps-synthesis.html
font-variant-small-caps-synthesis-expected.html
font-variant-small-caps-synthesis.html
font-variant-synthesis-jdaggett-expected.html
font-variant-synthesis-jdaggett.html
font-weight-expected.txt
font-weight-multiple-selectors-expected.txt
font-weight-multiple-selectors.html
font-weight.html
infinite-word-spacing-expected.txt
infinite-word-spacing.html
khtml-background-size-0x0-bmp-expected.txt
khtml-background-size-0x0-bmp.html
out-of-memory-in-css-tokenizer-expected.txt
out-of-memory-in-css-tokenizer.html
overwrite-content-alignment-expected.txt
overwrite-content-alignment.html
overwrite-self-alignment-expected.txt
overwrite-self-alignment.html
parse-align-content-expected.txt
parse-align-content.html
parse-align-items-expected.txt
parse-align-items.html
parse-align-self-expected.txt
parse-align-self.html
parse-alignment-of-root-elements-expected.txt
parse-alignment-of-root-elements.html
parse-justify-content-expected.txt
parse-justify-content.html
parse-place-content-expected.txt
parse-place-content.html
parse-place-items-expected.txt
parse-place-items.html
parse-place-self-expected.txt
parse-place-self.html
parsing-css3-nthchild-expected.txt
parsing-css3-nthchild.html
style-zoomed-image-expected.txt
style-zoomed-image.html
supports-crash-expected.txt
supports-crash.html
supports-cssom-expected.txt DOMException should not have its own toString() 2017-07-19 20:24:15 +00:00
supports-cssom.html
supports-dom-api-expected.txt [css-conditional] The one-string version of CSS.supports should be wrapped in implied parentheses. 2017-06-06 18:27:53 +00:00
supports-dom-api.html
supports-expected.txt Handle custom identifiers and strings separately, so we can quote strings correctly consistently 2021-06-07 02:39:33 +00:00
supports-not-selector-cssom-expected.txt
supports-not-selector-cssom.html
supports-not-selector-expected.html
supports-not-selector.html
supports.html Handle custom identifiers and strings separately, so we can quote strings correctly consistently 2021-06-07 02:39:33 +00:00
unicode-bidi-insolate-parse-expected.txt
unicode-bidi-insolate-parse.html
unicode-bidi-isolate-aharon-expected.html
unicode-bidi-isolate-aharon-failing-expected.html
unicode-bidi-isolate-aharon-failing.html
unicode-bidi-isolate-aharon.html
unicode-bidi-isolate-basic.html
zoom-coords-expected.txt
zoom-coords.xhtml