bool GrDrawTarget::canCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(dst); SkASSERT(src); SkIRect clippedSrcRect; SkIPoint clippedDstPoint; // If the rect is outside the src or dst then we're guaranteed success if (!clip_srcrect_and_dstpoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { return true; } // Check that the read/write rects are contained within the src/dst bounds. SkASSERT(!clippedSrcRect.isEmpty()); SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect)); SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0); SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() && clippedDstPoint.fY + clippedSrcRect.height() <= dst->height()); return !dst->surfacePriv().isSameAs(src) && dst->asRenderTarget() && src->asTexture(); }
bool GrDrawTarget::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(dst); SkASSERT(src); SkIRect clippedSrcRect; SkIPoint clippedDstPoint; // If the rect is outside the src or dst then we've already succeeded. if (!clip_srcrect_and_dstpoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { return true; } if (this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) { return true; } GrRenderTarget* rt = dst->asRenderTarget(); GrTexture* tex = src->asTexture(); if ((dst == src) || !rt || !tex) { return false; } GrPipelineBuilder pipelineBuilder; pipelineBuilder.setRenderTarget(rt); SkMatrix matrix; matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX), SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)); matrix.postIDiv(tex->width(), tex->height()); pipelineBuilder.addColorTextureProcessor(tex, matrix); SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, clippedDstPoint.fY, clippedSrcRect.width(), clippedSrcRect.height()); this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect); return true; }
bool GrDrawTarget::canCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(NULL != dst); SkASSERT(NULL != src); SkIRect clippedSrcRect; SkIPoint clippedDstPoint; // If the rect is outside the src or dst then we're guaranteed success if (!clip_srcrect_and_dstpoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { return true; } return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); }
bool GrDrawTarget::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(dst); SkASSERT(src); SkIRect clippedSrcRect; SkIPoint clippedDstPoint; // If the rect is outside the src or dst then we've already succeeded. if (!clip_srcrect_and_dstpoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { SkASSERT(GrDrawTarget::canCopySurface(dst, src, srcRect, dstPoint)); return true; } if (!GrDrawTarget::canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) { return false; } GrRenderTarget* rt = dst->asRenderTarget(); GrTexture* tex = src->asTexture(); GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit); this->drawState()->setRenderTarget(rt); SkMatrix matrix; matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX), SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)); matrix.postIDiv(tex->width(), tex->height()); this->drawState()->addColorTextureProcessor(tex, matrix); SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, clippedDstPoint.fY, clippedSrcRect.width(), clippedSrcRect.height()); this->drawSimpleRect(dstRect); return true; }
void GrDrawTarget::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(dst); SkASSERT(src); SkIRect clippedSrcRect; SkIPoint clippedDstPoint; // If the rect is outside the src or dst then we've already succeeded. if (!clip_srcrect_and_dstpoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { return; } this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); }
bool GrDrawTarget::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(NULL != dst); SkASSERT(NULL != src); SkIRect clippedSrcRect; SkIPoint clippedDstPoint; // If the rect is outside the src or dst then we've already succeeded. if (!clip_srcrect_and_dstpoint(dst, src, srcRect, dstPoint, &clippedSrcRect, &clippedDstPoint)) { SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint)); return true; } bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)); return result; }