Remove SkScalarClampMax and SkScalarPin

Change-Id: Ic96a0ea2cd1bfd59ee3f236543e1d6dd102544ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269142
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Brian Osman 2020-02-06 12:52:25 -05:00 committed by Skia Commit-Bot
parent 7f36405ea3
commit aba642c6ac
22 changed files with 60 additions and 69 deletions

View File

@ -7,6 +7,7 @@ This file includes a list of high level updates for each milestone release.
Milestone 82
<Insert new notes here- top is most recent.>
* Removed SkScalarClampMax and SkScalarPin.
* Removed SkMax32 and SkMin32.
* Removed SkMaxScalar and SkMinScalar.

View File

@ -413,17 +413,17 @@ static void convert_rgba_to_yuva(const float mtx[20], SkColor col, uint8_t yuv[4
const uint8_t g = SkColorGetG(col);
const uint8_t b = SkColorGetB(col);
yuv[0] = SkScalarPin(SkScalarRoundToInt(mtx[ 0]*r + mtx[ 1]*g + mtx[ 2]*b + mtx[ 4]*255), 0, 255);
yuv[1] = SkScalarPin(SkScalarRoundToInt(mtx[ 5]*r + mtx[ 6]*g + mtx[ 7]*b + mtx[ 9]*255), 0, 255);
yuv[2] = SkScalarPin(SkScalarRoundToInt(mtx[10]*r + mtx[11]*g + mtx[12]*b + mtx[14]*255), 0, 255);
yuv[0] = SkTPin(SkScalarRoundToInt(mtx[ 0]*r + mtx[ 1]*g + mtx[ 2]*b + mtx[ 4]*255), 0, 255);
yuv[1] = SkTPin(SkScalarRoundToInt(mtx[ 5]*r + mtx[ 6]*g + mtx[ 7]*b + mtx[ 9]*255), 0, 255);
yuv[2] = SkTPin(SkScalarRoundToInt(mtx[10]*r + mtx[11]*g + mtx[12]*b + mtx[14]*255), 0, 255);
yuv[3] = SkColorGetA(col);
}
static SkPMColor convert_yuva_to_rgba(const float mtx[20],
uint8_t y, uint8_t u, uint8_t v, uint8_t a) {
uint8_t r = SkScalarPin(SkScalarRoundToInt(mtx[ 0]*y + mtx[ 1]*u + mtx[ 2]*v + mtx[ 4]*255), 0, 255);
uint8_t g = SkScalarPin(SkScalarRoundToInt(mtx[ 5]*y + mtx[ 6]*u + mtx[ 7]*v + mtx[ 9]*255), 0, 255);
uint8_t b = SkScalarPin(SkScalarRoundToInt(mtx[10]*y + mtx[11]*u + mtx[12]*v + mtx[14]*255), 0, 255);
uint8_t r = SkTPin(SkScalarRoundToInt(mtx[ 0]*y + mtx[ 1]*u + mtx[ 2]*v + mtx[ 4]*255), 0, 255);
uint8_t g = SkTPin(SkScalarRoundToInt(mtx[ 5]*y + mtx[ 6]*u + mtx[ 7]*v + mtx[ 9]*255), 0, 255);
uint8_t b = SkTPin(SkScalarRoundToInt(mtx[10]*y + mtx[11]*u + mtx[12]*v + mtx[14]*255), 0, 255);
return SkPremultiplyARGBInline(a, r, g, b);
}

View File

@ -31,7 +31,7 @@ static inline unsigned SkAlpha255To256(U8CPU alpha) {
#define SkAlphaMul(value, alpha256) (((value) * (alpha256)) >> 8)
static inline U8CPU SkUnitScalarClampToByte(SkScalar x) {
return static_cast<U8CPU>(SkScalarPin(x, 0, 1) * 255 + 0.5);
return static_cast<U8CPU>(SkTPin(x, 0.0f, 1.0f) * 255 + 0.5);
}
#define SK_A32_BITS 8

View File

@ -103,16 +103,6 @@ static inline SkScalar SkScalarFraction(SkScalar x) {
return x - SkScalarTruncToScalar(x);
}
static inline SkScalar SkScalarClampMax(SkScalar x, SkScalar max) {
x = SkTMin(x, max);
x = SkTMax<SkScalar>(x, 0);
return x;
}
static inline SkScalar SkScalarPin(SkScalar x, SkScalar min, SkScalar max) {
return SkTPin(x, min, max);
}
static inline SkScalar SkScalarSquare(SkScalar x) { return x * x; }
#define SkScalarInvert(x) sk_ieee_float_divide_TODO_IS_DIVIDE_BY_ZERO_SAFE_HERE(SK_Scalar1, (x))

View File

@ -216,10 +216,10 @@ static SkScalar get_framed_coverage(const SkPoint outer[4], const SkScalar outer
SkScalar coverage = bary[0] * c0 + bary[1] * c1 + bary[2] * c2;
if (coverage < 0.5f) {
// Check distances to domain
SkScalar l = SkScalarPin(point.fX - geomDomain.fLeft, 0.f, 1.f);
SkScalar t = SkScalarPin(point.fY - geomDomain.fTop, 0.f, 1.f);
SkScalar r = SkScalarPin(geomDomain.fRight - point.fX, 0.f, 1.f);
SkScalar b = SkScalarPin(geomDomain.fBottom - point.fY, 0.f, 1.f);
SkScalar l = SkTPin(point.fX - geomDomain.fLeft, 0.f, 1.f);
SkScalar t = SkTPin(point.fY - geomDomain.fTop, 0.f, 1.f);
SkScalar r = SkTPin(geomDomain.fRight - point.fX, 0.f, 1.f);
SkScalar b = SkTPin(geomDomain.fBottom - point.fY, 0.f, 1.f);
coverage = std::min(coverage, l * t * r * b);
}
return coverage;

View File

@ -73,8 +73,8 @@ void SkRGBToHSV(U8CPU r, U8CPU g, U8CPU b, SkScalar hsv[3]) {
SkColor SkHSVToColor(U8CPU a, const SkScalar hsv[3]) {
SkASSERT(hsv);
SkScalar s = SkScalarPin(hsv[1], 0, 1);
SkScalar v = SkScalarPin(hsv[2], 0, 1);
SkScalar s = SkTPin(hsv[1], 0.0f, 1.0f);
SkScalar v = SkTPin(hsv[2], 0.0f, 1.0f);
U8CPU v_byte = SkScalarRoundToInt(v * 255);

View File

@ -52,7 +52,7 @@ static float compute_t_from_x(float A, float B, float C, float x) {
}
float SkCubicMap::computeYFromX(float x) const {
x = SkScalarPin(x, 0, 1);
x = SkTPin(x, 0.0f, 1.0f);
if (nearly_zero(x) || nearly_zero(1 - x)) {
return x;

View File

@ -327,7 +327,7 @@ static unsigned char pack_distance_field_val(float dist) {
// The distance field is constructed as unsigned char values, so that the zero value is at 128,
// Beside 128, we have 128 values in range [0, 128), but only 127 values in range (128, 255].
// So we multiply distanceMagnitude by 127/128 at the latter range to avoid overflow.
dist = SkScalarPin(-dist, -distanceMagnitude, distanceMagnitude * 127.0f / 128.0f);
dist = SkTPin<float>(-dist, -distanceMagnitude, distanceMagnitude * 127.0f / 128.0f);
// Scale into the positive range for unsigned distance.
dist += distanceMagnitude;

View File

@ -769,12 +769,12 @@ static int solve_cubic_poly(const SkScalar coeff[4], SkScalar tValues[3]) {
if (R2MinusQ3 < 0) { // we have 3 real roots
// the divide/root can, due to finite precisions, be slightly outside of -1...1
SkScalar theta = SkScalarACos(SkScalarPin(R / SkScalarSqrt(Q3), -1, 1));
SkScalar theta = SkScalarACos(SkTPin(R / SkScalarSqrt(Q3), -1.0f, 1.0f));
SkScalar neg2RootQ = -2 * SkScalarSqrt(Q);
tValues[0] = SkScalarPin(neg2RootQ * SkScalarCos(theta/3) - adiv3, 0, 1);
tValues[1] = SkScalarPin(neg2RootQ * SkScalarCos((theta + 2*SK_ScalarPI)/3) - adiv3, 0, 1);
tValues[2] = SkScalarPin(neg2RootQ * SkScalarCos((theta - 2*SK_ScalarPI)/3) - adiv3, 0, 1);
tValues[0] = SkTPin(neg2RootQ * SkScalarCos(theta/3) - adiv3, 0.0f, 1.0f);
tValues[1] = SkTPin(neg2RootQ * SkScalarCos((theta + 2*SK_ScalarPI)/3) - adiv3, 0.0f, 1.0f);
tValues[2] = SkTPin(neg2RootQ * SkScalarCos((theta - 2*SK_ScalarPI)/3) - adiv3, 0.0f, 1.0f);
SkDEBUGCODE(test_collaps_duplicates();)
// now sort the roots
@ -789,7 +789,7 @@ static int solve_cubic_poly(const SkScalar coeff[4], SkScalar tValues[3]) {
if (A != 0) {
A += Q / A;
}
tValues[0] = SkScalarPin(A - adiv3, 0, 1);
tValues[0] = SkTPin(A - adiv3, 0.0f, 1.0f);
return 1;
}
}

View File

@ -51,7 +51,7 @@ sk_sp<SkMaskFilter> SkBlurMaskFilter::MakeEmboss(SkScalar blurSigma, const SkSca
light.fAmbient = SkUnitScalarClampToByte(ambient);
// specular should be 0..15.99 as a scalar
static const SkScalar kSpecularMultiplier = SkIntToScalar(255) / 16;
light.fSpecular = static_cast<U8CPU>(SkScalarPin(specular, 0, 16) * kSpecularMultiplier + 0.5);
light.fSpecular = static_cast<U8CPU>(SkTPin(specular, 0.0f, 16.0f) * kSpecularMultiplier + 0.5);
return SkEmbossMaskFilter::Make(blurSigma, light);
}

View File

@ -28,9 +28,9 @@ public:
SkHighContrast_Filter(const SkHighContrastConfig& config) {
fConfig = config;
// Clamp contrast to just inside -1 to 1 to avoid division by zero.
fConfig.fContrast = SkScalarPin(fConfig.fContrast,
-1.0f + FLT_EPSILON,
1.0f - FLT_EPSILON);
fConfig.fContrast = SkTPin(fConfig.fContrast,
-1.0f + FLT_EPSILON,
1.0f - FLT_EPSILON);
}
~SkHighContrast_Filter() override {}

View File

@ -67,8 +67,8 @@ sk_sp<SkImageFilter> SkAlphaThresholdFilter::Make(const SkRegion& region, SkScal
SkScalar outerThreshold,
sk_sp<SkImageFilter> input,
const SkImageFilter::CropRect* cropRect) {
innerThreshold = SkScalarPin(innerThreshold, 0.f, 1.f);
outerThreshold = SkScalarPin(outerThreshold, 0.f, 1.f);
innerThreshold = SkTPin(innerThreshold, 0.f, 1.f);
outerThreshold = SkTPin(outerThreshold, 0.f, 1.f);
if (!SkScalarIsFinite(innerThreshold) || !SkScalarIsFinite(outerThreshold)) {
return nullptr;
}

View File

@ -164,7 +164,7 @@ public:
SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight,
const SkPoint3& lightColor) const override {
SkScalar colorScale = fKD * normal.dot(surfaceTolight);
colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
colorScale = SkTPin(colorScale, 0.0f, SK_Scalar1);
SkPoint3 color = lightColor.makeScale(colorScale);
return SkPackARGB32(255,
SkClampMax(SkScalarRoundToInt(color.fX), 255),
@ -189,7 +189,7 @@ public:
halfDir.fZ += SK_Scalar1; // eye position is always (0, 0, 1)
fast_normalize(&halfDir);
SkScalar colorScale = fKS * SkScalarPow(normal.dot(halfDir), fShininess);
colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
colorScale = SkTPin(colorScale, 0.0f, SK_Scalar1);
SkPoint3 color = lightColor.makeScale(colorScale);
return SkPackARGB32(SkClampMax(SkScalarRoundToInt(max_component(color)), 255),
SkClampMax(SkScalarRoundToInt(color.fX), 255),
@ -967,7 +967,7 @@ public:
: INHERITED(color),
fLocation(location),
fTarget(target),
fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSpecularExponentMax))
fSpecularExponent(SkTPin(specularExponent, kSpecularExponentMin, kSpecularExponentMax))
{
fS = target - location;
fast_normalize(&fS);

View File

@ -242,8 +242,8 @@ void PathSegment::init() {
SkPoint t = _P1mP0 - fPts[2] + fPts[1];
t.fX = _P1mP0.fX / t.fX;
t.fY = _P1mP0.fY / t.fY;
t.fX = SkScalarClampMax(t.fX, 1.0);
t.fY = SkScalarClampMax(t.fY, 1.0);
t.fX = SkTPin(t.fX, 0.0f, 1.0f);
t.fY = SkTPin(t.fY, 0.0f, 1.0f);
t.fX = _P1mP0.fX * t.fX;
t.fY = _P1mP0.fY * t.fY;
const SkPoint m = fPts[0] + t;
@ -695,7 +695,7 @@ static unsigned char pack_distance_field_val(float dist) {
// The distance field is constructed as unsigned char values, so that the zero value is at 128,
// Beside 128, we have 128 values in range [0, 128), but only 127 values in range (128, 255].
// So we multiply distanceMagnitude by 127/128 at the latter range to avoid overflow.
dist = SkScalarPin(-dist, -distanceMagnitude, distanceMagnitude * 127.0f / 128.0f);
dist = SkTPin<float>(-dist, -distanceMagnitude, distanceMagnitude * 127.0f / 128.0f);
// Scale into the positive range for unsigned distance.
dist += distanceMagnitude;

View File

@ -35,62 +35,62 @@ bool GrOctoBounds::clip(const SkIRect& clipRect) {
// y = x + (y0 - x0)
// Substitute: l45 = x0 - y0
// y = x - l45
b = SkScalarPin(r - l45, t, b);
b = SkTPin(r - l45, t, b);
} else if (r45 < Get_x45(r,b)) {
// Slide the right side leftward until it crosses the r45 diagonal at y=b.
// x = y + (x0 - y0)
// Substitute: r45 = x0 - y0
// x = y + r45
r = SkScalarPin(b + r45, l, r);
r = SkTPin(b + r45, l, r);
}
if (l45 > Get_x45(l,t)) {
// Slide the left side rightward until it crosses the l45 diagonal at y=t.
// x = y + (x0 - y0)
// Substitute: l45 = x0 - y0
// x = y + l45
l = SkScalarPin(t + l45, l, r);
l = SkTPin(t + l45, l, r);
} else if (r45 < Get_x45(l,t)) {
// Slide the top downward until it crosses the r45 diagonal at x=l.
// y = x + (y0 - x0)
// Substitute: r45 = x0 - y0
// y = x - r45
t = SkScalarPin(l - r45, t, b);
t = SkTPin(l - r45, t, b);
}
if (t45 > Get_y45(l,b)) {
// Slide the left side rightward until it crosses the t45 diagonal at y=b.
// x = -y + (x0 + y0)
// Substitute: t45 = x0 + y0
// x = -y + t45
l = SkScalarPin(t45 - b, l, r);
l = SkTPin(t45 - b, l, r);
} else if (b45 < Get_y45(l,b)) {
// Slide the bottom upward until it crosses the b45 diagonal at x=l.
// y = -x + (y0 + x0)
// Substitute: b45 = x0 + y0
// y = -x + b45
b = SkScalarPin(b45 - l, t, b);
b = SkTPin(b45 - l, t, b);
}
if (t45 > Get_y45(r,t)) {
// Slide the top downward until it crosses the t45 diagonal at x=r.
// y = -x + (y0 + x0)
// Substitute: t45 = x0 + y0
// y = -x + t45
t = SkScalarPin(t45 - r, t, b);
t = SkTPin(t45 - r, t, b);
} else if (b45 < Get_y45(r,t)) {
// Slide the right side leftward until it crosses the b45 diagonal at y=t.
// x = -y + (x0 + y0)
// Substitute: b45 = x0 + y0
// x = -y + b45
r = SkScalarPin(b45 - t, l, r);
r = SkTPin(b45 - t, l, r);
}
// Tighten the 45-degree bounding box. Since the dev bounds are now fully tightened, we only
// have to clamp the diagonals to outer corners.
// NOTE: This will not cause l,t,r,b to need more insetting. We only ever change a diagonal by
// pinning it to a FAR corner, which, by definition, is still outside the other corners.
l45 = SkScalarPin(Get_x45(l,b), l45, r45);
t45 = SkScalarPin(Get_y45(l,t), t45, b45);
r45 = SkScalarPin(Get_x45(r,t), l45, r45);
b45 = SkScalarPin(Get_y45(r,b), t45, b45);
l45 = SkTPin(Get_x45(l,b), l45, r45);
t45 = SkTPin(Get_y45(l,t), t45, b45);
r45 = SkTPin(Get_x45(r,t), l45, r45);
b45 = SkTPin(Get_y45(r,b), t45, b45);
// Make one final check for empty or NaN bounds. If the dev bounds were clipped completely
// outside one of the diagonals, they will have been pinned to empty. It's also possible that

View File

@ -38,10 +38,10 @@ GrTextureDomain::GrTextureDomain(GrSurfaceProxy* proxy, const SkRect& domain, Mo
// It is OK if the domain rect is a line or point, but it should not be inverted. We do not
// handle rects that do not intersect the [0..1]x[0..1] rect.
SkASSERT(domain.isSorted());
fDomain.fLeft = SkScalarPin(domain.fLeft, 0.0f, kFullRect.fRight);
fDomain.fRight = SkScalarPin(domain.fRight, fDomain.fLeft, kFullRect.fRight);
fDomain.fTop = SkScalarPin(domain.fTop, 0.0f, kFullRect.fBottom);
fDomain.fBottom = SkScalarPin(domain.fBottom, fDomain.fTop, kFullRect.fBottom);
fDomain.fLeft = SkTPin(domain.fLeft, 0.0f, kFullRect.fRight);
fDomain.fRight = SkTPin(domain.fRight, fDomain.fLeft, kFullRect.fRight);
fDomain.fTop = SkTPin(domain.fTop, 0.0f, kFullRect.fBottom);
fDomain.fBottom = SkTPin(domain.fBottom, fDomain.fTop, kFullRect.fBottom);
SkASSERT(fDomain.fLeft <= fDomain.fRight);
SkASSERT(fDomain.fTop <= fDomain.fBottom);
}

View File

@ -665,7 +665,7 @@ static SkScalar compute_coverage(SkScalar depth, SkScalar initialDepth, SkScalar
}
SkScalar result = (depth - initialDepth) / (targetDepth - initialDepth) *
(targetCoverage - initialCoverage) + initialCoverage;
return SkScalarClampMax(result, 1.0f);
return SkTPin(result, 0.0f, 1.0f);
}
// return true when processing is complete

View File

@ -563,7 +563,7 @@ SkScalar SkPerlinNoiseShaderImpl::PerlinNoiseShaderContext::calculateTurbulenceV
}
// Clamp result
return SkScalarPin(turbulenceFunctionResult, 0, SK_Scalar1);
return SkTPin(turbulenceFunctionResult, 0.0f, SK_Scalar1);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -623,7 +623,7 @@ SkScalar SkPerlinNoiseShaderImpl::PerlinNoiseShaderContext::calculateImprovedNoi
y *= 2;
ratio *= 2;
}
result = SkScalarClampMax((result + 1.0f) / 2.0f, 1.0f);
result = SkTPin((result + 1.0f) / 2.0f, 0.0f, 1.0f);
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -187,7 +187,7 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
const SkScalar uniformStep = desc.fPos[startIndex] - prev;
for (int i = startIndex; i < count; i++) {
// Pin the last value to 1.0, and make sure pos is monotonic.
auto curr = (i == desc.fCount) ? 1 : SkScalarPin(desc.fPos[i], prev, 1);
auto curr = (i == desc.fCount) ? 1 : SkTPin(desc.fPos[i], prev, 1.0f);
uniformStops &= SkScalarNearlyEqual(uniformStep, curr - prev);
*origPosPtr++ = prev = curr;

View File

@ -357,9 +357,9 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC
indices[i + 4] = indices[i + 2];
indices[i + 5] = (x + 1) * stride + y;
}
v = SkScalarClampMax(v + 1.f / lodY, 1);
v = SkTPin(v + 1.f / lodY, 0.0f, 1.0f);
}
u = SkScalarClampMax(u + 1.f / lodX, 1);
u = SkTPin(u + 1.f / lodX, 0.0f, 1.0f);
}
if (tmpColors) {

View File

@ -913,8 +913,8 @@ SkAmbientShadowTessellator::SkAmbientShadowTessellator(const SkPath& path,
// umbraColor is the interior value, penumbraColor the exterior value.
auto outset = SkDrawShadowMetrics::AmbientBlurRadius(baseZ);
auto inset = outset * SkDrawShadowMetrics::AmbientRecipAlpha(baseZ) - outset;
inset = SkScalarPin(inset, 0, SkTMin(path.getBounds().width(),
path.getBounds().height()));
inset = SkTPin(inset, 0.0f, SkTMin(path.getBounds().width(),
path.getBounds().height()));
if (!this->computePathPolygon(path, ctm)) {
return;

View File

@ -1036,12 +1036,12 @@ void Viewer::setupCurrentSlide() {
}
}
#define MAX_ZOOM_LEVEL 8
#define MIN_ZOOM_LEVEL -8
#define MAX_ZOOM_LEVEL 8.0f
#define MIN_ZOOM_LEVEL -8.0f
void Viewer::changeZoomLevel(float delta) {
fZoomLevel += delta;
fZoomLevel = SkScalarPin(fZoomLevel, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL);
fZoomLevel = SkTPin(fZoomLevel, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL);
this->preTouchMatrixChanged();
}