Skip to content

Commit

Permalink
Revert most of "Add CanvasFilter objects as possible 2D context filters"
Browse files Browse the repository at this point in the history
It did not have implementer agreement after all.

This reverts most of commit 5db6a65, keeping some of the editorial refactorings.

Co-authored-by: Domenic Denicola <[email protected]>
  • Loading branch information
annevk and domenic authored Aug 30, 2022
1 parent 22d8cdb commit c7ad099
Showing 1 changed file with 18 additions and 274 deletions.
292 changes: 18 additions & 274 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -4207,8 +4207,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://svgwg.org/svg2-draft/struct.html#TitleElement">SVG <code>title</code></dfn> element</li>
<li><dfn data-x-href="https://svgwg.org/svg2-draft/struct.html#UseElement">SVG <code>use</code></dfn> element</li>
<li><dfn data-x-href="https://svgwg.org/svg2-draft/painting.html#TextRendering">SVG <code>text-rendering</code></dfn> property</li>
<li><dfn data-x-href="https://svgwg.org/svg2-draft/struct.html#TermCoreAttribute">core attribute</dfn></li>
<li><dfn data-x-href="https://svgwg.org/svg2-draft/styling.html#PresentationAttributes">presentation attribute</dfn></li>
</ul>
</dd>

Expand All @@ -4221,8 +4219,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<ul class="brief">
<li><dfn data-x-href="https://drafts.fxtf.org/filter-effects/#typedef-filter-value-list">&lt;filter-value-list&gt;</dfn></li>
<li><dfn data-x-href="https://drafts.fxtf.org/filter-effects/#filter-primitive-attributes">filter primitive attribute</dfn></li>
<li><dfn data-x-href="https://drafts.fxtf.org/filter-effects/#FilterProperty">filter property</dfn></li>
</ul>
</dd>

Expand Down Expand Up @@ -62188,14 +62184,7 @@ interface mixin <dfn interface>CanvasShadowStyles</dfn> {

interface mixin <dfn interface>CanvasFilters</dfn> {
// filters
attribute (DOMString or <span>CanvasFilter</span>) <span data-x="dom-context-2d-filter">filter</span>; // (default "none")
};

typedef record&lt;DOMString, any> <dfn>CanvasFilterInput</dfn>;

[Exposed=(Window,Worker,PaintWorklet)]
interface <dfn interface>CanvasFilter</dfn> {
<span data-x="dom-CanvasFilter">constructor</span>(optional (<span>CanvasFilterInput</span> or sequence&lt;<span>CanvasFilterInput</span>>) filters);
attribute DOMString <span data-x="dom-context-2d-filter">filter</span>; // (default "none")
};

interface mixin <dfn interface>CanvasRect</dfn> {
Expand Down Expand Up @@ -67340,76 +67329,50 @@ console.log(pixels.data[2]);

<h6>Filters</h6>

<p>All drawing operations on an object which implements the <code>CanvasFilters</code> interface
are affected by the global <dfn attribute for="CanvasFilters"><code
<p>All drawing operations on an object which implements the <code>CanvasFilters</code>
interface are affected by the global <dfn attribute for="CanvasFilters"><code
data-x="dom-context-2d-filter">filter</code></dfn> attribute.</p>

<dl class="domintro">
<dt><code data-x=""><var>context</var>.<span subdfn data-x="dom-context-2d-filter">filter</span> [ = <var>value</var> ]</code></dt>

<dd>
<p>Returns the current filter.</p>


<p>Can be set, to change the filter. Values can either be the string "<code
data-x="">none</code>", a string parseable as a <span>&lt;filter-value-list&gt;</span>, or a
<code>CanvasFilter</code> object.</p>
data-x="">none</code>" or a string parseable as a <span>&lt;filter-value-list&gt;</span>. Other
values are ignored.</p>
</dd>

<dt><code data-x=""><var>filter</var> = new <span subdfn data-x="dom-CanvasFilter">CanvasFilter</span>(<var>input</var>)</code></dt>
<dd><p>Constructs a new <code data-x="dom-CanvasFilter">CanvasFilter</code> from the properties
of the <var>input</var> object. These properties include a <code data-x="">filter</code>
property, whose value is one of the <span>supported filter names</span>, and additionally can
include properties corresponding to the settings for the filter. These latter properties are the
same as the XML attribute names when using the corresponding SVG filters.</p></dd>

<dt><code data-x=""><var>filter</var> = new <span data-x="dom-CanvasFilter">CanvasFilter</span>(<var>inputs</var>)</code></dt>
<dd><p>Constructs a new <code data-x="dom-CanvasFilter">CanvasFilter</code> from the
<var>inputs</var> array. Each element in the array is an input as described for the previous
overload. They are composed in sequence to create the final filter.</p></dd>
</dl>

<div w-nodev>

<p>Such objects have an associated <dfn data-x="concept-canvas-current-filter">current
filter</dfn>, which is either a string or a <code>CanvasFilter</code>. Initially the <span
filter</dfn>, which is a string. Initially the <span
data-x="concept-canvas-current-filter">current filter</span> is set to the string "<code
data-x="">none</code>". Whenever the value of the <span
data-x="concept-canvas-current-filter">current filter</span> is the string "<code
data-x="">none</code>" filters will be disabled for the context.</p>

<p>A <code>CanvasFilter</code> is an interface for creating SVG filters using JavaScript. A
<code>CanvasFilter</code> has an associated <dfn
data-x="concept-concept-canvasfilter-xml-filter-list">XML filter list</dfn>. An <span
data-x="concept-concept-canvasfilter-xml-filter-list">XML filter list</span> is a
<span>list</span> of <span>XML element data for filters</span> that fully describes an SVG filter
network. It is set during construction of the <code>CanvasFilter</code>.</p>

<p>The <code data-x="dom-context-2d-filter">filter</code> getter steps are to return
<span>this</span>'s <span data-x="concept-canvas-current-filter">current filter</span>.</p>

<p>The <code data-x="dom-context-2d-filter">filter</code> setter steps are:</p>

<ol>
<li>
<p>If the given value is a string, then:</p>
<li><p>If the given value is "<code data-x="">none</code>", then set <span>this</span>'s <span
data-x="concept-canvas-current-filter">current filter</span> to "<code data-x="">none</code>"
and return.</p></li>

<ol>
<li><p>If the given value is "<code data-x="">none</code>", then set <span>this</span>'s <span
data-x="concept-canvas-current-filter">current filter</span> to "<code data-x="">none</code>"
and return.</p></li>
<li><p>Let <var>parsedValue</var> be the result of <span data-x="parse something according to a
CSS grammar">parsing</span> the given values as a <span>&lt;filter-value-list&gt;</span>. If any
property-independent style sheet syntax like 'inherit' or 'initial' is present, then this
parsing must return failure.</p></li>

<li><p>Let <var>parsedValue</var> be the result of <span data-x="parse something according to
a CSS grammar">parsing</span> the given values as a <span>&lt;filter-value-list&gt;</span>. If
any property-independent style sheet syntax like 'inherit' or 'initial' is present, then this
parsing must return failure.</p></li>
<li><p>If <var>parsedValue</var> is failure, then return.</p></li>

<li><p>If <var>parsedValue</var> is failure, then return.</p></li>

<li><p>Set <span>this</span>'s <span data-x="concept-canvas-current-filter">current
filter</span> to the given value.</p></li>
</ol>
</li>

<li><p>Otherwise, set <span>this</span>'s <span data-x="concept-canvas-current-filter">current
<li><p>Set <span>this</span>'s <span data-x="concept-canvas-current-filter">current
filter</span> to the given value.</p></li>
</ol>

Expand All @@ -67424,220 +67387,6 @@ console.log(pixels.data[2]);
undefined</code> are all treated as unparseable inputs and the value of the <span
data-x="concept-canvas-current-filter">current filter</span> is left unchanged.</p>

<div w-nodev>

<p>For the construction of <code>CanvasFilter</code> objects, the following definitions are
needed:</p>

</div>

<p>The <dfn>supported filter names</dfn> are "<code data-x="">gaussianBlur</code>", "<code
data-x="">colorMatrix</code>", "<code data-x="">convolveMatrix</code>", and "<code
data-x="">componentTransfer</code>".

<div w-nodev>

<p>The <dfn>XML element data for filters</dfn> is a <span>struct</span>, with the following <span
data-x="struct item">items</span>:</p>

<ul>
<li><p>A string <dfn data-x="xml-filter-name">name</dfn></p></li>

<li><p>An <span data-x="ordered map">ordered map</span> of strings to strings <dfn
data-x="xml-filter-attributes">attributes</dfn></p></li>

<li><p>A list of <span>XML element data for filters</span> <dfn
data-x="xml-filter-children">children</dfn></p></li>
</ul>

<p>To get the <dfn>IDL type for a canvas filter attribute</dfn> <var>attrName</var>:</p>

<ol>
<li><p>Let <var>type</var> be the type listed for <var>attrName</var> in <cite>Filter
Effects</cite>. <ref spec=FILTERS></p></li>

<li><p>If <var>type</var> is "<code data-x="">false | true</code>", then return <code
data-x="idl-boolean">boolean</code>.</p></li>

<li><p>If <var>type</var> is "<code data-x="">list of &lt;number&gt;s</code>", then return <code
data-x="">sequence&lt;long long&gt;</code>.</p></li>

<li><p>If <var>type</var> is <code data-x="">"&lt;number-optional-number&gt;</code>", "<code
data-x="">&lt;number&gt;</code>", or "<code data-x="">&lt;integer&gt;</code>", then return <code
data-x="">long long</code>.</p></li>

<li><p>Return <code data-x="idl-DOMString">DOMString</code>.</p></li>
</ol>

<p>To <dfn data-x="generate-xml-value">generate an XML value</dfn> from a <var>key</var>,
<var>value</var> pair:

<ol>
<li><p>Let <var>type</var> be the result of getting the <span>IDL type for a canvas filter
attribute</span> for <var>key</var>.</p></li>

<li><p>Let <var>idlValue</var> be the result of <span
data-x="concept-idl-convert">converting</span> <var>value</var> to <var>type</var>.</p></li>

<li><p>Let <var>xmlValue</var> be the result of <span
data-x="concept-idl-convert">converting</span> <var>idlValue</var> to an ECMAScript value, and
then <span data-x="concept-idl-convert">converting</span> that result to a <code
data-x="idl-DOMString">DOMString</code>.</p></li>

<li><p>Return <var>xmlValue</var>.</p></li>
</ol>

<p>The <dfn constructor for="CanvasFilter"><code data-x="dom-CanvasFilter">new
CanvasFilter(<var>filters</var>)</code></dfn> constructor steps are:</p>

<ol>
<li><p>Let <var>xmlFilters</var> be an empty list.</p></li>

<li><p>If <var>filters</var> is a <code>CanvasFilterInput</code>, then set <var>filters</var> to
« <var>filters</var> ».</p></li>

<li>
<p>For each <var>filterDict</var> of <var>filters:</var></p>

<ol>
<li><p>If <var>filterDict</var>["<code data-x="">filter</code>"] does not <span data-x="map
exists">exist</span>, then throw a <code>TypeError</code>.</p></li>

<li><p>Let <var>filterName</var> be the value of <var>filterDict</var>["<code
data-x="">filter</code>"].</p></li>

<li><p>If <var>filterName</var> is not one of <span>supported filter names</span>, then
<span>continue</span>.</p></li>

<li><p>Let <var>xmlName</var> be the concatenation of "<code data-x="">fe</code>", the first
code unit of <var>filterName</var> <span>converted to ASCII uppercase</span>, and all code
units of <var>filterName</var> after the first one.</p></li>

<li><p>Let <var>xmlFilter</var> be a new <span>XML element data for filters</span> whose <span
data-x="xml-filter-name">name</span> is <var>xmlName</var>, whose <span
data-x="xml-filter-attributes">attributes</span> is an empty ordered map, and whose <span
data-x="xml-filter-children">children</span> is an empty list.</p></li>

<li><p><span data-x="list append">Append</span> <var>xmlFilter</var> to
<var>xmlFilters</var>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <var>key</var> → <var>value</var> of
<var>filterDict</var>:</p>

<ol>
<li>
<p>If any of the following are true:</p>

<ul>
<li><p><var>key</var> is not the local name of an attribute listed for the filter
primitive given by <var>xmlName</var> <ref spec=FILTERS></p></li>

<li><p><var>key</var> is the local name of a <span>core attribute</span></p></li>

<li><p><var>key</var> is the local name of a <span>presentation attribute</span></p></li>

<li><p><var>key</var> is the local name of a <span>filter primitive
attribute</span></p></li>

<li><p><var>key</var> is "<code data-x="">in</code>" or "<code
data-x="">filter</code>"</p></li>

<li><p><var>key</var> contains U+003A (:)</p></li>
</ul>

<p>then <span>continue</span>.</p>
</li>

<li>
<p>If <var>key</var> is one of "<code data-x="">funcR</code>", "<code
data-x="">funcG</code>", "<code data-x="">funcB</code>", "<code
data-x="">funcA</code>":</p>

<ol>
<li><p>Set <var>value</var> to the result of <span
data-x="concept-idl-convert">converting</span> <var>value</var> to <code
data-x="">record&lt;DOMString, any></code>.</p></li>

<li><p>Let <var>xmlTransferName</var> be the concatenation of "<code data-x="">fe</code>",
the first code unit of <var>key</var> <span>converted to ASCII uppercase</span>, and all
code units of name after the first one.</p></li>

<li><p>Let <var>transferFunction</var> be a new <span>XML element data for filters</span>
whose <span data-x="xml-filter-name">name</span> is <var>xmlTransferName</var>, whose
<span data-x="xml-filter-attributes">attributes</span> is an empty ordered map, and whose
<span data-x="xml-filter-children">children</span> is an empty list.</p></li>

<li>
<p>For each <var>transferName</var> → <var>transferValue</var> of <var>value</var>:</p>

<ol>
<li><p>Let <var>transferFunctionValue</var> be the result of <span
data-x="generate-xml-value">generating an XML value</span> from <var>transferName</var>
and <var>transferValue</var>.</p></li>

<li><p>Set <var>transferFunction</var>'s <span
data-x="xml-filter-attributes">attributes</span>[<var>key</var>] to
<var>transferFunctionValue</var>.</p></li>
</ol>
</li>

<li><p>Append <var>transferFunction</var> to <var>xmlFilter</var>'s <span
data-x="xml-filter-children">children</span>.</p></li>
</ol>
</li>

<li>
<p>Otherwise:</p>

<ol>
<li><p>Let <var>attrXMLValue</var> be the result of <span
data-x="generate-xml-value">generating an XML value</span> from <var>key</var> and
<var>value</var>.</p></li>

<li><p>Set <var>xmlFilter</var>'s <span
data-x="xml-filter-attributes">attributes</span>[<var>key</var>] to
<var>attrXMLValue</var>.</p></li>
</ol>
</li>
</ol>
</li>
</ol>
</li>

<li><p>Set <span>this</span>'s <span data-x="concept-concept-canvasfilter-xml-filter-list">XML
filter list</span> to <var>xmlFilters</var>.</p></li>
</ol>

</div>

<div class="example" id="example-canvas-filter">
<p>The following example will set the canvas's filter to a <code data-x="">colorMatrix</code>
filter that swaps the green and red channels, then blurs the result by 5 pixels:</p>

<pre><code class="js">// canvas is a reference to a &lt;canvas> element
const context = canvas.getContext('2d');
context.filter = new CanvasFilter([
{
filter: "colorMatrix",
type: "matrix",
values: [
0, 1, 0, 0, 0,
1, 0, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
],
},
{
filter: "gaussianBlur",
stdDeviation: 5,
}
]);</code></pre>
</div>

<p class="note">Currently, <code>CanvasFilter</code>s can only be linked lists. Full filter
graphs are a planned expansion of this feature.</p>

<p>Coordinates used in the value of the <span data-x="concept-canvas-current-filter">current
filter</span> are interpreted such that one pixel is equivalent to one SVG user space unit and to
one canvas coordinate space unit. Filter coordinates are not affected by the <span
Expand Down Expand Up @@ -67701,12 +67450,7 @@ context.filter = new CanvasFilter([
the input to the <span data-x="concept-canvas-current-filter">current filter</span>, creating
image <var>B</var>. If the <span data-x="concept-canvas-current-filter">current filter</span>
is a string parseable as a <span>&lt;filter-value-list&gt;</span>, then draw using the <span
data-x="concept-canvas-current-filter">current filter</span> in the same manner as SVG. If the
<span data-x="concept-canvas-current-filter">current filter</span> is a
<code>CanvasFilter</code>, draw using the equivalent SVG for the XML structure stored in the
<span data-x="concept-canvas-current-filter">current filter</span>'s by mapping each
<span>filter property</span> of the <span
data-x="concept-concept-canvasfilter-xml-filter-list">XML filter list</span>.</p>
data-x="concept-canvas-current-filter">current filter</span> in the same manner as SVG.</p>

<p>Otherwise, let <var>B</var> be an alias for <var>A</var>.</p>
</li>
Expand Down

0 comments on commit c7ad099

Please sign in to comment.