Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert HDR video frames to SDR when drawing to canvas #4725

Merged

Conversation

heycam
Copy link
Contributor

@heycam heycam commented Sep 26, 2022

adb0798

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

a8c03e8

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios   πŸ›  mac   πŸ›  wpe   πŸ›  πŸ§ͺ win
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim   πŸ›  mac-debug βœ… πŸ›  gtk   πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ›  mac-AS-debug   πŸ§ͺ gtk-wk2
  πŸ§ͺ api-ios   πŸ§ͺ api-mac   πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ jsc βœ… πŸ›  tv   πŸ§ͺ mac-wk1 βœ… πŸ›  jsc-armv7
βœ… πŸ›  tv-sim   πŸ§ͺ mac-wk2 βœ… πŸ§ͺ jsc-armv7-tests
  πŸ›  πŸ§ͺ merge βœ… πŸ›  watch   πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ›  jsc-mips
βœ… πŸ›  πŸ§ͺ unsafe-merge βœ… πŸ›  watch-sim   πŸ§ͺ mac-wk2-stress ❌ πŸ§ͺ jsc-mips-tests

@heycam heycam self-assigned this Sep 26, 2022
@heycam heycam added Media Bugs related to the HTML 5 Media elements. Other labels Sep 26, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 26, 2022
@heycam heycam removed the merging-blocked Applied to prevent a change from being merged label Sep 26, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 27, 2022
@heycam heycam removed the merging-blocked Applied to prevent a change from being merged label Sep 27, 2022
@heycam heycam added merge-queue Applied to send a pull request to merge-queue unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merge-queue Applied to send a pull request to merge-queue labels Sep 28, 2022
@webkit-commit-queue
Copy link
Collaborator

Committed 254973@main (adb0798): https://commits.webkit.org/254973@main

Reviewed commits have been landed. Closing PR #4725 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit adb0798 into WebKit:main Sep 28, 2022
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
5 participants