Changeset 52206 in webkit


Ignore:
Timestamp:
Dec 16, 2009 11:00:25 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-16 Benjamin Otte <otte@gnome.org>

Reviewed by Darin Adler.

Get rid of the phase argument to Image::drawPattern.
https://bugs.webkit.org/show_bug.cgi?id=31187

The argument can be expressed equally well as part of the
patternTransform. All backends but the Qt one did exactly that
manually anyway.

  • platform/graphics/BitmapImage.h:
  • platform/graphics/GeneratedImage.cpp: (WebCore::GeneratedImage::drawPattern):
  • platform/graphics/GeneratedImage.h:
  • platform/graphics/Image.cpp: (WebCore::Image::drawTiled):
  • platform/graphics/Image.h:
  • platform/graphics/cairo/ImageCairo.cpp: (WebCore::Image::drawPattern):
  • platform/graphics/cg/ImageCG.cpp: (WebCore::Image::drawPattern):
  • platform/graphics/haiku/ImageHaiku.cpp: (WebCore::Image::drawPattern):
  • platform/graphics/qt/ImageQt.cpp: (WebCore::Image::drawPattern):
  • platform/graphics/skia/ImageSkia.cpp: (WebCore::Image::drawPattern):
  • platform/graphics/wince/GraphicsContextWince.cpp: (WebCore::GraphicsContext::drawBitmapPattern):
  • platform/graphics/wince/ImageBufferWince.cpp: (WebCore::): (WebCore::BufferedImage::drawPattern):
  • platform/graphics/wx/ImageWx.cpp: (WebCore::BitmapImage::drawPattern): (WebCore::Image::drawPattern):
Location:
trunk/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r52205 r52206  
     12009-12-16  Benjamin Otte  <otte@gnome.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Get rid of the phase argument to Image::drawPattern.
     6        https://bugs.webkit.org/show_bug.cgi?id=31187
     7
     8        The argument can be expressed equally well as part of the
     9        patternTransform. All backends but the Qt one did exactly that
     10        manually anyway.
     11
     12        * platform/graphics/BitmapImage.h:
     13        * platform/graphics/GeneratedImage.cpp:
     14        (WebCore::GeneratedImage::drawPattern):
     15        * platform/graphics/GeneratedImage.h:
     16        * platform/graphics/Image.cpp:
     17        (WebCore::Image::drawTiled):
     18        * platform/graphics/Image.h:
     19        * platform/graphics/cairo/ImageCairo.cpp:
     20        (WebCore::Image::drawPattern):
     21        * platform/graphics/cg/ImageCG.cpp:
     22        (WebCore::Image::drawPattern):
     23        * platform/graphics/haiku/ImageHaiku.cpp:
     24        (WebCore::Image::drawPattern):
     25        * platform/graphics/qt/ImageQt.cpp:
     26        (WebCore::Image::drawPattern):
     27        * platform/graphics/skia/ImageSkia.cpp:
     28        (WebCore::Image::drawPattern):
     29        * platform/graphics/wince/GraphicsContextWince.cpp:
     30        (WebCore::GraphicsContext::drawBitmapPattern):
     31        * platform/graphics/wince/ImageBufferWince.cpp:
     32        (WebCore::):
     33        (WebCore::BufferedImage::drawPattern):
     34        * platform/graphics/wx/ImageWx.cpp:
     35        (WebCore::BitmapImage::drawPattern):
     36        (WebCore::Image::drawPattern):
     37
    1382009-12-16  Kenneth Russell  <kbr@google.com>
    239
  • trunk/WebCore/platform/graphics/BitmapImage.h

    r51212 r52206  
    172172#if PLATFORM(WX) || (PLATFORM(WINCE) && !PLATFORM(QT))
    173173    virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
    174                              const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
     174                             ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
    175175#endif
    176176
  • trunk/WebCore/platform/graphics/GeneratedImage.cpp

    r51212 r52206  
    4949
    5050void GeneratedImage::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
    51                                  const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect)
     51                                 ColorSpace styleColorSpace, CompositeOperator compositeOp, const FloatRect& destRect)
    5252{
    5353    // Create a BitmapImage and call drawPattern on it.
     
    6363   
    6464    // Now just call drawTiled on that image.
    65     bitmap->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, compositeOp, destRect);
     65    bitmap->drawPattern(context, srcRect, patternTransform, styleColorSpace, compositeOp, destRect);
    6666}
    6767
  • trunk/WebCore/platform/graphics/GeneratedImage.h

    r51212 r52206  
    6060    virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator);
    6161    virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
    62                              const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
     62                             ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
    6363   
    6464    GeneratedImage(PassRefPtr<Generator> generator, const IntSize& size)
  • trunk/WebCore/platform/graphics/Image.cpp

    r51212 r52206  
    137137    }
    138138
    139     TransformationMatrix patternTransform = TransformationMatrix().scaleNonUniform(scale.width(), scale.height());
     139    TransformationMatrix patternTransform = TransformationMatrix();
     140    patternTransform.translate(oneTileRect.x(), oneTileRect.y());
     141    patternTransform.scaleNonUniform(scale.width(), scale.height());
     142
    140143    FloatRect tileRect(FloatPoint(), intrinsicTileSize);   
    141     drawPattern(ctxt, tileRect, patternTransform, oneTileRect.location(), styleColorSpace, op, destRect);
     144    drawPattern(ctxt, tileRect, patternTransform, styleColorSpace, op, destRect);
    142145   
    143146    startAnimation();
     
    159162
    160163    FloatSize scale = calculatePatternScale(dstRect, srcRect, hRule, vRule);
    161     TransformationMatrix patternTransform = TransformationMatrix().scaleNonUniform(scale.width(), scale.height());
    162164
    163165    // We want to construct the phase such that the pattern is centered (when stretch is not
     
    169171    if (vRule == Image::RepeatTile)
    170172        vPhase -= fmodf(dstRect.height(), scale.height() * srcRect.height()) / 2.0f;
    171     FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase);
     173    TransformationMatrix patternTransform = TransformationMatrix();
     174    patternTransform.translate(dstRect.x() - hPhase, dstRect.y() - vPhase);
     175    patternTransform.scaleNonUniform(scale.width(), scale.height());
    172176   
    173     drawPattern(ctxt, srcRect, patternTransform, patternPhase, styleColorSpace, op, dstRect);
     177    drawPattern(ctxt, srcRect, patternTransform, styleColorSpace, op, dstRect);
    174178
    175179    startAnimation();
  • trunk/WebCore/platform/graphics/Image.h

    r51212 r52206  
    171171   
    172172    virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
    173                              const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
     173                             ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
    174174
    175175private:
  • trunk/WebCore/platform/graphics/cairo/ImageCairo.cpp

    r51212 r52206  
    172172
    173173void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const TransformationMatrix& patternTransform,
    174                         const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
     174                        ColorSpace, CompositeOperator op, const FloatRect& destRect)
    175175{
    176176    cairo_surface_t* image = nativeImageForCurrentFrame();
    177177    if (!image) // If it's too early we won't have an image yet.
    178178        return;
    179 
    180     // Avoid NaN
    181     if (!isfinite(phase.x()) || !isfinite(phase.y()))
    182        return;
    183179
    184180    cairo_t* cr = context->platformContext();
     
    201197    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
    202198
    203     cairo_matrix_t pattern_matrix = cairo_matrix_t(patternTransform);
    204     cairo_matrix_t phase_matrix = {1, 0, 0, 1, phase.x() + tileRect.x() * patternTransform.a(), phase.y() + tileRect.y() * patternTransform.d()};
    205     cairo_matrix_t combined;
    206     cairo_matrix_multiply(&combined, &pattern_matrix, &phase_matrix);
    207     cairo_matrix_invert(&combined);
    208     cairo_pattern_set_matrix(pattern, &combined);
     199    cairo_matrix_t patternMatrix = cairo_matrix_t(patternTransform);
     200    cairo_matrix_t phaseMatrix = {1, 0, 0, 1, tileRect.x() * patternTransform.a(), tileRect.y() * patternTransform.d()};
     201    cairo_matrix_t combinedMatrix;
     202    cairo_matrix_multiply(&combinedMatrix, &patternMatrix, &phaseMatrix);
     203    cairo_matrix_invert(&combinedMatrix);
     204    cairo_pattern_set_matrix(pattern, &combinedMatrix);
     205    if (cairo_pattern_status(pattern)) {
     206        cairo_pattern_destroy(pattern);
     207        return;
     208    }
    209209
    210210    context->setCompositeOperation(op);
  • trunk/WebCore/platform/graphics/cg/ImageCG.cpp

    r51313 r52206  
    246246
    247247void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform,
    248                         const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
     248                        ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect)
    249249{
    250250    if (!nativeImageForCurrentFrame())
     
    268268    // We have to adjust the phase to deal with the fact we're in Cartesian space now (with the bottom left corner of destRect being
    269269    // the origin).
    270     float adjustedX = phase.x() - destRect.x() + tileRect.x() * narrowPrecisionToFloat(patternTransform.a()); // We translated the context so that destRect.x() is the origin, so subtract it out.
    271     float adjustedY = destRect.height() - (phase.y() - destRect.y() + tileRect.y() * narrowPrecisionToFloat(patternTransform.d()) + scaledTileHeight);
     270    float adjustedX = - destRect.x() + tileRect.x() * narrowPrecisionToFloat(patternTransform.a()); // We translated the context so that destRect.x() is the origin, so subtract it out.
     271    float adjustedY = destRect.height() + destRect.y() - tileRect.y() * narrowPrecisionToFloat(patternTransform.d()) - scaledTileHeight;
    272272
    273273    CGImageRef tileImage = nativeImageForCurrentFrame();
  • trunk/WebCore/platform/graphics/haiku/ImageHaiku.cpp

    r51212 r52206  
    110110}
    111111
    112 void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const TransformationMatrix& patternTransform, const FloatPoint& srcPoint, ColorSpace, CompositeOperator op, const FloatRect& dstRect)
     112void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const TransformationMatrix& patternTransform, ColorSpace, CompositeOperator op, const FloatRect& dstRect)
    113113{
    114     // FIXME: finish this to support also phased position (srcPoint)
    115114    startAnimation();
    116115
  • trunk/WebCore/platform/graphics/qt/ImageQt.cpp

    r51212 r52206  
    9595
    9696void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform,
    97                         const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
     97                        ColorSpace, CompositeOperator op, const FloatRect& destRect)
    9898{
    9999    QPixmap* framePixmap = nativeImageForCurrentFrame();
     
    113113    if (!pixmap.hasAlpha() && p->compositionMode() == QPainter::CompositionMode_SourceOver)
    114114        p->setCompositionMode(QPainter::CompositionMode_Source);
    115     p->setBrushOrigin(phase);
    116115    p->fillRect(destRect, b);
    117116    ctxt->restore();
  • trunk/WebCore/platform/graphics/skia/ImageSkia.cpp

    r51212 r52206  
    302302                        const FloatRect& floatSrcRect,
    303303                        const TransformationMatrix& patternTransform,
    304                         const FloatPoint& phase,
    305304                        ColorSpace styleColorSpace,
    306305                        CompositeOperator compositeOp,
     
    366365    // the coordinate system origin as the base for the patter. If WebKit wants
    367366    // a shifted image, it will shift it from there using the patternTransform.
    368     float adjustedX = phase.x() + normSrcRect.x() *
     367    float adjustedX = normSrcRect.x() *
    369368                      narrowPrecisionToFloat(patternTransform.a());
    370     float adjustedY = phase.y() + normSrcRect.y() *
     369    float adjustedY = normSrcRect.y() *
    371370                      narrowPrecisionToFloat(patternTransform.d());
    372371    matrix.postTranslate(SkFloatToScalar(adjustedX),
  • trunk/WebCore/platform/graphics/wince/GraphicsContextWince.cpp

    r51161 r52206  
    18721872
    18731873void GraphicsContext::drawBitmapPattern(SharedBitmap* bmp, const FloatRect& tileRectIn, const TransformationMatrix& patternTransform,
    1874                 const FloatPoint& phase, CompositeOperator op, const FloatRect& destRectIn, const IntSize& origSourceSize)
     1874                CompositeOperator op, const FloatRect& destRectIn, const IntSize& origSourceSize)
    18751875{
    18761876    if (!m_data->m_opacity)
     
    18931893    transform.translate(moved.width(), moved.height());
    18941894
    1895     bmp->drawPattern(dc, transform, tileRectIn, patternTransform, phase, op, destRectIn, origSourceSize);
     1895    bmp->drawPattern(dc, transform, tileRectIn, patternTransform, op, destRectIn, origSourceSize);
    18961896
    18971897    if (!bmp->hasAlpha())
  • trunk/WebCore/platform/graphics/wince/ImageBufferWince.cpp

    r47968 r52206  
    4444    virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
    4545    virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
    46                              const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
     46                             CompositeOperator, const FloatRect& destRect);
    4747
    4848    const ImageBufferData* m_data;
     
    5757
    5858void BufferedImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRectIn, const TransformationMatrix& patternTransform,
    59                              const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
    60 {
    61     m_data->m_bitmap->drawPattern(ctxt, tileRectIn, patternTransform, phase, op, destRect, size());
     59                             CompositeOperator op, const FloatRect& destRect)
     60{
     61    m_data->m_bitmap->drawPattern(ctxt, tileRectIn, patternTransform, op, destRect, size());
    6262}
    6363
  • trunk/WebCore/platform/graphics/wx/ImageWx.cpp

    r51419 r52206  
    177177}
    178178
    179 void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& srcRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, ColorSpace, CompositeOperator, const FloatRect& dstRect)
     179void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& srcRect, const TransformationMatrix& patternTransform, ColorSpace, CompositeOperator, const FloatRect& dstRect)
    180180{
    181181    if (!m_source.initialized())
     
    202202    wxGraphicsContext* gc = context->GetGraphicsContext();
    203203
    204     float adjustedX = phase.x() + srcRect.x() *
    205                       narrowPrecisionToFloat(patternTransform.a());
    206     float adjustedY = phase.y() + srcRect.y() *
    207                       narrowPrecisionToFloat(patternTransform.d());
     204    float adjustedX = srcRect.x() * narrowPrecisionToFloat(patternTransform.a());
     205    float adjustedY = srcRect.y() * narrowPrecisionToFloat(patternTransform.d());
    208206                     
    209207    gc->ConcatTransform(patternTransform);
     
    262260}
    263261
    264 void Image::drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, ColorSpace, CompositeOperator, const FloatRect& destRect)
     262void Image::drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform, ColorSpace, CompositeOperator, const FloatRect& destRect)
    265263{
    266264    notImplemented();
Note: See TracChangeset for help on using the changeset viewer.