Changeset 75139 in webkit


Ignore:
Timestamp:
Jan 5, 2011 10:11:02 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-01-05 Helder Correia <helder@sencha.com>

Reviewed by Simon Fraser.

Shadows are not drawn when filling a rect with a gradient fillStyle on Mac and Chromium-Mac
https://bugs.webkit.org/show_bug.cgi?id=51869

GraphicsContext::fillRect(const FloatRect&) is clipping to the rect.
The shadow is being drawn, but getting clipped to the rect being filled.
The solution is to draw the gradient into a CGLayer (when a shadow is
required), then render the layer to the GraphicsContext.

This patch also fixes:
canvas/philip/tests/2d.shadow.gradient.alpha.html
canvas/philip/tests/2d.shadow.gradient.basic.html
canvas/philip/tests/2d.shadow.gradient.transparent.2.html

New test to ensure that shadows are drawn when fillStyle is a gradient,
possibly with some transparency and blur, and specifically using
fillRect.

  • fast/canvas/canvas-fillRect-gradient-shadow-expected.txt: Added.
  • fast/canvas/canvas-fillRect-gradient-shadow.html: Added.
  • fast/canvas/script-tests/canvas-fillRect-gradient-shadow.js: Added.

2011-01-05 Helder Correia <helder@sencha.com>

Reviewed by Simon Fraser.

Shadows are not drawn when filling a rect with a gradient fillStyle on Mac and Chromium-Mac
https://bugs.webkit.org/show_bug.cgi?id=51869

GraphicsContext::fillRect(const FloatRect&) is clipping to the rect.
The shadow is being drawn, but getting clipped to the rect being filled.
The solution is to draw the gradient into a CGLayer (when a shadow is
required), then render the layer to the GraphicsContext.

This patch also fixes:
canvas/philip/tests/2d.shadow.gradient.alpha.html
canvas/philip/tests/2d.shadow.gradient.basic.html
canvas/philip/tests/2d.shadow.gradient.transparent.2.html

Test: fast/canvas/canvas-fillRect-gradient-shadow.html

  • platform/graphics/Gradient.h:
  • platform/graphics/cg/GradientCG.cpp: (WebCore::Gradient::paint):
  • platform/graphics/cg/GraphicsContextCG.cpp: (WebCore::GraphicsContext::fillRect):
Location:
trunk
Files:
3 added
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r75137 r75139  
     12011-01-05  Helder Correia  <helder@sencha.com>
     2
     3        Reviewed by Simon Fraser.
     4
     5        Shadows are not drawn when filling a rect with a gradient fillStyle on Mac and Chromium-Mac
     6        https://bugs.webkit.org/show_bug.cgi?id=51869
     7
     8        GraphicsContext::fillRect(const FloatRect&) is clipping to the rect.
     9        The shadow is being drawn, but getting clipped to the rect being filled.
     10        The solution is to draw the gradient into a CGLayer (when a shadow is
     11        required), then render the layer to the GraphicsContext.
     12
     13        This patch also fixes:
     14        canvas/philip/tests/2d.shadow.gradient.alpha.html
     15        canvas/philip/tests/2d.shadow.gradient.basic.html
     16        canvas/philip/tests/2d.shadow.gradient.transparent.2.html
     17
     18        New test to ensure that shadows are drawn when fillStyle is a gradient,
     19        possibly with some transparency and blur, and specifically using
     20        fillRect.
     21
     22        * fast/canvas/canvas-fillRect-gradient-shadow-expected.txt: Added.
     23        * fast/canvas/canvas-fillRect-gradient-shadow.html: Added.
     24        * fast/canvas/script-tests/canvas-fillRect-gradient-shadow.js: Added.
     25
    1262011-01-05  Simon Fraser  <simon.fraser@apple.com>
    227
  • trunk/WebCore/ChangeLog

    r75138 r75139  
     12011-01-05  Helder Correia  <helder@sencha.com>
     2
     3        Reviewed by Simon Fraser.
     4
     5        Shadows are not drawn when filling a rect with a gradient fillStyle on Mac and Chromium-Mac
     6        https://bugs.webkit.org/show_bug.cgi?id=51869
     7
     8        GraphicsContext::fillRect(const FloatRect&) is clipping to the rect.
     9        The shadow is being drawn, but getting clipped to the rect being filled.
     10        The solution is to draw the gradient into a CGLayer (when a shadow is
     11        required), then render the layer to the GraphicsContext.
     12
     13        This patch also fixes:
     14        canvas/philip/tests/2d.shadow.gradient.alpha.html
     15        canvas/philip/tests/2d.shadow.gradient.basic.html
     16        canvas/philip/tests/2d.shadow.gradient.transparent.2.html
     17
     18        Test: fast/canvas/canvas-fillRect-gradient-shadow.html
     19
     20        * platform/graphics/Gradient.h:
     21        * platform/graphics/cg/GradientCG.cpp:
     22        (WebCore::Gradient::paint):
     23        * platform/graphics/cg/GraphicsContextCG.cpp:
     24        (WebCore::GraphicsContext::fillRect):
     25
    1262011-01-05  Steve Falkenburg  <sfalken@apple.com>
    227
  • trunk/WebCore/platform/graphics/Gradient.h

    r74915 r75139  
    3535#include <wtf/PassRefPtr.h>
    3636#include <wtf/Vector.h>
     37
     38#if PLATFORM(WIN)
     39#include <CoreGraphics/CoreGraphics.h>
     40#endif
    3741
    3842#if PLATFORM(CG)
     
    137141
    138142#if PLATFORM(CG)
     143        void paint(CGContextRef);
    139144        void paint(GraphicsContext*);
    140145#endif
  • trunk/WebCore/platform/graphics/GraphicsContext.cpp

    r74662 r75139  
    149149}
    150150
     151bool GraphicsContext::hasShadow() const
     152{
     153    return m_state.shadowColor.isValid() && m_state.shadowColor.alpha()
     154           && (m_state.shadowBlur || m_state.shadowOffset.width() || m_state.shadowOffset.height());
     155}
     156
    151157bool GraphicsContext::getShadow(FloatSize& offset, float& blur, Color& color, ColorSpace& colorSpace) const
    152158{
     
    156162    colorSpace = m_state.shadowColorSpace;
    157163
    158     return color.isValid() && color.alpha() && (blur || offset.width() || offset.height());
     164    return hasShadow();
    159165}
    160166
  • trunk/WebCore/platform/graphics/GraphicsContext.h

    r74662 r75139  
    347347        void endTransparencyLayer();
    348348
     349        bool hasShadow() const;
    349350        void setShadow(const FloatSize&, float blur, const Color&, ColorSpace);
    350351        bool getShadow(FloatSize&, float&, Color&, ColorSpace&) const;
  • trunk/WebCore/platform/graphics/cg/GradientCG.cpp

    r75097 r75139  
    113113{
    114114    CGContextRef ctx = context->platformContext();
     115    paint(ctx);
     116}
     117
     118void Gradient::paint(CGContextRef context)
     119{
    115120#if USE_CG_SHADING
    116     CGContextDrawShading(ctx, platformGradient());
     121    CGContextDrawShading(context, platformGradient());
    117122#else
    118123    CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
     
    120125        bool needScaling = aspectRatio() != 1;
    121126        if (needScaling) {
    122             CGContextSaveGState(ctx);
     127            CGContextSaveGState(context);
    123128            // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
    124129            // for which m_p0 == m_p1.
    125130            ASSERT(m_p0 == m_p1);
    126             CGContextTranslateCTM(ctx, m_p0.x(), m_p0.y());
    127             CGContextScaleCTM(ctx, 1, 1 / aspectRatio());
    128             CGContextTranslateCTM(ctx, -m_p0.x(), -m_p0.y());
     131            CGContextTranslateCTM(context, m_p0.x(), m_p0.y());
     132            CGContextScaleCTM(context, 1, 1 / aspectRatio());
     133            CGContextTranslateCTM(context, -m_p0.x(), -m_p0.y());
    129134        }
    130135
    131         CGContextDrawRadialGradient(ctx, platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);
    132        
     136        CGContextDrawRadialGradient(context, platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);
     137
    133138        if (needScaling)
    134             CGContextRestoreGState(ctx);
     139            CGContextRestoreGState(context);
    135140    } else
    136         CGContextDrawLinearGradient(ctx, platformGradient(), m_p0, m_p1, extendOptions);
     141        CGContextDrawLinearGradient(context, platformGradient(), m_p0, m_p1, extendOptions);
    137142#endif
    138143}
  • trunk/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r74151 r75139  
    602602    if (m_state.fillGradient) {
    603603        CGContextSaveGState(context);
    604         CGContextClipToRect(context, rect);
    605604        CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
    606         m_state.fillGradient->paint(this);
     605        if (hasShadow()) {
     606            CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(rect.width(), rect.height()), 0);
     607            CGContextRef layerContext = CGLayerGetContext(layer);
     608            m_state.fillGradient->paint(layerContext);
     609            CGContextDrawLayerAtPoint(context, CGPointMake(rect.left(), rect.top()), layer);
     610            CGLayerRelease(layer);
     611        } else {
     612            CGContextClipToRect(context, rect);
     613            m_state.fillGradient->paint(this);
     614        }
    607615        CGContextRestoreGState(context);
    608616        return;
Note: See TracChangeset for help on using the changeset viewer.