If we compute an exact clip bounds prefer it over user passed bounds. Also clarify that bounds are conservative.
Review URL: http://codereview.appspot.com/4254063/
git-svn-id: http://skia.googlecode.com/svn/trunk@909 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrClip.h b/gpu/include/GrClip.h
index 64c9bbb..00da110 100644
--- a/gpu/include/GrClip.h
+++ b/gpu/include/GrClip.h
@@ -29,10 +29,11 @@
GrClip();
GrClip(const GrClip& src);
/**
- * If specified, the bounds parameter already takes (tx,ty) into account.
+ * If specified, the conservativeBounds parameter already takes (tx,ty)
+ * into account.
*/
GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* bounds = NULL);
+ const GrRect* conservativeBounds = NULL);
GrClip(const GrIRect& rect);
GrClip(const GrRect& rect);
@@ -40,9 +41,9 @@
GrClip& operator=(const GrClip& src);
- bool hasBounds() const { return fBoundsValid; }
+ bool hasConservativeBounds() const { return fConservativeBoundsValid; }
- const GrRect& getBounds() const { return fBounds; }
+ const GrRect& getConservativeBounds() const { return fConservativeBounds; }
int getElementCount() const { return fList.count(); }
@@ -67,8 +68,10 @@
bool isRect() const {
if (1 == fList.count() && kRect_ClipType == fList[0].fType) {
- GrAssert(fBoundsValid);
- GrAssert(fBounds == fList[0].fRect);
+ // if we determined that the clip is a single rect
+ // we ought to have also used that rect as the bounds.
+ GrAssert(fConservativeBoundsValid);
+ GrAssert(fConservativeBounds == fList[0].fRect);
return true;
} else {
return false;
@@ -86,7 +89,7 @@
* If specified, the bounds parameter already takes (tx,ty) into account.
*/
void setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* bounds = NULL);
+ const GrRect* conservativeBounds = NULL);
void setFromRect(const GrRect& rect);
void setFromIRect(const GrIRect& rect);
@@ -131,8 +134,8 @@
bool operator !=(const Element& e) const { return !(*this == e); }
};
- GrRect fBounds;
- bool fBoundsValid;
+ GrRect fConservativeBounds;
+ bool fConservativeBoundsValid;
enum {
kPreAllocElements = 4,
diff --git a/gpu/src/GrClip.cpp b/gpu/src/GrClip.cpp
index 5ba991b..e8da3d1 100644
--- a/gpu/src/GrClip.cpp
+++ b/gpu/src/GrClip.cpp
@@ -19,8 +19,8 @@
GrClip::GrClip()
: fList(fListMemory, kPreAllocElements) {
- fBounds.setEmpty();
- fBoundsValid = true;
+ fConservativeBounds.setEmpty();
+ fConservativeBoundsValid = true;
}
GrClip::GrClip(const GrClip& src)
@@ -48,15 +48,15 @@
GrClip& GrClip::operator=(const GrClip& src) {
fList = src.fList;
- fBounds = src.fBounds;
- fBoundsValid = src.fBoundsValid;
+ fConservativeBounds = src.fConservativeBounds;
+ fConservativeBoundsValid = src.fConservativeBoundsValid;
return *this;
}
void GrClip::setEmpty() {
fList.reset();
- fBounds.setEmpty();
- fBoundsValid = true;
+ fConservativeBounds.setEmpty();
+ fConservativeBoundsValid = true;
}
void GrClip::setFromRect(const GrRect& r) {
@@ -68,8 +68,8 @@
fList.push_back();
fList.back().fRect = r;
fList.back().fType = kRect_ClipType;
- fBounds = r;
- fBoundsValid = true;
+ fConservativeBounds = r;
+ fConservativeBoundsValid = true;
}
}
@@ -82,13 +82,13 @@
fList.push_back();
fList.back().fRect.set(r);
fList.back().fType = kRect_ClipType;
- fBounds.set(r);
- fBoundsValid = true;
+ fConservativeBounds.set(r);
+ fConservativeBoundsValid = true;
}
}
void GrClip::setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* bounds) {
+ const GrRect* conservativeBounds) {
fList.reset();
int rectCount = 0;
@@ -138,18 +138,16 @@
}
}
}
- fBoundsValid = false;
- if (NULL == bounds) {
- if (isectRectValid) {
- fBoundsValid = true;
- if (rectCount > 0) {
- fBounds = fList[0].fRect;
- } else {
- fBounds.setEmpty();
- }
+ fConservativeBoundsValid = false;
+ if (isectRectValid) {
+ fConservativeBoundsValid = true;
+ if (rectCount > 0) {
+ fConservativeBounds = fList[0].fRect;
+ } else {
+ fConservativeBounds.setEmpty();
}
- } else {
- fBounds = *bounds;
- fBoundsValid = true;
+ } else if (NULL != conservativeBounds) {
+ fConservativeBounds = *conservativeBounds;
+ fConservativeBoundsValid = true;
}
}
diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp
index 4a46e98..045dcd0 100644
--- a/gpu/src/GrGpu.cpp
+++ b/gpu/src/GrGpu.cpp
@@ -295,8 +295,8 @@
GrRect rtRect;
rtRect.setLTRB(0, 0,
GrIntToScalar(rt.width()), GrIntToScalar(rt.height()));
- if (fClip.hasBounds()) {
- bounds = fClip.getBounds();
+ if (fClip.hasConservativeBounds()) {
+ bounds = fClip.getConservativeBounds();
bounds.intersectWith(rtRect);
} else {
bounds = rtRect;
@@ -342,13 +342,13 @@
// the full rt size and another element intersected with it.
// We can skip the first full-size rect and save a big rect draw.
int firstElement = 0;
- if (clip.getElementCount() > 1 &&
+ if (clip.getElementCount() > 1 &&
kRect_ClipType == clip.getElementType(0) &&
kIntersect_SetOp == clip.getOp(1)&&
clip.getRect(0).contains(bounds)) {
firstElement = 1;
}
-
+
// walk through each clip element and perform its set op
// with the existing clip.
for (int c = firstElement; c < count; ++c) {
@@ -390,8 +390,8 @@
this->drawSimpleRect(clip.getRect(c), NULL, 0);
} else {
SET_RANDOM_COLOR
- getPathRenderer()->drawPathToStencil(this, clip.getPath(c),
- NonInvertedFill(fill),
+ getPathRenderer()->drawPathToStencil(this, clip.getPath(c),
+ NonInvertedFill(fill),
NULL);
}
}
@@ -408,7 +408,7 @@
} else {
SET_RANDOM_COLOR
getPathRenderer()->drawPath(this, 0,
- clip.getPath(c),
+ clip.getPath(c),
fill, NULL);
}
} else {
diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp
index a249364..b2fe581 100644
--- a/gpu/src/GrInOrderDrawBuffer.cpp
+++ b/gpu/src/GrInOrderDrawBuffer.cpp
@@ -104,10 +104,7 @@
bool disabledClip = false;
if (this->isClipState() && fClip.isRect()) {
- // single rect clip should have bounds
- GrAssert(fClip.hasBounds());
-
- GrRect clipRect = GrRect(fClip.getBounds());
+ GrRect clipRect = fClip.getRect(0);
// If the clip rect touches the edge of the viewport, extended it
// out (close) to infinity to avoid bogus intersections.
// We might consider a more exact clip to viewport if this
diff --git a/gpu/src/GrTextContext.cpp b/gpu/src/GrTextContext.cpp
index 802e3e3..6819bde 100644
--- a/gpu/src/GrTextContext.cpp
+++ b/gpu/src/GrTextContext.cpp
@@ -73,16 +73,16 @@
} else {
fExtMatrix = GrMatrix::I();
}
- if (context->getClip().hasBounds()) {
+ if (context->getClip().hasConservativeBounds()) {
if (!fExtMatrix.isIdentity()) {
GrMatrix inverse;
- GrRect r = context->getClip().getBounds();
+ GrRect r = context->getClip().getConservativeBounds();
if (fExtMatrix.invert(&inverse)) {
inverse.mapRect(&r);
r.roundOut(&fClipRect);
}
} else {
- context->getClip().getBounds().roundOut(&fClipRect);
+ context->getClip().getConservativeBounds().roundOut(&fClipRect);
}
} else {
fClipRect.setLargest();