diff --git a/src/gpu/ganesh/GrDrawingManager.cpp b/src/gpu/ganesh/GrDrawingManager.cpp index 28a50ae4626..aebe063d27b 100644 --- a/src/gpu/ganesh/GrDrawingManager.cpp +++ b/src/gpu/ganesh/GrDrawingManager.cpp @@ -175,6 +175,7 @@ bool GrDrawingManager::flush(SkSpan proxies, } bool cachePurgeNeeded = false; + bool renderTasksDropped = !preFlushSuccessful; if (preFlushSuccessful) { bool usingReorderedDAG = false; @@ -205,7 +206,8 @@ bool GrDrawingManager::flush(SkSpan proxies, resourceAllocator.assign(); } - cachePurgeNeeded = !resourceAllocator.failedInstantiation() && + renderTasksDropped = resourceAllocator.failedInstantiation(); + cachePurgeNeeded = !renderTasksDropped && this->executeRenderTasks(&flushState); } this->removeRenderTasks(); @@ -226,7 +228,11 @@ bool GrDrawingManager::flush(SkSpan proxies, } fFlushing = false; - return true; + // Propagate that queued work was discarded so callers (e.g. + // SurfaceContext::readPixels) do not assume targets contain + // freshly-rendered data when in fact a recycled scratch resource was + // never overwritten. + return !renderTasksDropped; } bool GrDrawingManager::submitToGpu() { diff --git a/src/gpu/ganesh/SurfaceContext.cpp b/src/gpu/ganesh/SurfaceContext.cpp index 1afa768d241..fdde04c22e9 100644 --- a/src/gpu/ganesh/SurfaceContext.cpp +++ b/src/gpu/ganesh/SurfaceContext.cpp @@ -216,6 +216,15 @@ bool SurfaceContext::readPixels(GrDirectContext* dContext, GrPixmap dst, SkIPoin sfc->fillRectToRectWithFP(SkIRect::MakePtSize(pt, dst.dimensions()), SkIRect::MakeSize(dst.dimensions()), std::move(fp)); + // The kApprox temp surface may be backed by a recycled scratch + // texture that still holds a prior occupant's pixels. Flush now + // and verify the fill above was actually executed; if + // GrDrawingManager::flush() dropped render tasks (preFlush / + // instantiation failure) we must not read back stale contents. + if (dContext->priv().flushSurface(sfc->asSurfaceProxy()) == + GrSemaphoresSubmitted::kNo) { + return false; + } pt = {0, 0}; tempCtx = std::move(sfc); } else {