Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Convert HDR video frames to SDR when drawing to canvas
https://bugs.webkit.org/show_bug.cgi?id=240972 rdar://98692644 Reviewed by Jer Noble. Core Animation has a bug with accelerated rendering where drawing an image with HDR color space metadata does not correctly tone map the image. To work around this, we perform our own color space conversion of the image to the destination color space in this case. By using CGIOSurfaceContextGetSurface, we limit this workaround to CGContexts that are backed by an IOSurface (and so use accelerated drawing). Doing this color space conversion inside GraphicsContextCG::drawNativeImage means that we'll do it each time the image is drawn. Ideally this would only be done once for a given { CGImage, DestinationColorSpace } pair. * LayoutTests/fast/canvas/canvas-drawImage-hdr-video-expected.txt: Added. * LayoutTests/fast/canvas/canvas-drawImage-hdr-video.html: Added. * LayoutTests/fast/canvas/resources/hdr.mp4: Added. * LayoutTests/platform/gtk/fast/canvas/canvas-drawImage-hdr-video-expected.txt: Added. * Source/WTF/wtf/PlatformHave.h: * Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h: * Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp: (WebCore::GraphicsContextCG::drawNativeImage): * Source/WebCore/platform/graphics/cg/GraphicsContextCG.h: * Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm: (WebCore::GraphicsContextCG::convertToDestinationColorSpaceIfNeeded): * Source/WebCore/platform/graphics/cocoa/IOSurface.h: * Source/WebCore/platform/graphics/cocoa/IOSurface.mm: (WebCore::IOSurface::bitmapConfiguration const): (WebCore::IOSurface::createCompatibleBitmap): (WebCore::IOSurface::ensurePlatformContext): * Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp: (WebCore::GraphicsContextCG::convertToDestinationColorSpaceIfNeeded): Canonical link: https://commits.webkit.org/254973@main
- Loading branch information
Showing
13 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pixel at 1920,540: 0,174,0,255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
<script src="../../media/utilities.js"></script> | ||
<pre id=log></pre> | ||
<script> | ||
if (window.testRunner) { | ||
testRunner.dumpAsText(); | ||
testRunner.waitUntilDone(); | ||
} | ||
|
||
let video = document.createElement("video"); | ||
|
||
waitForVideoFrame(video, async function() { | ||
let canvas = document.createElement("canvas"); | ||
canvas.width = 3840; | ||
canvas.height = 2160; | ||
|
||
let ctx = canvas.getContext("2d"); | ||
ctx.drawImage(video, 0, 0); | ||
|
||
let x = 1920; | ||
let y = 540; | ||
|
||
let data = ctx.getImageData(x, y, 1, 1).data; | ||
log.textContent = `Pixel at ${x},${y}: ${[...data]}`; | ||
|
||
if (window.testRunner) | ||
testRunner.notifyDone(); | ||
}); | ||
|
||
video.src = "resources/hdr.mp4"; | ||
</script> |
BIN
+56.9 KB
LayoutTests/fast/canvas/resources/hdr.mp4
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pixel at 1920,540: 16,223,6,255 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters