diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp index 98820c37a9..2b9d1e7ca1 100644 --- a/src/gpu/GrContextPriv.cpp +++ b/src/gpu/GrContextPriv.cpp @@ -304,13 +304,12 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top, ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy()); GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "readSurfacePixels", fContext); - GrSurfaceProxy* srcProxy = src->asSurfaceProxy(); - // MDB TODO: delay this instantiation until later in the method - if (!srcProxy->instantiate(this->resourceProvider())) { + if (!src->asSurfaceProxy()->instantiate(this->resourceProvider(), true)) { return false; } + GrSurfaceProxy* srcProxy = src->asSurfaceProxy(); GrSurface* srcSurface = srcProxy->peekSurface(); if (!GrSurfacePriv::AdjustReadPixelParams(srcSurface->width(), srcSurface->height(), @@ -451,7 +450,9 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top, sk_bzero(buffer, tempPixmap.computeByteSize()); } - this->flush(srcProxy); + if (srcSurface->surfacePriv().hasPendingWrite()) { + this->flush(nullptr); // MDB TODO: tighten this + } if (!fContext->fGpu->readPixels(srcSurface, left, top, width, height, allowedColorType, buffer, rowBytes)) { @@ -492,11 +493,11 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top, return false; } - GrSurfaceProxy* dstProxy = dst->asSurfaceProxy(); - if (!dstProxy->instantiate(this->resourceProvider())) { + if (!dst->asSurfaceProxy()->instantiate(this->resourceProvider(), true)) { return false; } + GrSurfaceProxy* dstProxy = dst->asSurfaceProxy(); GrSurface* dstSurface = dstProxy->peekSurface(); if (!GrSurfacePriv::AdjustWritePixelParams(dstSurface->width(), dstSurface->height(), @@ -579,13 +580,10 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top, dst->asRenderTargetContext()->fillRectToRect( GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), SkRect::MakeXYWH(left, top, width, height), SkRect::MakeWH(width, height)); + return true; } else { - if (!dst->copy(tempProxy.get(), SkIRect::MakeWH(width, height), {left, top})) { - return false; - } + return dst->copy(tempProxy.get(), SkIRect::MakeWH(width, height), {left, top}); } - - return true; } bool convert = premul || needColorConversion; @@ -647,7 +645,9 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top, top = dstSurface->height() - top - height; } - this->flush(dstProxy); + if (dstSurface->surfacePriv().hasPendingIO()) { + this->flush(nullptr); // MDB TODO: tighten this + } return this->getGpu()->writePixels(dstSurface, left, top, width, height, srcColorType, buffer, rowBytes);