Pass origins through the flushSurfaces calls.
Bug: skia:9556
Change-Id: Ie4a0b33dd35e50b93c30cb0010f60c2893140661
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270439
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index e033ffa..f1f0d86 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -40,7 +40,8 @@
fContext->addOnFlushCallbackObject(onFlushCBObject);
}
-GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
+GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[],
+ GrSurfaceOrigin origins[], int numProxies,
const GrFlushInfo& info) {
ASSERT_SINGLE_OWNER
RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo)
@@ -52,11 +53,12 @@
ASSERT_OWNED_PROXY(proxies[i]);
}
return fContext->drawingManager()->flushSurfaces(
- proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info);
+ proxies, origins, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info);
}
-void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) {
- this->flushSurfaces(proxy ? &proxy : nullptr, proxy ? 1 : 0, {});
+void GrContextPriv::flushSurface(GrSurfaceProxy* proxy, GrSurfaceOrigin origin) {
+ SkASSERT(proxy);
+ this->flushSurfaces(&proxy, &origin, 1, {});
}
void GrContextPriv::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 8e78956..28201ae 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -86,11 +86,16 @@
* GrContext will detect when it must perform a resolve before reading pixels back from the
* surface or using it as a texture.
*/
- GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], int numProxies, const GrFlushInfo&);
+ GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy*[], GrSurfaceOrigin[], int numProxies,
+ const GrFlushInfo&);
- /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is
- * allowed. */
- void flushSurface(GrSurfaceProxy*);
+ /** Version of above that flushes for a single proxy and uses a default GrFlushInfo. Null is not
+ * allowed for the proxy. */
+ void flushSurface(GrSurfaceProxy*, GrSurfaceOrigin);
+
+ void flushSurface() {
+ this->flushSurfaces(nullptr, nullptr, 0, {});
+ }
/**
* Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words,
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 68f57f1..961c603 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -494,7 +494,8 @@
return anyRenderTasksExecuted;
}
-GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
+GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(GrSurfaceProxy* proxies[],
+ GrSurfaceOrigin origins[], int numProxies,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
if (this->wasAbandoned()) {
@@ -534,7 +535,7 @@
if (rtProxy->isMSAADirty()) {
SkASSERT(rtProxy->peekRenderTarget());
gpu->resolveRenderTarget(rtProxy->peekRenderTarget(), rtProxy->msaaDirtyRect(),
- rtProxy->origin(), GrGpu::ForExternalIO::kYes);
+ origins[i], GrGpu::ForExternalIO::kYes);
rtProxy->markMSAAResolved();
}
}
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index 8bb64e3..752973a 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -93,13 +93,14 @@
static bool ProgramUnitTest(GrContext* context, int maxStages, int maxLevels);
GrSemaphoresSubmitted flushSurfaces(GrSurfaceProxy* proxies[],
+ GrSurfaceOrigin origins[],
int cnt,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info);
- GrSemaphoresSubmitted flushSurface(GrSurfaceProxy* proxy,
+ GrSemaphoresSubmitted flushSurface(GrSurfaceProxy* proxy, GrSurfaceOrigin origin,
SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info) {
- return this->flushSurfaces(&proxy, 1, access, info);
+ return this->flushSurfaces(&proxy, &origin, 1, access, info);
}
void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 6a08e46..65abda8 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -2164,7 +2164,8 @@
SkDEBUGCODE(this->validate();)
GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "flush", fContext);
- return this->drawingManager()->flushSurface(this->asSurfaceProxy(), access, info);
+ return this->drawingManager()->flushSurface(this->asSurfaceProxy(), this->origin(), access,
+ info);
}
bool GrRenderTargetContext::waitOnSemaphores(int numSemaphores,
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 5c4e04a..88b5962 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -240,7 +240,7 @@
return tempCtx->readPixels(dstInfo, dst, rowBytes, {0, 0}, direct);
}
- bool flip = srcProxy->origin() == kBottomLeft_GrSurfaceOrigin;
+ bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
auto supportedRead = caps->supportedReadPixelsColorType(
this->colorInfo().colorType(), srcProxy->backendFormat(), dstInfo.colorType());
@@ -267,7 +267,7 @@
pt.fY = flip ? srcSurface->height() - pt.fY - dstInfo.height() : pt.fY;
}
- direct->priv().flushSurface(srcProxy);
+ direct->priv().flushSurface(srcProxy, this->origin());
if (!direct->priv().getGpu()->readPixels(srcSurface, pt.fX, pt.fY, dstInfo.width(),
dstInfo.height(), this->colorInfo().colorType(),
@@ -378,7 +378,7 @@
// we can use a draw instead which doesn't have this origin restriction. Thus for render
// targets we will use top left and otherwise we will make the origins match.
GrSurfaceOrigin tempOrigin =
- this->asRenderTargetContext() ? kTopLeft_GrSurfaceOrigin : dstProxy->origin();
+ this->asRenderTargetContext() ? kTopLeft_GrSurfaceOrigin : this->origin();
auto tempProxy = direct->priv().proxyProvider()->createProxy(
format, srcInfo.dimensions(), tempReadSwizzle, GrRenderable::kNo, 1, tempOrigin,
GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
@@ -436,7 +436,7 @@
caps->supportedWritePixelsColorType(this->colorInfo().colorType(),
dstProxy->backendFormat(),
srcInfo.colorType()).fColorType;
- bool flip = dstProxy->origin() == kBottomLeft_GrSurfaceOrigin;
+ bool flip = this->origin() == kBottomLeft_GrSurfaceOrigin;
bool makeTight = !caps->writePixelsRowBytesSupport() && rowBytes != tightRowBytes;
bool convert = premul || unpremul || needColorConversion || makeTight ||
(srcInfo.colorType() != allowedColorType) || flip;
@@ -462,7 +462,11 @@
// giving the drawing manager the chance of skipping the flush (i.e., by passing in the
// destination proxy)
// TODO: should this policy decision just be moved into the drawing manager?
- direct->priv().flushSurface(caps->preferVRAMUseOverFlushes() ? dstProxy : nullptr);
+ if (caps->preferVRAMUseOverFlushes()) {
+ direct->priv().flushSurface(dstProxy, this->origin());
+ } else {
+ direct->priv().flushSurface();
+ }
return direct->priv().getGpu()->writePixels(dstSurface, pt.fX, pt.fY, srcInfo.width(),
srcInfo.height(), this->colorInfo().colorType(),
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 18728a4..b8a7595 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -71,7 +71,8 @@
}
GrSurfaceProxy* p[1] = {fView.proxy()};
- return context->priv().flushSurfaces(p, 1, info);
+ GrSurfaceOrigin origin = fView.origin();
+ return context->priv().flushSurfaces(p, &origin, 1, info);
}
sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(GrRecordingContext* context,
@@ -560,7 +561,7 @@
sk_sp<GrTexture> texture = sk_ref_sp(view.proxy()->peekTexture());
// Flush any writes or uploads
- context->priv().flushSurface(view.proxy());
+ context->priv().flushSurface(view.proxy(), view.origin());
GrGpu* gpu = context->priv().getGpu();
std::unique_ptr<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get());
@@ -697,8 +698,11 @@
return false;
}
+ const GrSurfaceProxyView* view = as_IB(image)->view(ctx);
+ SkASSERT(view);
+
// Flush any pending IO on the texture.
- ctx->priv().flushSurface(as_IB(image)->peekProxy());
+ ctx->priv().flushSurface(view->proxy(), view->origin());
// We must make a copy of the image if the image is not unique, if the GrTexture owned by the
// image is not unique, or if the texture wraps an external object.
@@ -715,8 +719,11 @@
return false;
}
+ view = as_IB(image)->view(ctx);
+ SkASSERT(view);
+
// Flush to ensure that the copy is completed before we return the texture.
- ctx->priv().flushSurface(as_IB(image)->peekProxy());
+ ctx->priv().flushSurface(view->proxy(), view->origin());
}
SkASSERT(!texture->resourcePriv().refsWrappedObjects());
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 563d290..3d0f3c7 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -221,7 +221,7 @@
GrTexture* texture = proxy->peekTexture();
if (texture) {
if (flushPendingGrContextIO) {
- direct->priv().flushSurface(proxy);
+ direct->priv().flushSurface(proxy, view->origin());
}
if (origin) {
*origin = proxy->origin();
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 2f7ced0..1c0505f 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -119,15 +119,18 @@
GrSurfaceProxy* proxies[4] = {fViews[0].proxy(), fViews[1].proxy(), fViews[2].proxy(),
fViews[3].proxy()};
+ GrSurfaceOrigin origins[4] = {fViews[0].origin(), fViews[1].origin(), fViews[2].origin(),
+ fViews[3].origin()};
int numProxies = fNumViews;
if (fRGBView.proxy()) {
// Either we've already flushed the flattening draw or the flattening is unflushed. In the
// latter case it should still be ok to just pass fRGBView proxy because it in turn depends
// on the planar proxies and will cause all of their work to flush as well.
proxies[0] = fRGBView.proxy();
+ origins[0] = fRGBView.origin();
numProxies = 1;
}
- return context->priv().flushSurfaces(proxies, numProxies, info);
+ return context->priv().flushSurfaces(proxies, origins, numProxies, info);
}
GrTextureProxy* SkImage_GpuYUVA::peekProxy() const { return fRGBView.asTextureProxy(); }