Skip to content

Commit

Permalink
Port SystemImage to the new IPC serialization format
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266009

Reviewed by Alex Christensen.

* Source/WebKit/Scripts/generate-serializers.py:
(parse_serialized_types):
* Source/WebKit/Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<SystemImage>::encode): Deleted.
(IPC::ArgumentCoder<SystemImage>::decode): Deleted.
* Source/WebKit/Shared/WebCoreArgumentCoders.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/271754@main
  • Loading branch information
cdumez committed Dec 8, 2023
1 parent 6f54043 commit 2a3e294
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 78 deletions.
3 changes: 3 additions & 0 deletions Source/WebKit/Scripts/generate-serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def decode_type(type):

if type.members_are_subclasses:
result.append(' auto type = decoder.decode<' + type.subclass_enum_name() + '>();')
result.append(' UNUSED_PARAM(type);')
result.append(' if (UNLIKELY(!decoder.isValid()))')
result.append(' return std::nullopt;')
result.append('')
Expand Down Expand Up @@ -995,6 +996,7 @@ def generate_impl(serialized_types, serialized_enums, headers, generating_webkit
result.append('#if ' + type.condition)
result.append('template<> bool ' + type.function_name_for_enum() + '<IPC::' + type.subclass_enum_name() + ', void>(IPC::EncodedVariantIndex value)')
result.append('{')
result.append('IGNORE_WARNINGS_BEGIN("switch-unreachable")')
result.append(' switch (static_cast<IPC::' + type.subclass_enum_name() + '>(value)) {')
for member in type.members:
if member.condition is not None:
Expand All @@ -1006,6 +1008,7 @@ def generate_impl(serialized_types, serialized_enums, headers, generating_webkit
result.append(' default:')
result.append(' return false;')
result.append(' }')
result.append('IGNORE_WARNINGS_END')
result.append('}')
if type.condition is not None:
result.append('#endif')
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/Scripts/webkit/tests/GeneratedSerializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ void ArgumentCoder<WebCore::TimingFunction>::encode(Encoder& encoder, const WebC
std::optional<Ref<WebCore::TimingFunction>> ArgumentCoder<WebCore::TimingFunction>::decode(Decoder& decoder)
{
auto type = decoder.decode<WebCore_TimingFunction_Subclass>();
UNUSED_PARAM(type);
if (UNLIKELY(!decoder.isValid()))
return std::nullopt;

Expand Down Expand Up @@ -756,6 +757,7 @@ void ArgumentCoder<WebCore::MoveOnlyBaseClass>::encode(Encoder& encoder, WebCore
std::optional<WebCore::MoveOnlyBaseClass> ArgumentCoder<WebCore::MoveOnlyBaseClass>::decode(Decoder& decoder)
{
auto type = decoder.decode<WebCore_MoveOnlyBaseClass_Subclass>();
UNUSED_PARAM(type);
if (UNLIKELY(!decoder.isValid()))
return std::nullopt;

Expand Down Expand Up @@ -1225,6 +1227,7 @@ namespace WTF {

template<> bool isValidEnum<IPC::WebCore_TimingFunction_Subclass, void>(IPC::EncodedVariantIndex value)
{
IGNORE_WARNINGS_BEGIN("switch-unreachable")
switch (static_cast<IPC::WebCore_TimingFunction_Subclass>(value)) {
case IPC::WebCore_TimingFunction_Subclass::LinearTimingFunction:
case IPC::WebCore_TimingFunction_Subclass::CubicBezierTimingFunction:
Expand All @@ -1236,16 +1239,19 @@ template<> bool isValidEnum<IPC::WebCore_TimingFunction_Subclass, void>(IPC::Enc
default:
return false;
}
IGNORE_WARNINGS_END
}

template<> bool isValidEnum<IPC::WebCore_MoveOnlyBaseClass_Subclass, void>(IPC::EncodedVariantIndex value)
{
IGNORE_WARNINGS_BEGIN("switch-unreachable")
switch (static_cast<IPC::WebCore_MoveOnlyBaseClass_Subclass>(value)) {
case IPC::WebCore_MoveOnlyBaseClass_Subclass::MoveOnlyDerivedClass:
return true;
default:
return false;
}
IGNORE_WARNINGS_END
}

template<> bool isValidEnum<EnumWithoutNamespace, void>(uint8_t value)
Expand Down
72 changes: 0 additions & 72 deletions Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,78 +664,6 @@ std::optional<WebCore::ScriptBuffer> ArgumentCoder<WebCore::ScriptBuffer>::decod
return std::nullopt;
}

template<typename Encoder>
void ArgumentCoder<SystemImage>::encode(Encoder& encoder, const SystemImage& systemImage)
{
encoder << systemImage.systemImageType();

switch (systemImage.systemImageType()) {
#if ENABLE(APPLE_PAY)
case SystemImageType::ApplePayLogo:
encoder << downcast<ApplePayLogoSystemImage>(systemImage);
return;
#endif
#if USE(SYSTEM_PREVIEW)
case SystemImageType::ARKitBadge:
encoder << downcast<ARKitBadgeSystemImage>(systemImage);
return;
#endif
#if USE(APPKIT)
case SystemImageType::AppKitControl:
encoder << downcast<AppKitControlSystemImage>(systemImage);
return;
#endif
}

ASSERT_NOT_REACHED();
}

template
void ArgumentCoder<SystemImage>::encode<Encoder>(Encoder&, const SystemImage&);
template
void ArgumentCoder<SystemImage>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, const SystemImage&);

std::optional<Ref<SystemImage>> ArgumentCoder<SystemImage>::decode(Decoder& decoder)
{
std::optional<SystemImageType> systemImageType;
decoder >> systemImageType;
if (!systemImageType)
return std::nullopt;

switch (*systemImageType) {
#if ENABLE(APPLE_PAY)
case SystemImageType::ApplePayLogo: {
std::optional<Ref<ApplePayLogoSystemImage>> image;
decoder >> image;
if (!image)
return std::nullopt;
return WTFMove(*image);
}
#endif
#if USE(SYSTEM_PREVIEW)
case SystemImageType::ARKitBadge: {
std::optional<Ref<ARKitBadgeSystemImage>> image;
decoder >> image;
if (!image)
return std::nullopt;
return WTFMove(*image);
}
#endif
#if USE(APPKIT)
case SystemImageType::AppKitControl: {
std::optional<Ref<AppKitControlSystemImage>> image;
decoder >> image;
if (!image)
return std::nullopt;
return WTFMove(*image);
}
#endif
}

ASSERT_NOT_REACHED();
return std::nullopt;
}

template<typename Encoder>
void ArgumentCoder<ControlPart>::encode(Encoder& encoder, const ControlPart& part)
{
Expand Down
6 changes: 0 additions & 6 deletions Source/WebKit/Shared/WebCoreArgumentCoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,6 @@ template<> struct ArgumentCoder<WebCore::ScriptBuffer> {
static std::optional<WebCore::ScriptBuffer> decode(Decoder&);
};

template<> struct ArgumentCoder<WebCore::SystemImage> {
template<typename Encoder>
static void encode(Encoder&, const WebCore::SystemImage&);
static std::optional<Ref<WebCore::SystemImage>> decode(Decoder&);
};

template<> struct ArgumentCoder<WebCore::ControlPart> {
template<typename Encoder>
static void encode(Encoder&, const WebCore::ControlPart&);
Expand Down
12 changes: 12 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -6844,6 +6844,18 @@ enum class WebCore::InspectorClientDeveloperPreference : uint8_t {
MockCaptureDevicesEnabled,
};

[AdditionalEncoder=StreamConnectionEncoder, RefCounted] class WebCore::SystemImage subclasses {
#if ENABLE(APPLE_PAY)
WebCore::ApplePayLogoSystemImage
#endif
#if USE(SYSTEM_PREVIEW)
WebCore::ARKitBadgeSystemImage
#endif
#if USE(APPKIT)
WebCore::AppKitControlSystemImage
#endif
}

#if ENABLE(WEB_CODECS)
header: <WebCore/WebCodecsEncodedVideoChunk.h>
[CustomHeader, RefCounted] class WebCore::WebCodecsEncodedVideoChunkStorage {
Expand Down

0 comments on commit 2a3e294

Please sign in to comment.