diff --git a/Source/WebCore/platform/graphics/filters/FilterOperation.h b/Source/WebCore/platform/graphics/filters/FilterOperation.h index d97bf9b926d7..644fc6a3dc70 100644 --- a/Source/WebCore/platform/graphics/filters/FilterOperation.h +++ b/Source/WebCore/platform/graphics/filters/FilterOperation.h @@ -79,14 +79,24 @@ class FilterOperation : public ThreadSafeRefCounted { Type type() const { return m_type; } + static bool isBasicColorMatrixFilterOperationType(Type type) + { + return type == Type::Grayscale || type == Type::Sepia || type == Type::Saturate || type == Type::HueRotate; + } + bool isBasicColorMatrixFilterOperation() const { - return m_type == Type::Grayscale || m_type == Type::Sepia || m_type == Type::Saturate || m_type == Type::HueRotate; + return isBasicColorMatrixFilterOperationType(m_type); + } + + static bool isBasicComponentTransferFilterOperationType(Type type) + { + return type == Type::Invert || type == Type::Brightness || type == Type::Contrast || type == Type::Opacity; } bool isBasicComponentTransferFilterOperation() const { - return m_type == Type::Invert || m_type == Type::Brightness || m_type == Type::Contrast || m_type == Type::Opacity; + return isBasicComponentTransferFilterOperationType(m_type); } bool isSameType(const FilterOperation& o) const { return o.type() == m_type; } diff --git a/Source/WebKit/Shared/WebCoreArgumentCoders.cpp b/Source/WebKit/Shared/WebCoreArgumentCoders.cpp index ff5353746a52..d10fff37c024 100644 --- a/Source/WebKit/Shared/WebCoreArgumentCoders.cpp +++ b/Source/WebKit/Shared/WebCoreArgumentCoders.cpp @@ -431,121 +431,6 @@ bool ArgumentCoder::decode(Decoder& decoder, ResourceError& resou } #if !USE(COORDINATED_GRAPHICS) -void ArgumentCoder::encode(Encoder& encoder, const FilterOperation& filter) -{ - encoder << filter.type(); - - switch (filter.type()) { - case FilterOperation::Type::None: - case FilterOperation::Type::Reference: - ASSERT_NOT_REACHED(); - return; - case FilterOperation::Type::Grayscale: - case FilterOperation::Type::Sepia: - case FilterOperation::Type::Saturate: - case FilterOperation::Type::HueRotate: - encoder << downcast(filter).amount(); - return; - case FilterOperation::Type::Invert: - case FilterOperation::Type::Opacity: - case FilterOperation::Type::Brightness: - case FilterOperation::Type::Contrast: - encoder << downcast(filter).amount(); - return; - case FilterOperation::Type::AppleInvertLightness: - ASSERT_NOT_REACHED(); // AppleInvertLightness is only used in -apple-color-filter. - return; - case FilterOperation::Type::Blur: - encoder << downcast(filter).stdDeviation(); - return; - case FilterOperation::Type::DropShadow: { - const auto& dropShadowFilter = downcast(filter); - encoder << dropShadowFilter.location(); - encoder << dropShadowFilter.stdDeviation(); - encoder << dropShadowFilter.color(); - return; - } - case FilterOperation::Type::Default: - encoder << downcast(filter).representedType(); - return; - case FilterOperation::Type::Passthrough: - return; - } - - ASSERT_NOT_REACHED(); -} - -bool decodeFilterOperation(Decoder& decoder, RefPtr& filter) -{ - FilterOperation::Type type; - if (!decoder.decode(type)) - return false; - - switch (type) { - case FilterOperation::Type::None: - case FilterOperation::Type::Reference: - ASSERT_NOT_REACHED(); - return false; - case FilterOperation::Type::Grayscale: - case FilterOperation::Type::Sepia: - case FilterOperation::Type::Saturate: - case FilterOperation::Type::HueRotate: { - double amount; - if (!decoder.decode(amount)) - return false; - filter = BasicColorMatrixFilterOperation::create(amount, type); - return true; - } - case FilterOperation::Type::Invert: - case FilterOperation::Type::Opacity: - case FilterOperation::Type::Brightness: - case FilterOperation::Type::Contrast: { - double amount; - if (!decoder.decode(amount)) - return false; - filter = BasicComponentTransferFilterOperation::create(amount, type); - return true; - } - case FilterOperation::Type::AppleInvertLightness: - ASSERT_NOT_REACHED(); // AppleInvertLightness is only used in -apple-color-filter. - return false; - case FilterOperation::Type::Blur: { - Length stdDeviation; - if (!decoder.decode(stdDeviation)) - return false; - filter = BlurFilterOperation::create(stdDeviation); - return true; - } - case FilterOperation::Type::DropShadow: { - IntPoint location; - int stdDeviation; - Color color; - if (!decoder.decode(location)) - return false; - if (!decoder.decode(stdDeviation)) - return false; - if (!decoder.decode(color)) - return false; - filter = DropShadowFilterOperation::create(location, stdDeviation, color); - return true; - } - case FilterOperation::Type::Default: { - FilterOperation::Type representedType; - if (!decoder.decode(representedType)) - return false; - filter = DefaultFilterOperation::create(representedType); - return true; - } - case FilterOperation::Type::Passthrough: - filter = PassthroughFilterOperation::create(); - return true; - } - - ASSERT_NOT_REACHED(); - return false; -} - - void ArgumentCoder::encode(Encoder& encoder, const FilterOperations& filters) { encoder << static_cast(filters.size()); @@ -561,36 +446,15 @@ bool ArgumentCoder::decode(Decoder& decoder, FilterOperations& return false; for (uint64_t i = 0; i < filterCount; ++i) { - RefPtr filter; - if (!decodeFilterOperation(decoder, filter)) + std::optional> filter; + decoder >> filter; + if (!filter) return false; - filters.operations().append(WTFMove(filter)); + filters.operations().append(WTFMove(*filter)); } return true; } - -void ArgumentCoder>::encode(Encoder& encoder, const RefPtr& operation) -{ - encoder << !!operation; - if (operation) - encoder << *operation; -} - -WARN_UNUSED_RETURN bool ArgumentCoder>::decode(Decoder& decoder, RefPtr& value) -{ - std::optional isNull; - decoder >> isNull; - if (!isNull) - return false; - - if (!decodeFilterOperation(decoder, value)) { - value = nullptr; - return false; - } - return true; -} - #endif // !USE(COORDINATED_GRAPHICS) #if ENABLE(WIRELESS_PLAYBACK_TARGET) diff --git a/Source/WebKit/Shared/WebCoreArgumentCoders.h b/Source/WebKit/Shared/WebCoreArgumentCoders.h index d4ff2659c740..bff9704b5d31 100644 --- a/Source/WebKit/Shared/WebCoreArgumentCoders.h +++ b/Source/WebKit/Shared/WebCoreArgumentCoders.h @@ -212,16 +212,6 @@ template<> struct ArgumentCoder { static void encode(Encoder&, const WebCore::FilterOperations&); static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FilterOperations&); }; - -template<> struct ArgumentCoder { - static void encode(Encoder&, const WebCore::FilterOperation&); -}; -WARN_UNUSED_RETURN bool decodeFilterOperation(Decoder&, RefPtr&); - -template<> struct ArgumentCoder> { - static void encode(Encoder&, const RefPtr&); - static WARN_UNUSED_RETURN bool decode(Decoder&, RefPtr&); -}; #endif #if ENABLE(WIRELESS_PLAYBACK_TARGET) diff --git a/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in b/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in index 774b7df268ef..b4464181a9f6 100644 --- a/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in +++ b/Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in @@ -6863,6 +6863,40 @@ headers: