Drawing an SVG image into a canvas using drawImage() ignores globalAlpha.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Feb 2015 20:31:04 +0000 (20:31 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Feb 2015 20:31:04 +0000 (20:31 +0000)
commitb178f1cce0e5635deb202e6ae96bda2a16848c9c
treea7780566a26c7d12a0310db44f5b66528cca33d8
parent7ec9efdc7eb7f9850513992a87efcef33fdbc084
Drawing an SVG image into a canvas using drawImage() ignores globalAlpha.
https://bugs.webkit.org/show_bug.cgi?id=141729.

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2015-02-23
Reviewed by Simon Fraser.

Source/WebCore:

When drawing an SVG image and the drawing context is set to be transparent,
make sure this transparency is applied to the compositing layer.

Test: svg/canvas/canvas-global-alpha-svg.html

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::setAlpha): Make setAlpha() calls the platform
function and sets 'm_state.alpha' to the input value.

(WebCore::GraphicsContext::alpha): Add a new function 'alpha()' which
returns the value of the global alpha.

* platform/graphics/GraphicsContext.h:
(WebCore::GraphicsContextState::GraphicsContextState): Add a new member
'alpha' to the context state since the getter function CGContextGetAlpha
is defined only in a private header file. Also move single line functions
from the source file to the header file.

* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::setPlatformAlpha):
(WebCore::GraphicsContext::setAlpha): Deleted.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::setPlatformAlpha):
(WebCore::GraphicsContext::setAlpha): Deleted.
Rename setAlpha() to setPlatformAlpha() in the platform files. Add setAlpha()
to the core file. setAlpha() will set the value of 'm_state.alpha' and call
setPlatformAlpha().

* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::draw): If the drawing context is transparent, apply its
global alpha value to the compositing layer.

LayoutTests:

Add a new test which draws an SVG image on a canvas after setting its
globalAlpha to a value less than 1.

* svg/canvas/canvas-global-alpha-svg-expected.html: Added.
* svg/canvas/canvas-global-alpha-svg.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180511 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/svg/canvas/canvas-global-alpha-svg-expected.html [new file with mode: 0644]
LayoutTests/svg/canvas/canvas-global-alpha-svg.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsContext.cpp
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
Source/WebCore/svg/graphics/SVGImage.cpp