Changeset 191324 in webkit


Ignore:
Timestamp:
Oct 19, 2015 5:36:03 PM (9 years ago)
Author:
mmaxfield@apple.com
Message:

Host GraphicsContext's CTM inside GraphicsContextState
https://bugs.webkit.org/show_bug.cgi?id=150146

There are 6 operations which interact with CTMs:

  • Get
  • Set
  • Concatenate
  • Scale
  • Rotate
  • Translate

This patch modifies all these operations so that these operations shadow the
platform's CTM inside GraphicsContextState. This way, we don't have to consult
with the underlying graphics context in order to know the current CTM.

There are currently many places in the Core Graphics ports where we will change
the platform's CTM out from under the GraphicsContext. This patch migrates
those users to going through GraphicsContext, thereby preserving the integrity
of the shadowed state.

No new tests because there is no behavior change.

  • platform/graphics/GraphicsContext.cpp: Setters deletate to platform calls.

The getter can just consult with the shadowed state.
(WebCore::GraphicsContext::concatCTM):
(WebCore::GraphicsContext::scale):
(WebCore::GraphicsContext::rotate):
(WebCore::GraphicsContext::translate):
(WebCore::GraphicsContext::setCTM):
(WebCore::GraphicsContext::getCTM):
(WebCore::GraphicsContext::beginTransparencyLayer):
(WebCore::GraphicsContext::applyDeviceScaleFactor):

  • platform/graphics/GraphicsContext.h:

(WebCore::GraphicsContext::scale):
(WebCore::GraphicsContext::checkCTMInvariants): Make sure the shadowed state
matches the platform graphics context's state.

  • platform/graphics/Image.h:

(WebCore::Image::nativeImageForCurrentFrame):

  • platform/graphics/cairo/GraphicsContextCairo.cpp: Renaming functions.

(WebCore::GraphicsContext::resetPlatformCTM):
(WebCore::GraphicsContext::getPlatformCTM):
(WebCore::GraphicsContext::translatePlatformCTM):
(WebCore::GraphicsContext::concatPlatformCTM):
(WebCore::GraphicsContext::setPlatformCTM):
(WebCore::GraphicsContext::rotatePlatformCTM):
(WebCore::GraphicsContext::scalePlatformCTM):
(WebCore::GraphicsContext::getCTM): Deleted.
(WebCore::GraphicsContext::translate): Deleted.
(WebCore::GraphicsContext::concatCTM): Deleted.
(WebCore::GraphicsContext::setCTM): Deleted.
(WebCore::GraphicsContext::rotate): Deleted.
(WebCore::GraphicsContext::scale): Deleted.

  • platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:

Renaming functions.
(WebCore::GraphicsContextPlatformPrivate::save):
(WebCore::GraphicsContextPlatformPrivate::restore):
(WebCore::GraphicsContextPlatformPrivate::flush):
(WebCore::GraphicsContextPlatformPrivate::clip):
(WebCore::GraphicsContextPlatformPrivate::scalePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::rotatePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::translatePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::concatPlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::setPlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::scale): Deleted.
(WebCore::GraphicsContextPlatformPrivate::rotate): Deleted.
(WebCore::GraphicsContextPlatformPrivate::translate): Deleted.
(WebCore::GraphicsContextPlatformPrivate::concatCTM): Deleted.
(WebCore::GraphicsContextPlatformPrivate::setCTM): Deleted.

  • platform/graphics/cg/GraphicsContextCG.cpp: Renaming functions. Also,

migrate CTM setters to go through GraphicsContext.
(WebCore::GraphicsContext::resetPlatformCTM):
(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::drawNativeImage):
(WebCore::GraphicsContext::drawPattern):
(WebCore::GraphicsContext::fillPath):
(WebCore::GraphicsContext::scalePlatformCTM):
(WebCore::GraphicsContext::rotatePlatformCTM):
(WebCore::GraphicsContext::translatePlatformCTM):
(WebCore::GraphicsContext::concatPlatformCTM):
(WebCore::GraphicsContext::setPlatformCTM):
(WebCore::GraphicsContext::getPlatformCTM):
(WebCore::GraphicsContext::scale): Deleted.
(WebCore::GraphicsContext::rotate): Deleted.
(WebCore::GraphicsContext::translate): Deleted.
(WebCore::GraphicsContext::concatCTM): Deleted.
(WebCore::GraphicsContext::setCTM): Deleted.
(WebCore::GraphicsContext::getCTM): Deleted.

  • platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:

(WebCore::GraphicsContextPlatformPrivate::save):
(WebCore::GraphicsContextPlatformPrivate::restore):
(WebCore::GraphicsContextPlatformPrivate::flush):
(WebCore::GraphicsContextPlatformPrivate::clip):
(WebCore::GraphicsContextPlatformPrivate::scalePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::rotatePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::translatePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::concatPlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::setPlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::scale): Deleted.
(WebCore::GraphicsContextPlatformPrivate::rotate): Deleted.
(WebCore::GraphicsContextPlatformPrivate::translate): Deleted.
(WebCore::GraphicsContextPlatformPrivate::concatCTM): Deleted.
(WebCore::GraphicsContextPlatformPrivate::setCTM): Deleted.

  • platform/graphics/transforms/AffineTransform.h:

(WebCore::AffineTransform::isEssentiallyEqualTo): Equality comparison on floats
is not a good idea. Instead, this function is more valuable. (However, note that
it is expected for values in a CTM to hold values close to 0, which means that
this function might erroneously return false (similar to operator=()).

  • platform/graphics/win/GraphicsContextWin.cpp:

(WebCore::GraphicsContextPlatformPrivate::scalePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::rotatePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::translatePlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::concatPlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::setPlatformCTM):
(WebCore::GraphicsContextPlatformPrivate::scale): Deleted.
(WebCore::GraphicsContextPlatformPrivate::rotate): Deleted.
(WebCore::GraphicsContextPlatformPrivate::translate): Deleted.
(WebCore::GraphicsContextPlatformPrivate::concatCTM): Deleted.
(WebCore::GraphicsContextPlatformPrivate::setCTM): Deleted.

  • platform/mac/DragImageMac.mm:

(WebCore::drawAtPoint):

  • platform/spi/cg/CoreGraphicsSPI.h:
Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r191323 r191324  
     12015-10-19  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Host GraphicsContext's CTM inside GraphicsContextState
     4        https://bugs.webkit.org/show_bug.cgi?id=150146
     5
     6        There are 6 operations which interact with CTMs:
     7        - Get
     8        - Set
     9        - Concatenate
     10        - Scale
     11        - Rotate
     12        - Translate
     13
     14        This patch modifies all these operations so that these operations shadow the
     15        platform's CTM inside GraphicsContextState. This way, we don't have to consult
     16        with the underlying graphics context in order to know the current CTM.
     17
     18        There are currently many places in the Core Graphics ports where we will change
     19        the platform's CTM out from under the GraphicsContext. This patch migrates
     20        those users to going through GraphicsContext, thereby preserving the integrity
     21        of the shadowed state.
     22
     23        No new tests because there is no behavior change.
     24
     25        * platform/graphics/GraphicsContext.cpp: Setters deletate to platform calls.
     26        The getter can just consult with the shadowed state.
     27        (WebCore::GraphicsContext::concatCTM):
     28        (WebCore::GraphicsContext::scale):
     29        (WebCore::GraphicsContext::rotate):
     30        (WebCore::GraphicsContext::translate):
     31        (WebCore::GraphicsContext::setCTM):
     32        (WebCore::GraphicsContext::getCTM):
     33        (WebCore::GraphicsContext::beginTransparencyLayer):
     34        (WebCore::GraphicsContext::applyDeviceScaleFactor):
     35        * platform/graphics/GraphicsContext.h:
     36        (WebCore::GraphicsContext::scale):
     37        (WebCore::GraphicsContext::checkCTMInvariants): Make sure the shadowed state
     38        matches the platform graphics context's state.
     39        * platform/graphics/Image.h:
     40        (WebCore::Image::nativeImageForCurrentFrame):
     41        * platform/graphics/cairo/GraphicsContextCairo.cpp: Renaming functions.
     42        (WebCore::GraphicsContext::resetPlatformCTM):
     43        (WebCore::GraphicsContext::getPlatformCTM):
     44        (WebCore::GraphicsContext::translatePlatformCTM):
     45        (WebCore::GraphicsContext::concatPlatformCTM):
     46        (WebCore::GraphicsContext::setPlatformCTM):
     47        (WebCore::GraphicsContext::rotatePlatformCTM):
     48        (WebCore::GraphicsContext::scalePlatformCTM):
     49        (WebCore::GraphicsContext::getCTM): Deleted.
     50        (WebCore::GraphicsContext::translate): Deleted.
     51        (WebCore::GraphicsContext::concatCTM): Deleted.
     52        (WebCore::GraphicsContext::setCTM): Deleted.
     53        (WebCore::GraphicsContext::rotate): Deleted.
     54        (WebCore::GraphicsContext::scale): Deleted.
     55        * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
     56        Renaming functions.
     57        (WebCore::GraphicsContextPlatformPrivate::save):
     58        (WebCore::GraphicsContextPlatformPrivate::restore):
     59        (WebCore::GraphicsContextPlatformPrivate::flush):
     60        (WebCore::GraphicsContextPlatformPrivate::clip):
     61        (WebCore::GraphicsContextPlatformPrivate::scalePlatformCTM):
     62        (WebCore::GraphicsContextPlatformPrivate::rotatePlatformCTM):
     63        (WebCore::GraphicsContextPlatformPrivate::translatePlatformCTM):
     64        (WebCore::GraphicsContextPlatformPrivate::concatPlatformCTM):
     65        (WebCore::GraphicsContextPlatformPrivate::setPlatformCTM):
     66        (WebCore::GraphicsContextPlatformPrivate::scale): Deleted.
     67        (WebCore::GraphicsContextPlatformPrivate::rotate): Deleted.
     68        (WebCore::GraphicsContextPlatformPrivate::translate): Deleted.
     69        (WebCore::GraphicsContextPlatformPrivate::concatCTM): Deleted.
     70        (WebCore::GraphicsContextPlatformPrivate::setCTM): Deleted.
     71        * platform/graphics/cg/GraphicsContextCG.cpp: Renaming functions. Also,
     72        migrate CTM setters to go through GraphicsContext.
     73        (WebCore::GraphicsContext::resetPlatformCTM):
     74        (WebCore::GraphicsContext::platformInit):
     75        (WebCore::GraphicsContext::drawNativeImage):
     76        (WebCore::GraphicsContext::drawPattern):
     77        (WebCore::GraphicsContext::fillPath):
     78        (WebCore::GraphicsContext::scalePlatformCTM):
     79        (WebCore::GraphicsContext::rotatePlatformCTM):
     80        (WebCore::GraphicsContext::translatePlatformCTM):
     81        (WebCore::GraphicsContext::concatPlatformCTM):
     82        (WebCore::GraphicsContext::setPlatformCTM):
     83        (WebCore::GraphicsContext::getPlatformCTM):
     84        (WebCore::GraphicsContext::scale): Deleted.
     85        (WebCore::GraphicsContext::rotate): Deleted.
     86        (WebCore::GraphicsContext::translate): Deleted.
     87        (WebCore::GraphicsContext::concatCTM): Deleted.
     88        (WebCore::GraphicsContext::setCTM): Deleted.
     89        (WebCore::GraphicsContext::getCTM): Deleted.
     90        * platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
     91        (WebCore::GraphicsContextPlatformPrivate::save):
     92        (WebCore::GraphicsContextPlatformPrivate::restore):
     93        (WebCore::GraphicsContextPlatformPrivate::flush):
     94        (WebCore::GraphicsContextPlatformPrivate::clip):
     95        (WebCore::GraphicsContextPlatformPrivate::scalePlatformCTM):
     96        (WebCore::GraphicsContextPlatformPrivate::rotatePlatformCTM):
     97        (WebCore::GraphicsContextPlatformPrivate::translatePlatformCTM):
     98        (WebCore::GraphicsContextPlatformPrivate::concatPlatformCTM):
     99        (WebCore::GraphicsContextPlatformPrivate::setPlatformCTM):
     100        (WebCore::GraphicsContextPlatformPrivate::scale): Deleted.
     101        (WebCore::GraphicsContextPlatformPrivate::rotate): Deleted.
     102        (WebCore::GraphicsContextPlatformPrivate::translate): Deleted.
     103        (WebCore::GraphicsContextPlatformPrivate::concatCTM): Deleted.
     104        (WebCore::GraphicsContextPlatformPrivate::setCTM): Deleted.
     105        * platform/graphics/transforms/AffineTransform.h:
     106        (WebCore::AffineTransform::isEssentiallyEqualTo): Equality comparison on floats
     107        is not a good idea. Instead, this function is more valuable. (However, note that
     108        it is expected for values in a CTM to hold values close to 0, which means that
     109        this function might erroneously return false (similar to operator=()).
     110        * platform/graphics/win/GraphicsContextWin.cpp:
     111        (WebCore::GraphicsContextPlatformPrivate::scalePlatformCTM):
     112        (WebCore::GraphicsContextPlatformPrivate::rotatePlatformCTM):
     113        (WebCore::GraphicsContextPlatformPrivate::translatePlatformCTM):
     114        (WebCore::GraphicsContextPlatformPrivate::concatPlatformCTM):
     115        (WebCore::GraphicsContextPlatformPrivate::setPlatformCTM):
     116        (WebCore::GraphicsContextPlatformPrivate::scale): Deleted.
     117        (WebCore::GraphicsContextPlatformPrivate::rotate): Deleted.
     118        (WebCore::GraphicsContextPlatformPrivate::translate): Deleted.
     119        (WebCore::GraphicsContextPlatformPrivate::concatCTM): Deleted.
     120        (WebCore::GraphicsContextPlatformPrivate::setCTM): Deleted.
     121        * platform/mac/DragImageMac.mm:
     122        (WebCore::drawAtPoint):
     123        * platform/spi/cg/CoreGraphicsSPI.h:
     124
    11252015-10-19  Tim Horton  <timothy_horton@apple.com>
    2126
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r191314 r191324  
    143143}
    144144
     145void GraphicsContext::concatCTM(const AffineTransform& other)
     146{
     147    if (paintingDisabled())
     148        return;
     149
     150    checkCTMInvariants();
     151
     152    m_state.ctm *= other;
     153    concatPlatformCTM(other);
     154
     155    checkCTMInvariants();
     156}
     157
     158void GraphicsContext::scale(float x, float y)
     159{
     160    if (paintingDisabled())
     161        return;
     162
     163    checkCTMInvariants();
     164
     165    m_state.ctm.scale(x, y);
     166    scalePlatformCTM(x, y);
     167
     168    checkCTMInvariants();
     169}
     170
     171void GraphicsContext::rotate(float angle)
     172{
     173    if (paintingDisabled())
     174        return;
     175
     176    checkCTMInvariants();
     177
     178    m_state.ctm.rotate(rad2deg(angle));
     179    rotatePlatformCTM(angle);
     180
     181    checkCTMInvariants();
     182}
     183
     184void GraphicsContext::translate(float x, float y)
     185{
     186    if (paintingDisabled())
     187        return;
     188
     189    checkCTMInvariants();
     190
     191    m_state.ctm.translate(x, y);
     192    translatePlatformCTM(x, y);
     193
     194    checkCTMInvariants();
     195}
     196
     197void GraphicsContext::setCTM(const AffineTransform& other)
     198{
     199    if (paintingDisabled())
     200        return;
     201
     202    checkCTMInvariants();
     203
     204    m_state.ctm = other;
     205    setPlatformCTM(other);
     206
     207    checkCTMInvariants();
     208}
     209
     210AffineTransform GraphicsContext::getCTM(IncludeDeviceScale includeScale) const
     211{
     212    if (paintingDisabled())
     213        return AffineTransform();
     214
     215    AffineTransform result;
     216    if (includeScale == DefinitelyIncludeDeviceScale)
     217        result = m_state.userToDeviceSpaceCTM * m_state.ctm;
     218    else
     219        result = m_state.ctm;
     220
     221    ASSERT(result.isEssentiallyEqualTo(getPlatformCTM(includeScale)));
     222
     223    return result;
     224}
     225
    145226void GraphicsContext::drawRaisedEllipse(const FloatRect& rect, const Color& ellipseColor, ColorSpace ellipseColorSpace, const Color& shadowColor, ColorSpace shadowColorSpace)
    146227{
     
    296377    beginPlatformTransparencyLayer(opacity);
    297378    ++m_transparencyCount;
     379
     380    resetPlatformCTM();
    298381}
    299382
     
    655738void GraphicsContext::applyDeviceScaleFactor(float deviceScaleFactor)
    656739{
    657     scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
     740    scale(deviceScaleFactor, deviceScaleFactor);
     741
    658742    platformApplyDeviceScaleFactor(deviceScaleFactor);
    659743}
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r191314 r191324  
    157157    BlendMode blendMode { BlendModeNormal };
    158158
     159    AffineTransform userToDeviceSpaceCTM;
     160    AffineTransform ctm;
     161
    159162    bool shouldAntialias : 1;
    160163    bool shouldSmoothFonts : 1;
     
    421424    void clipOut(const Path&);
    422425
    423     WEBCORE_EXPORT void scale(const FloatSize&);
     426    WEBCORE_EXPORT void scale(const FloatSize& size) { scale(size.width(), size.height()); }
    424427    void rotate(float angleInRadians);
    425428    void translate(const FloatSize& size) { translate(size.width(), size.height()); }
     429    WEBCORE_EXPORT void scale(float x, float y);
    426430    WEBCORE_EXPORT void translate(float x, float y);
    427431
    428432    void setURLForRect(const URL&, const IntRect&);
    429433
     434    void checkCTMInvariants() const
     435    {
     436        ASSERT(getCTM(DefinitelyIncludeDeviceScale).isEssentiallyEqualTo(getPlatformCTM(DefinitelyIncludeDeviceScale)));
     437        ASSERT(getCTM(PossiblyIncludeDeviceScale).isEssentiallyEqualTo(getPlatformCTM(PossiblyIncludeDeviceScale)));
     438    }
    430439    void concatCTM(const AffineTransform&);
    431440    void setCTM(const AffineTransform&);
     441    void resetPlatformCTM();
    432442
    433443    enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
    434     AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
     444    AffineTransform getCTM(IncludeDeviceScale = PossiblyIncludeDeviceScale) const;
    435445
    436446#if ENABLE(3D_TRANSFORMS) && USE(TEXTURE_MAPPER)
     
    546556    void setPlatformCompositeOperation(CompositeOperator, BlendMode = BlendModeNormal);
    547557
     558    void concatPlatformCTM(const AffineTransform&);
     559    void scalePlatformCTM(float x, float y);
     560    void rotatePlatformCTM(float);
     561    void translatePlatformCTM(float, float);
     562    void setPlatformCTM(const AffineTransform&);
     563    AffineTransform getPlatformCTM(IncludeDeviceScale = PossiblyIncludeDeviceScale) const; // This is only computed to ASSERT() that the GraphicsContextState agrees with the underlying platform.
     564
    548565    void beginPlatformTransparencyLayer(float opacity);
    549566    void endPlatformTransparencyLayer();
  • trunk/Source/WebCore/platform/graphics/Image.h

    r191314 r191324  
    134134    enum TileRule { StretchTile, RoundTile, SpaceTile, RepeatTile };
    135135
    136     virtual PassNativeImagePtr nativeImageForCurrentFrame() { return 0; }
     136    virtual PassNativeImagePtr nativeImageForCurrentFrame() { return nullptr; }
    137137    virtual ImageOrientation orientationForCurrentFrame() { return ImageOrientation(); }
    138138
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r191314 r191324  
    195195}
    196196
    197 AffineTransform GraphicsContext::getCTM(IncludeDeviceScale) const
     197void GraphicsContext::resetPlatformCTM()
     198{
     199    if (platformContext())
     200        m_state.ctm = getPlatformCTM();
     201    else
     202        m_state.ctm.makeIdentity();
     203}
     204
     205AffineTransform GraphicsContext::getPlatformCTM(IncludeDeviceScale) const
    198206{
    199207    if (paintingDisabled())
     
    712720}
    713721
    714 void GraphicsContext::translate(float x, float y)
     722void GraphicsContext::translatePlatformCTM(float x, float y)
    715723{
    716724    if (paintingDisabled())
     
    719727    cairo_t* cr = platformContext()->cr();
    720728    cairo_translate(cr, x, y);
    721     m_data->translate(x, y);
     729    m_data->translatePlatformCTM(x, y);
    722730}
    723731
     
    774782}
    775783
    776 void GraphicsContext::concatCTM(const AffineTransform& transform)
     784void GraphicsContext::concatPlatformCTM(const AffineTransform& transform)
    777785{
    778786    if (paintingDisabled())
     
    782790    const cairo_matrix_t matrix = cairo_matrix_t(transform);
    783791    cairo_transform(cr, &matrix);
    784     m_data->concatCTM(transform);
    785 }
    786 
    787 void GraphicsContext::setCTM(const AffineTransform& transform)
     792    m_data->concatPlatformCTM(transform);
     793}
     794
     795void GraphicsContext::setPlatformCTM(const AffineTransform& transform)
    788796{
    789797    if (paintingDisabled())
     
    793801    const cairo_matrix_t matrix = cairo_matrix_t(transform);
    794802    cairo_set_matrix(cr, &matrix);
    795     m_data->setCTM(transform);
     803    m_data->setPlatformCTM(transform);
    796804}
    797805
     
    10041012}
    10051013
    1006 void GraphicsContext::rotate(float radians)
     1014void GraphicsContext::rotatePlatformCTM(float radians)
    10071015{
    10081016    if (paintingDisabled())
     
    10101018
    10111019    cairo_rotate(platformContext()->cr(), radians);
    1012     m_data->rotate(radians);
    1013 }
    1014 
    1015 void GraphicsContext::scale(const FloatSize& size)
    1016 {
    1017     if (paintingDisabled())
    1018         return;
    1019 
    1020     cairo_scale(platformContext()->cr(), size.width(), size.height());
    1021     m_data->scale(size);
     1020    m_data->rotatePlatformCTM(radians);
     1021}
     1022
     1023void GraphicsContext::scalePlatformCTM(float x, float y)
     1024{
     1025    if (paintingDisabled())
     1026        return;
     1027
     1028    cairo_scale(platformContext()->cr(), x, y);
     1029    m_data->scalePlatformCTM(x, y);
    10221030}
    10231031
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h

    r191314 r191324  
    6868    void clip(const FloatRect&);
    6969    void clip(const Path&);
    70     void scale(const FloatSize&);
    71     void rotate(float);
    72     void translate(float, float);
    73     void concatCTM(const AffineTransform&);
    74     void setCTM(const AffineTransform&);
     70    void scalePlatformCTM(float, float);
     71    void rotatePlatformCTM(float);
     72    void translatePlatformCTM(float, float);
     73    void concatPlatformCTM(const AffineTransform&);
     74    void setPlatformCTM(const AffineTransform&);
    7575    void syncContext(cairo_t* cr);
    7676#else
    7777    // On everything else, we do nothing.
    78     void save() {}
    79     void restore() {}
    80     void flush() {}
    81     void clip(const FloatRect&) {}
    82     void clip(const Path&) {}
    83     void scale(const FloatSize&) {}
    84     void rotate(float) {}
    85     void translate(float, float) {}
    86     void concatCTM(const AffineTransform&) {}
    87     void setCTM(const AffineTransform&) {}
     78    void save() { }
     79    void restore() { }
     80    void flush() { }
     81    void clip(const FloatRect&) { }
     82    void clip(const Path&) { }
     83    void scalePlatformCTM(float, float) { }
     84    void rotatePlatformCTM(float) { }
     85    void translatePlatformCTM(float, float) { }
     86    void concatPlatformCTM(const AffineTransform&) { }
     87    void setPlatformCTM(const AffineTransform&) { }
    8888    void syncContext(cairo_t*) { }
    8989#endif
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r191314 r191324  
    105105#endif
    106106
     107void GraphicsContext::resetPlatformCTM()
     108{
     109    m_state.ctm = CGContextGetCTM(platformContext());
     110#if PLATFORM(WIN) || PLATFORM(IOS)
     111    m_state.userToDeviceSpaceCTM = static_cast<AffineTransform>(CGContextGetUserSpaceToDeviceSpaceTransform(platformContext())) * m_state.ctm.inverse();
     112#else
     113    m_state.userToDeviceSpaceCTM = CGContextGetDefaultUserSpaceToDeviceSpaceTransform(platformContext());
     114#endif
     115}
     116
    107117void GraphicsContext::platformInit(CGContextRef cgContext)
    108118{
     
    114124        setPlatformStrokeColor(strokeColor(), strokeColorSpace());
    115125        setPlatformStrokeThickness(strokeThickness());
     126        resetPlatformCTM();
    116127    }
    117128}
     
    155166
    156167    CGContextRef context = platformContext();
    157     CGContextStateSaver stateSaver(context);
     168    GraphicsContextStateSaver stateSaver(*this);
    158169
    159170#if PLATFORM(IOS)
     
    269280
    270281    CGContextRef context = platformContext();
    271     CGContextStateSaver stateSaver(context);
     282    GraphicsContextStateSaver stateSaver(*this);
    272283    CGContextClipToRect(context, destRect);
    273284
     
    671682            FloatSize layerSize = getCTM().mapSize(rect.size());
    672683
    673             CGLayerRef layer = CGLayerCreateWithContext(context, layerSize, 0);
     684            CGLayerRef layer = CGLayerCreateWithContext(context, layerSize, nullptr);
    674685            CGContextRef layerContext = CGLayerGetContext(layer);
    675686
     
    12541265}
    12551266
    1256 void GraphicsContext::scale(const FloatSize& size)
    1257 {
    1258     if (paintingDisabled())
    1259         return;
    1260     CGContextScaleCTM(platformContext(), size.width(), size.height());
    1261     m_data->scale(size);
     1267void GraphicsContext::scalePlatformCTM(float x, float y)
     1268{
     1269    if (paintingDisabled())
     1270        return;
     1271    CGContextScaleCTM(platformContext(), x, y);
     1272    m_data->scalePlatformCTM(x, y);
    12621273    m_data->m_userToDeviceTransformKnownToBeIdentity = false;
    12631274}
    12641275
    1265 void GraphicsContext::rotate(float angle)
     1276void GraphicsContext::rotatePlatformCTM(float angle)
    12661277{
    12671278    if (paintingDisabled())
    12681279        return;
    12691280    CGContextRotateCTM(platformContext(), angle);
    1270     m_data->rotate(angle);
     1281    m_data->rotatePlatformCTM(angle);
    12711282    m_data->m_userToDeviceTransformKnownToBeIdentity = false;
    12721283}
    12731284
    1274 void GraphicsContext::translate(float x, float y)
     1285void GraphicsContext::translatePlatformCTM(float x, float y)
    12751286{
    12761287    if (paintingDisabled())
    12771288        return;
    12781289    CGContextTranslateCTM(platformContext(), x, y);
    1279     m_data->translate(x, y);
     1290    m_data->translatePlatformCTM(x, y);
    12801291    m_data->m_userToDeviceTransformKnownToBeIdentity = false;
    12811292}
    12821293
    1283 void GraphicsContext::concatCTM(const AffineTransform& transform)
     1294void GraphicsContext::concatPlatformCTM(const AffineTransform& transform)
    12841295{
    12851296    if (paintingDisabled())
    12861297        return;
    12871298    CGContextConcatCTM(platformContext(), transform);
    1288     m_data->concatCTM(transform);
     1299    m_data->concatPlatformCTM(transform);
    12891300    m_data->m_userToDeviceTransformKnownToBeIdentity = false;
    12901301}
    12911302
    1292 void GraphicsContext::setCTM(const AffineTransform& transform)
     1303void GraphicsContext::setPlatformCTM(const AffineTransform& transform)
    12931304{
    12941305    if (paintingDisabled())
    12951306        return;
    12961307    CGContextSetCTM(platformContext(), transform);
    1297     m_data->setCTM(transform);
     1308    m_data->setPlatformCTM(transform);
    12981309    m_data->m_userToDeviceTransformKnownToBeIdentity = false;
    12991310}
    13001311
    1301 AffineTransform GraphicsContext::getCTM(IncludeDeviceScale includeScale) const
     1312AffineTransform GraphicsContext::getPlatformCTM(IncludeDeviceScale includeScale) const
    13021313{
    13031314    if (paintingDisabled())
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h

    r191314 r191324  
    5454#if PLATFORM(COCOA)
    5555    // These methods do nothing on Mac.
    56     void save() {}
    57     void restore() {}
    58     void flush() {}
    59     void clip(const FloatRect&) {}
    60     void clip(const Path&) {}
    61     void scale(const FloatSize&) {}
    62     void rotate(float) {}
    63     void translate(float, float) {}
    64     void concatCTM(const AffineTransform&) {}
    65     void setCTM(const AffineTransform&) {}
     56    void save() { }
     57    void restore() { }
     58    void flush() { }
     59    void clip(const FloatRect&) { }
     60    void clip(const Path&) { }
     61    void scalePlatformCTM(float, float) { }
     62    void rotatePlatformCTM(float) { }
     63    void translatePlatformCTM(float, float) { }
     64    void concatPlatformCTM(const AffineTransform&) { }
     65    void setPlatformCTM(const AffineTransform&) { }
    6666#endif
    6767
     
    7373    void clip(const FloatRect&);
    7474    void clip(const Path&);
    75     void scale(const FloatSize&);
    76     void rotate(float);
    77     void translate(float, float);
    78     void concatCTM(const AffineTransform&);
    79     void setCTM(const AffineTransform&);
     75    void scalePlatformCTM(float x, float y);
     76    void rotatePlatformCTM(float);
     77    void translatePlatformCTM(float, float);
     78    void concatPlatformCTM(const AffineTransform&);
     79    void setPlatformCTM(const AffineTransform&);
    8080
    8181    HDC m_hdc;
  • trunk/Source/WebCore/platform/graphics/transforms/AffineTransform.h

    r191314 r191324  
    3131#include <array>
    3232#include <wtf/FastMalloc.h>
     33#include <wtf/MathExtras.h>
    3334
    3435#if USE(CG)
     
    141142    }
    142143
     144    // FIXME: If you compare floats for equality, you're gonna have a bad time. We should delete this.
    143145    bool operator== (const AffineTransform& m2) const
    144146    {
     
    152154
    153155    bool operator!=(const AffineTransform& other) const { return !(*this == other); }
     156
     157    bool isEssentiallyEqualTo(const AffineTransform& m2, double epsilon = 0.001) const
     158    {
     159        // WTF::areEssentiallyEqual() doesn't work well in this case. That function is designed to allow for error
     160        // which scales proportionately to the values. However, AffineTransforms are often rotated by pi/2, which
     161        // are not exactly representable. This results in AffineTransform components which are close to, but not
     162        // exactly equal to, zero. In this case, the error and the value are approximately equal, which leads to
     163        // a false negative return.
     164        return std::abs(m_transform[0] - m2.m_transform[0]) < epsilon
     165            && std::abs(m_transform[1] - m2.m_transform[1]) < epsilon
     166            && std::abs(m_transform[2] - m2.m_transform[2]) < epsilon
     167            && std::abs(m_transform[3] - m2.m_transform[3]) < epsilon
     168            && std::abs(m_transform[4] - m2.m_transform[4]) < epsilon
     169            && std::abs(m_transform[5] - m2.m_transform[5]) < epsilon;
     170    }
    154171
    155172    // *this = *this * t (i.e., a multRight)
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextWin.cpp

    r191314 r191324  
    172172}
    173173
    174 void GraphicsContextPlatformPrivate::scale(const FloatSize& size)
    175 {
    176     if (!m_hdc)
    177         return;
    178 
    179     XFORM xform = TransformationMatrix().scaleNonUniform(size.width(), size.height());
     174void GraphicsContextPlatformPrivate::scalePlatformCTM(float x, float y)
     175{
     176    if (!m_hdc)
     177        return;
     178
     179    XFORM xform = TransformationMatrix().scaleNonUniform(x, y);
    180180    ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
    181181}
     
    183183static const double deg2rad = 0.017453292519943295769; // pi/180
    184184
    185 void GraphicsContextPlatformPrivate::rotate(float degreesAngle)
     185void GraphicsContextPlatformPrivate::rotatePlatformCTM(float degreesAngle)
    186186{
    187187    XFORM xform = TransformationMatrix().rotate(degreesAngle);
     
    189189}
    190190
    191 void GraphicsContextPlatformPrivate::translate(float x , float y)
     191void GraphicsContextPlatformPrivate::translatePlatformCTM(float x , float y)
    192192{
    193193    if (!m_hdc)
     
    198198}
    199199
    200 void GraphicsContextPlatformPrivate::concatCTM(const AffineTransform& transform)
     200void GraphicsContextPlatformPrivate::concatPlatformCTM(const AffineTransform& transform)
    201201{
    202202    if (!m_hdc)
     
    207207}
    208208
    209 void GraphicsContextPlatformPrivate::setCTM(const AffineTransform& transform)
     209void GraphicsContextPlatformPrivate::setPlatformCTM(const AffineTransform& transform)
    210210{
    211211    if (!m_hdc)
  • trunk/Source/WebCore/platform/mac/DragImageMac.mm

    r191314 r191324  
    217217        NSGraphicsContext *nsContext = [NSGraphicsContext currentContext];
    218218        CGContextRef cgContext = static_cast<CGContextRef>([nsContext graphicsPort]);
    219         GraphicsContext graphicsContext(cgContext);   
    220219       
    221220        // Safari doesn't flip the NSGraphicsContext before calling WebKit, yet WebCore requires a flipped graphics context.
     
    223222        if (!flipped)
    224223            CGContextScaleCTM(cgContext, 1, -1);
     224
     225        GraphicsContext graphicsContext(cgContext);
    225226           
    226227        FontCascade webCoreFont(FontPlatformData(toCTFont(font), [font pointSize]), Antialiased);
  • trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h

    r191314 r191324  
    144144void CGContextSetShouldAntialiasFonts(CGContextRef, bool shouldAntialiasFonts);
    145145void CGContextResetClip(CGContextRef);
     146CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform(CGContextRef);
     147CGAffineTransform CGContextGetDefaultUserSpaceToDeviceSpaceTransform(CGContextRef);
    146148#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
    147149void CGContextSetFontDilation(CGContextRef, CGSize);
Note: See TracChangeset for help on using the changeset viewer.