Title: [264290] trunk/Source
Revision
264290
Author
da...@apple.com
Date
2020-07-12 21:09:20 -0700 (Sun, 12 Jul 2020)

Log Message

Some further streamlining of Gradient handling code
https://bugs.webkit.org/show_bug.cgi?id=214239

Reviewed by Sam Weinig.

Source/WebCore:

* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::interpolateColorStop): Deleted.
(WebCore::createConic): Rewrite the interpolation code to create a new
vector rather than edit the existing one and to use a more straightforward
idiom, and a lambda rather than a helper function. Also removed an explicit
conversion to Gradient::ColorStop, no longer needed because of the overload
added to Vector::insert.

* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::RenderSVGResourceGradient::applyResource): Use ensure rather
than add to initialize gradient data in the gradient map. Change the #if
for USE(CG) so it doesn't confuse brace matching from the syntax handling
of text editors like the one in Xcode. Update for the changes to the
buildGradient and gradientTransform functions. Use auto a bit more.
(WebCore::RenderSVGResourceGradient::postApplyResource): Update since the
map now contains GradientData rather than unique_ptr<GradientData>. Use
std::exchange when fetching m_savedContext and a local variable to make
the gradient-related code a bit less wordy.
(WebCore::RenderSVGResourceGradient::addStops): Updated to take Gradient&
rather than GradientData* and made this a static member function.
(WebCore::RenderSVGResourceGradient::platformSpreadMethodFromSVGType):
Made this a static member function.

* rendering/svg/RenderSVGResourceGradient.h: Made more functions private.
Converted addStops and platformSpreadMethodFromSVGType to static member
functions. Made GradientData a member class, and put directly into the
HashMap rather than putting unique_ptr into the map. Changed
calculateGradientTransform to gradientTransform, which uses a return
value rather than an out argument. Changed buildGradient to return
Ref<Gradient> rather than taking a GradientData* to store it in.

* rendering/svg/RenderSVGResourceLinearGradient.cpp:
(WebCore::RenderSVGResourceLinearGradient::buildGradient const):
Changed to return the gradient instead of modifying an argument and
updated for the change to addStops.

* rendering/svg/RenderSVGResourceLinearGradient.h: Made more functions
private and updated for changes to gradientTransform and buildGradient.

* rendering/svg/RenderSVGResourceRadialGradient.cpp:
(WebCore::RenderSVGResourceRadialGradient::buildGradient const):
Changed to return the gradient instead of modifying an argument and
updated for the change to addStops.

* rendering/svg/RenderSVGResourceRadialGradient.h: Made more functions
private and updated for changes to gradientTransform and buildGradient.

* svg/GradientAttributes.h: Removed the stopsSet boolean since
the stops vector is empty if and only if it's not set. Made the setStops
function take an rvalue reference so it doesn't always copy a vector.
Also use the ColorStopVector type, sharing the same inline capacity
policy with the Gradient class; both are optimizing the same thing.

* svg/SVGGradientElement.cpp:
(WebCore::SVGGradientElement::buildStops): Use the ColorStopVector type.
* svg/SVGGradientElement.h: Update for the above.

* svg/SVGLinearGradientElement.cpp:
(WebCore::setGradientAttributes): Update for changes to buildStops and
removed an unnecessary check for an empty vector now that an empty
vector has the same semantics as "no stops".
* svg/SVGRadialGradientElement.cpp:
(WebCore::setGradientAttributes): Ditto.

Source/WTF:

* wtf/Vector.h: Added an overload for insert analogous to the ones we already have
for append and uncheckedAppend, helpful for type deduction.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (264289 => 264290)


--- trunk/Source/WTF/ChangeLog	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WTF/ChangeLog	2020-07-13 04:09:20 UTC (rev 264290)
@@ -1,3 +1,13 @@
+2020-07-12  Darin Adler  <da...@apple.com>
+
+        Some further streamlining of Gradient handling code
+        https://bugs.webkit.org/show_bug.cgi?id=214239
+
+        Reviewed by Sam Weinig.
+
+        * wtf/Vector.h: Added an overload for insert analogous to the ones we already have
+        for append and uncheckedAppend, helpful for type deduction.
+
 2020-07-12  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         [macOS]: A HEIF image, selected from the OpenPanel, should be converted to an accepted MIME type

Modified: trunk/Source/WTF/wtf/Vector.h (264289 => 264290)


--- trunk/Source/WTF/wtf/Vector.h	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WTF/wtf/Vector.h	2020-07-13 04:09:20 UTC (rev 264290)
@@ -786,6 +786,7 @@
     template<typename U, size_t otherCapacity> void appendVector(const Vector<U, otherCapacity>&);
     template<typename U, size_t otherCapacity> void appendVector(Vector<U, otherCapacity>&&);
 
+    void insert(size_t position, ValueType&& value) { insert<ValueType>(position, std::forward<ValueType>(value)); }
     template<typename U> void insert(size_t position, const U*, size_t);
     template<typename U> void insert(size_t position, U&&);
     template<typename U, size_t c, typename OH, size_t m, typename M> void insertVector(size_t position, const Vector<U, c, OH, m, M>&);

Modified: trunk/Source/WebCore/ChangeLog (264289 => 264290)


--- trunk/Source/WebCore/ChangeLog	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/ChangeLog	2020-07-13 04:09:20 UTC (rev 264290)
@@ -1,3 +1,74 @@
+2020-07-12  Darin Adler  <da...@apple.com>
+
+        Some further streamlining of Gradient handling code
+        https://bugs.webkit.org/show_bug.cgi?id=214239
+
+        Reviewed by Sam Weinig.
+
+        * platform/graphics/cairo/GradientCairo.cpp:
+        (WebCore::interpolateColorStop): Deleted.
+        (WebCore::createConic): Rewrite the interpolation code to create a new
+        vector rather than edit the existing one and to use a more straightforward
+        idiom, and a lambda rather than a helper function. Also removed an explicit
+        conversion to Gradient::ColorStop, no longer needed because of the overload
+        added to Vector::insert.
+
+        * rendering/svg/RenderSVGResourceGradient.cpp:
+        (WebCore::RenderSVGResourceGradient::applyResource): Use ensure rather
+        than add to initialize gradient data in the gradient map. Change the #if
+        for USE(CG) so it doesn't confuse brace matching from the syntax handling
+        of text editors like the one in Xcode. Update for the changes to the
+        buildGradient and gradientTransform functions. Use auto a bit more.
+        (WebCore::RenderSVGResourceGradient::postApplyResource): Update since the
+        map now contains GradientData rather than unique_ptr<GradientData>. Use
+        std::exchange when fetching m_savedContext and a local variable to make
+        the gradient-related code a bit less wordy.
+        (WebCore::RenderSVGResourceGradient::addStops): Updated to take Gradient&
+        rather than GradientData* and made this a static member function.
+        (WebCore::RenderSVGResourceGradient::platformSpreadMethodFromSVGType):
+        Made this a static member function.
+
+        * rendering/svg/RenderSVGResourceGradient.h: Made more functions private.
+        Converted addStops and platformSpreadMethodFromSVGType to static member
+        functions. Made GradientData a member class, and put directly into the
+        HashMap rather than putting unique_ptr into the map. Changed
+        calculateGradientTransform to gradientTransform, which uses a return
+        value rather than an out argument. Changed buildGradient to return
+        Ref<Gradient> rather than taking a GradientData* to store it in.
+
+        * rendering/svg/RenderSVGResourceLinearGradient.cpp:
+        (WebCore::RenderSVGResourceLinearGradient::buildGradient const):
+        Changed to return the gradient instead of modifying an argument and
+        updated for the change to addStops.
+
+        * rendering/svg/RenderSVGResourceLinearGradient.h: Made more functions
+        private and updated for changes to gradientTransform and buildGradient.
+
+        * rendering/svg/RenderSVGResourceRadialGradient.cpp:
+        (WebCore::RenderSVGResourceRadialGradient::buildGradient const):
+        Changed to return the gradient instead of modifying an argument and
+        updated for the change to addStops.
+
+        * rendering/svg/RenderSVGResourceRadialGradient.h: Made more functions
+        private and updated for changes to gradientTransform and buildGradient.
+
+        * svg/GradientAttributes.h: Removed the stopsSet boolean since
+        the stops vector is empty if and only if it's not set. Made the setStops
+        function take an rvalue reference so it doesn't always copy a vector.
+        Also use the ColorStopVector type, sharing the same inline capacity
+        policy with the Gradient class; both are optimizing the same thing.
+
+        * svg/SVGGradientElement.cpp:
+        (WebCore::SVGGradientElement::buildStops): Use the ColorStopVector type.
+        * svg/SVGGradientElement.h: Update for the above.
+
+        * svg/SVGLinearGradientElement.cpp:
+        (WebCore::setGradientAttributes): Update for changes to buildStops and
+        removed an unnecessary check for an empty vector now that an empty
+        vector has the same semantics as "no stops".
+        * svg/SVGRadialGradientElement.cpp:
+        (WebCore::setGradientAttributes): Ditto.
+
 2020-07-12  Fujii Hironori  <hironori.fu...@sony.com>
 
         [WinCairo][Clang] Unreviewed build fix for r264272

Modified: trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp (264289 => 264290)


--- trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -134,29 +134,21 @@
     cairo_mesh_pattern_end_patch(gradient);
 }
 
-static Gradient::ColorStop interpolateColorStop(const Gradient::ColorStop& from, const Gradient::ColorStop& to)
-{
-    return { blend(from.offset, to.offset, 0.5), blend(from.color, to.color, 0.5) };
-}
-
 static RefPtr<cairo_pattern_t> createConic(float xo, float yo, float r, float angleRadians,
     Gradient::ColorStopVector stops, float globalAlpha)
 {
     // It's not possible to paint an entire circle with a single Bezier curve.
-    // To have a good approximation to a circle it's necessary to use at least
-    // four Bezier curves. So three additional stops with interpolated colors
-    // are added to force painting of four Bezier curves.
+    // To have a good approximation to a circle it's necessary to use at least four Bezier curves.
+    // So add three additional interpolated stops, allowing for four Bezier curves.
     if (stops.size() == 2) {
-        auto third = interpolateColorStop(stops.first(), stops.last());
-        auto second = interpolateColorStop(stops.first(), third);
-        auto fourth = interpolateColorStop(third, stops.last());
-        stops.insert(1, WTFMove(fourth));
-        stops.insert(1, WTFMove(third));
-        stops.insert(1, WTFMove(second));
+        auto interpolatedStop = [&] (double fraction) -> Gradient::ColorStop {
+            return { blend(stops.first().offset, stops.last().offset, fraction), blend(stops.first().color, stops.last().color, fraction) };
+        };
+        stops = { stops.first(), interpolatedStop(0.25), interpolatedStop(0.5), interpolatedStop(0.75), stops.last() };
     }
 
     if (stops.first().offset > 0.0f)
-        stops.insert(0, Gradient::ColorStop { 0.0f, stops.first().color });
+        stops.insert(0, { 0.0f, stops.first().color });
     if (stops.last().offset < 1.0f)
         stops.append({ 1.0f, stops.last().color });
 

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp (264289 => 264290)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -117,45 +117,39 @@
     if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty())
         return false;
 
-    auto& gradientData = m_gradientMap.add(&renderer, nullptr).iterator->value;
-    if (!gradientData)
-        gradientData = makeUnique<GradientData>();
-
     bool isPaintingText = resourceMode.contains(RenderSVGResourceMode::ApplyToText);
 
-    // Create gradient object
-    if (!gradientData->gradient) {
-        buildGradient(gradientData.get(), style);
+    auto& gradientData = m_gradientMap.ensure(&renderer, [&]() -> GradientData {
+        auto gradient = buildGradient(style);
 
+        AffineTransform userspaceTransform;
+
         // CG platforms will handle the gradient space transform for text after applying the
         // resource, so don't apply it here. For non-CG platforms, we want the text bounding
         // box applied to the gradient space transform now, so the gradient shader can use it.
+        if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()
 #if USE(CG)
-        if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty() && !isPaintingText) {
-#else
-        if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) {
+            && !isPaintingText
 #endif
-            gradientData->userspaceTransform.translate(objectBoundingBox.location());
-            gradientData->userspaceTransform.scale(objectBoundingBox.size());
+        ) {
+            userspaceTransform.translate(objectBoundingBox.location());
+            userspaceTransform.scale(objectBoundingBox.size());
         }
 
-        AffineTransform gradientTransform;
-        calculateGradientTransform(gradientTransform);
-
-        gradientData->userspaceTransform *= gradientTransform;
+        userspaceTransform *= gradientTransform();
         if (isPaintingText) {
             // Depending on font scaling factor, we may need to rescale the gradient here since
             // text painting removes the scale factor from the context.
             AffineTransform additionalTextTransform;
             if (shouldTransformOnTextPainting(renderer, additionalTextTransform))
-                gradientData->userspaceTransform *= additionalTextTransform;
+                userspaceTransform *= additionalTextTransform;
         }
-        gradientData->gradient->setGradientSpaceTransform(gradientData->userspaceTransform);
-    }
 
-    if (!gradientData->gradient)
-        return false;
+        gradient->setGradientSpaceTransform(userspaceTransform);
 
+        return { WTFMove(gradient), userspaceTransform };
+    }).iterator->value;
+
     // Draw gradient
     context->save();
 
@@ -166,21 +160,20 @@
             return false;
         }
 #endif
-
         context->setTextDrawingMode(resourceMode.contains(RenderSVGResourceMode::ApplyToFill) ? TextDrawingMode::Fill : TextDrawingMode::Stroke);
     }
 
-    const SVGRenderStyle& svgStyle = style.svgStyle();
+    auto& svgStyle = style.svgStyle();
 
     if (resourceMode.contains(RenderSVGResourceMode::ApplyToFill)) {
         context->setAlpha(svgStyle.fillOpacity());
-        context->setFillGradient(*gradientData->gradient);
+        context->setFillGradient(*gradientData.gradient);
         context->setFillRule(svgStyle.fillRule());
     } else if (resourceMode.contains(RenderSVGResourceMode::ApplyToStroke)) {
         if (svgStyle.vectorEffect() == VectorEffect::NonScalingStroke)
-            gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(&renderer, gradientData->userspaceTransform));
+            gradientData.gradient->setGradientSpaceTransform(transformOnNonScalingStroke(&renderer, gradientData.userspaceTransform));
         context->setAlpha(svgStyle.strokeOpacity());
-        context->setStrokeGradient(*gradientData->gradient);
+        context->setStrokeGradient(*gradientData.gradient);
         SVGRenderSupport::applyStrokeStyleToContext(context, style, renderer);
     }
 
@@ -195,21 +188,22 @@
     if (resourceMode.contains(RenderSVGResourceMode::ApplyToText)) {
 #if USE(CG)
         // CG requires special handling for gradient on text
-        GradientData* gradientData = nullptr;
-        if (m_savedContext && (gradientData = m_gradientMap.get(&renderer))) {
-            // Restore on-screen drawing context
-            context = m_savedContext;
-            m_savedContext = nullptr;
+        if (m_savedContext) {
+            auto gradientData = m_gradientMap.find(&renderer);
+            if (gradientData != m_gradientMap.end()) {
+                auto& gradient = *gradientData->value.gradient;
 
-            AffineTransform gradientTransform;
-            calculateGradientTransform(gradientTransform);
+                // Restore on-screen drawing context
+                context = std::exchange(m_savedContext, nullptr);
 
-            FloatRect targetRect;
-            gradientData->gradient->setGradientSpaceTransform(clipToTextMask(*context, m_imageBuffer, targetRect, &renderer, gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX, gradientTransform));
-            context->setFillGradient(*gradientData->gradient);
+                FloatRect targetRect;
+                gradient.setGradientSpaceTransform(clipToTextMask(*context, m_imageBuffer, targetRect, &renderer, gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX, gradientTransform()));
 
-            context->fillRect(targetRect);
-            m_imageBuffer.reset();
+                context->setFillGradient(gradient);
+                context->fillRect(targetRect);
+
+                m_imageBuffer.reset();
+            }
         }
 #else
         UNUSED_PARAM(renderer);
@@ -232,15 +226,13 @@
     context->restore();
 }
 
-void RenderSVGResourceGradient::addStops(GradientData* gradientData, const Vector<Gradient::ColorStop>& stops, const RenderStyle& style) const
+void RenderSVGResourceGradient::addStops(Gradient& gradient, const Gradient::ColorStopVector& stops, const RenderStyle& style)
 {
-    ASSERT(gradientData);
-    ASSERT(gradientData->gradient);
     for (auto& stop : stops)
-        gradientData->gradient->addColorStop({ stop.offset, style.colorByApplyingColorFilter(stop.color) });
+        gradient.addColorStop({ stop.offset, style.colorByApplyingColorFilter(stop.color) });
 }
 
-GradientSpreadMethod RenderSVGResourceGradient::platformSpreadMethodFromSVGType(SVGSpreadMethodType method) const
+GradientSpreadMethod RenderSVGResourceGradient::platformSpreadMethodFromSVGType(SVGSpreadMethodType method)
 {
     switch (method) {
     case SVGSpreadMethodUnknown:

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h (264289 => 264290)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h	2020-07-13 04:09:20 UTC (rev 264290)
@@ -29,13 +29,6 @@
 
 namespace WebCore {
 
-struct GradientData {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    RefPtr<Gradient> gradient;
-    AffineTransform userspaceTransform;
-};
-
 class GraphicsContext;
 
 class RenderSVGResourceGradient : public RenderSVGResourceContainer {
@@ -53,20 +46,23 @@
 protected:
     RenderSVGResourceGradient(SVGGradientElement&, RenderStyle&&);
 
+    static void addStops(Gradient&, const Gradient::ColorStopVector&, const RenderStyle&);
+    static GradientSpreadMethod platformSpreadMethodFromSVGType(SVGSpreadMethodType);
+
+private:
     void element() const = delete;
 
-    void addStops(GradientData*, const Vector<Gradient::ColorStop>&, const RenderStyle&) const;
-
     virtual SVGUnitTypes::SVGUnitType gradientUnits() const = 0;
-    virtual void calculateGradientTransform(AffineTransform&) = 0;
+    virtual AffineTransform gradientTransform() const = 0;
     virtual bool collectGradientAttributes() = 0;
-    virtual void buildGradient(GradientData*, const RenderStyle&) const = 0;
+    virtual Ref<Gradient> buildGradient(const RenderStyle&) const = 0;
 
-    GradientSpreadMethod platformSpreadMethodFromSVGType(SVGSpreadMethodType) const;
+    struct GradientData {
+        RefPtr<Gradient> gradient;
+        AffineTransform userspaceTransform;
+    };
+    HashMap<RenderObject*, GradientData> m_gradientMap;
 
-private:
-    HashMap<RenderObject*, std::unique_ptr<GradientData>> m_gradientMap;
-
 #if USE(CG)
     GraphicsContext* m_savedContext { nullptr };
     std::unique_ptr<ImageBuffer> m_imageBuffer;

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp (264289 => 264290)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -50,11 +50,12 @@
     return SVGLengthContext::resolvePoint(&linearGradientElement(), attributes.gradientUnits(), attributes.x2(), attributes.y2());
 }
 
-void RenderSVGResourceLinearGradient::buildGradient(GradientData* gradientData, const RenderStyle& style) const
+Ref<Gradient> RenderSVGResourceLinearGradient::buildGradient(const RenderStyle& style) const
 {
-    gradientData->gradient = Gradient::create(Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) });
-    gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
-    addStops(gradientData, m_attributes.stops(), style);
+    auto gradient = Gradient::create(Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) });
+    gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
+    addStops(gradient, m_attributes.stops(), style);
+    return gradient;
 }
 
 }

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.h (264289 => 264290)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.h	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.h	2020-07-13 04:09:20 UTC (rev 264290)
@@ -34,20 +34,20 @@
 
     SVGLinearGradientElement& linearGradientElement() const { return downcast<SVGLinearGradientElement>(RenderSVGResourceGradient::gradientElement()); }
 
-    RenderSVGResourceType resourceType() const override { return LinearGradientResourceType; }
-
-    SVGUnitTypes::SVGUnitType gradientUnits() const override { return m_attributes.gradientUnits(); }
-    void calculateGradientTransform(AffineTransform& transform) override { transform = m_attributes.gradientTransform(); }
-    bool collectGradientAttributes() override;
-    void buildGradient(GradientData*, const RenderStyle&) const override;
-
     FloatPoint startPoint(const LinearGradientAttributes&) const;
     FloatPoint endPoint(const LinearGradientAttributes&) const;
 
 private:
+    RenderSVGResourceType resourceType() const final { return LinearGradientResourceType; }
+
+    SVGUnitTypes::SVGUnitType gradientUnits() const final { return m_attributes.gradientUnits(); }
+    AffineTransform gradientTransform() const final { return m_attributes.gradientTransform(); }
+    bool collectGradientAttributes() final;
+    Ref<Gradient> buildGradient(const RenderStyle&) const final;
+
     void gradientElement() const = delete;
 
-    const char* renderName() const override { return "RenderSVGResourceLinearGradient"; }
+    const char* renderName() const final { return "RenderSVGResourceLinearGradient"; }
 
     LinearGradientAttributes m_attributes;
 };

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp (264289 => 264290)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -61,12 +61,12 @@
     return SVGLengthContext::resolveLength(&radialGradientElement(), attributes.gradientUnits(), attributes.fr());
 }
 
-void RenderSVGResourceRadialGradient::buildGradient(GradientData* gradientData, const RenderStyle& style) const
+Ref<Gradient> RenderSVGResourceRadialGradient::buildGradient(const RenderStyle& style) const
 {
-    gradientData->gradient = Gradient::create(Gradient::RadialData { this->focalPoint(m_attributes), this->centerPoint(m_attributes), this->focalRadius(m_attributes), this->radius(m_attributes), 1 });
-    gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
-
-    addStops(gradientData, m_attributes.stops(), style);
+    auto gradient = Gradient::create(Gradient::RadialData { focalPoint(m_attributes), centerPoint(m_attributes), focalRadius(m_attributes), radius(m_attributes), 1 });
+    gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
+    addStops(gradient, m_attributes.stops(), style);
+    return gradient;
 }
 
 }

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.h (264289 => 264290)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.h	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.h	2020-07-13 04:09:20 UTC (rev 264290)
@@ -36,12 +36,6 @@
 
     SVGRadialGradientElement& radialGradientElement() const { return downcast<SVGRadialGradientElement>(RenderSVGResourceGradient::gradientElement()); }
 
-    RenderSVGResourceType resourceType() const override { return RadialGradientResourceType; }
-
-    SVGUnitTypes::SVGUnitType gradientUnits() const override { return m_attributes.gradientUnits(); }
-    void calculateGradientTransform(AffineTransform& transform) override { transform = m_attributes.gradientTransform(); }
-    void buildGradient(GradientData*, const RenderStyle&) const override;
-
     FloatPoint centerPoint(const RadialGradientAttributes&) const;
     FloatPoint focalPoint(const RadialGradientAttributes&) const;
     float radius(const RadialGradientAttributes&) const;
@@ -48,10 +42,16 @@
     float focalRadius(const RadialGradientAttributes&) const;
 
 private:
+    RenderSVGResourceType resourceType() const final { return RadialGradientResourceType; }
+
+    SVGUnitTypes::SVGUnitType gradientUnits() const final { return m_attributes.gradientUnits(); }
+    AffineTransform gradientTransform() const final { return m_attributes.gradientTransform(); }
+    Ref<Gradient> buildGradient(const RenderStyle&) const final;
+
     void gradientElement() const = delete;
 
-    const char* renderName() const override { return "RenderSVGResourceRadialGradient"; }
-    bool collectGradientAttributes() override;
+    const char* renderName() const final { return "RenderSVGResourceRadialGradient"; }
+    bool collectGradientAttributes() final;
 
     RadialGradientAttributes m_attributes;
 };

Modified: trunk/Source/WebCore/svg/GradientAttributes.h (264289 => 264290)


--- trunk/Source/WebCore/svg/GradientAttributes.h	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/svg/GradientAttributes.h	2020-07-13 04:09:20 UTC (rev 264290)
@@ -31,7 +31,6 @@
         , m_spreadMethodSet(false)
         , m_gradientUnitsSet(false)
         , m_gradientTransformSet(false)
-        , m_stopsSet(false)
     {
     }
 
@@ -38,7 +37,7 @@
     SVGSpreadMethodType spreadMethod() const { return static_cast<SVGSpreadMethodType>(m_spreadMethod); }
     SVGUnitTypes::SVGUnitType gradientUnits() const { return static_cast<SVGUnitTypes::SVGUnitType>(m_gradientUnits); }
     AffineTransform gradientTransform() const { return m_gradientTransform; }
-    const Vector<Gradient::ColorStop>& stops() const { return m_stops; }
+    const Gradient::ColorStopVector& stops() const { return m_stops; }
 
     void setSpreadMethod(SVGSpreadMethodType value)
     {
@@ -58,21 +57,20 @@
         m_gradientTransformSet = true;
     }
 
-    void setStops(const Vector<Gradient::ColorStop>& value)
+    void setStops(Gradient::ColorStopVector&& value)
     {
-        m_stops = value;
-        m_stopsSet = true;
-    } 
+        m_stops = WTFMove(value);
+    }
 
     bool hasSpreadMethod() const { return m_spreadMethodSet; }
     bool hasGradientUnits() const { return m_gradientUnitsSet; }
     bool hasGradientTransform() const { return m_gradientTransformSet; }
-    bool hasStops() const { return m_stopsSet; }
+    bool hasStops() const { return !m_stops.isEmpty(); }
 
 private:
     // Properties
     AffineTransform m_gradientTransform;
-    Vector<Gradient::ColorStop> m_stops;
+    Gradient::ColorStopVector m_stops;
 
     unsigned m_spreadMethod : 2;
     unsigned m_gradientUnits : 2;
@@ -81,13 +79,12 @@
     unsigned m_spreadMethodSet : 1;
     unsigned m_gradientUnitsSet : 1;
     unsigned m_gradientTransformSet : 1;
-    unsigned m_stopsSet : 1;
 };
 
 struct SameSizeAsGradientAttributes {
     AffineTransform a;
-    Vector<Gradient::ColorStop> b;
-    unsigned c : 8;
+    Gradient::ColorStopVector b;
+    unsigned c : 7;
 };
 
 COMPILE_ASSERT(sizeof(GradientAttributes) == sizeof(SameSizeAsGradientAttributes), GradientAttributes_size_guard);

Modified: trunk/Source/WebCore/svg/SVGGradientElement.cpp (264289 => 264290)


--- trunk/Source/WebCore/svg/SVGGradientElement.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/svg/SVGGradientElement.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -98,9 +98,9 @@
         object->setNeedsLayout();
 }
 
-Vector<Gradient::ColorStop> SVGGradientElement::buildStops()
+Gradient::ColorStopVector SVGGradientElement::buildStops()
 {
-    Vector<Gradient::ColorStop> stops;
+    Gradient::ColorStopVector stops;
     float previousOffset = 0.0f;
     for (auto& stop : childrenOfType<SVGStopElement>(*this)) {
         auto monotonicallyIncreasingOffset = std::clamp(stop.offset(), previousOffset, 1.0f);

Modified: trunk/Source/WebCore/svg/SVGGradientElement.h (264289 => 264290)


--- trunk/Source/WebCore/svg/SVGGradientElement.h	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/svg/SVGGradientElement.h	2020-07-13 04:09:20 UTC (rev 264290)
@@ -79,7 +79,7 @@
         SVG_SPREADMETHOD_REPEAT = SVGSpreadMethodUnknown
     };
 
-    Vector<Gradient::ColorStop> buildStops();
+    Gradient::ColorStopVector buildStops();
 
     using PropertyRegistry = SVGPropertyOwnerRegistry<SVGGradientElement, SVGElement, SVGURIReference>;
 

Modified: trunk/Source/WebCore/svg/SVGLinearGradientElement.cpp (264289 => 264290)


--- trunk/Source/WebCore/svg/SVGLinearGradientElement.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/svg/SVGLinearGradientElement.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -106,11 +106,8 @@
     if (!attributes.hasGradientTransform() && element.hasAttribute(SVGNames::gradientTransformAttr))
         attributes.setGradientTransform(element.gradientTransform().concatenate());
 
-    if (!attributes.hasStops()) {
-        const Vector<Gradient::ColorStop>& stops(element.buildStops());
-        if (!stops.isEmpty())
-            attributes.setStops(stops);
-    }
+    if (!attributes.hasStops())
+        attributes.setStops(element.buildStops());
 
     if (isLinear) {
         SVGLinearGradientElement& linear = downcast<SVGLinearGradientElement>(element);

Modified: trunk/Source/WebCore/svg/SVGRadialGradientElement.cpp (264289 => 264290)


--- trunk/Source/WebCore/svg/SVGRadialGradientElement.cpp	2020-07-13 01:11:21 UTC (rev 264289)
+++ trunk/Source/WebCore/svg/SVGRadialGradientElement.cpp	2020-07-13 04:09:20 UTC (rev 264290)
@@ -112,11 +112,8 @@
     if (!attributes.hasGradientTransform() && element.hasAttribute(SVGNames::gradientTransformAttr))
         attributes.setGradientTransform(element.gradientTransform().concatenate());
 
-    if (!attributes.hasStops()) {
-        const Vector<Gradient::ColorStop>& stops(element.buildStops());
-        if (!stops.isEmpty())
-            attributes.setStops(stops);
-    }
+    if (!attributes.hasStops())
+        attributes.setStops(element.buildStops());
 
     if (isRadial) {
         SVGRadialGradientElement& radial = downcast<SVGRadialGradientElement>(element);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to