Bug 52509 - Shadow is not shown when using strokeRect with a gradient strokeStyle
Summary: Shadow is not shown when using strokeRect with a gradient strokeStyle
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Helder Correia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-15 01:41 PST by Helder Correia
Modified: 2012-04-12 13:04 PDT (History)
6 users (show)

See Also:


Attachments
Patch (16.45 KB, patch)
2011-01-15 02:11 PST, Helder Correia
no flags Details | Formatted Diff | Diff
Concat CTM with strokeGradient->gradientSpaceTransform() (16.74 KB, patch)
2011-01-23 20:46 PST, Helder Correia
no flags Details | Formatted Diff | Diff
Added svg/css/text-gradient-stroke-shadow.svg (400.64 KB, patch)
2011-02-02 15:25 PST, Helder Correia
no flags Details | Formatted Diff | Diff
New rect-gradient-stroke-shadow.svg. Add comment for line width. Fix build. (131.32 KB, patch)
2011-02-03 15:13 PST, Helder Correia
no flags Details | Formatted Diff | Diff
Ceil layer size and round blit destination. (131.35 KB, patch)
2011-02-03 18:20 PST, Helder Correia
no flags Details | Formatted Diff | Diff
Performance test (3.24 KB, text/html)
2011-02-24 12:28 PST, Helder Correia
no flags Details
Remove formatting hunks (128.81 KB, patch)
2011-02-24 12:38 PST, Helder Correia
no flags Details | Formatted Diff | Diff
Otherwise the layer size will not be suficient to contain all pixels because of smoothing when we're scaling. (128.76 KB, patch)
2011-02-25 18:19 PST, Helder Correia
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Helder Correia 2011-01-15 01:41:40 PST
This happens in CG and is related to bug 51869, this time to be fixed in GraphicsContext::strokeRect(const FloatRect& r, float lineWidth). We need to draw the gradient clipped to the stroke on a CGLayer first, and then draw the layer on the GraphicsContext.
Comment 1 Helder Correia 2011-01-15 02:11:02 PST
Created attachment 79059 [details]
Patch
Comment 2 Simon Fraser (smfr) 2011-01-18 12:35:46 PST
Comment on attachment 79059 [details]
Patch

Why does this code do anything with m_state.fillGradient->gradientSpaceTransform() ?
Comment 3 Helder Correia 2011-01-23 20:46:41 PST
Created attachment 79887 [details]
Concat CTM with strokeGradient->gradientSpaceTransform()
Comment 4 Helder Correia 2011-02-02 15:25:38 PST
Created attachment 80979 [details]
Added svg/css/text-gradient-stroke-shadow.svg
Comment 5 Build Bot 2011-02-02 15:53:57 PST
Attachment 80979 [details] did not build on win:
Build output: http://queues.webkit.org/results/7690217
Comment 6 Simon Fraser (smfr) 2011-02-02 16:11:08 PST
Comment on attachment 80979 [details]
Added svg/css/text-gradient-stroke-shadow.svg

View in context: https://bugs.webkit.org/attachment.cgi?id=80979&action=review

> LayoutTests/svg/css/text-gradient-stroke-shadow.svg:8
> +<text x="100" y="300" style="font-size: 300px; text-shadow: #000 20px 20px 20px;" stroke-width="10" stroke="url(#gradient)">SVG</text>

Maybe just use a rect in these tests to avoid font differences between platforms.

Why does Mac render hollow characters, but the other platforms render solid black ones?

> Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:972
> +            const float halfLineWidth = lineWidth / 2;

Can you add a comment explaining the lineWidth/2 offset? Why do it here, and not in the non-shadow path?

> Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:1000
>  
> +

New blank line here.
Comment 7 Helder Correia 2011-02-03 15:13:24 PST
Created attachment 81121 [details]
New rect-gradient-stroke-shadow.svg. Add comment for line width. Fix build.
Comment 8 Simon Fraser (smfr) 2011-02-03 16:27:44 PST
Comment on attachment 81121 [details]
New rect-gradient-stroke-shadow.svg. Add comment for line width. Fix build.

View in context: https://bugs.webkit.org/attachment.cgi?id=81121&action=review

> Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:988
> +            // Compensate for half of the line width, otherwise the layer's top-left corner would
> +            // be aligned with the rect's top-left corner, not considering the line width. This
> +            // would result in leaving half of the line out of the layer on the left and top sides.
> +            const float translationX = halfLineWidth - rect.x();
> +            const float translationY = halfLineWidth - rect.y();
> +            CGContextTranslateCTM(layerContext, translationX, translationY);
> +
> +            CGContextAddRect(layerContext, rect);
> +            CGContextReplacePathWithStrokedPath(layerContext);
> +            CGContextClip(layerContext);
> +            CGContextConcatCTM(layerContext, m_state.strokeGradient->gradientSpaceTransform());
> +            m_state.strokeGradient->paint(layerContext);
> +
> +            const float destinationX = rect.x() - halfLineWidth;
> +            const float destinationY = rect.y() - halfLineWidth;
> +            CGContextDrawLayerAtPoint(context, CGPointMake(destinationX, destinationY), layer);

I think you want to avoid drawing the layer at half-pixel offsets. Why not just round out the layer size to a whole pixel?
Comment 9 Helder Correia 2011-02-03 18:20:10 PST
Created attachment 81165 [details]
Ceil layer size and round blit destination.
Comment 10 Tor Arne Vestbø 2011-02-18 19:37:11 PST
Comment on attachment 81165 [details]
Ceil layer size and round blit destination.

View in context: https://bugs.webkit.org/attachment.cgi?id=81165&action=review

> Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:193
> -    
> +

Please leave out these formatting hunks
Comment 11 Helder Correia 2011-02-24 12:28:12 PST
Created attachment 83698 [details]
Performance test
Comment 12 Helder Correia 2011-02-24 12:38:20 PST
Created attachment 83703 [details]
Remove formatting hunks
Comment 13 Helder Correia 2011-02-25 18:19:19 PST
Created attachment 83912 [details]
Otherwise the layer size will not be suficient to contain all pixels because of smoothing when we're scaling.
Comment 14 Helder Correia 2011-03-07 17:51:00 PST
Manually committed r80515: http://trac.webkit.org/changeset/80515
Comment 15 Stephen Chenney 2012-04-12 13:04:55 PDT
Committed r114023: <http://trac.webkit.org/changeset/114023>