diff --git a/gm/preservefillrule.cpp b/gm/preservefillrule.cpp index bf795dcba7..d42f5a27b0 100644 --- a/gm/preservefillrule.cpp +++ b/gm/preservefillrule.cpp @@ -113,7 +113,7 @@ private: canvas->drawPath(star7_evenOdd, paint); canvas->drawPath(star5_winding, paint); canvas->drawPath(star5_evenOdd, paint); - rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr); + dContext->priv().flushSurface(rtc->asSurfaceProxy()); // Ensure the path cache is behaving in such a way that we are actually testing what we // think we are. diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp index bd4bf60869..8982015c1e 100644 --- a/src/gpu/GrDirectContext.cpp +++ b/src/gpu/GrDirectContext.cpp @@ -365,13 +365,8 @@ GrSemaphoresSubmitted GrDirectContext::flush(const GrFlushInfo& info) { return GrSemaphoresSubmitted::kNo; } - bool flushed = this->drawingManager()->flush( - {}, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr); - - if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) { - return GrSemaphoresSubmitted::kNo; - } - return GrSemaphoresSubmitted::kYes; + return this->drawingManager()->flushSurfaces({}, SkSurface::BackendSurfaceAccess::kNoAccess, + info, nullptr); } bool GrDirectContext::submit(bool syncCpu) { diff --git a/src/gpu/GrDirectContextPriv.cpp b/src/gpu/GrDirectContextPriv.cpp index 10b59c864f..145946171e 100644 --- a/src/gpu/GrDirectContextPriv.cpp +++ b/src/gpu/GrDirectContextPriv.cpp @@ -39,24 +39,31 @@ void GrDirectContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFl fContext->addOnFlushCallbackObject(onFlushCBObject); } -GrSemaphoresSubmitted GrDirectContextPriv::flushSurfaces(SkSpan proxies, - const GrFlushInfo& info) { +GrSemaphoresSubmitted GrDirectContextPriv::flushSurfaces( + SkSpan proxies, + SkSurface::BackendSurfaceAccess access, + const GrFlushInfo& info, + const GrBackendSurfaceMutableState* newState) { ASSERT_SINGLE_OWNER - RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo) GR_CREATE_TRACE_MARKER_CONTEXT("GrDirectContextPriv", "flushSurfaces", fContext); + + if (fContext->abandoned()) { + if (info.fSubmittedProc) { + info.fSubmittedProc(info.fSubmittedContext, false); + } + if (info.fFinishedProc) { + info.fFinishedProc(info.fFinishedContext); + } + return GrSemaphoresSubmitted::kNo; + } + #ifdef SK_DEBUG for (GrSurfaceProxy* proxy : proxies) { SkASSERT(proxy); ASSERT_OWNED_PROXY(proxy); } #endif - return fContext->drawingManager()->flushSurfaces( - proxies, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr); -} - -void GrDirectContextPriv::flushSurface(GrSurfaceProxy* proxy) { - size_t size = proxy ? 1 : 0; - this->flushSurfaces({&proxy, size}, {}); + return fContext->drawingManager()->flushSurfaces(proxies, access, info, newState); } void GrDirectContextPriv::copyRenderTasksFromDDL(sk_sp ddl, diff --git a/src/gpu/GrDirectContextPriv.h b/src/gpu/GrDirectContextPriv.h index 119df845b7..d96030e715 100644 --- a/src/gpu/GrDirectContextPriv.h +++ b/src/gpu/GrDirectContextPriv.h @@ -8,6 +8,7 @@ #ifndef GrDirectContextPriv_DEFINED #define GrDirectContextPriv_DEFINED +#include "include/core/SkSurface.h" #include "include/gpu/GrDirectContext.h" #include "src/core/SkSpan.h" @@ -81,11 +82,21 @@ public: * GrContext will detect when it must perform a resolve before reading pixels back from the * surface or using it as a texture. */ - GrSemaphoresSubmitted flushSurfaces(SkSpan, const GrFlushInfo&); + GrSemaphoresSubmitted flushSurfaces( + SkSpan, + SkSurface::BackendSurfaceAccess = SkSurface::BackendSurfaceAccess::kNoAccess, + const GrFlushInfo& = {}, + const GrBackendSurfaceMutableState* newState = nullptr); - /** 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. Null is allowed. */ + GrSemaphoresSubmitted flushSurface( + GrSurfaceProxy* proxy, + SkSurface::BackendSurfaceAccess access = SkSurface::BackendSurfaceAccess::kNoAccess, + const GrFlushInfo& info = {}, + const GrBackendSurfaceMutableState* newState = nullptr) { + size_t size = proxy ? 1 : 0; + return this->flushSurfaces({&proxy, size}, access, info, newState); + } /** * Returns true if createPMToUPMEffect and createUPMToPMEffect will succeed. In other words, diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index 5f11fdc71f..53d49229bd 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -757,7 +757,10 @@ void GrSurfaceContext::asyncReadPixels(GrDirectContext* dContext, GrFlushInfo flushInfo; flushInfo.fFinishedContext = finishContext; flushInfo.fFinishedProc = finishCallback; - this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo, nullptr); + + dContext->priv().flushSurface(this->asSurfaceProxy(), + SkSurface::BackendSurfaceAccess::kNoAccess, + flushInfo); } void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(GrDirectContext* dContext, @@ -1025,7 +1028,9 @@ void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(GrDirectContext* dContext GrFlushInfo flushInfo; flushInfo.fFinishedContext = finishContext; flushInfo.fFinishedProc = finishCallback; - this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo, nullptr); + dContext->priv().flushSurface(this->asSurfaceProxy(), + SkSurface::BackendSurfaceAccess::kNoAccess, + flushInfo); } bool GrSurfaceContext::copy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { @@ -1213,26 +1218,6 @@ std::unique_ptr GrSurfaceContext::rescale(const GrImageIn return tempA; } -GrSemaphoresSubmitted GrSurfaceContext::flush(SkSurface::BackendSurfaceAccess access, - const GrFlushInfo& info, - const GrBackendSurfaceMutableState* newState) { - ASSERT_SINGLE_OWNER - if (fContext->abandoned()) { - if (info.fSubmittedProc) { - info.fSubmittedProc(info.fSubmittedContext, false); - } - if (info.fFinishedProc) { - info.fFinishedProc(info.fFinishedContext); - } - return GrSemaphoresSubmitted::kNo; - } - SkDEBUGCODE(this->validate();) - GR_CREATE_TRACE_MARKER_CONTEXT("GrRenderTargetContext", "flush", fContext); - - GrSurfaceProxy* proxies[1] = {this->asSurfaceProxy()}; - return this->drawingManager()->flushSurfaces(proxies, access, info, newState); -} - GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorType dstCT, const SkIRect& rect) { SkASSERT(rect.fLeft >= 0 && rect.fRight <= this->width()); diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h index 3b60b1447c..bc4d0c885a 100644 --- a/src/gpu/GrSurfaceContext.h +++ b/src/gpu/GrSurfaceContext.h @@ -158,14 +158,6 @@ public: SkImage::RescaleGamma, SkFilterQuality); - /** - * After this returns any pending surface IO will be issued to the backend 3D API and - * if the surface has MSAA it will be resolved. - */ - GrSemaphoresSubmitted flush(SkSurface::BackendSurfaceAccess access, - const GrFlushInfo&, - const GrBackendSurfaceMutableState*); - GrAuditTrail* auditTrail(); // Provides access to functions that aren't part of the public API. diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index b1ada97dd6..cf7bbf5043 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -33,6 +33,7 @@ #include "src/core/SkVerticesPriv.h" #include "src/gpu/GrBitmapTextureMaker.h" #include "src/gpu/GrBlurUtils.h" +#include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrGpu.h" #include "src/gpu/GrImageTextureMaker.h" #include "src/gpu/GrRecordingContextPriv.h" @@ -1033,18 +1034,10 @@ void SkGpuDevice::flush() { return; } - this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr); + direct->priv().flushSurface(fRenderTargetContext->asSurfaceProxy()); direct->submit(); } -GrSemaphoresSubmitted SkGpuDevice::flush(SkSurface::BackendSurfaceAccess access, - const GrFlushInfo& info, - const GrBackendSurfaceMutableState* newState) { - ASSERT_SINGLE_OWNER - - return fRenderTargetContext->flush(access, info, newState); -} - bool SkGpuDevice::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores, bool deleteSemaphoresAfterWait) { ASSERT_SINGLE_OWNER diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index da8bdefaee..251fe55e3f 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -131,8 +131,6 @@ public: sk_sp snapSpecial(const SkIRect&, bool = false) override; void flush() override; - GrSemaphoresSubmitted flush(SkSurface::BackendSurfaceAccess access, const GrFlushInfo&, - const GrBackendSurfaceMutableState*); bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores, bool deleteSemaphoresAfterWait); diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 1209106072..fe4fb7bdb6 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -77,8 +77,8 @@ GrSemaphoresSubmitted SkImage_Gpu::onFlush(GrDirectContext* dContext, const GrFl return GrSemaphoresSubmitted::kNo; } - GrSurfaceProxy* p[1] = {fView.proxy()}; - return dContext->priv().flushSurfaces(p, info); + return dContext->priv().flushSurface(fView.proxy(), SkSurface::BackendSurfaceAccess::kNoAccess, + info); } sk_sp SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT, diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp index ec48e6b7e5..aabafd953b 100644 --- a/src/image/SkImage_GpuYUVA.cpp +++ b/src/image/SkImage_GpuYUVA.cpp @@ -142,7 +142,9 @@ GrSemaphoresSubmitted SkImage_GpuYUVA::onFlush(GrDirectContext* dContext, const proxies[0] = fRGBView.proxy(); numProxies = 1; } - return dContext->priv().flushSurfaces({proxies, numProxies}, info); + return dContext->priv().flushSurfaces({proxies, numProxies}, + SkSurface::BackendSurfaceAccess::kNoAccess, + info); } GrTextureProxy* SkImage_GpuYUVA::peekProxy() const { return fRGBView.asTextureProxy(); } diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 70e019481e..22d82fd112 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -44,6 +44,11 @@ GrRecordingContext* SkSurface_Gpu::onGetRecordingContext() { static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, SkSurface::BackendHandleAccess access) { + auto dContext = surface->recordingContext()->asDirectContext(); + if (!dContext) { + return nullptr; + } + switch (access) { case SkSurface::kFlushRead_BackendHandleAccess: break; @@ -54,9 +59,11 @@ static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, break; } - // Grab the render target *after* firing notifications, as it may get switched if CoW kicks in. - surface->getDevice()->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr); GrRenderTargetContext* rtc = surface->getDevice()->accessRenderTargetContext(); + dContext->priv().flushSurface(rtc->asSurfaceProxy()); + + // Grab the render target *after* firing notifications, as it may get switched if CoW kicks in. + rtc = surface->getDevice()->accessRenderTargetContext(); return rtc->accessRenderTarget(); } @@ -201,7 +208,15 @@ void SkSurface_Gpu::onDiscard() { GrSemaphoresSubmitted SkSurface_Gpu::onFlush(BackendSurfaceAccess access, const GrFlushInfo& info, const GrBackendSurfaceMutableState* newState) { - return fDevice->flush(access, info, newState); + + auto dContext = fDevice->recordingContext()->asDirectContext(); + if (!dContext) { + return GrSemaphoresSubmitted::kNo; + } + + GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext(); + + return dContext->priv().flushSurface(rtc->asSurfaceProxy(), access, info, newState); } bool SkSurface_Gpu::onWait(int numSemaphores, const GrBackendSemaphore* waitSemaphores, diff --git a/tests/DefaultPathRendererTest.cpp b/tests/DefaultPathRendererTest.cpp index da576118ea..50e039a694 100644 --- a/tests/DefaultPathRendererTest.cpp +++ b/tests/DefaultPathRendererTest.cpp @@ -96,10 +96,9 @@ static void run_test(GrDirectContext* dContext, skiatest::Reporter* reporter) { auto fp = GrConstColorProcessor::Make(color); paint.setColorFragmentProcessor(std::move(fp)); - rtc->drawPath(nullptr, std::move(paint), GrAA::kNo, - SkMatrix::I(), invPath, style); + rtc->drawPath(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), invPath, style); - rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr); + dContext->priv().flushSurface(rtc->asSurfaceProxy()); } { diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp index ff3c0ec21f..909a0df3b6 100644 --- a/tests/OnFlushCallbackTest.cpp +++ b/tests/OnFlushCallbackTest.cpp @@ -598,7 +598,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(OnFlushCallbackTest, reporter, ctxInfo) { rtc->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), r); } - rtc->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr); + dContext->priv().flushSurface(rtc->asSurfaceProxy()); SkBitmap readBack; readBack.allocN32Pixels(kFinalWidth, kFinalHeight);