haikuwebkit/LayoutTests/svg/canvas/canvas-global-alpha-svg.html

39 lines
1014 B
HTML
Raw Permalink Normal View History

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. Canonical link: https://commits.webkit.org/159934@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180511 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-23 20:31:04 +00:00
<!DOCTYPE html>
<html>
<style>
canvas, svg {
image-rendering: pixelated;
}
</style>
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. Canonical link: https://commits.webkit.org/159934@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180511 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-23 20:31:04 +00:00
<body>
<canvas id="canvas"></canvas>
<script>
if (window.testRunner)
testRunner.waitUntilDone();
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. Canonical link: https://commits.webkit.org/159934@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180511 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-23 20:31:04 +00:00
var canvas = document.getElementById("canvas");
canvas.width = 150;
canvas.height = 150;
var context = canvas.getContext("2d");
context.strokeStyle = "green";
context.lineWidth = 50;
context.strokeRect(0,0,150,150);
var svgImage = new Image();
svgImage.onload = function() {
context.globalAlpha = 0.2;
context.drawImage(svgImage, 25, 25);
if (window.testRunner)
testRunner.notifyDone();
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. Canonical link: https://commits.webkit.org/159934@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180511 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-02-23 20:31:04 +00:00
};
svgImage.src = "data:image/svg+xml, \
<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'> \
<rect width='100%' height='100%' style='fill:none;stroke:green;stroke-width:50%;'/> \
<rect x='25%' y='25%' width='50%' height='50%' fill='green' fill-opacity='0.2'/> \
</svg>";
</script>
</body>
</html>