[cg] userSpaceOnUse SVG Patterns have the wrong origin

https://bugs.webkit.org/show_bug.cgi?id=75741
<rdar://problem/9383222>

Reviewed by Simon Fraser.

The transformation from pattern space to user space should use the userToBase CTM,
not the current CTM.

Test: svg/custom/pattern-userSpaceOnUse-userToBaseTransform.xhtml

* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::applyStrokePattern):
(WebCore::GraphicsContext::applyFillPattern):
(WebCore::GraphicsContext::getCTM):
* platform/graphics/cg/TransformationMatrixCG.cpp:
(WebCore::AffineTransform::AffineTransform): Add a AffineTransform(CGAffineTransform) constructor
* platform/graphics/transforms/AffineTransform.h:

Add a test that ensures that userSpaceOnUse patterns are rendered in the
correct orientation and location in both the accelerated compositing and
regular cases, as well as with SVG translation.

* platform/mac/svg/custom/pattern-userSpaceOnUse-userToBaseTransform-expected.png: Added.
* platform/mac/svg/custom/pattern-userSpaceOnUse-userToBaseTransform-expected.txt: Added.
* svg/custom/pattern-userSpaceOnUse-userToBaseTransform.xhtml: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104356 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7ecb1d83
2012-01-06 Tim Horton <timothy_horton@apple.com>
[cg] userSpaceOnUse SVG Patterns have the wrong origin
https://bugs.webkit.org/show_bug.cgi?id=75741
<rdar://problem/9383222>
Reviewed by Simon Fraser.
Add a test that ensures that userSpaceOnUse patterns are rendered in the
correct orientation and location in both the accelerated compositing and
regular cases, as well as with SVG translation.
* platform/mac/svg/custom/pattern-userSpaceOnUse-userToBaseTransform-expected.png: Added.
* platform/mac/svg/custom/pattern-userSpaceOnUse-userToBaseTransform-expected.txt: Added.
* svg/custom/pattern-userSpaceOnUse-userToBaseTransform.xhtml: Added.
2012-01-06 Dale Curtis <dalecurtis@chromium.org>
[chromium] Rebaseline media/media-document-audio-repaint after 74123 goes in.
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x358
RenderBlock {html} at (0,0) size 800x358
RenderBody {body} at (8,8) size 784x342
RenderText {#text} at (0,0) size 762x18
text run at (0,0) width 762: "There should be no red displayed on the screen, and the patterns should not change when the browser window is resized."
RenderBR {br} at (762,0) size 0x18
RenderBR {br} at (0,18) size 0x18
RenderSVGRoot {svg} at (8,44) size 202x203
RenderSVGContainer {g} at (9,45) size 200x200
RenderSVGRect {rect} at (9,145) size 100x50 [fill={[type=SOLID] [color=#FF0000]}] [x=0.00] [y=100.00] [width=100.00] [height=50.00]
RenderSVGRect {rect} at (109,45) size 100x50 [fill={[type=SOLID] [color=#FF0000]}] [x=100.00] [y=0.00] [width=100.00] [height=50.00]
RenderSVGRect {rect} at (9,145) size 100x100 [fill={[type=PATTERN] [id="pattern"]}] [x=0.00] [y=100.00] [width=100.00] [height=100.00]
RenderSVGRect {rect} at (109,45) size 100x100 [fill={[type=PATTERN] [id="pattern"]}] [x=100.00] [y=0.00] [width=100.00] [height=100.00]
RenderText {#text} at (202,324) size 4x18
text run at (202,324) width 4: " "
RenderSVGRoot {svg} at (214,44) size 202x287
RenderSVGText {text} at (5,266) size 81x18 contains 1 chunk(s)
RenderSVGInlineText {#text} at (0,0) size 81x18
chunk 1 text run 1 at (5.00,280.00) startOffset 0 endOffset 11 width 81.00: "+Transforms"
RenderSVGContainer {g} at (215,145) size 100x100 [transform={m=((1.00,0.00)(0.00,1.00)) t=(0.00,100.00)}]
RenderSVGRect {rect} at (215,145) size 100x50 [fill={[type=SOLID] [color=#FF0000]}] [x=0.00] [y=0.00] [width=100.00] [height=50.00]
RenderSVGRect {rect} at (215,145) size 100x100 [fill={[type=PATTERN] [id="pattern"]}] [x=0.00] [y=0.00] [width=100.00] [height=100.00]
RenderSVGContainer {g} at (315,45) size 100x100 [transform={m=((1.00,0.00)(0.00,1.00)) t=(100.00,0.00)}]
RenderSVGRect {rect} at (315,45) size 100x50 [fill={[type=SOLID] [color=#FF0000]}] [x=0.00] [y=0.00] [width=100.00] [height=50.00]
RenderSVGRect {rect} at (315,45) size 100x100 [fill={[type=PATTERN] [id="pattern"]}] [x=0.00] [y=0.00] [width=100.00] [height=100.00]
RenderSVGHiddenContainer {defs} at (0,0) size 0x0
RenderSVGResourcePattern {pattern} [id="pattern"] [patternUnits=userSpaceOnUse] [patternContentUnits=userSpaceOnUse]
RenderSVGRect {rect} at (215,45) size 100x25 [fill={[type=SOLID] [color=#008000]}] [x=0.00] [y=0.00] [width=100.00] [height=25.00]
RenderSVGRect {rect} at (215,70) size 100x25 [fill={[type=SOLID] [color=#0000FF]}] [x=0.00] [y=25.00] [width=100.00] [height=25.00]
RenderText {#text} at (408,324) size 4x18
text run at (408,324) width 4: " "
RenderText {#text} at (0,0) size 0x0
layer at (420,44) size 202x302
RenderSVGRoot {svg} at (420,44) size 202x287
RenderSVGText {text} at (5,266) size 169x18 contains 1 chunk(s)
RenderSVGInlineText {#text} at (0,0) size 169x18
chunk 1 text run 1 at (5.00,280.00) startOffset 0 endOffset 24 width 169.00: "+Accelerated Compositing"
RenderSVGContainer {g} at (421,45) size 200x200
RenderSVGRect {rect} at (421,145) size 100x100 [fill={[type=PATTERN] [id="pattern"]}] [x=0.00] [y=100.00] [width=100.00] [height=100.00]
RenderSVGRect {rect} at (521,45) size 100x100 [fill={[type=PATTERN] [id="pattern"]}] [x=100.00] [y=0.00] [width=100.00] [height=100.00]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>userSpaceOnUse SVG Patterns</title>
</head>
<body>
There should be no red displayed on the screen, and the patterns should not change when the browser window is resized.<br/><br/>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg" width="200" height="300" style="border: solid 1px black;">
<g>
<rect x="0" y="100" width="100" height="50" fill="red"/>
<rect x="100" y="0" width="100" height="50" fill="red"/>
<rect x="0" y="100" width="100" height="100" fill="url(#pattern)"/>
<rect x="100" y="0" width="100" height="100" fill="url(#pattern)"/>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg" width="200" height="300" style="border: solid 1px black;">
<text x="5" y="280">+Transforms</text>
<g transform="translate(0, 100)">
<rect width="100" height="50" fill="red"/>
<rect width="100" height="100" fill="url(#pattern)"/>
</g>
<g transform="translate(100, 0)">
<rect width="100" height="50" fill="red"/>
<rect width="100" height="100" fill="url(#pattern)"/>
</g>
<defs>
<pattern id="pattern" patternUnits="userSpaceOnUse" patternContentUnits="userSpaceOnUse" x="0" y="0" width="100" height="100">
<rect width="100" height="25" preserveAspectRatio="none" fill="green"/>
<rect width="100" y="25" height="25" preserveAspectRatio="none" fill="blue"/>
</pattern>
</defs>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg" width="200" height="300" style="border: solid 1px black; -webkit-transform: translateZ(0px); -moz-transform: translateZ(0px); -o-transform: translateZ(0px);">
<text x="5" y="280">+Accelerated Compositing</text>
<g>
<rect x="0" y="100" width="100" height="100" fill="url(#pattern)"/>
<rect x="100" y="0" width="100" height="100" fill="url(#pattern)"/>
</g>
</svg>
</body>
</html>
2012-01-06 Tim Horton <timothy_horton@apple.com>
[cg] userSpaceOnUse SVG Patterns have the wrong origin
https://bugs.webkit.org/show_bug.cgi?id=75741
<rdar://problem/9383222>
Reviewed by Simon Fraser.
The transformation from pattern space to user space should use the userToBase CTM,
not the current CTM.
Test: svg/custom/pattern-userSpaceOnUse-userToBaseTransform.xhtml
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::applyStrokePattern):
(WebCore::GraphicsContext::applyFillPattern):
(WebCore::GraphicsContext::getCTM):
* platform/graphics/cg/TransformationMatrixCG.cpp:
(WebCore::AffineTransform::AffineTransform): Add a AffineTransform(CGAffineTransform) constructor
* platform/graphics/transforms/AffineTransform.h:
2012-01-05 Simon Fraser <simon.fraser@apple.com>
Avoid falling into tiled layers more often when the device scale factor is > 1
......@@ -527,8 +527,9 @@ void GraphicsContext::clipConvexPolygon(size_t numberOfPoints, const FloatPoint*
void GraphicsContext::applyStrokePattern()
{
CGContextRef cgContext = platformContext();
AffineTransform userToBaseCTM = AffineTransform(wkGetUserToBaseCTM(cgContext));
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_state.strokePattern->createPlatformPattern(getCTM()));
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_state.strokePattern->createPlatformPattern(userToBaseCTM));
if (!platformPattern)
return;
......@@ -542,8 +543,9 @@ void GraphicsContext::applyStrokePattern()
void GraphicsContext::applyFillPattern()
{
CGContextRef cgContext = platformContext();
AffineTransform userToBaseCTM = AffineTransform(wkGetUserToBaseCTM(cgContext));
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_state.fillPattern->createPlatformPattern(getCTM()));
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_state.fillPattern->createPlatformPattern(userToBaseCTM));
if (!platformPattern)
return;
......@@ -1253,8 +1255,7 @@ AffineTransform GraphicsContext::getCTM() const
if (paintingDisabled())
return AffineTransform();
CGAffineTransform t = CGContextGetCTM(platformContext());
return AffineTransform(t.a, t.b, t.c, t.d, t.tx, t.ty);
return AffineTransform(CGContextGetCTM(platformContext()));
}
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect, RoundingMode roundingMode)
......
......@@ -54,6 +54,11 @@ TransformationMatrix::operator CGAffineTransform() const
narrowPrecisionToCGFloat(f()));
}
AffineTransform::AffineTransform(const CGAffineTransform& t)
{
setMatrix(t.a, t.b, t.c, t.d, t.tx, t.ty);
}
AffineTransform::operator CGAffineTransform() const
{
return CGAffineTransformMake(narrowPrecisionToCGFloat(a()),
......
......@@ -63,6 +63,10 @@ public:
AffineTransform();
AffineTransform(double a, double b, double c, double d, double e, double f);
#if USE(CG)
AffineTransform(const CGAffineTransform&);
#endif
void setMatrix(double a, double b, double c, double d, double e, double f);
void map(double x, double y, double& x2, double& y2) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment