Add SkParticleValue to allow further customization of curve behavior
All curves (and path affectors) are driven by an SkParticleValue. The
value can derive its value from the current defaults (age of particle
or effect), or explicitly choose the other one, a random value, or any
other particle value. Values can be range adjusted and support repeat,
clamp, and mirror tiling.
Also fixed some more issues related to resource path in the slide GUI.
Bug: skia:
Change-Id: I4755018d5b57ae2d5ec400d541055ca4fb542978
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/196760
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/modules/particles/src/SkCurve.cpp b/modules/particles/src/SkCurve.cpp
index 3dc7819..5dcfb60d 100644
--- a/modules/particles/src/SkCurve.cpp
+++ b/modules/particles/src/SkCurve.cpp
@@ -7,6 +7,7 @@
#include "SkCurve.h"
+#include "SkParticleData.h"
#include "SkRandom.h"
#include "SkReflected.h"
@@ -78,9 +79,11 @@
}
}
-SkScalar SkCurve::eval(SkScalar x, SkRandom& random) const {
+SkScalar SkCurve::eval(const SkParticleUpdateParams& params, SkParticleState& ps) const {
SkASSERT(fSegments.count() == fXValues.count() + 1);
+ float x = fInput.eval(params, ps);
+
int i = 0;
for (; i < fXValues.count(); ++i) {
if (x <= fXValues[i]) {
@@ -98,12 +101,13 @@
// Always pull t and negate here, so that the stable generator behaves consistently, even if
// our segments use an inconsistent feature-set.
- SkScalar t = random.nextF();
- bool negate = random.nextBool();
+ SkScalar t = ps.fRandom.nextF();
+ bool negate = ps.fRandom.nextBool();
return fSegments[i].eval(segmentX, t, negate);
}
void SkCurve::visitFields(SkFieldVisitor* v) {
+ v->visit("Input", fInput);
v->visit("XValues", fXValues);
v->visit("Segments", fSegments);
@@ -117,10 +121,10 @@
}
}
-SkColor4f SkColorCurveSegment::eval(SkScalar x, SkRandom& random) const {
+SkColor4f SkColorCurveSegment::eval(SkScalar x, SkScalar t) const {
SkColor4f result = eval_segment(fMin, x, fType);
if (fRanged) {
- result = result + (eval_segment(fMax, x, fType) - result) * random.nextF();
+ result = result + (eval_segment(fMax, x, fType) - result) * t;
}
return result;
}
@@ -148,9 +152,11 @@
}
}
-SkColor4f SkColorCurve::eval(SkScalar x, SkRandom& random) const {
+SkColor4f SkColorCurve::eval(const SkParticleUpdateParams& params, SkParticleState& ps) const {
SkASSERT(fSegments.count() == fXValues.count() + 1);
+ float x = fInput.eval(params, ps);
+
int i = 0;
for (; i < fXValues.count(); ++i) {
if (x <= fXValues[i]) {
@@ -165,10 +171,11 @@
segmentX = rangeMin;
}
SkASSERT(0.0f <= segmentX && segmentX <= 1.0f);
- return fSegments[i].eval(segmentX, random);
+ return fSegments[i].eval(segmentX, ps.fRandom.nextF());
}
void SkColorCurve::visitFields(SkFieldVisitor* v) {
+ v->visit("Input", fInput);
v->visit("XValues", fXValues);
v->visit("Segments", fSegments);