<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[225036] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/225036">225036</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-11-19 15:06:03 -0800 (Sun, 19 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Clean up gradient code in preparation for conic gradients
https://bugs.webkit.org/show_bug.cgi?id=179595

Patch by Sam Weinig <sam@webkit.org> on 2017-11-19
Reviewed by Darin Adler.

- Switches Gradient to use a Varient with type specific data structs and makes the
  points / radii immutable.
- Replaces CSSGradientValue::addStops with template function CSSGradientValue::computeStops
  which dispatches to a helper adoptor struct which is passed in for gradient type specific
  values, rather than switching on type in the function itself. In addition, the function no
  longer mutates a Gradient, but rather mutates type specific the data struct (e.g. Linear or
  Radial for now).

* css/CSSGradientValue.cpp:
(WebCore::LinearGradientAdaptor::LinearGradientAdaptor):
(WebCore::RadialGradientAdaptor::RadialGradientAdaptor):

    Add helper structs for the now templatized CSSGradientValue::computeStops that
    implement type specific functionality.

(WebCore::CSSGradientValue::computeStops):

    Renamed from addStops. Now takes a GradientAdaptor wrapper which abstracts out
    the gradient type specific functionlity.

(WebCore::CSSLinearGradientValue::createGradient):
(WebCore::CSSRadialGradientValue::createGradient):
(WebCore::CSSConicGradientValue::createGradient):

    Update to call computeStops and use new Gradient create function.

* css/CSSGradientValue.h:

    Update for new signature for computeStops.

* html/canvas/CanvasGradient.cpp:
(WebCore::CanvasGradient::CanvasGradient):

    Update to use new Gradient create function.

* inspector/InspectorCanvas.cpp:
(WebCore::InspectorCanvas::buildArrayForCanvasGradient):

    Update to get gradient point / radii information from the data accessor.

* platform/graphics/Gradient.cpp:
(WebCore::Gradient::Gradient):

    Update constructors to the new data structs.

(WebCore::Gradient::type const):

    Add helper to get the type of the varient, need for inspector code.

(WebCore::Gradient::adjustParametersForTiledDrawing):
(WebCore::Gradient::isZeroSize const):
(WebCore::Gradient::hash const):

    Update to switch on the underlying variant to get data values.

(WebCore::Gradient::addColorStop):

    Simplify by having one addColorStop call the other.

(WebCore::Gradient::setSortedColorStops):

    Added. Replaces setStopsSorted. Used now that CSSGradientValue computes and sorts
    its color stops before creating the gradient.

* platform/graphics/Gradient.h:
(WebCore::Gradient::create):

    Replace create functions with ones that take data structs.

(WebCore::Gradient::data const):

    Add accessor for the underlying variant.

(WebCore::Gradient::isRadial const): Deleted.

    Replaced by type accessor.

(WebCore::Gradient::p0 const): Deleted.
(WebCore::Gradient::p1 const): Deleted.
(WebCore::Gradient::setP0): Deleted.
(WebCore::Gradient::setP1): Deleted.
(WebCore::Gradient::startRadius const): Deleted.
(WebCore::Gradient::endRadius const): Deleted.
(WebCore::Gradient::setStartRadius): Deleted.
(WebCore::Gradient::setEndRadius): Deleted.

    Point and radii are now immutable.

(WebCore::Gradient::setStopsSorted): Deleted.

    Replaced by setSortedColorStops function.

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::fillRect):

    Pass the GraphicsContext by reference.

* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::Gradient::createPlatformGradient):

    Update to switch on the underlying variant to get data values.

(WebCore::Gradient::fill):

    Pass the GraphicsContext by reference.

* platform/graphics/cg/GradientCG.cpp:
(WebCore::Gradient::platformDestroy):

    Use nullptr.

(WebCore::Gradient::fill):

    Pass the GraphicsContext by reference.

(WebCore::Gradient::paint):

    Update to switch on the underlying variant to get data values.

* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::fillPath):
(WebCore::GraphicsContext::strokePath):
(WebCore::GraphicsContext::fillRect):
(WebCore::GraphicsContext::strokeRect):

    Pass the GraphicsContext by reference.

* platform/graphics/win/GradientDirect2D.cpp:
(WebCore::Gradient::generateGradient):

    Update to switch on the underlying variant to get data values.

(WebCore::Gradient::fill):

    Pass the GraphicsContext by reference.

* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::paintProgressBar):
* rendering/svg/RenderSVGResourceLinearGradient.cpp:
(WebCore::RenderSVGResourceLinearGradient::buildGradient const):
* rendering/svg/RenderSVGResourceRadialGradient.cpp:
(WebCore::RenderSVGResourceRadialGradient::buildGradient const):

    Update for new Gradient create function signature.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSGradientValuecpp">trunk/Source/WebCore/css/CSSGradientValue.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSGradientValueh">trunk/Source/WebCore/css/CSSGradientValue.h</a></li>
<li><a href="#trunkSourceWebCorehtmlcanvasCanvasGradientcpp">trunk/Source/WebCore/html/canvas/CanvasGradient.cpp</a></li>
<li><a href="#trunkSourceWebCoreinspectorInspectorCanvascpp">trunk/Source/WebCore/inspector/InspectorCanvas.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGradientcpp">trunk/Source/WebCore/platform/graphics/Gradient.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGradienth">trunk/Source/WebCore/platform/graphics/Gradient.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContextcpp">trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoGradientCairocpp">trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgGradientCGcpp">trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgGraphicsContextCGcpp">trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGradientDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderThemeIOSmm">trunk/Source/WebCore/rendering/RenderThemeIOS.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingsvgRenderSVGResourceLinearGradientcpp">trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingsvgRenderSVGResourceRadialGradientcpp">trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/ChangeLog      2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -1,3 +1,155 @@
</span><ins>+2017-11-19  Sam Weinig  <sam@webkit.org>
+
+        Clean up gradient code in preparation for conic gradients
+        https://bugs.webkit.org/show_bug.cgi?id=179595
+
+        Reviewed by Darin Adler.
+
+        - Switches Gradient to use a Varient with type specific data structs and makes the 
+          points / radii immutable.
+        - Replaces CSSGradientValue::addStops with template function CSSGradientValue::computeStops
+          which dispatches to a helper adoptor struct which is passed in for gradient type specific
+          values, rather than switching on type in the function itself. In addition, the function no
+          longer mutates a Gradient, but rather mutates type specific the data struct (e.g. Linear or
+          Radial for now).
+
+        * css/CSSGradientValue.cpp:
+        (WebCore::LinearGradientAdaptor::LinearGradientAdaptor):
+        (WebCore::RadialGradientAdaptor::RadialGradientAdaptor):
+
+            Add helper structs for the now templatized CSSGradientValue::computeStops that
+            implement type specific functionality.
+
+        (WebCore::CSSGradientValue::computeStops):
+        
+            Renamed from addStops. Now takes a GradientAdaptor wrapper which abstracts out
+            the gradient type specific functionlity.
+        
+        (WebCore::CSSLinearGradientValue::createGradient):
+        (WebCore::CSSRadialGradientValue::createGradient):
+        (WebCore::CSSConicGradientValue::createGradient):
+        
+            Update to call computeStops and use new Gradient create function. 
+        
+        * css/CSSGradientValue.h:
+        
+            Update for new signature for computeStops.
+        
+        * html/canvas/CanvasGradient.cpp:
+        (WebCore::CanvasGradient::CanvasGradient):
+        
+            Update to use new Gradient create function.
+        
+        * inspector/InspectorCanvas.cpp:
+        (WebCore::InspectorCanvas::buildArrayForCanvasGradient):
+        
+            Update to get gradient point / radii information from the data accessor.
+
+        * platform/graphics/Gradient.cpp:
+        (WebCore::Gradient::Gradient):
+        
+            Update constructors to the new data structs.
+        
+        (WebCore::Gradient::type const):
+        
+            Add helper to get the type of the varient, need for inspector code.
+        
+        (WebCore::Gradient::adjustParametersForTiledDrawing):
+        (WebCore::Gradient::isZeroSize const):
+        (WebCore::Gradient::hash const):
+        
+            Update to switch on the underlying variant to get data values.
+        
+        (WebCore::Gradient::addColorStop):
+        
+            Simplify by having one addColorStop call the other.
+            
+        (WebCore::Gradient::setSortedColorStops):
+        
+            Added. Replaces setStopsSorted. Used now that CSSGradientValue computes and sorts
+            its color stops before creating the gradient.
+
+        * platform/graphics/Gradient.h:
+        (WebCore::Gradient::create):
+        
+            Replace create functions with ones that take data structs.
+        
+        (WebCore::Gradient::data const):
+
+            Add accessor for the underlying variant.
+
+        (WebCore::Gradient::isRadial const): Deleted.
+        
+            Replaced by type accessor.
+        
+        (WebCore::Gradient::p0 const): Deleted.
+        (WebCore::Gradient::p1 const): Deleted.
+        (WebCore::Gradient::setP0): Deleted.
+        (WebCore::Gradient::setP1): Deleted.
+        (WebCore::Gradient::startRadius const): Deleted.
+        (WebCore::Gradient::endRadius const): Deleted.
+        (WebCore::Gradient::setStartRadius): Deleted.
+        (WebCore::Gradient::setEndRadius): Deleted.
+        
+            Point and radii are now immutable.
+        
+        (WebCore::Gradient::setStopsSorted): Deleted.
+        
+            Replaced by setSortedColorStops function.
+        
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::fillRect):
+        
+            Pass the GraphicsContext by reference.
+        
+        * platform/graphics/cairo/GradientCairo.cpp:
+        (WebCore::Gradient::createPlatformGradient):
+
+            Update to switch on the underlying variant to get data values.
+
+        (WebCore::Gradient::fill):
+        
+            Pass the GraphicsContext by reference.
+        
+        * platform/graphics/cg/GradientCG.cpp:
+        (WebCore::Gradient::platformDestroy):
+        
+            Use nullptr.
+        
+        (WebCore::Gradient::fill):
+        
+            Pass the GraphicsContext by reference.
+        
+        (WebCore::Gradient::paint):
+
+            Update to switch on the underlying variant to get data values.
+
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::fillPath):
+        (WebCore::GraphicsContext::strokePath):
+        (WebCore::GraphicsContext::fillRect):
+        (WebCore::GraphicsContext::strokeRect):
+        
+            Pass the GraphicsContext by reference.
+        
+        * platform/graphics/win/GradientDirect2D.cpp:
+        (WebCore::Gradient::generateGradient):
+
+            Update to switch on the underlying variant to get data values.
+        
+        (WebCore::Gradient::fill):
+    
+            Pass the GraphicsContext by reference.
+        
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::paintProgressBar):
+        * rendering/svg/RenderSVGResourceLinearGradient.cpp:
+        (WebCore::RenderSVGResourceLinearGradient::buildGradient const):
+        * rendering/svg/RenderSVGResourceRadialGradient.cpp:
+        (WebCore::RenderSVGResourceRadialGradient::buildGradient const):
+        
+            Update for new Gradient create function signature.
+
</ins><span class="cx"> 2017-11-19  Simon Fraser  <simon.fraser@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Use TypedArrayView's setRange() in FETurbulence
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSGradientValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSGradientValue.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSGradientValue.cpp    2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/css/CSSGradientValue.cpp       2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -135,14 +135,121 @@
</span><span class="cx">     return Color(red, green, blue, alpha);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CSSGradientValue::addStops(Gradient& gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
</del><ins>+class LinearGradientAdapter {
+public:
+    explicit LinearGradientAdapter(Gradient::LinearData& data)
+        : m_data(data)
+    {
+    }
+
+    FloatPoint startPoint() const { return m_data.point0; }
+    FloatPoint endPoint() const { return m_data.point1; }
+    float maxExtent(float, float) const { return 1; }
+
+    void normalizeStopsAndEndpointsOutsideRange(Vector<GradientStop>& stops)
+    {
+        float firstOffset = stops.first().offset;
+        float lastOffset = stops.last().offset;
+        if (firstOffset != lastOffset) {
+            float scale = lastOffset - firstOffset;
+
+            for (auto& stop : stops)
+                stop.offset = (stop.offset - firstOffset) / scale;
+
+            auto p0 = m_data.point0;
+            auto p1 = m_data.point1;
+            m_data.point0 = { p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y()) };
+            m_data.point1 = { p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y()) };
+        } else {
+            // There's a single position that is outside the scale, clamp the positions to 1.
+            for (auto& stop : stops)
+                stop.offset = 1;
+        }
+    }
+
+private:
+    Gradient::LinearData& m_data;
+};
+
+class RadialGradientAdapter {
+public:
+    explicit RadialGradientAdapter(Gradient::RadialData& data)
+        : m_data(data)
+    {
+    }
+
+    FloatPoint startPoint() const { return m_data.point0; }
+    FloatPoint endPoint() const { return m_data.point0 + FloatSize { m_data.endRadius, 0 }; }
+
+    // Radial gradients may need to extend further than the endpoints, because they have
+    // to repeat out to the corners of the box.
+    float maxExtent(float maxLengthForRepeat, float gradientLength) const
+    {
+        if (maxLengthForRepeat > gradientLength)
+            return gradientLength > 0 ? maxLengthForRepeat / gradientLength : 0;
+        return 1;
+    }
+
+    void normalizeStopsAndEndpointsOutsideRange(Vector<GradientStop>& stops)
+    {
+        auto numStops = stops.size();
+
+        // Rather than scaling the points < 0, we truncate them, so only scale according to the largest point.
+        float firstOffset = 0;
+        float lastOffset = stops.last().offset;
+        float scale = lastOffset - firstOffset;
+
+        // Reset points below 0 to the first visible color.
+        size_t firstZeroOrGreaterIndex = numStops;
+        for (size_t i = 0; i < numStops; ++i) {
+            if (stops[i].offset >= 0) {
+                firstZeroOrGreaterIndex = i;
+                break;
+            }
+        }
+
+        if (firstZeroOrGreaterIndex > 0) {
+            if (firstZeroOrGreaterIndex < numStops && stops[firstZeroOrGreaterIndex].offset > 0) {
+                float prevOffset = stops[firstZeroOrGreaterIndex - 1].offset;
+                float nextOffset = stops[firstZeroOrGreaterIndex].offset;
+
+                float interStopProportion = -prevOffset / (nextOffset - prevOffset);
+                // FIXME: when we interpolate gradients using premultiplied colors, this should do premultiplication.
+                Color blendedColor = blend(stops[firstZeroOrGreaterIndex - 1].color, stops[firstZeroOrGreaterIndex].color, interStopProportion);
+
+                // Clamp the positions to 0 and set the color.
+                for (size_t i = 0; i < firstZeroOrGreaterIndex; ++i) {
+                    stops[i].offset = 0;
+                    stops[i].color = blendedColor;
+                }
+            } else {
+                // All stops are below 0; just clamp them.
+                for (size_t i = 0; i < firstZeroOrGreaterIndex; ++i)
+                    stops[i].offset = 0;
+            }
+        }
+
+        for (auto& stop : stops)
+            stop.offset /= scale;
+
+        m_data.startRadius *= scale;
+        m_data.endRadius *= scale;
+    }
+
+private:
+    Gradient::RadialData& m_data;
+};
+
+template<typename GradientAdapter>
+Gradient::ColorStopVector CSSGradientValue::computeStops(GradientAdapter& gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
</ins><span class="cx"> {
</span><span class="cx">     if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
</span><span class="cx">         sortStopsIfNeeded();
</span><span class="cx"> 
</span><del>-        for (unsigned i = 0; i < m_stops.size(); i++) {
-            const CSSGradientColorStop& stop = m_stops[i];
</del><ins>+        Gradient::ColorStopVector result;
+        result.reserveInitialCapacity(m_stops.size());
</ins><span class="cx"> 
</span><ins>+        for (auto& stop : m_stops) {
</ins><span class="cx">             float offset;
</span><span class="cx">             if (stop.m_position->isPercentage())
</span><span class="cx">                 offset = stop.m_position->floatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100;
</span><span class="lines">@@ -149,43 +256,32 @@
</span><span class="cx">             else
</span><span class="cx">                 offset = stop.m_position->floatValue(CSSPrimitiveValue::CSS_NUMBER);
</span><span class="cx"> 
</span><del>-            gradient.addColorStop(offset, stop.m_resolvedColor);
</del><ins>+            result.uncheckedAppend({ offset, stop.m_resolvedColor });
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // The back end already sorted the stops.
-        gradient.setStopsSorted(true);
-        return;
</del><ins>+        return result;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     size_t numStops = m_stops.size();
</span><del>-
</del><span class="cx">     Vector<GradientStop> stops(numStops);
</span><span class="cx"> 
</span><del>-    float gradientLength = 0;
-    bool computedGradientLength = false;
</del><ins>+    auto gradientStart = gradient.startPoint();
+    auto gradientEnd = gradient.endPoint();
</ins><span class="cx"> 
</span><del>-    FloatPoint gradientStart = gradient.p0();
-    FloatPoint gradientEnd;
-    if (isLinearGradientValue())
-        gradientEnd = gradient.p1();
-    else if (isRadialGradientValue())
-        gradientEnd = gradientStart + FloatSize(gradient.endRadius(), 0);
</del><ins>+    auto gradientSize = gradientStart - gradientEnd;
+    float gradientLength = gradientSize.diagonalLength();
</ins><span class="cx"> 
</span><span class="cx">     for (size_t i = 0; i < numStops; ++i) {
</span><del>-        const CSSGradientColorStop& stop = m_stops[i];
</del><ins>+        auto& stop = m_stops[i];
</ins><span class="cx"> 
</span><span class="cx">         stops[i].isMidpoint = stop.isMidpoint;
</span><span class="cx">         stops[i].color = stop.m_resolvedColor;
</span><span class="cx"> 
</span><span class="cx">         if (stop.m_position) {
</span><del>-            const CSSPrimitiveValue& positionValue = *stop.m_position;
</del><ins>+            auto& positionValue = *stop.m_position;
</ins><span class="cx">             if (positionValue.isPercentage())
</span><span class="cx">                 stops[i].offset = positionValue.floatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100;
</span><span class="cx">             else if (positionValue.isLength() || positionValue.isViewportPercentageLength() || positionValue.isCalculatedPercentageWithLength()) {
</span><del>-                if (!computedGradientLength) {
-                    FloatSize gradientSize(gradientStart - gradientEnd);
-                    gradientLength = gradientSize.diagonalLength();
-                }
</del><span class="cx">                 float length;
</span><span class="cx">                 if (positionValue.isLength())
</span><span class="cx">                     length = positionValue.computeLength<float>(conversionData);
</span><span class="lines">@@ -342,7 +438,7 @@
</span><span class="cx">     if (m_repeating && numStops > 1) {
</span><span class="cx">         // If the difference in the positions of the first and last color-stops is 0,
</span><span class="cx">         // the gradient defines a solid-color image with the color of the last color-stop in the rule.
</span><del>-        float gradientRange = stops[numStops - 1].offset - stops[0].offset;
</del><ins>+        float gradientRange = stops.last().offset - stops.first().offset;
</ins><span class="cx">         if (!gradientRange) {
</span><span class="cx">             stops.first().offset = 0;
</span><span class="cx">             stops.first().color = stops.last().color;
</span><span class="lines">@@ -349,20 +445,8 @@
</span><span class="cx">             stops.shrink(1);
</span><span class="cx">             numStops = 1;
</span><span class="cx">         } else {
</span><del>-            float maxExtent = 1;
</del><ins>+            float maxExtent = gradient.maxExtent(maxLengthForRepeat, gradientLength);
</ins><span class="cx"> 
</span><del>-            // Radial gradients may need to extend further than the endpoints, because they have
-            // to repeat out to the corners of the box.
-            if (isRadialGradientValue()) {
-                if (!computedGradientLength) {
-                    FloatSize gradientSize(gradientStart - gradientEnd);
-                    gradientLength = gradientSize.diagonalLength();
-                }
-
-                if (maxLengthForRepeat > gradientLength)
-                    maxExtent = gradientLength > 0 ? maxLengthForRepeat / gradientLength : 0;
-            }
-
</del><span class="cx">             size_t originalNumStops = numStops;
</span><span class="cx">             size_t originalFirstStopIndex = 0;
</span><span class="cx"> 
</span><span class="lines">@@ -407,76 +491,16 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    numStops = stops.size();
-
</del><span class="cx">     // If the gradient goes outside the 0-1 range, normalize it by moving the endpoints, and adjusting the stops.
</span><del>-    if (numStops > 1 && (stops[0].offset < 0 || stops[numStops - 1].offset > 1)) {
-        if (isLinearGradientValue()) {
-            float firstOffset = stops[0].offset;
-            float lastOffset = stops[numStops - 1].offset;
-            if (firstOffset != lastOffset) {
-                float scale = lastOffset - firstOffset;
</del><ins>+    if (stops.size() > 1 && (stops.first().offset < 0 || stops.last().offset > 1))
+        gradient.normalizeStopsAndEndpointsOutsideRange(stops);
+    
+    Gradient::ColorStopVector result;
+    result.reserveInitialCapacity(stops.size());
+    for (auto& stop : stops)
+        result.uncheckedAppend({ stop.offset, stop.color });
</ins><span class="cx"> 
</span><del>-                for (size_t i = 0; i < numStops; ++i)
-                    stops[i].offset = (stops[i].offset - firstOffset) / scale;
-
-                FloatPoint p0 = gradient.p0();
-                FloatPoint p1 = gradient.p1();
-                gradient.setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y())));
-                gradient.setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y())));
-            } else {
-                // There's a single position that is outside the scale, clamp the positions to 1.
-                for (size_t i = 0; i < numStops; ++i)
-                    stops[i].offset = 1;
-            }
-        } else if (isRadialGradientValue()) {
-            // Rather than scaling the points < 0, we truncate them, so only scale according to the largest point.
-            float firstOffset = 0;
-            float lastOffset = stops[numStops - 1].offset;
-            float scale = lastOffset - firstOffset;
-
-            // Reset points below 0 to the first visible color.
-            size_t firstZeroOrGreaterIndex = numStops;
-            for (size_t i = 0; i < numStops; ++i) {
-                if (stops[i].offset >= 0) {
-                    firstZeroOrGreaterIndex = i;
-                    break;
-                }
-            }
-
-            if (firstZeroOrGreaterIndex > 0) {
-                if (firstZeroOrGreaterIndex < numStops && stops[firstZeroOrGreaterIndex].offset > 0) {
-                    float prevOffset = stops[firstZeroOrGreaterIndex - 1].offset;
-                    float nextOffset = stops[firstZeroOrGreaterIndex].offset;
-
-                    float interStopProportion = -prevOffset / (nextOffset - prevOffset);
-                    // FIXME: when we interpolate gradients using premultiplied colors, this should do premultiplication.
-                    Color blendedColor = blend(stops[firstZeroOrGreaterIndex - 1].color, stops[firstZeroOrGreaterIndex].color, interStopProportion);
-
-                    // Clamp the positions to 0 and set the color.
-                    for (size_t i = 0; i < firstZeroOrGreaterIndex; ++i) {
-                        stops[i].offset = 0;
-                        stops[i].color = blendedColor;
-                    }
-                } else {
-                    // All stops are below 0; just clamp them.
-                    for (size_t i = 0; i < firstZeroOrGreaterIndex; ++i)
-                        stops[i].offset = 0;
-                }
-            }
-
-            for (size_t i = 0; i < numStops; ++i)
-                stops[i].offset /= scale;
-
-            gradient.setStartRadius(gradient.startRadius() * scale);
-            gradient.setEndRadius(gradient.endRadius() * scale);
-        }
-    }
-
-    for (unsigned i = 0; i < numStops; i++)
-        gradient.addColorStop(stops[i].offset, stops[i].color);
-
-    gradient.setStopsSorted(true);
</del><ins>+    return result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static float positionFromValue(const CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)
</span><span class="lines">@@ -624,7 +648,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         for (unsigned i = 0; i < m_stops.size(); i++) {
</span><del>-            const CSSGradientColorStop& stop = m_stops[i];
</del><ins>+            auto& stop = m_stops[i];
</ins><span class="cx">             result.appendLiteral(", ");
</span><span class="cx">             result.append(stop.m_color->cssText());
</span><span class="cx">             if (stop.m_position) {
</span><span class="lines">@@ -801,14 +825,14 @@
</span><span class="cx">         default:
</span><span class="cx">             ASSERT_NOT_REACHED();
</span><span class="cx">         }
</span><del>-
</del><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Ref<Gradient> gradient = Gradient::create(firstPoint, secondPoint);
</del><ins>+    Gradient::LinearData data { firstPoint, secondPoint };
+    LinearGradientAdapter adapter { data };
+    auto stops = computeStops(adapter, conversionData, 1);
</ins><span class="cx"> 
</span><del>-    // Now add the stops.
-    addStops(gradient, conversionData, 1);
-
</del><ins>+    auto gradient = Gradient::create(WTFMove(data));
+    gradient->setSortedColorStops(WTFMove(stops));
</ins><span class="cx">     return gradient;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1213,9 +1237,7 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Ref<Gradient> gradient = Gradient::create(firstPoint, firstRadius, secondPoint, secondRadius, aspectRatio);
-
-    // addStops() only uses maxExtent for repeating gradients.
</del><ins>+    // computeStops() only uses maxExtent for repeating gradients.
</ins><span class="cx">     float maxExtent = 0;
</span><span class="cx">     if (m_repeating) {
</span><span class="cx">         FloatPoint corner;
</span><span class="lines">@@ -1222,9 +1244,12 @@
</span><span class="cx">         maxExtent = distanceToFarthestCorner(secondPoint, size, corner);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // Now add the stops.
-    addStops(gradient, conversionData, maxExtent);
</del><ins>+    Gradient::RadialData data { firstPoint, secondPoint, firstRadius, secondRadius, aspectRatio };
+    RadialGradientAdapter adapter { data };
+    auto stops = computeStops(adapter, conversionData, maxExtent);
</ins><span class="cx"> 
</span><ins>+    auto gradient = Gradient::create(WTFMove(data));
+    gradient->setSortedColorStops(WTFMove(stops));
</ins><span class="cx">     return gradient;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1326,7 +1351,7 @@
</span><span class="cx"> Ref<Gradient> CSSConicGradientValue::createGradient(RenderElement&, const FloatSize&)
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Implement.
</span><del>-    return Gradient::create(FloatPoint { }, FloatPoint { });
</del><ins>+    return Gradient::create(Gradient::LinearData { });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool CSSConicGradientValue::equals(const CSSConicGradientValue& other) const
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSGradientValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSGradientValue.h (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSGradientValue.h      2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/css/CSSGradientValue.h 2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -27,12 +27,12 @@
</span><span class="cx"> 
</span><span class="cx"> #include "CSSImageGeneratorValue.h"
</span><span class="cx"> #include "CSSPrimitiveValue.h"
</span><ins>+#include "Gradient.h"
</ins><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class FloatPoint;
</span><del>-class Gradient;
</del><span class="cx"> class StyleResolver;
</span><span class="cx"> 
</span><span class="cx"> enum CSSGradientType {
</span><span class="lines">@@ -109,7 +109,8 @@
</span><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void addStops(Gradient&, const CSSToLengthConversionData&, float maxLengthForRepeat = 0);
</del><ins>+    template<typename GradientAdapter>
+    Gradient::ColorStopVector computeStops(GradientAdapter&, const CSSToLengthConversionData&, float maxLengthForRepeat);
</ins><span class="cx"> 
</span><span class="cx">     // Resolve points/radii to front end values.
</span><span class="cx">     FloatPoint computeEndPoint(CSSPrimitiveValue*, CSSPrimitiveValue*, const CSSToLengthConversionData&, const FloatSize&);
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlcanvasCanvasGradientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/canvas/CanvasGradient.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/canvas/CanvasGradient.cpp      2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/html/canvas/CanvasGradient.cpp 2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -32,12 +32,12 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> CanvasGradient::CanvasGradient(const FloatPoint& p0, const FloatPoint& p1)
</span><del>-    : m_gradient(Gradient::create(p0, p1))
</del><ins>+    : m_gradient(Gradient::create(Gradient::LinearData { p0, p1 }))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CanvasGradient::CanvasGradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1)
</span><del>-    : m_gradient(Gradient::create(p0, r0, p1, r1))
</del><ins>+    : m_gradient(Gradient::create(Gradient::RadialData { p0, p1, r0, r1, 1 }))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreinspectorInspectorCanvascpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/inspector/InspectorCanvas.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/inspector/InspectorCanvas.cpp       2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/inspector/InspectorCanvas.cpp  2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -591,23 +591,30 @@
</span><span class="cx"> 
</span><span class="cx"> RefPtr<Inspector::Protocol::Array<InspectorValue>> InspectorCanvas::buildArrayForCanvasGradient(const CanvasGradient& canvasGradient)
</span><span class="cx"> {
</span><del>-    const Gradient& gradient = canvasGradient.gradient();
-    bool isRadial = gradient.isRadial();
</del><ins>+    const auto& gradient = canvasGradient.gradient();
</ins><span class="cx"> 
</span><del>-    String type = isRadial ? ASCIILiteral("radial-gradient") : ASCIILiteral("linear-gradient");
</del><ins>+    String type = gradient.type() == Gradient::Type::Radial ? ASCIILiteral("radial-gradient") : ASCIILiteral("linear-gradient");
</ins><span class="cx"> 
</span><span class="cx">     RefPtr<Inspector::Protocol::Array<float>> parameters = Inspector::Protocol::Array<float>::create();
</span><del>-    parameters->addItem(gradient.p0().x());
-    parameters->addItem(gradient.p0().y());
-    if (isRadial)
-        parameters->addItem(gradient.startRadius());
-    parameters->addItem(gradient.p1().x());
-    parameters->addItem(gradient.p1().y());
-    if (isRadial)
-        parameters->addItem(gradient.endRadius());
</del><ins>+    WTF::switchOn(gradient.data(),
+        [&parameters] (const Gradient::LinearData& data) {
+            parameters->addItem(data.point0.x());
+            parameters->addItem(data.point0.y());
+            parameters->addItem(data.point1.x());
+            parameters->addItem(data.point1.y());
+        },
+        [&parameters] (const Gradient::RadialData& data) {
+            parameters->addItem(data.point0.x());
+            parameters->addItem(data.point0.y());
+            parameters->addItem(data.startRadius);
+            parameters->addItem(data.point1.x());
+            parameters->addItem(data.point1.y());
+            parameters->addItem(data.endRadius);
+        }
+    );
</ins><span class="cx"> 
</span><span class="cx">     RefPtr<Inspector::Protocol::Array<InspectorValue>> stops = Inspector::Protocol::Array<InspectorValue>::create();
</span><del>-    for (const Gradient::ColorStop& colorStop : gradient.stops()) {
</del><ins>+    for (auto& colorStop : gradient.stops()) {
</ins><span class="cx">         RefPtr<Inspector::Protocol::Array<InspectorValue>> stop = Inspector::Protocol::Array<InspectorValue>::create();
</span><span class="cx">         stop->addItem(colorStop.offset);
</span><span class="cx">         stop->addItem(indexForData(colorStop.color.cssText()));
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGradientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Gradient.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Gradient.cpp      2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/Gradient.cpp 2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -36,30 +36,24 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1)
-    : m_radial(false)
-    , m_p0(p0)
-    , m_p1(p1)
-    , m_r0(0)
-    , m_r1(0)
-    , m_aspectRatio(1)
-    , m_stopsSorted(false)
-    , m_spreadMethod(SpreadMethodPad)
-    , m_cachedHash(0)
</del><ins>+Ref<Gradient> Gradient::create(LinearData&& data)
</ins><span class="cx"> {
</span><ins>+    return adoptRef(*new Gradient(WTFMove(data)));
+}
+
+Ref<Gradient> Gradient::create(RadialData&& data)
+{
+    return adoptRef(*new Gradient(WTFMove(data)));
+}
+
+Gradient::Gradient(LinearData&& data)
+    : m_data(WTFMove(data))
+{
</ins><span class="cx">     platformInit();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Gradient::Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio)
-    : m_radial(true)
-    , m_p0(p0)
-    , m_p1(p1)
-    , m_r0(r0)
-    , m_r1(r1)
-    , m_aspectRatio(aspectRatio)
-    , m_stopsSorted(false)
-    , m_spreadMethod(SpreadMethodPad)
-    , m_cachedHash(0)
</del><ins>+Gradient::Gradient(RadialData&& data)
+    : m_data(WTFMove(data))
</ins><span class="cx"> {
</span><span class="cx">     platformInit();
</span><span class="cx"> }
</span><span class="lines">@@ -69,11 +63,20 @@
</span><span class="cx">     platformDestroy();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+auto Gradient::type() const -> Type
+{
+    return WTF::switchOn(m_data,
+        [] (const LinearData&) {
+            return Type::Linear;
+        },
+        [] (const RadialData&) {
+            return Type::Radial;
+        }
+    );
+}
+
</ins><span class="cx"> void Gradient::adjustParametersForTiledDrawing(FloatSize& size, FloatRect& srcRect, const FloatSize& spacing)
</span><span class="cx"> {
</span><del>-    if (m_radial)
-        return;
-
</del><span class="cx">     if (srcRect.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -80,37 +83,60 @@
</span><span class="cx">     if (!spacing.isZero())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (m_p0.x() == m_p1.x()) {
-        size.setWidth(1);
-        srcRect.setWidth(1);
-        srcRect.setX(0);
-        return;
-    }
-    if (m_p0.y() != m_p1.y())
-        return;
</del><ins>+    WTF::switchOn(m_data,
+        [&] (const LinearData& data) {
+            if (data.point0.x() == data.point1.x()) {
+                size.setWidth(1);
+                srcRect.setWidth(1);
+                srcRect.setX(0);
+                return;
+            }
+            if (data.point0.y() != data.point1.y())
+                return;
</ins><span class="cx"> 
</span><del>-    size.setHeight(1);
-    srcRect.setHeight(1);
-    srcRect.setY(0);
</del><ins>+            size.setHeight(1);
+            srcRect.setHeight(1);
+            srcRect.setY(0);
+        },
+        [] (const RadialData&) {
+        }
+    );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Gradient::isZeroSize() const
+{
+    return WTF::switchOn(m_data,
+        [] (const LinearData& data) {
+            return data.point0.x() == data.point1.x() && data.point0.y() == data.point1.y();
+        },
+        [] (const RadialData& data) {
+            return data.point0.x() == data.point1.x() && data.point0.y() == data.point1.y() && data.startRadius == data.endRadius;
+        }
+    );
+}
+
</ins><span class="cx"> void Gradient::addColorStop(float offset, const Color& color)
</span><span class="cx"> {
</span><del>-    m_stops.append(ColorStop(offset, color));
</del><ins>+    addColorStop({ offset, color });
+}
</ins><span class="cx"> 
</span><ins>+void Gradient::addColorStop(const Gradient::ColorStop& stop)
+{
+    m_stops.append(stop);
+
</ins><span class="cx">     m_stopsSorted = false;
</span><ins>+
</ins><span class="cx">     platformDestroy();
</span><del>-
</del><span class="cx">     invalidateHash();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Gradient::addColorStop(const Gradient::ColorStop& stop)
</del><ins>+void Gradient::setSortedColorStops(ColorStopVector&& stops)
</ins><span class="cx"> {
</span><del>-    m_stops.append(stop);
</del><ins>+    m_stops = WTFMove(stops);
</ins><span class="cx"> 
</span><del>-    m_stopsSorted = false;
</del><ins>+    m_stopsSorted = true;
+
</ins><span class="cx">     platformDestroy();
</span><del>-
</del><span class="cx">     invalidateHash();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -130,7 +156,6 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     std::stable_sort(m_stops.begin(), m_stops.end(), compareStops);
</span><del>-
</del><span class="cx">     invalidateHash();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -173,14 +198,14 @@
</span><span class="cx">         return m_cachedHash;
</span><span class="cx"> 
</span><span class="cx">     struct {
</span><del>-        AffineTransform gradientSpaceTransformation;
-        FloatPoint p0;
-        FloatPoint p1;
-        float r0;
-        float r1;
</del><ins>+        Type type;
+        FloatPoint point0;
+        FloatPoint point1;
+        float startRadius;
+        float endRadius;
</ins><span class="cx">         float aspectRatio;
</span><span class="cx">         GradientSpreadMethod spreadMethod;
</span><del>-        bool radial;
</del><ins>+        AffineTransform gradientSpaceTransformation;
</ins><span class="cx">     } parameters;
</span><span class="cx"> 
</span><span class="cx">     // StringHasher requires that the memory it hashes be a multiple of two in size.
</span><span class="lines">@@ -190,14 +215,27 @@
</span><span class="cx">     // Ensure that any padding in the struct is zero-filled, so it will not affect the hash value.
</span><span class="cx">     memset(&parameters, 0, sizeof(parameters));
</span><span class="cx">     
</span><ins>+    WTF::switchOn(m_data,
+        [&parameters] (const LinearData& data) {
+            parameters.point0 = data.point0;
+            parameters.point1 = data.point1;
+            parameters.startRadius = 0;
+            parameters.endRadius = 0;
+            parameters.aspectRatio = 0;
+            parameters.type = Type::Linear;
+        },
+        [&parameters] (const RadialData& data) {
+            parameters.point0 = data.point0;
+            parameters.point1 = data.point1;
+            parameters.startRadius = data.startRadius;
+            parameters.endRadius = data.endRadius;
+            parameters.aspectRatio = data.aspectRatio;
+            parameters.type = Type::Radial;
+        }
+    );
+
+    parameters.spreadMethod = m_spreadMethod;
</ins><span class="cx">     parameters.gradientSpaceTransformation = m_gradientSpaceTransformation;
</span><del>-    parameters.p0 = m_p0;
-    parameters.p1 = m_p1;
-    parameters.r0 = m_r0;
-    parameters.r1 = m_r1;
-    parameters.aspectRatio = m_aspectRatio;
-    parameters.spreadMethod = m_spreadMethod;
-    parameters.radial = m_radial;
</del><span class="cx"> 
</span><span class="cx">     unsigned parametersHash = StringHasher::hashMemory(&parameters, sizeof(parameters));
</span><span class="cx">     unsigned stopHash = StringHasher::hashMemory(m_stops.data(), m_stops.size() * sizeof(ColorStop));
</span><span class="lines">@@ -207,4 +245,4 @@
</span><span class="cx">     return m_cachedHash;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-} //namespace
</del><ins>+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGradienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Gradient.h (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Gradient.h        2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/Gradient.h   2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -25,8 +25,7 @@
</span><span class="cx">  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef Gradient_h
-#define Gradient_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #include "AffineTransform.h"
</span><span class="cx"> #include "Color.h"
</span><span class="lines">@@ -33,15 +32,13 @@
</span><span class="cx"> #include "FloatPoint.h"
</span><span class="cx"> #include "GraphicsTypes.h"
</span><span class="cx"> #include <wtf/RefCounted.h>
</span><ins>+#include <wtf/Variant.h>
</ins><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx"> 
</span><span class="cx"> #if USE(CG)
</span><del>-
</del><span class="cx"> typedef struct CGContext* CGContextRef;
</span><del>-
</del><span class="cx"> typedef struct CGGradient* CGGradientRef;
</span><span class="cx"> typedef CGGradientRef PlatformGradient;
</span><del>-
</del><span class="cx"> #elif USE(DIRECT2D)
</span><span class="cx"> interface ID2D1Brush;
</span><span class="cx"> interface ID2D1RenderTarget;
</span><span class="lines">@@ -55,152 +52,108 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-    class Color;
-    class FloatRect;
-    class GraphicsContext;
</del><ins>+class Color;
+class FloatRect;
+class GraphicsContext;
</ins><span class="cx"> 
</span><del>-    class Gradient : public RefCounted<Gradient> {
-    public:
-        static Ref<Gradient> create(const FloatPoint& p0, const FloatPoint& p1)
</del><ins>+class Gradient : public RefCounted<Gradient> {
+public:
+    // FIXME: ExtendedColor - A color stop needs a notion of color space.
+    struct ColorStop {
+        float offset { 0 };
+        Color color;
+
+        ColorStop() = default;
+        ColorStop(float offset, const Color& color)
+            : offset(offset)
+            , color(color)
</ins><span class="cx">         {
</span><del>-            return adoptRef(*new Gradient(p0, p1));
</del><span class="cx">         }
</span><del>-        static Ref<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio = 1)
-        {
-            return adoptRef(*new Gradient(p0, r0, p1, r1, aspectRatio));
-        }
-        WEBCORE_EXPORT ~Gradient();
</del><ins>+    };
</ins><span class="cx"> 
</span><del>-        struct ColorStop;
-        WEBCORE_EXPORT void addColorStop(const ColorStop&);
-        WEBCORE_EXPORT void addColorStop(float, const Color&);
</del><ins>+    using ColorStopVector = Vector<ColorStop, 2>;
</ins><span class="cx"> 
</span><del>-        bool hasAlpha() const;
</del><ins>+    struct LinearData {
+        FloatPoint point0;
+        FloatPoint point1;
+    };
</ins><span class="cx"> 
</span><del>-        bool isRadial() const { return m_radial; }
-        bool isZeroSize() const { return m_p0.x() == m_p1.x() && m_p0.y() == m_p1.y() && (!m_radial || m_r0 == m_r1); }
</del><ins>+    struct RadialData {
+        FloatPoint point0;
+        FloatPoint point1;
+        float startRadius;
+        float endRadius;
+        float aspectRatio; // For elliptical gradient, width / height.
+    };
</ins><span class="cx"> 
</span><del>-        const FloatPoint& p0() const { return m_p0; }
-        const FloatPoint& p1() const { return m_p1; }
</del><ins>+    using Data = Variant<LinearData, RadialData>;
</ins><span class="cx"> 
</span><del>-        void setP0(const FloatPoint& p)
-        {
-            if (m_p0 == p)
-                return;
-            
-            m_p0 = p;
-            
-            invalidateHash();
-        }
-        
-        void setP1(const FloatPoint& p)
-        {
-            if (m_p1 == p)
-                return;
-            
-            m_p1 = p;
-            
-            invalidateHash();
-        }
</del><ins>+    enum class Type { Linear, Radial };
</ins><span class="cx"> 
</span><del>-        float startRadius() const { return m_r0; }
-        float endRadius() const { return m_r1; }
</del><ins>+    static Ref<Gradient> create(LinearData&&);
+    static Ref<Gradient> create(RadialData&&);
</ins><span class="cx"> 
</span><del>-        void setStartRadius(float r)
-        {
-            if (m_r0 == r)
-                return;
</del><ins>+    WEBCORE_EXPORT ~Gradient();
</ins><span class="cx"> 
</span><del>-            m_r0 = r;
</del><ins>+    Type type() const;
</ins><span class="cx"> 
</span><del>-            invalidateHash();
-        }
</del><ins>+    bool hasAlpha() const;
+    bool isZeroSize() const;
</ins><span class="cx"> 
</span><del>-        void setEndRadius(float r)
-        {
-            if (m_r1 == r)
-                return;
</del><ins>+    const Data& data() const { return m_data; }
</ins><span class="cx"> 
</span><del>-            m_r1 = r;
</del><ins>+    WEBCORE_EXPORT void addColorStop(const ColorStop&);
+    WEBCORE_EXPORT void addColorStop(float, const Color&);
+    void setSortedColorStops(ColorStopVector&&);
</ins><span class="cx"> 
</span><del>-            invalidateHash();
-        }
</del><ins>+    const ColorStopVector& stops() const { return m_stops; }
</ins><span class="cx"> 
</span><del>-        float aspectRatio() const { return m_aspectRatio; }
</del><ins>+    void setSpreadMethod(GradientSpreadMethod);
+    GradientSpreadMethod spreadMethod() const { return m_spreadMethod; }
</ins><span class="cx"> 
</span><del>-#if USE(WINGDI)
-        const Vector<ColorStop, 2>& getStops() const;
-#else
-        PlatformGradient platformGradient();
-#endif
</del><ins>+    // CG needs to transform the gradient at draw time.
+    void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
+    const AffineTransform& gradientSpaceTransform() { return m_gradientSpaceTransformation; }
</ins><span class="cx"> 
</span><del>-        // FIXME: ExtendedColor - A color stop needs a notion of color space.
-        struct ColorStop {
-            float offset { 0 };
-            Color color;
</del><ins>+    void fill(GraphicsContext&, const FloatRect&);
+    void adjustParametersForTiledDrawing(FloatSize&, FloatRect&, const FloatSize& spacing);
</ins><span class="cx"> 
</span><del>-            ColorStop() { }
-            ColorStop(float offset, const Color& color)
-                : offset(offset)
-                , color(color)
-                { }
-        };
</del><ins>+    unsigned hash() const;
+    void invalidateHash() { m_cachedHash = 0; }
</ins><span class="cx"> 
</span><del>-        const Vector<ColorStop, 2>& stops() const { return m_stops; }
-
-        void setStopsSorted(bool s) { m_stopsSorted = s; }
-        
-        void setSpreadMethod(GradientSpreadMethod);
-        GradientSpreadMethod spreadMethod() { return m_spreadMethod; }
-        void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
-        // Qt and CG transform the gradient at draw time
-        AffineTransform gradientSpaceTransform() { return m_gradientSpaceTransformation; }
-
-        void fill(GraphicsContext*, const FloatRect&);
-        void adjustParametersForTiledDrawing(FloatSize&, FloatRect&, const FloatSize& spacing);
-
-        unsigned hash() const;
-        void invalidateHash() { m_cachedHash = 0; }
-
</del><span class="cx"> #if USE(CG)
</span><del>-        void paint(CGContextRef);
-        void paint(GraphicsContext*);
</del><ins>+    void paint(GraphicsContext&);
+    void paint(CGContextRef);
</ins><span class="cx"> #elif USE(DIRECT2D)
</span><del>-        PlatformGradient createPlatformGradientIfNecessary(ID2D1RenderTarget*);
</del><ins>+    PlatformGradient createPlatformGradientIfNecessary(ID2D1RenderTarget*);
</ins><span class="cx"> #elif USE(CAIRO)
</span><del>-        PlatformGradient createPlatformGradient(float globalAlpha);
</del><ins>+    PlatformGradient createPlatformGradient(float globalAlpha);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    private:
-        WEBCORE_EXPORT Gradient(const FloatPoint& p0, const FloatPoint& p1);
-        Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio);
</del><ins>+private:
+    Gradient(LinearData&&);
+    Gradient(RadialData&&);
</ins><span class="cx"> 
</span><del>-        void platformInit() { m_gradient = nullptr; }
-        void platformDestroy();
</del><ins>+    PlatformGradient platformGradient();
+    void platformInit() { m_gradient = nullptr; }
+    void platformDestroy();
</ins><span class="cx"> 
</span><del>-        void sortStopsIfNecessary();
</del><ins>+    void sortStopsIfNecessary();
</ins><span class="cx"> 
</span><span class="cx"> #if USE(DIRECT2D)
</span><del>-        void generateGradient(ID2D1RenderTarget*);
</del><ins>+    void generateGradient(ID2D1RenderTarget*);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        // Keep any parameters relevant to rendering in sync with the structure in Gradient::hash().
-        bool m_radial;
-        FloatPoint m_p0;
-        FloatPoint m_p1;
-        float m_r0;
-        float m_r1;
-        float m_aspectRatio; // For elliptical gradient, width / height.
-        mutable Vector<ColorStop, 2> m_stops;
-        mutable bool m_stopsSorted;
-        GradientSpreadMethod m_spreadMethod;
-        AffineTransform m_gradientSpaceTransformation;
</del><ins>+    Data m_data;
</ins><span class="cx"> 
</span><del>-        mutable unsigned m_cachedHash;
</del><ins>+    mutable ColorStopVector m_stops;
+    mutable bool m_stopsSorted { false };
+    GradientSpreadMethod m_spreadMethod { SpreadMethodPad };
+    AffineTransform m_gradientSpaceTransformation;
</ins><span class="cx"> 
</span><del>-        PlatformGradient m_gradient;
-    };
</del><ins>+    mutable unsigned m_cachedHash { 0 };
</ins><span class="cx"> 
</span><del>-} //namespace
</del><ins>+    PlatformGradient m_gradient;
+};
</ins><span class="cx"> 
</span><del>-#endif
</del><ins>+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp       2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp  2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -852,7 +852,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    gradient.fill(this, rect);
</del><ins>+    gradient.fill(*this, rect);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoGradientCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp   2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp      2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -42,11 +42,14 @@
</span><span class="cx"> 
</span><span class="cx"> cairo_pattern_t* Gradient::createPlatformGradient(float globalAlpha)
</span><span class="cx"> {
</span><del>-    cairo_pattern_t* gradient;
-    if (m_radial)
-        gradient = cairo_pattern_create_radial(m_p0.x(), m_p0.y(), m_r0, m_p1.x(), m_p1.y(), m_r1);
-    else
-        gradient = cairo_pattern_create_linear(m_p0.x(), m_p0.y(), m_p1.x(), m_p1.y());
</del><ins>+    cairo_pattern_t* gradient = WTF::switchOn(m_data,
+        [&] (const LinearData& data) -> cairo_pattern_t* {
+            return cairo_pattern_create_linear(data.point0.x(), data.point0.y(), data.point1.x(), data.point1.y());
+        },
+        [&] (const RadialData& data) -> cairo_pattern_t* {
+            return cairo_pattern_create_radial(data.point0.x(), data.point0.y(), data.startRadius, data.point1.x(), data.point1.y(), data.endRadius);
+        }
+    );
</ins><span class="cx"> 
</span><span class="cx">     for (const auto& stop : m_stops) {
</span><span class="cx">         if (stop.color.isExtended()) {
</span><span class="lines">@@ -78,14 +81,14 @@
</span><span class="cx">     return gradient;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Gradient::fill(GraphicsContext* context, const FloatRect& rect)
</del><ins>+void Gradient::fill(GraphicsContext& context, const FloatRect& rect)
</ins><span class="cx"> {
</span><span class="cx">     RefPtr<cairo_pattern_t> platformGradient = adoptRef(createPlatformGradient(1.0));
</span><span class="cx"> 
</span><del>-    context->save();
-    ASSERT(context->hasPlatformContext());
-    Cairo::fillRect(*context->platformContext(), rect, platformGradient.get());
-    context->restore();
</del><ins>+    context.save();
+    ASSERT(context.hasPlatformContext());
+    Cairo::fillRect(*context.platformContext(), rect, platformGradient.get());
+    context.restore();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgGradientCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp 2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp    2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -38,7 +38,7 @@
</span><span class="cx"> void Gradient::platformDestroy()
</span><span class="cx"> {
</span><span class="cx">     CGGradientRelease(m_gradient);
</span><del>-    m_gradient = 0;
</del><ins>+    m_gradient = nullptr;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CGGradientRef Gradient::platformGradient()
</span><span class="lines">@@ -92,43 +92,45 @@
</span><span class="cx">     return m_gradient;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Gradient::fill(GraphicsContext* context, const FloatRect& rect)
</del><ins>+void Gradient::fill(GraphicsContext& context, const FloatRect& rect)
</ins><span class="cx"> {
</span><del>-    context->clip(rect);
</del><ins>+    context.clip(rect);
</ins><span class="cx">     paint(context);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Gradient::paint(GraphicsContext* context)
</del><ins>+void Gradient::paint(GraphicsContext& context)
</ins><span class="cx"> {
</span><del>-    CGContextRef ctx = context->platformContext();
-    paint(ctx);
</del><ins>+    paint(context.platformContext());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Gradient::paint(CGContextRef context)
</del><ins>+void Gradient::paint(CGContextRef platformContext)
</ins><span class="cx"> {
</span><span class="cx">     CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
</span><del>-    if (!m_radial) {
-        CGContextDrawLinearGradient(context, platformGradient(), m_p0, m_p1, extendOptions);
-        return;
-    }
</del><span class="cx"> 
</span><del>-    bool needScaling = aspectRatio() != 1;
-    if (needScaling) {
-        CGContextSaveGState(context);
-        // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
-        // for which m_p0 == m_p1.
-        ASSERT(m_p0 == m_p1);
-        CGContextTranslateCTM(context, m_p0.x(), m_p0.y());
-        CGContextScaleCTM(context, 1, 1 / aspectRatio());
-        CGContextTranslateCTM(context, -m_p0.x(), -m_p0.y());
-    }
</del><ins>+    WTF::switchOn(m_data,
+        [&] (const LinearData& data) {
+            CGContextDrawLinearGradient(platformContext, platformGradient(), data.point0, data.point1, extendOptions);
+        },
+        [&] (const RadialData& data) {
+            bool needScaling = data.aspectRatio != 1;
+            if (needScaling) {
+                CGContextSaveGState(platformContext);
+                // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
+                // for which point0 == point1.
+                ASSERT(data.point0 == data.point1);
+                CGContextTranslateCTM(platformContext, data.point0.x(), data.point0.y());
+                CGContextScaleCTM(platformContext, 1, 1 / data.aspectRatio);
+                CGContextTranslateCTM(platformContext, -data.point0.x(), -data.point0.y());
+            }
</ins><span class="cx"> 
</span><del>-    CGContextDrawRadialGradient(context, platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);
</del><ins>+            CGContextDrawRadialGradient(platformContext, platformGradient(), data.point0, data.startRadius, data.point1, data.endRadius, extendOptions);
</ins><span class="cx"> 
</span><del>-    if (needScaling)
-        CGContextRestoreGState(context);
</del><ins>+            if (needScaling)
+                CGContextRestoreGState(platformContext);
+        }
+    );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-} //namespace
</del><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgGraphicsContextCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp  2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp     2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -777,7 +777,7 @@
</span><span class="cx">             else
</span><span class="cx">                 CGContextClip(context);
</span><span class="cx"> 
</span><del>-            m_state.fillGradient->paint(this);
</del><ins>+            m_state.fillGradient->paint(*this);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return;
</span><span class="lines">@@ -848,7 +848,7 @@
</span><span class="cx">             CGContextReplacePathWithStrokedPath(context);
</span><span class="cx">             CGContextClip(context);
</span><span class="cx">             CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
</span><del>-            m_state.strokeGradient->paint(this);
</del><ins>+            m_state.strokeGradient->paint(*this);
</ins><span class="cx">         }
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -896,7 +896,7 @@
</span><span class="cx">         } else {
</span><span class="cx">             CGContextClipToRect(context, rect);
</span><span class="cx">             CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
</span><del>-            m_state.fillGradient->paint(this);
</del><ins>+            m_state.fillGradient->paint(*this);
</ins><span class="cx">         }
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -1323,7 +1323,7 @@
</span><span class="cx">             CGContextReplacePathWithStrokedPath(context);
</span><span class="cx">             CGContextClip(context);
</span><span class="cx">             CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
</span><del>-            m_state.strokeGradient->paint(this);
</del><ins>+            m_state.strokeGradient->paint(*this);
</ins><span class="cx">         }
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGradientDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp  2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/platform/graphics/win/GradientDirect2D.cpp     2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -78,62 +78,78 @@
</span><span class="cx">         m_gradient = nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (m_radial) {
-        FloatSize offset = p1() - p0();
-        ID2D1RadialGradientBrush* radialGradient = nullptr;
-        float radiusX = endRadius() + offset.width();
-        float radiusY = radiusX / m_aspectRatio;
-        hr = renderTarget->CreateRadialGradientBrush(
-            D2D1::RadialGradientBrushProperties(p0(), D2D1::Point2F(offset.width(), offset.height()), radiusX, radiusY),
-            D2D1::BrushProperties(), gradientStopCollection.get(),
-            &radialGradient);
-        RELEASE_ASSERT(SUCCEEDED(hr));
-        m_gradient = radialGradient;
-    } else {
-        ID2D1LinearGradientBrush* linearGradient = nullptr;
-        hr = renderTarget->CreateLinearGradientBrush(
-            D2D1::LinearGradientBrushProperties(p0(), p1()),
-            D2D1::BrushProperties(), gradientStopCollection.get(),
-            &linearGradient);
-        RELEASE_ASSERT(SUCCEEDED(hr));
-        m_gradient = linearGradient;
-    }
</del><ins>+    WTF::switchOn(m_data,
+        [&] (const LinearData& data) {
+            ID2D1LinearGradientBrush* linearGradient = nullptr;
+            hr = renderTarget->CreateLinearGradientBrush(
+                D2D1::LinearGradientBrushProperties(data.point0, data.point1),
+                D2D1::BrushProperties(), gradientStopCollection.get(),
+                &linearGradient);
+            RELEASE_ASSERT(SUCCEEDED(hr));
+            m_gradient = linearGradient;
+        },
+        [&] (const RadialData& data) {
+            FloatSize offset = data.point1 - data.point0;
+            ID2D1RadialGradientBrush* radialGradient = nullptr;
+            float radiusX = data.endRadius + offset.width();
+            float radiusY = radiusX / data.aspectRatio;
+            hr = renderTarget->CreateRadialGradientBrush(
+                D2D1::RadialGradientBrushProperties(p0(), D2D1::Point2F(offset.width(), offset.height()), radiusX, radiusY),
+                D2D1::BrushProperties(), gradientStopCollection.get(),
+                &radialGradient);
+            RELEASE_ASSERT(SUCCEEDED(hr));
+            m_gradient = radialGradient;
+        }
+    );
</ins><span class="cx"> 
</span><span class="cx">     hash();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Gradient::fill(GraphicsContext* context, const FloatRect& rect)
</del><ins>+void Gradient::fill(GraphicsContext& context, const FloatRect& rect)
</ins><span class="cx"> {
</span><del>-    auto d2dContext = context->platformContext();
</del><ins>+    auto d2dContext = context.platformContext();
</ins><span class="cx"> 
</span><del>-    bool needScaling = aspectRatio() != 1;
-    if (needScaling) {
-        context->save();
-        // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
-        // for which m_p0 == m_p1.
-        ASSERT(m_p0 == m_p1);
</del><ins>+    WTF::switchOn(m_data,
+        [&] (const LinearData& data) {
+            if (!m_cachedHash || !m_gradient)
+                generateGradient(d2dContext);
</ins><span class="cx"> 
</span><del>-        D2D1_MATRIX_3X2_F ctm = { };
-        d2dContext->GetTransform(&ctm);
</del><ins>+            d2dContext->SetTags(GRADIENT_DRAWING, __LINE__);
</ins><span class="cx"> 
</span><del>-        AffineTransform transform(ctm);
-        transform.translate(m_p0);
-        transform.scaleNonUniform(1.0, 1.0 / aspectRatio());
-        transform.translate(-m_p0);
</del><ins>+            const D2D1_RECT_F d2dRect = rect;
+            d2dContext->FillRectangle(&d2dRect, m_gradient);
+        },
+        [&] (const RadialData& data) {
+            bool needScaling = data.aspectRatio != 1;
+            if (needScaling) {
+                context.save();
+                // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
+                // for which m_p0 == m_p1.
+                ASSERT(data.point0 == data.point1);
</ins><span class="cx"> 
</span><del>-        d2dContext->SetTransform(ctm);
-    }
</del><ins>+                D2D1_MATRIX_3X2_F ctm = { };
+                d2dContext->GetTransform(&ctm);
</ins><span class="cx"> 
</span><del>-    if (!m_cachedHash || !m_gradient)
-        generateGradient(d2dContext);
</del><ins>+                AffineTransform transform(ctm);
+                transform.translate(data.point0);
+                transform.scaleNonUniform(1.0, 1.0 / data.aspectRatio);
+                transform.translate(-data.point0);
</ins><span class="cx"> 
</span><del>-    d2dContext->SetTags(GRADIENT_DRAWING, __LINE__);
</del><ins>+                d2dContext->SetTransform(ctm);
+            }
</ins><span class="cx"> 
</span><del>-    const D2D1_RECT_F d2dRect = rect;
-    d2dContext->FillRectangle(&d2dRect, m_gradient);
</del><ins>+            if (!m_cachedHash || !m_gradient)
+                generateGradient(d2dContext);
</ins><span class="cx"> 
</span><del>-    if (needScaling)
-        context->restore();
</del><ins>+            d2dContext->SetTags(GRADIENT_DRAWING, __LINE__);
+
+            const D2D1_RECT_F d2dRect = rect;
+            d2dContext->FillRectangle(&d2dRect, m_gradient);
+
+            if (needScaling)
+                context.restore();
+        }
+    );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderThemeIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm 2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm    2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -897,7 +897,7 @@
</span><span class="cx">     context.setStrokeStyle(SolidStroke);
</span><span class="cx"> 
</span><span class="cx">     const float verticalRenderingPosition = rect.y() + verticalOffset;
</span><del>-    RefPtr<Gradient> strokeGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1));
</del><ins>+    RefPtr<Gradient> strokeGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
</ins><span class="cx">     strokeGradient->addColorStop(0.0, Color(0x8d, 0x8d, 0x8d));
</span><span class="cx">     strokeGradient->addColorStop(0.45, Color(0xee, 0xee, 0xee));
</span><span class="cx">     strokeGradient->addColorStop(0.55, Color(0xee, 0xee, 0xee));
</span><span class="lines">@@ -917,7 +917,7 @@
</span><span class="cx">     paintInfo.context().clipRoundedRect(FloatRoundedRect(border, roundedCornerRadius, roundedCornerRadius, roundedCornerRadius, roundedCornerRadius));
</span><span class="cx"> 
</span><span class="cx">     float upperGradientHeight = progressBarHeight / 2.;
</span><del>-    RefPtr<Gradient> upperGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + upperGradientHeight - 1.5));
</del><ins>+    RefPtr<Gradient> upperGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + upperGradientHeight - 1.5) });
</ins><span class="cx">     upperGradient->addColorStop(0.0, Color(133, 133, 133, 188));
</span><span class="cx">     upperGradient->addColorStop(1.0, Color(18, 18, 18, 51));
</span><span class="cx">     context.setFillGradient(upperGradient.releaseNonNull());
</span><span class="lines">@@ -929,7 +929,7 @@
</span><span class="cx">         // 2) Draw the progress bar.
</span><span class="cx">         double position = clampTo(renderProgress.position(), 0.0, 1.0);
</span><span class="cx">         double barWidth = position * rect.width();
</span><del>-        RefPtr<Gradient> barGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1));
</del><ins>+        RefPtr<Gradient> barGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
</ins><span class="cx">         barGradient->addColorStop(0.0, Color(195, 217, 247));
</span><span class="cx">         barGradient->addColorStop(0.45, Color(118, 164, 228));
</span><span class="cx">         barGradient->addColorStop(0.49, Color(118, 164, 228));
</span><span class="lines">@@ -938,7 +938,7 @@
</span><span class="cx">         barGradient->addColorStop(1.0, Color(57, 142, 244));
</span><span class="cx">         context.setFillGradient(barGradient.releaseNonNull());
</span><span class="cx"> 
</span><del>-        RefPtr<Gradient> barStrokeGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1));
</del><ins>+        RefPtr<Gradient> barStrokeGradient = Gradient::create(Gradient::LinearData { FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1) });
</ins><span class="cx">         barStrokeGradient->addColorStop(0.0, Color(95, 107, 183));
</span><span class="cx">         barStrokeGradient->addColorStop(0.5, Color(66, 106, 174, 240));
</span><span class="cx">         barStrokeGradient->addColorStop(1.0, Color(38, 104, 166));
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingsvgRenderSVGResourceLinearGradientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp   2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp      2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderSVGResourceLinearGradient::buildGradient(GradientData* gradientData) const
</span><span class="cx"> {
</span><del>-    gradientData->gradient = Gradient::create(startPoint(m_attributes), endPoint(m_attributes));
</del><ins>+    gradientData->gradient = Gradient::create(Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) });
</ins><span class="cx">     gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
</span><span class="cx">     addStops(gradientData, m_attributes.stops());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingsvgRenderSVGResourceRadialGradientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp (225035 => 225036)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp   2017-11-19 21:57:13 UTC (rev 225035)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp      2017-11-19 23:06:03 UTC (rev 225036)
</span><span class="lines">@@ -63,11 +63,7 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderSVGResourceRadialGradient::buildGradient(GradientData* gradientData) const
</span><span class="cx"> {
</span><del>-    gradientData->gradient = Gradient::create(this->focalPoint(m_attributes),
-        this->focalRadius(m_attributes),
-        this->centerPoint(m_attributes),
-        this->radius(m_attributes));
-
</del><ins>+    gradientData->gradient = Gradient::create(Gradient::RadialData { this->focalPoint(m_attributes), this->centerPoint(m_attributes), this->focalRadius(m_attributes), this->radius(m_attributes), 1 });
</ins><span class="cx">     gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
</span><span class="cx"> 
</span><span class="cx">     addStops(gradientData, m_attributes.stops());
</span></span></pre>
</div>
</div>

</body>
</html>