Skip to content

[HDR] Use ExtendedDisplayP3 as the HDR backing store colorSpace on iOS #47313

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

Conversation

shallawa
Copy link
Contributor

@shallawa shallawa commented Jun 27, 2025

c52a198

[HDR] Use ExtendedDisplayP3 as the HDR backing store colorSpace on iOS
https://bugs.webkit.org/show_bug.cgi?id=295118
rdar://153919243

Reviewed by Mike Wyrzykowski and Simon Fraser.

For compositing HDR drawing on macOS, the DisplayColorSpace should be used to
avoid extra colorSpace conversion.

For compositing HDR drawing on iOS, using ExtendedDisplayP3 ensures any blending
operations happen in the same gamma space as the compositor.

For non compositing HDR drawing, ExtendedDisplayP3 will be used for everything
else on macOS and iOS.

* Source/WebCore/platform/graphics/ContentsFormat.cpp:
(WebCore::contentsFormatExtendedColorSpace):

Canonical link: https://commits.webkit.org/296814@main

2364e58

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@shallawa shallawa self-assigned this Jun 27, 2025
@shallawa shallawa added the Images For bugs in image handling. label Jun 27, 2025
@shallawa shallawa force-pushed the eng/HDR-Use-ExtendedDisplayP3-as-the-HDR-backing-store-colorSpace-on-iOS branch from 340e1ff to 0125679 Compare June 27, 2025 18:36
@weinig
Copy link
Contributor

weinig commented Jun 27, 2025

Can you expand on how a color space affects tone mapping? Commonly, it is only the headroom that has affect as all changing from extended SRGB to extended P3 does is change the coordinate space.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 27, 2025
@shallawa
Copy link
Contributor Author

Can you expand on how a color space affects tone mapping? Commonly, it is only the headroom that has affect as all changing from extended SRGB to extended P3 does is change the coordinate space.

I really do not know the difference between the tone-mapping to SRGB versus the tone-mapping to P3 on iOS. This was recommended internally by macOS system frameworks teams. I think iOS might have tone-mapping calculations tuned for P3 better than it for SRGB.

@shallawa shallawa requested review from weinig, smfr and heycam June 27, 2025 22:08
@@ -45,7 +42,11 @@ std::optional<DestinationColorSpace> contentsFormatExtendedColorSpace(ContentsFo
#endif
#if ENABLE(PIXEL_FORMAT_RGBA16F) && ENABLE(DESTINATION_COLOR_SPACE_EXTENDED_REC_2020)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you stop using Rec2020 below it's' weird to still have this #if ...DESTINATION_COLOR_SPACE_EXTENDED_REC_2020

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@shallawa shallawa removed the merging-blocked Applied to prevent a change from being merged label Jun 27, 2025
@shallawa shallawa force-pushed the eng/HDR-Use-ExtendedDisplayP3-as-the-HDR-backing-store-colorSpace-on-iOS branch from 0125679 to 08ec995 Compare June 27, 2025 23:09
@weinig
Copy link
Contributor

weinig commented Jun 27, 2025

Given this can give different results, this feels like something we should be really clear on. I think before changing this kind of thing, getting more details on exactly what is different, and making sure those differences are tested, makes sense.

@weinig
Copy link
Contributor

weinig commented Jun 27, 2025

Also, if macOS and iOS are giving different results, that seems like a bad thing, no?

@weinig
Copy link
Contributor

weinig commented Jun 27, 2025

ExtendedDisplayP3 produces better tone-mapping to SDR on iOS. On iOS we have to
explicitly choose the backing store colorSpace.

The PR also changes things to use ExtendedSRGB on all other platforms, instead of ExtendedRec2020, so the commit message should state that.

@shallawa shallawa force-pushed the eng/HDR-Use-ExtendedDisplayP3-as-the-HDR-backing-store-colorSpace-on-iOS branch from 08ec995 to 2364e58 Compare June 28, 2025 00:25
@shallawa
Copy link
Contributor Author

ExtendedDisplayP3 produces better tone-mapping to SDR on iOS. On iOS we have to
explicitly choose the backing store colorSpace.

The PR also changes things to use ExtendedSRGB on all other platforms, instead of ExtendedRec2020, so the commit message should state that.

I changed the PR to use ExtendedDisplayP3 for all non compositing scenarios on macOS and for everything on iOS. I think ExtendedDisplayP3 should be fine for all drawing except the compositing drawing on macOS.

@shallawa
Copy link
Contributor Author

Also, if macOS and iOS are giving different results, that seems like a bad thing, no?

On macOS, we rely on one of two things to get the colorSpace of the backing stores:

  1. NSScreen by calling [NSScreen mainScreen].colorSpace
  2. NSView by calling [[m_view window] colorSpace]

NSScreen and NSView are available only on macOS. So on iOS we have to use a predefined colorSpace. This has been the behavior for many years.

I am not aware of a more robust way to calculate the colorSpace on iOS. Please let me know if there is a better way to do that.

@shallawa
Copy link
Contributor Author

Given this can give different results, this feels like something we should be really clear on. I think before changing this kind of thing, getting more details on exactly what is different, and making sure those differences are tested, makes sense.

There is no real technical reason for choosing ExtendedRec2020 for HDR on iOS. I just tried it when I added the support for HDR and things seem to work. I used by eyes to compare the display on macOS and on iOS and I did not notice any significant difference.

The recommendation was to use an extended color for HDR backing store so I chose ExtendedRec2020. I even used it for both macOS and iOS at the beginning. Then I changed it on macOS to use the DisplayColorSpace. Then I changed again it to the CGColorSpaceCreateExtended of the DisplayColorSpace.

Recently we received reports about differences in the display between macOS and iOS when displaying gain-map images and when tone-mapping HDR images to SDR images.

@mwyrzykowski
Copy link
Contributor

Can you expand on how a color space affects tone mapping? Commonly, it is only the headroom that has affect as all changing from extended SRGB to extended P3 does is change the coordinate space.

I really do not know the difference between the tone-mapping to SRGB versus the tone-mapping to P3 on iOS. This was recommended internally by macOS system frameworks teams. I think iOS might have tone-mapping calculations tuned for P3 better than it for SRGB.

System tonemapping is not applied for non-extended color spaces.

@shallawa shallawa added the merge-queue Applied to send a pull request to merge-queue label Jun 30, 2025
@webkit-commit-queue webkit-commit-queue force-pushed the eng/HDR-Use-ExtendedDisplayP3-as-the-HDR-backing-store-colorSpace-on-iOS branch from 2364e58 to 5fe83f4 Compare June 30, 2025 18:26
https://bugs.webkit.org/show_bug.cgi?id=295118
rdar://153919243

Reviewed by Mike Wyrzykowski and Simon Fraser.

For compositing HDR drawing on macOS, the DisplayColorSpace should be used to
avoid extra colorSpace conversion.

For compositing HDR drawing on iOS, using ExtendedDisplayP3 ensures any blending
operations happen in the same gamma space as the compositor.

For non compositing HDR drawing, ExtendedDisplayP3 will be used for everything
else on macOS and iOS.

* Source/WebCore/platform/graphics/ContentsFormat.cpp:
(WebCore::contentsFormatExtendedColorSpace):

Canonical link: https://commits.webkit.org/296814@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/HDR-Use-ExtendedDisplayP3-as-the-HDR-backing-store-colorSpace-on-iOS branch from 5fe83f4 to c52a198 Compare June 30, 2025 18:28
@webkit-commit-queue
Copy link
Collaborator

Committed 296814@main (c52a198): https://commits.webkit.org/296814@main

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

@webkit-commit-queue webkit-commit-queue merged commit c52a198 into WebKit:main Jun 30, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Images For bugs in image handling.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants