Skip to content

Commit b0d65d9

Browse files
committed
ImageBitmap with SVG image source does not honor flipY
https://bugs.webkit.org/show_bug.cgi?id=231001 rdar://83959718 Reviewed by Nikolas Zimmermann. SVGImage::draw needs to honor ImagePaintingOptions::orientation() in the hasPlatformContext() case for ImageBitmap's flipY handling to work. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY-expected.txt: * LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY-expected.txt: * LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY-expected.txt: * LayoutTests/platform/mac/TestExpectations: * Source/WebCore/svg/graphics/SVGImage.cpp: (WebCore::SVGImage::draw): Canonical link: https://commits.webkit.org/304137@main
1 parent a979a88 commit b0d65d9

File tree

6 files changed

+47
-36
lines changed

6 files changed

+47
-36
lines changed

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY-expected.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation
88
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
99
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
1010
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
11-
FAIL createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 3 but got 255
12-
FAIL createImageBitmap from a bitmap SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
11+
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
12+
PASS createImageBitmap from a bitmap SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
1313
PASS createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
14-
FAIL createImageBitmap from a vector SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
15-
FAIL createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 3 but got 255
16-
FAIL createImageBitmap from an OffscreenCanvas imageOrientation: "from-image", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
14+
PASS createImageBitmap from a vector SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
15+
PASS createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
16+
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "from-image", and drawImage on the created ImageBitmap
1717
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "flipY", and drawImage on the created ImageBitmap
1818
PASS createImageBitmap from an ImageData imageOrientation: "from-image", and drawImage on the created ImageBitmap
1919
PASS createImageBitmap from an ImageData imageOrientation: "flipY", and drawImage on the created ImageBitmap
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

2-
PASS createImageBitmap from an HTMLCanvasElement imageOrientation: "none", and drawImage on the created ImageBitmap
2+
PASS createImageBitmap from an HTMLCanvasElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
33
PASS createImageBitmap from an HTMLCanvasElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
4-
PASS createImageBitmap from an HTMLVideoElement imageOrientation: "none", and drawImage on the created ImageBitmap
4+
PASS createImageBitmap from an HTMLVideoElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
55
PASS createImageBitmap from an HTMLVideoElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
6-
PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "none", and drawImage on the created ImageBitmap
6+
PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "from-image", and drawImage on the created ImageBitmap
77
PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "flipY", and drawImage on the created ImageBitmap
8-
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap
8+
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
99
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
10-
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap
11-
FAIL createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap assert_approx_equals: Red channel of the pixel at (5, 15) expected 255 +/- 10 but got 0
12-
FAIL createImageBitmap from a bitmap SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
13-
FAIL createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
14-
FAIL createImageBitmap from a vector SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
15-
FAIL createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
16-
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "none", and drawImage on the created ImageBitmap
10+
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
11+
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
12+
PASS createImageBitmap from a bitmap SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
13+
PASS createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
14+
PASS createImageBitmap from a vector SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
15+
PASS createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
16+
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "from-image", and drawImage on the created ImageBitmap
1717
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "flipY", and drawImage on the created ImageBitmap
18-
PASS createImageBitmap from an ImageData imageOrientation: "none", and drawImage on the created ImageBitmap
18+
PASS createImageBitmap from an ImageData imageOrientation: "from-image", and drawImage on the created ImageBitmap
1919
PASS createImageBitmap from an ImageData imageOrientation: "flipY", and drawImage on the created ImageBitmap
20-
PASS createImageBitmap from an ImageBitmap imageOrientation: "none", and drawImage on the created ImageBitmap
20+
PASS createImageBitmap from an ImageBitmap imageOrientation: "from-image", and drawImage on the created ImageBitmap
2121
PASS createImageBitmap from an ImageBitmap imageOrientation: "flipY", and drawImage on the created ImageBitmap
22-
PASS createImageBitmap from a Blob imageOrientation: "none", and drawImage on the created ImageBitmap
22+
PASS createImageBitmap from a Blob imageOrientation: "from-image", and drawImage on the created ImageBitmap
2323
PASS createImageBitmap from a Blob imageOrientation: "flipY", and drawImage on the created ImageBitmap
2424

LayoutTests/platform/ios/TestExpectations

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6902,6 +6902,7 @@ webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/contain-intri
69026902
imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-drawImage.html [ Failure ]
69036903
imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY.html [ Failure ]
69046904

6905+
69056906
webkit.org/b/245588 mathml/presentation/mathvariant-inheritance.html [ ImageOnlyFailure ]
69066907
webkit.org/b/245588 mathml/non-core/fenced-mi.html [ ImageOnlyFailure ]
69076908

Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

2-
PASS createImageBitmap from an HTMLCanvasElement imageOrientation: "none", and drawImage on the created ImageBitmap
2+
PASS createImageBitmap from an HTMLCanvasElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
33
PASS createImageBitmap from an HTMLCanvasElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
4-
PASS createImageBitmap from an HTMLVideoElement imageOrientation: "none", and drawImage on the created ImageBitmap
4+
PASS createImageBitmap from an HTMLVideoElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
55
PASS createImageBitmap from an HTMLVideoElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
6-
PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "none", and drawImage on the created ImageBitmap
6+
PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "from-image", and drawImage on the created ImageBitmap
77
PASS createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "flipY", and drawImage on the created ImageBitmap
8-
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap
8+
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
99
PASS createImageBitmap from a bitmap HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
10-
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap
11-
FAIL createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 3 but got 255
12-
FAIL createImageBitmap from a bitmap SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
13-
FAIL createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
14-
FAIL createImageBitmap from a vector SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
15-
FAIL createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "TypeError: Type error"
16-
FAIL createImageBitmap from an OffscreenCanvas imageOrientation: "none", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: OffscreenCanvas"
17-
FAIL createImageBitmap from an OffscreenCanvas imageOrientation: "flipY", and drawImage on the created ImageBitmap promise_test: Unhandled rejection with value: object "ReferenceError: Can't find variable: OffscreenCanvas"
18-
PASS createImageBitmap from an ImageData imageOrientation: "none", and drawImage on the created ImageBitmap
10+
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
11+
PASS createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
12+
PASS createImageBitmap from a bitmap SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
13+
PASS createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
14+
PASS createImageBitmap from a vector SVGImageElement imageOrientation: "from-image", and drawImage on the created ImageBitmap
15+
PASS createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap
16+
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "from-image", and drawImage on the created ImageBitmap
17+
PASS createImageBitmap from an OffscreenCanvas imageOrientation: "flipY", and drawImage on the created ImageBitmap
18+
PASS createImageBitmap from an ImageData imageOrientation: "from-image", and drawImage on the created ImageBitmap
1919
PASS createImageBitmap from an ImageData imageOrientation: "flipY", and drawImage on the created ImageBitmap
20-
PASS createImageBitmap from an ImageBitmap imageOrientation: "none", and drawImage on the created ImageBitmap
20+
PASS createImageBitmap from an ImageBitmap imageOrientation: "from-image", and drawImage on the created ImageBitmap
2121
PASS createImageBitmap from an ImageBitmap imageOrientation: "flipY", and drawImage on the created ImageBitmap
22-
PASS createImageBitmap from a Blob imageOrientation: "none", and drawImage on the created ImageBitmap
22+
PASS createImageBitmap from a Blob imageOrientation: "from-image", and drawImage on the created ImageBitmap
2323
PASS createImageBitmap from a Blob imageOrientation: "flipY", and drawImage on the created ImageBitmap
2424

LayoutTests/platform/mac/TestExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,6 @@ webkit.org/b/237172 imported/w3c/web-platform-tests/speech-api/SpeechSynthesis-s
18621862

18631863
# Note: These tests were previously marked as flaky failures for Big Sur Release WK2 for webkit.org/b/235681, this may need to be re-added once webkit.org/b/248067 is resolved
18641864
webkit.org/b/248067 imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-drawImage.html [ Pass Failure ]
1865-
webkit.org/b/248067 imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY.html [ Pass Failure ]
18661865

18671866
# Plugins
18681867
# FIXME: Remove these tests.

Source/WebCore/svg/graphics/SVGImage.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ ImageDrawResult SVGImage::draw(GraphicsContext& context, const FloatRect& dstRec
306306
context.setCompositeOperation(CompositeOperator::SourceOver, BlendMode::Normal);
307307
}
308308

309-
// FIXME: We should honor options.orientation(), since ImageBitmap's flipY handling relies on it. https://bugs.webkit.org/show_bug.cgi?id=231001
309+
auto orientation = options.orientation();
310+
// SVG images don't have intrinsic orientation metadata like EXIF, so FromImage defaults to None.
311+
if (orientation == ImageOrientation::Orientation::FromImage)
312+
orientation = ImageOrientation::Orientation::None;
313+
310314
FloatSize scale(dstRect.size() / srcRect.size());
311315

312316
// We can only draw the entire frame, clipped to the rect we want. So compute where the top left
@@ -317,6 +321,13 @@ ImageDrawResult SVGImage::draw(GraphicsContext& context, const FloatRect& dstRec
317321
context.translate(destOffset);
318322
context.scale(scale);
319323

324+
// Apply orientation transformation if needed.
325+
if (orientation != ImageOrientation::Orientation::None) {
326+
auto containerSizeForTransform = containerSize();
327+
auto orientationTransform = ImageOrientation(orientation).transformFromDefault(FloatSize(containerSizeForTransform));
328+
context.concatCTM(orientationTransform);
329+
}
330+
320331
view->resize(containerSize());
321332

322333
{

0 commit comments

Comments
 (0)