Changeset 195848 in webkit


Ignore:
Timestamp:
Jan 29, 2016 3:15:58 PM (8 years ago)
Author:
Simon Fraser
Message:

image-rendering: -webkit-optimize-contrast not working for background images
https://bugs.webkit.org/show_bug.cgi?id=97991

Reviewed by Darin Adler.
Source/WebCore:

Don't equate "pixelated" and "crisp-edges" values for image-rendering with low
quality scaling; they should map to InterpolationNone, not InterpolationLow.

To support this change ImageQualityController to return a InterpolationQuality
from the renamed chooseInterpolationQuality(). If the returned value is not
InterpolationDefault, set the GraphicsContext image interpolation when drawing
images and image buffers.

Remove the redundant "useLowQualityScale" from

Test: fast/images/image-rendering-interpolation.html

  • html/HTMLCanvasElement.cpp:

(WebCore::HTMLCanvasElement::paint):

  • html/HTMLCanvasElement.h:
  • page/DragController.cpp:

(WebCore::DragController::doImageDrag):

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::drawImage):
(WebCore::GraphicsContext::drawTiledImage):
(WebCore::GraphicsContext::drawImageBuffer):
(WebCore::GraphicsContext::drawConsumingImageBuffer):
(WebCore::InterpolationQualityMaintainer::InterpolationQualityMaintainer): Deleted.
(WebCore::InterpolationQualityMaintainer::~InterpolationQualityMaintainer): Deleted.

  • platform/graphics/GraphicsContext.h:

(WebCore::ImagePaintingOptions::ImagePaintingOptions):
(WebCore::ImagePaintingOptions::usesDefaultInterpolation):
(WebCore::InterpolationQualityMaintainer::InterpolationQualityMaintainer):
(WebCore::InterpolationQualityMaintainer::~InterpolationQualityMaintainer):

  • platform/graphics/GraphicsTypes.h:
  • platform/graphics/ImageBuffer.h:
  • platform/graphics/cg/ImageBufferCG.cpp:

(WebCore::ImageBuffer::drawConsuming):
(WebCore::ImageBuffer::draw):

  • rendering/ImageQualityController.cpp:

(WebCore::ImageQualityController::interpolationQualityFromStyle):
(WebCore::ImageQualityController::chooseInterpolationQuality):
(WebCore::ImageQualityController::ImageQualityController): Deleted.
(WebCore::ImageQualityController::shouldPaintAtLowQuality): Deleted.

  • rendering/ImageQualityController.h:
  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::chooseInterpolationQuality):
(WebCore::RenderBoxModelObject::paintFillLayerExtended):
(WebCore::RenderBoxModelObject::shouldPaintAtLowQuality): Deleted.

  • rendering/RenderBoxModelObject.h:
  • rendering/RenderEmbeddedObject.cpp:

(WebCore::RenderEmbeddedObject::paintSnapshotImage):

  • rendering/RenderHTMLCanvas.cpp:

(WebCore::RenderHTMLCanvas::paintReplaced):

  • rendering/RenderImage.cpp:

(WebCore::RenderImage::paintIntoRect):

  • rendering/RenderSnapshottedPlugIn.cpp:

(WebCore::RenderSnapshottedPlugIn::paintSnapshot):

  • rendering/style/RenderStyle.h:

LayoutTests:

  • fast/images/image-rendering-interpolation-expected.html: Added.
  • fast/images/image-rendering-interpolation.html: Added.
Location:
trunk
Files:
2 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r195838 r195848  
     12016-01-29  Simon Fraser  <simon.fraser@apple.com>
     2
     3        image-rendering: -webkit-optimize-contrast not working for background images
     4        https://bugs.webkit.org/show_bug.cgi?id=97991
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/images/image-rendering-interpolation-expected.html: Added.
     9        * fast/images/image-rendering-interpolation.html: Added.
     10
    1112016-01-29  Brady Eidson  <beidson@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r195838 r195848  
     12016-01-29  Simon Fraser  <simon.fraser@apple.com>
     2
     3        image-rendering: -webkit-optimize-contrast not working for background images
     4        https://bugs.webkit.org/show_bug.cgi?id=97991
     5
     6        Reviewed by Darin Adler.
     7       
     8        Don't equate "pixelated" and "crisp-edges" values for image-rendering with low
     9        quality scaling; they should map to InterpolationNone, not InterpolationLow.
     10       
     11        To support this change ImageQualityController to return a InterpolationQuality
     12        from the renamed chooseInterpolationQuality(). If the returned value is not
     13        InterpolationDefault, set the GraphicsContext image interpolation when drawing
     14        images and image buffers.
     15       
     16        Remove the redundant "useLowQualityScale" from
     17
     18        Test: fast/images/image-rendering-interpolation.html
     19
     20        * html/HTMLCanvasElement.cpp:
     21        (WebCore::HTMLCanvasElement::paint):
     22        * html/HTMLCanvasElement.h:
     23        * page/DragController.cpp:
     24        (WebCore::DragController::doImageDrag):
     25        * platform/graphics/GraphicsContext.cpp:
     26        (WebCore::GraphicsContext::drawImage):
     27        (WebCore::GraphicsContext::drawTiledImage):
     28        (WebCore::GraphicsContext::drawImageBuffer):
     29        (WebCore::GraphicsContext::drawConsumingImageBuffer):
     30        (WebCore::InterpolationQualityMaintainer::InterpolationQualityMaintainer): Deleted.
     31        (WebCore::InterpolationQualityMaintainer::~InterpolationQualityMaintainer): Deleted.
     32        * platform/graphics/GraphicsContext.h:
     33        (WebCore::ImagePaintingOptions::ImagePaintingOptions):
     34        (WebCore::ImagePaintingOptions::usesDefaultInterpolation):
     35        (WebCore::InterpolationQualityMaintainer::InterpolationQualityMaintainer):
     36        (WebCore::InterpolationQualityMaintainer::~InterpolationQualityMaintainer):
     37        * platform/graphics/GraphicsTypes.h:
     38        * platform/graphics/ImageBuffer.h:
     39        * platform/graphics/cg/ImageBufferCG.cpp:
     40        (WebCore::ImageBuffer::drawConsuming):
     41        (WebCore::ImageBuffer::draw):
     42        * rendering/ImageQualityController.cpp:
     43        (WebCore::ImageQualityController::interpolationQualityFromStyle):
     44        (WebCore::ImageQualityController::chooseInterpolationQuality):
     45        (WebCore::ImageQualityController::ImageQualityController): Deleted.
     46        (WebCore::ImageQualityController::shouldPaintAtLowQuality): Deleted.
     47        * rendering/ImageQualityController.h:
     48        * rendering/RenderBoxModelObject.cpp:
     49        (WebCore::RenderBoxModelObject::chooseInterpolationQuality):
     50        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
     51        (WebCore::RenderBoxModelObject::shouldPaintAtLowQuality): Deleted.
     52        * rendering/RenderBoxModelObject.h:
     53        * rendering/RenderEmbeddedObject.cpp:
     54        (WebCore::RenderEmbeddedObject::paintSnapshotImage):
     55        * rendering/RenderHTMLCanvas.cpp:
     56        (WebCore::RenderHTMLCanvas::paintReplaced):
     57        * rendering/RenderImage.cpp:
     58        (WebCore::RenderImage::paintIntoRect):
     59        * rendering/RenderSnapshottedPlugIn.cpp:
     60        (WebCore::RenderSnapshottedPlugIn::paintSnapshot):
     61        * rendering/style/RenderStyle.h:
     62
    1632016-01-29  Brady Eidson  <beidson@apple.com>
    264
  • trunk/Source/WebCore/html/HTMLCanvasElement.cpp

    r195646 r195848  
    404404
    405405
    406 void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r, bool useLowQualityScale)
     406void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r)
    407407{
    408408    // Clear the dirty rect
     
    427427                orientationDescription.setImageOrientationEnum(renderer()->style().imageOrientation());
    428428#endif
    429                 context.drawImage(*m_presentedImage, snappedIntRect(r), ImagePaintingOptions(orientationDescription, useLowQualityScale));
     429                context.drawImage(*m_presentedImage, snappedIntRect(r), ImagePaintingOptions(orientationDescription));
    430430            } else
    431                 context.drawImageBuffer(*imageBuffer, snappedIntRect(r), useLowQualityScale);
     431                context.drawImageBuffer(*imageBuffer, snappedIntRect(r));
    432432        }
    433433    }
  • trunk/Source/WebCore/html/HTMLCanvasElement.h

    r195646 r195848  
    110110    void notifyObserversCanvasChanged(const FloatRect&);
    111111
    112     void paint(GraphicsContext&, const LayoutRect&, bool useLowQualityScale = false);
     112    void paint(GraphicsContext&, const LayoutRect&);
    113113
    114114    GraphicsContext* drawingContext() const;
  • trunk/Source/WebCore/page/DragController.cpp

    r194496 r195848  
    936936        return;
    937937
    938     ImageOrientationDescription orientationDescription(element.renderer()->shouldRespectImageOrientation());
    939 #if ENABLE(CSS_IMAGE_ORIENTATION)
    940     orientationDescription.setImageOrientationEnum(element.renderer()->style().imageOrientation());
    941 #endif
     938    ImageOrientationDescription orientationDescription(element.renderer()->shouldRespectImageOrientation(), element.renderer()->style().imageOrientation());
    942939
    943940    Image* image = getImage(element);
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r195415 r195848  
    7878};
    7979
    80 class InterpolationQualityMaintainer {
    81 public:
    82     explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, InterpolationQuality interpolationQualityToUse)
    83         : m_graphicsContext(graphicsContext)
    84         , m_currentInterpolationQuality(graphicsContext.imageInterpolationQuality())
    85         , m_interpolationQualityChanged(m_currentInterpolationQuality != interpolationQualityToUse)
    86     {
    87         if (m_interpolationQualityChanged)
    88             m_graphicsContext.setImageInterpolationQuality(interpolationQualityToUse);
    89     }
    90 
    91     ~InterpolationQualityMaintainer()
    92     {
    93         if (m_interpolationQualityChanged)
    94             m_graphicsContext.setImageInterpolationQuality(m_currentInterpolationQuality);
    95     }
    96 
    97 private:
    98     GraphicsContext& m_graphicsContext;
    99     InterpolationQuality m_currentInterpolationQuality;
    100     bool m_interpolationQualityChanged;
    101 };
    102 
    103 
    10480#define CHECK_FOR_CHANGED_PROPERTY(flag, property) \
    10581    if ((m_changeFlags & GraphicsContextState::flag) && (m_state.property != state.property)) \
     
    768744    }
    769745
    770     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_useLowQualityScale ? InterpolationLow : imageInterpolationQuality());
     746    InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
    771747    image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_orientationDescription);
    772748}
     
    782758    }
    783759
    784     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_useLowQualityScale ? InterpolationLow : imageInterpolationQuality());
     760    InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
    785761    image.drawTiled(*this, destination, source, tileSize, spacing, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
    786762}
     
    803779    }
    804780
    805     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_useLowQualityScale ? InterpolationLow : imageInterpolationQuality());
     781    InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
    806782    image.drawTiled(*this, destination, source, tileScaleFactor, hRule, vRule, imagePaintingOptions.m_compositeOperator);
    807783}
     
    822798        return;
    823799
    824     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_useLowQualityScale ? InterpolationLow : imageInterpolationQuality());
    825     image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_useLowQualityScale);
     800    InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
     801    image.draw(*this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
    826802}
    827803
     
    847823        return;
    848824   
    849     InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_useLowQualityScale ? InterpolationLow : imageInterpolationQuality());
    850 
    851     ImageBuffer::drawConsuming(WTFMove(image), *this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_useLowQualityScale);
     825    InterpolationQualityMaintainer interpolationQualityForThisScope(*this, imagePaintingOptions.m_interpolationQuality);
     826    ImageBuffer::drawConsuming(WTFMove(image), *this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode);
    852827}
    853828
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r195170 r195848  
    101101    DoubleStroke,
    102102    WavyStroke,
    103 };
    104 
    105 enum InterpolationQuality {
    106     InterpolationDefault,
    107     InterpolationNone,
    108     InterpolationLow,
    109     InterpolationMedium,
    110     InterpolationHigh
    111103};
    112104
     
    195187
    196188struct ImagePaintingOptions {
    197     ImagePaintingOptions(CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal, ImageOrientationDescription orientationDescription = ImageOrientationDescription(), bool useLowQualityScale = false)
     189    ImagePaintingOptions(CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal, ImageOrientationDescription orientationDescription = ImageOrientationDescription(), InterpolationQuality interpolationQuality = InterpolationDefault)
    198190        : m_compositeOperator(compositeOperator)
    199191        , m_blendMode(blendMode)
    200192        , m_orientationDescription(orientationDescription)
    201         , m_useLowQualityScale(useLowQualityScale)
    202     {
    203     }
    204 
    205     ImagePaintingOptions(ImageOrientationDescription orientationDescription, bool useLowQualityScale = false, CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal)
     193        , m_interpolationQuality(interpolationQuality)
     194    {
     195    }
     196
     197    ImagePaintingOptions(ImageOrientationDescription orientationDescription, InterpolationQuality interpolationQuality = InterpolationDefault, CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal)
    206198        : m_compositeOperator(compositeOperator)
    207199        , m_blendMode(blendMode)
    208200        , m_orientationDescription(orientationDescription)
    209         , m_useLowQualityScale(useLowQualityScale)
    210     {
    211     }
    212 
    213     ImagePaintingOptions(bool useLowQualityScale, ImageOrientationDescription orientationDescription = ImageOrientationDescription(), CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal)
     201        , m_interpolationQuality(interpolationQuality)
     202    {
     203    }
     204
     205    ImagePaintingOptions(InterpolationQuality interpolationQuality, ImageOrientationDescription orientationDescription = ImageOrientationDescription(), CompositeOperator compositeOperator = CompositeSourceOver, BlendMode blendMode = BlendModeNormal)
    214206        : m_compositeOperator(compositeOperator)
    215207        , m_blendMode(blendMode)
    216208        , m_orientationDescription(orientationDescription)
    217         , m_useLowQualityScale(useLowQualityScale)
    218     {
    219     }
     209        , m_interpolationQuality(interpolationQuality)
     210    {
     211    }
     212   
     213    bool usesDefaultInterpolation() const { return m_interpolationQuality == InterpolationDefault; }
    220214
    221215    CompositeOperator m_compositeOperator;
    222216    BlendMode m_blendMode;
    223217    ImageOrientationDescription m_orientationDescription;
    224     bool m_useLowQualityScale;
     218    InterpolationQuality m_interpolationQuality;
    225219};
    226220
     
    658652};
    659653
     654class InterpolationQualityMaintainer {
     655public:
     656    explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, InterpolationQuality interpolationQualityToUse)
     657        : m_graphicsContext(graphicsContext)
     658        , m_currentInterpolationQuality(graphicsContext.imageInterpolationQuality())
     659        , m_interpolationQualityChanged(interpolationQualityToUse != InterpolationDefault && m_currentInterpolationQuality != interpolationQualityToUse)
     660    {
     661        if (m_interpolationQualityChanged)
     662            m_graphicsContext.setImageInterpolationQuality(interpolationQualityToUse);
     663    }
     664
     665    explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, Optional<InterpolationQuality> interpolationQuality)
     666        : InterpolationQualityMaintainer(graphicsContext, interpolationQuality ? interpolationQuality.value() : graphicsContext.imageInterpolationQuality())
     667    {
     668    }
     669
     670    ~InterpolationQualityMaintainer()
     671    {
     672        if (m_interpolationQualityChanged)
     673            m_graphicsContext.setImageInterpolationQuality(m_currentInterpolationQuality);
     674    }
     675
     676private:
     677    GraphicsContext& m_graphicsContext;
     678    InterpolationQuality m_currentInterpolationQuality;
     679    bool m_interpolationQualityChanged;
     680};
     681
    660682} // namespace WebCore
    661683
  • trunk/Source/WebCore/platform/graphics/GraphicsTypes.h

    r191310 r195848  
    7676};
    7777
     78enum InterpolationQuality {
     79    InterpolationDefault,
     80    InterpolationNone,
     81    InterpolationLow,
     82    InterpolationMedium,
     83    InterpolationHigh
     84};
     85
    7886enum LineCap { ButtCap, RoundCap, SquareCap };
    7987
  • trunk/Source/WebCore/platform/graphics/ImageBuffer.h

    r194630 r195848  
    143143#endif
    144144   
    145     void draw(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal, bool useLowQualityScale = false);
     145    void draw(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal);
    146146    void drawPattern(GraphicsContext&, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, const FloatRect& destRect, BlendMode = BlendModeNormal);
    147147
    148     static void drawConsuming(std::unique_ptr<ImageBuffer>, GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal, bool useLowQualityScale = false);
     148    static void drawConsuming(std::unique_ptr<ImageBuffer>, GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, BlendMode = BlendModeNormal);
    149149
    150150    inline void genericConvertToLuminanceMask();
  • trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r194630 r195848  
    215215}
    216216
    217 void ImageBuffer::drawConsuming(std::unique_ptr<ImageBuffer> imageBuffer, GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, bool useLowQualityScale)
    218 {
    219     imageBuffer->draw(destContext, destRect, srcRect, op, blendMode, useLowQualityScale);
     217void ImageBuffer::drawConsuming(std::unique_ptr<ImageBuffer> imageBuffer, GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode)
     218{
     219    imageBuffer->draw(destContext, destRect, srcRect, op, blendMode);
    220220}
    221221
    222222void ImageBuffer::draw(GraphicsContext& destinationContext, const FloatRect& destRect, const FloatRect& srcRect,
    223     CompositeOperator op, BlendMode blendMode, bool useLowQualityScale)
     223    CompositeOperator op, BlendMode blendMode)
    224224{
    225225    BackingStoreCopy copyMode = &destinationContext == &context() ? CopyBackingStore : DontCopyBackingStore;
    226226    RefPtr<Image> image = copyImage(copyMode);
    227     destinationContext.drawImage(*image, destRect, srcRect, ImagePaintingOptions(op, blendMode, ImageOrientationDescription(), useLowQualityScale));
     227    destinationContext.drawImage(*image, destRect, srcRect, ImagePaintingOptions(op, blendMode, ImageOrientationDescription()));
    228228}
    229229
  • trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r195452 r195848  
    265265}
    266266
    267 void ImageBuffer::drawConsuming(std::unique_ptr<ImageBuffer> imageBuffer, GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, bool useLowQualityScale)
     267void ImageBuffer::drawConsuming(std::unique_ptr<ImageBuffer> imageBuffer, GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode)
    268268{
    269269#if USE(IOSURFACE_CANVAS_BACKING_STORE)
    270270    if (!imageBuffer->m_data.surface) {
    271         imageBuffer->draw(destContext, destRect, srcRect, op, blendMode, useLowQualityScale);
     271        imageBuffer->draw(destContext, destRect, srcRect, op, blendMode);
    272272        return;
    273273    }
     
    284284    destContext.drawNativeImage(image.get(), backingStoreSize, destRect, adjustedSrcRect, op, blendMode);
    285285#else
    286     imageBuffer->draw(destContext, destRect, srcRect, op, blendMode, useLowQualityScale);
    287 #endif
    288 }
    289 
    290 void ImageBuffer::draw(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, bool)
     286    imageBuffer->draw(destContext, destRect, srcRect, op, blendMode);
     287#endif
     288}
     289
     290void ImageBuffer::draw(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode)
    291291{
    292292    RetainPtr<CGImageRef> image;
  • trunk/Source/WebCore/rendering/ImageQualityController.cpp

    r195699 r195848  
    4141    : m_renderView(renderView)
    4242    , m_timer(*this, &ImageQualityController::highQualityRepaintTimerFired)
    43     , m_animatedResizeIsActive(false)
    44     , m_liveResizeOptimizationIsActive(false)
    4543{
    4644}
     
    10098}
    10199
    102 bool ImageQualityController::shouldPaintAtLowQuality(GraphicsContext& context, RenderBoxModelObject* object, Image& image, const void *layer, const LayoutSize& size)
     100Optional<InterpolationQuality> ImageQualityController::interpolationQualityFromStyle(const RenderStyle& style)
    103101{
    104     // If the image is not a bitmap image, then none of this is relevant and we just paint at high
    105     // quality.
    106     if (!(image.isBitmapImage() || image.isPDFDocumentImage()) || context.paintingDisabled())
    107         return false;
    108 
    109     switch (object->style().imageRendering()) {
     102    switch (style.imageRendering()) {
    110103    case ImageRenderingOptimizeSpeed:
     104        return InterpolationLow;
    111105    case ImageRenderingCrispEdges:
    112106    case ImageRenderingPixelated:
    113         return true;
     107        return InterpolationNone;
    114108    case ImageRenderingOptimizeQuality:
    115         return false; // FIXME: CSS 3 Images says that optimizeQuality should behave like 'auto', but that prevents authors from overriding this low quality rendering behavior.
     109        return InterpolationDefault; // FIXME: CSS 3 Images says that optimizeQuality should behave like 'auto', but that prevents authors from overriding this low quality rendering behavior.
    116110    case ImageRenderingAuto:
    117111        break;
    118112    }
     113    return Nullopt;
     114}
     115
     116InterpolationQuality ImageQualityController::chooseInterpolationQuality(GraphicsContext& context, RenderBoxModelObject* object, Image& image, const void *layer, const LayoutSize& size)
     117{
     118    // If the image is not a bitmap image, then none of this is relevant and we just paint at high quality.
     119    if (!(image.isBitmapImage() || image.isPDFDocumentImage()) || context.paintingDisabled())
     120        return InterpolationDefault;
     121
     122    if (Optional<InterpolationQuality> styleInterpolation = interpolationQualityFromStyle(object->style()))
     123        return styleInterpolation.value();
    119124
    120125    // Make sure to use the unzoomed image size, since if a full page zoom is in effect, the image
     
    142147            restartTimer();
    143148            m_liveResizeOptimizationIsActive = true;
    144             return true;
     149            return InterpolationLow;
    145150        }
    146151        if (m_liveResizeOptimizationIsActive)
    147             return false;
     152            return InterpolationDefault;
    148153    }
    149154
     
    153158        // There is no scale in effect. If we had a scale in effect before, we can just remove this object from the list.
    154159        removeLayer(object, innerMap, layer);
    155         return false;
     160        return InterpolationDefault;
    156161    }
    157162
     
    160165        double totalPixels = static_cast<double>(image.width()) * static_cast<double>(image.height());
    161166        if (totalPixels > cInterpolationCutoff)
    162             return true;
     167            return InterpolationLow;
    163168    }
    164169
     
    167172        set(object, innerMap, layer, size);
    168173        restartTimer();
    169         return true;
     174        return InterpolationLow;
    170175    }
    171176    // If this is the first time resizing this image, or its size is the
     
    175180        restartTimer();
    176181        set(object, innerMap, layer, size);
    177         return false;
     182        return InterpolationDefault;
    178183    }
    179184    // If the timer is no longer active, draw at high quality and don't
     
    181186    if (!m_timer.isActive()) {
    182187        removeLayer(object, innerMap, layer);
    183         return false;
     188        return InterpolationDefault;
    184189    }
    185190    // This object has been resized to two different sizes while the timer
     
    189194    m_animatedResizeIsActive = true;
    190195    restartTimer();
    191     return true;
     196    return InterpolationLow;
    192197}
    193198
  • trunk/Source/WebCore/rendering/ImageQualityController.h

    r191049 r195848  
    2727#define ImageQualityController_h
    2828
     29#include "GraphicsTypes.h"
    2930#include "Timer.h"
    3031#include <wtf/HashMap.h>
     32#include <wtf/Optional.h>
    3133
    3234namespace WebCore {
    3335
    34 class Frame;
    3536class GraphicsContext;
    3637class Image;
     
    3839class RenderBoxModelObject;
    3940class RenderView;
     41class RenderStyle;
    4042
    4143class ImageQualityController {
     
    4446    explicit ImageQualityController(const RenderView&);
    4547
    46     bool shouldPaintAtLowQuality(GraphicsContext&, RenderBoxModelObject*, Image&, const void* layer, const LayoutSize&);
     48    static Optional<InterpolationQuality> interpolationQualityFromStyle(const RenderStyle&);
     49    InterpolationQuality chooseInterpolationQuality(GraphicsContext&, RenderBoxModelObject*, Image&, const void* layer, const LayoutSize&);
     50
    4751    void rendererWillBeDestroyed(RenderBoxModelObject& renderer) { removeObject(&renderer); }
    4852
     
    6064    ObjectLayerSizeMap m_objectLayerSizeMap;
    6165    Timer m_timer;
    62     bool m_animatedResizeIsActive;
    63     bool m_liveResizeOptimizationIsActive;
     66    bool m_animatedResizeIsActive { false };
     67    bool m_liveResizeOptimizationIsActive { false };
    6468};
    6569
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r195170 r195848  
    160160    ASSERT(isComposited());
    161161    layer()->backing()->suspendAnimations(time);
    162 }
    163 
    164 bool RenderBoxModelObject::shouldPaintAtLowQuality(GraphicsContext& context, Image& image, const void* layer, const LayoutSize& size)
    165 {
    166     return view().imageQualityController().shouldPaintAtLowQuality(context, this, image, layer, size);
    167162}
    168163
     
    595590}
    596591
     592InterpolationQuality RenderBoxModelObject::chooseInterpolationQuality(GraphicsContext& context, Image& image, const void* layer, const LayoutSize& size)
     593{
     594    return view().imageQualityController().chooseInterpolationQuality(context, this, image, layer, size);
     595}
     596
    597597void RenderBoxModelObject::paintMaskForTextFillBox(ImageBuffer* maskImage, const IntRect& maskRect, InlineFlowBox* box, const LayoutRect& scrolledPaintRect)
    598598{
     
    835835            CompositeOperator compositeOp = op == CompositeSourceOver ? bgLayer->composite() : op;
    836836            context.setDrawLuminanceMask(bgLayer->maskSourceType() == MaskLuminance);
    837             bool useLowQualityScaling = shouldPaintAtLowQuality(context, *image, bgLayer, geometry.tileSize());
    838             context.drawTiledImage(*image, geometry.destRect(), toLayoutPoint(geometry.relativePhase()), geometry.tileSize(), geometry.spaceSize(), ImagePaintingOptions(compositeOp, bgLayer->blendMode(), ImageOrientationDescription(), useLowQualityScaling));
     837
     838            InterpolationQuality interpolation = chooseInterpolationQuality(context, *image, bgLayer, geometry.tileSize());
     839            context.drawTiledImage(*image, geometry.destRect(), toLayoutPoint(geometry.relativePhase()), geometry.tileSize(), geometry.spaceSize(), ImagePaintingOptions(compositeOp, bgLayer->blendMode(), ImageOrientationDescription(), interpolation));
    839840        }
    840841    }
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.h

    r194417 r195848  
    252252    LayoutRect borderInnerRectAdjustedForBleedAvoidance(const GraphicsContext&, const LayoutRect&, BackgroundBleedAvoidance) const;
    253253
    254     bool shouldPaintAtLowQuality(GraphicsContext&, Image&, const void*, const LayoutSize&);
     254    InterpolationQuality chooseInterpolationQuality(GraphicsContext&, Image&, const void*, const LayoutSize&);
    255255
    256256    RenderBoxModelObject* continuation() const;
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp

    r194496 r195848  
    215215        return;
    216216
    217     bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, &image, alignedRect.size());
    218     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
    219 #if ENABLE(CSS_IMAGE_ORIENTATION)
    220     orientationDescription.setImageOrientationEnum(style().imageOrientation());
    221 #endif
    222     context.drawImage(image, alignedRect, ImagePaintingOptions(orientationDescription, useLowQualityScaling));
     217    InterpolationQuality interpolation = chooseInterpolationQuality(context, image, &image, alignedRect.size());
     218    ImageOrientationDescription orientationDescription(shouldRespectImageOrientation(), style().imageOrientation());
     219    context.drawImage(image, alignedRect, ImagePaintingOptions(orientationDescription, interpolation));
    223220}
    224221
  • trunk/Source/WebCore/rendering/RenderHTMLCanvas.cpp

    r195699 r195848  
    3434#include "HTMLCanvasElement.h"
    3535#include "HTMLNames.h"
     36#include "ImageQualityController.h"
    3637#include "Page.h"
    3738#include "PaintInfo.h"
     
    8586    }
    8687
    87     bool useLowQualityScale = style().imageRendering() == ImageRenderingCrispEdges || style().imageRendering() == ImageRenderingPixelated || style().imageRendering() == ImageRenderingOptimizeSpeed;
    88     canvasElement().paint(context, replacedContentRect, useLowQualityScale);
     88    InterpolationQualityMaintainer interpolationMaintainer(context, ImageQualityController::interpolationQualityFromStyle(style()));
     89    canvasElement().paint(context, replacedContentRect);
    8990}
    9091
  • trunk/Source/WebCore/rendering/RenderImage.cpp

    r194496 r195848  
    548548    HTMLImageElement* imageElement = is<HTMLImageElement>(element()) ? downcast<HTMLImageElement>(element()) : nullptr;
    549549    CompositeOperator compositeOperator = imageElement ? imageElement->compositeOperator() : CompositeSourceOver;
     550
     551    // FIXME: Document when image != img.get().
    550552    Image* image = imageResource().image().get();
    551     bool useLowQualityScaling = image && shouldPaintAtLowQuality(context, *image, image, LayoutSize(rect.size()));
    552     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
    553 #if ENABLE(CSS_IMAGE_ORIENTATION)
    554     orientationDescription.setImageOrientationEnum(style().imageOrientation());
    555 #endif
    556     context.drawImage(*img, rect,
    557         ImagePaintingOptions(compositeOperator, BlendModeNormal, orientationDescription, useLowQualityScaling));
     553    InterpolationQuality interpolation = image ? chooseInterpolationQuality(context, *image, image, LayoutSize(rect.size())) : InterpolationDefault;
     554
     555    ImageOrientationDescription orientationDescription(shouldRespectImageOrientation(), style().imageOrientation());
     556    context.drawImage(*img, rect, ImagePaintingOptions(compositeOperator, BlendModeNormal, orientationDescription, interpolation));
    558557}
    559558
  • trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp

    r194496 r195848  
    136136        return;
    137137
    138     bool useLowQualityScaling = shouldPaintAtLowQuality(context, *image, image, alignedRect.size());
    139 
    140     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
    141 #if ENABLE(CSS_IMAGE_ORIENTATION)
    142     orientationDescription.setImageOrientationEnum(style().imageOrientation());
    143 #endif
    144     context.drawImage(*image, alignedRect, ImagePaintingOptions(orientationDescription, useLowQualityScaling));
     138    InterpolationQuality interpolation = chooseInterpolationQuality(context, *image, image, alignedRect.size());
     139    ImageOrientationDescription orientationDescription(shouldRespectImageOrientation(), style().imageOrientation());
     140    context.drawImage(*image, alignedRect, ImagePaintingOptions(orientationDescription, interpolation));
    145141}
    146142
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r195577 r195848  
    11641164    bool isFlippedBlocksWritingMode() const { return WebCore::isFlippedWritingMode(writingMode()); }
    11651165
     1166    ImageOrientationEnum imageOrientation() const
     1167    {
    11661168#if ENABLE(CSS_IMAGE_ORIENTATION)
    1167     ImageOrientationEnum imageOrientation() const { return static_cast<ImageOrientationEnum>(rareInheritedData->m_imageOrientation); }
    1168 #endif
     1169        return static_cast<ImageOrientationEnum>(rareInheritedData->m_imageOrientation);
     1170#else
     1171        return DefaultImageOrientation;
     1172#endif
     1173    }
    11691174
    11701175    EImageRendering imageRendering() const { return static_cast<EImageRendering>(rareInheritedData->m_imageRendering); }
Note: See TracChangeset for help on using the changeset viewer.