Skip to content

Commit

Permalink
Port FilterOperation 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=266004

Reviewed by Brady Eidson.

* Source/WebCore/platform/graphics/filters/FilterOperation.cpp:
(WebCore::DefaultFilterOperation::representedType const):
(WebCore::FilterOperation::ipcData const):
(WebCore::FilterOperation::create):
* Source/WebCore/platform/graphics/filters/FilterOperation.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<FilterOperations>::decode):
(IPC::ArgumentCoder<FilterOperation>::encode): Deleted.
(IPC::decodeFilterOperation): Deleted.
(IPC::ArgumentCoder<RefPtr<WebCore::FilterOperation>>::encode): Deleted.
(IPC::ArgumentCoder<RefPtr<WebCore::FilterOperation>>::decode): Deleted.
* Source/WebKit/Shared/WebCoreArgumentCoders.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/271732@main
  • Loading branch information
cdumez committed Dec 8, 2023
1 parent 6294044 commit 8425593
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 152 deletions.
14 changes: 12 additions & 2 deletions Source/WebCore/platform/graphics/filters/FilterOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,24 @@ class FilterOperation : public ThreadSafeRefCounted<FilterOperation> {

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; }
Expand Down
144 changes: 4 additions & 140 deletions Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,121 +431,6 @@ bool ArgumentCoder<ResourceError>::decode(Decoder& decoder, ResourceError& resou
}

#if !USE(COORDINATED_GRAPHICS)
void ArgumentCoder<FilterOperation>::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<BasicColorMatrixFilterOperation>(filter).amount();
return;
case FilterOperation::Type::Invert:
case FilterOperation::Type::Opacity:
case FilterOperation::Type::Brightness:
case FilterOperation::Type::Contrast:
encoder << downcast<BasicComponentTransferFilterOperation>(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<BlurFilterOperation>(filter).stdDeviation();
return;
case FilterOperation::Type::DropShadow: {
const auto& dropShadowFilter = downcast<DropShadowFilterOperation>(filter);
encoder << dropShadowFilter.location();
encoder << dropShadowFilter.stdDeviation();
encoder << dropShadowFilter.color();
return;
}
case FilterOperation::Type::Default:
encoder << downcast<DefaultFilterOperation>(filter).representedType();
return;
case FilterOperation::Type::Passthrough:
return;
}

ASSERT_NOT_REACHED();
}

bool decodeFilterOperation(Decoder& decoder, RefPtr<FilterOperation>& 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<FilterOperations>::encode(Encoder& encoder, const FilterOperations& filters)
{
encoder << static_cast<uint64_t>(filters.size());
Expand All @@ -561,36 +446,15 @@ bool ArgumentCoder<FilterOperations>::decode(Decoder& decoder, FilterOperations&
return false;

for (uint64_t i = 0; i < filterCount; ++i) {
RefPtr<FilterOperation> filter;
if (!decodeFilterOperation(decoder, filter))
std::optional<Ref<FilterOperation>> filter;
decoder >> filter;
if (!filter)
return false;
filters.operations().append(WTFMove(filter));
filters.operations().append(WTFMove(*filter));
}

return true;
}

void ArgumentCoder<RefPtr<WebCore::FilterOperation>>::encode(Encoder& encoder, const RefPtr<WebCore::FilterOperation>& operation)
{
encoder << !!operation;
if (operation)
encoder << *operation;
}

WARN_UNUSED_RETURN bool ArgumentCoder<RefPtr<WebCore::FilterOperation>>::decode(Decoder& decoder, RefPtr<WebCore::FilterOperation>& value)
{
std::optional<bool> 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)
Expand Down
10 changes: 0 additions & 10 deletions Source/WebKit/Shared/WebCoreArgumentCoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,6 @@ template<> struct ArgumentCoder<WebCore::FilterOperations> {
static void encode(Encoder&, const WebCore::FilterOperations&);
static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FilterOperations&);
};

template<> struct ArgumentCoder<WebCore::FilterOperation> {
static void encode(Encoder&, const WebCore::FilterOperation&);
};
WARN_UNUSED_RETURN bool decodeFilterOperation(Decoder&, RefPtr<WebCore::FilterOperation>&);

template<> struct ArgumentCoder<RefPtr<WebCore::FilterOperation>> {
static void encode(Encoder&, const RefPtr<WebCore::FilterOperation>&);
static WARN_UNUSED_RETURN bool decode(Decoder&, RefPtr<WebCore::FilterOperation>&);
};
#endif

#if ENABLE(WIRELESS_PLAYBACK_TARGET)
Expand Down
34 changes: 34 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -6863,6 +6863,40 @@ headers: <JavaScriptCore/WasmModule.h> <WebCore/ImageBitmapBacking.h> <WebCore/M
WebCore::SerializedScriptValue::Internals m_internals;
};

#if !USE(COORDINATED_GRAPHICS)
[RefCounted] class WebCore::FilterOperation subclasses {
WebCore::BasicColorMatrixFilterOperation
WebCore::BasicComponentTransferFilterOperation
WebCore::BlurFilterOperation
WebCore::DropShadowFilterOperation
WebCore::DefaultFilterOperation
WebCore::PassthroughFilterOperation
}

[CustomHeader, RefCounted] class WebCore::BasicColorMatrixFilterOperation {
double amount();
[Validator='WebCore::FilterOperation::isBasicColorMatrixFilterOperationType(*type)'] WebCore::FilterOperation::Type type();
};
[CustomHeader, RefCounted] class WebCore::BasicComponentTransferFilterOperation {
double amount();
[Validator='WebCore::FilterOperation::isBasicComponentTransferFilterOperationType(*type)'] WebCore::FilterOperation::Type type();
};
[CustomHeader, RefCounted] class WebCore::BlurFilterOperation {
WebCore::Length stdDeviation();
};
[CustomHeader, RefCounted] class WebCore::DropShadowFilterOperation {
WebCore::IntPoint location();
int stdDeviation();
WebCore::Color color();
};
[CustomHeader, RefCounted] class WebCore::DefaultFilterOperation {
WebCore::FilterOperation::Type representedType();
};
[CustomHeader, RefCounted] class WebCore::PassthroughFilterOperation {
[NotSerialized] WebCore::FilterOperation::Type type();
};
#endif // !USE(COORDINATED_GRAPHICS)

#if ENABLE(MEDIA_SOURCE)

header: <WebCore/MediaSourcePrivate.h>
Expand Down

0 comments on commit 8425593

Please sign in to comment.