Title: [287411] trunk
Revision
287411
Author
wei...@apple.com
Date
2021-12-23 13:35:00 -0800 (Thu, 23 Dec 2021)

Log Message

Encapsulate gradient color stops into a self contained class
https://bugs.webkit.org/show_bug.cgi?id=234583

Reviewed by Simon Fraser.

Source/WebCore:

Replace most uses of Gradient::ColorStopVector with new GradientColorStops class.

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
Add new file.

* css/CSSGradientValue.h:
* css/CSSGradientValue.cpp:
(WebCore::CSSGradientValue::computeStops):
Replace some usage of Gradient::ColorStopVector with GradientColorStops. While here,
optimize color filter transformation to only happen when there is color filter,
removing extra unnecessary copies of Colors.

Also utilizes the GradientColorStops::Sorted type to create a GradientColorStops
object that has the isSorted bit set.

(WebCore::CSSLinearGradientValue::createGradient):
(WebCore::CSSRadialGradientValue::createGradient):
(WebCore::CSSConicGradientValue::createGradient):
The calls to setSortedColorStops is no longer needed, as the GradientColorStops
now maintains that state.

* platform/graphics/Color.h:
(WebCore::add):
Move definition of add(Hasher&, Color) here, where it makes sense, rather than
keeping it in Gradient.

* platform/graphics/FloatPoint.h:
(WebCore::add):
Move definition of add(Hasher&, FloatPoint) here, where it makes sense, rather than
keeping it in Gradient.

* platform/graphics/Gradient.h:
* platform/graphics/Gradient.cpp:
(WebCore::Gradient::create):
(WebCore::Gradient::Gradient):
(WebCore::Gradient::addColorStop):
(WebCore::Gradient::hash const):
(WebCore::Gradient::setSortedColorStops): Deleted.
(WebCore::Gradient::sortStops const): Deleted.
Replace ColorStopVector with GradientColorStops. This allows removing the m_stopsSorted
bit, as the new class maintains that, as well as removing setSortedColorStops since
you can achieve this by just creating the Gradient with a GradientColorStops that knows
it is sorted (using the GradientColorStops::Sorted helper).

* platform/graphics/GradientColorStop.h:
(WebCore::add):
Move definition of add(Hasher&, GradientColorStop) here, where it makes sense, rather than
keeping it in Gradient.

* platform/graphics/GradientColorStops.h: Added.
(WebCore::GradientColorStops::GradientColorStops):
(WebCore::GradientColorStops::addColorStop):
(WebCore::GradientColorStops::sort):
(WebCore::GradientColorStops::sorted const):
(WebCore::GradientColorStops::size const):
(WebCore::GradientColorStops::isEmpty const):
(WebCore::GradientColorStops::begin const):
(WebCore::GradientColorStops::end const):
(WebCore::GradientColorStops::mapColors const):
(WebCore::GradientColorStops::stops const):
(WebCore::GradientColorStops::validateIsSorted const):
(WebCore::GradientColorStops::encode const):
(WebCore::GradientColorStops::decode):
Encapsulate state and functionality of the gradient color stop list, maintaining
the sorted state, and providing a pleasent API to work with. In the future, this
will be a good place to add functions to analyze and transform the list for optimizing
what can use the gradient fast paths.

* platform/graphics/cairo/GradientCairo.cpp:
Update to use the new names.

* platform/graphics/cg/GradientCG.cpp:
(WebCore::Gradient::paint):
Ensure the color stops passed to the gradient renderer are sorted using the sorted()
helper, which does an inplace sort and returns a reference to itself.

* platform/graphics/cg/GradientRendererCG.h:
* platform/graphics/cg/GradientRendererCG.cpp:
(WebCore::GradientRendererCG::GradientRendererCG):
(WebCore::GradientRendererCG::pickStrategy const):
(WebCore::GradientRendererCG::makeGradient const):
(WebCore::GradientRendererCG::makeShading const):
Replace uses of GradientColorStopVector with GradientColorStops.

* rendering/svg/RenderSVGResourceGradient.h:
* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::RenderSVGResourceGradient::stopsByApplyingColorFilter):
Add early return if there is no color filter to apply, and utilize the mapColors()
function to update the colors if there is.

* rendering/svg/RenderSVGResourceLinearGradient.cpp:
(WebCore::RenderSVGResourceLinearGradient::buildGradient const):
* rendering/svg/RenderSVGResourceRadialGradient.cpp:
(WebCore::RenderSVGResourceRadialGradient::buildGradient const):
Remove some extraneous type names.

* svg/GradientAttributes.h:
(WebCore::GradientAttributes::stops const):
(WebCore::GradientAttributes::setStops):
* svg/SVGGradientElement.cpp:
(WebCore::SVGGradientElement::buildStops):
* svg/SVGGradientElement.h:
Replace uses of GradientColorStopVector with GradientColorStops.

Tools:

* TestRunnerShared/PlatformGTK.cmake: Added.
* TestRunnerShared/PlatformWPE.cmake: Added.
Keep GTK and WPE ports building by propogating glib.h header to the test runnner. Change
by Fujii Hironori.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287410 => 287411)


--- trunk/Source/WebCore/ChangeLog	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/ChangeLog	2021-12-23 21:35:00 UTC (rev 287411)
@@ -1,3 +1,115 @@
+2021-12-23  Sam Weinig  <wei...@apple.com>
+
+        Encapsulate gradient color stops into a self contained class
+        https://bugs.webkit.org/show_bug.cgi?id=234583
+
+        Reviewed by Simon Fraser.
+
+        Replace most uses of Gradient::ColorStopVector with new GradientColorStops class.
+
+        * Headers.cmake:
+        * WebCore.xcodeproj/project.pbxproj:
+        Add new file.
+
+        * css/CSSGradientValue.h:
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSGradientValue::computeStops):
+        Replace some usage of Gradient::ColorStopVector with GradientColorStops. While here,
+        optimize color filter transformation to only happen when there is color filter,
+        removing extra unnecessary copies of Colors.
+
+        Also utilizes the GradientColorStops::Sorted type to create a GradientColorStops
+        object that has the isSorted bit set.
+ 
+        (WebCore::CSSLinearGradientValue::createGradient):
+        (WebCore::CSSRadialGradientValue::createGradient):
+        (WebCore::CSSConicGradientValue::createGradient):
+        The calls to setSortedColorStops is no longer needed, as the GradientColorStops
+        now maintains that state.
+
+        * platform/graphics/Color.h:
+        (WebCore::add):
+        Move definition of add(Hasher&, Color) here, where it makes sense, rather than
+        keeping it in Gradient.
+
+        * platform/graphics/FloatPoint.h:
+        (WebCore::add):
+        Move definition of add(Hasher&, FloatPoint) here, where it makes sense, rather than
+        keeping it in Gradient.
+
+        * platform/graphics/Gradient.h:
+        * platform/graphics/Gradient.cpp:
+        (WebCore::Gradient::create):
+        (WebCore::Gradient::Gradient):
+        (WebCore::Gradient::addColorStop):
+        (WebCore::Gradient::hash const):
+        (WebCore::Gradient::setSortedColorStops): Deleted.
+        (WebCore::Gradient::sortStops const): Deleted.
+        Replace ColorStopVector with GradientColorStops. This allows removing the m_stopsSorted
+        bit, as the new class maintains that, as well as removing setSortedColorStops since
+        you can achieve this by just creating the Gradient with a GradientColorStops that knows
+        it is sorted (using the GradientColorStops::Sorted helper).
+
+        * platform/graphics/GradientColorStop.h:
+        (WebCore::add):
+        Move definition of add(Hasher&, GradientColorStop) here, where it makes sense, rather than
+        keeping it in Gradient.
+
+        * platform/graphics/GradientColorStops.h: Added.
+        (WebCore::GradientColorStops::GradientColorStops):
+        (WebCore::GradientColorStops::addColorStop):
+        (WebCore::GradientColorStops::sort):
+        (WebCore::GradientColorStops::sorted const):
+        (WebCore::GradientColorStops::size const):
+        (WebCore::GradientColorStops::isEmpty const):
+        (WebCore::GradientColorStops::begin const):
+        (WebCore::GradientColorStops::end const):
+        (WebCore::GradientColorStops::mapColors const):
+        (WebCore::GradientColorStops::stops const):
+        (WebCore::GradientColorStops::validateIsSorted const):
+        (WebCore::GradientColorStops::encode const):
+        (WebCore::GradientColorStops::decode):
+        Encapsulate state and functionality of the gradient color stop list, maintaining
+        the sorted state, and providing a pleasent API to work with. In the future, this
+        will be a good place to add functions to analyze and transform the list for optimizing
+        what can use the gradient fast paths.
+
+        * platform/graphics/cairo/GradientCairo.cpp:
+        Update to use the new names.
+
+        * platform/graphics/cg/GradientCG.cpp:
+        (WebCore::Gradient::paint):
+        Ensure the color stops passed to the gradient renderer are sorted using the sorted()
+        helper, which does an inplace sort and returns a reference to itself.
+
+        * platform/graphics/cg/GradientRendererCG.h:
+        * platform/graphics/cg/GradientRendererCG.cpp:
+        (WebCore::GradientRendererCG::GradientRendererCG):
+        (WebCore::GradientRendererCG::pickStrategy const):
+        (WebCore::GradientRendererCG::makeGradient const):
+        (WebCore::GradientRendererCG::makeShading const):
+        Replace uses of GradientColorStopVector with GradientColorStops.
+
+        * rendering/svg/RenderSVGResourceGradient.h:
+        * rendering/svg/RenderSVGResourceGradient.cpp:
+        (WebCore::RenderSVGResourceGradient::stopsByApplyingColorFilter):
+        Add early return if there is no color filter to apply, and utilize the mapColors()
+        function to update the colors if there is.
+
+        * rendering/svg/RenderSVGResourceLinearGradient.cpp:
+        (WebCore::RenderSVGResourceLinearGradient::buildGradient const):
+        * rendering/svg/RenderSVGResourceRadialGradient.cpp:
+        (WebCore::RenderSVGResourceRadialGradient::buildGradient const):
+        Remove some extraneous type names.
+
+        * svg/GradientAttributes.h:
+        (WebCore::GradientAttributes::stops const):
+        (WebCore::GradientAttributes::setStops):
+        * svg/SVGGradientElement.cpp:
+        (WebCore::SVGGradientElement::buildStops):
+        * svg/SVGGradientElement.h:
+        Replace uses of GradientColorStopVector with GradientColorStops.
+
 2021-12-23  Philippe Normand  <pnorm...@igalia.com>
 
         [GStreamer] MediaPlayerPrivateGStreamer mishandles failure to create WebKitTextCombiner

Modified: trunk/Source/WebCore/Headers.cmake (287410 => 287411)


--- trunk/Source/WebCore/Headers.cmake	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/Headers.cmake	2021-12-23 21:35:00 UTC (rev 287411)
@@ -1462,6 +1462,7 @@
     platform/graphics/GlyphPage.h
     platform/graphics/Gradient.h
     platform/graphics/GradientColorStop.h
+    platform/graphics/GradientColorStops.h
     platform/graphics/GraphicsContext.h
     platform/graphics/GraphicsContextFlushIdentifier.h
     platform/graphics/GraphicsContextGL.h

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287410 => 287411)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-12-23 21:35:00 UTC (rev 287411)
@@ -4088,6 +4088,7 @@
 		BC14028B0E83680800319717 /* ScrollbarThemeComposite.h in Headers */ = {isa = PBXBuildFile; fileRef = BC1402890E83680800319717 /* ScrollbarThemeComposite.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC19CDF2276FFC6D0053F734 /* GradientRendererCG.h in Headers */ = {isa = PBXBuildFile; fileRef = BC19CDF0276FFB260053F734 /* GradientRendererCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC19CDF4277106390053F734 /* GradientColorStop.h in Headers */ = {isa = PBXBuildFile; fileRef = BC19CDF3277106390053F734 /* GradientColorStop.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		BC19CE2B2772BF7B0053F734 /* GradientColorStops.h in Headers */ = {isa = PBXBuildFile; fileRef = BC19CE292772BF770053F734 /* GradientColorStops.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC1A7D9818FCB5B000421879 /* RenderMultiColumnSpannerPlaceholder.h in Headers */ = {isa = PBXBuildFile; fileRef = BC1A7D9618FCB5B000421879 /* RenderMultiColumnSpannerPlaceholder.h */; };
 		BC2272870E82E70700E7F975 /* StyleReflection.h in Headers */ = {isa = PBXBuildFile; fileRef = BC2272860E82E70700E7F975 /* StyleReflection.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */ = {isa = PBXBuildFile; fileRef = BC2272A10E82E87C00E7F975 /* CursorData.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -15136,6 +15137,7 @@
 		BC19CDEF276FFB260053F734 /* GradientRendererCG.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GradientRendererCG.cpp; sourceTree = "<group>"; };
 		BC19CDF0276FFB260053F734 /* GradientRendererCG.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GradientRendererCG.h; sourceTree = "<group>"; };
 		BC19CDF3277106390053F734 /* GradientColorStop.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GradientColorStop.h; sourceTree = "<group>"; };
+		BC19CE292772BF770053F734 /* GradientColorStops.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GradientColorStops.h; sourceTree = "<group>"; };
 		BC1A7D9518FCB5B000421879 /* RenderMultiColumnSpannerPlaceholder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMultiColumnSpannerPlaceholder.cpp; sourceTree = "<group>"; };
 		BC1A7D9618FCB5B000421879 /* RenderMultiColumnSpannerPlaceholder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMultiColumnSpannerPlaceholder.h; sourceTree = "<group>"; };
 		BC20FB7E0C0E8E6C00D1447F /* JSDeprecatedCSSOMValueCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSDeprecatedCSSOMValueCustom.cpp; sourceTree = "<group>"; };
@@ -28785,6 +28787,7 @@
 				BC53C6070DA56C570021EB5D /* Gradient.cpp */,
 				BC53C5F40DA56B920021EB5D /* Gradient.h */,
 				BC19CDF3277106390053F734 /* GradientColorStop.h */,
+				BC19CE292772BF770053F734 /* GradientColorStops.h */,
 				2D2FC0561460CD6F00263633 /* GradientImage.cpp */,
 				2D2FC0571460CD6F00263633 /* GradientImage.h */,
 				B2A015920AF6CD53006BCE0E /* GraphicsContext.cpp */,
@@ -37570,6 +37573,7 @@
 				BE913D80181EF92400DCB09E /* TrackPrivateBase.h in Headers */,
 				CD1F9B1C27024BC200617EB6 /* TrackPrivateBaseClient.h in Headers */,
 				FFAC30FE184FB145008C4F1E /* TrailingObjects.h in Headers */,
+				BC19CE2B2772BF7B0053F734 /* GradientColorStops.h in Headers */,
 				516071321BD8308B00DBC4F2 /* TransactionOperation.h in Headers */,
 				CD3EEF4125799FD9006563BB /* TransferFunction.h in Headers */,
 				49E911C40EF86D47009D0CAF /* TransformationMatrix.h in Headers */,

Modified: trunk/Source/WebCore/css/CSSGradientValue.cpp (287410 => 287411)


--- trunk/Source/WebCore/css/CSSGradientValue.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/css/CSSGradientValue.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -300,12 +300,14 @@
 };
 
 template<typename GradientAdapter>
-Gradient::ColorStopVector CSSGradientValue::computeStops(GradientAdapter& gradientAdapter, const CSSToLengthConversionData& conversionData, const RenderStyle& style, float maxLengthForRepeat)
+GradientColorStops CSSGradientValue::computeStops(GradientAdapter& gradientAdapter, const CSSToLengthConversionData& conversionData, const RenderStyle& style, float maxLengthForRepeat)
 {
+    bool hasColorFilter = style.hasAppleColorFilter();
+
     if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
-        Gradient::ColorStopVector result;
+        GradientColorStops::StopVector result;
         result.reserveInitialCapacity(m_stops.size());
-
+        
         for (auto& stop : m_stops) {
             float offset;
             if (stop.position->isPercentage())
@@ -313,17 +315,14 @@
             else
                 offset = stop.position->floatValue(CSSUnitType::CSS_NUMBER);
 
-            Color color = stop.resolvedColor;
-            if (style.hasAppleColorFilter())
-                style.appleColorFilter().transformColor(color);
-            result.uncheckedAppend({ offset, color });
+            result.uncheckedAppend({ offset, hasColorFilter ? style.colorByApplyingColorFilter(stop.resolvedColor) : stop.resolvedColor });
         }
 
-        std::stable_sort(result.begin(), result.end(), [] (const Gradient::ColorStop& a, const Gradient::ColorStop& b) {
+        std::stable_sort(result.begin(), result.end(), [] (const GradientColorStop& a, const GradientColorStop& b) {
             return a.offset < b.offset;
         });
 
-        return result;
+        return GradientColorStops::Sorted { WTFMove(result) };
     }
 
     size_t numStops = m_stops.size();
@@ -334,12 +333,8 @@
     for (size_t i = 0; i < numStops; ++i) {
         auto& stop = m_stops[i];
 
-        Color color = stop.resolvedColor;
-        if (style.hasAppleColorFilter())
-            style.appleColorFilter().transformColor(color);
+        stops[i].color = hasColorFilter ? style.colorByApplyingColorFilter(stop.resolvedColor) : stop.resolvedColor;
 
-        stops[i].color = color;
-
         if (stop.position) {
             auto& positionValue = *stop.position;
             if (positionValue.isPercentage())
@@ -554,12 +549,12 @@
     if (stops.size() > 1 && (*stops.first().offset < 0 || *stops.last().offset > 1))
         gradientAdapter.normalizeStopsAndEndpointsOutsideRange(stops, m_colorInterpolationMethod);
     
-    Gradient::ColorStopVector result;
+    GradientColorStops::StopVector result;
     result.reserveInitialCapacity(stops.size());
     for (auto& stop : stops)
-        result.uncheckedAppend({ *stop.offset, stop.color });
+        result.uncheckedAppend({ *stop.offset, WTFMove(stop.color) });
 
-    return result;
+    return GradientColorStops::Sorted { WTFMove(result) };
 }
 
 static float positionFromValue(const CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)
@@ -867,9 +862,7 @@
     LinearGradientAdapter adapter { data };
     auto stops = computeStops(adapter, conversionData, renderer.style(), 1);
 
-    auto gradient = Gradient::create(WTFMove(data), colorInterpolationMethod());
-    gradient->setSortedColorStops(WTFMove(stops));
-    return gradient;
+    return Gradient::create(WTFMove(data), colorInterpolationMethod(), GradientSpreadMethod::Pad, WTFMove(stops));
 }
 
 bool CSSLinearGradientValue::equals(const CSSLinearGradientValue& other) const
@@ -1201,9 +1194,7 @@
     RadialGradientAdapter adapter { data };
     auto stops = computeStops(adapter, conversionData, renderer.style(), maxExtent);
 
-    auto gradient = Gradient::create(WTFMove(data), colorInterpolationMethod());
-    gradient->setSortedColorStops(WTFMove(stops));
-    return gradient;
+    return Gradient::create(WTFMove(data), colorInterpolationMethod(), GradientSpreadMethod::Pad, WTFMove(stops));
 }
 
 bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const
@@ -1275,9 +1266,7 @@
     ConicGradientAdapter adapter;
     auto stops = computeStops(adapter, conversionData, renderer.style(), 1);
 
-    auto gradient = Gradient::create(WTFMove(data), colorInterpolationMethod());
-    gradient->setSortedColorStops(WTFMove(stops));
-    return gradient;
+    return Gradient::create(WTFMove(data), colorInterpolationMethod(), GradientSpreadMethod::Pad, WTFMove(stops));
 }
 
 bool CSSConicGradientValue::equals(const CSSConicGradientValue& other) const

Modified: trunk/Source/WebCore/css/CSSGradientValue.h (287410 => 287411)


--- trunk/Source/WebCore/css/CSSGradientValue.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/css/CSSGradientValue.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -104,7 +104,7 @@
     {
     }
 
-    template<typename GradientAdapter> Gradient::ColorStopVector computeStops(GradientAdapter&, const CSSToLengthConversionData&, const RenderStyle&, float maxLengthForRepeat);
+    template<typename GradientAdapter> GradientColorStops computeStops(GradientAdapter&, const CSSToLengthConversionData&, const RenderStyle&, float maxLengthForRepeat);
 
     auto firstX() const { return m_firstX.get(); }
     auto firstY() const { return m_firstY.get(); }

Modified: trunk/Source/WebCore/platform/graphics/Color.h (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/Color.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -632,6 +632,12 @@
     return Color { asSRGBA(PackedColor::RGBA { value }), flags };
 }
 
+inline void add(Hasher& hasher, const Color& color)
+{
+    // FIXME: We don't want to hash a hash; do better.
+    add(hasher, color.hash());
+}
+
 } // namespace WebCore
 
 namespace WTF {

Modified: trunk/Source/WebCore/platform/graphics/FloatPoint.h (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/FloatPoint.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/FloatPoint.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -28,6 +28,7 @@
 
 #include "FloatSize.h"
 #include "IntPoint.h"
+#include <wtf/Hasher.h>
 #include <wtf/MathExtras.h>
 
 #if USE(CG)
@@ -55,7 +56,6 @@
 
 class AffineTransform;
 class TransformationMatrix;
-class IntPoint;
 class IntSize;
 
 class FloatPoint {
@@ -310,6 +310,11 @@
     return WTF::areEssentiallyEqual(a.x(), b.x()) && WTF::areEssentiallyEqual(a.y(), b.y());
 }
 
+inline void add(Hasher& hasher, const FloatPoint& point)
+{
+    add(hasher, point.x(), point.y());
+}
+
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const FloatPoint&);
 
 }

Modified: trunk/Source/WebCore/platform/graphics/Gradient.cpp (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/Gradient.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/Gradient.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -33,12 +33,12 @@
 
 namespace WebCore {
 
-Ref<Gradient> Gradient::create(Data&& data, ColorInterpolationMethod colorInterpolationMethod, GradientSpreadMethod spreadMethod, ColorStopVector&& stops)
+Ref<Gradient> Gradient::create(Data&& data, ColorInterpolationMethod colorInterpolationMethod, GradientSpreadMethod spreadMethod, GradientColorStops&& stops)
 {
     return adoptRef(*new Gradient(WTFMove(data), colorInterpolationMethod, spreadMethod, WTFMove(stops)));
 }
 
-Gradient::Gradient(Data&& data, ColorInterpolationMethod colorInterpolationMethod, GradientSpreadMethod spreadMethod, ColorStopVector&& stops)
+Gradient::Gradient(Data&& data, ColorInterpolationMethod colorInterpolationMethod, GradientSpreadMethod spreadMethod, GradientColorStops&& stops)
     : m_data { WTFMove(data) }
     , m_colorInterpolationMethod { colorInterpolationMethod }
     , m_spreadMethod { spreadMethod }
@@ -91,44 +91,13 @@
     );
 }
 
-void Gradient::addColorStop(Gradient::ColorStop&& stop)
+void Gradient::addColorStop(GradientColorStop&& stop)
 {
-    m_stops.append(WTFMove(stop));
-    m_stopsSorted = false;
+    m_stops.addColorStop(WTFMove(stop));
     m_cachedHash = 0;
     stopsChanged();
 }
 
-void Gradient::setSortedColorStops(ColorStopVector&& stops)
-{
-    m_stops = WTFMove(stops);
-    m_stopsSorted = true;
-    m_cachedHash = 0;
-    stopsChanged();
-}
-
-void Gradient::sortStops() const
-{
-    if (m_stopsSorted)
-        return;
-    m_stopsSorted = true;
-    std::stable_sort(m_stops.begin(), m_stops.end(), [] (auto& a, auto& b) {
-        return a.offset < b.offset;
-    });
-}
-
-// FIXME: Instead of these add(Hasher) functions, consider using encode functions to compute the hash.
-
-static void add(Hasher& hasher, const FloatPoint& point)
-{
-    add(hasher, point.x(), point.y());
-}
-
-static void add(Hasher& hasher, const Gradient::ColorStop& stop)
-{
-    add(hasher, stop.offset, stop.color);
-}
-
 static void add(Hasher& hasher, const Gradient::LinearData& data)
 {
     add(hasher, data.point0, data.point1);
@@ -146,10 +115,8 @@
 
 unsigned Gradient::hash() const
 {
-    if (!m_cachedHash) {
-        sortStops();
-        m_cachedHash = computeHash(m_data, m_colorInterpolationMethod, m_spreadMethod, m_stops);
-    }
+    if (!m_cachedHash)
+        m_cachedHash = computeHash(m_data, m_colorInterpolationMethod, m_spreadMethod, m_stops.sorted());
     return m_cachedHash;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/Gradient.h (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/Gradient.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/Gradient.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -30,7 +30,7 @@
 #include "Color.h"
 #include "ColorInterpolationMethod.h"
 #include "FloatPoint.h"
-#include "GradientColorStop.h"
+#include "GradientColorStops.h"
 #include "GraphicsTypes.h"
 #include <variant>
 #include <wtf/Vector.h>
@@ -64,9 +64,6 @@
 
 class Gradient : public RefCounted<Gradient> {
 public:
-    using ColorStop = GradientColorStop;
-    using ColorStopVector = GradientColorStopVector;
-
     struct LinearData {
         FloatPoint point0;
         FloatPoint point1;
@@ -96,16 +93,15 @@
 
     using Data = "" RadialData, ConicData>;
 
-    WEBCORE_EXPORT static Ref<Gradient> create(Data&&, ColorInterpolationMethod, GradientSpreadMethod = GradientSpreadMethod::Pad, ColorStopVector&& = { });
+    WEBCORE_EXPORT static Ref<Gradient> create(Data&&, ColorInterpolationMethod, GradientSpreadMethod = GradientSpreadMethod::Pad, GradientColorStops&& = { });
 
     bool isZeroSize() const;
 
     const Data& data() const { return m_data; }
 
-    WEBCORE_EXPORT void addColorStop(ColorStop&&);
-    WEBCORE_EXPORT void setSortedColorStops(ColorStopVector&&);
+    WEBCORE_EXPORT void addColorStop(GradientColorStop&&);
 
-    const ColorStopVector& stops() const { return m_stops; }
+    const GradientColorStops& stops() const { return m_stops; }
     GradientSpreadMethod spreadMethod() const { return m_spreadMethod; }
 
     void fill(GraphicsContext&, const FloatRect&);
@@ -130,16 +126,14 @@
     template<typename Decoder> static std::optional<Ref<Gradient>> decode(Decoder&);
 
 private:
-    explicit Gradient(Data&&, ColorInterpolationMethod, GradientSpreadMethod, ColorStopVector&&);
+    explicit Gradient(Data&&, ColorInterpolationMethod, GradientSpreadMethod, GradientColorStops&&);
 
-    void sortStops() const;
     void stopsChanged();
 
     Data m_data;
     ColorInterpolationMethod m_colorInterpolationMethod;
     GradientSpreadMethod m_spreadMethod;
-    mutable ColorStopVector m_stops;
-    mutable bool m_stopsSorted { false };
+    GradientColorStops m_stops;
     mutable unsigned m_cachedHash { 0 };
 
 #if USE(CG)
@@ -257,7 +251,7 @@
     if (!spreadMethod)
         return std::nullopt;
 
-    std::optional<ColorStopVector> stops;
+    std::optional<GradientColorStops> stops;
     decoder >> stops;
     if (!stops)
         return std::nullopt;
@@ -265,10 +259,4 @@
     return Gradient::create(WTFMove(*data), *colorInterpolationMethod, *spreadMethod, WTFMove(*stops));
 }
 
-inline void add(Hasher& hasher, const Color& color)
-{
-    // FIXME: We don't want to hash a hash; do better.
-    add(hasher, color.hash());
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/GradientColorStop.h (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/GradientColorStop.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/GradientColorStop.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -27,7 +27,7 @@
 
 #include "Color.h"
 #include <optional>
-#include <wtf/Vector.h>
+#include <wtf/Hasher.h>
 
 namespace WebCore {
 
@@ -39,8 +39,6 @@
     template<typename Decoder> static std::optional<GradientColorStop> decode(Decoder&);
 };
 
-using GradientColorStopVector = Vector<GradientColorStop, 2>;
-
 template<typename Encoder> void GradientColorStop::encode(Encoder& encoder) const
 {
     encoder << offset;
@@ -62,4 +60,9 @@
     return {{ *offset, *color }};
 }
 
+inline void add(Hasher& hasher, const GradientColorStop& stop)
+{
+    add(hasher, stop.offset, stop.color);
 }
+
+}

Added: trunk/Source/WebCore/platform/graphics/GradientColorStops.h (0 => 287411)


--- trunk/Source/WebCore/platform/graphics/GradientColorStops.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/GradientColorStops.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "GradientColorStop.h"
+#include <algorithm>
+#include <optional>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class GradientColorStops {
+public:
+    using StopVector = Vector<GradientColorStop, 2>;
+
+    struct Sorted {
+        StopVector stops;
+    };
+
+    GradientColorStops()
+        : m_isSorted { true }
+    {
+    }
+
+    GradientColorStops(StopVector stops)
+        : m_stops { WTFMove(stops) }
+        , m_isSorted { false }
+    {
+    }
+
+    GradientColorStops(Sorted sortedStops)
+        : m_stops { WTFMove(sortedStops.stops) }
+        , m_isSorted { true }
+    {
+        ASSERT(validateIsSorted());
+    }
+
+    void addColorStop(GradientColorStop stop)
+    {
+        if (!m_stops.isEmpty() && m_stops.last().offset > stop.offset)
+            m_isSorted = false;
+        m_stops.append(WTFMove(stop));
+    }
+
+    void sort()
+    {
+        if (m_isSorted)
+            return;
+
+        std::stable_sort(m_stops.begin(), m_stops.end(), [] (auto& a, auto& b) {
+            return a.offset < b.offset;
+        });
+        m_isSorted = true;
+    }
+
+    const GradientColorStops& sorted() const
+    {
+        const_cast<GradientColorStops*>(this)->sort();
+        return *this;
+    }
+
+    size_t size() const { return m_stops.size(); }
+    bool isEmpty() const { return m_stops.isEmpty(); }
+
+    StopVector::const_iterator begin() const { return m_stops.begin(); }
+    StopVector::const_iterator end() const { return m_stops.end(); }
+
+    template<typename MapFunction> GradientColorStops mapColors(MapFunction&& mapFunction) const
+    {
+        GradientColorStops result;
+        result.m_stops.reserveInitialCapacity(size());
+        for (auto& stop : m_stops)
+            result.m_stops.uncheckedAppend({ stop.offset, mapFunction(stop.color) });
+        return result;
+    }
+
+    const StopVector& stops() const { return m_stops; }
+
+    template<typename Encoder> void encode(Encoder&) const;
+    template<typename Decoder> static std::optional<GradientColorStops> decode(Decoder&);
+
+private:
+#if ASSERT_ENABLED
+    bool validateIsSorted() const
+    {
+        return std::is_sorted(m_stops.begin(), m_stops.end(), [] (auto& a, auto& b) {
+            return a.offset < b.offset;
+        });
+    }
+#endif
+
+    StopVector m_stops;
+    bool m_isSorted;
+};
+
+template<typename Encoder> void GradientColorStops::encode(Encoder& encoder) const
+{
+    encoder << m_stops;
+}
+
+template<typename Decoder> std::optional<GradientColorStops> GradientColorStops::decode(Decoder& decoder)
+{
+    std::optional<StopVector> stops;
+    decoder >> stops;
+    if (!stops)
+        return std::nullopt;
+
+    return {{ WTFMove(*stops) }};
+}
+
+}

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


--- trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -43,7 +43,7 @@
 {
 }
 
-static void addColorStopRGBA(cairo_pattern_t *gradient, Gradient::ColorStop stop, float globalAlpha)
+static void addColorStopRGBA(cairo_pattern_t *gradient, GradientColorStop stop, float globalAlpha)
 {
     auto [r, g, b, a] = stop.color.toSRGBALossy<float>();
     cairo_pattern_add_color_stop_rgba(gradient, stop.offset, r, g, b, a * globalAlpha);
@@ -53,7 +53,7 @@
     double x, y;
 } point_t;
 
-static void setCornerColorRGBA(cairo_pattern_t* gradient, int id, Gradient::ColorStop stop, float globalAlpha)
+static void setCornerColorRGBA(cairo_pattern_t* gradient, int id, GradientColorStop stop, float globalAlpha)
 {
     auto [r, g, b, a] = stop.color.toSRGBALossy<float>();
     cairo_mesh_pattern_set_corner_color_rgba(gradient, id, r, g, b, a * globalAlpha);
@@ -74,7 +74,7 @@
 }
 
 static void addConicSector(cairo_pattern_t *gradient, float cx, float cy, float r, float angleRadians,
-    Gradient::ColorStop from, Gradient::ColorStop to, float globalAlpha)
+    GradientColorStop from, GradientColorStop to, float globalAlpha)
 {
     const double angOffset = 0.25; // 90 degrees.
 
@@ -149,7 +149,7 @@
 }
 
 static RefPtr<cairo_pattern_t> createConic(float xo, float yo, float r, float angleRadians,
-    Gradient::ColorStopVector stops, float globalAlpha)
+    GradientColorStops::StopVector stops, float globalAlpha)
 {
     // Degenerated gradients with two stops at the same offset arrive with a single stop at 0.0
     // Add another point here so it can be interpolated properly below.
@@ -173,7 +173,7 @@
                 last, {0.25, last.color}, {0.5, last.color}, {0.75, last.color}, {1.0, last.color}
             };
         } else {
-            auto interpolatedStop = [&] (double fraction) -> Gradient::ColorStop {
+            auto interpolatedStop = [&] (double fraction) -> GradientColorStop {
                 auto offset = blend(stops.first().offset, stops.last().offset, fraction);
                 auto interpColor = blendWithoutPremultiply(stops.first().color, stops.last().color, fraction);
                 return { offset, interpColor };
@@ -224,7 +224,7 @@
             // Thus, here I give the radius an extremely large value. The resulting gradient will be later clipped by fillRect.
             // An alternative solution could be to change the API and pass a rect's width and height to optimize the computation of the radius.
             const float radius = 4096;
-            return createConic(data.point0.x(), data.point0.y(), radius, data.angleRadians, stops(), globalAlpha);
+            return createConic(data.point0.x(), data.point0.y(), radius, data.angleRadians, stops().stops(), globalAlpha);
         }
     );
 

Modified: trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -53,10 +53,8 @@
 
 void Gradient::paint(CGContextRef platformContext)
 {
-    if (!m_platformRenderer) {
-        sortStops();
-        m_platformRenderer = GradientRendererCG { m_colorInterpolationMethod, m_stops };
-    }
+    if (!m_platformRenderer)
+        m_platformRenderer = GradientRendererCG { m_colorInterpolationMethod, m_stops.sorted() };
 
     WTF::switchOn(m_data,
         [&] (const LinearData& data) {

Modified: trunk/Source/WebCore/platform/graphics/cg/GradientRendererCG.cpp (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/cg/GradientRendererCG.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/cg/GradientRendererCG.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -28,11 +28,12 @@
 
 #include "ColorInterpolation.h"
 #include "ColorSpaceCG.h"
+#include "GradientColorStops.h"
 #include <pal/spi/cg/CoreGraphicsSPI.h>
 
 namespace WebCore {
 
-GradientRendererCG::GradientRendererCG(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStopVector& stops)
+GradientRendererCG::GradientRendererCG(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStops& stops)
     : m_strategy { pickStrategy(colorInterpolationMethod, stops) }
 {
 }
@@ -39,7 +40,7 @@
 
 // MARK: - Strategy selection.
 
-GradientRendererCG::Strategy GradientRendererCG::pickStrategy(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStopVector& stops) const
+GradientRendererCG::Strategy GradientRendererCG::pickStrategy(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStops& stops) const
 {
     return WTF::switchOn(colorInterpolationMethod.colorSpace,
         [&] (const ColorInterpolationMethod::SRGB&) -> Strategy {
@@ -64,7 +65,7 @@
 
 // MARK: - Gradient strategy.
 
-GradientRendererCG::Strategy GradientRendererCG::makeGradient(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStopVector& stops) const
+GradientRendererCG::Strategy GradientRendererCG::makeGradient(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStops& stops) const
 {
     ASSERT_UNUSED(colorInterpolationMethod, std::holds_alternative<ColorInterpolationMethod::SRGB>(colorInterpolationMethod.colorSpace));
 #if !HAVE(CORE_GRAPHICS_PREMULTIPLIED_INTERPOLATION_GRADIENT)
@@ -201,7 +202,7 @@
         out[componentIndex] = interpolatedColorConvertedToOutputSpace[componentIndex];
 }
 
-GradientRendererCG::Strategy GradientRendererCG::makeShading(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStopVector& stops) const
+GradientRendererCG::Strategy GradientRendererCG::makeShading(ColorInterpolationMethod colorInterpolationMethod, const GradientColorStops& stops) const
 {
     auto makeData = [&] (auto colorInterpolationMethod, auto& stops) {
         auto convertColorToColorInterpolationSpace = [&] (const Color& color, auto colorInterpolationMethod) -> ColorComponents<float, 4> {

Modified: trunk/Source/WebCore/platform/graphics/cg/GradientRendererCG.h (287410 => 287411)


--- trunk/Source/WebCore/platform/graphics/cg/GradientRendererCG.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/platform/graphics/cg/GradientRendererCG.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -27,7 +27,6 @@
 
 #include "ColorComponents.h"
 #include "ColorInterpolationMethod.h"
-#include "GradientColorStop.h"
 #include <CoreGraphics/CoreGraphics.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/ThreadSafeRefCounted.h>
@@ -35,6 +34,8 @@
 
 namespace WebCore {
 
+class GradientColorStops;
+
 struct ColorConvertedToInterpolationColorSpaceStop {
     float offset;
     ColorComponents<float, 4> colorComponents;
@@ -42,7 +43,7 @@
 
 class GradientRendererCG {
 public:
-    GradientRendererCG(ColorInterpolationMethod, const GradientColorStopVector&);
+    GradientRendererCG(ColorInterpolationMethod, const GradientColorStops&);
 
     void drawLinearGradient(CGContextRef, CGPoint startPoint, CGPoint endPoint, CGGradientDrawingOptions);
     void drawRadialGradient(CGContextRef, CGPoint startCenter, CGFloat startRadius, CGPoint endCenter, CGFloat endRadius, CGGradientDrawingOptions);
@@ -84,9 +85,9 @@
 
     using Strategy = std::variant<Gradient, Shading>;
 
-    Strategy pickStrategy(ColorInterpolationMethod, const GradientColorStopVector&) const;
-    Strategy makeGradient(ColorInterpolationMethod, const GradientColorStopVector&) const;
-    Strategy makeShading(ColorInterpolationMethod, const GradientColorStopVector&) const;
+    Strategy pickStrategy(ColorInterpolationMethod, const GradientColorStops&) const;
+    Strategy makeGradient(ColorInterpolationMethod, const GradientColorStops&) const;
+    Strategy makeShading(ColorInterpolationMethod, const GradientColorStops&) const;
 
     Strategy m_strategy;
 };

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp (287410 => 287411)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -225,13 +225,12 @@
     context->restore();
 }
 
-Gradient::ColorStopVector RenderSVGResourceGradient::stopsByApplyingColorFilter(const Gradient::ColorStopVector& stops, const RenderStyle& style)
+GradientColorStops RenderSVGResourceGradient::stopsByApplyingColorFilter(const GradientColorStops& stops, const RenderStyle& style)
 {
-    Gradient::ColorStopVector result;
-    result.reserveInitialCapacity(stops.size());
-    for (auto& stop : stops)
-        result.uncheckedAppend({ stop.offset, style.colorByApplyingColorFilter(stop.color) });
-    return result;
+    if (!style.hasAppleColorFilter())
+        return stops;
+
+    return stops.mapColors([&] (auto& color) { return style.colorByApplyingColorFilter(color); });
 }
 
 GradientSpreadMethod RenderSVGResourceGradient::platformSpreadMethodFromSVGType(SVGSpreadMethodType method)

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h (287410 => 287411)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -46,7 +46,7 @@
 protected:
     RenderSVGResourceGradient(SVGGradientElement&, RenderStyle&&);
 
-    static Gradient::ColorStopVector stopsByApplyingColorFilter(const Gradient::ColorStopVector&, const RenderStyle&);
+    static GradientColorStops stopsByApplyingColorFilter(const GradientColorStops&, const RenderStyle&);
     static GradientSpreadMethod platformSpreadMethodFromSVGType(SVGSpreadMethodType);
 
 private:

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp (287410 => 287411)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -55,7 +55,7 @@
 {
     return Gradient::create(
         Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) },
-        ColorInterpolationMethod { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied },
+        { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied },
         platformSpreadMethodFromSVGType(m_attributes.spreadMethod()),
         stopsByApplyingColorFilter(m_attributes.stops(), style)
     );

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp (287410 => 287411)


--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -66,7 +66,7 @@
 {
     return Gradient::create(
         Gradient::RadialData { focalPoint(m_attributes), centerPoint(m_attributes), focalRadius(m_attributes), radius(m_attributes), 1 },
-        ColorInterpolationMethod { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied },
+        { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied },
         platformSpreadMethodFromSVGType(m_attributes.spreadMethod()),
         stopsByApplyingColorFilter(m_attributes.stops(), style)
     );

Modified: trunk/Source/WebCore/svg/GradientAttributes.h (287410 => 287411)


--- trunk/Source/WebCore/svg/GradientAttributes.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/svg/GradientAttributes.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -37,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 Gradient::ColorStopVector& stops() const { return m_stops; }
+    const GradientColorStops& stops() const { return m_stops; }
 
     void setSpreadMethod(SVGSpreadMethodType value)
     {
@@ -57,7 +57,7 @@
         m_gradientTransformSet = true;
     }
 
-    void setStops(Gradient::ColorStopVector&& value)
+    void setStops(GradientColorStops&& value)
     {
         m_stops = WTFMove(value);
     }
@@ -70,7 +70,7 @@
 private:
     // Properties
     AffineTransform m_gradientTransform;
-    Gradient::ColorStopVector m_stops;
+    GradientColorStops m_stops;
 
     unsigned m_spreadMethod : 2;
     unsigned m_gradientUnits : 2;
@@ -83,7 +83,7 @@
 
 struct SameSizeAsGradientAttributes {
     AffineTransform a;
-    Gradient::ColorStopVector b;
+    GradientColorStops b;
     unsigned c : 7;
 };
 

Modified: trunk/Source/WebCore/svg/SVGGradientElement.cpp (287410 => 287411)


--- trunk/Source/WebCore/svg/SVGGradientElement.cpp	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/svg/SVGGradientElement.cpp	2021-12-23 21:35:00 UTC (rev 287411)
@@ -98,14 +98,14 @@
         object->setNeedsLayout();
 }
 
-Gradient::ColorStopVector SVGGradientElement::buildStops()
+GradientColorStops SVGGradientElement::buildStops()
 {
-    Gradient::ColorStopVector stops;
+    GradientColorStops stops;
     float previousOffset = 0.0f;
     for (auto& stop : childrenOfType<SVGStopElement>(*this)) {
         auto monotonicallyIncreasingOffset = std::clamp(stop.offset(), previousOffset, 1.0f);
         previousOffset = monotonicallyIncreasingOffset;
-        stops.append({ monotonicallyIncreasingOffset, stop.stopColorIncludingOpacity() });
+        stops.addColorStop({ monotonicallyIncreasingOffset, stop.stopColorIncludingOpacity() });
     }
     return stops;
 }

Modified: trunk/Source/WebCore/svg/SVGGradientElement.h (287410 => 287411)


--- trunk/Source/WebCore/svg/SVGGradientElement.h	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Source/WebCore/svg/SVGGradientElement.h	2021-12-23 21:35:00 UTC (rev 287411)
@@ -79,7 +79,7 @@
         SVG_SPREADMETHOD_REPEAT = SVGSpreadMethodUnknown
     };
 
-    Gradient::ColorStopVector buildStops();
+    GradientColorStops buildStops();
 
     using PropertyRegistry = SVGPropertyOwnerRegistry<SVGGradientElement, SVGElement, SVGURIReference>;
 

Modified: trunk/Tools/ChangeLog (287410 => 287411)


--- trunk/Tools/ChangeLog	2021-12-23 20:56:29 UTC (rev 287410)
+++ trunk/Tools/ChangeLog	2021-12-23 21:35:00 UTC (rev 287411)
@@ -1,3 +1,15 @@
+2021-12-23  Sam Weinig  <wei...@apple.com>
+
+        Encapsulate gradient color stops into a self contained class
+        https://bugs.webkit.org/show_bug.cgi?id=234583
+
+        Reviewed by Simon Fraser.
+
+        * TestRunnerShared/PlatformGTK.cmake: Added.
+        * TestRunnerShared/PlatformWPE.cmake: Added.
+        Keep GTK and WPE ports building by propogating glib.h header to the test runnner. Change
+        by Fujii Hironori.
+
 2021-12-23  Patrick Griffis  <pgrif...@igalia.com>
 
         [Flatpak] Revert filesystem permission change in r287396

Added: trunk/Tools/TestRunnerShared/PlatformGTK.cmake (0 => 287411)


--- trunk/Tools/TestRunnerShared/PlatformGTK.cmake	                        (rev 0)
+++ trunk/Tools/TestRunnerShared/PlatformGTK.cmake	2021-12-23 21:35:00 UTC (rev 287411)
@@ -0,0 +1,3 @@
+list(APPEND TestRunnerShared_SYSTEM_INCLUDE_DIRECTORIES
+    ${GLIB_INCLUDE_DIRS}
+)

Added: trunk/Tools/TestRunnerShared/PlatformWPE.cmake (0 => 287411)


--- trunk/Tools/TestRunnerShared/PlatformWPE.cmake	                        (rev 0)
+++ trunk/Tools/TestRunnerShared/PlatformWPE.cmake	2021-12-23 21:35:00 UTC (rev 287411)
@@ -0,0 +1,3 @@
+list(APPEND TestRunnerShared_SYSTEM_INCLUDE_DIRECTORIES
+    ${GLIB_INCLUDE_DIRS}
+)
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to