Skip to content

Commit

Permalink
Use the display colorspace for IOSurfaces with macOS UI-side compositing
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=247929
<rdar://problem/102346748>

Reviewed by Tim Horton.

Hook up `RemoteLayerTreeDrawingAreaMac::setColorSpace()`, and add a `displayColorSpace()`
getter on DrawingArea, implementing on TiledCoreAnimationDrawingArea and RemoteLayerTreeDrawingAreaMac.
TiledCoreAnimationDrawingArea stores the colorspace on the LayerHostingContext, and
RemoteLayerTreeDrawingAreaMac stores it directly.

Then add some code for macOS in `RemoteLayerBackingStore::colorSpace()` to fetch the
colorspace via the RemoteLayerTreeContext, which consults the DrawingArea.

Also hook up `RemoteLayerTreeDrawingAreaProxyMac::colorSpaceDidChange()`, which
is used to push in the colorspace on initial window creation.

Updating the colorspace on all IOSurfaces when moving a window between displays is not yet supported.

* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::colorSpace const):
* Source/WebKit/UIProcess/DrawingAreaProxy.h:
(WebKit::DrawingAreaProxy::colorSpaceDidChange):
* Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.h:
* Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxyMac::colorSpaceDidChange):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/mac/WebPageProxyMac.mm:
* Source/WebKit/WebProcess/WebPage/DrawingArea.h:
(WebKit::DrawingArea::displayColorSpace const):
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h:
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::displayColorSpace const):
* Source/WebKit/WebProcess/WebPage/mac/RemoteLayerTreeDrawingAreaMac.h:
* Source/WebKit/WebProcess/WebPage/mac/RemoteLayerTreeDrawingAreaMac.mm:
(WebKit::RemoteLayerTreeDrawingAreaMac::RemoteLayerTreeDrawingAreaMac):
(WebKit::RemoteLayerTreeDrawingAreaMac::setColorSpace):
(WebKit::RemoteLayerTreeDrawingAreaMac::displayColorSpace const):
* Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
* Source/WebKit/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::displayColorSpace const):

Canonical link: https://commits.webkit.org/256715@main
  • Loading branch information
smfr committed Nov 15, 2022
1 parent 02f0132 commit c32ad27
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 5 deletions.
Expand Up @@ -198,8 +198,13 @@

DestinationColorSpace RemoteLayerBackingStore::colorSpace() const
{
#if PLATFORM(MAC)
if (auto* context = m_layer->context())
return context->displayColorSpace().value_or(DestinationColorSpace::SRGB());
#else
if (usesDeepColorBackingStore())
return DestinationColorSpace { extendedSRGBColorSpaceRef() };
#endif
return DestinationColorSpace::SRGB();
}

Expand Down
3 changes: 1 addition & 2 deletions Source/WebKit/UIProcess/DrawingAreaProxy.h
Expand Up @@ -75,7 +75,7 @@ class DrawingAreaProxy : public IPC::MessageReceiver, protected IPC::MessageSend
virtual WebCore::DelegatedScrollingMode delegatedScrollingMode() const;

virtual void deviceScaleFactorDidChange() = 0;

virtual void colorSpaceDidChange() { }
virtual void windowScreenDidChange(WebCore::PlatformDisplayID, std::optional<WebCore::FramesPerSecond> /* nominalFramesPerSecond */) { }

// FIXME: These should be pure virtual.
Expand All @@ -92,7 +92,6 @@ class DrawingAreaProxy : public IPC::MessageReceiver, protected IPC::MessageSend
virtual void targetRefreshRateDidChange(unsigned) { }
#endif

virtual void colorSpaceDidChange() { }
virtual void minimumSizeForAutoLayoutDidChange() { }
virtual void sizeToContentAutoSizeMaximumSizeDidChange() { }
virtual void windowKindDidChange() { }
Expand Down
Expand Up @@ -56,6 +56,7 @@ friend class RemoteScrollingCoordinatorProxyMac;
void pauseDisplayRefreshCallbacks() override;
void setPreferredFramesPerSecond(WebCore::FramesPerSecond) override;
void windowScreenDidChange(WebCore::PlatformDisplayID, std::optional<WebCore::FramesPerSecond>) override;
void colorSpaceDidChange() override;

void didChangeViewExposedRect() override;

Expand Down
Expand Up @@ -28,6 +28,7 @@

#if PLATFORM(MAC)

#import "DrawingAreaMessages.h"
#import "RemoteScrollingCoordinatorProxyMac.h"
#import "WebPageProxy.h"
#import "WebProcessPool.h"
Expand Down Expand Up @@ -213,6 +214,11 @@ explicit RemoteLayerTreeDisplayLinkClient(WebPageProxyIdentifier pageID)
updateDebugIndicatorPosition();
}

void RemoteLayerTreeDrawingAreaProxyMac::colorSpaceDidChange()
{
send(Messages::DrawingArea::SetColorSpace(m_webPageProxy.colorSpace()));
}

} // namespace WebKit

#endif // PLATFORM(MAC)
4 changes: 2 additions & 2 deletions Source/WebKit/UIProcess/WebPageProxy.h
Expand Up @@ -1205,6 +1205,8 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
#if PLATFORM(MAC)
void setUseSystemAppearance(bool);
bool useSystemAppearance() const { return m_useSystemAppearance; }

WebCore::DestinationColorSpace colorSpace();
#endif

void effectiveAppearanceDidChange();
Expand All @@ -1224,8 +1226,6 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
RefPtr<WebCore::SharedBuffer> dataSelectionForPasteboard(const String& pasteboardType);
void makeFirstResponder();
void assistiveTechnologyMakeFirstResponder();

WebCore::DestinationColorSpace colorSpace();
#endif

void pageScaleFactorDidChange(double);
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
Expand Up @@ -318,10 +318,12 @@ static inline bool expectsLegacyImplicitRubberBandControl()
pageClient().assistiveTechnologyMakeFirstResponder();
}

#if PLATFORM(MAC)
WebCore::DestinationColorSpace WebPageProxy::colorSpace()
{
return pageClient().colorSpace();
}
#endif

void WebPageProxy::registerUIProcessAccessibilityTokens(const IPC::DataReference& elementToken, const IPC::DataReference& windowToken)
{
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/WebProcess/WebPage/DrawingArea.h
Expand Up @@ -133,6 +133,8 @@ class DrawingArea : public IPC::MessageReceiver, public WebCore::DisplayRefreshM

virtual void setShouldScaleViewToFitDocument(bool) { }

virtual std::optional<WebCore::DestinationColorSpace> displayColorSpace() const { return { }; }

virtual bool addMilestonesToDispatch(OptionSet<WebCore::LayoutMilestone>) { return false; }

#if PLATFORM(COCOA)
Expand Down Expand Up @@ -187,7 +189,6 @@ class DrawingArea : public IPC::MessageReceiver, public WebCore::DisplayRefreshM
RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) override;

#if PLATFORM(COCOA)
// Used by TiledCoreAnimationDrawingArea.
virtual void setDeviceScaleFactor(float) { }
virtual void setColorSpace(std::optional<WebCore::DestinationColorSpace>) { }

Expand Down
Expand Up @@ -57,6 +57,8 @@ class RemoteLayerTreeContext : public WebCore::GraphicsLayerFactory {
float deviceScaleFactor() const;

LayerHostingMode layerHostingMode() const;

std::optional<WebCore::DestinationColorSpace> displayColorSpace() const;

void buildTransaction(RemoteLayerTreeTransaction&, WebCore::PlatformCALayer& rootLayer);

Expand Down
Expand Up @@ -29,6 +29,7 @@
#import "GenericCallback.h"
#import "GraphicsLayerCARemote.h"
#import "PlatformCALayerRemote.h"
#import "RemoteLayerTreeDrawingArea.h"
#import "RemoteLayerTreeTransaction.h"
#import "RemoteLayerWithRemoteRenderingBackingStoreCollection.h"
#import "WebPage.h"
Expand Down Expand Up @@ -81,6 +82,14 @@
return m_webPage.layerHostingMode();
}

std::optional<WebCore::DestinationColorSpace> RemoteLayerTreeContext::displayColorSpace() const
{
if (auto* drawingArea = m_webPage.drawingArea())
return drawingArea->displayColorSpace();

return { };
}

#if PLATFORM(IOS_FAMILY)
bool RemoteLayerTreeContext::canShowWhileLocked() const
{
Expand Down
Expand Up @@ -38,6 +38,11 @@ class RemoteLayerTreeDrawingAreaMac final : public RemoteLayerTreeDrawingArea {

private:
WebCore::DelegatedScrollingMode delegatedScrollingMode() const override;

void setColorSpace(std::optional<WebCore::DestinationColorSpace>) override;
std::optional<WebCore::DestinationColorSpace> displayColorSpace() const override;

std::optional<WebCore::DestinationColorSpace> m_displayColorSpace;
};

} // namespace WebKit
Expand Down
Expand Up @@ -28,6 +28,7 @@

#if PLATFORM(MAC)

#import "WebPageCreationParameters.h"
#import <WebCore/ScrollView.h>

namespace WebKit {
Expand All @@ -36,6 +37,7 @@
RemoteLayerTreeDrawingAreaMac::RemoteLayerTreeDrawingAreaMac(WebPage& webPage, const WebPageCreationParameters& parameters)
: RemoteLayerTreeDrawingArea(webPage, parameters)
{
setColorSpace(parameters.colorSpace);
}

RemoteLayerTreeDrawingAreaMac::~RemoteLayerTreeDrawingAreaMac() = default;
Expand All @@ -45,6 +47,17 @@
return DelegatedScrollingMode::DelegatedToWebKit;
}

void RemoteLayerTreeDrawingAreaMac::setColorSpace(std::optional<WebCore::DestinationColorSpace> colorSpace)
{
m_displayColorSpace = colorSpace;
}

std::optional<WebCore::DestinationColorSpace> RemoteLayerTreeDrawingAreaMac::displayColorSpace() const
{
return m_displayColorSpace;
}


} // namespace WebKit

#endif // PLATFORM(MAC)
Expand Up @@ -102,6 +102,7 @@ class TiledCoreAnimationDrawingArea final : public DrawingArea {
void resumePainting();
void setLayerHostingMode(LayerHostingMode) override;
void setColorSpace(std::optional<WebCore::DestinationColorSpace>) override;
std::optional<WebCore::DestinationColorSpace> displayColorSpace() const override;
void addFence(const WTF::MachSendRight&) override;

void addTransactionCallbackID(CallbackID) override;
Expand Down
Expand Up @@ -645,6 +645,11 @@
m_layerHostingContext->setColorSpace(colorSpace ? colorSpace->platformColorSpace() : nullptr);
}

std::optional<WebCore::DestinationColorSpace> TiledCoreAnimationDrawingArea::displayColorSpace() const
{
return DestinationColorSpace { m_layerHostingContext->colorSpace() };
}

RefPtr<WebCore::DisplayRefreshMonitor> TiledCoreAnimationDrawingArea::createDisplayRefreshMonitor(PlatformDisplayID displayID)
{
return DisplayRefreshMonitorMac::create(displayID);
Expand Down

0 comments on commit c32ad27

Please sign in to comment.