Trim the copy of the dst made for dst-reading effects using the clip and dev-bounds of draw.
Adds dev bounds to circles and rects drawn by GrDrawTarget base class (GrIODB already provides rect bounds).
Author: bsalomon@google.com
Reviewed By: robertphilips@google.com,jvanverth@google.com,robertphillips@google.com
Review URL: https://chromiumcodereview.appspot.com/13222004
git-svn-id: http://skia.googlecode.com/svn/trunk@8453 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 4d4ba49..bc7d39e 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -407,15 +407,7 @@
}
bool GrDrawTarget::setupDstReadIfNecessary(DrawInfo* info) {
- bool willReadDst = false;
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- const GrEffectRef* effect = this->drawState()->getStage(s).getEffect();
- if (NULL != effect && (*effect)->willReadDst()) {
- willReadDst = true;
- break;
- }
- }
- if (!willReadDst) {
+ if (!this->getDrawState().willEffectReadDst()) {
return true;
}
GrRenderTarget* rt = this->drawState()->getRenderTarget();
@@ -426,8 +418,24 @@
GrPrintf("Reading Dst of non-texture render target is not currently supported.\n");
return false;
}
- // TODO: Consider bounds of draw and bounds of clip
+ const GrClipData* clip = this->getClip();
+ GrIRect copyRect;
+ clip->getConservativeBounds(this->getDrawState().getRenderTarget(), ©Rect);
+ SkIRect drawIBounds;
+ if (info->getDevIBounds(&drawIBounds)) {
+ if (!copyRect.intersect(drawIBounds)) {
+#if GR_DEBUG
+ GrPrintf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
+#endif
+ return false;
+ }
+ } else {
+#if GR_DEBUG
+ //GrPrintf("No dev bounds when dst copy is made.\n");
+#endif
+ }
+
GrDrawTarget::AutoGeometryAndStatePush agasp(this, kReset_ASRInit);
// The draw will resolve dst if it has MSAA. Two things to consider in the future:
@@ -437,8 +445,8 @@
// copy of it.
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
- desc.fWidth = rt->width();
- desc.fHeight = rt->height();
+ desc.fWidth = copyRect.width();
+ desc.fHeight = copyRect.height();
desc.fSampleCnt = 0;
desc.fConfig = rt->config();
@@ -454,11 +462,14 @@
SkMatrix matrix;
matrix.setIDiv(rt->width(), rt->height());
this->drawState()->createTextureEffect(kTextureStage, rt->asTexture(), matrix);
- SkRect copyRect = SkRect::MakeWH(SkIntToScalar(desc.fWidth),
- SkIntToScalar(desc.fHeight));
- this->drawRect(copyRect, NULL, ©Rect, NULL);
+
+ SkRect srcRect = SkRect::MakeFromIRect(copyRect);
+ SkRect dstRect = SkRect::MakeWH(SkIntToScalar(copyRect.width()),
+ SkIntToScalar(copyRect.height()));
+ this->drawRect(dstRect, NULL, &srcRect, NULL);
+
info->fDstCopy.setTexture(ast.texture());
- info->fDstCopy.setOffset(0, 0);
+ info->fDstCopy.setOffset(copyRect.fLeft, copyRect.fTop);
return true;
}
@@ -645,8 +656,13 @@
localMatrix->mapPointsWithStride(coords, vsize, 4);
}
}
+ SkTLazy<SkRect> bounds;
+ if (this->getDrawState().willEffectReadDst()) {
+ bounds.init();
+ this->getDrawState().getViewMatrix().mapRect(bounds.get(), rect);
+ }
- this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
+ this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, bounds.getMaybeNull());
}
void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) {