Changeset 156391 in webkit


Ignore:
Timestamp:
Sep 25, 2013 6:53:08 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

<https://webkit.org/b/120476> [CSS Masking] Implement luminance masking

Source/WebCore:

Added implementation for luminance masking. A luminance mask is applied by transforming its RGB values into
an alpha value, using luminance-to-alpha coefficients. Because this conversion is already implemented in
the ImageBuffer class, we used it in our implementation.

Patch by Andrei Parvu <parvu@adobe.com> on 2013-09-25
Reviewed by Dirk Schulze.

Tests: css3/masking/mask-luminance-gradient.html

css3/masking/mask-luminance-png.html
css3/masking/mask-luminance-svg.html

  • platform/graphics/BitmapImage.cpp: Add a drawPattern method, in which an ImageBuffer is created and converted from alpha to luminance, if there is a luminance mask.

(WebCore::BitmapImage::BitmapImage):
(WebCore::BitmapImage::drawPattern):

  • platform/graphics/BitmapImage.h:
  • platform/graphics/GeneratorGeneratedImage.cpp: Convert the ImageBuffer to luminance, if necessary.

(WebCore::GeneratorGeneratedImage::drawPattern):

  • platform/graphics/GraphicsContext.cpp: Add methods which set and check if a luminance mask is drawn.

(WebCore::GraphicsContext::setDrawLuminanceMask):
(WebCore::GraphicsContext::drawLuminanceMask):

  • platform/graphics/GraphicsContext.h: Add property to ContextState for luminance drawing.

(WebCore::GraphicsContextState::GraphicsContextState):

  • rendering/RenderBoxModelObject.cpp: Set the luminance property of the mask, if the layer has a mask source type of luminance.

(WebCore::RenderBoxModelObject::paintFillLayerExtended):

  • svg/graphics/SVGImage.cpp: Convert the ImageBuffer to luminance, if necessary.

(WebCore::SVGImage::drawPatternForContainer):

  • svg/graphics/SVGImageForContainer.cpp: Pass the luminance property to the SVG image.

(WebCore::SVGImageForContainer::drawPattern):

LayoutTests:

Added tests to verify the implementation of luminance masking.

Patch by Andrei Parvu <parvu@adobe.com> on 2013-09-25
Reviewed by Dirk Schulze.

  • css3/masking/mask-luminance-gradient-expected.html: Added.
  • css3/masking/mask-luminance-gradient.html: Added.
  • css3/masking/mask-luminance-png.html: Added.
  • css3/masking/mask-luminance-svg-expected.html: Added.
  • css3/masking/mask-luminance-svg.html: Added.
  • css3/masking/resources/circle-alpha.svg: Added.
  • css3/masking/resources/circle2.svg: Added.
  • css3/masking/resources/dice.png: Added.
  • platform/mac/css3/masking/mask-luminance-png-expected.txt: Added.
Location:
trunk
Files:
9 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r156389 r156391  
     12013-09-25  Andrei Parvu  <parvu@adobe.com>
     2
     3        <https://webkit.org/b/120476> [CSS Masking] Implement luminance masking
     4
     5        Added tests to verify the implementation of luminance masking.
     6
     7        Reviewed by Dirk Schulze.
     8
     9        * css3/masking/mask-luminance-gradient-expected.html: Added.
     10        * css3/masking/mask-luminance-gradient.html: Added.
     11        * css3/masking/mask-luminance-png.html: Added.
     12        * css3/masking/mask-luminance-svg-expected.html: Added.
     13        * css3/masking/mask-luminance-svg.html: Added.
     14        * css3/masking/resources/circle-alpha.svg: Added.
     15        * css3/masking/resources/circle2.svg: Added.
     16        * css3/masking/resources/dice.png: Added.
     17        * platform/mac/css3/masking/mask-luminance-png-expected.txt: Added.
     18
    1192013-09-25  Krzysztof Czech  <k.czech@samsung.com>
    220
  • trunk/Source/WebCore/ChangeLog

    r156390 r156391  
     12013-09-25  Andrei Parvu  <parvu@adobe.com>
     2
     3        <https://webkit.org/b/120476> [CSS Masking] Implement luminance masking
     4
     5        Added implementation for luminance masking. A luminance mask is applied by transforming its RGB values into
     6        an alpha value, using luminance-to-alpha coefficients. Because this conversion is already implemented in
     7        the ImageBuffer class, we used it in our implementation.
     8
     9        Reviewed by Dirk Schulze.
     10
     11        Tests: css3/masking/mask-luminance-gradient.html
     12               css3/masking/mask-luminance-png.html
     13               css3/masking/mask-luminance-svg.html
     14
     15        * platform/graphics/BitmapImage.cpp: Add a drawPattern method, in which an ImageBuffer is created and converted from alpha to luminance, if there is a luminance mask.
     16        (WebCore::BitmapImage::BitmapImage):
     17        (WebCore::BitmapImage::drawPattern):
     18        * platform/graphics/BitmapImage.h:
     19        * platform/graphics/GeneratorGeneratedImage.cpp: Convert the ImageBuffer to luminance, if necessary.
     20        (WebCore::GeneratorGeneratedImage::drawPattern):
     21        * platform/graphics/GraphicsContext.cpp: Add methods which set and check if a luminance mask is drawn.
     22        (WebCore::GraphicsContext::setDrawLuminanceMask):
     23        (WebCore::GraphicsContext::drawLuminanceMask):
     24        * platform/graphics/GraphicsContext.h: Add property to ContextState for luminance drawing.
     25        (WebCore::GraphicsContextState::GraphicsContextState):
     26        * rendering/RenderBoxModelObject.cpp: Set the luminance property of the mask, if the layer has a mask source type of luminance.
     27        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
     28        * svg/graphics/SVGImage.cpp: Convert the ImageBuffer to luminance, if necessary.
     29        (WebCore::SVGImage::drawPatternForContainer):
     30        * svg/graphics/SVGImageForContainer.cpp: Pass the luminance property to the SVG image.
     31        (WebCore::SVGImageForContainer::drawPattern):
     32
    1332013-09-25  Andreas Kling  <akling@apple.com>
    234
  • trunk/Source/WebCore/platform/graphics/BitmapImage.cpp

    r155721 r156391  
    2929
    3030#include "FloatRect.h"
     31#include "ImageBuffer.h"
    3132#include "ImageObserver.h"
    3233#include "IntRect.h"
     
    5960    , m_hasUniformFrameSize(true)
    6061    , m_haveFrameCount(false)
     62    , m_cachedImage(0)
    6163{
    6264}
     
    493495}
    494496
     497void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& transform,
     498    const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
     499{
     500    if (tileRect.isEmpty())
     501        return;
     502
     503    if (!ctxt->drawLuminanceMask()) {
     504        Image::drawPattern(ctxt, tileRect, transform, phase, styleColorSpace, op, destRect, blendMode);
     505        return;
     506    }
     507    if (!m_cachedImage) {
     508        OwnPtr<ImageBuffer> buffer = ImageBuffer::create(expandedIntSize(tileRect.size()));
     509        ASSERT(buffer.get() > 0);
     510
     511        ImageObserver* observer = imageObserver();
     512        ASSERT(observer);
     513
     514        // Temporarily reset image observer, we don't want to receive any changeInRect() calls due to this relayout.
     515        setImageObserver(0);
     516
     517        draw(buffer->context(), tileRect, tileRect, styleColorSpace, op, blendMode);
     518
     519        setImageObserver(observer);
     520        buffer->convertToLuminanceMask();
     521
     522        m_cachedImage = buffer->copyImage(DontCopyBackingStore, Unscaled);
     523        m_cachedImage->setSpaceSize(spaceSize());
     524
     525        setImageObserver(observer);
     526    }
     527
     528    ctxt->setDrawLuminanceMask(false);
     529    m_cachedImage->drawPattern(ctxt, tileRect, transform, phase, styleColorSpace, op, destRect, blendMode);
     530}
    495531
    496532
  • trunk/Source/WebCore/platform/graphics/BitmapImage.h

    r156226 r156391  
    137137    virtual unsigned decodedSize() const OVERRIDE;
    138138
     139    virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
     140        const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal) OVERRIDE;
     141
    139142#if PLATFORM(MAC)
    140143    // Accessors for native image formats.
     
    297300    mutable bool m_hasUniformFrameSize : 1;
    298301    mutable bool m_haveFrameCount : 1;
     302
     303    RefPtr<Image> m_cachedImage;
    299304};
    300305
  • trunk/Source/WebCore/platform/graphics/GradientImage.cpp

    r156226 r156391  
    7373        m_cachedGeneratorHash = generatorHash;
    7474        m_cachedAdjustedSize = adjustedSize;
     75
     76        if (destContext->drawLuminanceMask())
     77            m_cachedImageBuffer->convertToLuminanceMask();
    7578    }
    7679
    7780    m_cachedImageBuffer->setSpaceSize(spaceSize());
     81    destContext->setDrawLuminanceMask(false);
     82
    7883    // Tile the image buffer into the context.
    7984    m_cachedImageBuffer->drawPattern(destContext, adjustedSrcRect, adjustedPatternCTM, phase, styleColorSpace, compositeOp, destRect);
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r154088 r156391  
    739739}
    740740
     741void GraphicsContext::setDrawLuminanceMask(bool drawLuminanceMask)
     742{
     743    m_state.drawLuminanceMask = drawLuminanceMask;
     744}
     745
     746bool GraphicsContext::drawLuminanceMask() const
     747{
     748    return m_state.drawLuminanceMask;
     749}
     750
    741751#if !USE(CG)
    742752// Implement this if you want to go ahead and push the drawing mode into your native context
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r154088 r156391  
    151151            , shadowsUseLegacyRadius(false)
    152152#endif
     153            , drawLuminanceMask(false)
    153154        {
    154155        }
     
    189190        bool shadowsUseLegacyRadius : 1;
    190191#endif
     192        bool drawLuminanceMask : 1;
    191193    };
    192194
     
    382384        CompositeOperator compositeOperation() const;
    383385        BlendMode blendModeOperation() const;
     386
     387        void setDrawLuminanceMask(bool);
     388        bool drawLuminanceMask() const;
    384389
    385390        void clip(const Path&, WindRule = RULE_EVENODD);
  • trunk/Source/WebCore/platform/graphics/Image.cpp

    r154875 r156391  
    121121   
    122122    // Check and see if a single draw of the image can cover the entire area we are supposed to tile.   
    123     if (oneTileRect.contains(destRect)) {
     123    if (oneTileRect.contains(destRect) && !ctxt->drawLuminanceMask()) {
    124124        FloatRect visibleSrcRect;
    125125        visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r156322 r156391  
    798798            RenderObject* clientForBackgroundImage = backgroundObject ? backgroundObject : this;
    799799            RefPtr<Image> image = bgImage->image(clientForBackgroundImage, geometry.tileSize());
     800            context->setDrawLuminanceMask(bgLayer->maskSourceType() == MaskLuminance);
    800801            bool useLowQualityScaling = shouldPaintAtLowQuality(context, image.get(), bgLayer, geometry.tileSize());
    801802            if (image.get())
  • trunk/Source/WebCore/svg/graphics/SVGImage.cpp

    r155217 r156391  
    202202        return;
    203203    drawForContainer(buffer->context(), containerSize, zoom, imageBufferSize, zoomedContainerRect, ColorSpaceDeviceRGB, CompositeSourceOver, BlendModeNormal);
     204    if (context->drawLuminanceMask())
     205        buffer->convertToLuminanceMask();
     206
    204207    RefPtr<Image> image = buffer->copyImage(DontCopyBackingStore, Unscaled);
    205208    image->setSpaceSize(spaceSize());
     
    211214    unscaledPatternTransform.scale(1 / imageBufferScale.width(), 1 / imageBufferScale.height());
    212215
     216    context->setDrawLuminanceMask(false);
    213217    image->drawPattern(context, scaledSrcRect, unscaledPatternTransform, phase, colorSpace, compositeOp, dstRect);
    214218}
Note: See TracChangeset for help on using the changeset viewer.