Changeset 190383 in webkit


Ignore:
Timestamp:
Sep 30, 2015 8:17:26 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore:
Add support for the imageSmoothingQuality property for CanvasRenderingContext2D.
https://bugs.webkit.org/show_bug.cgi?id=149541

Patch by Katlyn Graff <kgraff@apple.com> on 2015-09-30
Reviewed by Ryosuke Niwa.

As documented here: https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing
Exposes the smooothing quality of algorithms used for scaling images. Valid input
values are low, medium, and high: associated algorithms are expected to vary for
differing hardware. setImageSmoothingQuality provides a handle into CGInterpolationQuality.

Test: fast/canvas/canvas-imageSmoothingQuality.html

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::State::State):
(WebCore::CanvasRenderingContext2D::State::operator=):
(WebCore::smoothingToInterpolationQuality):
(WebCore::CanvasRenderingContext2D::imageSmoothingQuality):
(WebCore::CanvasRenderingContext2D::setImageSmoothingQuality):
(WebCore::CanvasRenderingContext2D::setImageSmoothingEnabled):

  • html/canvas/CanvasRenderingContext2D.h:
  • html/canvas/CanvasRenderingContext2D.idl:

LayoutTests:
Tests support for imageSmoothingQuality attribute of Canvas element.
https://bugs.webkit.org/show_bug.cgi?id=149541

Patch by Katlyn Graff <kgraff@apple.com> on 2015-09-30
Reviewed by Ryosuke Niwa.

Tests low, medium, high, and default values, value persistence when
imageSmoothingEnabled is changed, and invalid input.

  • fast/canvas/canvas-imageSmoothingQuality-expected.txt: Added.
  • fast/canvas/canvas-imageSmoothingQuality.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190379 r190383  
     12015-09-30  Katlyn Graff  <kgraff@apple.com>
     2
     3        Tests support for imageSmoothingQuality attribute of Canvas element.
     4        https://bugs.webkit.org/show_bug.cgi?id=149541
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Tests low, medium, high, and default values, value persistence when
     9        imageSmoothingEnabled is changed, and invalid input.
     10
     11        * fast/canvas/canvas-imageSmoothingQuality-expected.txt: Added.
     12        * fast/canvas/canvas-imageSmoothingQuality.html: Added.
     13
    1142015-09-30  Brady Eidson  <beidson@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r190382 r190383  
     12015-09-30  Katlyn Graff  <kgraff@apple.com>
     2
     3        Add support for the imageSmoothingQuality property for CanvasRenderingContext2D.
     4        https://bugs.webkit.org/show_bug.cgi?id=149541
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        As documented here: https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing
     9        Exposes the smooothing quality of algorithms used for scaling images. Valid input
     10        values are low, medium, and high: associated algorithms are expected to vary for
     11        differing hardware. setImageSmoothingQuality provides a handle into CGInterpolationQuality.
     12
     13        Test: fast/canvas/canvas-imageSmoothingQuality.html
     14
     15        * html/canvas/CanvasRenderingContext2D.cpp:
     16        (WebCore::CanvasRenderingContext2D::State::State):
     17        (WebCore::CanvasRenderingContext2D::State::operator=):
     18        (WebCore::smoothingToInterpolationQuality):
     19        (WebCore::CanvasRenderingContext2D::imageSmoothingQuality):
     20        (WebCore::CanvasRenderingContext2D::setImageSmoothingQuality):
     21        (WebCore::CanvasRenderingContext2D::setImageSmoothingEnabled):
     22        * html/canvas/CanvasRenderingContext2D.h:
     23        * html/canvas/CanvasRenderingContext2D.idl:
     24
    1252015-09-30  Dean Jackson  <dino@apple.com>
    226
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r190274 r190383  
    4343#include "ExceptionCodePlaceholder.h"
    4444#include "FloatQuad.h"
    45 #include "GraphicsContext.h"
    4645#include "HTMLImageElement.h"
    4746#include "HTMLVideoElement.h"
     
    174173    , lineDashOffset(0)
    175174    , imageSmoothingEnabled(true)
     175    , imageSmoothingQuality(SmoothingQuality::Low)
    176176    , textAlign(StartTextAlign)
    177177    , textBaseline(AlphabeticTextBaseline)
     
    200200    , lineDashOffset(other.lineDashOffset)
    201201    , imageSmoothingEnabled(other.imageSmoothingEnabled)
     202    , imageSmoothingQuality(other.imageSmoothingQuality)
    202203    , textAlign(other.textAlign)
    203204    , textBaseline(other.textBaseline)
     
    230231    hasInvertibleTransform = other.hasInvertibleTransform;
    231232    imageSmoothingEnabled = other.imageSmoothingEnabled;
     233    imageSmoothingQuality = other.imageSmoothingQuality;
    232234    textAlign = other.textAlign;
    233235    textBaseline = other.textBaseline;
     
    25402542#endif
    25412543
     2544static InterpolationQuality smoothingToInterpolationQuality(CanvasRenderingContext2D::SmoothingQuality quality)
     2545{
     2546    switch (quality) {
     2547    case CanvasRenderingContext2D::SmoothingQuality::Low:
     2548        return InterpolationLow;
     2549    case CanvasRenderingContext2D::SmoothingQuality::Medium:
     2550        return InterpolationMedium;
     2551    case CanvasRenderingContext2D::SmoothingQuality::High:
     2552        return InterpolationHigh;
     2553    }
     2554
     2555    ASSERT_NOT_REACHED();
     2556    return InterpolationLow;
     2557};
     2558
     2559String CanvasRenderingContext2D::imageSmoothingQuality() const
     2560{
     2561    switch (state().imageSmoothingQuality) {
     2562    case SmoothingQuality::Low:
     2563        return ASCIILiteral("low");
     2564    case SmoothingQuality::Medium:
     2565        return ASCIILiteral("medium");
     2566    case SmoothingQuality::High:
     2567        return ASCIILiteral("high");
     2568    }
     2569
     2570    ASSERT_NOT_REACHED();
     2571    return ASCIILiteral("low");
     2572}
     2573
     2574void CanvasRenderingContext2D::setImageSmoothingQuality(const String& smoothingQualityString)
     2575{
     2576    SmoothingQuality quality;
     2577    if (smoothingQualityString == "low")
     2578        quality = SmoothingQuality::Low;
     2579    else if (smoothingQualityString == "medium")
     2580        quality = SmoothingQuality::Medium;
     2581    else if (smoothingQualityString == "high")
     2582        quality = SmoothingQuality::High;
     2583    else {
     2584        ASSERT_NOT_REACHED();
     2585        return;
     2586    }
     2587
     2588    if (quality == state().imageSmoothingQuality)
     2589        return;
     2590
     2591    realizeSaves();
     2592    modifiableState().imageSmoothingQuality = quality;
     2593
     2594    if (!modifiableState().imageSmoothingEnabled)
     2595        return;
     2596
     2597    if (auto* context = drawingContext())
     2598        context->setImageInterpolationQuality(smoothingToInterpolationQuality(quality));
     2599}
     2600
    25422601bool CanvasRenderingContext2D::imageSmoothingEnabled() const
    25432602{
     
    25542613    GraphicsContext* c = drawingContext();
    25552614    if (c)
    2556         c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone);
     2615        c->setImageInterpolationQuality(enabled ? smoothingToInterpolationQuality(state().imageSmoothingQuality) : InterpolationNone);
    25572616}
    25582617
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r189830 r190383  
    3535#include "FloatSize.h"
    3636#include "FontCascade.h"
     37#include "GraphicsContext.h"
    3738#include "GraphicsTypes.h"
    3839#include "ImageBuffer.h"
     
    228229    bool imageSmoothingEnabled() const;
    229230    void setImageSmoothingEnabled(bool);
     231
     232    String imageSmoothingQuality() const;
     233    void setImageSmoothingQuality(const String&);
     234
     235    enum class SmoothingQuality {
     236        Low,
     237        Medium,
     238        High
     239    };
    230240
    231241private:
     
    282292        float lineDashOffset;
    283293        bool imageSmoothingEnabled;
     294        SmoothingQuality imageSmoothingQuality;
    284295
    285296        // Text state.
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r190021 r190383  
    2424 */
    2525
     26enum ImageSmoothingQuality { "low", "medium", "high" };
    2627enum CanvasWindingRule { "nonzero", "evenodd" };
    2728
     
    189190    attribute boolean imageSmoothingEnabled;
    190191    [ImplementedAs=imageSmoothingEnabled] attribute boolean webkitImageSmoothingEnabled;
     192    attribute ImageSmoothingQuality imageSmoothingQuality;
    191193};
    192194
Note: See TracChangeset for help on using the changeset viewer.