From 0d075de8634b5f96430280d5ae7eeeca33b22f6c Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Mon, 4 Mar 2019 11:08:13 -0500 Subject: [PATCH] Clean up GrSurfaceContext's relationship with GrRecordingContext GrSurfaceContext was explicitly holding a lot of things it could just get from its GrRecordingContext. Change-Id: Ia2e9708d71318dc0c101d56aadf5ae797230bc75 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/194360 Reviewed-by: Greg Daniel Commit-Queue: Robert Phillips --- gm/compositor_quads.cpp | 4 +++ src/gpu/GrDrawingManager.cpp | 22 +++++++---------- src/gpu/GrDrawingManager.h | 5 +--- src/gpu/GrRecordingContext.cpp | 2 +- src/gpu/GrRenderTargetContext.cpp | 6 +---- src/gpu/GrRenderTargetContext.h | 8 +++--- src/gpu/GrSurfaceContext.cpp | 37 +++++++++++++++++----------- src/gpu/GrSurfaceContext.h | 18 ++++---------- src/gpu/GrTextureContext.cpp | 8 ++---- src/gpu/GrTextureContext.h | 7 +++--- src/gpu/effects/GrRRectBlurEffect.fp | 1 + src/gpu/effects/GrRRectBlurEffect.h | 1 + tools/gpu/GrTest.cpp | 2 +- 13 files changed, 56 insertions(+), 65 deletions(-) diff --git a/gm/compositor_quads.cpp b/gm/compositor_quads.cpp index ddc2a9a75a..3a9db780cc 100644 --- a/gm/compositor_quads.cpp +++ b/gm/compositor_quads.cpp @@ -9,6 +9,10 @@ #if SK_SUPPORT_GPU +#include "GrClip.h" +#include "GrContext.h" +#include "GrRect.h" +#include "GrRenderTargetContextPriv.h" #include "Resources.h" #include "SkColorMatrixFilter.h" #include "SkFont.h" diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 2f38e9c690..aa22cef4ad 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -150,14 +150,12 @@ void GrDrawingManager::OpListDAG::cleanup(const GrCaps* caps) { GrDrawingManager::GrDrawingManager(GrRecordingContext* context, const GrPathRendererChain::Options& optionsForPathRendererChain, const GrTextContext::Options& optionsForTextContext, - GrSingleOwner* singleOwner, bool explicitlyAllocating, GrContextOptions::Enable sortOpLists, GrContextOptions::Enable reduceOpListSplitting) : fContext(context) , fOptionsForPathRendererChain(optionsForPathRendererChain) , fOptionsForTextContext(optionsForTextContext) - , fSingleOwner(singleOwner) , fDAG(explicitlyAllocating, sortOpLists) , fTextContext(nullptr) , fPathRendererChain(nullptr) @@ -770,14 +768,13 @@ sk_sp GrDrawingManager::makeRenderTargetContext( return nullptr; } - sk_sp rtp(sk_ref_sp(sProxy->asRenderTargetProxy())); + sk_sp renderTargetProxy(sk_ref_sp(sProxy->asRenderTargetProxy())); - return sk_sp(new GrRenderTargetContext( - fContext, this, std::move(rtp), - std::move(colorSpace), - surfaceProps, - fContext->priv().auditTrail(), - fSingleOwner, managedOpList)); + return sk_sp(new GrRenderTargetContext(fContext, + std::move(renderTargetProxy), + std::move(colorSpace), + surfaceProps, + managedOpList)); } sk_sp GrDrawingManager::makeTextureContext(sk_sp sProxy, @@ -798,8 +795,7 @@ sk_sp GrDrawingManager::makeTextureContext(sk_sp textureProxy(sk_ref_sp(sProxy->asTextureProxy())); - return sk_sp(new GrTextureContext(fContext, this, std::move(textureProxy), - std::move(colorSpace), - fContext->priv().auditTrail(), - fSingleOwner)); + return sk_sp(new GrTextureContext(fContext, + std::move(textureProxy), + std::move(colorSpace))); } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index bbd14670de..97ae745a05 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -23,7 +23,6 @@ class GrOpFlushState; class GrRecordingContext; class GrRenderTargetContext; class GrRenderTargetProxy; -class GrSingleOWner; class GrRenderTargetOpList; class GrSoftwarePathRenderer; class GrTextureContext; @@ -138,7 +137,7 @@ private: }; GrDrawingManager(GrRecordingContext*, const GrPathRendererChain::Options&, - const GrTextContext::Options&, GrSingleOwner*, + const GrTextContext::Options&, bool explicitlyAllocating, GrContextOptions::Enable sortRenderTargets, GrContextOptions::Enable reduceOpListSplitting); @@ -171,8 +170,6 @@ private: // This cache is used by both the vertex and index pools. It reuses memory across multiple // flushes. sk_sp fCpuBufferCache; - // In debug builds we guard against improper thread handling - GrSingleOwner* fSingleOwner; OpListDAG fDAG; GrOpList* fActiveOpList = nullptr; diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp index 7384e3c169..553fc7da70 100644 --- a/src/gpu/GrRecordingContext.cpp +++ b/src/gpu/GrRecordingContext.cpp @@ -8,6 +8,7 @@ #include "GrRecordingContext.h" #include "GrCaps.h" +#include "GrContext.h" #include "GrDrawingManager.h" #include "GrMemoryPool.h" #include "GrProxyProvider.h" @@ -92,7 +93,6 @@ bool GrRecordingContext::init(sk_sp caps, sk_spsingleOwner(), this->explicitlyAllocateGPUResources(), this->options().fSortRenderTargets, this->options().fReduceOpListSplitting)); diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 0b7582bc2e..d3f033f14c 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -160,15 +160,11 @@ private: // stack. When this occurs with a closed GrOpList, a new one will be allocated // when the renderTargetContext attempts to use it (via getOpList). GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context, - GrDrawingManager* drawingMgr, sk_sp rtp, sk_sp colorSpace, const SkSurfaceProps* surfaceProps, - GrAuditTrail* auditTrail, - GrSingleOwner* singleOwner, bool managedOpList) - : GrSurfaceContext(context, drawingMgr, rtp->config(), std::move(colorSpace), auditTrail, - singleOwner) + : GrSurfaceContext(context, rtp->config(), std::move(colorSpace)) , fRenderTargetProxy(std::move(rtp)) , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index 65ce093757..1d2f7a5bd2 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -9,7 +9,6 @@ #define GrRenderTargetContext_DEFINED #include "../private/GrRenderTargetProxy.h" -#include "GrContext.h" #include "GrPaint.h" #include "GrSurfaceContext.h" #include "GrTypesPriv.h" @@ -28,6 +27,7 @@ class GrCoverageCountingPathRenderer; class GrDrawingManager; class GrDrawOp; class GrFixedClip; +class GrOp; class GrRenderTarget; class GrRenderTargetContextPriv; class GrRenderTargetOpList; @@ -456,9 +456,9 @@ public: bool isWrapped_ForTesting() const; protected: - GrRenderTargetContext(GrRecordingContext*, GrDrawingManager*, sk_sp, - sk_sp, const SkSurfaceProps*, GrAuditTrail*, - GrSingleOwner*, bool managedOpList = true); + GrRenderTargetContext(GrRecordingContext*, sk_sp, + sk_sp, const SkSurfaceProps*, + bool managedOpList = true); SkDEBUGCODE(void validate() const override;) diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index 2d85a11a66..ae44eb9faf 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -23,27 +23,36 @@ // stack. When this occurs with a closed GrOpList, a new one will be allocated // when the renderTargetContext attempts to use it (via getOpList). GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context, - GrDrawingManager* drawingMgr, GrPixelConfig config, - sk_sp colorSpace, - GrAuditTrail* auditTrail, - GrSingleOwner* singleOwner) + sk_sp colorSpace) : fContext(context) - , fAuditTrail(auditTrail) - , fColorSpaceInfo(std::move(colorSpace), config) - , fDrawingManager(drawingMgr) -#ifdef SK_DEBUG - , fSingleOwner(singleOwner) -#endif -{ + , fColorSpaceInfo(std::move(colorSpace), config) { } +GrAuditTrail* GrSurfaceContext::auditTrail() { + return fContext->priv().auditTrail(); +} + +GrDrawingManager* GrSurfaceContext::drawingManager() { + return fContext->priv().drawingManager(); +} + +const GrDrawingManager* GrSurfaceContext::drawingManager() const { + return fContext->priv().drawingManager(); +} + +#ifdef SK_DEBUG +GrSingleOwner* GrSurfaceContext::singleOwner() { + return fContext->priv().singleOwner(); +} +#endif + bool GrSurfaceContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer, size_t dstRowBytes, int x, int y, uint32_t flags) { ASSERT_SINGLE_OWNER RETURN_FALSE_IF_ABANDONED SkDEBUGCODE(this->validate();) - GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrSurfaceContext::readPixels"); + GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels"); // TODO: this seems to duplicate code in SkImage_Gpu::onReadPixels if (kUnpremul_SkAlphaType == dstInfo.alphaType() && @@ -70,7 +79,7 @@ bool GrSurfaceContext::writePixels(const SkImageInfo& srcInfo, const void* srcBu ASSERT_SINGLE_OWNER RETURN_FALSE_IF_ABANDONED SkDEBUGCODE(this->validate();) - GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrSurfaceContext::writePixels"); + GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::writePixels"); if (kUnpremul_SkAlphaType == srcInfo.alphaType()) { flags |= GrContextPriv::kUnpremul_PixelOpsFlag; @@ -94,7 +103,7 @@ bool GrSurfaceContext::copy(GrSurfaceProxy* src, const SkIRect& srcRect, const S ASSERT_SINGLE_OWNER RETURN_FALSE_IF_ABANDONED SkDEBUGCODE(this->validate();) - GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrSurfaceContext::copy"); + GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::copy"); if (!fContext->priv().caps()->canCopySurface(this->asSurfaceProxy(), src, srcRect, dstPoint)) { diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h index 9d60689d3a..368fbfb247 100644 --- a/src/gpu/GrSurfaceContext.h +++ b/src/gpu/GrSurfaceContext.h @@ -13,7 +13,6 @@ #include "SkRefCnt.h" class GrAuditTrail; -class GrContext; class GrDrawingManager; class GrOpList; class GrRecordingContext; @@ -103,7 +102,7 @@ public: virtual GrRenderTargetContext* asRenderTargetContext() { return nullptr; } - GrAuditTrail* auditTrail() { return fAuditTrail; } + GrAuditTrail* auditTrail(); // Provides access to functions that aren't part of the public API. GrSurfaceContextPriv surfPriv(); @@ -112,28 +111,21 @@ public: protected: friend class GrSurfaceContextPriv; - GrSurfaceContext(GrRecordingContext*, GrDrawingManager*, GrPixelConfig, sk_sp, - GrAuditTrail*, GrSingleOwner*); + GrSurfaceContext(GrRecordingContext*, GrPixelConfig, sk_sp); - GrDrawingManager* drawingManager() { return fDrawingManager; } - const GrDrawingManager* drawingManager() const { return fDrawingManager; } + GrDrawingManager* drawingManager(); + const GrDrawingManager* drawingManager() const; virtual GrOpList* getOpList() = 0; SkDEBUGCODE(virtual void validate() const = 0;) - SkDEBUGCODE(GrSingleOwner* singleOwner() { return fSingleOwner; }) + SkDEBUGCODE(GrSingleOwner* singleOwner();) GrRecordingContext* fContext; - GrAuditTrail* fAuditTrail; private: GrColorSpaceInfo fColorSpaceInfo; - GrDrawingManager* fDrawingManager; - - // In debug builds we guard against improper thread handling - SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) - typedef SkRefCnt INHERITED; }; diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp index e4434a2935..0b396e196e 100644 --- a/src/gpu/GrTextureContext.cpp +++ b/src/gpu/GrTextureContext.cpp @@ -18,13 +18,9 @@ #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; } GrTextureContext::GrTextureContext(GrRecordingContext* context, - GrDrawingManager* drawingMgr, sk_sp textureProxy, - sk_sp colorSpace, - GrAuditTrail* auditTrail, - GrSingleOwner* singleOwner) - : GrSurfaceContext(context, drawingMgr, textureProxy->config(), std::move(colorSpace), - auditTrail, singleOwner) + sk_sp colorSpace) + : GrSurfaceContext(context, textureProxy->config(), std::move(colorSpace)) , fTextureProxy(std::move(textureProxy)) , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) { SkDEBUGCODE(this->validate();) diff --git a/src/gpu/GrTextureContext.h b/src/gpu/GrTextureContext.h index 70603a24b3..9544f4d5c7 100644 --- a/src/gpu/GrTextureContext.h +++ b/src/gpu/GrTextureContext.h @@ -39,8 +39,7 @@ public: sk_sp asRenderTargetProxyRef() override; protected: - GrTextureContext(GrRecordingContext*, GrDrawingManager*, sk_sp, - sk_sp, GrAuditTrail*, GrSingleOwner*); + GrTextureContext(GrRecordingContext*, sk_sp, sk_sp); SkDEBUGCODE(void validate() const override;) @@ -49,11 +48,11 @@ private: GrOpList* getOpList() override; - sk_sp fTextureProxy; + sk_sp fTextureProxy; // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'. - sk_sp fOpList; + sk_sp fOpList; typedef GrSurfaceContext INHERITED; }; diff --git a/src/gpu/effects/GrRRectBlurEffect.fp b/src/gpu/effects/GrRRectBlurEffect.fp index c21cd8bf2d..c5e1b8ae12 100644 --- a/src/gpu/effects/GrRRectBlurEffect.fp +++ b/src/gpu/effects/GrRRectBlurEffect.fp @@ -15,6 +15,7 @@ uniform half blurRadius; @header { #include "GrCaps.h" #include "GrClip.h" + #include "GrContext.h" #include "GrPaint.h" #include "GrProxyProvider.h" #include "GrRecordingContext.h" diff --git a/src/gpu/effects/GrRRectBlurEffect.h b/src/gpu/effects/GrRRectBlurEffect.h index dc1579687a..e4155c4e03 100644 --- a/src/gpu/effects/GrRRectBlurEffect.h +++ b/src/gpu/effects/GrRRectBlurEffect.h @@ -14,6 +14,7 @@ #include "GrCaps.h" #include "GrClip.h" +#include "GrContext.h" #include "GrPaint.h" #include "GrProxyProvider.h" #include "GrRecordingContext.h" diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index 2de8e6a42d..b8a743ff43 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -89,7 +89,7 @@ void GrRenderTargetContextPriv::testingOnly_addDrawOp( return; } SkDEBUGCODE(fRenderTargetContext->validate()); - GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, + GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->auditTrail(), "GrRenderTargetContext::testingOnly_addDrawOp"); fRenderTargetContext->addDrawOp(clip, std::move(op), willAddFn); }