Particles: SkScalar -> float

Pulling this cleanup out of a larger CL

Change-Id: Ib3ecff5d242eba72a7f2bc3ce07e09760a9ba7b7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223181
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2019-06-24 10:44:02 -04:00 committed by Skia Commit-Bot
parent 91032f8cd7
commit e1cb9ac0e1
2 changed files with 25 additions and 26 deletions

View File

@ -9,7 +9,6 @@
#define SkCurve_DEFINED
#include "include/core/SkColor.h"
#include "include/core/SkScalar.h"
#include "include/private/SkTArray.h"
#include "modules/particles/include/SkParticleData.h"
@ -50,17 +49,17 @@ enum SkCurveSegmentType {
};
struct SkCurveSegment {
SkScalar eval(SkScalar x, SkScalar t, bool negate) const;
float eval(float x, float t, bool negate) const;
void visitFields(SkFieldVisitor* v);
void setConstant(SkScalar c) {
void setConstant(float c) {
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 };
float fMin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
float fMax[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
int fType = kConstant_SegmentType;
bool fRanged = false;
@ -68,18 +67,18 @@ struct SkCurveSegment {
};
struct SkCurve {
SkCurve(SkScalar c = 0.0f) {
SkCurve(float c = 0.0f) {
fSegments.push_back().setConstant(c);
}
SkScalar eval(const SkParticleUpdateParams& params, SkParticleState& ps) const;
float eval(const SkParticleUpdateParams& params, SkParticleState& ps) const;
void visitFields(SkFieldVisitor* v);
// Parameters that determine our x-value during evaluation
SkParticleValue fInput;
// It should always be true that (fXValues.count() + 1) == fSegments.count()
SkTArray<SkScalar, true> fXValues;
SkTArray<float, true> fXValues;
SkTArray<SkCurveSegment, true> fSegments;
};
@ -97,7 +96,7 @@ struct SkColorCurveSegment {
}
}
SkColor4f eval(SkScalar x, SkScalar t) const;
SkColor4f eval(float x, float t) const;
void visitFields(SkFieldVisitor* v);
void setConstant(SkColor4f c) {
@ -122,7 +121,7 @@ struct SkColorCurve {
void visitFields(SkFieldVisitor* v);
SkParticleValue fInput;
SkTArray<SkScalar, true> fXValues;
SkTArray<float, true> fXValues;
SkTArray<SkColorCurveSegment, true> fSegments;
};

View File

@ -26,13 +26,13 @@ static SkColor4f operator-(SkColor4f c1, SkColor4f c2) {
}
template <typename T>
static T eval_cubic(const T* pts, SkScalar x) {
SkScalar ix = (1 - x);
static T eval_cubic(const T* pts, float x) {
float ix = (1 - x);
return pts[0]*(ix*ix*ix) + pts[1]*(3*ix*ix*x) + pts[2]*(3*ix*x*x) + pts[3]*(x*x*x);
}
template <typename T>
static T eval_segment(const T* pts, SkScalar x, int type) {
static T eval_segment(const T* pts, float x, int type) {
switch (type) {
case kLinear_SegmentType:
return pts[0] + (pts[3] - pts[0]) * x;
@ -44,8 +44,8 @@ static T eval_segment(const T* pts, SkScalar x, int type) {
}
}
SkScalar SkCurveSegment::eval(SkScalar x, SkScalar t, bool negate) const {
SkScalar result = eval_segment(fMin, x, fType);
float SkCurveSegment::eval(float x, float t, bool negate) const {
float result = eval_segment(fMin, x, fType);
if (fRanged) {
result += (eval_segment(fMax, x, fType) - result) * t;
}
@ -79,7 +79,7 @@ void SkCurveSegment::visitFields(SkFieldVisitor* v) {
}
}
SkScalar SkCurve::eval(const SkParticleUpdateParams& params, SkParticleState& ps) const {
float SkCurve::eval(const SkParticleUpdateParams& params, SkParticleState& ps) const {
SkASSERT(fSegments.count() == fXValues.count() + 1);
float x = fInput.eval(params, ps);
@ -91,17 +91,17 @@ SkScalar SkCurve::eval(const SkParticleUpdateParams& params, SkParticleState& ps
}
}
SkScalar rangeMin = (i == 0) ? 0.0f : fXValues[i - 1];
SkScalar rangeMax = (i == fXValues.count()) ? 1.0f : fXValues[i];
SkScalar segmentX = (x - rangeMin) / (rangeMax - rangeMin);
if (!SkScalarIsFinite(segmentX)) {
float rangeMin = (i == 0) ? 0.0f : fXValues[i - 1];
float rangeMax = (i == fXValues.count()) ? 1.0f : fXValues[i];
float segmentX = (x - rangeMin) / (rangeMax - rangeMin);
if (!sk_float_isfinite(segmentX)) {
segmentX = rangeMin;
}
SkASSERT(0.0f <= segmentX && segmentX <= 1.0f);
// Always pull t and negate here, so that the stable generator behaves consistently, even if
// our segments use an inconsistent feature-set.
SkScalar t = ps.fRandom.nextF();
float t = ps.fRandom.nextF();
bool negate = ps.fRandom.nextBool();
return fSegments[i].eval(segmentX, t, negate);
}
@ -121,7 +121,7 @@ void SkCurve::visitFields(SkFieldVisitor* v) {
}
}
SkColor4f SkColorCurveSegment::eval(SkScalar x, SkScalar t) const {
SkColor4f SkColorCurveSegment::eval(float x, float t) const {
SkColor4f result = eval_segment(fMin, x, fType);
if (fRanged) {
result = result + (eval_segment(fMax, x, fType) - result) * t;
@ -164,10 +164,10 @@ SkColor4f SkColorCurve::eval(const SkParticleUpdateParams& params, SkParticleSta
}
}
SkScalar rangeMin = (i == 0) ? 0.0f : fXValues[i - 1];
SkScalar rangeMax = (i == fXValues.count()) ? 1.0f : fXValues[i];
SkScalar segmentX = (x - rangeMin) / (rangeMax - rangeMin);
if (!SkScalarIsFinite(segmentX)) {
float rangeMin = (i == 0) ? 0.0f : fXValues[i - 1];
float rangeMax = (i == fXValues.count()) ? 1.0f : fXValues[i];
float segmentX = (x - rangeMin) / (rangeMax - rangeMin);
if (!sk_float_isfinite(segmentX)) {
segmentX = rangeMin;
}
SkASSERT(0.0f <= segmentX && segmentX <= 1.0f);