Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d6203e5d590d1c6378593373a9f70ef210e86829
      
https://github.com/WebKit/WebKit/commit/d6203e5d590d1c6378593373a9f70ef210e86829
  Author: Simon Fraser <[email protected]>
  Date:   2026-01-26 (Mon, 26 Jan 2026)

  Changed paths:
    M LayoutTests/TestExpectations
    A 
LayoutTests/compositing/background-color/background-color-clamping-expected.txt
    A LayoutTests/compositing/background-color/background-color-clamping.html
    M LayoutTests/platform/ios/TestExpectations
    A 
LayoutTests/platform/ios/compositing/background-color/background-color-clamping-expected.txt
    M LayoutTests/platform/mac/TestExpectations
    M Source/WebCore/Configurations/AllowedSPI-legacy.toml
    M Source/WebCore/Configurations/AllowedSPI.toml
    M Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h
    M Source/WebCore/platform/graphics/Color.h
    M Source/WebCore/platform/graphics/ColorConversion.h
    M Source/WebCore/platform/graphics/cg/ColorCG.cpp
    M Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
    M Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorder.cpp
    M Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorder.h
    M Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
    M Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
    M Source/WebKit/UIProcess/PageClient.h
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/UIProcess/ios/PageClientImplIOS.h
    M Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
    M Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
    M Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm

  Log Message:
  -----------
  REGRESSION (297279@main): P3 colors can be mismatched between painted 
content, and layer backgrounds (see on book.stevejobsarchive.com).
https://bugs.webkit.org/show_bug.cgi?id=305683
rdar://166725679

Reviewed by Sam Weinig.

https://book.stevejobsarchive.com used a display-p3 color in CSS, and this was 
used both
for painted backgrounds, and for "simple container" layers where we set it as 
layer.backgroundColor.

This bug was introduced by 297279@main, which added clamping of the colors in 
the painting
path to sRGB, but not in the layer backgroundColor path, which also caused 
colors to no longer
paint as P3.

The fix is to convert out-of-line colors into a clamping colorspace, which is 
DisplayP3 if
the output colorspace is wide gamut, or SRGB. This happens only before colors 
go into the cache,
so is not super hot code. We also need to used the clamped color for layer 
background colors in
`RemoteLayerTreePropertyApplier::applyPropertiesToLayer()` so that they match 
the paint-time clamp.

Rename `cachedSDRCGColorForColorspace()` to 
`createCGColorInDestinationStandardRange()` to be more
accurate.

We also need a fix in `DrawGlyphsRecorder`, so that text being rendered in P3 
respects the
colorspace of the target context to avoid clamping. We implement the 
`deGetColorSpace` callback,
have `GraphicsContextCG::colorSpace()` use `CGContextGetColorSpace()`, and have 
the buffer in
`DrawGlyphsRecorder::drawOTSVGRun()` use the right colorspace.

On iOS we need to get to the display colorspace in 
`RemoteLayerTreePropertyApplier::applyPropertiesToLayer()`,
so expose `WebPageProxy::colorSpace()` for Cocoa platforms, and cache it in 
PageClientImpl() because
fetching it involves calling `MediaToolbox_MTShouldPlayHDRVideo()`.

* LayoutTests/TestExpectations:
* 
LayoutTests/compositing/background-color/background-color-clamping-expected.txt:
 Added.
* LayoutTests/compositing/background-color/background-color-clamping.html: 
Added.
* LayoutTests/platform/ios/TestExpectations:
* 
LayoutTests/platform/ios/compositing/background-color/background-color-clamping-expected.txt:
 Added.
* LayoutTests/platform/mac/TestExpectations:
* Source/WebCore/Configurations/AllowedSPI-legacy.toml:
* Source/WebCore/Configurations/AllowedSPI.toml:
* Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h:
* Source/WebCore/platform/graphics/Color.h:
* Source/WebCore/platform/graphics/ColorConversion.h:
* Source/WebCore/platform/graphics/cg/ColorCG.cpp:
(WTF::RetainPtr<CGColorRef>>::createValueForKey):
(WebCore::createCGColorInDestinationStandardRange):
(WebCore::cachedCGColorInDestinationStandardRange):
(WebCore::createSDRCGColorForColorspace): Deleted.
(WebCore::cachedSDRCGColorForColorspace): Deleted.
* Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::setCGFillColor):
(WebCore::GraphicsContextCG::colorSpace const):
(WebCore::GraphicsContextCG::setCGDropShadow):
(WebCore::GraphicsContextCG::didUpdateState):
* Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorder.cpp:
(WebCore::getColorSpace):
(WebCore::DrawGlyphsRecorder::createInternalContext):
(WebCore::DrawGlyphsRecorder::colorSpace const):
(WebCore::DrawGlyphsRecorder::drawOTSVGRun):
* Source/WebCore/platform/graphics/coretext/DrawGlyphsRecorder.h:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.mm:
(WebKit::RemoteLayerTreePropertyApplier::applyPropertiesToLayer):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
(dumpCALayer): Dump background color.
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::colorSpace const):
* Source/WebKit/UIProcess/PageClient.h:
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.h:
* Source/WebKit/UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::colorSpace):
* Source/WebKit/UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::colorSpace): Deleted.
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::displayColorSpace const):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to