Particles: Improvements to SkCurve
Added explicit Linear segment type, merge math evaluation helpers for
scalar and color curves. Add logic to visitFields that cuts down on the
serialized size of simple curves, and makes the GUI easier to work with.
Remove the curve plot from the GUI. It was incorrect (wrong points at
cubic handle locations), not terribly helpful, and difficult to
maintain.
Bug: skia:
Change-Id: I190cb5d118b1f4b910984e4df50ee3351c8be895
Reviewed-on: https://skia-review.googlesource.com/c/195884
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/modules/particles/include/SkCurve.h b/modules/particles/include/SkCurve.h
index ec61228..076a1aa 100644
--- a/modules/particles/include/SkCurve.h
+++ b/modules/particles/include/SkCurve.h
@@ -44,20 +44,26 @@
* 50% of the time.
*/
+enum SkCurveSegmentType {
+ kConstant_SegmentType,
+ kLinear_SegmentType,
+ kCubic_SegmentType,
+};
+
struct SkCurveSegment {
SkScalar eval(SkScalar x, SkScalar t, bool negate) const;
void visitFields(SkFieldVisitor* v);
void setConstant(SkScalar c) {
- fConstant = true;
- fRanged = false;
+ fType = kConstant_SegmentType;
+ fRanged = false;
fMin[0] = c;
}
SkScalar fMin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
SkScalar fMax[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
- bool fConstant = true;
+ int fType = kConstant_SegmentType;
bool fRanged = false;
bool fBidirectional = false;
};
@@ -71,9 +77,6 @@
SkScalar eval(SkScalar x, SkRandom& random) const;
void visitFields(SkFieldVisitor* v);
- // Returns the (very conversative) range of this SkCurve in extents (as [minimum, maximum]).
- void getExtents(SkScalar extents[2]) const;
-
// It should always be true that (fXValues.count() + 1) == fSegments.count()
SkTArray<SkScalar, true> fXValues;
SkTArray<SkCurveSegment, true> fSegments;
@@ -97,7 +100,7 @@
void visitFields(SkFieldVisitor* v);
void setConstant(SkColor4f c) {
- fConstant = true;
+ fType = kConstant_SegmentType;
fRanged = false;
fMin[0] = c;
}
@@ -105,7 +108,7 @@
SkColor4f fMin[4];
SkColor4f fMax[4];
- bool fConstant = true;
+ int fType = kConstant_SegmentType;
bool fRanged = false;
};