summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Chromium Automerger <chromium-automerger@android>2014-05-05 20:42:54 +0000
committerAndroid Chromium Automerger <chromium-automerger@android>2014-05-05 20:42:54 +0000
commitb9f56bb9959a89e569bddee9bc6871cdecd05d32 (patch)
treed43e596f6c3edd210c357fe03e858254ad81772e
parentd4117eda3c0b06341359a2e6b1b681db3c0eb35c (diff)
parentd2b8224663697e9ce19c97862eaf783b1e9e1151 (diff)
downloadinclude-b9f56bb9959a89e569bddee9bc6871cdecd05d32.tar.gz
Merge third_party/skia/include from https://chromium.googlesource.com/external/skia/include.git at d2b8224663697e9ce19c97862eaf783b1e9e1151
This commit was generated by merge_from_chromium.py. Change-Id: I55e9f482313eacde51846a44218ed59fa7835706
-rw-r--r--core/SkRect.h18
-rw-r--r--core/SkScalar.h20
2 files changed, 38 insertions, 0 deletions
diff --git a/core/SkRect.h b/core/SkRect.h
index 397e4a0..fd8cb16 100644
--- a/core/SkRect.h
+++ b/core/SkRect.h
@@ -732,6 +732,24 @@ struct SK_API SkRect {
}
/**
+ * Variant of round() that explicitly performs the rounding step (i.e. floor(x + 0.5)) using
+ * double instead of SkScalar (float). It does this by calling SkDScalarRoundToInt(), which
+ * may be slower than calling SkScalarRountToInt(), but gives slightly more accurate results.
+ *
+ * e.g.
+ * SkScalar x = 0.49999997f;
+ * int ix = SkScalarRoundToInt(x);
+ * SkASSERT(0 == ix); // <--- fails
+ * ix = SkDScalarRoundToInt(x);
+ * SkASSERT(0 == ix); // <--- succeeds
+ */
+ void dround(SkIRect* dst) const {
+ SkASSERT(dst);
+ dst->set(SkDScalarRoundToInt(fLeft), SkDScalarRoundToInt(fTop),
+ SkDScalarRoundToInt(fRight), SkDScalarRoundToInt(fBottom));
+ }
+
+ /**
* Set the dst rectangle by rounding "out" this rectangle, choosing the
* SkScalarFloor of top and left, and the SkScalarCeil of right and bottom.
*/
diff --git a/core/SkScalar.h b/core/SkScalar.h
index b9256ba..b37cf5c 100644
--- a/core/SkScalar.h
+++ b/core/SkScalar.h
@@ -83,6 +83,26 @@ static inline bool SkScalarIsFinite(float x) {
#define SkScalarRoundToInt(x) sk_float_round2int(x)
#define SkScalarTruncToInt(x) static_cast<int>(x)
+/**
+ * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5) explicitly using
+ * double, to avoid possibly losing the low bit(s) of the answer before calling floor().
+ *
+ * This routine will likely be slower than SkScalarRoundToInt(), and should only be used when the
+ * extra precision is known to be valuable.
+ *
+ * In particular, this catches the following case:
+ * SkScalar x = 0.49999997;
+ * int ix = SkScalarRoundToInt(x);
+ * SkASSERT(0 == ix); // <--- fails
+ * ix = SkDScalarRoundToInt(x);
+ * SkASSERT(0 == ix); // <--- succeeds
+ */
+static inline int SkDScalarRoundToInt(SkScalar x) {
+ double xx = x;
+ xx += 0.5;
+ return (int)floor(xx);
+}
+
/** Returns the absolute value of the specified SkScalar
*/
#define SkScalarAbs(x) sk_float_abs(x)