Skip to content

Commit

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

Reviewed by Simon Fraser.

This removes a lot of boilerplate code and replaces it with generated code with static_asserts
that verify we didn't forget anything.  It also exposes the structure to the IPC testing API.
The collections of changed layers were a little tricky, but by adding the new attribute CustomEncoder
we can manually write the encoder and it keeps all the complexity in one small class.

* Source/WTF/wtf/Forward.h:
* Source/WebKit/Platform/IPC/ArgumentCoders.h:
(IPC::ArgumentCoder<UniqueRef<T>>::encode):
(IPC::ArgumentCoder<UniqueRef<T>>::decode):
* Source/WebKit/Scripts/generate-serializers.py:
(SerializedType.__init__):
(generate_impl):
* Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.cpp:
(IPC::ArgumentCoder<WebKit::CustomEncoded>::decode):
* Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.h:
* Source/WebKit/Scripts/webkit/tests/SerializedTypeInfo.cpp:
(WebKit::allSerializedTypes):
* Source/WebKit/Scripts/webkit/tests/TestSerializedType.serialization.in:
* Source/WebKit/Shared/RemoteLayerTree/LayerProperties.h: Added.
(WebKit::LayerProperties::notePropertiesChanged):
(WebKit::LayerProperties::resetChangedProperties):
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTree.serialization.in:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.h:
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.mm:
(WebKit::applyCommonPropertiesToLayer):
(WebKit::RemoteLayerTreePropertyApplier::applyPropertiesToLayer):
(WebKit::RemoteLayerTreePropertyApplier::applyProperties):
(WebKit::applyInteractionRegionsHierarchyUpdate):
(WebKit::RemoteLayerTreePropertyApplier::applyHierarchyUpdates):
(WebKit::RemoteLayerTreePropertyApplier::updateMask):
(WebKit::RemoteLayerTreePropertyApplier::applyPropertiesToUIView):
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.h:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::notePropertiesChanged): Deleted.
(WebKit::RemoteLayerTreeTransaction::LayerProperties::resetChangedProperties): Deleted.
(WebKit::RemoteLayerTreeTransaction::hasAnyLayerChanges const): Deleted.
(WebKit::RemoteLayerTreeTransaction::changedLayers): Deleted.
(WebKit::RemoteLayerTreeTransaction::changedLayerProperties const): Deleted.
(WebKit::RemoteLayerTreeTransaction::changedLayerProperties): Deleted.
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreeTransaction.mm:
(WebKit::LayerProperties::encode const):
(WebKit::LayerProperties::decode):
(WebKit::RemoteLayerTreeTransaction::layerPropertiesChanged):
(WebKit::dumpChangedLayers):
(WebKit::RemoteLayerTreeTransaction::description const):
(WebKit::RemoteLayerTreeTransaction::hasAnyLayerChanges const):
(WebKit::RemoteLayerTreeTransaction::changedLayers):
(WebKit::RemoteLayerTreeTransaction::changedLayerProperties const):
(WebKit::RemoteLayerTreeTransaction::changedLayerProperties):
(WebKit::ChangedLayers::ChangedLayers):
(IPC::ArgumentCoder<WebKit::ChangedLayers>::encode):
(WebKit::RemoteLayerTreeTransaction::LayerProperties::LayerProperties): Deleted.
(WebKit::RemoteLayerTreeTransaction::LayerProperties::encode const): Deleted.
(WebKit::RemoteLayerTreeTransaction::LayerProperties::decode): Deleted.
(WebKit::RemoteLayerTreeTransaction::encode const): Deleted.
(WebKit::RemoteLayerTreeTransaction::decode): Deleted.
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.mm:
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::updateLayerTree):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h:
(WebKit::PlatformCALayerRemote::properties):
(WebKit::PlatformCALayerRemote::properties const):

Canonical link: https://commits.webkit.org/266149@main
  • Loading branch information
achristensen07 committed Jul 19, 2023
1 parent 8514f36 commit c94a197
Show file tree
Hide file tree
Showing 18 changed files with 394 additions and 469 deletions.
2 changes: 2 additions & 0 deletions Source/WTF/wtf/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ template<typename> class StringBuffer;
template<typename> class StringParsingBuffer;
template<typename, typename = void> class StringTypeAdapter;
template<typename> class UniqueRef;
template<typename T, class... Args> UniqueRef<T> makeUniqueRef(Args&&...);
template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16, typename = VectorBufferMalloc> class Vector;
template<typename, typename = DefaultWeakPtrImpl> class WeakPtr;

Expand Down Expand Up @@ -152,6 +153,7 @@ using WTF::LazyNeverDestroyed;
using WTF::Lock;
using WTF::Logger;
using WTF::MachSendRight;
using WTF::makeUniqueRef;
using WTF::MonotonicTime;
using WTF::NeverDestroyed;
using WTF::ObjectIdentifier;
Expand Down
2 changes: 0 additions & 2 deletions Source/WebKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ set(WebKit_SERIALIZATION_IN_FILES

Shared/Gamepad/GamepadData.serialization.in

Shared/RemoteLayerTree/RemoteLayerTree.serialization.in

Shared/WebGPU/WebGPUBindGroupDescriptor.serialization.in
Shared/WebGPU/WebGPUBindGroupEntry.serialization.in
Shared/WebGPU/WebGPUBindGroupLayoutDescriptor.serialization.in
Expand Down
18 changes: 18 additions & 0 deletions Source/WebKit/Platform/IPC/ArgumentCoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ template<typename T> struct ArgumentCoder<std::unique_ptr<T>> {
}
};

template<typename T> struct ArgumentCoder<UniqueRef<T>> {
template<typename Encoder, typename U>
static void encode(Encoder& encoder, U&& object)
{
static_assert(std::is_same_v<std::remove_cvref_t<U>, UniqueRef<T>>);
encoder << std::forward_like<U>(*object);
}

template<typename Decoder>
static std::optional<UniqueRef<T>> decode(Decoder& decoder)
{
auto object = decoder.template decode<T>();
if (!object)
return std::nullopt;
return makeUniqueRef<T>(WTFMove(*object));
}
};

template<typename... Elements> struct ArgumentCoder<std::tuple<Elements...>> {
template<typename Encoder, typename T>
static void encode(Encoder& encoder, T&& tuple)
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/Scripts/generate-serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# OptionSet - for enum classes, instead of only allowing deserialization of the exact values, allow deserialization of any bit combination of the values.
# RValue - serializer takes an rvalue reference, instead of an lvalue.
# WebKitPlatform - put serializer into a file built as part of WebKitPlatform
# CustomEncoder - Only generate the decoder, not the encoder.
#
# Supported member attributes:
#
Expand Down Expand Up @@ -66,6 +67,7 @@ def __init__(self, struct_or_class, namespace, name, parent_class_name, members,
self.webkit_platform = False
self.members_are_subclasses = False
self.custom_member_layout = False
self.custom_encoder = False
if attributes is not None:
for attribute in attributes.split(', '):
if '=' in attribute:
Expand All @@ -89,6 +91,8 @@ def __init__(self, struct_or_class, namespace, name, parent_class_name, members,
self.custom_member_layout = True
elif attribute == 'LegacyPopulateFromEmptyConstructor':
self.populate_from_empty_constructor = True
elif attribute == 'CustomEncoder':
self.custom_encoder = True
if other_metadata:
if other_metadata == 'subclasses':
self.members_are_subclasses = True
Expand Down Expand Up @@ -607,6 +611,8 @@ def generate_impl(serialized_types, serialized_enums, headers, generating_webkit
result.append('};')
result.append('')
for encoder in type.encoders:
if type.custom_encoder:
continue
if type.rvalue:
result.append('void ArgumentCoder<' + type.namespace_and_name() + '>::encode(' + encoder + '& encoder, ' + type.namespace_and_name() + '&& instance)')
else:
Expand Down
13 changes: 13 additions & 0 deletions Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#if ENABLE(TEST_FEATURE)
#include "CommonHeader.h"
#endif
#include "CustomEncoded.h"
#if ENABLE(TEST_FEATURE)
#include "FirstMemberType.h"
#endif
Expand Down Expand Up @@ -787,6 +788,18 @@ std::optional<WebCore::MoveOnlyDerivedClass> ArgumentCoder<WebCore::MoveOnlyDeri
};
}

std::optional<WebKit::CustomEncoded> ArgumentCoder<WebKit::CustomEncoded>::decode(Decoder& decoder)
{
auto value = decoder.decode<int>();
if (UNLIKELY(!decoder.isValid()))
return std::nullopt;
return {
WebKit::CustomEncoded {
WTFMove(*value)
}
};
}

} // namespace IPC

namespace WTF {
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace Namespace { class AnotherCommonClass; }
namespace WebCore { class MoveOnlyBaseClass; }
namespace WebCore { class MoveOnlyDerivedClass; }
namespace WebKit { class PlatformClass; }
namespace WebKit { class CustomEncoded; }

namespace IPC {

Expand Down Expand Up @@ -172,6 +173,11 @@ template<> struct ArgumentCoder<WebKit::PlatformClass> {
static std::optional<WebKit::PlatformClass> decode(Decoder&);
};

template<> struct ArgumentCoder<WebKit::CustomEncoded> {
static void encode(Encoder&, const WebKit::CustomEncoded&);
static std::optional<WebKit::CustomEncoded> decode(Decoder&);
};

} // namespace IPC


Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/Scripts/webkit/tests/SerializedTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#if ENABLE(TEST_FEATURE)
#include "CommonHeader.h"
#endif
#include "CustomEncoded.h"
#if ENABLE(TEST_FEATURE)
#include "FirstMemberType.h"
#endif
Expand Down Expand Up @@ -212,6 +213,12 @@ Vector<SerializedTypeInfo> allSerializedTypes()
"value"_s
}
} },
{ "WebKit::CustomEncoded"_s, {
{
"int"_s,
"value"_s
}
} },
{ "WebCore::SharedStringHash"_s, {
{ "uint32_t"_s, "alias"_s }
} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ webkit_platform_headers: "PlatformClass.h"
[CustomHeader, WebKitPlatform] class WebKit::PlatformClass {
int value;
};

[CustomEncoder] class WebKit::CustomEncoded {
int value;
};
177 changes: 177 additions & 0 deletions Source/WebKit/Shared/RemoteLayerTree/LayerProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "PlatformCAAnimationRemote.h"
#include <WebCore/PlatformCALayer.h>

namespace WebKit {

class RemoteLayerBackingStore;
class RemoteLayerBackingStoreProperties;

enum class LayerChange : uint64_t {
NameChanged = 1LLU << 1,
ChildrenChanged = 1LLU << 2,
PositionChanged = 1LLU << 3,
BoundsChanged = 1LLU << 4,
BackgroundColorChanged = 1LLU << 5,
AnchorPointChanged = 1LLU << 6,
BorderWidthChanged = 1LLU << 7,
BorderColorChanged = 1LLU << 8,
OpacityChanged = 1LLU << 9,
TransformChanged = 1LLU << 10,
SublayerTransformChanged = 1LLU << 11,
HiddenChanged = 1LLU << 12,
GeometryFlippedChanged = 1LLU << 13,
DoubleSidedChanged = 1LLU << 14,
MasksToBoundsChanged = 1LLU << 15,
OpaqueChanged = 1LLU << 16,
ContentsHiddenChanged = 1LLU << 17,
MaskLayerChanged = 1LLU << 18,
ClonedContentsChanged = 1LLU << 19,
ContentsRectChanged = 1LLU << 20,
ContentsScaleChanged = 1LLU << 21,
CornerRadiusChanged = 1LLU << 22,
ShapeRoundedRectChanged = 1LLU << 23,
ShapePathChanged = 1LLU << 24,
MinificationFilterChanged = 1LLU << 25,
MagnificationFilterChanged = 1LLU << 26,
BlendModeChanged = 1LLU << 27,
WindRuleChanged = 1LLU << 28,
SpeedChanged = 1LLU << 29,
TimeOffsetChanged = 1LLU << 30,
BackingStoreChanged = 1LLU << 31,
BackingStoreAttachmentChanged = 1LLU << 32,
FiltersChanged = 1LLU << 33,
AnimationsChanged = 1LLU << 34,
AntialiasesEdgesChanged = 1LLU << 35,
CustomAppearanceChanged = 1LLU << 36,
UserInteractionEnabledChanged = 1LLU << 37,
EventRegionChanged = 1LLU << 38,
ScrollingNodeIDChanged = 1LLU << 39,
#if HAVE(CORE_ANIMATION_SEPARATED_LAYERS)
SeparatedChanged = 1LLU << 40,
#if HAVE(CORE_ANIMATION_SEPARATED_PORTALS)
SeparatedPortalChanged = 1LLU << 41,
DescendentOfSeparatedPortalChanged = 1LLU << 42,
#endif
#endif
VideoGravityChanged = 1LLU << 44,
#if ENABLE(INTERACTION_REGIONS_IN_EVENT_REGION)
CoverageRectChanged = 1LLU << 45,
#endif
};

struct LayerProperties {
WTF_MAKE_STRUCT_FAST_ALLOCATED;
LayerProperties();
LayerProperties(LayerProperties&&);

void encode(IPC::Encoder&) const;
static WARN_UNUSED_RETURN bool decode(IPC::Decoder&, LayerProperties&);

void notePropertiesChanged(OptionSet<LayerChange> changeFlags)
{
changedProperties.add(changeFlags);
everChangedProperties.add(changeFlags);
}

void resetChangedProperties()
{
changedProperties = { };
}

OptionSet<LayerChange> changedProperties;
OptionSet<LayerChange> everChangedProperties;

String name;
std::unique_ptr<WebCore::TransformationMatrix> transform;
std::unique_ptr<WebCore::TransformationMatrix> sublayerTransform;
std::unique_ptr<WebCore::FloatRoundedRect> shapeRoundedRect;

Vector<WebCore::PlatformLayerIdentifier> children;

Vector<std::pair<String, PlatformCAAnimationRemote::Properties>> addedAnimations;
HashSet<String> keysOfAnimationsToRemove;
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
Vector<Ref<WebCore::AcceleratedEffect>> effects;
WebCore::AcceleratedEffectValues baseValues;
#endif

WebCore::FloatPoint3D position;
WebCore::FloatPoint3D anchorPoint { 0.5, 0.5, 0 };
WebCore::FloatRect bounds;
WebCore::FloatRect contentsRect { 0, 0, 1, 1 };
// Used in the WebContent process.
std::unique_ptr<RemoteLayerBackingStore> backingStore;
// Used in the UI process.
std::unique_ptr<RemoteLayerBackingStoreProperties> backingStoreProperties;
std::unique_ptr<WebCore::FilterOperations> filters;
WebCore::Path shapePath;
Markable<WebCore::PlatformLayerIdentifier> maskLayerID;
Markable<WebCore::PlatformLayerIdentifier> clonedLayerID;
#if ENABLE(SCROLLING_THREAD)
WebCore::ScrollingNodeID scrollingNodeID { 0 };
#endif
double timeOffset { 0 };
float speed { 1 };
float contentsScale { 1 };
float cornerRadius { 0 };
float borderWidth { 0 };
float opacity { 1 };
WebCore::Color backgroundColor { WebCore::Color::transparentBlack };
WebCore::Color borderColor { WebCore::Color::black };
WebCore::GraphicsLayer::CustomAppearance customAppearance { WebCore::GraphicsLayer::CustomAppearance::None };
WebCore::PlatformCALayer::FilterType minificationFilter { WebCore::PlatformCALayer::FilterType::Linear };
WebCore::PlatformCALayer::FilterType magnificationFilter { WebCore::PlatformCALayer::FilterType::Linear };
WebCore::BlendMode blendMode { WebCore::BlendMode::Normal };
WebCore::WindRule windRule { WebCore::WindRule::NonZero };
WebCore::MediaPlayerVideoGravity videoGravity { WebCore::MediaPlayerVideoGravity::ResizeAspect };
bool antialiasesEdges { true };
bool hidden { false };
bool backingStoreAttached { true };
bool geometryFlipped { false };
bool doubleSided { false };
bool masksToBounds { false };
bool opaque { false };
bool contentsHidden { false };
bool userInteractionEnabled { true };
WebCore::EventRegion eventRegion;

#if ENABLE(INTERACTION_REGIONS_IN_EVENT_REGION)
WebCore::FloatRect coverageRect;
#endif
#if HAVE(CORE_ANIMATION_SEPARATED_LAYERS)
bool isSeparated { false };
#if HAVE(CORE_ANIMATION_SEPARATED_PORTALS)
bool isSeparatedPortal { false };
bool isDescendentOfSeparatedPortal { false };
#endif
#endif
};

}
Loading

0 comments on commit c94a197

Please sign in to comment.