aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders/gradients/SkTwoPointConicalGradient.h
diff options
context:
space:
mode:
authorGravatar Yuqian Li <liyuqian@google.com>2018-01-04 10:08:42 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-05 19:33:25 +0000
commitd208a8847777d4643188813f03a15dfed4887365 (patch)
tree2e32f528f77bb3b3ac04bc6b551a16463af4cac9 /src/shaders/gradients/SkTwoPointConicalGradient.h
parentfa3783f17dba971e3204ba950965d9c65eb8711d (diff)
Update 2pt conical gradient in raster pipeline
The updated algorithm matches our new GPU algorithm (https://skia.org/dev/design/conical) and it brings about 7%-26% speedup. In the next CL, I'll simplify the GPU code by reusing the CPU code in this CL. 7.20% faster in gradient_conical_clamp_hicolor 8.94% faster in gradient_conicalZero_clamp_hicolor 10.00% faster in gradient_conicalOut_clamp_hicolor 11.72% faster in gradient_conicalOutZero_clamp_hicolor 13.62% faster in gradient_conical_clamp_3color 16.52% faster in gradient_conicalZero_clamp_3color 17.48% faster in gradient_conical_clamp 17.70% faster in gradient_conical_clamp_shallow 20.60% faster in gradient_conicalOut_clamp_3color 20.98% faster in gradient_conicalOutZero_clamp_3color 21.79% faster in gradient_conicalZero_clamp 22.48% faster in gradient_conicalOut_clamp 26.13% faster in gradient_conicalOutZero_clamp Bug: skia: Change-Id: Ia159495e1c77658cb28e48c9edf84938464e501c Reviewed-on: https://skia-review.googlesource.com/90262 Commit-Queue: Yuqian Li <liyuqian@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/shaders/gradients/SkTwoPointConicalGradient.h')
-rw-r--r--src/shaders/gradients/SkTwoPointConicalGradient.h31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/shaders/gradients/SkTwoPointConicalGradient.h b/src/shaders/gradients/SkTwoPointConicalGradient.h
index 96039e4771..623e69f95a 100644
--- a/src/shaders/gradients/SkTwoPointConicalGradient.h
+++ b/src/shaders/gradients/SkTwoPointConicalGradient.h
@@ -13,6 +13,30 @@
class SkTwoPointConicalGradient final : public SkGradientShaderBase {
public:
+ // See https://skia.org/dev/design/conical for what focal data means and how our shader works.
+ // We make it public so the GPU shader can also use it.
+ struct FocalData {
+ SkScalar fR1; // r1 after mapping focal point to (0, 0)
+ SkScalar fFocalX; // f
+ bool fIsSwapped; // whether we swapped r0, r1
+
+ // The input r0, r1 are the radii when we map centers to {(0, 0), (1, 0)}.
+ // We'll post concat matrix with our transformation matrix that maps focal point to (0, 0).
+ void set(SkScalar r0, SkScalar r1, SkMatrix& matrix);
+
+ // Whether the focal point (0, 0) is on the end circle with center (1, 0) and radius r1. If
+ // this is true, it's as if an aircraft is flying at Mach 1 and all circles (soundwaves)
+ // will go through the focal point (aircraft). In our previous implementations, this was
+ // known as the edge case where the inside circle touches the outside circle (on the focal
+ // point). If we were to solve for t bruteforcely using a quadratic equation, this case
+ // implies that the quadratic equation degenerates to a linear equation.
+ bool isFocalOnCircle() const { return SkScalarNearlyZero(1 - fR1); }
+
+ bool isSwapped() const { return fIsSwapped; }
+ bool isWellBehaved() const { return !this->isFocalOnCircle() && fR1 > 1; }
+ bool isNativelyFocal() const { return SkScalarNearlyZero(fFocalX); }
+ };
+
static sk_sp<SkShader> Create(const SkPoint& start, SkScalar startRadius,
const SkPoint& end, SkScalar endRadius,
const Descriptor&);
@@ -45,12 +69,13 @@ protected:
private:
enum class Type {
kRadial,
- kTwoPoint,
+ kStrip,
+ kFocal
};
SkTwoPointConicalGradient(const SkPoint& c0, SkScalar r0,
const SkPoint& c1, SkScalar r1,
- const Descriptor&, Type, const SkMatrix&);
+ const Descriptor&, Type, const SkMatrix&, const FocalData&);
SkPoint fCenter1;
SkPoint fCenter2;
@@ -58,6 +83,8 @@ private:
SkScalar fRadius2;
Type fType;
+ FocalData fFocalData;
+
friend class SkGradientShader;
typedef SkGradientShaderBase INHERITED;
};