Changeset 65331 in webkit


Ignore:
Timestamp:
Aug 13, 2010 10:24:45 AM (14 years ago)
Author:
ariya@webkit.org
Message:

2010-08-13 Ariya Hidayat <ariya@sencha.com>

Reviewed by Simon Hausmann.

[Qt] Canvas and CSS: blur option in shadow not working
https://bugs.webkit.org/show_bug.cgi?id=34479

Patch 1: Refactor shadow states handling.

  • platform/graphics/qt/GraphicsContextQt.cpp: (WebCore::GraphicsContextPlatformPrivate::): Added shadow states as member variables. (WebCore::GraphicsContextPlatformPrivate::hasShadow): Convenient function to check whether there is shadow or not. (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate): (WebCore::GraphicsContext::drawRect): Use shadow states instead of calling getShadow. (WebCore::GraphicsContext::drawLine): ditto. (WebCore::GraphicsContext::strokeArc): ditto. (WebCore::GraphicsContext::drawConvexPolygon): ditto. (WebCore::GraphicsContext::fillPath): ditto. (WebCore::GraphicsContext::strokePath): ditto. (WebCore::GraphicsContext::fillRect): Removes the use of helper function drawBorderlessRectShadow as the code already becomes a lot simpler. (WebCore::GraphicsContext::fillRoundedRect): Removes the use of helper function drawFilledShadowPath as the code already becomes a lot simpler. (WebCore::GraphicsContext::setPlatformShadow): Store shadow states and find out the shadow type (complexity) for future use. (WebCore::GraphicsContext::clearPlatformShadow): Reset shadow states.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65330 r65331  
     12010-08-13  Ariya Hidayat  <ariya@sencha.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        [Qt] Canvas and CSS: blur option in shadow not working
     6        https://bugs.webkit.org/show_bug.cgi?id=34479
     7
     8        Patch 1: Refactor shadow states handling.
     9
     10        * platform/graphics/qt/GraphicsContextQt.cpp:
     11        (WebCore::GraphicsContextPlatformPrivate::): Added shadow states as
     12        member variables.
     13        (WebCore::GraphicsContextPlatformPrivate::hasShadow): Convenient
     14        function to check whether there is shadow or not.
     15        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
     16        (WebCore::GraphicsContext::drawRect): Use shadow states instead of
     17        calling getShadow.
     18        (WebCore::GraphicsContext::drawLine): ditto.
     19        (WebCore::GraphicsContext::strokeArc): ditto.
     20        (WebCore::GraphicsContext::drawConvexPolygon): ditto.
     21        (WebCore::GraphicsContext::fillPath): ditto.
     22        (WebCore::GraphicsContext::strokePath): ditto.
     23        (WebCore::GraphicsContext::fillRect): Removes the use of helper function
     24        drawBorderlessRectShadow as the code already becomes a lot simpler.
     25        (WebCore::GraphicsContext::fillRoundedRect): Removes the use of helper
     26        function drawFilledShadowPath as the code already becomes a lot simpler.
     27        (WebCore::GraphicsContext::setPlatformShadow): Store shadow states
     28        and find out the shadow type (complexity) for future use.
     29        (WebCore::GraphicsContext::clearPlatformShadow): Reset shadow states.
     30
    1312010-08-11  Zhenyao Mo  <zmo@google.com>
    232
  • trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r65276 r65331  
    200200    QPainterPath currentPath;
    201201
     202    enum {
     203        NoShadow,
     204        OpaqueSolidShadow,
     205        AlphaSolidShadow,
     206        BlurShadow
     207    } shadowType;
     208    QColor shadowColor;
     209    int shadowBlurRadius;
     210    QPointF shadowOffset;
     211
     212    bool hasShadow() const
     213    {
     214        return shadowType != NoShadow;
     215    }
     216
    202217private:
    203218    QPainter* painter;
     
    223238    } else
    224239        antiAliasingForRectsAndLines = false;
     240
     241    shadowType = NoShadow;
     242    shadowBlurRadius = 0;
    225243}
    226244
     
    293311    p->setRenderHint(QPainter::Antialiasing, m_data->antiAliasingForRectsAndLines);
    294312
    295     if (m_common->state.shadowColor.isValid()) {
    296         FloatSize shadowSize;
    297         float shadowBlur;
    298         Color shadowColor;
    299         if (getShadow(shadowSize, shadowBlur, shadowColor)) {
    300             IntRect shadowRect = rect;
    301             shadowRect.move(shadowSize.width(), shadowSize.height());
    302             shadowRect.inflate(static_cast<int>(p->pen().widthF()));
    303             p->fillRect(shadowRect, QColor(shadowColor));
    304         }
     313    if (m_data->hasShadow()) {
     314        IntRect shadowRect = rect;
     315        shadowRect.move(m_data->shadowOffset.x(), m_data->shadowOffset.y());
     316        shadowRect.inflate(static_cast<int>(p->pen().widthF()));
     317        p->fillRect(shadowRect, m_data->shadowColor);
    305318    }
    306319
     
    332345    adjustLineToPixelBoundaries(p1, p2, width, style);
    333346
    334     FloatSize shadowSize;
    335     float shadowBlur;
    336     Color shadowColor;
    337     if (textDrawingMode() == cTextFill && getShadow(shadowSize, shadowBlur, shadowColor)) {
    338         p->save();
    339         p->translate(shadowSize.width(), shadowSize.height());
    340         p->setPen(shadowColor);
    341         p->drawLine(p1, p2);
    342         p->restore();
     347    if (m_data->hasShadow()) {
     348        if (textDrawingMode() == cTextFill) {
     349            p->save();
     350            p->translate(m_data->shadowOffset);
     351            p->setPen(m_data->shadowColor);
     352            p->drawLine(p1, p2);
     353            p->restore();
     354        }
    343355    }
    344356
     
    434446    p->setRenderHint(QPainter::Antialiasing, true);
    435447
    436     FloatSize shadowSize;
    437     float shadowBlur;
    438     Color shadowColor;
    439448    startAngle *= 16;
    440449    angleSpan *= 16;
    441     if (getShadow(shadowSize, shadowBlur, shadowColor)) {
     450
     451    if (m_data->hasShadow()) {
    442452        p->save();
    443         p->translate(shadowSize.width(), shadowSize.height());
     453        p->translate(m_data->shadowOffset);
    444454        QPen pen(p->pen());
    445         pen.setColor(shadowColor);
     455        pen.setColor(m_data->shadowColor);
    446456        p->setPen(pen);
    447457        p->drawArc(rect, startAngle, angleSpan);
     
    469479    p->save();
    470480    p->setRenderHint(QPainter::Antialiasing, shouldAntialias);
    471     FloatSize shadowSize;
    472     float shadowBlur;
    473     Color shadowColor;
    474     if (getShadow(shadowSize, shadowBlur, shadowColor)) {
     481    if (m_data->hasShadow()) {
    475482        p->save();
    476         p->translate(shadowSize.width(), shadowSize.height());
     483        p->translate(m_data->shadowOffset);
    477484        if (p->brush().style() != Qt::NoBrush)
    478             p->setBrush(QBrush(shadowColor));
     485            p->setBrush(QBrush(m_data->shadowColor));
    479486        QPen pen(p->pen());
    480487        if (pen.style() != Qt::NoPen) {
    481             pen.setColor(shadowColor);
     488            pen.setColor(m_data->shadowColor);
    482489            p->setPen(pen);
    483490        }
     
    513520}
    514521
    515 static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath& path)
    516 {
    517     FloatSize shadowSize;
    518     float shadowBlur;
    519     Color shadowColor;
    520     if (context->getShadow(shadowSize, shadowBlur, shadowColor)) {
    521         p->translate(shadowSize.width(), shadowSize.height());
    522         p->fillPath(path, QBrush(shadowColor));
    523         p->translate(-shadowSize.width(), -shadowSize.height());
    524     }
    525 }
    526 
    527522void GraphicsContext::fillPath()
    528523{
     
    534529    path.setFillRule(toQtFillRule(fillRule()));
    535530
    536     drawFilledShadowPath(this, p, path);
     531    if (m_data->hasShadow()) {
     532        p->translate(m_data->shadowOffset);
     533        p->fillPath(path, m_data->shadowColor);
     534        p->translate(-m_data->shadowOffset);
     535    }
    537536    if (m_common->state.fillPattern) {
    538537        AffineTransform affine;
     
    558557    path.setFillRule(toQtFillRule(fillRule()));
    559558
    560     FloatSize shadowSize;
    561     float shadowBlur;
    562     Color shadowColor;
    563     if (getShadow(shadowSize, shadowBlur, shadowColor)) {
    564         QTransform t(p->worldTransform());
    565         p->translate(shadowSize.width(), shadowSize.height());
     559    if (m_data->hasShadow()) {
     560        p->translate(m_data->shadowOffset);
    566561        QPen shadowPen(pen);
    567         shadowPen.setColor(shadowColor);
     562        shadowPen.setColor(m_data->shadowColor);
    568563        p->strokePath(path, shadowPen);
    569         p->setWorldTransform(t);
     564        p->translate(-m_data->shadowOffset);
    570565    }
    571566    if (m_common->state.strokePattern) {
     
    583578        p->strokePath(path, pen);
    584579    m_data->currentPath = QPainterPath();
    585 }
    586 
    587 static inline void drawBorderlessRectShadow(GraphicsContext* context, QPainter* p, const FloatRect& rect)
    588 {
    589     FloatSize shadowSize;
    590     float shadowBlur;
    591     Color shadowColor;
    592     if (context->getShadow(shadowSize, shadowBlur, shadowColor)) {
    593         FloatRect shadowRect(rect);
    594         shadowRect.move(shadowSize.width(), shadowSize.height());
    595         p->fillRect(shadowRect, QColor(shadowColor));
    596     }
    597580}
    598581
     
    672655    FloatRect normalizedRect = rect.normalized();
    673656
    674     FloatSize shadowSize;
    675     float shadowBlur;
    676     Color shadowColor;
    677     bool hasShadow = getShadow(shadowSize, shadowBlur, shadowColor);
    678     FloatRect shadowDestRect;
     657    QRectF shadowDestRect;
    679658    QImage* shadowImage = 0;
    680659    QPainter* pShadow = 0;
    681660
    682     if (hasShadow) {
     661    if (m_data->hasShadow()) {
    683662        shadowImage = new QImage(roundedIntSize(normalizedRect.size()), QImage::Format_ARGB32_Premultiplied);
    684663        pShadow = new QPainter(shadowImage);
    685664        shadowDestRect = normalizedRect;
    686         shadowDestRect.move(shadowSize.width(), shadowSize.height());
     665        shadowDestRect.translate(m_data->shadowOffset);
    687666
    688667        pShadow->setCompositionMode(QPainter::CompositionMode_Source);
    689         pShadow->fillRect(shadowImage->rect(), shadowColor);
     668        pShadow->fillRect(shadowDestRect, m_data->shadowColor);
    690669        pShadow->setCompositionMode(QPainter::CompositionMode_DestinationIn);
    691670    }
     
    697676        QPixmap* image = m_common->state.fillPattern->tileImage()->nativeImageForCurrentFrame();
    698677
    699         if (hasShadow) {
     678        if (m_data->hasShadow()) {
    700679            drawRepeatPattern(pShadow, image, FloatRect(static_cast<QRectF>(shadowImage->rect())), m_common->state.fillPattern->repeatX(), m_common->state.fillPattern->repeatY());
    701680            pShadow->end();
     
    707686        brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform());
    708687
    709         if (hasShadow) {
     688        if (m_data->hasShadow()) {
    710689            pShadow->fillRect(shadowImage->rect(), brush);
    711690            pShadow->end();
     
    714693        p->fillRect(normalizedRect, brush);
    715694    } else {
    716         if (hasShadow) {
     695        if (m_data->hasShadow()) {
    717696            pShadow->fillRect(shadowImage->rect(), p->brush());
    718697            pShadow->end();
     
    734713    m_data->solidColor.setColor(color);
    735714    QPainter* p = m_data->p();
    736     if (m_common->state.shadowColor.isValid())
    737         drawBorderlessRectShadow(this, p, rect);
     715
     716    if (m_data->hasShadow())
     717        p->fillRect(QRectF(rect).translated(m_data->shadowOffset), m_data->shadowColor);
     718
    738719    p->fillRect(rect, m_data->solidColor);
    739720}
     
    746727    Path path = Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight);
    747728    QPainter* p = m_data->p();
    748     drawFilledShadowPath(this, p, path.platformPath());
     729    if (m_data->hasShadow()) {
     730        p->translate(m_data->shadowOffset);
     731        p->fillPath(path.platformPath(), m_data->shadowColor);
     732        p->translate(-m_data->shadowOffset);
     733    }
    749734    p->fillPath(path.platformPath(), QColor(color));
    750735}
     
    888873}
    889874
    890 void GraphicsContext::setPlatformShadow(const FloatSize& size, float, const Color&, ColorSpace)
     875void GraphicsContext::setPlatformShadow(const FloatSize& size, float blur, const Color& color, ColorSpace)
    891876{
    892877    // Qt doesn't support shadows natively, they are drawn manually in the draw*
     
    898883        m_common->state.shadowSize = FloatSize(size.width(), -size.height());
    899884    }
     885
     886    // Here we just store important shadow states.
     887
     888    m_data->shadowBlurRadius = qRound(blur);
     889    m_data->shadowOffset = QPointF(m_common->state.shadowSize.width(), m_common->state.shadowSize.height());
     890    m_data->shadowColor = color;
     891
     892    // The type of shadow is decided by the blur radius, shadow offset, and shadow color.
     893
     894    if (!color.isValid() || !color.alpha()) {
     895        // Can't paint the shadow with invalid or invisible color.
     896        m_data->shadowType = GraphicsContextPlatformPrivate::NoShadow;
     897    } else {
     898        if (blur >= 1) {
     899            // Shadow is always blurred, even the offset is zero.
     900            m_data->shadowType = GraphicsContextPlatformPrivate::BlurShadow;
     901        } else {
     902            if (m_data->shadowOffset.isNull()) {
     903                // Without blur and zero offset means the shadow is fully hidden.
     904                m_data->shadowType = GraphicsContextPlatformPrivate::NoShadow;
     905            } else {
     906                if (color.hasAlpha())
     907                    m_data->shadowType = GraphicsContextPlatformPrivate::AlphaSolidShadow;
     908                else
     909                    m_data->shadowType = GraphicsContextPlatformPrivate::OpaqueSolidShadow;
     910            }
     911        }
     912    }
    900913}
    901914
    902915void GraphicsContext::clearPlatformShadow()
    903916{
    904     // Qt doesn't support shadows natively, they are drawn manually in the draw*
    905     // functions
     917    m_data->shadowType = GraphicsContextPlatformPrivate::NoShadow;
    906918}
    907919
Note: See TracChangeset for help on using the changeset viewer.