Replace SkPin32 with SkTPin and remove.
SkPin32 is already just forwarding to SkTPin, so convert existing
users and remove SkPin32.
Review URL: https://codereview.chromium.org/1314583003
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index c128e48..a5468f3 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -392,13 +392,9 @@
return value;
}
-template <typename T> static inline const T& SkTPin(const T& x, const T& min, const T& max) {
- return SkTMax(SkTMin(x, max), min);
-}
-
-/** Returns signed 32 bit value pinned between min and max, inclusively. */
-static inline int32_t SkPin32(int32_t value, int32_t min, int32_t max) {
- return SkTPin(value, min, max);
+/** Returns value pinned between min and max, inclusively. */
+template <typename T> static inline const T& SkTPin(const T& value, const T& min, const T& max) {
+ return SkTMax(SkTMin(value, max), min);
}
static inline uint32_t SkSetClearShift(uint32_t bits, bool cond,
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 7cc7344..7d08184 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -199,7 +199,7 @@
if (pr) {
const SkImageInfo& info = pr->info();
- fPixelRefOrigin.set(SkPin32(dx, 0, info.width()), SkPin32(dy, 0, info.height()));
+ fPixelRefOrigin.set(SkTPin(dx, 0, info.width()), SkTPin(dy, 0, info.height()));
} else {
// ignore dx,dy if there is no pixelref
fPixelRefOrigin.setZero();
diff --git a/src/core/SkFontStyle.cpp b/src/core/SkFontStyle.cpp
index 285d17a..badf9d7 100644
--- a/src/core/SkFontStyle.cpp
+++ b/src/core/SkFontStyle.cpp
@@ -18,9 +18,9 @@
SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
fUnion.fU32 = 0;
- fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight);
- fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width);
- fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant);
+ fUnion.fR.fWeight = SkTPin<int>(weight, kThin_Weight, kBlack_Weight);
+ fUnion.fR.fWidth = SkTPin<int>(width, kUltraCondensed_Width, kUltaExpanded_Width);
+ fUnion.fR.fSlant = SkTPin<int>(slant, kUpright_Slant, kItalic_Slant);
}
SkFontStyle::SkFontStyle(unsigned oldStyle) {
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index 9110d80..d93f662 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -509,7 +509,7 @@
}
void SkString::insertHex(size_t offset, uint32_t hex, int minDigits) {
- minDigits = SkPin32(minDigits, 0, 8);
+ minDigits = SkTPin(minDigits, 0, 8);
static const char gHex[] = "0123456789ABCDEF";
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 1e1ec45..b9998f8 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -361,8 +361,8 @@
SkScalar y_interp = SkScalarMul(weight, (fSrcRect.y() + y * inv_y_zoom)) +
(SK_Scalar1 - weight) * y;
- int x_val = SkPin32(SkScalarFloorToInt(x_interp), 0, width - 1);
- int y_val = SkPin32(SkScalarFloorToInt(y_interp), 0, height - 1);
+ int x_val = SkTPin(SkScalarFloorToInt(x_interp), 0, width - 1);
+ int y_val = SkTPin(SkScalarFloorToInt(y_interp), 0, height - 1);
*dptr = sptr[y_val * width + x_val];
dptr++;
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index c2ad9ea..499ba51 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -126,8 +126,8 @@
class ClampPixelFetcher {
public:
static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
- x = SkPin32(x, bounds.fLeft, bounds.fRight - 1);
- y = SkPin32(y, bounds.fTop, bounds.fBottom - 1);
+ x = SkTPin(x, bounds.fLeft, bounds.fRight - 1);
+ y = SkTPin(y, bounds.fTop, bounds.fBottom - 1);
return *src.getAddr32(x, y);
}
};
diff --git a/src/effects/SkTableMaskFilter.cpp b/src/effects/SkTableMaskFilter.cpp
index 999b998..88484d7 100644
--- a/src/effects/SkTableMaskFilter.cpp
+++ b/src/effects/SkTableMaskFilter.cpp
@@ -91,7 +91,7 @@
float x = 0;
for (int i = 0; i < 256; i++) {
// float ee = powf(x, g) * 255;
- table[i] = SkPin32(sk_float_round2int(powf(x, g) * 255), 0, 255);
+ table[i] = SkTPin(sk_float_round2int(powf(x, g) * 255), 0, 255);
x += dx;
}
}
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 3a1a21e..c7e7308 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -92,10 +92,10 @@
// might perform this check for the other modes,
// but the win will be a smaller % of the total
if (dy == 0) {
- fy = SkPin32(fy, -0xFFFF >> 1, 0xFFFF >> 1);
+ fy = SkTPin(fy, -0xFFFF >> 1, 0xFFFF >> 1);
fy *= fy;
do {
- unsigned xx = SkPin32(fx, -0xFFFF >> 1, 0xFFFF >> 1);
+ unsigned xx = SkTPin(fx, -0xFFFF >> 1, 0xFFFF >> 1);
unsigned fi = (xx * xx + fy) >> (14 + 16 - kSQRT_TABLE_BITS);
fi = SkFastMin32(fi, 0xFFFF >> (16 - kSQRT_TABLE_BITS));
fx += dx;
@@ -105,8 +105,8 @@
} while (--count != 0);
} else {
do {
- unsigned xx = SkPin32(fx, -0xFFFF >> 1, 0xFFFF >> 1);
- unsigned fi = SkPin32(fy, -0xFFFF >> 1, 0xFFFF >> 1);
+ unsigned xx = SkTPin(fx, -0xFFFF >> 1, 0xFFFF >> 1);
+ unsigned fi = SkTPin(fy, -0xFFFF >> 1, 0xFFFF >> 1);
fi = (xx * xx + fi * fi) >> (14 + 16 - kSQRT_TABLE_BITS);
fi = SkFastMin32(fi, 0xFFFF >> (16 - kSQRT_TABLE_BITS));
fx += dx;