Changeset 68145 in webkit


Ignore:
Timestamp:
Sep 23, 2010 8:51:41 AM (14 years ago)
Author:
Martin Robinson
Message:

2010-09-23 Martin Robinson <mrobinson@igalia.com>

Reviewed by Ariya Hidayat.

[Cairo] Generalize ContextShadow from the Qt port and use it for shadow code
https://bugs.webkit.org/show_bug.cgi?id=45599

Make ContextShadow platform-independent and add a Cairo implementation. This is currently
disabled for Cairo, but will be enabled in a followup patch with new baselines.

No new tests as this does not change functionality.

  • GNUmakefile.am: Update source lists.
  • WebCore.pro: Update source lists.
  • platform/graphics/ContextShadow.cpp: Added. A generalized version of Qt's ContextShadow. (WebCore::ContextShadow::ContextShadow): (WebCore::ContextShadow::clear): (WebCore::ContextShadow::blurLayerImage): (WebCore::ContextShadow::calculateMinimalLayerRect):
  • platform/graphics/ContextShadow.h: Added. (WebCore::ContextShadow::offset):
  • platform/graphics/cairo/CairoUtilities.cpp: Added. (WebCore::setSourceRGBAFromColor): A utility to set the source RGBA on a Cairo surface from a WebCore color.
  • platform/graphics/cairo/CairoUtilities.h: Added.
  • platform/graphics/cairo/ContextShadowCairo.cpp: Added. (WebCore::purgeScratchBuffer): Static function to purge the shadow buffer. (WebCore::PurgeScratchBufferTimer::fired): Timer callback. (WebCore::scheduleScratchBufferPurge): Schedule's a WebCore timer to purge the shadow buffer. (WebCore::getScratchBuffer): Create or reuse the scratch buffer. (WebCore::ContextShadow::beginShadowLayer): Added. (WebCore::ContextShadow::endShadowLayer): Added.
  • platform/graphics/gtk/CairoUtilities.cpp: Removed.
  • platform/graphics/gtk/CairoUtilities.h: Removed.
  • platform/graphics/gtk/GdkCairoUtilities.cpp: Renamed from CairoUtilities.cpp. (getCairoSurfacePixel): (getGdkPixbufPixel): (cairoImageSurfaceToGdkPixbuf):
  • platform/graphics/gtk/GdkCairoUtilities.h: Added.
  • platform/graphics/gtk/ImageBufferGtk.cpp:
  • platform/graphics/gtk/ImageGtk.cpp:
  • platform/graphics/qt/ContextShadow.cpp: Removed.
  • platform/graphics/qt/ContextShadow.h: Removed.
  • platform/graphics/qt/ContextShadowQt.cpp: Added. Adapted from code originally in ContextShadow.cpp. (WebCore::ShadowBuffer::ShadowBuffer): (WebCore::ShadowBuffer::scratchImage): (WebCore::ShadowBuffer::schedulePurge): (WebCore::ShadowBuffer::timerEvent): (WebCore::ContextShadow::beginShadowLayer): (WebCore::ContextShadow::endShadowLayer):
  • platform/graphics/qt/FontQt.cpp: (WebCore::drawTextCommon): Updated to reflect new ContextShadow members.
  • platform/graphics/qt/GraphicsContextQt.cpp: (WebCore::GraphicsContextPlatformPrivate::hasShadow): Updated to reflect new ContextShadow members. (WebCore::GraphicsContext::strokeArc): Ditto. (WebCore::GraphicsContext::drawConvexPolygon): Ditto. (WebCore::GraphicsContext::fillPath): Ditto. (WebCore::GraphicsContext::strokePath): Ditto. (WebCore::GraphicsContext::fillRect): Ditto. (WebCore::GraphicsContext::fillRoundedRect): Ditto. (WebCore::GraphicsContext::setPlatformShadow): Ditto.
Location:
trunk/WebCore
Files:
2 added
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r68144 r68145  
     12010-09-23  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Ariya Hidayat.
     4
     5        [Cairo] Generalize ContextShadow from the Qt port and use it for shadow code
     6        https://bugs.webkit.org/show_bug.cgi?id=45599
     7
     8        Make ContextShadow platform-independent and add a Cairo implementation. This is currently
     9        disabled for Cairo, but will be enabled in a followup patch with new baselines.
     10
     11        No new tests as this does not change functionality.
     12
     13        * GNUmakefile.am: Update source lists.
     14        * WebCore.pro: Update source lists.
     15        * platform/graphics/ContextShadow.cpp: Added. A generalized version of Qt's ContextShadow.
     16        (WebCore::ContextShadow::ContextShadow):
     17        (WebCore::ContextShadow::clear):
     18        (WebCore::ContextShadow::blurLayerImage):
     19        (WebCore::ContextShadow::calculateMinimalLayerRect):
     20        * platform/graphics/ContextShadow.h: Added.
     21        (WebCore::ContextShadow::offset):
     22        * platform/graphics/cairo/CairoUtilities.cpp: Added.
     23        (WebCore::setSourceRGBAFromColor): A utility to set the source RGBA on a Cairo surface from a WebCore color.
     24        * platform/graphics/cairo/CairoUtilities.h: Added.
     25        * platform/graphics/cairo/ContextShadowCairo.cpp: Added.
     26        (WebCore::purgeScratchBuffer): Static function to purge the shadow buffer.
     27        (WebCore::PurgeScratchBufferTimer::fired): Timer callback.
     28        (WebCore::scheduleScratchBufferPurge): Schedule's a WebCore timer to purge the shadow buffer.
     29        (WebCore::getScratchBuffer): Create or reuse the scratch buffer.
     30        (WebCore::ContextShadow::beginShadowLayer): Added.
     31        (WebCore::ContextShadow::endShadowLayer): Added.
     32        * platform/graphics/gtk/CairoUtilities.cpp: Removed.
     33        * platform/graphics/gtk/CairoUtilities.h: Removed.
     34        * platform/graphics/gtk/GdkCairoUtilities.cpp: Renamed from CairoUtilities.cpp.
     35        (getCairoSurfacePixel):
     36        (getGdkPixbufPixel):
     37        (cairoImageSurfaceToGdkPixbuf):
     38        * platform/graphics/gtk/GdkCairoUtilities.h: Added.
     39        * platform/graphics/gtk/ImageBufferGtk.cpp:
     40        * platform/graphics/gtk/ImageGtk.cpp:
     41        * platform/graphics/qt/ContextShadow.cpp: Removed.
     42        * platform/graphics/qt/ContextShadow.h: Removed.
     43        * platform/graphics/qt/ContextShadowQt.cpp: Added. Adapted from code originally in ContextShadow.cpp.
     44        (WebCore::ShadowBuffer::ShadowBuffer):
     45        (WebCore::ShadowBuffer::scratchImage):
     46        (WebCore::ShadowBuffer::schedulePurge):
     47        (WebCore::ShadowBuffer::timerEvent):
     48        (WebCore::ContextShadow::beginShadowLayer):
     49        (WebCore::ContextShadow::endShadowLayer):
     50        * platform/graphics/qt/FontQt.cpp:
     51        (WebCore::drawTextCommon): Updated to reflect new ContextShadow members.
     52        * platform/graphics/qt/GraphicsContextQt.cpp:
     53        (WebCore::GraphicsContextPlatformPrivate::hasShadow): Updated to reflect new ContextShadow members.
     54        (WebCore::GraphicsContext::strokeArc): Ditto.
     55        (WebCore::GraphicsContext::drawConvexPolygon): Ditto.
     56        (WebCore::GraphicsContext::fillPath): Ditto.
     57        (WebCore::GraphicsContext::strokePath): Ditto.
     58        (WebCore::GraphicsContext::fillRect): Ditto.
     59        (WebCore::GraphicsContext::fillRoundedRect): Ditto.
     60        (WebCore::GraphicsContext::setPlatformShadow): Ditto.
     61
    1622010-09-23  Patrick Gansterer  <paroga@webkit.org>
    263
  • trunk/WebCore/GNUmakefile.am

    r68022 r68145  
    20872087        WebCore/platform/graphics/Color.h \
    20882088        WebCore/platform/graphics/ColorSpace.h \
     2089        WebCore/platform/graphics/ContextShadow.cpp \
     2090        WebCore/platform/graphics/ContextShadow.h \
    20892091        WebCore/platform/graphics/DashArray.h \
    20902092        WebCore/platform/graphics/filters/DistantLightSource.h \
     
    33573359        WebCore/platform/graphics/cairo/CairoUtilities.cpp \
    33583360        WebCore/platform/graphics/cairo/CairoUtilities.h \
     3361        WebCore/platform/graphics/cairo/ContextShadowCairo.cpp \
    33593362        WebCore/platform/graphics/cairo/FontCairo.cpp \
    33603363        WebCore/platform/graphics/cairo/FontCustomPlatformData.h \
  • trunk/WebCore/WebCore.pro

    r68056 r68145  
    10961096    platform/graphics/BitmapImage.cpp \
    10971097    platform/graphics/Color.cpp \
     1098    platform/graphics/ContextShadow.cpp \
    10981099    platform/graphics/FloatPoint3D.cpp \
    10991100    platform/graphics/FloatPoint.cpp \
     
    19781979    platform/graphics/BitmapImage.h \
    19791980    platform/graphics/Color.h \
     1981    platform/graphics/ContextShadow.h \
    19801982    platform/graphics/filters/FEBlend.h \
    19811983    platform/graphics/filters/FEColorMatrix.h \
     
    20232025    platform/graphics/Pattern.h \
    20242026    platform/graphics/Pen.h \
    2025     platform/graphics/qt/ContextShadow.h \
    20262027    platform/graphics/qt/FontCustomPlatformData.h \
    20272028    platform/graphics/qt/GraphicsLayerQt.h \
     
    25372538    platform/graphics/qt/TransformationMatrixQt.cpp \
    25382539    platform/graphics/qt/ColorQt.cpp \
    2539     platform/graphics/qt/ContextShadow.cpp \
     2540    platform/graphics/qt/ContextShadowQt.cpp \
    25402541    platform/graphics/qt/FontQt.cpp \
    25412542    platform/graphics/qt/FontPlatformDataQt.cpp \
  • trunk/WebCore/platform/graphics/ContextShadow.cpp

    r68144 r68145  
    11/*
    22 * Copyright (C) 2010 Sencha, Inc.
     3 * Copyright (C) 2010 Igalia S.L.
    34 *
    45 * All rights reserved.
     
    2930#include "ContextShadow.h"
    3031
    31 #include <QTimerEvent>
     32#include <wtf/MathExtras.h>
    3233#include <wtf/Noncopyable.h>
     34
     35using WTF::min;
     36using WTF::max;
    3337
    3438namespace WebCore {
    3539
    36 // ContextShadow needs a scratch image as the buffer for the blur filter.
    37 // Instead of creating and destroying the buffer for every operation,
    38 // we create a buffer which will be automatically purged via a timer.
    39 
    40 class ShadowBuffer: public QObject {
    41 public:
    42     ShadowBuffer(QObject* parent = 0);
    43 
    44     QImage* scratchImage(const QSize& size);
    45 
    46     void schedulePurge();
    47 
    48 protected:
    49     void timerEvent(QTimerEvent* event);
    50 
    51 private:
    52     QImage image;
    53     int timerId;
    54 };
    55 
    56 ShadowBuffer::ShadowBuffer(QObject* parent)
    57     : QObject(parent)
    58     , timerId(0)
     40ContextShadow::ContextShadow()
     41    : m_type(NoShadow)
     42    , m_blurRadius(0)
    5943{
    6044}
    6145
    62 QImage* ShadowBuffer::scratchImage(const QSize& size)
     46ContextShadow::ContextShadow(const Color& color, float radius, const FloatSize& offset)
     47    : m_color(color)
     48    , m_blurRadius(round(radius))
     49    , m_offset(offset)
    6350{
    64     int width = size.width();
    65     int height = size.height();
     51    // See comments in http://webkit.org/b/40793, it seems sensible
     52    // to follow Skia's limit of 128 pixels of blur radius
     53    m_blurRadius = min(m_blurRadius, 128);
    6654
    67     // We do not need to recreate the buffer if the buffer is reasonably
    68     // larger than the requested size. However, if the requested size is
    69     // much smaller than our buffer, reduce our buffer so that we will not
    70     // keep too many allocated pixels for too long.
    71     if (!image.isNull() && (image.width() > width) && (image.height() > height))
    72         if (((2 * width) > image.width()) && ((2 * height) > image.height())) {
    73             image.fill(Qt::transparent);
    74             return &image;
    75         }
    76 
    77     // Round to the nearest 32 pixels so we do not grow the buffer everytime
    78     // there is larger request by 1 pixel.
    79     width = (1 + (width >> 5)) << 5;
    80     height = (1 + (height >> 5)) << 5;
    81 
    82     image = QImage(width, height, QImage::Format_ARGB32_Premultiplied);
    83     image.fill(Qt::transparent);
    84     return &image;
    85 }
    86 
    87 void ShadowBuffer::schedulePurge()
    88 {
    89     static const double BufferPurgeDelay = 2; // seconds
    90     killTimer(timerId);
    91     timerId = startTimer(BufferPurgeDelay * 1000);
    92 }
    93 
    94 void ShadowBuffer::timerEvent(QTimerEvent* event)
    95 {
    96     if (event->timerId() == timerId) {
    97         killTimer(timerId);
    98         image = QImage();
    99     }
    100     QObject::timerEvent(event);
    101 }
    102 
    103 Q_GLOBAL_STATIC(ShadowBuffer, scratchShadowBuffer)
    104 
    105 ContextShadow::ContextShadow()
    106     : type(NoShadow)
    107     , blurRadius(0)
    108 {
    109 }
    110 
    111 ContextShadow::ContextShadow(const QColor& c, float r, qreal dx, qreal dy)
    112     : color(c)
    113     , blurRadius(qRound(r))
    114     , offset(dx, dy)
    115 {
    11655    // The type of shadow is decided by the blur radius, shadow offset, and shadow color.
    117     if (!color.isValid() || !color.alpha()) {
     56    if (!m_color.isValid() || !color.alpha()) {
    11857        // Can't paint the shadow with invalid or invisible color.
    119         type = NoShadow;
    120     } else if (r > 0) {
     58        m_type = NoShadow;
     59    } else if (radius > 0) {
    12160        // Shadow is always blurred, even the offset is zero.
    122         type = BlurShadow;
    123     } else if (offset.isNull()) {
     61        m_type = BlurShadow;
     62    } else if (!m_offset.width() && !m_offset.height()) {
    12463        // Without blur and zero offset means the shadow is fully hidden.
    125         type = NoShadow;
     64        m_type = NoShadow;
    12665    } else {
    127         if (color.alpha() > 0)
    128             type = AlphaSolidShadow;
    129         else
    130             type = OpaqueSolidShadow;
     66        m_type = SolidShadow;
    13167    }
    13268}
     
    13470void ContextShadow::clear()
    13571{
    136     type = NoShadow;
    137     color = QColor();
    138     blurRadius = 0;
    139     offset = QPointF(0, 0);
     72    m_type = NoShadow;
     73    m_color = Color();
     74    m_blurRadius = 0;
     75    m_offset = FloatSize();
    14076}
    14177
     
    14783// approximates a real gaussian blur nicely.
    14884
    149 void shadowBlur(QImage& image, int radius, const QColor& shadowColor)
     85void ContextShadow::blurLayerImage(unsigned char* imageData, const IntSize& size, int rowStride)
    15086{
    151     // See comments in http://webkit.org/b/40793, it seems sensible
    152     // to follow Skia's limit of 128 pixels for the blur radius.
    153     if (radius > 128)
    154         radius = 128;
    155 
    15687    int channels[4] = { 3, 0, 1, 3 };
    157     int dmax = radius >> 1;
    158     int dmin = dmax - 1 + (radius & 1);
     88    int dmax = m_blurRadius >> 1;
     89    int dmin = dmax - 1 + (m_blurRadius & 1);
    15990    if (dmin < 0)
    16091        dmin = 0;
     
    16394    for (int k = 0; k < 2; ++k) {
    16495
    165         unsigned char* pixels = image.bits();
    166         int stride = (!k) ? 4 : image.bytesPerLine();
    167         int delta = (!k) ? image.bytesPerLine() : 4;
    168         int jfinal = (!k) ? image.height() : image.width();
    169         int dim = (!k) ? image.width() : image.height();
     96        unsigned char* pixels = imageData;
     97        int stride = (!k) ? 4 : rowStride;
     98        int delta = (!k) ? rowStride : 4;
     99        int jfinal = (!k) ? size.height() : size.width();
     100        int dim = (!k) ? size.width() : size.height();
    170101
    171102        for (int j = 0; j < jfinal; ++j, pixels += delta) {
     
    214145        }
    215146    }
    216 
    217     // "Colorize" with the right shadow color.
    218     QPainter p(&image);
    219     p.setCompositionMode(QPainter::CompositionMode_SourceIn);
    220     p.fillRect(image.rect(), shadowColor.rgb());
    221     p.end();
    222147}
    223148
    224 QPainter* ContextShadow::beginShadowLayer(QPainter* p, const QRectF &rect)
     149void ContextShadow::calculateLayerBoundingRect(const FloatRect& layerArea, const IntRect& clipRect)
    225150{
    226     // We expand the area by the blur radius * 2 to give extra space
    227     // for the blur transition.
    228     int extra = (type == BlurShadow) ? blurRadius * 2 : 0;
     151    // Calculate the destination of the blurred layer.
     152    FloatRect destinationRect(layerArea);
     153    destinationRect.move(m_offset);
     154    m_layerRect = enclosingIntRect(destinationRect);
    229155
    230     QRectF shadowRect = rect.translated(offset);
    231     QRectF bufferRect = shadowRect.adjusted(-extra, -extra, extra, extra);
    232     m_layerRect = bufferRect.toAlignedRect();
    233 
    234     QRect clipRect;
    235     if (p->hasClipping())
    236 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
    237         clipRect = p->clipBoundingRect().toAlignedRect();
    238 #else
    239         clipRect = p->clipRegion().boundingRect();
    240 #endif
    241     else
    242         clipRect = p->transform().inverted().mapRect(p->window());
     156    // We expand the area by the blur radius * 2 to give extra space for the blur transition.
     157    m_layerRect.inflate((m_type == BlurShadow) ? ceil(m_blurRadius * 2) : 0);
    243158
    244159    if (!clipRect.contains(m_layerRect)) {
     160        // No need to have the buffer larger than the clip.
     161        m_layerRect.intersect(clipRect);
    245162
    246         // No need to have the buffer larger than the clip.
    247         m_layerRect = m_layerRect.intersected(clipRect);
     163        // If we are totally outside the clip region, we aren't painting at all.
    248164        if (m_layerRect.isEmpty())
    249             return 0;
     165            return;
    250166
    251167        // We adjust again because the pixels at the borders are still
    252168        // potentially affected by the pixels outside the buffer.
    253         if (type == BlurShadow)
    254             m_layerRect.adjust(-extra, -extra, extra, extra);
     169        if (m_type == BlurShadow)
     170            m_layerRect.inflate((m_type == BlurShadow) ? ceil(m_blurRadius * 2) : 0);
    255171    }
    256 
    257     ShadowBuffer* shadowBuffer = scratchShadowBuffer();
    258     QImage* shadowImage = shadowBuffer->scratchImage(m_layerRect.size());
    259     m_layerImage = QImage(*shadowImage);
    260 
    261     m_layerPainter = new QPainter;
    262     m_layerPainter->begin(&m_layerImage);
    263     m_layerPainter->setFont(p->font());
    264     m_layerPainter->translate(offset);
    265 
    266     // The origin is now the top left corner of the scratch image.
    267     m_layerPainter->translate(-m_layerRect.topLeft());
    268 
    269     return m_layerPainter;
    270172}
    271173
    272 void ContextShadow::endShadowLayer(QPainter* p)
    273 {
    274     m_layerPainter->end();
    275     delete m_layerPainter;
    276     m_layerPainter = 0;
    277 
    278     if (type == BlurShadow)
    279         shadowBlur(m_layerImage, blurRadius, color);
    280 
    281     p->drawImage(m_layerRect.topLeft(), m_layerImage);
    282 
    283     scratchShadowBuffer()->schedulePurge();
    284 }
    285 
    286 }
     174} // namespace WebCore
  • trunk/WebCore/platform/graphics/ContextShadow.h

    r68144 r68145  
    11/*
    22 * Copyright (C) 2010 Sencha, Inc.
     3 * Copyright (C) 2010 Igalia S.L.
    34 *
    45 * All rights reserved.
     
    2930#define ContextShadow_h
    3031
    31 #include <QPainter>
     32#include "Color.h"
     33#include "FloatRect.h"
     34#include "IntRect.h"
     35#include "RefCounted.h"
     36
     37#if PLATFORM(CAIRO)
     38typedef struct _cairo cairo_t;
     39typedef struct _cairo_surface cairo_surface_t;
     40typedef cairo_surface_t* PlatformImage;
     41typedef cairo_t* PlatformContext;
     42#elif PLATFORM(QT)
     43#include <QImage>
     44class QPainter;
     45typedef QImage PlatformImage;
     46typedef QPainter* PlatformContext;
     47#endif
    3248
    3349namespace WebCore {
     
    4561    enum {
    4662        NoShadow,
    47         OpaqueSolidShadow,
    48         AlphaSolidShadow,
     63        SolidShadow,
    4964        BlurShadow
    50     } type;
     65    } m_type;
    5166
    52     QColor color;
    53     int blurRadius;
    54     QPointF offset;
     67    Color m_color;
     68    int m_blurRadius;
     69    FloatSize m_offset;
    5570
    5671    ContextShadow();
    57     ContextShadow(const QColor& c, float r, qreal dx, qreal dy);
     72    ContextShadow(const Color&, float radius, const FloatSize& offset);
    5873
    5974    void clear();
    6075
    6176    // The pair beginShadowLayer and endShadowLayer creates a temporary image
    62     // where the caller can draw onto, using the returned QPainter. This
    63     // QPainter instance must be used only to draw between the call to
    64     // beginShadowLayer and endShadowLayer.
     77    // where the caller can draw onto, using the returned context. This context
     78    // must be used only to draw between the call to beginShadowLayer and
     79    // endShadowLayer.
    6580    //
    66     // Note: multiple/nested shadow layer is NOT allowed.
     81    // Note: multiple/nested shadow layers are NOT allowed.
    6782    //
    6883    // The current clip region will be used to optimize the size of the
    69     // temporary image. Thus, the original painter should not change any
    70     // clipping until endShadowLayer.
    71     // If the shadow will be completely outside the clipping region,
    72     // beginShadowLayer will return 0.
     84    // temporary image. Thus, the original context should not change any
     85    // clipping until endShadowLayer. If the shadow will be completely outside
     86    // the clipping region, beginShadowLayer will return 0.
    7387    //
    74     // The returned QPainter will have the transformation matrix and clipping
    75     // properly initialized to start doing the painting (no need to account
    76     // for the shadow offset), however it will not have the same render hints,
    77     // pen, brush, etc as the passed QPainter. This is intentional, usually
    78     // shadow has different properties than the shape which casts the shadow.
     88    // The returned context will have the transformation matrix and clipping
     89    // properly initialized to start doing the painting (no need to account for
     90    // the shadow offset), however it will not have the same render hints, pen,
     91    // brush, etc as the passed context. This is intentional, usually shadows
     92    // have different properties than the shapes which cast them.
    7993    //
    80     // Once endShadowLayer is called, the temporary image will be drawn
    81     // with the original painter. If blur radius is specified, the shadow
    82     // will be filtered first.
    83     QPainter* beginShadowLayer(QPainter* p, const QRectF& rect);
    84     void endShadowLayer(QPainter* p);
     94    // Once endShadowLayer is called, the temporary image will be drawn with the
     95    // original context. If blur radius is specified, the shadow will be
     96    // filtered first.
     97
     98    PlatformContext beginShadowLayer(PlatformContext, const FloatRect& layerArea);
     99    void endShadowLayer(PlatformContext);
     100    static void purgeScratchBuffer();
     101
     102#if PLATFORM(QT)
     103    QPointF offset() { return QPointF(m_offset.width(), m_offset.height()); }
     104#endif
     105
    85106
    86107private:
    87     QRect m_layerRect;
    88     QImage m_layerImage;
    89     QPainter* m_layerPainter;
     108    IntRect m_layerRect;
     109    PlatformImage m_layerImage;
     110    PlatformContext m_layerContext;
     111
     112    void blurLayerImage(unsigned char*, const IntSize& imageSize, int stride);
     113    void calculateLayerBoundingRect(const FloatRect& layerArea, const IntRect& clipRect);
    90114};
    91115
  • trunk/WebCore/platform/graphics/cairo/CairoUtilities.cpp

    r67981 r68145  
    2727#include "CairoUtilities.h"
    2828
     29#include "Color.h"
    2930#include <cairo.h>
    3031#include <wtf/Vector.h>
     
    4950}
    5051
     52void setSourceRGBAFromColor(cairo_t* context, const Color& color)
     53{
     54    float red, green, blue, alpha;
     55    color.getRGBA(red, green, blue, alpha);
     56    cairo_set_source_rgba(context, red, green, blue, alpha);
     57}
     58
    5159} // namespace WebCore
    52 
  • trunk/WebCore/platform/graphics/cairo/CairoUtilities.h

    r67981 r68145  
    3030
    3131namespace WebCore {
     32class Color;
    3233
    3334void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr);
     35void setSourceRGBAFromColor(cairo_t*, const Color&);
     36
    3437} // namespace WebCore
    3538
  • trunk/WebCore/platform/graphics/qt/FontQt.cpp

    r65876 r68145  
    126126            ContextShadow* ctxShadow = ctx->contextShadow();
    127127
    128             if (ctxShadow->type != ContextShadow::NoShadow) {
     128            if (ctxShadow->m_type != ContextShadow::NoShadow) {
    129129                qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
    130                 if (ctxShadow->offset.x() > 0)
    131                     dx2 = ctxShadow->offset.x();
     130                if (ctxShadow->offset().x() > 0)
     131                    dx2 = ctxShadow->offset().x();
    132132                else
    133                     dx1 = -ctxShadow->offset.x();
    134                 if (ctxShadow->offset.y() > 0)
    135                     dy2 = ctxShadow->offset.y();
     133                    dx1 = -ctxShadow->offset().x();
     134                if (ctxShadow->offset().y() > 0)
     135                    dy2 = ctxShadow->offset().y();
    136136                else
    137                     dy1 = -ctxShadow->offset.y();
     137                    dy1 = -ctxShadow->offset().y();
    138138                // expand the clip rect to include the text shadow as well
    139139                clip.adjust(dx1, dx2, dy1, dy2);
    140                 clip.adjust(-ctxShadow->blurRadius, -ctxShadow->blurRadius, ctxShadow->blurRadius, ctxShadow->blurRadius);
     140                clip.adjust(-ctxShadow->m_blurRadius, -ctxShadow->m_blurRadius, ctxShadow->m_blurRadius, ctxShadow->m_blurRadius);
    141141            }
    142142            p->save();
     
    144144            pt.setY(pt.y() - ascent);
    145145
    146             if (ctxShadow->type != ContextShadow::NoShadow) {
     146            if (ctxShadow->m_type != ContextShadow::NoShadow) {
    147147                ContextShadow* ctxShadow = ctx->contextShadow();
    148                 if (ctxShadow->type != ContextShadow::BlurShadow) {
     148                if (ctxShadow->m_type != ContextShadow::BlurShadow) {
    149149                    p->save();
    150                     p->setPen(ctxShadow->color);
    151                     p->translate(ctxShadow->offset);
     150                    p->setPen(ctxShadow->m_color);
     151                    p->translate(ctxShadow->offset());
    152152                    line.draw(p, pt);
    153153                    p->restore();
     
    156156                    if (shadowPainter) {
    157157                        // Since it will be blurred anyway, we don't care about render hints.
    158                         shadowPainter->setPen(ctxShadow->color);
     158                        shadowPainter->setFont(p->font());
     159                        shadowPainter->setPen(ctxShadow->m_color);
    159160                        line.draw(shadowPainter, pt);
    160161                        ctxShadow->endShadowLayer(p);
     
    182183        flags |= Qt::TextBypassShaping;
    183184#endif
    184     if (ctx->contextShadow()->type != ContextShadow::NoShadow) {
     185    if (ctx->contextShadow()->m_type != ContextShadow::NoShadow) {
    185186        ContextShadow* ctxShadow = ctx->contextShadow();
    186         if (ctxShadow->type != ContextShadow::BlurShadow) {
     187        if (ctxShadow->m_type != ContextShadow::BlurShadow) {
    187188            p->save();
    188             p->setPen(ctxShadow->color);
    189             p->translate(ctxShadow->offset);
     189            p->setPen(ctxShadow->m_color);
     190            p->translate(ctxShadow->offset());
    190191            p->drawText(pt, string, flags, run.padding());
    191192            p->restore();
     
    197198                // Since it will be blurred anyway, we don't care about render hints.
    198199                shadowPainter->setFont(p->font());
    199                 shadowPainter->setPen(ctxShadow->color);
     200                shadowPainter->setPen(ctxShadow->m_color);
    200201                shadowPainter->drawText(pt, string, flags, run.padding());
    201202                ctxShadow->endShadowLayer(p);
  • trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r67819 r68145  
    202202    bool hasShadow() const
    203203    {
    204         return shadow.type != ContextShadow::NoShadow;
     204        return shadow.m_type != ContextShadow::NoShadow;
    205205    }
    206206
     
    441441    if (m_data->hasShadow()) {
    442442        p->save();
    443         p->translate(m_data->shadow.offset);
     443        p->translate(m_data->shadow.offset());
    444444        QPen pen(p->pen());
    445         pen.setColor(m_data->shadow.color);
     445        pen.setColor(m_data->shadow.m_color);
    446446        p->setPen(pen);
    447447        p->drawArc(rect, startAngle, angleSpan);
     
    471471    if (m_data->hasShadow()) {
    472472        p->save();
    473         p->translate(m_data->shadow.offset);
     473        p->translate(m_data->shadow.offset());
    474474        if (p->brush().style() != Qt::NoBrush)
    475             p->setBrush(QBrush(m_data->shadow.color));
     475            p->setBrush(QBrush(m_data->shadow.m_color));
    476476        QPen pen(p->pen());
    477477        if (pen.style() != Qt::NoPen) {
    478             pen.setColor(m_data->shadow.color);
     478            pen.setColor(m_data->shadow.m_color);
    479479            p->setPen(pen);
    480480        }
     
    520520
    521521    if (m_data->hasShadow()) {
    522         p->translate(m_data->shadow.offset);
    523         p->fillPath(path, m_data->shadow.color);
    524         p->translate(-m_data->shadow.offset);
     522        p->translate(m_data->shadow.offset());
     523        p->fillPath(path, QColor(m_data->shadow.m_color));
     524        p->translate(-m_data->shadow.offset());
    525525    }
    526526    if (m_common->state.fillPattern) {
     
    548548
    549549    if (m_data->hasShadow()) {
    550         p->translate(m_data->shadow.offset);
     550        p->translate(m_data->shadow.offset());
    551551        QPen shadowPen(pen);
    552         shadowPen.setColor(m_data->shadow.color);
     552        shadowPen.setColor(m_data->shadow.m_color);
    553553        p->strokePath(path, shadowPen);
    554         p->translate(-m_data->shadow.offset);
     554        p->translate(-m_data->shadow.offset());
    555555    }
    556556    if (m_common->state.strokePattern) {
     
    654654            drawRepeatPattern(shadowPainter, image, normalizedRect, m_common->state.fillPattern->repeatX(), m_common->state.fillPattern->repeatY());
    655655            shadowPainter->setCompositionMode(QPainter::CompositionMode_SourceIn);
    656             shadowPainter->fillRect(normalizedRect, shadow->color);
     656            shadowPainter->fillRect(normalizedRect, shadow->m_color);
    657657            shadow->endShadowLayer(p);
    658658        }
     
    665665            shadowPainter->fillRect(normalizedRect, brush);
    666666            shadowPainter->setCompositionMode(QPainter::CompositionMode_SourceIn);
    667             shadowPainter->fillRect(normalizedRect, shadow->color);
     667            shadowPainter->fillRect(normalizedRect, shadow->m_color);
    668668            shadow->endShadowLayer(p);
    669669        }
     
    671671    } else {
    672672        if (m_data->hasShadow()) {
    673             if (shadow->type == ContextShadow::BlurShadow) {
     673            if (shadow->m_type == ContextShadow::BlurShadow) {
    674674                QPainter* shadowPainter = shadow->beginShadowLayer(p, normalizedRect);
    675675                if (shadowPainter) {
     
    680680                // Solid rectangle fill with no blur shadow can be done faster
    681681                // without using the shadow layer at all.
    682                 QColor shadowColor = shadow->color;
     682                QColor shadowColor = shadow->m_color;
    683683                shadowColor.setAlphaF(shadowColor.alphaF() * p->brush().color().alphaF());
    684                 p->fillRect(normalizedRect.translated(shadow->offset), shadowColor);
     684                p->fillRect(normalizedRect.translated(shadow->offset()), shadowColor);
    685685            }
    686686        }
     
    702702        ContextShadow* shadow = contextShadow();
    703703
    704         if (shadow->type != ContextShadow::BlurShadow) {
     704        if (shadow->m_type != ContextShadow::BlurShadow) {
    705705            // We do not need any layer for simple shadow.
    706             p->fillRect(normalizedRect.translated(shadow->offset), shadow->color);
     706            p->fillRect(normalizedRect.translated(shadow->offset()), shadow->m_color);
    707707        } else {
    708708            QPainter* shadowPainter = shadow->beginShadowLayer(p, normalizedRect);
    709709            if (shadowPainter) {
    710710                shadowPainter->setCompositionMode(QPainter::CompositionMode_Source);
    711                 shadowPainter->fillRect(normalizedRect, shadow->color);
     711                shadowPainter->fillRect(normalizedRect, shadow->m_color);
    712712                shadow->endShadowLayer(p);
    713713            }
     
    726726    QPainter* p = m_data->p();
    727727    if (m_data->hasShadow()) {
    728         p->translate(m_data->shadow.offset);
    729         p->fillPath(path.platformPath(), m_data->shadow.color);
    730         p->translate(-m_data->shadow.offset);
     728        p->translate(m_data->shadow.offset());
     729        p->fillPath(path.platformPath(), QColor(m_data->shadow.m_color));
     730        p->translate(-m_data->shadow.offset());
    731731    }
    732732    p->fillPath(path.platformPath(), QColor(color));
     
    885885        // We flip the height since CG and HTML5 Canvas have opposite Y axis
    886886        m_common->state.shadowOffset = FloatSize(size.width(), -size.height());
    887         m_data->shadow = ContextShadow(color, blur, size.width(), -size.height());
     887        m_data->shadow = ContextShadow(color, blur, FloatSize(size.width(), -size.height()));
    888888    } else {
    889         m_data->shadow = ContextShadow(color, blur, size.width(), size.height());
     889        m_data->shadow = ContextShadow(color, blur, FloatSize(size.width(), size.height()));
    890890    }
    891891}
Note: See TracChangeset for help on using the changeset viewer.