Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Unified Diff: third_party/WebKit/Source/platform/graphics/Gradient.cpp

Issue 2787113002: Initial conic-gradient() implementation (Closed)
Patch Set: silence msvc warning Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/Gradient.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Gradient.cpp b/third_party/WebKit/Source/platform/graphics/Gradient.cpp
index f3705a6e070cadf1ded8c5d72e08dc102e7c8b82..06e993f00b2519fcd71a955665c52af126624284 100644
--- a/third_party/WebKit/Source/platform/graphics/Gradient.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Gradient.cpp
@@ -192,8 +192,8 @@ class LinearGradient final : public Gradient {
}
private:
- FloatPoint m_p0;
- FloatPoint m_p1;
+ const FloatPoint m_p0;
+ const FloatPoint m_p1;
};
class RadialGradient final : public Gradient {
@@ -246,11 +246,50 @@ class RadialGradient final : public Gradient {
}
private:
- FloatPoint m_p0;
- FloatPoint m_p1;
- float m_r0;
- float m_r1;
- float m_aspectRatio; // For elliptical gradient, width / height.
+ const FloatPoint m_p0;
+ const FloatPoint m_p1;
+ const float m_r0;
+ const float m_r1;
+ const float m_aspectRatio; // For elliptical gradient, width / height.
+};
+
+class ConicGradient final : public Gradient {
+ public:
+ ConicGradient(const FloatPoint& position,
+ float angle,
+ GradientSpreadMethod spreadMethod,
+ ColorInterpolation interpolation)
+ : Gradient(Type::Conic, spreadMethod, interpolation),
+ m_position(position),
+ m_angle(angle) {}
+
+ protected:
+ sk_sp<SkShader> createShader(const ColorBuffer& colors,
+ const OffsetBuffer& pos,
+ SkShader::TileMode tileMode,
+ uint32_t flags,
+ const SkMatrix& localMatrix) const override {
+ if (tileMode != SkShader::kClamp_TileMode) {
+ // TODO(fmalita): kRepeat support
+ return nullptr;
+ }
+
+ // Skia's sweep gradient angles are relative to the x-axis, not the y-axis.
+ const float skiaAngle = m_angle - 90;
+ SkTCopyOnFirstWrite<SkMatrix> adjustedLocalMatrix(localMatrix);
+ if (skiaAngle) {
+ adjustedLocalMatrix.writable()->preRotate(skiaAngle, m_position.x(),
+ m_position.y());
+ }
+
+ return SkGradientShader::MakeSweep(
+ m_position.x(), m_position.y(), colors.data(), pos.data(),
+ static_cast<int>(colors.size()), flags, adjustedLocalMatrix);
+ }
+
+ private:
+ const FloatPoint m_position;
+ const float m_angle;
};
} // anonymous ns
@@ -273,4 +312,12 @@ PassRefPtr<Gradient> Gradient::createRadial(const FloatPoint& p0,
interpolation));
}
+PassRefPtr<Gradient> Gradient::createConic(const FloatPoint& position,
+ float angle,
+ GradientSpreadMethod spreadMethod,
+ ColorInterpolation interpolation) {
+ return adoptRef(
+ new ConicGradient(position, angle, spreadMethod, interpolation));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698