<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[286753] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/286753">286753</a></dd>
<dt>Author</dt> <dd>said@apple.com</dd>
<dt>Date</dt> <dd>2021-12-08 16:36:26 -0800 (Wed, 08 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GPU Process] [Filters] Add the encoding and decoding for SVGFilter
https://bugs.webkit.org/show_bug.cgi?id=234024

Reviewed by Wenson Hsieh.

Source/WebCore:

Add new methods to help encoding and decoding SVGFilter members. Also
add a new constructor for SVGFilter which is going to be called from
FilterReference.

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/filters/FilterEffectGeometry.h:
(WebCore::FilterEffectGeometry::encode const):
(WebCore::FilterEffectGeometry::decode):

* platform/graphics/filters/SourceAlpha.cpp:
(WebCore::SourceAlpha::create):
(WebCore::SourceAlpha::SourceAlpha):
* platform/graphics/filters/SourceAlpha.h:
The plan is to remove the input effects from FilterEffect. Currently it
is still used but not through FilterEffect::apply(). So it is okay for
now for GPUProcess to create SourceAlpha without input since the input
will not used inside GPUProcess.

* svg/SVGUnitTypes.h:
* svg/graphics/filters/SVGFilter.cpp:
(WebCore::SVGFilter::create):
(WebCore::SVGFilter::SVGFilter):
* svg/graphics/filters/SVGFilter.h:

Source/WebKit:

When encoding the SVGFilter we need to encode the individual FilterEffects
in filter.expression(). And for every SVGFilterExpressionTerm we need to
encode the index of its Ref<FilterEffect> in the individual FilterEffects.

When decoding the SVGFilter we do the opposite. We get the Ref<FilterEffect>
which corresponds to index of ExpressionReferenceTerm. We send the decoded
expression to the constructor of SVGFilter.

* Platform/IPC/FilterReference.h:
(IPC::FilterReference::decodeFilterEffect):
(IPC::FilterReference::ExpressionReferenceTerm::encode const):
(IPC::FilterReference::ExpressionReferenceTerm::decode):
(IPC::FilterReference::encodeSVGFilter):
(IPC::FilterReference::decodeSVGFilter):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreHeaderscmake">trunk/Source/WebCore/Headers.cmake</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsfiltersFilterEffectGeometryh">trunk/Source/WebCore/platform/graphics/filters/FilterEffectGeometry.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsfiltersSourceAlphacpp">trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsfiltersSourceAlphah">trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.h</a></li>
<li><a href="#trunkSourceWebCoresvgSVGUnitTypesh">trunk/Source/WebCore/svg/SVGUnitTypes.h</a></li>
<li><a href="#trunkSourceWebCoresvggraphicsfiltersSVGFiltercpp">trunk/Source/WebCore/svg/graphics/filters/SVGFilter.cpp</a></li>
<li><a href="#trunkSourceWebCoresvggraphicsfiltersSVGFilterh">trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCFilterReferenceh">trunk/Source/WebKit/Platform/IPC/FilterReference.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/ChangeLog      2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2021-12-08  Said Abou-Hallawa  <said@apple.com>
+
+        [GPU Process] [Filters] Add the encoding and decoding for SVGFilter
+        https://bugs.webkit.org/show_bug.cgi?id=234024
+
+        Reviewed by Wenson Hsieh.
+
+        Add new methods to help encoding and decoding SVGFilter members. Also
+        add a new constructor for SVGFilter which is going to be called from
+        FilterReference.
+
+        * Headers.cmake:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/filters/FilterEffectGeometry.h:
+        (WebCore::FilterEffectGeometry::encode const):
+        (WebCore::FilterEffectGeometry::decode):
+
+        * platform/graphics/filters/SourceAlpha.cpp:
+        (WebCore::SourceAlpha::create):
+        (WebCore::SourceAlpha::SourceAlpha):
+        * platform/graphics/filters/SourceAlpha.h:
+        The plan is to remove the input effects from FilterEffect. Currently it
+        is still used but not through FilterEffect::apply(). So it is okay for 
+        now for GPUProcess to create SourceAlpha without input since the input
+        will not used inside GPUProcess.
+
+        * svg/SVGUnitTypes.h:
+        * svg/graphics/filters/SVGFilter.cpp:
+        (WebCore::SVGFilter::create):
+        (WebCore::SVGFilter::SVGFilter):
+        * svg/graphics/filters/SVGFilter.h:
+
</ins><span class="cx"> 2021-12-08  Don Olmstead  <don.olmstead@sony.com>
</span><span class="cx"> 
</span><span class="cx">         [Win] Remove CF when using Windows clipboard
</span></span></pre></div>
<a id="trunkSourceWebCoreHeaderscmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Headers.cmake (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Headers.cmake       2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/Headers.cmake  2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -1597,6 +1597,7 @@
</span><span class="cx">     platform/graphics/filters/FilterOperation.h
</span><span class="cx">     platform/graphics/filters/FilterOperations.h
</span><span class="cx">     platform/graphics/filters/LightSource.h
</span><ins>+    platform/graphics/filters/SourceAlpha.h
</ins><span class="cx">     platform/graphics/filters/SourceGraphic.h
</span><span class="cx"> 
</span><span class="cx">     platform/graphics/iso/ISOBox.h
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -2756,7 +2756,7 @@
</span><span class="cx">          8485227C1190162C006EDC7F /* JSSVGHKernElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 848522781190162C006EDC7F /* JSSVGHKernElement.h */; };
</span><span class="cx">          8485227E1190162C006EDC7F /* JSSVGVKernElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 8485227A1190162C006EDC7F /* JSSVGVKernElement.h */; };
</span><span class="cx">          8485228B1190173C006EDC7F /* SVGVKernElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 848522881190173C006EDC7F /* SVGVKernElement.h */; };
</span><del>-               84A81F3E0FC7DFF000955300 /* SourceAlpha.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A81F3C0FC7DFF000955300 /* SourceAlpha.h */; };
</del><ins>+                84A81F3E0FC7DFF000955300 /* SourceAlpha.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A81F3C0FC7DFF000955300 /* SourceAlpha.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">           84A81F420FC7E02700955300 /* SourceGraphic.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A81F400FC7E02700955300 /* SourceGraphic.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          84B349A222F86E7500D47BCF /* EventTargetConcrete.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B349A022F86E7400D47BCF /* EventTargetConcrete.h */; };
</span><span class="cx">          84B6B978120F13E500B8EFAF /* SVGPathSegListSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B6B976120F13E500B8EFAF /* SVGPathSegListSource.h */; };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsfiltersFilterEffectGeometryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffectGeometry.h (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/filters/FilterEffectGeometry.h    2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffectGeometry.h       2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -78,6 +78,9 @@
</span><span class="cx">         return std::nullopt;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<FilterEffectGeometry> decode(Decoder&);
+
</ins><span class="cx"> private:
</span><span class="cx">     FloatRect m_boundaries;
</span><span class="cx">     OptionSet<Flags> m_flags;
</span><span class="lines">@@ -85,4 +88,42 @@
</span><span class="cx"> 
</span><span class="cx"> using FilterEffectGeometryMap = HashMap<Ref<FilterEffect>, FilterEffectGeometry>;
</span><span class="cx"> 
</span><ins>+template<class Encoder>
+void FilterEffectGeometry::encode(Encoder& encoder) const
+{
+    encoder << m_boundaries;
+    encoder << m_flags;
+}
+
+template<class Decoder>
+std::optional<FilterEffectGeometry> FilterEffectGeometry::decode(Decoder& decoder)
+{
+    std::optional<FloatRect> boundaries;
+    decoder >> boundaries;
+    if (!boundaries)
+        return std::nullopt;
+
+    std::optional<OptionSet<Flags>> flags;
+    decoder >> flags;
+    if (!flags)
+        return std::nullopt;
+
+    return FilterEffectGeometry(*boundaries, *flags);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><ins>+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::FilterEffectGeometry::Flags> {
+    using values = EnumValues<
+        WebCore::FilterEffectGeometry::Flags,
+
+        WebCore::FilterEffectGeometry::Flags::HasX,
+        WebCore::FilterEffectGeometry::Flags::HasY,
+        WebCore::FilterEffectGeometry::Flags::HasWidth,
+        WebCore::FilterEffectGeometry::Flags::HasHeight
+    >;
+};
+
+} // namespace WTF
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsfiltersSourceAlphacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp   2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp      2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -21,17 +21,26 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "SourceAlpha.h"
</span><span class="cx"> 
</span><del>-#include "Filter.h"
</del><span class="cx"> #include "SourceAlphaSoftwareApplier.h"
</span><span class="cx"> #include <wtf/text/TextStream.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+Ref<SourceAlpha> SourceAlpha::create()
+{
+    return adoptRef(*new SourceAlpha());
+}
+
</ins><span class="cx"> Ref<SourceAlpha> SourceAlpha::create(FilterEffect& sourceEffect)
</span><span class="cx"> {
</span><span class="cx">     return adoptRef(*new SourceAlpha(sourceEffect));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+SourceAlpha::SourceAlpha()
+    : FilterEffect(FilterEffect::Type::SourceAlpha)
+{
+}
+
</ins><span class="cx"> SourceAlpha::SourceAlpha(FilterEffect& sourceEffect)
</span><span class="cx">     : FilterEffect(FilterEffect::Type::SourceAlpha)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsfiltersSourceAlphah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.h (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.h     2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.h        2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -25,12 +25,14 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class SourceAlpha : public FilterEffect {
</span><del>-public:        
</del><ins>+public:
+    WEBCORE_EXPORT static Ref<SourceAlpha> create();
</ins><span class="cx">     static Ref<SourceAlpha> create(FilterEffect&);
</span><span class="cx"> 
</span><span class="cx">     static AtomString effectName() { return FilterEffect::sourceAlphaName(); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    SourceAlpha();
</ins><span class="cx">     explicit SourceAlpha(FilterEffect&);
</span><span class="cx"> 
</span><span class="cx">     FloatRect calculateImageRect(const Filter&, const FilterImageVector& inputs, const FloatRect& primitiveSubregion) const override;
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGUnitTypesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGUnitTypes.h (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGUnitTypes.h  2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/svg/SVGUnitTypes.h     2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -66,3 +66,17 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><ins>+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::SVGUnitTypes::SVGUnitType> {
+    using values = EnumValues<
+        WebCore::SVGUnitTypes::SVGUnitType,
+
+        WebCore::SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN,
+        WebCore::SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE,
+        WebCore::SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
+    >;
+};
+
+} // namespace WTF
</ins></span></pre></div>
<a id="trunkSourceWebCoresvggraphicsfiltersSVGFiltercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/graphics/filters/SVGFilter.cpp (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/graphics/filters/SVGFilter.cpp  2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/svg/graphics/filters/SVGFilter.cpp     2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -69,6 +69,11 @@
</span><span class="cx">     return filter;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr<SVGFilter> SVGFilter::create(const FloatRect& targetBoundingBox, SVGUnitTypes::SVGUnitType primitiveUnits, SVGFilterExpression&& expression)
+{
+    return adoptRef(*new SVGFilter(targetBoundingBox, primitiveUnits, WTFMove(expression)));
+}
+
</ins><span class="cx"> SVGFilter::SVGFilter(RenderingMode renderingMode, const FloatSize& filterScale, ClipOperation clipOperation, const FloatRect& filterRegion, const FloatRect& targetBoundingBox, SVGUnitTypes::SVGUnitType primitiveUnits)
</span><span class="cx">     : Filter(Filter::Type::SVGFilter, renderingMode, filterScale, clipOperation, filterRegion)
</span><span class="cx">     , m_targetBoundingBox(targetBoundingBox)
</span><span class="lines">@@ -76,6 +81,14 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+SVGFilter::SVGFilter(const FloatRect& targetBoundingBox, SVGUnitTypes::SVGUnitType primitiveUnits, SVGFilterExpression&& expression)
+    : Filter(Filter::Type::SVGFilter)
+    , m_targetBoundingBox(targetBoundingBox)
+    , m_primitiveUnits(primitiveUnits)
+    , m_expression(WTFMove(expression))
+{
+}
+
</ins><span class="cx"> FloatSize SVGFilter::resolvedSize(const FloatSize& size) const
</span><span class="cx"> {
</span><span class="cx">     return m_primitiveUnits == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX ? size * m_targetBoundingBox.size() : size;
</span></span></pre></div>
<a id="trunkSourceWebCoresvggraphicsfiltersSVGFilterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h    2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h       2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -39,9 +39,13 @@
</span><span class="cx">     static RefPtr<SVGFilter> create(SVGFilterElement&, SVGFilterBuilder&, RenderingMode, const FloatSize& filterScale, ClipOperation, const FloatRect& targetBoundingBox, FilterEffect& previousEffect);
</span><span class="cx">     static RefPtr<SVGFilter> create(SVGFilterElement&, SVGFilterBuilder&, RenderingMode, const FloatSize& filterScale, const FloatRect& filterRegion, const FloatRect& targetBoundingBox);
</span><span class="cx">     static RefPtr<SVGFilter> create(SVGFilterElement&, SVGFilterBuilder&, RenderingMode, const FloatSize& filterScale, ClipOperation, const FloatRect& filterRegion, const FloatRect& targetBoundingBox, FilterEffect* previousEffect);
</span><ins>+    WEBCORE_EXPORT static RefPtr<SVGFilter> create(const FloatRect& targetBoundingBox, SVGUnitTypes::SVGUnitType primitiveUnits, SVGFilterExpression&&);
</ins><span class="cx"> 
</span><span class="cx">     FloatRect targetBoundingBox() const { return m_targetBoundingBox; }
</span><ins>+    SVGUnitTypes::SVGUnitType primitiveUnits() const { return m_primitiveUnits; }
</ins><span class="cx"> 
</span><ins>+    const SVGFilterExpression& expression() const { return m_expression; }
+    
</ins><span class="cx">     RefPtr<FilterEffect> lastEffect() const final;
</span><span class="cx"> 
</span><span class="cx">     RefPtr<FilterImage> apply() final;
</span><span class="lines">@@ -50,6 +54,7 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     SVGFilter(RenderingMode, const FloatSize& filterScale, ClipOperation, const FloatRect& filterRegion, const FloatRect& targetBoundingBox, SVGUnitTypes::SVGUnitType primitiveUnits);
</span><ins>+    SVGFilter(const FloatRect& targetBoundingBox, SVGUnitTypes::SVGUnitType primitiveUnits, SVGFilterExpression&&);
</ins><span class="cx"> 
</span><span class="cx">     void setExpression(SVGFilterExpression&& expression) { m_expression = WTFMove(expression); }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebKit/ChangeLog       2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2021-12-08  Said Abou-Hallawa  <said@apple.com>
+
+        [GPU Process] [Filters] Add the encoding and decoding for SVGFilter
+        https://bugs.webkit.org/show_bug.cgi?id=234024
+
+        Reviewed by Wenson Hsieh.
+
+        When encoding the SVGFilter we need to encode the individual FilterEffects
+        in filter.expression(). And for every SVGFilterExpressionTerm we need to
+        encode the index of its Ref<FilterEffect> in the individual FilterEffects.
+
+        When decoding the SVGFilter we do the opposite. We get the Ref<FilterEffect>
+        which corresponds to index of ExpressionReferenceTerm. We send the decoded
+        expression to the constructor of SVGFilter.
+
+        * Platform/IPC/FilterReference.h:
+        (IPC::FilterReference::decodeFilterEffect):
+        (IPC::FilterReference::ExpressionReferenceTerm::encode const):
+        (IPC::FilterReference::ExpressionReferenceTerm::decode):
+        (IPC::FilterReference::encodeSVGFilter):
+        (IPC::FilterReference::decodeSVGFilter):
+
</ins><span class="cx"> 2021-12-08  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Add SPI to load a resource in the context of a page
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCFilterReferenceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/FilterReference.h (286752 => 286753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/FilterReference.h       2021-12-09 00:32:05 UTC (rev 286752)
+++ trunk/Source/WebKit/Platform/IPC/FilterReference.h  2021-12-09 00:36:26 UTC (rev 286753)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx"> #include <WebCore/Filter.h>
</span><span class="cx"> #include <WebCore/FilterEffectVector.h>
</span><span class="cx"> #include <WebCore/SVGFilter.h>
</span><ins>+#include <WebCore/SourceAlpha.h>
</ins><span class="cx"> #include <WebCore/SourceGraphic.h>
</span><span class="cx"> 
</span><span class="cx"> namespace IPC {
</span><span class="lines">@@ -62,8 +63,20 @@
</span><span class="cx">     template<class Decoder> static std::optional<FilterReference> decode(Decoder&);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    struct ExpressionReferenceTerm {
+        unsigned index;
+        std::optional<WebCore::FilterEffectGeometry> geometry;
+        unsigned level;
+    
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static std::optional<ExpressionReferenceTerm> decode(Decoder&);
+    };
+    
+    using ExpressionReference = Vector<ExpressionReferenceTerm>;
+
</ins><span class="cx">     template<class Encoder> static void encodeFilterEffect(const WebCore::FilterEffect&, Encoder&);
</span><span class="cx">     template<class Decoder> static RefPtr<WebCore::FilterEffect> decodeFilterEffect(Decoder&, WebCore::FilterFunction::Type);
</span><ins>+    template<class Decoder> static RefPtr<WebCore::FilterEffect> decodeFilterEffect(Decoder&);
</ins><span class="cx"> 
</span><span class="cx">     template<class Encoder> static void encodeSVGFilter(const WebCore::SVGFilter&, Encoder&);
</span><span class="cx">     template<class Decoder> static RefPtr<WebCore::SVGFilter> decodeSVGFilter(Decoder&);
</span><span class="lines">@@ -243,11 +256,14 @@
</span><span class="cx">         effect = WebCore::FETurbulence::decode(decoder);
</span><span class="cx">         break;
</span><span class="cx"> 
</span><ins>+    case WebCore::FilterEffect::Type::SourceAlpha:
+        effect = WebCore::SourceAlpha::create();
+        break;
+
</ins><span class="cx">     case WebCore::FilterEffect::Type::SourceGraphic:
</span><span class="cx">         effect = WebCore::SourceGraphic::create();
</span><span class="cx">         break;
</span><span class="cx"> 
</span><del>-    case WebCore::FilterEffect::Type::SourceAlpha:
</del><span class="cx">     default:
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><span class="cx">     }
</span><span class="lines">@@ -260,17 +276,121 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template<class Decoder>
+RefPtr<WebCore::FilterEffect> FilterReference::decodeFilterEffect(Decoder& decoder)
+{
+    std::optional<WebCore::FilterFunction::Type> filterType;
+    decoder >> filterType;
+    if (!filterType)
+        return nullptr;
+
+    return decodeFilterEffect(decoder, *filterType);
+}
+
</ins><span class="cx"> template<class Encoder>
</span><ins>+void FilterReference::ExpressionReferenceTerm::encode(Encoder& encoder) const
+{
+    encoder << index;
+    encoder << geometry;
+    encoder << level;
+}
+
+template<class Decoder>
+std::optional<FilterReference::ExpressionReferenceTerm> FilterReference::ExpressionReferenceTerm::decode(Decoder& decoder)
+{
+    std::optional<unsigned> index;
+    decoder >> index;
+    if (!index)
+        return std::nullopt;
+
+    std::optional<std::optional<WebCore::FilterEffectGeometry>> geometry;
+    decoder >> geometry;
+    if (!geometry)
+        return std::nullopt;
+
+    std::optional<unsigned> level;
+    decoder >> level;
+    if (!level)
+        return std::nullopt;
+
+    return { { *index, *geometry, *level } };
+}
+
+template<class Encoder>
</ins><span class="cx"> void FilterReference::encodeSVGFilter(const WebCore::SVGFilter& filter, Encoder& encoder)
</span><span class="cx"> {
</span><del>-    // FIXME: Encode the SVGFilter.
</del><ins>+    HashMap<Ref<WebCore::FilterEffect>, unsigned> indicies;
+    Vector<Ref<WebCore::FilterEffect>> effects;
+
+    // Get the individual FilterEffects in filter.expression().
+    for (auto& term : filter.expression()) {
+        if (indicies.contains(term.effect))
+            continue;
+        indicies.add(term.effect, effects.size());
+        effects.append(term.effect);
+    }
+
+    // Replace the Ref<FilterEffect> in SVGExpressionTerm with its index in indicies.
+    auto expressionReference = WTF::map(filter.expression(), [&indicies] (auto&& term) -> ExpressionReferenceTerm {
+        ASSERT(indicies.contains(term.effect));
+        unsigned index = indicies.get(term.effect);
+        return { index, term.geometry, term.level };
+    });
+
+    encoder << filter.targetBoundingBox();
+    encoder << filter.primitiveUnits();
+    
+    encoder << effects.size();
+    for (auto& effect : effects)
+        encodeFilterEffect(effect, encoder);
+
+    encoder << expressionReference;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<class Decoder>
</span><span class="cx"> RefPtr<WebCore::SVGFilter> FilterReference::decodeSVGFilter(Decoder& decoder)
</span><span class="cx"> {
</span><del>-    // FIXME: Decode the SVGFilter.
-    return nullptr;
</del><ins>+    std::optional<WebCore::FloatRect> targetBoundingBox;
+    decoder >> targetBoundingBox;
+    if (!targetBoundingBox)
+        return nullptr;
+
+    std::optional<WebCore::SVGUnitTypes::SVGUnitType> primitiveUnits;
+    decoder >> primitiveUnits;
+    if (!primitiveUnits)
+        return nullptr;
+
+    std::optional<size_t> effectsSize;
+    decoder >> effectsSize;
+    if (!effectsSize || !*effectsSize)
+        return nullptr;
+
+    Vector<Ref<WebCore::FilterEffect>> effects;
+
+    for (size_t i = 0; i < *effectsSize; ++i) {
+        auto effect = decodeFilterEffect(decoder);
+        if (!effect)
+            return nullptr;
+
+        effects.append(effect.releaseNonNull());
+    }
+
+    std::optional<ExpressionReference> expressionReference;
+    decoder >> expressionReference;
+    if (!expressionReference || expressionReference->isEmpty())
+        return nullptr;
+
+    WebCore::SVGFilterExpression expression;
+    expression.reserveInitialCapacity(expressionReference->size());
+
+    // Replace the index in ExpressionReferenceTerm with its Ref<FilterEffect> in effects.
+    for (auto& term : *expressionReference) {
+        if (term.index >= effects.size())
+            return nullptr;
+        expression.uncheckedAppend({ effects[term.index], term.geometry, term.level });
+    }
+    
+    return WebCore::SVGFilter::create(*targetBoundingBox, *primitiveUnits, WTFMove(expression));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<class Encoder>
</span></span></pre>
</div>
</div>

</body>
</html>