Diff
Modified: trunk/Source/WebCore/ChangeLog (287323 => 287324)
--- trunk/Source/WebCore/ChangeLog 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/ChangeLog 2021-12-21 19:15:59 UTC (rev 287324)
@@ -1,3 +1,37 @@
+2021-12-21 Sam Weinig <wei...@apple.com>
+
+ Gradient encode/decode does not validate that the serialized stops were sorted
+ https://bugs.webkit.org/show_bug.cgi?id=234558
+
+ Reviewed by Simon Fraser.
+
+ Stop encoding and decoding the stopsSorted bit on Gradient for serialization as
+ we still need to validate the stops are sorted on deserialization.
+
+ While here, optimize things a bit by allowing one to pass all the necessary
+ parameters to the Gradient create function, which allows us to avoid unnecessary
+ extra invalidation. Now that the GradientSpreadMethod can be set on construction
+ there is no need for its setter.
+
+ * platform/graphics/Gradient.cpp:
+ (WebCore::Gradient::create):
+ (WebCore::Gradient::Gradient):
+ (WebCore::Gradient::sortStops const):
+ (WebCore::Gradient::setSpreadMethod): Deleted.
+ * platform/graphics/Gradient.h:
+ (WebCore::Gradient::create):
+ (WebCore::Gradient::stops const):
+ (WebCore::Gradient::encode const):
+ (WebCore::Gradient::decode):
+ * rendering/svg/RenderSVGResourceGradient.cpp:
+ (WebCore::RenderSVGResourceGradient::stopsByApplyingColorFilter):
+ (WebCore::RenderSVGResourceGradient::addStops): Deleted.
+ * rendering/svg/RenderSVGResourceGradient.h:
+ * rendering/svg/RenderSVGResourceLinearGradient.cpp:
+ (WebCore::RenderSVGResourceLinearGradient::buildGradient const):
+ * rendering/svg/RenderSVGResourceRadialGradient.cpp:
+ (WebCore::RenderSVGResourceRadialGradient::buildGradient const):
+
2021-12-21 Wenson Hsieh <wenson_hs...@apple.com>
Add support for a UI delegate method to decide how to handle detected modal containers
Modified: trunk/Source/WebCore/platform/graphics/Gradient.cpp (287323 => 287324)
--- trunk/Source/WebCore/platform/graphics/Gradient.cpp 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/platform/graphics/Gradient.cpp 2021-12-21 19:15:59 UTC (rev 287324)
@@ -27,7 +27,6 @@
#include "config.h"
#include "Gradient.h"
-#include "Color.h"
#include "FloatRect.h"
#include <wtf/HashFunctions.h>
#include <wtf/Hasher.h>
@@ -34,14 +33,16 @@
namespace WebCore {
-Ref<Gradient> Gradient::create(Data&& data, ColorInterpolationMethod colorInterpolationMethod)
+Ref<Gradient> Gradient::create(Data&& data, ColorInterpolationMethod colorInterpolationMethod, GradientSpreadMethod spreadMethod, ColorStopVector&& stops)
{
- return adoptRef(*new Gradient(WTFMove(data), colorInterpolationMethod));
+ return adoptRef(*new Gradient(WTFMove(data), colorInterpolationMethod, spreadMethod, WTFMove(stops)));
}
-Gradient::Gradient(Data&& data, ColorInterpolationMethod colorInterpolationMethod)
+Gradient::Gradient(Data&& data, ColorInterpolationMethod colorInterpolationMethod, GradientSpreadMethod spreadMethod, ColorStopVector&& stops)
: m_data { WTFMove(data) }
, m_colorInterpolationMethod { colorInterpolationMethod }
+ , m_spreadMethod { spreadMethod }
+ , m_stops { WTFMove(stops) }
{
}
@@ -116,14 +117,6 @@
});
}
-void Gradient::setSpreadMethod(GradientSpreadMethod spreadMethod)
-{
- if (m_spreadMethod == spreadMethod)
- return;
- m_spreadMethod = spreadMethod;
- m_cachedHash = 0;
-}
-
// FIXME: Instead of these add(Hasher) functions, consider using encode functions to compute the hash.
static void add(Hasher& hasher, const FloatPoint& point)
Modified: trunk/Source/WebCore/platform/graphics/Gradient.h (287323 => 287324)
--- trunk/Source/WebCore/platform/graphics/Gradient.h 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/platform/graphics/Gradient.h 2021-12-21 19:15:59 UTC (rev 287324)
@@ -96,7 +96,7 @@
using Data = "" RadialData, ConicData>;
- WEBCORE_EXPORT static Ref<Gradient> create(Data&&, ColorInterpolationMethod);
+ WEBCORE_EXPORT static Ref<Gradient> create(Data&&, ColorInterpolationMethod, GradientSpreadMethod = GradientSpreadMethod::Pad, ColorStopVector&& = { });
bool isZeroSize() const;
@@ -106,8 +106,6 @@
WEBCORE_EXPORT void setSortedColorStops(ColorStopVector&&);
const ColorStopVector& stops() const { return m_stops; }
-
- WEBCORE_EXPORT void setSpreadMethod(GradientSpreadMethod);
GradientSpreadMethod spreadMethod() const { return m_spreadMethod; }
void fill(GraphicsContext&, const FloatRect&);
@@ -132,7 +130,7 @@
template<typename Decoder> static std::optional<Ref<Gradient>> decode(Decoder&);
private:
- explicit Gradient(Data&&, ColorInterpolationMethod);
+ explicit Gradient(Data&&, ColorInterpolationMethod, GradientSpreadMethod, ColorStopVector&&);
void sortStops() const;
void stopsChanged();
@@ -139,9 +137,9 @@
Data m_data;
ColorInterpolationMethod m_colorInterpolationMethod;
+ GradientSpreadMethod m_spreadMethod;
mutable ColorStopVector m_stops;
mutable bool m_stopsSorted { false };
- GradientSpreadMethod m_spreadMethod { GradientSpreadMethod::Pad };
mutable unsigned m_cachedHash { 0 };
#if USE(CG)
@@ -238,9 +236,8 @@
{
encoder << m_data;
encoder << m_colorInterpolationMethod;
+ encoder << m_spreadMethod;
encoder << m_stops;
- encoder << m_stopsSorted;
- encoder << m_spreadMethod;
}
template<typename Decoder> std::optional<Ref<Gradient>> Gradient::decode(Decoder& decoder)
@@ -255,29 +252,17 @@
if (!colorInterpolationMethod)
return std::nullopt;
- auto gradient = Gradient::create(WTFMove(*data), *colorInterpolationMethod);
+ std::optional<GradientSpreadMethod> spreadMethod;
+ decoder >> spreadMethod;
+ if (!spreadMethod)
+ return std::nullopt;
std::optional<ColorStopVector> stops;
decoder >> stops;
if (!stops)
return std::nullopt;
- std::optional<bool> stopsSorted;
- decoder >> stopsSorted;
- if (!stopsSorted.has_value())
- return std::nullopt;
- if (*stopsSorted)
- gradient->setSortedColorStops(WTFMove(*stops));
- else {
- for (auto& stop : *stops)
- gradient->addColorStop(WTFMove(stop));
- }
- GradientSpreadMethod spreadMethod;
- if (!decoder.decode(spreadMethod))
- return std::nullopt;
- gradient->setSpreadMethod(spreadMethod);
-
- return gradient;
+ return Gradient::create(WTFMove(*data), *colorInterpolationMethod, *spreadMethod, WTFMove(*stops));
}
inline void add(Hasher& hasher, const Color& color)
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp (287323 => 287324)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp 2021-12-21 19:15:59 UTC (rev 287324)
@@ -225,10 +225,13 @@
context->restore();
}
-void RenderSVGResourceGradient::addStops(Gradient& gradient, const Gradient::ColorStopVector& stops, const RenderStyle& style)
+Gradient::ColorStopVector RenderSVGResourceGradient::stopsByApplyingColorFilter(const Gradient::ColorStopVector& stops, const RenderStyle& style)
{
+ Gradient::ColorStopVector result;
+ result.reserveInitialCapacity(stops.size());
for (auto& stop : stops)
- gradient.addColorStop({ stop.offset, style.colorByApplyingColorFilter(stop.color) });
+ result.uncheckedAppend({ stop.offset, style.colorByApplyingColorFilter(stop.color) });
+ return result;
}
GradientSpreadMethod RenderSVGResourceGradient::platformSpreadMethodFromSVGType(SVGSpreadMethodType method)
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h (287323 => 287324)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h 2021-12-21 19:15:59 UTC (rev 287324)
@@ -46,7 +46,7 @@
protected:
RenderSVGResourceGradient(SVGGradientElement&, RenderStyle&&);
- static void addStops(Gradient&, const Gradient::ColorStopVector&, const RenderStyle&);
+ static Gradient::ColorStopVector stopsByApplyingColorFilter(const Gradient::ColorStopVector&, const RenderStyle&);
static GradientSpreadMethod platformSpreadMethodFromSVGType(SVGSpreadMethodType);
private:
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp (287323 => 287324)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp 2021-12-21 19:15:59 UTC (rev 287324)
@@ -53,10 +53,12 @@
Ref<Gradient> RenderSVGResourceLinearGradient::buildGradient(const RenderStyle& style) const
{
- auto gradient = Gradient::create(Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) }, { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied });
- gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
- addStops(gradient, m_attributes.stops(), style);
- return gradient;
+ return Gradient::create(
+ Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) },
+ ColorInterpolationMethod { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied },
+ platformSpreadMethodFromSVGType(m_attributes.spreadMethod()),
+ stopsByApplyingColorFilter(m_attributes.stops(), style)
+ );
}
}
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp (287323 => 287324)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp 2021-12-21 18:34:35 UTC (rev 287323)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp 2021-12-21 19:15:59 UTC (rev 287324)
@@ -64,10 +64,12 @@
Ref<Gradient> RenderSVGResourceRadialGradient::buildGradient(const RenderStyle& style) const
{
- auto gradient = Gradient::create(Gradient::RadialData { focalPoint(m_attributes), centerPoint(m_attributes), focalRadius(m_attributes), radius(m_attributes), 1 }, { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied });
- gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
- addStops(gradient, m_attributes.stops(), style);
- return gradient;
+ return Gradient::create(
+ Gradient::RadialData { focalPoint(m_attributes), centerPoint(m_attributes), focalRadius(m_attributes), radius(m_attributes), 1 },
+ ColorInterpolationMethod { ColorInterpolationMethod::SRGB { }, AlphaPremultiplication::Unpremultiplied },
+ platformSpreadMethodFromSVGType(m_attributes.spreadMethod()),
+ stopsByApplyingColorFilter(m_attributes.stops(), style)
+ );
}
}