Chromium Code Reviews| Index: src/gpu/GrDrawTarget.cpp |
| diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp |
| index 5faf00f843706992c0ca70acbaa0934d6ef8cb41..4a368fc3a064d320f9e1d262c8976eee88d7fb23 100644 |
| --- a/src/gpu/GrDrawTarget.cpp |
| +++ b/src/gpu/GrDrawTarget.cpp |
| @@ -6,9 +6,9 @@ |
| * found in the LICENSE file. |
| */ |
| - |
| - |
| #include "GrDrawTarget.h" |
| + |
| +#include "GrBatch.h" |
| #include "GrContext.h" |
| #include "GrDrawTargetCaps.h" |
| #include "GrPath.h" |
| @@ -433,6 +433,58 @@ bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, |
| } |
| } |
| +// TODO disgusting hack |
| +bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, |
| + const GrBatch* batch, |
| + GrDeviceCoordTexture* dstCopy, |
| + const SkRect* drawBounds) { |
| + if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor(batch)) { |
| + return true; |
| + } |
| + SkIRect copyRect; |
| + const GrClipData* clip = this->getClip(); |
| + GrRenderTarget* rt = ds->getRenderTarget(); |
| + clip->getConservativeBounds(rt, ©Rect); |
| + |
| + if (drawBounds) { |
| + SkIRect drawIBounds; |
| + drawBounds->roundOut(&drawIBounds); |
| + if (!copyRect.intersect(drawIBounds)) { |
| +#ifdef SK_DEBUG |
| + SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n"); |
| +#endif |
| + return false; |
| + } |
| + } else { |
| +#ifdef SK_DEBUG |
| + //SkDebugf("No dev bounds when dst copy is made.\n"); |
| +#endif |
| + } |
| + |
| + // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| + // have per-sample dst values by making the copy multisampled. |
| + GrSurfaceDesc desc; |
| + this->initCopySurfaceDstDesc(rt, &desc); |
| + desc.fWidth = copyRect.width(); |
| + desc.fHeight = copyRect.height(); |
| + |
| + SkAutoTUnref<GrTexture> copy( |
| + fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
| + |
| + if (!copy) { |
| + SkDebugf("Failed to create temporary copy of destination texture.\n"); |
| + return false; |
| + } |
| + SkIPoint dstPoint = {0, 0}; |
| + if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| + dstCopy->setTexture(copy); |
| + dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
| + return true; |
| + } else { |
| + return false; |
| + } |
| +} |
| + |
| void GrDrawTarget::drawIndexed(GrDrawState* ds, |
| const GrGeometryProcessor* gp, |
| GrPrimitiveType type, |
| @@ -523,6 +575,31 @@ void GrDrawTarget::drawNonIndexed(GrDrawState* ds, |
| } |
| } |
| + |
| +void GrDrawTarget::batchDraw(GrDrawState* ds, |
| + GrBatch* batch, |
| + GrPrimitiveType type, |
| + const SkRect* devBounds) { |
| + SkASSERT(ds); |
| + // TODO some kind of checkdraw, but not at this level |
| + |
| + // Setup clip |
| + GrScissorState scissorState; |
| + GrDrawState::AutoRestoreEffects are; |
| + GrDrawState::AutoRestoreStencil ars; |
| + if (!this->setupClip(ds, &are, &ars, &scissorState, devBounds)) { |
| + return; |
| + } |
| + |
| + // TODO: We should continue with incorrect blending. |
|
bsalomon
2015/01/20 16:14:02
let's just remove the todo... we will probably nev
|
| + GrDeviceCoordTexture dstCopy; |
| + if (!this->setupDstReadIfNecessary(ds, batch, &dstCopy, devBounds)) { |
| + return; |
| + } |
| + |
| + this->onBatchDraw(batch, *ds, type, scissorState, dstCopy.texture() ? &dstCopy : NULL); |
| +} |
| + |
| static const GrStencilSettings& winding_path_stencil_settings() { |
| GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| kIncClamp_StencilOp, |