aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkPoint.h13
-rw-r--r--include/core/SkRect.h18
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp4
-rw-r--r--src/effects/SkMatrixConvolutionImageFilter.cpp4
4 files changed, 23 insertions, 16 deletions
diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h
index 3ccc33e140..2d3a938693 100644
--- a/include/core/SkPoint.h
+++ b/include/core/SkPoint.h
@@ -10,6 +10,7 @@
#include "SkMath.h"
#include "SkScalar.h"
+#include "../private/SkSafe32.h"
/** \struct SkIPoint16
SkIPoint holds two 16 bit integer coordinates
@@ -115,8 +116,8 @@ struct SkIPoint {
@param v ivector to add
*/
void operator+=(const SkIVector& v) {
- fX += v.fX;
- fY += v.fY;
+ fX = Sk32_sat_add(fX, v.fX);
+ fY = Sk32_sat_add(fY, v.fY);
}
/** Subtracts ivector v from SkIPoint. Sets SkIPoint to: (fX - v.fX, fY - v.fY).
@@ -124,8 +125,8 @@ struct SkIPoint {
@param v ivector to subtract
*/
void operator-=(const SkIVector& v) {
- fX -= v.fX;
- fY -= v.fY;
+ fX = Sk32_sat_sub(fX, v.fX);
+ fY = Sk32_sat_sub(fY, v.fY);
}
/** Returns true if SkIPoint is equivalent to SkIPoint constructed from (x, y).
@@ -167,7 +168,7 @@ struct SkIPoint {
@return ivector from b to a
*/
friend SkIVector operator-(const SkIPoint& a, const SkIPoint& b) {
- return {a.fX - b.fX, a.fY - b.fY};
+ return { Sk32_sat_sub(a.fX, b.fX), Sk32_sat_sub(a.fY, b.fY) };
}
/** Returns SkIPoint resulting from SkIPoint a offset by ivector b, computed as: (a.fX + b.fX, a.fY + b.fY).
@@ -180,7 +181,7 @@ struct SkIPoint {
@return SkIPoint equal to a offset by b
*/
friend SkIPoint operator+(const SkIPoint& a, const SkIVector& b) {
- return {a.fX + b.fX, a.fY + b.fY};
+ return { Sk32_sat_add(a.fX, b.fX), Sk32_sat_add(a.fY, b.fY) };
}
};
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 5673980d49..ff7715853a 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -849,12 +849,18 @@ struct SK_API SkRect {
}
/** Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
- to or greater than fBottom. Call sort() to reverse rectangles with negative
- width() or height().
-
- @return true if width() or height() are zero or negative
- */
- bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+ * to or greater than fBottom. Call sort() to reverse rectangles with negative
+ * width() or height().
+ *
+ * This function also returns true if any of the values are NaN.
+ *
+ * @return true if width() or height() are zero or negative
+ */
+ bool isEmpty() const {
+ // We write it as the NOT of a non-empty rect, so we will return true if any values
+ // are NaN.
+ return !(fLeft < fRight && fTop < fBottom);
+ }
/** Returns true if fLeft is equal to or less than fRight, or if fTop is equal
to or less than fBottom. Call sort() to reverse rectangles with negative
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 1b055b69a3..ce7fe34ea4 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -88,8 +88,8 @@ void computeDisplacement(Extractor ex, const SkVector& scale, SkBitmap* dst,
SkScalar displX = scaleForColor.fX * ex.getX(c) + scaleAdj.fX;
SkScalar displY = scaleForColor.fY * ex.getY(c) + scaleAdj.fY;
// Truncate the displacement values
- const int srcX = x + SkScalarTruncToInt(displX);
- const int srcY = y + SkScalarTruncToInt(displY);
+ const int32_t srcX = Sk32_sat_add(x, SkScalarTruncToInt(displX));
+ const int32_t srcY = Sk32_sat_add(y, SkScalarTruncToInt(displY));
*dstPtr++ = ((srcX < 0) || (srcX >= srcW) || (srcY < 0) || (srcY >= srcH)) ?
0 : *(src.getAddr32(srcX, srcY));
}
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index 1e58786b4d..f4f5dd604b 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -403,8 +403,8 @@ SkIRect SkMatrixConvolutionImageFilter::onFilterNodeBounds(const SkIRect& src, c
MapDirection direction) const {
SkIRect dst = src;
int w = fKernelSize.width() - 1, h = fKernelSize.height() - 1;
- dst.fRight += w;
- dst.fBottom += h;
+ dst.fRight = Sk32_sat_add(dst.fRight, w);
+ dst.fBottom = Sk32_sat_add(dst.fBottom, h);
if (kReverse_MapDirection == direction) {
dst.offset(-fKernelOffset);
} else {