diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-10-12 14:34:30 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-10-12 14:34:30 +0000 |
commit | 0017708a5bcb6d0fbff0fac565085bef65de7433 (patch) | |
tree | be132512deecdb099e468286e17a44e9221f370e /src/core/SkRasterClip.cpp | |
parent | 58af9a64701540c7f8083bc22a42d0bae3a5583c (diff) |
use SkRasterClip inside canvas (check-point for soft clipping)
git-svn-id: http://skia.googlecode.com/svn/trunk@2462 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkRasterClip.cpp')
-rw-r--r-- | src/core/SkRasterClip.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/core/SkRasterClip.cpp b/src/core/SkRasterClip.cpp index b6a8926684..004e3fcb6b 100644 --- a/src/core/SkRasterClip.cpp +++ b/src/core/SkRasterClip.cpp @@ -112,6 +112,35 @@ bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { } } +// return true if x is nearly integral (within 1/256) 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 / 256); +} + +bool SkRasterClip::op(const SkRect& r, SkRegion::Op op, bool doAA) { + if (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)) { + doAA = false; + } + } + + if (fIsBW && !doAA) { + SkIRect ir; + r.round(&ir); + fBW.op(ir, op); + } else { + if (fIsBW) { + this->convertToAA(); + } + fAA.op(r, op, doAA); + } +} + const SkRegion& SkRasterClip::forceGetBW() { if (!fIsBW) { fBW.setRect(fAA.getBounds()); |