Forced GrClip to always have conservative bounds
http://codereview.appspot.com/6353089/
git-svn-id: http://skia.googlecode.com/svn/trunk@4545 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index e7dcf53..316e4d6 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -89,7 +89,9 @@
}
GrAutoUnref au(texture);
- ctx->setClip(GrRect::MakeWH(2*S, 2*S));
+ GrClip newClip(GrRect::MakeWH(2*S, 2*S));
+ ctx->setClip(newClip);
+
ctx->setRenderTarget(target);
GrPaint paint;
diff --git a/include/gpu/GrClip.h b/include/gpu/GrClip.h
index 3385c74..4fd8ddd 100644
--- a/include/gpu/GrClip.h
+++ b/include/gpu/GrClip.h
@@ -22,21 +22,21 @@
GrClip();
GrClip(const GrClip& src);
/**
- * If specified, the conservativeBounds parameter already takes (tx,ty)
- * into account.
+ * The conservativeBounds parameter already takes (tx,ty) into account.
*/
GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* conservativeBounds = NULL);
- GrClip(const GrIRect& rect);
- GrClip(const GrRect& rect);
+ const GrRect& conservativeBounds);
+ explicit GrClip(const GrIRect& rect);
+ explicit GrClip(const GrRect& rect);
~GrClip();
GrClip& operator=(const GrClip& src);
- bool hasConservativeBounds() const { return fConservativeBoundsValid; }
-
- const GrRect& getConservativeBounds() const { return fConservativeBounds; }
+ const GrRect& getConservativeBounds() const {
+ GrAssert(fConservativeBoundsValid);
+ return fConservativeBounds;
+ }
bool requiresAA() const { return fRequiresAA; }
@@ -90,7 +90,7 @@
* If specified, the bounds parameter already takes (tx,ty) into account.
*/
void setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* conservativeBounds = NULL);
+ const GrRect& conservativeBounds);
void setFromRect(const GrRect& rect);
void setFromIRect(const GrIRect& rect);
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index 1731db5..036f5e1 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -513,13 +513,8 @@
int rtHeight = drawState.getRenderTarget()->height();
GrIRect clip;
- if (target->getClip().hasConservativeBounds()) {
- GrRect clipRect = target->getClip().getConservativeBounds();
- clipRect.roundOut(&clip);
- } else {
- clip.setLargest();
- }
+ target->getClip().getConservativeBounds().roundOut(&clip);
GrVertexLayout layout = GrDrawTarget::kEdge_VertexLayoutBit;
GrMatrix viewM = drawState.getViewMatrix();
diff --git a/src/gpu/GrClip.cpp b/src/gpu/GrClip.cpp
index a5120d4..7803edc 100644
--- a/src/gpu/GrClip.cpp
+++ b/src/gpu/GrClip.cpp
@@ -29,7 +29,7 @@
}
GrClip::GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* bounds) {
+ const GrRect& bounds) {
this->setFromIterator(iter, tx, ty, bounds);
}
@@ -89,7 +89,7 @@
}
void GrClip::setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
- const GrRect* conservativeBounds) {
+ const GrRect& conservativeBounds) {
fList.reset();
fRequiresAA = false;
@@ -148,8 +148,8 @@
if (isectRectValid && rectCount) {
fConservativeBounds = fList[0].fRect;
fConservativeBoundsValid = true;
- } else if (NULL != conservativeBounds) {
- fConservativeBounds = *conservativeBounds;
+ } else {
+ fConservativeBounds = conservativeBounds;
fConservativeBoundsValid = true;
}
}
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index dcd32dd..7c54009 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -114,17 +114,13 @@
GrIRect bounds;
GrIRect rtRect;
rtRect.setLTRB(0, 0, rt->width(), rt->height());
- if (clipIn.hasConservativeBounds()) {
- GrRect softBounds = clipIn.getConservativeBounds();
- softBounds.roundOut(&bounds);
- if (!bounds.intersect(rtRect)) {
- bounds.setEmpty();
- }
- if (bounds.isEmpty()) {
- return false;
- }
- } else {
- bounds = rtRect;
+
+ clipIn.getConservativeBounds().roundOut(&bounds);
+ if (!bounds.intersect(rtRect)) {
+ bounds.setEmpty();
+ }
+ if (bounds.isEmpty()) {
+ return false;
}
#if GR_SW_CLIP
@@ -503,18 +499,11 @@
// unlike the stencil path the alpha path is not bound to the size of the
// render target - determine the minimum size required for the mask
- GrRect bounds;
-
- if (clipIn.hasConservativeBounds()) {
- bounds = clipIn.getConservativeBounds();
- if (!bounds.intersect(rtRect)) {
- // the mask will be empty in this case
- GrAssert(false);
- bounds.setEmpty();
- }
- } else {
- // still locked to the size of the render target
- bounds = rtRect;
+ GrRect bounds = clipIn.getConservativeBounds();
+ if (!bounds.intersect(rtRect)) {
+ // the mask will be empty in this case
+ GrAssert(false);
+ bounds.setEmpty();
}
GrIRect intBounds;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b004f28..6e92bf7 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1836,7 +1836,9 @@
srcRect.roundOut();
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
- this->setClip(srcRect);
+
+ GrClip newClip(srcRect);
+ this->setClip(newClip);
GrAssert(kBGRA_8888_PM_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_PM_GrPixelConfig == srcTexture->config() ||
@@ -1949,8 +1951,11 @@
GrRenderTarget* oldRenderTarget = this->getRenderTarget();
GrAutoMatrix avm(this, GrMatrix::I());
GrClip oldClip = this->getClip();
- this->setClip(GrRect::MakeWH(SkIntToScalar(srcTexture->width()),
- SkIntToScalar(srcTexture->height())));
+
+ GrClip newClip(GrRect::MakeWH(SkIntToScalar(srcTexture->width()),
+ SkIntToScalar(srcTexture->height())));
+ this->setClip(newClip);
+
if (radius.fWidth > 0) {
this->setRenderTarget(temp1->asRenderTarget());
apply_morphology(fGpu, srcTexture, rect, radius.fWidth, morphType,
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index bccfc47..5ab5fb4 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -46,15 +46,12 @@
}
*pathBounds = GrIRect::MakeWH(rt->width(), rt->height());
const GrClip& clip = target->getClip();
- if (clip.hasConservativeBounds()) {
- clip.getConservativeBounds().roundOut(clipBounds);
- if (!pathBounds->intersect(*clipBounds)) {
- return false;
- }
- } else {
- // pathBounds is currently the rt extent, set clip bounds to that rect.
- *clipBounds = *pathBounds;
+
+ clip.getConservativeBounds().roundOut(clipBounds);
+ if (!pathBounds->intersect(*clipBounds)) {
+ return false;
}
+
if (!path.getBounds().isEmpty()) {
GrRect pathSBounds;
matrix.mapRect(&pathSBounds, path.getBounds());
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 5b61be2..dc04fcd 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -90,19 +90,16 @@
} else {
fExtMatrix.reset();
}
- if (context->getClip().hasConservativeBounds()) {
- if (!fExtMatrix.isIdentity()) {
- GrMatrix inverse;
- GrRect r = context->getClip().getConservativeBounds();
- if (fExtMatrix.invert(&inverse)) {
- inverse.mapRect(&r);
- r.roundOut(&fClipRect);
- }
- } else {
- context->getClip().getConservativeBounds().roundOut(&fClipRect);
+
+ if (!fExtMatrix.isIdentity()) {
+ GrMatrix inverse;
+ GrRect r = context->getClip().getConservativeBounds();
+ if (fExtMatrix.invert(&inverse)) {
+ inverse.mapRect(&r);
+ r.roundOut(&fClipRect);
}
} else {
- fClipRect.setLargest();
+ context->getClip().getConservativeBounds().roundOut(&fClipRect);
}
// save the context's original matrix off and restore in destructor
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index e5227a2..ba8be8c 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -353,7 +353,7 @@
GrIntToScalar(skBounds.fRight),
GrIntToScalar(skBounds.fBottom));
GrClip grc(&iter, GrIntToScalar(-origin.x()), GrIntToScalar(-origin.y()),
- &bounds);
+ bounds);
context->setClip(grc);
}
@@ -814,7 +814,10 @@
// an AutoClipRestore.
GrClip oldClip = context->getClip();
context->setRenderTarget(pathTexture->asRenderTarget());
- context->setClip(srcRect);
+
+ GrClip newClip(srcRect);
+ context->setClip(newClip);
+
context->clear(NULL, 0);
GrPaint tempPaint;
tempPaint.reset();
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 736be93..3a3d638 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -493,8 +493,7 @@
GrIRect* rect = NULL;
GrIRect clipBounds;
- if (drawState.isClipState() &&
- fClip.hasConservativeBounds()) {
+ if (drawState.isClipState()) {
fClip.getConservativeBounds().roundOut(&clipBounds);
rect = &clipBounds;
}