aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRasterClip.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-11 20:57:25 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-11 20:57:25 +0000
commit18c464b460d062142ab7198724431a4d2ad7070d (patch)
treec9c0a49373a229daa7f6beffc8d30bf6e8ed94a4 /src/core/SkRasterClip.cpp
parent5adf9b2e984365299606ea0891ea0c88f71d8b27 (diff)
update the nearly_integral calculation to be (a) faster, and (b) to correctly
identify that the AA granularity is 1/4 of a pixel, not 1/16 (along an axis). git-svn-id: http://skia.googlecode.com/svn/trunk@3919 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkRasterClip.cpp')
-rw-r--r--src/core/SkRasterClip.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/core/SkRasterClip.cpp b/src/core/SkRasterClip.cpp
index 9a845de31e..aea731e1af 100644
--- a/src/core/SkRasterClip.cpp
+++ b/src/core/SkRasterClip.cpp
@@ -150,21 +150,27 @@ bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) {
return this->updateCacheAndReturnNonEmpty();
}
-// return true if x is nearly integral (within 1/16) since that is the highest
-// precision our aa code can have.
-static bool is_integral(SkScalar x) {
- int ix = SkScalarRoundToInt(x);
- SkScalar sx = SkIntToScalar(ix);
- return SkScalarAbs(sx - x) < (SK_Scalar1 / 16);
+/**
+ * Our antialiasing currently has a granularity of 1/4 of a pixel along each
+ * axis. Thus we can treat an axis coordinate as an integer if it differs
+ * from its nearest int by < half of that value (1.8 in this case).
+ */
+static bool nearly_integral(SkScalar x) {
+ static const SkScalar domain = SK_Scalar1 / 4;
+ static const SkScalar halfDomain = domain / 2;
+
+ x += halfDomain;
+ return x - SkScalarFloorToScalar(x) < domain;
}
bool SkRasterClip::op(const SkRect& r, SkRegion::Op op, bool doAA) {
AUTO_RASTERCLIP_VALIDATE(*this);
if (fIsBW && doAA) {
- // check that the rect really needs aa
- if (is_integral(r.fLeft) && is_integral(r.fTop) &&
- is_integral(r.fRight) && is_integral(r.fBottom)) {
+ // check that the rect really needs aa, or is it close enought to
+ // integer boundaries that we can just treat it as a BW rect?
+ if (nearly_integral(r.fLeft) && nearly_integral(r.fTop) &&
+ nearly_integral(r.fRight) && nearly_integral(r.fBottom)) {
doAA = false;
}
}