Skip to content

Commit 8a94842

Browse files
authored
Apply globalAlpha on the canvas filter source
The previous specification for canvas filters applies the globalAlpha on the filter result. The drawing model essentially says: 1. Render the shape, creating image A. 2. When the current filter is set, use it on image A to create image B. 3. Multiply the alpha component of every pixel in B by global alpha. This leads to a unexpected behavior. When drawing a transparent shape with a drop-shadow filter, the shadow should be visible through the transparent foreground. This should be true whether the drawing is made transparent via fillStyle or via globalAlpha. This is how Chromium and Gecko behave. Following the specification to the letter however, the shadow wouldn't be visible through the foreground. Align the standard with Chromium's and Gecko's behavior: 1. Render the shape, creating image A. 2. Multiply the alpha component of every pixel in A by global alpha, creating image B. 3. When the current filter is set, use it on image B to create image C.
1 parent 3a8303e commit 8a94842

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

source

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70026,6 +70026,9 @@ console.log(pixels.data[2]);
7002670026
and line styles must be honored, and the stroke must itself also be subjected to the current
7002770027
transformation matrix.</p></li>
7002870028

70029+
<li><p>Multiply the alpha component of every pixel in <var>A</var> by <code
70030+
data-x="concept-canvas-global-alpha">global alpha</code>.</p></li>
70031+
7002970032
<li>
7003070033
<p>When the <span data-x="concept-canvas-current-filter">current filter</span> is set to a
7003170034
value other than "<code data-x="">none</code>" and all the externally-defined filters it
@@ -70041,16 +70044,10 @@ console.log(pixels.data[2]);
7004170044
<li><p><span>When shadows are drawn</span>, render the shadow from image <var>B</var>,
7004270045
using the current shadow styles, creating image <var>C</var>.</p></li>
7004370046

70044-
<li><p><span>When shadows are drawn</span>, multiply the alpha component of every pixel in
70045-
<var>C</var> by <code data-x="concept-canvas-global-alpha">global alpha</code>.</p></li>
70046-
7004770047
<li><p><span>When shadows are drawn</span>, composite <var>C</var> within the
7004870048
<span>clipping region</span> over the current <span>output bitmap</span> using the <span>current
7004970049
compositing and blending operator</span>.</p></li>
7005070050

70051-
<li><p>Multiply the alpha component of every pixel in <var>B</var> by <code
70052-
data-x="concept-canvas-global-alpha">global alpha</code>.</p></li>
70053-
7005470051
<li><p>Composite <var>B</var> within the <span>clipping region</span> over the current
7005570052
<span>output bitmap</span> using the <span>current compositing and blending
7005670053
operator</span>.</p></li>

0 commit comments

Comments
 (0)