aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkCanvas.cpp
diff options
context:
space:
mode:
authorGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-13 15:07:58 +0000
committerGravatar tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-13 15:07:58 +0000
commitbcb671c82a7341253864cda3a5c46d396402d7fb (patch)
treed6ae7e16ada305c421324fa0542d165e9625e5ff /src/core/SkCanvas.cpp
parent8a0b0291ae4260ef2a46f4341c18a702c0ce3f8b (diff)
Add SkCanvas::getClipDescription() and getClipDeviceBounds() so clients don't
need to explicitly get the exact clip & compute those values themselves. (We may be able to provide description/bounds more cheaply than the exact clip.) git-svn-id: http://skia.googlecode.com/svn/trunk@2255 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkCanvas.cpp')
-rw-r--r--src/core/SkCanvas.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 1f75aa9ad6..3ee29ce67e 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -678,12 +678,12 @@ int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
fDeviceCMDirty = true;
- SkIRect ir;
- const SkIRect& clipBounds = this->getTotalClip().getBounds();
- if (clipBounds.isEmpty()) {
+ SkIRect clipBounds;
+ if (!this->getClipDeviceBounds(&clipBounds)) {
return count;
}
+ SkIRect ir;
if (NULL != bounds) {
SkRect r;
@@ -691,8 +691,9 @@ int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
r.roundOut(&ir);
// early exit if the layer's bounds are clipped out
if (!ir.intersect(clipBounds)) {
- if (bounds_affects_clip(flags))
+ if (bounds_affects_clip(flags)) {
fMCRec->fRegion->setEmpty();
+ }
return count;
}
} else { // no user bounds, so just use the clip
@@ -1095,11 +1096,8 @@ bool SkCanvas::quickRejectY(SkScalar top, SkScalar bottom, EdgeType et) const {
}
bool SkCanvas::getClipBounds(SkRect* bounds, EdgeType et) const {
- const SkRegion& clip = *fMCRec->fRegion;
- if (clip.isEmpty()) {
- if (bounds) {
- bounds->setEmpty();
- }
+ SkIRect ibounds;
+ if (!getClipDeviceBounds(&ibounds)) {
return false;
}
@@ -1113,24 +1111,41 @@ bool SkCanvas::getClipBounds(SkRect* bounds, EdgeType et) const {
}
if (NULL != bounds) {
- SkRect r;
- // get the clip's bounds
- const SkIRect& ibounds = clip.getBounds();
+ SkRect r;
// adjust it outwards if we are antialiasing
int inset = (kAA_EdgeType == et);
r.iset(ibounds.fLeft - inset, ibounds.fTop - inset,
ibounds.fRight + inset, ibounds.fBottom + inset);
-
- // invert into local coordinates
inverse.mapRect(bounds, r);
}
return true;
}
+bool SkCanvas::getClipDeviceBounds(SkIRect* bounds) const {
+ const SkRegion& clip = *fMCRec->fRegion;
+ if (clip.isEmpty()) {
+ if (bounds) {
+ bounds->setEmpty();
+ }
+ return false;
+ }
+
+ if (NULL != bounds) {
+ *bounds = clip.getBounds();
+ }
+ return true;
+}
+
const SkMatrix& SkCanvas::getTotalMatrix() const {
return *fMCRec->fMatrix;
}
+SkCanvas::ClipType SkCanvas::getClipType() const {
+ if (fMCRec->fRegion->isEmpty()) return kEmpty_ClipType;
+ if (fMCRec->fRegion->isRect()) return kRect_ClipType;
+ return kComplex_ClipType;
+}
+
const SkRegion& SkCanvas::getTotalClip() const {
return *fMCRec->fRegion;
}