| 1 |
From 731888c38ee41e5892488f1edb8b45160fa9863c Mon Sep 17 00:00:00 2001 |
| 2 |
From: Thomas Smith <[email protected]> |
| 3 |
Date: Thu, 16 Jul 2026 11:01:22 -0400 |
| 4 |
Subject: [PATCH] [ganesh] prevent stale readbacks |
| 5 |
|
| 6 |
* Ganesh's SurfaceContext::readPixels did not consider whether the content it was attempting to readback was successfully rendered or not, leading to a scenario where stale texture data could potentially be readback. |
| 7 |
|
| 8 |
* Add some state tracking so that a failed flush is propagated out of the drawing manager and to the surface context |
| 9 |
|
| 10 |
Bug: https://issues.chromium.org/issues/521491024 |
| 11 |
Change-Id: Idb2b5eaccda7f4ec388e3dc415ee41d329d28533 |
| 12 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1295737 |
| 13 |
Reviewed-by: Michael Ludwig <[email protected]> |
| 14 |
Commit-Queue: Thomas Smith <[email protected]> |
| 15 |
--- |
| 16 |
src/gpu/ganesh/GrDrawingManager.cpp | 9 ++-- |
| 17 |
src/gpu/ganesh/SurfaceContext.cpp | 7 ++- |
| 18 |
tests/ReadWritePixelsGpuTest.cpp | 73 +++++++++++++++++++++++++++++ |
| 19 |
3 files changed, 85 insertions(+), 4 deletions(-) |
| 20 |
|
| 21 |
diff --git a/src/gpu/ganesh/GrDrawingManager.cpp b/src/gpu/ganesh/GrDrawingManager.cpp |
| 22 |
index 398bc35c5e..55b58d958e 100644 |
| 23 |
--- a/src/gpu/ganesh/GrDrawingManager.cpp |
| 24 |
+++ b/src/gpu/ganesh/GrDrawingManager.cpp |
| 25 |
@@ -175,6 +175,7 @@ bool GrDrawingManager::flush(SkSpan<GrSurfaceProxy*> proxies, |
| 26 |
} |
| 27 |
|
| 28 |
bool cachePurgeNeeded = false; |
| 29 |
+ bool flushSuccessful = false; |
| 30 |
|
| 31 |
if (preFlushSuccessful) { |
| 32 |
bool usingReorderedDAG = false; |
| 33 |
@@ -205,8 +206,10 @@ bool GrDrawingManager::flush(SkSpan<GrSurfaceProxy*> proxies, |
| 34 |
resourceAllocator.assign(); |
| 35 |
} |
| 36 |
|
| 37 |
- cachePurgeNeeded = !resourceAllocator.failedInstantiation() && |
| 38 |
- this->executeRenderTasks(&flushState); |
| 39 |
+ if (!resourceAllocator.failedInstantiation()) { |
| 40 |
+ cachePurgeNeeded = this->executeRenderTasks(&flushState); |
| 41 |
+ flushSuccessful = true; |
| 42 |
+ } |
| 43 |
} |
| 44 |
this->removeRenderTasks(); |
| 45 |
|
| 46 |
@@ -226,7 +229,7 @@ bool GrDrawingManager::flush(SkSpan<GrSurfaceProxy*> proxies, |
| 47 |
} |
| 48 |
fFlushing = false; |
| 49 |
|
| 50 |
- return true; |
| 51 |
+ return flushSuccessful; |
| 52 |
} |
| 53 |
|
| 54 |
bool GrDrawingManager::submitToGpu() { |
| 55 |
diff --git a/src/gpu/ganesh/SurfaceContext.cpp b/src/gpu/ganesh/SurfaceContext.cpp |
| 56 |
index ba6bb936c4..efc3f0911a 100644 |
| 57 |
--- a/src/gpu/ganesh/SurfaceContext.cpp |
| 58 |
+++ b/src/gpu/ganesh/SurfaceContext.cpp |
| 59 |
@@ -292,7 +292,12 @@ bool SurfaceContext::readPixels(GrDirectContext* dContext, GrPixmap dst, SkIPoin |
| 60 |
pt.fY = flip ? srcSurface->height() - pt.fY - dst.height() : pt.fY; |
| 61 |
} |
| 62 |
|
| 63 |
- dContext->priv().flushSurface(srcProxy.get()); |
| 64 |
+ bool hasPendingTasks = |
| 65 |
+ dContext->priv().drawingManager()->getLastRenderTask(srcProxy.get()) != nullptr; |
| 66 |
+ GrSemaphoresSubmitted flushResult = dContext->priv().flushSurface(srcProxy.get()); |
| 67 |
+ if (flushResult == GrSemaphoresSubmitted::kNo && hasPendingTasks) { |
| 68 |
+ return false; |
| 69 |
+ } |
| 70 |
dContext->submit(); |
| 71 |
if (!dContext->priv().getGpu()->readPixels(srcSurface, |
| 72 |
SkIRect::MakePtSize(pt, dst.dimensions()), |
| 73 |
-- |
| 74 |
2.53.0 |
| 75 |
|