Implement 2-pt conical gradient layout
Add an FP that provides the two-point conical gradient effect. The
majority of the new FP's shader code is a straight forward port from
SkTwoPointConicalGradient_gpu.cpp. This FP is bulkier because of the
extensive calculations that go on in its overridden Make function.
To support 2-pt conical gradient's behavior of writing transparent
black in invalid areas of the conical interpolation, the contract of
gradient layout FPs has been updated to provide a flag in the y
component as to whether or not the fragment should be rejected.
A separate channel was used since negative values and large values are
perfectly reasonable for the untiled gradient layout to return (before
the value is then constrained into [0, 1]). It also seemed better to
avoid returning a problematic value like infinity or NaN.
Bug: skia:
Change-Id: I37373bb5aebd89cac8905602e699ad19f0f5ac82
Reviewed-on: https://skia-review.googlesource.com/148988
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/gradients/GrTwoPointConicalGradientLayout.h b/src/gpu/gradients/GrTwoPointConicalGradientLayout.h
new file mode 100644
index 0000000..4bccdea
--- /dev/null
+++ b/src/gpu/gradients/GrTwoPointConicalGradientLayout.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrTwoPointConicalGradientLayout.fp; do not modify.
+ **************************************************************************************************/
+#ifndef GrTwoPointConicalGradientLayout_DEFINED
+#define GrTwoPointConicalGradientLayout_DEFINED
+#include "SkTypes.h"
+
+#include "SkTwoPointConicalGradient.h"
+#include "GrFragmentProcessor.h"
+#include "GrCoordTransform.h"
+class GrTwoPointConicalGradientLayout : public GrFragmentProcessor {
+public:
+ enum class Type { kFocal = 2, kRadial = 0, kStrip = 1 };
+ const SkMatrix44& gradientMatrix() const { return fGradientMatrix; }
+ const Type& type() const { return fType; }
+ bool isRadiusIncreasing() const { return fIsRadiusIncreasing; }
+ bool isFocalOnCircle() const { return fIsFocalOnCircle; }
+ bool isWellBehaved() const { return fIsWellBehaved; }
+ bool isSwapped() const { return fIsSwapped; }
+ bool isNativelyFocal() const { return fIsNativelyFocal; }
+ const SkPoint& focalParams() const { return fFocalParams; }
+
+ static std::unique_ptr<GrFragmentProcessor> Make(const SkTwoPointConicalGradient& gradient,
+ const GrFPArgs& args);
+ GrTwoPointConicalGradientLayout(const GrTwoPointConicalGradientLayout& src);
+ std::unique_ptr<GrFragmentProcessor> clone() const override;
+ const char* name() const override { return "TwoPointConicalGradientLayout"; }
+
+private:
+ GrTwoPointConicalGradientLayout(SkMatrix44 gradientMatrix,
+ Type type,
+ bool isRadiusIncreasing,
+ bool isFocalOnCircle,
+ bool isWellBehaved,
+ bool isSwapped,
+ bool isNativelyFocal,
+ SkPoint focalParams)
+ : INHERITED(kGrTwoPointConicalGradientLayout_ClassID, kNone_OptimizationFlags)
+ , fGradientMatrix(gradientMatrix)
+ , fType(type)
+ , fIsRadiusIncreasing(isRadiusIncreasing)
+ , fIsFocalOnCircle(isFocalOnCircle)
+ , fIsWellBehaved(isWellBehaved)
+ , fIsSwapped(isSwapped)
+ , fIsNativelyFocal(isNativelyFocal)
+ , fFocalParams(focalParams)
+ , fCoordTransform0(gradientMatrix) {
+ this->addCoordTransform(&fCoordTransform0);
+ }
+ GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
+ void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+ bool onIsEqual(const GrFragmentProcessor&) const override;
+ GR_DECLARE_FRAGMENT_PROCESSOR_TEST
+ SkMatrix44 fGradientMatrix;
+ Type fType;
+ bool fIsRadiusIncreasing;
+ bool fIsFocalOnCircle;
+ bool fIsWellBehaved;
+ bool fIsSwapped;
+ bool fIsNativelyFocal;
+ SkPoint fFocalParams;
+ GrCoordTransform fCoordTransform0;
+ typedef GrFragmentProcessor INHERITED;
+};
+#endif