Skip to content

Commit

Permalink
Generate serialization of LayerCreationProperties
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259413
rdar://112694735

Reviewed by Tim Horton.

* Source/WebCore/platform/graphics/Model.h:
(WebCore::Model::encode const): Deleted.
(WebCore::Model::decode): Deleted.
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTree.serialization.in:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::description const):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::hostIdentifier const):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::hostingContextID const):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::preservesFlip const):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::hostingDeviceScaleFactor const):
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties): Deleted.
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::encode const): Deleted.
(WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::decode): Deleted.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::createLayer):
(WebKit::RemoteLayerTreeHost::makeNode):
* Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:
(WebKit::RemoteLayerTreeHost::makeNode):
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm:
(WebKit::PlatformCALayerRemoteCustom::populateCreationProperties):
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteHost.mm:
(WebKit::PlatformCALayerRemoteHost::populateCreationProperties):
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteModelHosting.mm:
(WebKit::PlatformCALayerRemoteModelHosting::populateCreationProperties):
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::layerDidEnterContext):

Canonical link: https://commits.webkit.org/266268@main
  • Loading branch information
achristensen07 committed Jul 24, 2023
1 parent 7d015b7 commit a6be02e
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 157 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/MediaSourcePrivate.h
platform/graphics/MediaSourcePrivateClient.h
platform/graphics/MediaUsageInfo.h
platform/graphics/Model.h
platform/graphics/NativeImage.h
platform/graphics/NullGraphicsContext.h
platform/graphics/Path.h
Expand Down
33 changes: 0 additions & 33 deletions Source/WebCore/platform/graphics/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class Model final : public RefCounted<Model> {
Ref<SharedBuffer> data() const { return m_data; }
const String& mimeType() const { return m_mimeType; }
const URL& url() const { return m_url; }

template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static RefPtr<Model> decode(Decoder&);

private:
explicit Model(Ref<SharedBuffer>&&, String, URL);

Expand All @@ -56,35 +52,6 @@ class Model final : public RefCounted<Model> {
URL m_url;
};

template<class Encoder>
void Model::encode(Encoder& encoder) const
{
encoder << m_data;
encoder << m_mimeType;
encoder << m_url;
}

template<class Decoder>
RefPtr<Model> Model::decode(Decoder& decoder)
{
std::optional<Ref<SharedBuffer>> data;
decoder >> data;
if (!data)
return nullptr;

std::optional<String> mimeType;
decoder >> mimeType;
if (!mimeType)
return nullptr;

std::optional<URL> url;
decoder >> url;
if (!url)
return nullptr;

return Model::create(WTFMove(*data), WTFMove(*mimeType), WTFMove(*url));
}

WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const Model&);

} // namespace WebCore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,30 @@ headers: "LayerProperties.h" "PlatformCALayerRemote.h"
[NotSerialized] HashSet<Ref<PlatformCALayerRemote>> changedLayers;
HashMap<WebCore::PlatformLayerIdentifier, UniqueRef<WebKit::LayerProperties>> changedLayerProperties;
}

[Nested] struct WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::NoAdditionalData {
};

[Nested] struct WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::VideoElementData {
WebKit::PlaybackSessionContextIdentifier playerIdentifier;
WebCore::FloatSize initialSize;
WebCore::FloatSize naturalSize;
};

[Nested] struct WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::CustomData {
uint32_t hostingContextID;
float hostingDeviceScaleFactor;
bool preservesFlip;
};

[Nested] struct WebKit::RemoteLayerTreeTransaction::LayerCreationProperties {
WebCore::PlatformLayerIdentifier layerID;
WebCore::PlatformCALayer::LayerType type;
std::optional<WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::VideoElementData> videoElementData;
#if ENABLE(MODEL_ELEMENT)
std::variant<WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::NoAdditionalData, WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::CustomData, Ref<WebCore::Model>, WebCore::LayerHostingContextIdentifier> additionalData;
#endif
#if !ENABLE(MODEL_ELEMENT)
std::variant<WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::NoAdditionalData, WebKit::RemoteLayerTreeTransaction::LayerCreationProperties::CustomData, WebCore::LayerHostingContextIdentifier> additionalData;
#endif
};
42 changes: 24 additions & 18 deletions Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,34 @@ class RemoteLayerTreeTransaction {
WTF_MAKE_FAST_ALLOCATED;
public:
struct LayerCreationProperties {
WTF_MAKE_STRUCT_FAST_ALLOCATED;
LayerCreationProperties();

void encode(IPC::Encoder&) const;
static std::optional<LayerCreationProperties> decode(IPC::Decoder&);
struct NoAdditionalData { };
struct CustomData {
uint32_t hostingContextID { 0 };
float hostingDeviceScaleFactor { 1 };
bool preservesFlip { false };
};
struct VideoElementData {
PlaybackSessionContextIdentifier playerIdentifier;
WebCore::FloatSize initialSize;
WebCore::FloatSize naturalSize;
};

WebCore::PlatformLayerIdentifier layerID;
WebCore::PlatformCALayer::LayerType type;
std::optional<PlaybackSessionContextIdentifier> playerIdentifier;
std::optional<WebCore::FloatSize> initialSize;
std::optional<WebCore::FloatSize> naturalSize;

uint32_t hostingContextID;
float hostingDeviceScaleFactor;
bool preservesFlip;

// FIXME: This could be a variant<CustomData, HostData, ModelData, NoData>.
Markable<WebCore::LayerHostingContextIdentifier> hostIdentifier;

WebCore::PlatformCALayer::LayerType type { WebCore::PlatformCALayer::LayerTypeLayer };
std::optional<VideoElementData> videoElementData;
std::variant<
NoAdditionalData, // PlatformCALayerRemote and PlatformCALayerRemoteTiledBacking
CustomData, // PlatformCALayerRemoteCustom
#if ENABLE(MODEL_ELEMENT)
RefPtr<WebCore::Model> model;
Ref<WebCore::Model>, // PlatformCALayerRemoteModelHosting
#endif
WebCore::LayerHostingContextIdentifier // PlatformCALayerRemoteHost
> additionalData;

std::optional<WebCore::LayerHostingContextIdentifier> hostIdentifier() const;
uint32_t hostingContextID() const;
bool preservesFlip() const;
float hostingDeviceScaleFactor() const;
};

explicit RemoteLayerTreeTransaction();
Expand Down
115 changes: 32 additions & 83 deletions Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,86 +43,6 @@
RemoteLayerTreeTransaction::RemoteLayerTreeTransaction(RemoteLayerTreeTransaction&&) = default;
RemoteLayerTreeTransaction& RemoteLayerTreeTransaction::operator=(RemoteLayerTreeTransaction&&) = default;

RemoteLayerTreeTransaction::LayerCreationProperties::LayerCreationProperties()
: type(WebCore::PlatformCALayer::LayerTypeLayer)
, playerIdentifier(std::nullopt)
, naturalSize(std::nullopt)
, hostingContextID(0)
, hostingDeviceScaleFactor(1)
, preservesFlip(false)
{
}

void RemoteLayerTreeTransaction::LayerCreationProperties::encode(IPC::Encoder& encoder) const
{
encoder << layerID;
encoder << type;

// PlatformCALayerRemoteCustom
encoder << playerIdentifier;
encoder << naturalSize;
encoder << initialSize;
encoder << hostingContextID;
encoder << hostingDeviceScaleFactor;
encoder << preservesFlip;

// PlatformCALayerRemoteHost
encoder << hostIdentifier;

#if ENABLE(MODEL_ELEMENT)
// PlatformCALayerRemoteModelHosting
encoder << !!model;
if (model)
encoder << *model;
#endif
}

auto RemoteLayerTreeTransaction::LayerCreationProperties::decode(IPC::Decoder& decoder) -> std::optional<LayerCreationProperties>
{
LayerCreationProperties result;
if (!decoder.decode(result.layerID))
return std::nullopt;

if (!decoder.decode(result.type))
return std::nullopt;

// PlatformCALayerRemoteCustom
if (!decoder.decode(result.playerIdentifier))
return std::nullopt;
if (!decoder.decode(result.naturalSize))
return std::nullopt;
if (!decoder.decode(result.initialSize))
return std::nullopt;

if (!decoder.decode(result.hostingContextID))
return std::nullopt;

if (!decoder.decode(result.hostingDeviceScaleFactor))
return std::nullopt;

if (!decoder.decode(result.preservesFlip))
return std::nullopt;

// PlatformCALayerRemoteHost
if (!decoder.decode(result.hostIdentifier))
return std::nullopt;

#if ENABLE(MODEL_ELEMENT)
// PlatformCALayerRemoteModelHosting
bool hasModel;
if (!decoder.decode(hasModel))
return std::nullopt;
if (hasModel) {
auto model = WebCore::Model::decode(decoder);
if (!model)
return std::nullopt;
result.model = model;
}
#endif

return WTFMove(result);
}

LayerProperties::LayerProperties() = default;

LayerProperties::LayerProperties(LayerProperties&&) = default;
Expand Down Expand Up @@ -803,14 +723,15 @@ static void dumpChangedLayers(TextStream& ts, const LayerPropertiesMap& changedL
ts << createdLayer.type <<" " << createdLayer.layerID;
switch (createdLayer.type) {
case WebCore::PlatformCALayer::LayerTypeAVPlayerLayer:
ts << " (context-id " << createdLayer.hostingContextID << ")";
ts << " (context-id " << createdLayer.hostingContextID() << ")";
break;
case WebCore::PlatformCALayer::LayerTypeCustom:
ts << " (context-id " << createdLayer.hostingContextID << ")";
ts << " (context-id " << createdLayer.hostingContextID() << ")";
break;
#if ENABLE(MODEL_ELEMENT)
case WebCore::PlatformCALayer::LayerTypeModelLayer:
ts << " (model " << *createdLayer.model << ")";
if (auto* model = std::get_if<Ref<WebCore::Model>>(&createdLayer.additionalData))
ts << " (model " << model->get() << ")";
break;
#endif
default:
Expand Down Expand Up @@ -875,6 +796,34 @@ static void dumpChangedLayers(TextStream& ts, const LayerPropertiesMap& changedL
ChangedLayers::ChangedLayers(LayerPropertiesMap&& changedLayerProperties)
: changedLayerProperties(WTFMove(changedLayerProperties)) { }

std::optional<WebCore::LayerHostingContextIdentifier> RemoteLayerTreeTransaction::LayerCreationProperties::hostIdentifier() const
{
if (auto* identifier = std::get_if<WebCore::LayerHostingContextIdentifier>(&additionalData))
return *identifier;
return std::nullopt;
}

uint32_t RemoteLayerTreeTransaction::LayerCreationProperties::hostingContextID() const
{
if (auto* customData = std::get_if<CustomData>(&additionalData))
return customData->hostingContextID;
return 0;
}

bool RemoteLayerTreeTransaction::LayerCreationProperties::preservesFlip() const
{
if (auto* customData = std::get_if<CustomData>(&additionalData))
return customData->preservesFlip;
return false;
}

float RemoteLayerTreeTransaction::LayerCreationProperties::hostingDeviceScaleFactor() const
{
if (auto* customData = std::get_if<CustomData>(&additionalData))
return customData->hostingDeviceScaleFactor;
return 1;
}

} // namespace WebKit

namespace IPC {
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -5698,3 +5698,9 @@ struct WebCore::CookieStoreGetOptions {
String name;
String url;
};

[RefCounted] class WebCore::Model {
Ref<WebCore::SharedBuffer> data()
String mimeType()
URL url()
}
16 changes: 8 additions & 8 deletions Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@
}
#endif

if (properties.hostIdentifier) {
m_hostingLayers.set(*properties.hostIdentifier, properties.layerID);
if (auto* hostedNode = nodeForID(m_hostedLayers.get(*properties.hostIdentifier)))
if (auto* hostIdentifier = std::get_if<WebCore::LayerHostingContextIdentifier>(&properties.additionalData)) {
m_hostingLayers.set(*hostIdentifier, properties.layerID);
if (auto* hostedNode = nodeForID(m_hostedLayers.get(*hostIdentifier)))
[node->layer() addSublayer:hostedNode->layer()];
}

Expand All @@ -386,7 +386,7 @@
std::unique_ptr<RemoteLayerTreeNode> RemoteLayerTreeHost::makeNode(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
{
auto makeWithLayer = [&] (RetainPtr<CALayer>&& layer) {
return makeUnique<RemoteLayerTreeNode>(properties.layerID, properties.hostIdentifier, WTFMove(layer));
return makeUnique<RemoteLayerTreeNode>(properties.layerID, properties.hostIdentifier(), WTFMove(layer));
};

switch (properties.type) {
Expand Down Expand Up @@ -426,15 +426,15 @@
return RemoteLayerTreeNode::createWithPlainLayer(properties.layerID);

#if HAVE(AVKIT)
if (properties.playerIdentifier && properties.initialSize && properties.naturalSize) {
if (properties.videoElementData) {
if (auto videoManager = m_drawingArea->page().videoFullscreenManager()) {
m_videoLayers.add(properties.layerID, *properties.playerIdentifier);
return makeWithLayer(videoManager->createLayerWithID(*properties.playerIdentifier, properties.hostingContextID, *properties.initialSize, *properties.naturalSize, properties.hostingDeviceScaleFactor));
m_videoLayers.add(properties.layerID, properties.videoElementData->playerIdentifier);
return makeWithLayer(videoManager->createLayerWithID(properties.videoElementData->playerIdentifier, properties.hostingContextID(), properties.videoElementData->initialSize, properties.videoElementData->naturalSize, properties.hostingDeviceScaleFactor()));
}
}
#endif

return makeWithLayer([CALayer _web_renderLayerWithContextID:properties.hostingContextID shouldPreserveFlip:properties.preservesFlip]);
return makeWithLayer([CALayer _web_renderLayerWithContextID:properties.hostingContextID() shouldPreserveFlip:properties.preservesFlip()]);

case PlatformCALayer::LayerTypeShapeLayer:
return makeWithLayer(adoptNS([[CAShapeLayer alloc] init]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
std::unique_ptr<RemoteLayerTreeNode> RemoteLayerTreeHost::makeNode(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
{
auto makeWithView = [&] (RetainPtr<UIView>&& view) {
return makeUnique<RemoteLayerTreeNode>(properties.layerID, properties.hostIdentifier, WTFMove(view));
return makeUnique<RemoteLayerTreeNode>(properties.layerID, properties.hostIdentifier(), WTFMove(view));
};

switch (properties.type) {
Expand Down Expand Up @@ -76,15 +76,15 @@
return makeWithView(adoptNS([[WKCompositingView alloc] init]));

#if HAVE(AVKIT)
if (properties.playerIdentifier && properties.initialSize && properties.naturalSize) {
if (properties.videoElementData) {
if (auto videoManager = m_drawingArea->page().videoFullscreenManager()) {
m_videoLayers.add(properties.layerID, *properties.playerIdentifier);
return makeWithView(videoManager->createViewWithID(*properties.playerIdentifier, properties.hostingContextID, *properties.initialSize, *properties.naturalSize, properties.hostingDeviceScaleFactor));
m_videoLayers.add(properties.layerID, properties.videoElementData->playerIdentifier);
return makeWithView(videoManager->createViewWithID(properties.videoElementData->playerIdentifier, properties.hostingContextID(), properties.videoElementData->initialSize, properties.videoElementData->naturalSize, properties.hostingDeviceScaleFactor()));
}
}
#endif

auto view = adoptNS([[WKUIRemoteView alloc] initWithFrame:CGRectZero pid:m_drawingArea->page().processID() contextID:properties.hostingContextID]);
auto view = adoptNS([[WKUIRemoteView alloc] initWithFrame:CGRectZero pid:m_drawingArea->page().processID() contextID:properties.hostingContextID()]);
return makeWithView(WTFMove(view));
}
case PlatformCALayer::LayerTypeShapeLayer:
Expand All @@ -99,11 +99,13 @@
#if ENABLE(MODEL_ELEMENT)
case PlatformCALayer::LayerTypeModelLayer:
if (m_drawingArea->page().preferences().modelElementEnabled()) {
if (auto* model = std::get_if<Ref<Model>>(&properties.additionalData)) {
#if ENABLE(SEPARATED_MODEL)
return makeWithView(adoptNS([[WKSeparatedModelView alloc] initWithModel:*properties.model]));
return makeWithView(adoptNS([[WKSeparatedModelView alloc] initWithModel:*model]));
#elif ENABLE(ARKIT_INLINE_PREVIEW_IOS)
return makeWithView(adoptNS([[WKModelView alloc] initWithModel:*properties.model layerID:properties.layerID page:m_drawingArea->page()]));
return makeWithView(adoptNS([[WKModelView alloc] initWithModel:*model layerID:properties.layerID page:m_drawingArea->page()]));
#endif
}
}
return makeWithView(adoptNS([[WKCompositingView alloc] init]));
#endif // ENABLE(MODEL_ELEMENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@
void PlatformCALayerRemoteCustom::populateCreationProperties(RemoteLayerTreeTransaction::LayerCreationProperties& properties, const RemoteLayerTreeContext& context, PlatformCALayer::LayerType type)
{
PlatformCALayerRemote::populateCreationProperties(properties, context, type);
properties.hostingContextID = hostingContextID();
properties.hostingDeviceScaleFactor = context.deviceScaleFactor();
properties.preservesFlip = YES;
ASSERT(std::holds_alternative<RemoteLayerTreeTransaction::LayerCreationProperties::NoAdditionalData>(properties.additionalData));
properties.additionalData = RemoteLayerTreeTransaction::LayerCreationProperties::CustomData {
.hostingContextID = hostingContextID(),
.hostingDeviceScaleFactor = context.deviceScaleFactor(),
.preservesFlip = true
};
}

Ref<WebCore::PlatformCALayer> PlatformCALayerRemoteCustom::clone(PlatformCALayerClient* owner) const
Expand Down
Loading

0 comments on commit a6be02e

Please sign in to comment.