Changeset 264280 in webkit


Ignore:
Timestamp:
Jul 12, 2020, 10:28:02 AM (5 years ago)
Author:
Darin Adler
Message:

Simplify and improve Gradient, some other small color-related removals
https://bugs.webkit.org/show_bug.cgi?id=214221

Reviewed by Sam Weinig.

  • css/CSSGradientValue.cpp: Removed some unneeded includes.
  • html/ColorInputType.cpp:

(WebCore::ColorInputType::currentColor): Deleted.
(WebCore::ColorInputType::shouldShowSuggestions const): Deleted.

  • html/ColorInputType.h: Updated for the above.
  • html/HTMLDocument.cpp: Removed unneeded include of HashTools.h.
  • html/canvas/CanvasGradient.cpp:

(WebCore::CanvasGradient::create): Moved these functions out of the
header since inlining should be the same or better with them here.
(WebCore::CanvasGradient::~CanvasGradient): Moved this out of the
header so we don't need to include Gradient.h in the header.
(WebCore::CanvasGradient::addColorStop): Updated for change to
Gradient::addColorStop and move Color rather than copying it.

  • html/canvas/CanvasGradient.h: Removed include of Gradient.h.

Moved things out of the header to make that work.

  • inspector/InspectorCanvas.cpp:

(WebCore::InspectorCanvas::buildArrayForCanvasGradient): Removed
use of Gradient::type and instead unify the type string code with
the code that interprets the data for the different types.

  • page/FrameView.cpp:

(WebCore::FrameView::recalculateScrollbarOverlayStyle): Refactored
to eliminate the multiple redundant code paths, otherwising leaving
the logic unchanged.

  • platform/ColorChooserClient.h: Remove unneeded includes and unused

currentColor and shouldShowSuggestions functions.

  • platform/graphics/Gradient.cpp:

(WebCore::Gradient::create): Replaced create functions that take
type-specific data structure with one that takes the variant Data.
(WebCore::Gradient::Gradient): Ditto. Also removed platformInit.
(WebCore::Gradient::~Gradient): Removed platformDestroy.
(WebCore::Gradient::type const): Deleted.
(WebCore::Gradient::addColorStop): Take an rvalue reference to cut down
a little bit on reference count churn. Replaced the platformDestroy
function with a new stopsChanged function. Removed an unneeded overload
that takes the two parts of a ColorStop separately.
(WebCore::Gradient::setSortedColorStops): Use stopsChanged.
(WebCore::Gradient::sortStops const): Simplify a bit, using a lambda.
Also gave this a shorter name; it still optimizes by not sorting if
the vector is already sorted.
(WebCore::Gradient::hasAlpha const): Deleted.
(WebCore::Gradient::setSpreadMethod): Removed some slightly overzealous
code checking this isn't used after creating the platform-specific gradient.
Decided not to bother with this for now.
(WebCore::Gradient::setGradientSpaceTransform): Tweaked formatting.
(WebCore::add): Added overloads to add(Hasher&) so we can use computeHash.
(WebCore::Gradient::hash const): Use computeHash instead of hashMemory.

  • platform/graphics/Gradient.h: Use RetainPtr, COMPtr, and RefPtr instead

of manually managing the lifetimes of the platform-specific underlying
gradient objects. Also removed the unhelpful PlatformGradient type. This
pattern, all too common in our platform library, provides no useful
abstraction here. Removed unneeded constructors from ColorStop.
Updated for changes above. Added platform-specific functions createBrush,
createPattern, and createCGGradient. Simplify encoding and decoding by
taking advantage of the support for encoding/decoding variants.
Remove the enum Gradient::Type entirely. Removed the invalidateHash
function because it's only used in a few setters and setting the hash
to 0 is a fine way to write it there.

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContextState::GraphicsContextState): Moved here from
the header so we don't need to include Gradient.h in the header.
(WebCore::GraphicsContextState::~GraphicsContextState): Ditto.
(WebCore::GraphicsContextState::operator=): Ditto.

  • platform/graphics/GraphicsContext.h: Removed include of Gradient.h.

Moved things out of the header to make that work.

  • platform/graphics/cairo/CairoOperations.cpp:

(WebCore::Cairo::FillSource::FillSource): Use createPattern instead of
createPlatformGradient.
(WebCore::Cairo::StrokeSource::StrokeSource): Ditto.

  • platform/graphics/cairo/GradientCairo.cpp:

(WebCore::Gradient::stopsChanged): Renamed from platformDestroy.
(WebCore::interpolateColorStop): Rewrote to use existing blend functions.
(WebCore::createConic): Changed return type to RefPtr. Tweaked to match
WebKit coding style a bit better, use auto, use Vector::first/last, and
updated for removal of the Gradient::ColorStop constructor.
(WebCore::Gradient::createPattern): Renamed from createPlatformGradient.
Changed to return a RefPtr instead of a raw pointer the caller needs to
adopt at each call site. Refactored so it no longer uses Gradient::type.
(WebCore::Gradient::fill): Use createPattern.

  • platform/graphics/cairo/GraphicsContextImplCairo.cpp:

(WebCore::GraphicsContextImplCairo::fillRect): Ditto.

  • platform/graphics/cg/GradientCG.cpp:

(WebCore::Gradient::stopsChanged): Renamed from platformDestroy, and
simplified implementation now that we use RetainPtr.
(WebCore::Gradient::createCGGradient): Renamed from platformGradient,
got rid of the return value, and made it caller responsibility to only
call this when a gradeitn needs to be allocated.
(WebCore::Gradient::paint): Updated to use the above.

  • platform/graphics/cg/GraphicsContextCG.cpp: Add include of Gradient.h.
  • platform/graphics/displaylists/DisplayListItems.h:

Added include of Gradient.h since the function templates in this file
encode and decode gradients.

  • platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:

(Nicosia::CairoOperationRecorder::fillRect): Use createPattern.

  • platform/graphics/win/Direct2DOperations.cpp:

(WebCore::Direct2D::FillSource::FillSource): Use createBrush
(WebCore::Direct2D::StrokeSource::StrokeSource): Ditto.

  • platform/graphics/win/GradientDirect2D.cpp:

(WebCore::Gradient::stopsChanged): Renamed from platformDestroy and
simplified implementation now that we use COMPtr.
(WebCore::Gradient::platformGradient): Deleted.
(WebCore::Gradient::createPlatformGradientIfNecessary): Deleted.
(WebCore::Gradient::createBrush): Renamed from generateGradient and
added a return value. Simplified now that we use COMPtr, optimized
the code a bit, and added some FIXME about mistakes I noticed.
(WebCore::Gradient::fill): Use createBrush and m_brush.

  • platform/graphics/win/GraphicsContextImplDirect2D.cpp:

(WebCore::GraphicsContextImplDirect2D::fillRect): Use createBrush.

  • platform/mac/ScrollAnimatorMac.mm: Added include of Gradient.h.
  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::paintProgressBar): Updated for changes to
addColorStop. Also remove a lot of unnecessary conversion from float
to double and back to float.

  • rendering/svg/RenderSVGResourceGradient.cpp:

(WebCore::RenderSVGResourceGradient::addStops): Update to make
and move a new color stop instead of copying it, modifying it in
place, and then copying it again.

  • rendering/svg/RenderSVGResourceGradient.cpp: Removed include of

Gradient.h.

  • svg/SVGGradientElement.cpp:

(WebCore::SVGGradientElement::buildStops): Use std::clamp to convert
the offsets into monotonically increasing ones in a more direct way,
using variable names instead of comments to clarify what we are doing.

Location:
trunk/Source/WebCore
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r264279 r264280  
     12020-07-12  Darin Adler  <[email protected]>
     2
     3        Simplify and improve Gradient, some other small color-related removals
     4        https://bugs.webkit.org/show_bug.cgi?id=214221
     5
     6        Reviewed by Sam Weinig.
     7
     8        * css/CSSGradientValue.cpp: Removed some unneeded includes.
     9
     10        * html/ColorInputType.cpp:
     11        (WebCore::ColorInputType::currentColor): Deleted.
     12        (WebCore::ColorInputType::shouldShowSuggestions const): Deleted.
     13        * html/ColorInputType.h: Updated for the above.
     14
     15        * html/HTMLDocument.cpp: Removed unneeded include of HashTools.h.
     16
     17        * html/canvas/CanvasGradient.cpp:
     18        (WebCore::CanvasGradient::create): Moved these functions out of the
     19        header since inlining should be the same or better with them here.
     20        (WebCore::CanvasGradient::~CanvasGradient): Moved this out of the
     21        header so we don't need to include Gradient.h in the header.
     22        (WebCore::CanvasGradient::addColorStop): Updated for change to
     23        Gradient::addColorStop and move Color rather than copying it.
     24
     25        * html/canvas/CanvasGradient.h: Removed include of Gradient.h.
     26        Moved things out of the header to make that work.
     27
     28        * inspector/InspectorCanvas.cpp:
     29        (WebCore::InspectorCanvas::buildArrayForCanvasGradient): Removed
     30        use of Gradient::type and instead unify the type string code with
     31        the code that interprets the data for the different types.
     32
     33        * page/FrameView.cpp:
     34        (WebCore::FrameView::recalculateScrollbarOverlayStyle): Refactored
     35        to eliminate the multiple redundant code paths, otherwising leaving
     36        the logic unchanged.
     37
     38        * platform/ColorChooserClient.h: Remove unneeded includes and unused
     39        currentColor and shouldShowSuggestions functions.
     40
     41        * platform/graphics/Gradient.cpp:
     42        (WebCore::Gradient::create): Replaced create functions that take
     43        type-specific data structure with one that takes the variant Data.
     44        (WebCore::Gradient::Gradient): Ditto. Also removed platformInit.
     45        (WebCore::Gradient::~Gradient): Removed platformDestroy.
     46        (WebCore::Gradient::type const): Deleted.
     47        (WebCore::Gradient::addColorStop): Take an rvalue reference to cut down
     48        a little bit on reference count churn. Replaced the platformDestroy
     49        function with a new stopsChanged function. Removed an unneeded overload
     50        that takes the two parts of a ColorStop separately.
     51        (WebCore::Gradient::setSortedColorStops): Use stopsChanged.
     52        (WebCore::Gradient::sortStops const): Simplify a bit, using a lambda.
     53        Also gave this a shorter name; it still optimizes by not sorting if
     54        the vector is already sorted.
     55        (WebCore::Gradient::hasAlpha const): Deleted.
     56        (WebCore::Gradient::setSpreadMethod): Removed some slightly overzealous
     57        code checking this isn't used after creating the platform-specific gradient.
     58        Decided not to bother with this for now.
     59        (WebCore::Gradient::setGradientSpaceTransform): Tweaked formatting.
     60        (WebCore::add): Added overloads to add(Hasher&) so we can use computeHash.
     61        (WebCore::Gradient::hash const): Use computeHash instead of hashMemory.
     62
     63        * platform/graphics/Gradient.h: Use RetainPtr, COMPtr, and RefPtr instead
     64        of manually managing the lifetimes of the platform-specific underlying
     65        gradient objects. Also removed the unhelpful PlatformGradient type. This
     66        pattern, all too common in our platform library, provides no useful
     67        abstraction here. Removed unneeded constructors from ColorStop.
     68        Updated for changes above. Added platform-specific functions createBrush,
     69        createPattern, and createCGGradient. Simplify encoding and decoding by
     70        taking advantage of the support for encoding/decoding variants.
     71        Remove the enum Gradient::Type entirely. Removed the invalidateHash
     72        function because it's only used in a few setters and setting the hash
     73        to 0 is a fine way to write it there.
     74
     75        * platform/graphics/GraphicsContext.cpp:
     76        (WebCore::GraphicsContextState::GraphicsContextState): Moved here from
     77        the header so we don't need to include Gradient.h in the header.
     78        (WebCore::GraphicsContextState::~GraphicsContextState): Ditto.
     79        (WebCore::GraphicsContextState::operator=): Ditto.
     80
     81        * platform/graphics/GraphicsContext.h: Removed include of Gradient.h.
     82        Moved things out of the header to make that work.
     83
     84        * platform/graphics/cairo/CairoOperations.cpp:
     85        (WebCore::Cairo::FillSource::FillSource): Use createPattern instead of
     86        createPlatformGradient.
     87        (WebCore::Cairo::StrokeSource::StrokeSource): Ditto.
     88
     89        * platform/graphics/cairo/GradientCairo.cpp:
     90        (WebCore::Gradient::stopsChanged): Renamed from platformDestroy.
     91        (WebCore::interpolateColorStop): Rewrote to use existing blend functions.
     92        (WebCore::createConic): Changed return type to RefPtr. Tweaked to match
     93        WebKit coding style a bit better, use auto, use Vector::first/last, and
     94        updated for removal of the Gradient::ColorStop constructor.
     95        (WebCore::Gradient::createPattern): Renamed from createPlatformGradient.
     96        Changed to return a RefPtr instead of a raw pointer the caller needs to
     97        adopt at each call site. Refactored so it no longer uses Gradient::type.
     98        (WebCore::Gradient::fill): Use createPattern.
     99        * platform/graphics/cairo/GraphicsContextImplCairo.cpp:
     100        (WebCore::GraphicsContextImplCairo::fillRect): Ditto.
     101
     102        * platform/graphics/cg/GradientCG.cpp:
     103        (WebCore::Gradient::stopsChanged): Renamed from platformDestroy, and
     104        simplified implementation now that we use RetainPtr.
     105        (WebCore::Gradient::createCGGradient): Renamed from platformGradient,
     106        got rid of the return value, and made it caller responsibility to only
     107        call this when a gradeitn needs to be allocated.
     108        (WebCore::Gradient::paint): Updated to use the above.
     109
     110        * platform/graphics/cg/GraphicsContextCG.cpp: Add include of Gradient.h.
     111
     112        * platform/graphics/displaylists/DisplayListItems.h:
     113        Added include of Gradient.h since the function templates in this file
     114        encode and decode gradients.
     115
     116        * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:
     117        (Nicosia::CairoOperationRecorder::fillRect): Use createPattern.
     118
     119        * platform/graphics/win/Direct2DOperations.cpp:
     120        (WebCore::Direct2D::FillSource::FillSource): Use createBrush
     121        (WebCore::Direct2D::StrokeSource::StrokeSource): Ditto.
     122
     123        * platform/graphics/win/GradientDirect2D.cpp:
     124        (WebCore::Gradient::stopsChanged): Renamed from platformDestroy and
     125        simplified implementation now that we use COMPtr.
     126        (WebCore::Gradient::platformGradient): Deleted.
     127        (WebCore::Gradient::createPlatformGradientIfNecessary): Deleted.
     128        (WebCore::Gradient::createBrush): Renamed from generateGradient and
     129        added a return value. Simplified now that we use COMPtr, optimized
     130        the code a bit, and added some FIXME about mistakes I noticed.
     131        (WebCore::Gradient::fill): Use createBrush and m_brush.
     132        * platform/graphics/win/GraphicsContextImplDirect2D.cpp:
     133        (WebCore::GraphicsContextImplDirect2D::fillRect): Use createBrush.
     134
     135        * platform/mac/ScrollAnimatorMac.mm: Added include of Gradient.h.
     136
     137        * rendering/RenderThemeIOS.mm:
     138        (WebCore::RenderThemeIOS::paintProgressBar): Updated for changes to
     139        addColorStop. Also remove a lot of unnecessary conversion from float
     140        to double and back to float.
     141
     142        * rendering/svg/RenderSVGResourceGradient.cpp:
     143        (WebCore::RenderSVGResourceGradient::addStops): Update to make
     144        and move a new color stop instead of copying it, modifying it in
     145        place, and then copying it again.
     146        * rendering/svg/RenderSVGResourceGradient.cpp: Removed include of
     147        Gradient.h.
     148
     149        * svg/SVGGradientElement.cpp:
     150        (WebCore::SVGGradientElement::buildStops): Use std::clamp to convert
     151        the offsets into monotonically increasing ones in a more direct way,
     152        using variable names instead of comments to clarify what we are doing.
     153
    11542020-07-12  Yusuke Suzuki  <[email protected]>
    2155
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r263776 r264280  
    3131#include "CSSValueKeywords.h"
    3232#include "ColorBlending.h"
    33 #include "FloatSize.h"
    34 #include "Gradient.h"
    3533#include "GradientImage.h"
    3634#include "NodeRenderStyle.h"
  • trunk/Source/WebCore/html/ColorInputType.cpp

    r264136 r264280  
    271271}
    272272
    273 Color ColorInputType::currentColor()
    274 {
    275     return valueAsColor();
    276 }
    277 
    278 bool ColorInputType::shouldShowSuggestions() const
    279 {
    280 #if ENABLE(DATALIST_ELEMENT)
    281     ASSERT(element());
    282     return element()->hasAttributeWithoutSynchronization(listAttr);
    283 #else
    284     return false;
    285 #endif
    286 }
    287 
    288273Vector<Color> ColorInputType::suggestedColors() const
    289274{
  • trunk/Source/WebCore/html/ColorInputType.h

    r246490 r264280  
    4949    void didEndChooser() final;
    5050    IntRect elementRectRelativeToRootView() const final;
    51     Color currentColor() final;
    52     bool shouldShowSuggestions() const final;
    5351    Vector<Color> suggestedColors() const final;
    5452    bool isMouseFocusable() const final;
  • trunk/Source/WebCore/html/HTMLDocument.cpp

    r262683 r264280  
    7575#include "HTMLIFrameElement.h"
    7676#include "HTMLNames.h"
    77 #include "HashTools.h"
    7877#include "ScriptController.h"
    7978#include "StyleResolver.h"
  • trunk/Source/WebCore/html/canvas/CanvasGradient.cpp

    r252856 r264280  
    3030#include "CanvasBase.h"
    3131#include "CanvasStyle.h"
     32#include "Gradient.h"
    3233
    3334namespace WebCore {
     
    4546}
    4647
     48Ref<CanvasGradient> CanvasGradient::create(const FloatPoint& p0, const FloatPoint& p1, CanvasBase& canvasBase)
     49{
     50    return adoptRef(*new CanvasGradient(p0, p1, canvasBase));
     51}
     52
     53Ref<CanvasGradient> CanvasGradient::create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, CanvasBase& canvasBase)
     54{
     55    return adoptRef(*new CanvasGradient(p0, r0, p1, r1, canvasBase));
     56}
     57
     58CanvasGradient::~CanvasGradient() = default;
     59
    4760ExceptionOr<void> CanvasGradient::addColorStop(float value, const String& colorString)
    4861{
     
    5568        return Exception { SyntaxError };
    5669
    57     m_gradient->addColorStop(value, color);
     70    m_gradient->addColorStop({ value, WTFMove(color) });
    5871    return { };
    5972}
  • trunk/Source/WebCore/html/canvas/CanvasGradient.h

    r252856 r264280  
    2828
    2929#include "ExceptionOr.h"
    30 #include "Gradient.h"
     30#include "FloatPoint.h"
    3131
    3232namespace WebCore {
    3333
    3434class CanvasBase;
     35class Gradient;
    3536
    3637class CanvasGradient : public RefCounted<CanvasGradient> {
    3738public:
    38     static Ref<CanvasGradient> create(const FloatPoint& p0, const FloatPoint& p1, CanvasBase& canvasBase)
    39     {
    40         return adoptRef(*new CanvasGradient(p0, p1, canvasBase));
    41     }
    42     static Ref<CanvasGradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, CanvasBase& canvasBase)
    43     {
    44         return adoptRef(*new CanvasGradient(p0, r0, p1, r1, canvasBase));
    45     }
     39    static Ref<CanvasGradient> create(const FloatPoint& p0, const FloatPoint& p1, CanvasBase&);
     40    static Ref<CanvasGradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, CanvasBase&);
     41    ~CanvasGradient();
    4642
    4743    Gradient& gradient() { return m_gradient; }
     
    5652    Ref<Gradient> m_gradient;
    5753    CanvasBase& m_canvas;
    58 
    5954};
    6055
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r259845 r264280  
    3737#include "CSSParser.h"
    3838#include "CSSPropertyNames.h"
     39#include "Gradient.h"
    3940#include "ImageBuffer.h"
    4041#include "ImageData.h"
  • trunk/Source/WebCore/inspector/InspectorCanvas.cpp

    r263788 r264280  
    11591159Ref<JSON::ArrayOf<JSON::Value>> InspectorCanvas::buildArrayForCanvasGradient(const CanvasGradient& canvasGradient)
    11601160{
    1161     const auto& gradient = canvasGradient.gradient();
    1162    
    1163     String type = gradient.type() == Gradient::Type::Radial ? "radial-gradient"_s : gradient.type() == Gradient::Type::Linear ? "linear-gradient"_s : "conic-gradient"_s;
    1164 
     1161    ASCIILiteral type = "linear-gradient"_s;
    11651162    auto parameters = JSON::ArrayOf<float>::create();
    1166     WTF::switchOn(gradient.data(),
    1167         [&parameters] (const Gradient::LinearData& data) {
     1163    WTF::switchOn(canvasGradient.gradient().data(),
     1164        [&] (const Gradient::LinearData& data) {
    11681165            parameters->addItem(data.point0.x());
    11691166            parameters->addItem(data.point0.y());
     
    11711168            parameters->addItem(data.point1.y());
    11721169        },
    1173         [&parameters] (const Gradient::RadialData& data) {
     1170        [&] (const Gradient::RadialData& data) {
     1171            type = "radial-gradient"_s;
    11741172            parameters->addItem(data.point0.x());
    11751173            parameters->addItem(data.point0.y());
     
    11791177            parameters->addItem(data.endRadius);
    11801178        },
    1181         [&parameters] (const Gradient::ConicData& data) {
     1179        [&] (const Gradient::ConicData& data) {
     1180            type = "conic-gradient"_s;
    11821181            parameters->addItem(data.point0.x());
    11831182            parameters->addItem(data.point0.y());
     
    11871186
    11881187    auto stops = JSON::ArrayOf<JSON::Value>::create();
    1189     for (auto& colorStop : gradient.stops()) {
     1188    for (auto& colorStop : canvasGradient.gradient().stops()) {
    11901189        auto stop = JSON::ArrayOf<JSON::Value>::create();
    11911190        stop->addItem(colorStop.offset);
  • trunk/Source/WebCore/page/FrameView.cpp

    r264203 r264280  
    351351void FrameView::recalculateScrollbarOverlayStyle()
    352352{
    353     ScrollbarOverlayStyle oldOverlayStyle = scrollbarOverlayStyle();
    354     Optional<ScrollbarOverlayStyle> clientOverlayStyle = frame().page() ? frame().page()->chrome().client().preferredScrollbarOverlayStyle() : WTF::nullopt;
    355     if (clientOverlayStyle) {
    356         if (clientOverlayStyle.value() != oldOverlayStyle)
    357             setScrollbarOverlayStyle(clientOverlayStyle.value());
    358         return;
    359     }
    360 
    361     ScrollbarOverlayStyle computedOverlayStyle = ScrollbarOverlayStyleDefault;
    362 
    363     Color backgroundColor = documentBackgroundColor();
    364     if (backgroundColor.isValid()) {
    365         // Reduce the background color from RGB to a lightness value
    366         // and determine which scrollbar style to use based on a lightness
    367         // heuristic.
    368         if (backgroundColor.lightness() <= .5f && backgroundColor.isVisible())
    369             computedOverlayStyle = ScrollbarOverlayStyleLight;
    370         else if (!backgroundColor.isVisible() && useDarkAppearance())
    371             computedOverlayStyle = ScrollbarOverlayStyleLight;
    372     }
    373 
    374     if (oldOverlayStyle != computedOverlayStyle)
    375         setScrollbarOverlayStyle(computedOverlayStyle);
     353    auto style = [this] {
     354        if (auto page = frame().page()) {
     355            if (auto clientStyle = page->chrome().client().preferredScrollbarOverlayStyle())
     356                return *clientStyle;
     357        }
     358        auto background = documentBackgroundColor();
     359        if (background.isVisible()) {
     360            if (background.lightness() <= .5f)
     361                return ScrollbarOverlayStyleLight;
     362        } else {
     363            if (useDarkAppearance())
     364                return ScrollbarOverlayStyleLight;
     365        }
     366        return ScrollbarOverlayStyleDefault;
     367    }();
     368    if (scrollbarOverlayStyle() != style)
     369        setScrollbarOverlayStyle(style);
    376370}
    377371
    378372#if ENABLE(DARK_MODE_CSS)
     373
    379374void FrameView::recalculateBaseBackgroundColor()
    380375{
     
    389384    updateBackgroundRecursively(backgroundColor);
    390385}
     386
    391387#endif
    392388
  • trunk/Source/WebCore/platform/ColorChooserClient.h

    r235004 r264280  
    2828 */
    2929
    30 #ifndef ColorChooserClient_h
    31 #define ColorChooserClient_h
     30#pragma once
    3231
    3332#if ENABLE(INPUT_TYPE_COLOR)
    3433
    35 #include "IntRect.h"
    36 #include <wtf/Vector.h>
     34#include <wtf/Forward.h>
    3735
    3836namespace WebCore {
    3937
    4038class Color;
     39class IntRect;
    4140
    4241class ColorChooserClient {
     
    4746    virtual void didEndChooser() = 0;
    4847    virtual IntRect elementRectRelativeToRootView() const = 0;
    49     virtual Color currentColor() = 0;
    50     virtual bool shouldShowSuggestions() const = 0;
    5148    virtual Vector<Color> suggestedColors() const = 0;
    5249};
     
    5552
    5653#endif // ENABLE(INPUT_TYPE_COLOR)
    57 
    58 #endif // ColorChooserClient_h
  • trunk/Source/WebCore/platform/graphics/Gradient.cpp

    r235877 r264280  
    3737namespace WebCore {
    3838
    39 Ref<Gradient> Gradient::create(LinearData&& data)
     39Ref<Gradient> Gradient::create(Data&& data)
    4040{
    4141    return adoptRef(*new Gradient(WTFMove(data)));
    4242}
    4343
    44 Ref<Gradient> Gradient::create(RadialData&& data)
     44Gradient::Gradient(Data&& data)
     45    : m_data(WTFMove(data))
    4546{
    46     return adoptRef(*new Gradient(WTFMove(data)));
    4747}
    4848
    49 Ref<Gradient> Gradient::create(ConicData&& data)
    50 {
    51     return adoptRef(*new Gradient(WTFMove(data)));
    52 }
    53 
    54 Gradient::Gradient(LinearData&& data)
    55     : m_data(WTFMove(data))
    56 {
    57     platformInit();
    58 }
    59 
    60 Gradient::Gradient(RadialData&& data)
    61     : m_data(WTFMove(data))
    62 {
    63     platformInit();
    64 }
    65    
    66 Gradient::Gradient(ConicData&& data)
    67     : m_data(WTFMove(data))
    68 {
    69     platformInit();
    70 }
    71 
    72 Gradient::~Gradient()
    73 {
    74     platformDestroy();
    75 }
    76 
    77 auto Gradient::type() const -> Type
    78 {
    79     return WTF::switchOn(m_data,
    80         [] (const LinearData&) {
    81             return Type::Linear;
    82         },
    83         [] (const RadialData&) {
    84             return Type::Radial;
    85         },
    86         [] (const ConicData&) {
    87             return Type::Conic;
    88         }
    89     );
    90 }
     49Gradient::~Gradient() = default;
    9150
    9251void Gradient::adjustParametersForTiledDrawing(FloatSize& size, FloatRect& srcRect, const FloatSize& spacing)
     
    13594}
    13695
    137 void Gradient::addColorStop(float offset, const Color& color)
     96void Gradient::addColorStop(Gradient::ColorStop&& stop)
    13897{
    139     addColorStop({ offset, color });
    140 }
    141 
    142 void Gradient::addColorStop(const Gradient::ColorStop& stop)
    143 {
    144     m_stops.append(stop);
    145 
     98    m_stops.append(WTFMove(stop));
    14699    m_stopsSorted = false;
    147 
    148     platformDestroy();
    149     invalidateHash();
     100    m_cachedHash = 0;
     101    stopsChanged();
    150102}
    151103
     
    153105{
    154106    m_stops = WTFMove(stops);
    155 
    156107    m_stopsSorted = true;
    157 
    158     platformDestroy();
    159     invalidateHash();
     108    m_cachedHash = 0;
     109    stopsChanged();
    160110}
    161111
    162 static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::ColorStop& b)
    163 {
    164     return a.offset < b.offset;
    165 }
    166 
    167 void Gradient::sortStopsIfNecessary()
     112void Gradient::sortStops() const
    168113{
    169114    if (m_stopsSorted)
    170115        return;
    171 
    172116    m_stopsSorted = true;
    173 
    174     if (!m_stops.size())
    175         return;
    176 
    177     std::stable_sort(m_stops.begin(), m_stops.end(), compareStops);
    178     invalidateHash();
    179 }
    180 
    181 bool Gradient::hasAlpha() const
    182 {
    183     for (const auto& stop : m_stops) {
    184         if (!stop.color.isOpaque())
    185             return true;
    186     }
    187 
    188     return false;
     117    std::stable_sort(m_stops.begin(), m_stops.end(), [] (auto& a, auto& b) {
     118        return a.offset < b.offset;
     119    });
    189120}
    190121
    191122void Gradient::setSpreadMethod(GradientSpreadMethod spreadMethod)
    192123{
    193     // FIXME: Should it become necessary, allow calls to this method after m_gradient has been set.
    194     ASSERT(m_gradient == 0);
    195 
    196124    if (m_spreadMethod == spreadMethod)
    197125        return;
    198 
    199126    m_spreadMethod = spreadMethod;
    200 
    201     invalidateHash();
     127    m_cachedHash = 0;
    202128}
    203129
     
    206132    if (m_gradientSpaceTransformation == gradientSpaceTransformation)
    207133        return;
     134    m_gradientSpaceTransformation = gradientSpaceTransformation;
     135    m_cachedHash = 0;
     136}
    208137
    209     m_gradientSpaceTransformation = gradientSpaceTransformation;
     138// FIXME: Instead of these add(Hasher) functions, consider using encode functions to compute the hash.
    210139
    211     invalidateHash();
     140static void add(Hasher& hasher, const Color& color)
     141{
     142    // FIXME: We don't want to hash a hash; do better.
     143    add(hasher, color.hash());
     144}
     145
     146static void add(Hasher& hasher, const FloatPoint& point)
     147{
     148    add(hasher, point.x(), point.y());
     149}
     150
     151static void add(Hasher& hasher, const AffineTransform& transform)
     152{
     153    add(hasher, transform.a(), transform.b(), transform.c(), transform.d(), transform.e(), transform.f());
     154}
     155
     156static void add(Hasher& hasher, const Gradient::ColorStop& stop)
     157{
     158    add(hasher, stop.offset, stop.color);
     159}
     160
     161static void add(Hasher& hasher, const Gradient::LinearData& data)
     162{
     163    add(hasher, data.point0, data.point1);
     164}
     165
     166static void add(Hasher& hasher, const Gradient::RadialData& data)
     167{
     168    add(hasher, data.point0, data.point1, data.startRadius, data.endRadius, data.aspectRatio);
     169}
     170
     171static void add(Hasher& hasher, const Gradient::ConicData& data)
     172{
     173    add(hasher, data.point0, data.angleRadians);
    212174}
    213175
    214176unsigned Gradient::hash() const
    215177{
    216     if (m_cachedHash)
    217         return m_cachedHash;
    218 
    219     struct {
    220         Type type;
    221         FloatPoint point0;
    222         FloatPoint point1;
    223         float startRadius;
    224         float endRadius;
    225         float aspectRatio;
    226         float angleRadians;
    227         GradientSpreadMethod spreadMethod;
    228         AffineTransform gradientSpaceTransformation;
    229     } parameters;
    230 
    231     // StringHasher requires that the memory it hashes be a multiple of two in size.
    232     COMPILE_ASSERT(!(sizeof(parameters) % 2), Gradient_parameters_size_should_be_multiple_of_two);
    233     COMPILE_ASSERT(!(sizeof(ColorStop) % 2), Color_stop_size_should_be_multiple_of_two);
    234    
    235     // Ensure that any padding in the struct is zero-filled, so it will not affect the hash value.
    236     // FIXME: This is asking for trouble, because it is a nontrivial type.
    237     memset(static_cast<void*>(&parameters), 0, sizeof(parameters));
    238    
    239     WTF::switchOn(m_data,
    240         [&parameters] (const LinearData& data) {
    241             parameters.point0 = data.point0;
    242             parameters.point1 = data.point1;
    243             parameters.startRadius = 0;
    244             parameters.endRadius = 0;
    245             parameters.aspectRatio = 0;
    246             parameters.angleRadians = 0;
    247             parameters.type = Type::Linear;
    248         },
    249         [&parameters] (const RadialData& data) {
    250             parameters.point0 = data.point0;
    251             parameters.point1 = data.point1;
    252             parameters.startRadius = data.startRadius;
    253             parameters.endRadius = data.endRadius;
    254             parameters.aspectRatio = data.aspectRatio;
    255             parameters.angleRadians = 0;
    256             parameters.type = Type::Radial;
    257         },
    258         [&parameters] (const ConicData& data) {
    259             parameters.point0 = data.point0;
    260             parameters.point1 = {0, 0};
    261             parameters.startRadius = 0;
    262             parameters.endRadius = 0;
    263             parameters.aspectRatio = 0;
    264             parameters.angleRadians = data.angleRadians;
    265             parameters.type = Type::Conic;
    266         }
    267     );
    268 
    269     parameters.spreadMethod = m_spreadMethod;
    270     parameters.gradientSpaceTransformation = m_gradientSpaceTransformation;
    271 
    272     unsigned parametersHash = StringHasher::hashMemory(&parameters, sizeof(parameters));
    273     unsigned stopHash = StringHasher::hashMemory(m_stops.data(), m_stops.size() * sizeof(ColorStop));
    274 
    275     m_cachedHash = pairIntHash(parametersHash, stopHash);
    276 
     178    if (!m_cachedHash) {
     179        sortStops();
     180        m_cachedHash = computeHash(m_data, m_spreadMethod, m_gradientSpaceTransformation, m_stops);
     181    }
    277182    return m_cachedHash;
    278183}
  • trunk/Source/WebCore/platform/graphics/Gradient.h

    r262684 r264280  
    3232#include "FloatPoint.h"
    3333#include "GraphicsTypes.h"
    34 #include <wtf/EnumTraits.h>
    35 #include <wtf/RefCounted.h>
    3634#include <wtf/Variant.h>
    3735#include <wtf/Vector.h>
    3836
    3937#if USE(CG)
     38#include <wtf/RetainPtr.h>
     39#endif
     40
     41#if USE(DIRECT2D)
     42#include "COMPtr.h"
     43#endif
     44
     45#if USE(CG)
    4046typedef struct CGContext* CGContextRef;
    4147typedef struct CGGradient* CGGradientRef;
    42 typedef CGGradientRef PlatformGradient;
    43 #elif USE(DIRECT2D)
     48#endif
     49
     50#if USE(DIRECT2D)
    4451interface ID2D1Brush;
    4552interface ID2D1RenderTarget;
    46 typedef ID2D1Brush* PlatformGradient;
    47 #elif USE(CAIRO)
     53#endif
     54
     55#if USE(CAIRO)
    4856typedef struct _cairo_pattern cairo_pattern_t;
    49 typedef cairo_pattern_t* PlatformGradient;
    50 #else
    51 typedef void* PlatformGradient;
    5257#endif
    5358
    5459namespace WebCore {
    5560
    56 class Color;
    5761class FloatRect;
    5862class GraphicsContext;
     
    6064class Gradient : public RefCounted<Gradient> {
    6165public:
    62     // FIXME: ExtendedColor - A color stop needs a notion of color space.
    6366    struct ColorStop {
    6467        float offset { 0 };
    6568        Color color;
    6669
    67         ColorStop() = default;
    68         ColorStop(float offset, const Color& color)
    69             : offset(offset)
    70             , color(color)
    71         {
    72         }
    73 
    74         template<class Encoder> void encode(Encoder&) const;
    75         template<class Decoder> static Optional<ColorStop> decode(Decoder&);
     70        template<typename Encoder> void encode(Encoder&) const;
     71        template<typename Decoder> static Optional<ColorStop> decode(Decoder&);
    7672    };
    7773
     
    8278        FloatPoint point1;
    8379
    84         template<class Encoder> void encode(Encoder&) const;
    85         template<class Decoder> static Optional<LinearData> decode(Decoder&);
     80        template<typename Encoder> void encode(Encoder&) const;
     81        template<typename Decoder> static Optional<LinearData> decode(Decoder&);
    8682    };
    8783
     
    9389        float aspectRatio; // For elliptical gradient, width / height.
    9490
    95         template<class Encoder> void encode(Encoder&) const;
    96         template<class Decoder> static Optional<RadialData> decode(Decoder&);
     91        template<typename Encoder> void encode(Encoder&) const;
     92        template<typename Decoder> static Optional<RadialData> decode(Decoder&);
    9793    };
    98    
     94
    9995    struct ConicData {
    10096        FloatPoint point0;
    10197        float angleRadians;
    10298
    103         template<class Encoder> void encode(Encoder&) const;
    104         template<class Decoder> static Optional<ConicData> decode(Decoder&);
     99        template<typename Encoder> void encode(Encoder&) const;
     100        template<typename Decoder> static Optional<ConicData> decode(Decoder&);
    105101    };
    106102
    107103    using Data = Variant<LinearData, RadialData, ConicData>;
    108104
    109     enum class Type { Linear, Radial, Conic };
    110 
    111     WEBCORE_EXPORT static Ref<Gradient> create(LinearData&&);
    112     WEBCORE_EXPORT static Ref<Gradient> create(RadialData&&);
    113     WEBCORE_EXPORT static Ref<Gradient> create(ConicData&&);
     105    WEBCORE_EXPORT static Ref<Gradient> create(Data&&);
    114106
    115107    WEBCORE_EXPORT ~Gradient();
    116108
    117     WEBCORE_EXPORT Type type() const;
    118 
    119     bool hasAlpha() const;
    120109    bool isZeroSize() const;
    121110
    122111    const Data& data() const { return m_data; }
    123112
    124     WEBCORE_EXPORT void addColorStop(const ColorStop&);
    125     WEBCORE_EXPORT void addColorStop(float, const Color&);
     113    WEBCORE_EXPORT void addColorStop(ColorStop&&);
    126114    WEBCORE_EXPORT void setSortedColorStops(ColorStopVector&&);
    127115
     
    131119    GradientSpreadMethod spreadMethod() const { return m_spreadMethod; }
    132120
    133     // CG needs to transform the gradient at draw time.
    134121    WEBCORE_EXPORT void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
    135122    const AffineTransform& gradientSpaceTransform() const { return m_gradientSpaceTransformation; }
     
    139126
    140127    unsigned hash() const;
    141     void invalidateHash() { m_cachedHash = 0; }
     128
     129#if USE(CAIRO)
     130    RefPtr<cairo_pattern_t> createPattern(float globalAlpha);
     131#endif
    142132
    143133#if USE(CG)
    144134    void paint(GraphicsContext&);
    145135    void paint(CGContextRef);
    146 #elif USE(DIRECT2D)
    147     PlatformGradient createPlatformGradientIfNecessary(ID2D1RenderTarget*);
    148 #elif USE(CAIRO)
    149     PlatformGradient createPlatformGradient(float globalAlpha);
    150 #endif
    151 
    152     template<class Encoder> void encode(Encoder&) const;
    153     template<class Decoder> static Optional<Ref<Gradient>> decode(Decoder&);
     136#endif
     137
     138#if USE(DIRECT2D)
     139    ID2D1Brush* createBrush(ID2D1RenderTarget*);
     140#endif
     141
     142    template<typename Encoder> void encode(Encoder&) const;
     143    template<typename Decoder> static Optional<Ref<Gradient>> decode(Decoder&);
    154144
    155145private:
    156     Gradient(LinearData&&);
    157     Gradient(RadialData&&);
    158     Gradient(ConicData&&);
    159 
    160     PlatformGradient platformGradient();
    161     void platformInit() { m_gradient = nullptr; }
    162     void platformDestroy();
    163 
    164     void sortStopsIfNecessary();
    165 
    166 #if USE(DIRECT2D)
    167     void generateGradient(ID2D1RenderTarget*);
     146    explicit Gradient(Data&&);
     147
     148    void sortStops() const;
     149    void stopsChanged();
     150
     151#if USE(CG)
     152    void createCGGradient();
    168153#endif
    169154
    170155    Data m_data;
    171 
    172156    mutable ColorStopVector m_stops;
    173157    mutable bool m_stopsSorted { false };
    174158    GradientSpreadMethod m_spreadMethod { GradientSpreadMethod::Pad };
     159    mutable unsigned m_cachedHash { 0 };
    175160    AffineTransform m_gradientSpaceTransformation;
    176161
    177     mutable unsigned m_cachedHash { 0 };
    178 
    179     PlatformGradient m_gradient;
     162#if USE(CG)
     163    RetainPtr<CGGradientRef> m_gradient;
     164#endif
     165
     166#if USE(DIRECT2D)
     167    COMPtr<ID2D1Brush> m_brush;
     168#endif
    180169};
    181170
    182 template<class Encoder>
    183 void Gradient::ColorStop::encode(Encoder& encoder) const
     171template<typename Encoder> void Gradient::ColorStop::encode(Encoder& encoder) const
    184172{
    185173    encoder << offset;
     
    187175}
    188176
    189 template<class Decoder>
    190 Optional<Gradient::ColorStop> Gradient::ColorStop::decode(Decoder& decoder)
     177template<typename Decoder> Optional<Gradient::ColorStop> Gradient::ColorStop::decode(Decoder& decoder)
    191178{
    192179    Optional<float> offset;
     
    203190}
    204191
    205 template<class Encoder>
    206 void Gradient::LinearData::encode(Encoder& encoder) const
     192template<typename Encoder> void Gradient::LinearData::encode(Encoder& encoder) const
    207193{
    208194    encoder << point0;
     
    210196}
    211197
    212 template<class Decoder>
    213 Optional<Gradient::LinearData> Gradient::LinearData::decode(Decoder& decoder)
     198template<typename Decoder> Optional<Gradient::LinearData> Gradient::LinearData::decode(Decoder& decoder)
    214199{
    215200    Optional<FloatPoint> point0;
     
    226211}
    227212
    228 template<class Encoder>
    229 void Gradient::RadialData::encode(Encoder& encoder) const
     213template<typename Encoder> void Gradient::RadialData::encode(Encoder& encoder) const
    230214{
    231215    encoder << point0;
     
    236220}
    237221
    238 template<class Decoder>
    239 Optional<Gradient::RadialData> Gradient::RadialData::decode(Decoder& decoder)
     222template<typename Decoder> Optional<Gradient::RadialData> Gradient::RadialData::decode(Decoder& decoder)
    240223{
    241224    Optional<FloatPoint> point0;
     
    267250}
    268251
    269 template<class Encoder>
    270 void Gradient::ConicData::encode(Encoder& encoder) const
     252template<typename Encoder> void Gradient::ConicData::encode(Encoder& encoder) const
    271253{
    272254    encoder << point0;
     
    274256}
    275257
    276 template<class Decoder>
    277 Optional<Gradient::ConicData> Gradient::ConicData::decode(Decoder& decoder)
     258template<typename Decoder> Optional<Gradient::ConicData> Gradient::ConicData::decode(Decoder& decoder)
    278259{
    279260    Optional<FloatPoint> point0;
     
    290271}
    291272
    292 template<class Encoder>
    293 void Gradient::encode(Encoder& encoder) const
    294 {
    295     auto type = this->type();
    296     encoder << type;
    297     switch (type) {
    298     case Type::Linear:
    299         encoder << WTF::get<Gradient::LinearData>(m_data);
    300         break;
    301     case Type::Radial:
    302         encoder << WTF::get<Gradient::RadialData>(m_data);
    303         break;
    304     case Type::Conic:
    305         encoder << WTF::get<Gradient::ConicData>(m_data);
    306         break;
    307     }
     273template<typename Encoder> void Gradient::encode(Encoder& encoder) const
     274{
     275    encoder << m_data;
    308276    encoder << m_stops;
    309277    encoder << m_stopsSorted;
     
    312280}
    313281
    314 template<class Decoder>
    315 Optional<Ref<Gradient>> Gradient::decode(Decoder& decoder)
    316 {
    317     Optional<Gradient::Type> type;
    318     decoder >> type;
    319     if (!type)
    320         return WTF::nullopt;
    321 
    322     RefPtr<Gradient> gradient;
    323     switch (*type) {
    324     case Type::Linear: {
    325         Optional<LinearData> linearData;
    326         decoder >> linearData;
    327         if (!linearData)
    328             return WTF::nullopt;
    329 
    330         gradient = Gradient::create(WTFMove(*linearData));
    331         break;
    332     }
    333     case Type::Radial: {
    334         Optional<RadialData> radialData;
    335         decoder >> radialData;
    336         if (!radialData)
    337             return WTF::nullopt;
    338 
    339         gradient = Gradient::create(WTFMove(*radialData));
    340         break;
    341     }
    342     case Type::Conic: {
    343         Optional<ConicData> conicData;
    344         decoder >> conicData;
    345         if (!conicData)
    346             return WTF::nullopt;
    347 
    348         gradient = Gradient::create(WTFMove(*conicData));
    349         break;
    350     }
    351     }
    352 
    353     if (!gradient) {
    354         ASSERT_NOT_REACHED();
    355         return WTF::nullopt;
    356     }
     282template<typename Decoder> Optional<Ref<Gradient>> Gradient::decode(Decoder& decoder)
     283{
     284    Optional<Data> data;
     285    decoder >> data;
     286    if (!data)
     287        return WTF::nullopt;
     288    auto gradient = Gradient::create(WTFMove(*data));
    357289
    358290    Optional<ColorStopVector> stops;
     
    360292    if (!stops)
    361293        return WTF::nullopt;
    362 
    363294    Optional<bool> stopsSorted;
    364295    decoder >> stopsSorted;
    365296    if (!stopsSorted.hasValue())
    366297        return WTF::nullopt;
    367 
    368     if (stopsSorted.value())
     298    if (*stopsSorted)
    369299        gradient->setSortedColorStops(WTFMove(*stops));
    370300    else {
    371301        for (auto& stop : *stops)
    372             gradient->addColorStop(stop);
     302            gradient->addColorStop(WTFMove(stop));
    373303    }
    374304
     
    376306    if (!decoder.decode(spreadMethod))
    377307        return WTF::nullopt;
    378 
    379308    gradient->setSpreadMethod(spreadMethod);
    380309
     
    383312    if (!gradientSpaceTransformation)
    384313        return WTF::nullopt;
    385 
    386314    gradient->setGradientSpaceTransform(WTFMove(*gradientSpaceTransformation));
    387     return gradient.releaseNonNull();
     315
     316    return WTFMove(gradient);
    388317}
    389318
    390319} // namespace WebCore
    391 
    392 namespace WTF {
    393 
    394 template<> struct EnumTraits<WebCore::Gradient::Type> {
    395     using values = EnumValues<
    396     WebCore::Gradient::Type,
    397     WebCore::Gradient::Type::Linear,
    398     WebCore::Gradient::Type::Radial,
    399     WebCore::Gradient::Type::Conic
    400     >;
    401 };
    402 
    403 } // namespace WTF
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r261162 r264280  
    7676        changeFlags.add(GraphicsContextState::flag);
    7777
     78GraphicsContextState::GraphicsContextState()
     79    : shouldAntialias(true)
     80    , shouldSmoothFonts(true)
     81    , shouldSubpixelQuantizeFonts(true)
     82    , shadowsIgnoreTransforms(false)
     83#if USE(CG)
     84    // Core Graphics incorrectly renders shadows with radius > 8px (<rdar://problem/8103442>),
     85    // but we need to preserve this buggy behavior for canvas and -webkit-box-shadow.
     86    , shadowsUseLegacyRadius(false)
     87#endif
     88    , drawLuminanceMask(false)
     89{
     90}
     91
     92GraphicsContextState::~GraphicsContextState() = default;
     93GraphicsContextState::GraphicsContextState(const GraphicsContextState&) = default;
     94GraphicsContextState::GraphicsContextState(GraphicsContextState&&) = default;
     95GraphicsContextState& GraphicsContextState::operator=(const GraphicsContextState&) = default;
     96GraphicsContextState& GraphicsContextState::operator=(GraphicsContextState&&) = default;
     97
    7898GraphicsContextState::StateChangeFlags GraphicsContextStateChange::changesFromState(const GraphicsContextState& state) const
    7999{
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r263208 r264280  
    3030#include "FloatRect.h"
    3131#include "FontCascade.h"
    32 #include "Gradient.h"
    3332#include "GraphicsTypes.h"
    3433#include "Image.h"
     
    9998class TransformationMatrix;
    10099
     100namespace DisplayList {
     101class Recorder;
     102}
     103
    101104enum class TextDrawingMode : uint8_t {
    102105    Fill = 1 << 0,
     
    154157}
    155158
    156 namespace DisplayList {
    157 class Recorder;
    158 }
    159 
    160159struct GraphicsContextState {
    161     GraphicsContextState()
    162         : shouldAntialias(true)
    163         , shouldSmoothFonts(true)
    164         , shouldSubpixelQuantizeFonts(true)
    165         , shadowsIgnoreTransforms(false)
    166 #if USE(CG)
    167         // Core Graphics incorrectly renders shadows with radius > 8px (<rdar://problem/8103442>),
    168         // but we need to preserve this buggy behavior for canvas and -webkit-box-shadow.
    169         , shadowsUseLegacyRadius(false)
    170 #endif
    171         , drawLuminanceMask(false)
    172     {
    173     }
     160    WEBCORE_EXPORT GraphicsContextState();
     161    WEBCORE_EXPORT ~GraphicsContextState();
     162
     163    GraphicsContextState(const GraphicsContextState&);
     164    GraphicsContextState(GraphicsContextState&&);
     165
     166    GraphicsContextState& operator=(const GraphicsContextState&);
     167    GraphicsContextState& operator=(GraphicsContextState&&);
    174168
    175169    enum Change : uint32_t {
     
    198192#endif
    199193    };
    200     typedef OptionSet<Change> StateChangeFlags;
     194    using StateChangeFlags = OptionSet<Change>;
    201195
    202196    RefPtr<Gradient> strokeGradient;
     
    309303
    310304    void setStrokeGradient(Ref<Gradient>&&);
    311     RefPtr<Gradient> strokeGradient() const { return m_state.strokeGradient; }
     305    Gradient* strokeGradient() const { return m_state.strokeGradient.get(); }
    312306
    313307    void setFillRule(WindRule);
     
    321315
    322316    WEBCORE_EXPORT void setFillGradient(Ref<Gradient>&&);
    323     RefPtr<Gradient> fillGradient() const { return m_state.fillGradient; }
     317    Gradient* fillGradient() const { return m_state.fillGradient.get(); }
    324318
    325319    void setShadowsIgnoreTransforms(bool);
  • trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp

    r263471 r264280  
    4141#include "FloatConversion.h"
    4242#include "FloatRect.h"
     43#include "Gradient.h"
    4344#include "GraphicsContext.h"
    4445#include "GraphicsContextPlatformPrivateCairo.h"
     
    569570        pattern.repeatY = state.fillPattern->repeatY();
    570571    } else if (state.fillGradient) {
    571         gradient.base = adoptRef(state.fillGradient->createPlatformGradient(1));
     572        gradient.base = state.fillGradient->createPattern(1);
    572573        if (state.alpha != 1)
    573             gradient.alphaAdjusted = adoptRef(state.fillGradient->createPlatformGradient(state.alpha));
     574            gradient.alphaAdjusted = state.fillGradient->createPattern(state.alpha);
    574575    } else
    575576        color = state.fillColor;
     
    582583        pattern = adoptRef(state.strokePattern->createPlatformPattern(AffineTransform()));
    583584    else if (state.strokeGradient) {
    584         gradient.base = adoptRef(state.strokeGradient->createPlatformGradient(1));
     585        gradient.base = state.strokeGradient->createPattern(1);
    585586        if (state.alpha != 1)
    586             gradient.alphaAdjusted = adoptRef(state.strokeGradient->createPlatformGradient(state.alpha));
     587            gradient.alphaAdjusted = state.strokeGradient->createPattern(state.alpha);
    587588    } else
    588589        color = state.strokeColor;
  • trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp

    r264273 r264280  
    3131#if USE(CAIRO)
    3232
     33#include "AnimationUtilities.h"
    3334#include "CairoOperations.h"
    3435#include "CairoUtilities.h"
     36#include "ColorBlending.h"
    3537#include "GraphicsContext.h"
    3638#include "PlatformContextCairo.h"
     
    3941namespace WebCore {
    4042
    41 void Gradient::platformDestroy()
     43void Gradient::stopsChanged()
    4244{
    4345}
     
    133135}
    134136
    135 static Gradient::ColorStop interpolateColorStop(Gradient::ColorStop from, Gradient::ColorStop to)
    136 {
    137     auto [r1, g1, b1, a1] = from.color.toSRGBALossy<float>();
    138     auto [r2, g2, b2, a2] = to.color.toSRGBALossy<float>();
    139 
    140     float offset = from.offset + (to.offset - from.offset) * 0.5f;
    141     float r = r1 + (r2 - r1) * 0.5f;
    142     float g = g1 + (g2 - g1) * 0.5f;
    143     float b = b1 + (b2 - b1) * 0.5f;
    144     float a = a1 + (a2 - a1) * 0.5f;
    145 
    146     return Gradient::ColorStop(offset, makeSimpleColor(SRGBA { r, g, b, a }));
    147 }
    148 
    149 static cairo_pattern_t* createConic(float xo, float yo, float r, float angleRadians,
     137static Gradient::ColorStop interpolateColorStop(const Gradient::ColorStop& from, const Gradient::ColorStop& to)
     138{
     139    return { blend(from.offset, to.offset, 0.5), blend(from.color, to.color, 0.5) };
     140}
     141
     142static RefPtr<cairo_pattern_t> createConic(float xo, float yo, float r, float angleRadians,
    150143    Gradient::ColorStopVector stops, float globalAlpha)
    151144{
    152     cairo_pattern_t* gradient = cairo_pattern_create_mesh();
    153     Gradient::ColorStop from, to;
    154 
    155     /* It's not possible to paint an entire circle with a single Bezier curve.
    156      * To have a good approximation to a circle it's necessary to use at least
    157      * four Bezier curves. So three additional stops with interpolated colors
    158      * are added to force painting of four Bezier curves. */
     145    // It's not possible to paint an entire circle with a single Bezier curve.
     146    // To have a good approximation to a circle it's necessary to use at least
     147    // four Bezier curves. So three additional stops with interpolated colors
     148    // are added to force painting of four Bezier curves.
    159149    if (stops.size() == 2) {
    160         Gradient::ColorStop first = stops.at(0);
    161         Gradient::ColorStop last = stops.at(1);
    162         Gradient::ColorStop third = interpolateColorStop(first, last);
    163         Gradient::ColorStop second = interpolateColorStop(first, third);
    164         Gradient::ColorStop fourth = interpolateColorStop(third, last);
    165         stops.insert(1, fourth);
    166         stops.insert(1, third);
    167         stops.insert(1, second);
     150        auto third = interpolateColorStop(stops.first(), stops.last());
     151        auto second = interpolateColorStop(stops.first(), third);
     152        auto fourth = interpolateColorStop(third, stops.last());
     153        stops.insert(1, WTFMove(fourth));
     154        stops.insert(1, WTFMove(third));
     155        stops.insert(1, WTFMove(second));
    168156    }
    169157
    170     // Add extra color stop at the beginning if first element offset is not zero.
    171     if (stops.at(0).offset > 0)
    172         stops.insert(0, Gradient::ColorStop(0, stops.at(0).color));
    173     // Add extra color stop at the end if last element offset is not zero.
    174     if (stops.at(stops.size() - 1).offset < 1)
    175         stops.append(Gradient::ColorStop(1, stops.at(stops.size() - 1).color));
    176 
    177     for (size_t i = 0; i < stops.size() - 1; i++) {
    178         from = stops.at(i), to = stops.at(i + 1);
    179         addConicSector(gradient, xo, yo, r, angleRadians, from, to, globalAlpha);
    180     }
    181 
     158    if (stops.first().offset > 0.0f)
     159        stops.insert(0, Gradient::ColorStop { 0.0f, stops.first().color });
     160    if (stops.last().offset < 1.0f)
     161        stops.append({ 1.0f, stops.last().color });
     162
     163    auto gradient = adoptRef(cairo_pattern_create_mesh());
     164    for (size_t i = 0; i < stops.size() - 1; i++)
     165        addConicSector(gradient.get(), xo, yo, r, angleRadians, stops[i], stops[i + 1], globalAlpha);
    182166    return gradient;
    183167}
    184168
    185 cairo_pattern_t* Gradient::createPlatformGradient(float globalAlpha)
    186 {
    187     cairo_pattern_t* gradient = WTF::switchOn(m_data,
    188         [&] (const LinearData& data) -> cairo_pattern_t* {
    189             return cairo_pattern_create_linear(data.point0.x(), data.point0.y(), data.point1.x(), data.point1.y());
     169RefPtr<cairo_pattern_t> Gradient::createPattern(float globalAlpha)
     170{
     171    auto gradient = WTF::switchOn(m_data,
     172        [&] (const LinearData& data) {
     173            auto gradient = adoptRef(cairo_pattern_create_linear(data.point0.x(), data.point0.y(), data.point1.x(), data.point1.y()));
     174            for (auto& stop : stops())
     175                addColorStopRGBA(gradient.get(), stop, globalAlpha);
     176            return gradient;
    190177        },
    191         [&] (const RadialData& data) -> cairo_pattern_t* {
    192             return cairo_pattern_create_radial(data.point0.x(), data.point0.y(), data.startRadius, data.point1.x(), data.point1.y(), data.endRadius);
     178        [&] (const RadialData& data) {
     179            auto gradient = adoptRef(cairo_pattern_create_radial(data.point0.x(), data.point0.y(), data.startRadius, data.point1.x(), data.point1.y(), data.endRadius));
     180            for (auto& stop : stops())
     181                addColorStopRGBA(gradient.get(), stop, globalAlpha);
     182            return gradient;
    193183        },
    194         [&] (const ConicData& data)  -> cairo_pattern_t* {
     184        [&] (const ConicData& data) {
    195185            // FIXME: data passed for a Conic gradient doesn't contain a radius. That's apparently correct because the W3C spec
    196186            // (https://www.w3.org/TR/css-images-4/#conic-gradients) states a conic gradient is only defined by its position and angle.
     
    202192    );
    203193
    204     if (type() != Type::Conic) {
    205         for (const auto& stop : stops()) {
    206             addColorStopRGBA(gradient, stop, globalAlpha);
    207         }
    208     }
    209 
    210194    switch (m_spreadMethod) {
    211195    case GradientSpreadMethod::Pad:
    212         cairo_pattern_set_extend(gradient, CAIRO_EXTEND_PAD);
     196        cairo_pattern_set_extend(gradient.get(), CAIRO_EXTEND_PAD);
    213197        break;
    214198    case GradientSpreadMethod::Reflect:
    215         cairo_pattern_set_extend(gradient, CAIRO_EXTEND_REFLECT);
     199        cairo_pattern_set_extend(gradient.get(), CAIRO_EXTEND_REFLECT);
    216200        break;
    217201    case GradientSpreadMethod::Repeat:
    218         cairo_pattern_set_extend(gradient, CAIRO_EXTEND_REPEAT);
     202        cairo_pattern_set_extend(gradient.get(), CAIRO_EXTEND_REPEAT);
    219203        break;
    220204    }
     
    222206    cairo_matrix_t matrix = toCairoMatrix(m_gradientSpaceTransformation);
    223207    cairo_matrix_invert(&matrix);
    224     cairo_pattern_set_matrix(gradient, &matrix);
     208    cairo_pattern_set_matrix(gradient.get(), &matrix);
    225209
    226210    return gradient;
     
    229213void Gradient::fill(GraphicsContext& context, const FloatRect& rect)
    230214{
    231     RefPtr<cairo_pattern_t> platformGradient = adoptRef(createPlatformGradient(1.0));
    232     if (!platformGradient)
     215    auto pattern = createPattern(1.0);
     216    if (!pattern)
    233217        return;
    234218
     
    237221
    238222    Cairo::save(platformContext);
    239     Cairo::fillRect(platformContext, rect, platformGradient.get());
     223    Cairo::fillRect(platformContext, rect, pattern.get());
    240224    Cairo::restore(platformContext);
    241225}
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp

    r256892 r264280  
    3434#include "Font.h"
    3535#include "GlyphBuffer.h"
     36#include "Gradient.h"
    3637#include "GraphicsContextPlatformPrivateCairo.h"
    3738#include "ImageBuffer.h"
    3839#include "IntRect.h"
    39 
    4040
    4141namespace WebCore {
     
    155155void GraphicsContextImplCairo::fillRect(const FloatRect& rect, Gradient& gradient)
    156156{
    157     RefPtr<cairo_pattern_t> platformGradient = adoptRef(gradient.createPlatformGradient(1.0));
    158     if (!platformGradient)
     157    auto pattern = gradient.createPattern(1.0);
     158    if (!pattern)
    159159        return;
    160160
    161161    Cairo::save(m_platformContext);
    162     Cairo::fillRect(m_platformContext, rect, platformGradient.get());
     162    Cairo::fillRect(m_platformContext, rect, pattern.get());
    163163    Cairo::restore(m_platformContext);
    164164}
  • trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp

    r262684 r264280  
    3636namespace WebCore {
    3737
    38 void Gradient::platformDestroy()
     38void Gradient::stopsChanged()
    3939{
    40     CGGradientRelease(m_gradient);
    4140    m_gradient = nullptr;
    4241}
    4342
    44 CGGradientRef Gradient::platformGradient()
     43void Gradient::createCGGradient()
    4544{
    46     if (m_gradient)
    47         return m_gradient;
    48 
    49     sortStopsIfNecessary();
     45    sortStops();
    5046
    5147    auto colorsArray = adoptCF(CFArrayCreateMutable(0, m_stops.size(), &kCFTypeArrayCallBacks));
     
    8379
    8480    if (hasExtendedColors)
    85         m_gradient = CGGradientCreateWithColors(extendedSRGBColorSpaceRef(), colorsArray.get(), locations.data());
     81        m_gradient = adoptCF(CGGradientCreateWithColors(extendedSRGBColorSpaceRef(), colorsArray.get(), locations.data()));
    8682    else
    87         m_gradient = CGGradientCreateWithColorComponents(sRGBColorSpaceRef(), colorComponents.data(), locations.data(), numStops);
    88 
    89     return m_gradient;
     83        m_gradient = adoptCF(CGGradientCreateWithColorComponents(sRGBColorSpaceRef(), colorComponents.data(), locations.data(), numStops));
    9084}
    9185
     
    10498{
    10599    CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
    106     CGGradientRef gradient = platformGradient();
     100
     101    if (!m_gradient)
     102        createCGGradient();
    107103
    108104    WTF::switchOn(m_data,
     
    147143                        CGPoint right = CGPointMake(flip ? start : start + width, boundingBox.origin.y);
    148144
    149                         CGContextDrawLinearGradient(platformContext, gradient, left, right, extendOptions);
     145                        CGContextDrawLinearGradient(platformContext, m_gradient.get(), left, right, extendOptions);
    150146
    151147                        if (m_spreadMethod == GradientSpreadMethod::Reflect)
     
    159155            }
    160156            case GradientSpreadMethod::Pad:
    161                 CGContextDrawLinearGradient(platformContext, gradient, data.point0, data.point1, extendOptions);
     157                CGContextDrawLinearGradient(platformContext, m_gradient.get(), data.point0, data.point1, extendOptions);
    162158            }
    163159        },
     
    174170            }
    175171
    176             CGContextDrawRadialGradient(platformContext, gradient, data.point0, data.startRadius, data.point1, data.endRadius, extendOptions);
     172            CGContextDrawRadialGradient(platformContext, m_gradient.get(), data.point0, data.startRadius, data.point1, data.endRadius, extendOptions);
    177173
    178174            if (needScaling)
     
    187183            CGContextRotateCTM(platformContext, (CGFloat)-M_PI_2);
    188184            CGContextTranslateCTM(platformContext, -data.point0.x(), -data.point0.y());
    189             CGContextDrawConicGradient(platformContext, platformGradient(), data.point0, data.angleRadians);
     185            CGContextDrawConicGradient(platformContext, m_gradient.get(), data.point0, data.angleRadians);
    190186            CGContextRestoreGState(platformContext);
    191187#else
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r263211 r264280  
    3333#include "DisplayListRecorder.h"
    3434#include "FloatConversion.h"
     35#include "Gradient.h"
    3536#include "GraphicsContextPlatformPrivateCG.h"
    3637#include "ImageBuffer.h"
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h

    r262994 r264280  
    2828#include "AlphaPremultiplication.h"
    2929#include "DisplayList.h"
    30 #include "FloatPoint.h"
    3130#include "FloatRoundedRect.h"
    3231#include "Font.h"
    3332#include "GlyphBuffer.h"
     33#include "Gradient.h"
    3434#include "Image.h"
    3535#include "ImageData.h"
    3636#include "Pattern.h"
    3737#include "SharedBuffer.h"
    38 #include <wtf/RefCounted.h>
    3938#include <wtf/TypeCasts.h>
    4039
  • trunk/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp

    r254506 r264280  
    3232#include "CairoOperations.h"
    3333#include "FloatRoundedRect.h"
     34#include "Gradient.h"
    3435#include "ImageBuffer.h"
    3536#include "NicosiaPaintingOperationReplayCairo.h"
     
    292293    };
    293294
    294     append(createCommand<FillRect>(rect, adoptRef(gradient.createPlatformGradient(1.0))));
     295    append(createCommand<FillRect>(rect, gradient.createPattern(1.0)));
    295296}
    296297
  • trunk/Source/WebCore/platform/graphics/win/Direct2DOperations.cpp

    r262108 r264280  
    302302        brush = state.fillPattern->createPlatformPattern(context, state.alpha, userToBaseCTM);
    303303    } else if (state.fillGradient && !state.fillGradient->stops().isEmpty())
    304         brush = state.fillGradient->createPlatformGradientIfNecessary(platformContext.renderTarget());
     304        brush = state.fillGradient->createBrush(platformContext.renderTarget());
    305305    else
    306306        brush = platformContext.brushWithColor(color);
     
    319319        brush = state.strokePattern->createPlatformPattern(context, state.alpha, userToBaseCTM);
    320320    } else if (state.strokeGradient)
    321         brush = state.strokeGradient->createPlatformGradientIfNecessary(platformContext.renderTarget());
     321        brush = state.strokeGradient->createBrush(platformContext.renderTarget());
    322322    else
    323323        brush = platformContext.brushWithColor(color);
  • trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp

    r263941 r264280  
    3232#include <d2d1.h>
    3333#include <wtf/MathExtras.h>
    34 #include <wtf/RetainPtr.h>
    3534
    3635#define GRADIENT_DRAWING 3
     
    3837namespace WebCore {
    3938
    40 void Gradient::platformDestroy()
    41 {
    42     if (m_gradient)
    43         m_gradient->Release();
    44     m_gradient = nullptr;
    45 }
    46 
    47 ID2D1Brush* Gradient::platformGradient()
    48 {
    49     ASSERT(m_gradient);
    50     return m_gradient;
    51 }
    52 
    53 ID2D1Brush* Gradient::createPlatformGradientIfNecessary(ID2D1RenderTarget* context)
    54 {
    55     generateGradient(context);
    56     return m_gradient;
     39void Gradient::stopsChanged()
     40{
     41    m_brush = nullptr;
    5742}
    5843
     
    6651}
    6752
    68 void Gradient::generateGradient(ID2D1RenderTarget* renderTarget)
    69 {
    70     sortStopsIfNecessary();
     53ID2D1Brush* Gradient::createBrush(ID2D1RenderTarget* renderTarget)
     54{
     55    sortStops();
    7156
    7257    Vector<D2D1_GRADIENT_STOP> gradientStops;
    73     // FIXME: Add support for ExtendedColor.
    74     for (auto stop : m_stops) {
     58    gradientStops.reserveInitialCapacity(m_stops.size());
     59    for (auto& stop : m_stops) {
     60        // FIXME: Add support for non-sRGBA color spaces.
    7561        auto [r, g, b, a] stop.color.toSRGBALossy<float>();
    76         gradientStops.append(D2D1::GradientStop(stop.offset, D2D1::ColorF(r, g, b, a)));
     62        gradientStops.gradientStops.uncheckedAppend(D2D1::GradientStop(stop.offset, D2D1::ColorF(r, g, b, a)));
    7763    }
    7864
     
    122108    HRESULT hr = renderTarget->CreateGradientStopCollection(gradientStops.data(), gradientStops.size(), &gradientStopCollection);
    123109    RELEASE_ASSERT(SUCCEEDED(hr));
    124 
    125     if (m_gradient) {
    126         m_gradient->Release();
    127         m_gradient = nullptr;
    128     }
    129110
    130111    WTF::switchOn(m_data,
     
    136117                &linearGradient);
    137118            RELEASE_ASSERT(SUCCEEDED(hr));
    138             m_gradient = linearGradient;
     119            m_brush = adoptCOM(linearGradient);
    139120        },
    140121        [&] (const RadialData& data) {
     
    155136                &radialGradient);
    156137            RELEASE_ASSERT(SUCCEEDED(hr));
    157             m_gradient = radialGradient;
     138            m_brush = adoptCOM(radialGradient);
    158139        },
    159140        [&] (const ConicData&) {
    160141            // FIXME: implement conic gradient rendering.
     142            m_brush = nullptr;
    161143        }
    162144    );
    163145
    164     hash();
     146    return m_brush.get();
    165147}
    166148
     
    171153    WTF::switchOn(m_data,
    172154        [&] (const LinearData& data) {
    173             if (!m_cachedHash || !m_gradient)
    174                 generateGradient(d2dContext);
     155            // FIXME: If we have a brush, why can we re-use it? What guarantees it's right for this context?
     156            if (!m_brush)
     157                createBrush(d2dContext);
    175158
    176159#if ASSERT_ENABLED
     
    179162
    180163            const D2D1_RECT_F d2dRect = rect;
    181             d2dContext->FillRectangle(&d2dRect, m_gradient);
     164            d2dContext->FillRectangle(&d2dRect, m_brush.get());
    182165        },
    183166        [&] (const RadialData& data) {
     
    200183            }
    201184
    202             if (!m_cachedHash || !m_gradient)
    203                 generateGradient(d2dContext);
     185            // FIXME: If we have a brush, why can we re-use it? What guarantees it's right for this context?
     186            if (!m_brush)
     187                createBrush(d2dContext);
    204188
    205189#if ASSERT_ENABLED
     
    208192
    209193            const D2D1_RECT_F d2dRect = rect;
    210             d2dContext->FillRectangle(&d2dRect, m_gradient);
     194            d2dContext->FillRectangle(&d2dRect, m_brush.get());
    211195
    212196            if (needScaling)
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextImplDirect2D.cpp

    r250188 r264280  
    156156void GraphicsContextImplDirect2D::fillRect(const FloatRect& rect, Gradient& gradient)
    157157{
    158     COMPtr<ID2D1Brush> platformGradient = gradient.createPlatformGradientIfNecessary(m_platformContext.renderTarget());
    159     if (!platformGradient)
     158    auto brush = gradient.createBrush(m_platformContext.renderTarget());
     159    if (!brush)
    160160        return;
    161161
    162     Direct2D::fillRectWithGradient(m_platformContext, rect, platformGradient.get());
     162    Direct2D::fillRectWithGradient(m_platformContext, rect, brush.get());
    163163}
    164164
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm

    r264190 r264280  
    2929#if ENABLE(SMOOTH_SCROLLING)
    3030
    31 #import "FloatPoint.h"
     31#import "Gradient.h"
    3232#import "GraphicsLayer.h"
    3333#import "Logging.h"
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r264050 r264280  
    901901
    902902    const int progressBarHeight = 9;
    903     const float verticalOffset = (rect.height() - progressBarHeight) / 2.0;
     903    const float verticalOffset = (rect.height() - progressBarHeight) / 2.0f;
    904904
    905905    GraphicsContextStateSaver stateSaver(paintInfo.context());
     
    913913    // 1.1) Draw the white background with grey gradient border.
    914914    GraphicsContext& context = paintInfo.context();
    915     context.setStrokeThickness(0.68);
     915    context.setStrokeThickness(0.68f);
    916916    context.setStrokeStyle(SolidStroke);
    917917
    918918    const float verticalRenderingPosition = rect.y() + verticalOffset;
    919919    auto strokeGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
    920     strokeGradient->addColorStop(0.0, makeSimpleColor(141, 141, 141));
    921     strokeGradient->addColorStop(0.45, makeSimpleColor(238, 238, 238));
    922     strokeGradient->addColorStop(0.55, makeSimpleColor(238, 238, 238));
    923     strokeGradient->addColorStop(1.0, makeSimpleColor(141, 141, 141));
     920    strokeGradient->addColorStop({ 0.0f, makeSimpleColor(141, 141, 141) });
     921    strokeGradient->addColorStop({ 0.45f, makeSimpleColor(238, 238, 238) });
     922    strokeGradient->addColorStop({ 0.55f, makeSimpleColor(238, 238, 238) });
     923    strokeGradient->addColorStop({ 1.0f, makeSimpleColor(141, 141, 141) });
    924924    context.setStrokeGradient(WTFMove(strokeGradient));
    925925
     
    927927
    928928    Path trackPath;
    929     FloatRect trackRect(rect.x() + 0.25, verticalRenderingPosition + 0.25, rect.width() - 0.5, progressBarHeight - 0.5);
     929    FloatRect trackRect(rect.x() + 0.25f, verticalRenderingPosition + 0.25f, rect.width() - 0.5f, progressBarHeight - 0.5f);
    930930    FloatSize roundedCornerRadius(5, 4);
    931931    trackPath.addRoundedRect(trackRect, roundedCornerRadius);
     
    937937
    938938    float upperGradientHeight = progressBarHeight / 2.;
    939     auto upperGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + upperGradientHeight - 1.5) });
    940     upperGradient->addColorStop(0.0, makeSimpleColor(133, 133, 133, 188));
    941     upperGradient->addColorStop(1.0, makeSimpleColor(18, 18, 18, 51));
     939    auto upperGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition + 0.5f), FloatPoint(rect.x(), verticalRenderingPosition + upperGradientHeight - 1.5) });
     940    upperGradient->addColorStop({ 0.0f, makeSimpleColor(133, 133, 133, 188) });
     941    upperGradient->addColorStop({ 1.0f, makeSimpleColor(18, 18, 18, 51) });
    942942    context.setFillGradient(WTFMove(upperGradient));
    943943
     
    948948        // 2) Draw the progress bar.
    949949        double position = clampTo(renderProgress.position(), 0.0, 1.0);
    950         double barWidth = position * rect.width();
    951         auto barGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
    952         barGradient->addColorStop(0.0, makeSimpleColor(195, 217, 247));
    953         barGradient->addColorStop(0.45, makeSimpleColor(118, 164, 228));
    954         barGradient->addColorStop(0.49, makeSimpleColor(118, 164, 228));
    955         barGradient->addColorStop(0.51, makeSimpleColor(36, 114, 210));
    956         barGradient->addColorStop(0.55, makeSimpleColor(36, 114, 210));
    957         barGradient->addColorStop(1.0, makeSimpleColor(57, 142, 244));
     950        float barWidth = position * rect.width();
     951        auto barGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition + 0.5f), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
     952        barGradient->addColorStop({ 0.0f, makeSimpleColor(195, 217, 247) });
     953        barGradient->addColorStop({ 0.45f, makeSimpleColor(118, 164, 228) });
     954        barGradient->addColorStop({ 0.49f, makeSimpleColor(118, 164, 228) });
     955        barGradient->addColorStop({ 0.51f, makeSimpleColor(36, 114, 210) });
     956        barGradient->addColorStop({ 0.55f, makeSimpleColor(36, 114, 210) });
     957        barGradient->addColorStop({ 1.0f, makeSimpleColor(57, 142, 244) });
    958958        context.setFillGradient(WTFMove(barGradient));
    959959
    960960        auto barStrokeGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
    961         barStrokeGradient->addColorStop(0.0, makeSimpleColor(95, 107, 183));
    962         barStrokeGradient->addColorStop(0.5, makeSimpleColor(66, 106, 174, 240));
    963         barStrokeGradient->addColorStop(1.0, makeSimpleColor(38, 104, 166));
     961        barStrokeGradient->addColorStop({ 0.0f, makeSimpleColor(95, 107, 183) });
     962        barStrokeGradient->addColorStop({ 0.5f, makeSimpleColor(66, 106, 174, 240) });
     963        barStrokeGradient->addColorStop({ 1.0f, makeSimpleColor(38, 104, 166) });
    964964        context.setStrokeGradient(WTFMove(barStrokeGradient));
    965965
     
    968968        if (!renderProgress.style().isLeftToRightDirection())
    969969            left = rect.maxX() - barWidth;
    970         FloatRect barRect(left + 0.25, verticalRenderingPosition + 0.25, std::max(barWidth - 0.5, 0.0), progressBarHeight - 0.5);
     970        FloatRect barRect(left + 0.25f, verticalRenderingPosition + 0.25f, std::max(barWidth - 0.5f, 0.0f), progressBarHeight - 0.5f);
    971971        barPath.addRoundedRect(barRect, roundedCornerRadius);
    972972        context.drawPath(barPath);
  • trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp

    r262684 r264280  
    235235void RenderSVGResourceGradient::addStops(GradientData* gradientData, const Vector<Gradient::ColorStop>& stops, const RenderStyle& style) const
    236236{
     237    ASSERT(gradientData);
    237238    ASSERT(gradientData->gradient);
    238 
    239     for (Gradient::ColorStop stop : stops) {
    240         stop.color = style.colorByApplyingColorFilter(stop.color);
    241         gradientData->gradient->addColorStop(stop);
    242     }
     239    for (auto& stop : stops)
     240        gradientData->gradient->addColorStop({ stop.offset, style.colorByApplyingColorFilter(stop.color) });
    243241}
    244242
  • trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h

    r231153 r264280  
    2222#pragma once
    2323
    24 #include "Gradient.h"
    2524#include "ImageBuffer.h"
    2625#include "RenderSVGResourceContainer.h"
  • trunk/Source/WebCore/svg/SVGGradientElement.cpp

    r251318 r264280  
    103103    Vector<Gradient::ColorStop> stops;
    104104    float previousOffset = 0.0f;
    105 
    106105    for (auto& stop : childrenOfType<SVGStopElement>(*this)) {
    107         const Color& color = stop.stopColorIncludingOpacity();
    108 
    109         // Figure out right monotonic offset.
    110         float offset = stop.offset();
    111         offset = std::min(std::max(previousOffset, offset), 1.0f);
    112         previousOffset = offset;
    113 
    114         stops.append(Gradient::ColorStop(offset, color));
     106        auto monotonicallyIncreasingOffset = std::clamp(stop.offset(), previousOffset, 1.0f);
     107        previousOffset = monotonicallyIncreasingOffset;
     108        stops.append({ monotonicallyIncreasingOffset, stop.stopColorIncludingOpacity() });
    115109    }
    116 
    117110    return stops;
    118111}
Note: See TracChangeset for help on using the changeset viewer.