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

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

Issue 2787113002: Initial conic-gradient() implementation (Closed)
Patch Set: baselines 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Gradient.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2ed0e01614269ba26327a1b8845be2e3234a1f70..df22651ca055c1830cf86701445ff2e07922c3bd 100644
--- a/third_party/WebKit/Source/platform/graphics/Gradient.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Gradient.cpp
@@ -194,8 +194,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 {
@@ -248,11 +248,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
@@ -275,4 +314,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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Gradient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698