Commit b857e84f authored by fmalita's avatar fmalita Committed by Commit bot

Remove two Gradient setters

setSpreadMethod() and setDrawsInPMColorSpace() are only ever called
immediately after instantiation, so they can be folded into ctor easily.

Refactor only, no functional changes.

BUG=614368
R=schenney@chromium.org,fs@opera.com

Review-Url: https://codereview.chromium.org/2754783003
Cr-Commit-Position: refs/heads/master@{#457473}
parent 76ea7030
...@@ -878,10 +878,10 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient( ...@@ -878,10 +878,10 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(
} }
} }
RefPtr<Gradient> gradient = Gradient::create(firstPoint, secondPoint); RefPtr<Gradient> gradient =
Gradient::create(firstPoint, secondPoint,
gradient->setSpreadMethod(m_repeating ? SpreadMethodRepeat : SpreadMethodPad); m_repeating ? SpreadMethodRepeat : SpreadMethodPad,
gradient->setDrawsInPMColorSpace(true); Gradient::ColorInterpolation::Premultiplied);
// Now add the stops. // Now add the stops.
addStops(gradient.get(), conversionData, object); addStops(gradient.get(), conversionData, object);
...@@ -1247,10 +1247,9 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient( ...@@ -1247,10 +1247,9 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(
RefPtr<Gradient> gradient = RefPtr<Gradient> gradient =
Gradient::create(firstPoint, firstRadius, secondPoint, Gradient::create(firstPoint, firstRadius, secondPoint,
isDegenerate ? 0 : secondRadius.width(), isDegenerate ? 0 : secondRadius.width(),
isDegenerate ? 1 : secondRadius.aspectRatio()); isDegenerate ? 1 : secondRadius.aspectRatio(),
m_repeating ? SpreadMethodRepeat : SpreadMethodPad,
gradient->setSpreadMethod(m_repeating ? SpreadMethodRepeat : SpreadMethodPad); Gradient::ColorInterpolation::Premultiplied);
gradient->setDrawsInPMColorSpace(true);
// Now add the stops. // Now add the stops.
addStops(gradient.get(), conversionData, object); addStops(gradient.get(), conversionData, object);
......
...@@ -52,10 +52,10 @@ FloatPoint LayoutSVGResourceLinearGradient::endPoint( ...@@ -52,10 +52,10 @@ FloatPoint LayoutSVGResourceLinearGradient::endPoint(
PassRefPtr<Gradient> LayoutSVGResourceLinearGradient::buildGradient() const { PassRefPtr<Gradient> LayoutSVGResourceLinearGradient::buildGradient() const {
const LinearGradientAttributes& attributes = this->attributes(); const LinearGradientAttributes& attributes = this->attributes();
RefPtr<Gradient> gradient = RefPtr<Gradient> gradient = Gradient::create(
Gradient::create(startPoint(attributes), endPoint(attributes)); startPoint(attributes), endPoint(attributes),
gradient->setSpreadMethod( platformSpreadMethodFromSVGType(attributes.spreadMethod()),
platformSpreadMethodFromSVGType(attributes.spreadMethod())); Gradient::ColorInterpolation::Unpremultiplied);
gradient->addColorStops(attributes.stops()); gradient->addColorStops(attributes.stops());
return gradient.release(); return gradient.release();
} }
......
...@@ -65,11 +65,11 @@ float LayoutSVGResourceRadialGradient::focalRadius( ...@@ -65,11 +65,11 @@ float LayoutSVGResourceRadialGradient::focalRadius(
PassRefPtr<Gradient> LayoutSVGResourceRadialGradient::buildGradient() const { PassRefPtr<Gradient> LayoutSVGResourceRadialGradient::buildGradient() const {
const RadialGradientAttributes& attributes = this->attributes(); const RadialGradientAttributes& attributes = this->attributes();
RefPtr<Gradient> gradient = RefPtr<Gradient> gradient = Gradient::create(
Gradient::create(focalPoint(attributes), focalRadius(attributes), focalPoint(attributes), focalRadius(attributes), centerPoint(attributes),
centerPoint(attributes), radius(attributes)); radius(attributes), 1,
gradient->setSpreadMethod( platformSpreadMethodFromSVGType(attributes.spreadMethod()),
platformSpreadMethodFromSVGType(attributes.spreadMethod())); Gradient::ColorInterpolation::Unpremultiplied);
gradient->addColorStops(attributes.stops()); gradient->addColorStops(attributes.stops());
return gradient.release(); return gradient.release();
} }
......
...@@ -42,7 +42,10 @@ typedef Vector<SkColor, 8> ColorStopColorVector; ...@@ -42,7 +42,10 @@ typedef Vector<SkColor, 8> ColorStopColorVector;
namespace blink { namespace blink {
Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1) Gradient::Gradient(const FloatPoint& p0,
const FloatPoint& p1,
GradientSpreadMethod spreadMethod,
ColorInterpolation interpolation)
: m_p0(p0), : m_p0(p0),
m_p1(p1), m_p1(p1),
m_r0(0), m_r0(0),
...@@ -50,14 +53,16 @@ Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1) ...@@ -50,14 +53,16 @@ Gradient::Gradient(const FloatPoint& p0, const FloatPoint& p1)
m_aspectRatio(1), m_aspectRatio(1),
m_radial(false), m_radial(false),
m_stopsSorted(false), m_stopsSorted(false),
m_drawInPMColorSpace(false), m_spreadMethod(spreadMethod),
m_spreadMethod(SpreadMethodPad) {} m_colorInterpolation(interpolation) {}
Gradient::Gradient(const FloatPoint& p0, Gradient::Gradient(const FloatPoint& p0,
float r0, float r0,
const FloatPoint& p1, const FloatPoint& p1,
float r1, float r1,
float aspectRatio) float aspectRatio,
GradientSpreadMethod spreadMethod,
ColorInterpolation interpolation)
: m_p0(p0), : m_p0(p0),
m_p1(p1), m_p1(p1),
m_r0(r0), m_r0(r0),
...@@ -65,8 +70,8 @@ Gradient::Gradient(const FloatPoint& p0, ...@@ -65,8 +70,8 @@ Gradient::Gradient(const FloatPoint& p0,
m_aspectRatio(aspectRatio), m_aspectRatio(aspectRatio),
m_radial(true), m_radial(true),
m_stopsSorted(false), m_stopsSorted(false),
m_drawInPMColorSpace(false), m_spreadMethod(spreadMethod),
m_spreadMethod(SpreadMethodPad) {} m_colorInterpolation(interpolation) {}
Gradient::~Gradient() {} Gradient::~Gradient() {}
...@@ -103,25 +108,6 @@ void Gradient::sortStopsIfNecessary() { ...@@ -103,25 +108,6 @@ void Gradient::sortStopsIfNecessary() {
std::stable_sort(m_stops.begin(), m_stops.end(), compareStops); std::stable_sort(m_stops.begin(), m_stops.end(), compareStops);
} }
void Gradient::setSpreadMethod(GradientSpreadMethod spreadMethod) {
// FIXME: Should it become necessary, allow calls to this method after
// |m_gradient| has been set.
DCHECK(!m_cachedShader);
if (m_spreadMethod == spreadMethod)
return;
m_spreadMethod = spreadMethod;
}
void Gradient::setDrawsInPMColorSpace(bool drawInPMColorSpace) {
if (drawInPMColorSpace == m_drawInPMColorSpace)
return;
m_drawInPMColorSpace = drawInPMColorSpace;
m_cachedShader.reset();
}
// Determine the total number of stops needed, including pseudo-stops at the // Determine the total number of stops needed, including pseudo-stops at the
// ends as necessary. // ends as necessary.
static size_t totalStopsNeeded(const Gradient::ColorStop* stopData, static size_t totalStopsNeeded(const Gradient::ColorStop* stopData,
...@@ -208,9 +194,9 @@ sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) { ...@@ -208,9 +194,9 @@ sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) {
} }
sk_sp<SkShader> shader; sk_sp<SkShader> shader;
uint32_t shouldDrawInPMColorSpace = uint32_t flags = m_colorInterpolation == ColorInterpolation::Premultiplied
m_drawInPMColorSpace ? SkGradientShader::kInterpolateColorsInPremul_Flag ? SkGradientShader::kInterpolateColorsInPremul_Flag
: 0; : 0;
if (m_radial) { if (m_radial) {
SkMatrix adjustedLocalMatrix = localMatrix; SkMatrix adjustedLocalMatrix = localMatrix;
...@@ -228,8 +214,7 @@ sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) { ...@@ -228,8 +214,7 @@ sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) {
if (m_p0 == m_p1 && m_r0 <= 0.0f) { if (m_p0 == m_p1 && m_r0 <= 0.0f) {
shader = SkGradientShader::MakeRadial( shader = SkGradientShader::MakeRadial(
m_p1.data(), m_r1, colors.data(), pos.data(), m_p1.data(), m_r1, colors.data(), pos.data(),
static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, static_cast<int>(countUsed), tile, flags, &adjustedLocalMatrix);
&adjustedLocalMatrix);
} else { } else {
// The radii we give to Skia must be positive. If we're given a // The radii we give to Skia must be positive. If we're given a
// negative radius, ask for zero instead. // negative radius, ask for zero instead.
...@@ -237,14 +222,13 @@ sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) { ...@@ -237,14 +222,13 @@ sk_sp<PaintShader> Gradient::createShader(const SkMatrix& localMatrix) {
SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0; SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0;
shader = SkGradientShader::MakeTwoPointConical( shader = SkGradientShader::MakeTwoPointConical(
m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(),
static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, static_cast<int>(countUsed), tile, flags, &adjustedLocalMatrix);
&adjustedLocalMatrix);
} }
} else { } else {
SkPoint pts[2] = {m_p0.data(), m_p1.data()}; SkPoint pts[2] = {m_p0.data(), m_p1.data()};
shader = SkGradientShader::MakeLinear( shader = SkGradientShader::MakeLinear(pts, colors.data(), pos.data(),
pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, static_cast<int>(countUsed), tile,
shouldDrawInPMColorSpace, &localMatrix); flags, &localMatrix);
} }
if (!shader) { if (!shader) {
......
...@@ -49,16 +49,28 @@ class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> { ...@@ -49,16 +49,28 @@ class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> {
WTF_MAKE_NONCOPYABLE(Gradient); WTF_MAKE_NONCOPYABLE(Gradient);
public: public:
static PassRefPtr<Gradient> create(const FloatPoint& p0, enum class ColorInterpolation {
const FloatPoint& p1) { Premultiplied,
return adoptRef(new Gradient(p0, p1)); Unpremultiplied,
};
static PassRefPtr<Gradient> create(
const FloatPoint& p0,
const FloatPoint& p1,
GradientSpreadMethod spreadMethod = SpreadMethodPad,
ColorInterpolation interpolation = ColorInterpolation::Unpremultiplied) {
return adoptRef(new Gradient(p0, p1, spreadMethod, interpolation));
} }
static PassRefPtr<Gradient> create(const FloatPoint& p0, static PassRefPtr<Gradient> create(
float r0, const FloatPoint& p0,
const FloatPoint& p1, float r0,
float r1, const FloatPoint& p1,
float aspectRatio = 1) { float r1,
return adoptRef(new Gradient(p0, r0, p1, r1, aspectRatio)); float aspectRatio = 1,
GradientSpreadMethod spreadMethod = SpreadMethodPad,
ColorInterpolation interpolation = ColorInterpolation::Unpremultiplied) {
return adoptRef(
new Gradient(p0, r0, p1, r1, aspectRatio, spreadMethod, interpolation));
} }
~Gradient(); ~Gradient();
...@@ -117,18 +129,20 @@ class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> { ...@@ -117,18 +129,20 @@ class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> {
void applyToFlags(PaintFlags&, const SkMatrix& localMatrix); void applyToFlags(PaintFlags&, const SkMatrix& localMatrix);
void setDrawsInPMColorSpace(bool drawInPMColorSpace);
void setSpreadMethod(GradientSpreadMethod);
GradientSpreadMethod spreadMethod() const { return m_spreadMethod; } GradientSpreadMethod spreadMethod() const { return m_spreadMethod; }
private: private:
Gradient(const FloatPoint& p0, const FloatPoint& p1); Gradient(const FloatPoint& p0,
const FloatPoint& p1,
GradientSpreadMethod,
ColorInterpolation);
Gradient(const FloatPoint& p0, Gradient(const FloatPoint& p0,
float r0, float r0,
const FloatPoint& p1, const FloatPoint& p1,
float r1, float r1,
float aspectRatio); float aspectRatio,
GradientSpreadMethod,
ColorInterpolation);
sk_sp<PaintShader> createShader(const SkMatrix& localMatrix); sk_sp<PaintShader> createShader(const SkMatrix& localMatrix);
...@@ -142,8 +156,8 @@ class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> { ...@@ -142,8 +156,8 @@ class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> {
Vector<ColorStop, 2> m_stops; Vector<ColorStop, 2> m_stops;
bool m_radial; bool m_radial;
bool m_stopsSorted; bool m_stopsSorted;
bool m_drawInPMColorSpace;
GradientSpreadMethod m_spreadMethod; GradientSpreadMethod m_spreadMethod;
ColorInterpolation m_colorInterpolation;
mutable sk_sp<PaintShader> m_cachedShader; mutable sk_sp<PaintShader> m_cachedShader;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment