Changeset 157045 in webkit


Ignore:
Timestamp:
Oct 7, 2013 9:48:09 AM (11 years ago)
Author:
timothy_horton@apple.com
Message:

-webkit-cross-fade paints SVGs at full opacity during cross-fade
https://bugs.webkit.org/show_bug.cgi?id=122441
<rdar://problem/13973162>

Reviewed by Simon Fraser.

Test: css3/images/cross-fade-svg-with-opacity.html

  • platform/graphics/CrossfadeGeneratedImage.cpp:

(WebCore::drawCrossfadeSubimage):
(WebCore::CrossfadeGeneratedImage::drawCrossfade):
Factor the image painting out into a function.
Conditionally use a transparency layer around painting if the image
we're drawing is an SVG (SVGImage is the only Image subclass that will
not respect the context's opacity).

Add a test that ensures that -cross-fade with SVG images draws correctly.

  • css3/images/cross-fade-svg-with-opacity-expected.html: Added.
  • css3/images/cross-fade-svg-with-opacity.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r157043 r157045  
     12013-10-07  Tim Horton  <timothy_horton@apple.com>
     2
     3        -webkit-cross-fade paints SVGs at full opacity during cross-fade
     4        https://bugs.webkit.org/show_bug.cgi?id=122441
     5        <rdar://problem/13973162>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Add a test that ensures that -cross-fade with SVG images draws correctly.
     10
     11        * css3/images/cross-fade-svg-with-opacity-expected.html: Added.
     12        * css3/images/cross-fade-svg-with-opacity.html: Added.
     13
    1142013-10-07  Filip Pizlo  <fpizlo@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r157044 r157045  
     12013-10-07  Tim Horton  <timothy_horton@apple.com>
     2
     3        -webkit-cross-fade paints SVGs at full opacity during cross-fade
     4        https://bugs.webkit.org/show_bug.cgi?id=122441
     5        <rdar://problem/13973162>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Test: css3/images/cross-fade-svg-with-opacity.html
     10
     11        * platform/graphics/CrossfadeGeneratedImage.cpp:
     12        (WebCore::drawCrossfadeSubimage):
     13        (WebCore::CrossfadeGeneratedImage::drawCrossfade):
     14        Factor the image painting out into a function.
     15        Conditionally use a transparency layer around painting if the image
     16        we're drawing is an SVG (SVGImage is the only Image subclass that will
     17        not respect the context's opacity).
     18
    1192013-10-06  Anders Carlsson  <andersca@apple.com>
    220
  • trunk/Source/WebCore/platform/graphics/CrossfadeGeneratedImage.cpp

    r155721 r157045  
    4444}
    4545
     46static void drawCrossfadeSubimage(GraphicsContext* context, Image* image, CompositeOperator operation, float opacity, IntSize targetSize)
     47{
     48    IntSize imageSize = image->size();
     49
     50    // SVGImage resets the opacity when painting, so we have to use transparency layers to accurately paint one at a given opacity.
     51    bool useTransparencyLayer = image->isSVGImage();
     52
     53    GraphicsContextStateSaver stateSaver(*context);
     54
     55    context->setCompositeOperation(operation);
     56
     57    if (useTransparencyLayer)
     58        context->beginTransparencyLayer(opacity);
     59    else
     60        context->setAlpha(opacity);
     61
     62    if (targetSize != imageSize)
     63        context->scale(FloatSize(static_cast<float>(targetSize.width()) / imageSize.width(),
     64            static_cast<float>(targetSize.height()) / imageSize.height()));
     65    context->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
     66
     67    if (useTransparencyLayer)
     68        context->endTransparencyLayer();
     69}
     70
    4671void CrossfadeGeneratedImage::drawCrossfade(GraphicsContext* context)
    4772{
    48     float inversePercentage = 1 - m_percentage;
    49 
    50     IntSize fromImageSize = m_fromImage->size();
    51     IntSize toImageSize = m_toImage->size();
    52 
    5373    // Draw nothing if either of the images hasn't loaded yet.
    5474    if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage())
     
    5979    context->clip(IntRect(IntPoint(), m_crossfadeSize));
    6080    context->beginTransparencyLayer(1);
    61    
    62     // Draw the image we're fading away from.
    63     context->save();
    64     if (m_crossfadeSize != fromImageSize)
    65         context->scale(FloatSize(static_cast<float>(m_crossfadeSize.width()) / fromImageSize.width(),
    66                                  static_cast<float>(m_crossfadeSize.height()) / fromImageSize.height()));
    67     context->setAlpha(inversePercentage);
    68     context->drawImage(m_fromImage, ColorSpaceDeviceRGB, IntPoint());
    69     context->restore();
    7081
    71     // Draw the image we're fading towards.
    72     context->save();
    73     if (m_crossfadeSize != toImageSize)
    74         context->scale(FloatSize(static_cast<float>(m_crossfadeSize.width()) / toImageSize.width(),
    75                                  static_cast<float>(m_crossfadeSize.height()) / toImageSize.height()));
    76     context->setAlpha(m_percentage);
    77     context->drawImage(m_toImage, ColorSpaceDeviceRGB, IntPoint(), CompositePlusLighter);
    78     context->restore();
     82    drawCrossfadeSubimage(context, m_fromImage, CompositeSourceOver, 1 - m_percentage, m_crossfadeSize);
     83    drawCrossfadeSubimage(context, m_toImage, CompositePlusLighter, m_percentage, m_crossfadeSize);
    7984
    8085    context->endTransparencyLayer();
Note: See TracChangeset for help on using the changeset viewer.