diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index b64b9ee23a..cecf52f329 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -197,7 +197,7 @@ void GrDrawingManager::addPreFlushCallbackObject(sk_sp fPreFlushCBObjects.push_back(preFlushCBObject); } -GrRenderTargetOpList* GrDrawingManager::newOpList(GrRenderTargetProxy* rtp) { +sk_sp GrDrawingManager::newRTOpList(sk_sp rtp) { SkASSERT(fContext); #ifndef ENABLE_MDB @@ -210,7 +210,7 @@ GrRenderTargetOpList* GrDrawingManager::newOpList(GrRenderTargetProxy* rtp) { // DrawingManager gets the creation ref - this ref is for the caller // TODO: although this is true right now it isn't cool - return SkRef((GrRenderTargetOpList*) fOpLists[0]); + return sk_ref_sp((GrRenderTargetOpList*) fOpLists[0]); } #endif @@ -219,18 +219,19 @@ GrRenderTargetOpList* GrDrawingManager::newOpList(GrRenderTargetProxy* rtp) { fContext->resourceProvider(), fContext->getAuditTrail(), fOptionsForOpLists); + SkASSERT(rtp->getLastOpList() == opList); *fOpLists.append() = opList; // DrawingManager gets the creation ref - this ref is for the caller - return SkRef(opList); + return sk_ref_sp(opList); } -GrTextureOpList* GrDrawingManager::newOpList(GrTextureProxy* textureProxy) { +sk_sp GrDrawingManager::newTextureOpList(sk_sp textureProxy) { SkASSERT(fContext); - GrTextureOpList* opList = new GrTextureOpList(textureProxy, fContext->getGpu(), - fContext->getAuditTrail()); + sk_sp opList(new GrTextureOpList(std::move(textureProxy), fContext->getGpu(), + fContext->getAuditTrail())); #ifndef ENABLE_MDB // When MDB is disabled we still create a new GrOpList, but don't store or ref it - we rely @@ -240,7 +241,7 @@ GrTextureOpList* GrDrawingManager::newOpList(GrTextureProxy* textureProxy) { *fOpLists.append() = opList; // Drawing manager gets the creation ref - this ref is for the caller - return SkRef(opList); + return opList; #endif } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index f30273f7f1..ac6bbb45f2 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -44,8 +44,8 @@ public: // The caller automatically gets a ref on the returned opList. It must // be balanced by an unref call. - GrRenderTargetOpList* newOpList(GrRenderTargetProxy* rtp); - GrTextureOpList* newOpList(GrTextureProxy* textureProxy); + sk_sp newRTOpList(sk_sp rtp); + sk_sp newTextureOpList(sk_sp textureProxy); GrContext* getContext() { return fContext; } diff --git a/src/gpu/GrOpList.cpp b/src/gpu/GrOpList.cpp index 1f90f431a5..28b972df99 100644 --- a/src/gpu/GrOpList.cpp +++ b/src/gpu/GrOpList.cpp @@ -21,12 +21,13 @@ uint32_t GrOpList::CreateUniqueID() { return id; } -GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail) - : fUniqueID(CreateUniqueID()) - , fFlags(0) - , fTarget(surfaceProxy) - , fAuditTrail(auditTrail) { - +GrOpList::GrOpList(sk_sp surfaceProxy, GrAuditTrail* auditTrail) + // MDB TODO: in the future opLists will own the GrSurfaceProxy they target. + // For now, preserve the status quo. + : fTarget(surfaceProxy.get()) + , fAuditTrail(auditTrail) + , fUniqueID(CreateUniqueID()) + , fFlags(0) { surfaceProxy->setLastOpList(this); } diff --git a/src/gpu/GrOpList.h b/src/gpu/GrOpList.h index 557126681a..0139b6b4d3 100644 --- a/src/gpu/GrOpList.h +++ b/src/gpu/GrOpList.h @@ -22,7 +22,7 @@ class GrTextureOpList; class GrOpList : public SkRefCnt { public: - GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail); + GrOpList(sk_sp surfaceProxy, GrAuditTrail* auditTrail); ~GrOpList() override; // These two methods are invoked as flush time @@ -80,6 +80,10 @@ public: */ SkDEBUGCODE(virtual void dump() const;) +protected: + GrSurfaceProxy* fTarget; + GrAuditTrail* fAuditTrail; + private: friend class GrDrawingManager; // for resetFlag & TopoSortTraits @@ -132,14 +136,10 @@ private: uint32_t fUniqueID; uint32_t fFlags; - GrSurfaceProxy* fTarget; // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies' SkTDArray fDependencies; -protected: - GrAuditTrail* fAuditTrail; - typedef SkRefCnt INHERITED; }; diff --git a/src/gpu/GrPreFlushResourceProvider.cpp b/src/gpu/GrPreFlushResourceProvider.cpp index 7a105604e0..3c6ddc4ab7 100644 --- a/src/gpu/GrPreFlushResourceProvider.cpp +++ b/src/gpu/GrPreFlushResourceProvider.cpp @@ -30,8 +30,10 @@ sk_sp GrPreFlushResourceProvider::makeRenderTargetContext return nullptr; } + // MDB TODO: This explicit resource creation is required in the pre-MDB world so that the + // pre-Flush ops are placed in their own opList. sk_sp opList(new GrRenderTargetOpList( - proxy->asRenderTargetProxy(), + sk_ref_sp(proxy->asRenderTargetProxy()), fDrawingMgr->fContext->getGpu(), fDrawingMgr->fContext->resourceProvider(), fDrawingMgr->fContext->getAuditTrail(), @@ -58,9 +60,10 @@ sk_sp GrPreFlushResourceProvider::makeRenderTargetContext sk_sp proxy, sk_sp colorSpace, const SkSurfaceProps* props) { - + // MDB TODO: This explicit resource creation is required in the pre-MDB world so that the + // pre-Flush ops are placed in their own opList. sk_sp opList(new GrRenderTargetOpList( - proxy->asRenderTargetProxy(), + sk_ref_sp(proxy->asRenderTargetProxy()), fDrawingMgr->fContext->getGpu(), fDrawingMgr->fContext->resourceProvider(), fDrawingMgr->fContext->getAuditTrail(), diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 40ccbeaa21..8ad9a4e633 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -82,7 +82,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrContext* context, GrSingleOwner* singleOwner) : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner) , fRenderTargetProxy(std::move(rtp)) - , fOpList(SkSafeRef(fRenderTargetProxy->getLastRenderTargetOpList())) + , fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList())) , fInstancedPipelineInfo(fRenderTargetProxy.get()) , fColorXformFromSRGB(nullptr) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { @@ -100,14 +100,13 @@ void GrRenderTargetContext::validate() const { fRenderTargetProxy->validate(fContext); if (fOpList && !fOpList->isClosed()) { - SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList); + SkASSERT(fRenderTargetProxy->getLastOpList() == fOpList.get()); } } #endif GrRenderTargetContext::~GrRenderTargetContext() { ASSERT_SINGLE_OWNER - SkSafeUnref(fOpList); } GrTextureProxy* GrRenderTargetContext::asTextureProxy() { @@ -123,10 +122,10 @@ GrRenderTargetOpList* GrRenderTargetContext::getOpList() { SkDEBUGCODE(this->validate();) if (!fOpList || fOpList->isClosed()) { - fOpList = this->drawingManager()->newOpList(fRenderTargetProxy.get()); + fOpList = this->drawingManager()->newRTOpList(fRenderTargetProxy); } - return fOpList; + return fOpList.get(); } // TODO: move this (and GrTextContext::copy) to GrSurfaceContext? diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index 1d1f9ecd18..dd42db6156 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -479,7 +479,7 @@ private: // 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'. - GrRenderTargetOpList* fOpList; + sk_sp fOpList; GrInstancedPipelineInfo fInstancedPipelineInfo; sk_sp fColorXformFromSRGB; diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index 3d38c99eb8..5730e2e7ad 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -25,16 +25,15 @@ using gr_instanced::InstancedRendering; static const int kDefaultMaxOpLookback = 10; static const int kDefaultMaxOpLookahead = 10; -GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu, +GrRenderTargetOpList::GrRenderTargetOpList(sk_sp proxy, GrGpu* gpu, GrResourceProvider* resourceProvider, GrAuditTrail* auditTrail, const Options& options) - : INHERITED(rtp, auditTrail) + : INHERITED(std::move(proxy), auditTrail) , fGpu(SkRef(gpu)) , fResourceProvider(resourceProvider) , fLastClipStackGenID(SK_InvalidUniqueID) , fClipAllocator(fClipAllocatorStorage, sizeof(fClipAllocatorStorage), sizeof(fClipAllocatorStorage)) { - fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback : options.fMaxOpCombineLookback; fMaxOpLookahead = (options.fMaxOpCombineLookahead < 0) ? kDefaultMaxOpLookahead diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h index cd08559a77..1b6f0865b0 100644 --- a/src/gpu/GrRenderTargetOpList.h +++ b/src/gpu/GrRenderTargetOpList.h @@ -39,7 +39,7 @@ public: int fMaxOpCombineLookahead = -1; }; - GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrResourceProvider*, + GrRenderTargetOpList(sk_sp, GrGpu*, GrResourceProvider*, GrAuditTrail*, const Options&); ~GrRenderTargetOpList() override; diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp index 76b7588e39..68e94f9be3 100644 --- a/src/gpu/GrTextureContext.cpp +++ b/src/gpu/GrTextureContext.cpp @@ -26,7 +26,7 @@ GrTextureContext::GrTextureContext(GrContext* context, GrSingleOwner* singleOwner) : GrSurfaceContext(context, drawingMgr, std::move(colorSpace), auditTrail, singleOwner) , fTextureProxy(std::move(textureProxy)) - , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList())) { + , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) { SkDEBUGCODE(this->validate();) } @@ -36,14 +36,13 @@ void GrTextureContext::validate() const { fTextureProxy->validate(fContext); if (fOpList && !fOpList->isClosed()) { - SkASSERT(fTextureProxy->getLastOpList() == fOpList); + SkASSERT(fTextureProxy->getLastOpList() == fOpList.get()); } } #endif GrTextureContext::~GrTextureContext() { ASSERT_SINGLE_OWNER - SkSafeUnref(fOpList); } GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() { @@ -63,10 +62,10 @@ GrTextureOpList* GrTextureContext::getOpList() { SkDEBUGCODE(this->validate();) if (!fOpList || fOpList->isClosed()) { - fOpList = this->drawingManager()->newOpList(fTextureProxy.get()); + fOpList = this->drawingManager()->newTextureOpList(fTextureProxy); } - return fOpList; + return fOpList.get(); } // TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext? diff --git a/src/gpu/GrTextureContext.h b/src/gpu/GrTextureContext.h index 995ebf53d2..4cde61b883 100644 --- a/src/gpu/GrTextureContext.h +++ b/src/gpu/GrTextureContext.h @@ -54,7 +54,7 @@ private: // 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'. - GrTextureOpList* fOpList; + sk_sp fOpList; typedef GrSurfaceContext INHERITED; }; diff --git a/src/gpu/GrTextureOpList.cpp b/src/gpu/GrTextureOpList.cpp index d2d922643a..d4becad579 100644 --- a/src/gpu/GrTextureOpList.cpp +++ b/src/gpu/GrTextureOpList.cpp @@ -15,8 +15,8 @@ //////////////////////////////////////////////////////////////////////////////// -GrTextureOpList::GrTextureOpList(GrTextureProxy* tex, GrGpu* gpu, GrAuditTrail* auditTrail) - : INHERITED(tex, auditTrail) +GrTextureOpList::GrTextureOpList(sk_sp proxy, GrGpu* gpu, GrAuditTrail* auditTrail) + : INHERITED(std::move(proxy), auditTrail) , fGpu(SkRef(gpu)) { } diff --git a/src/gpu/GrTextureOpList.h b/src/gpu/GrTextureOpList.h index 22828fd936..ca5bda44f6 100644 --- a/src/gpu/GrTextureOpList.h +++ b/src/gpu/GrTextureOpList.h @@ -23,7 +23,7 @@ struct SkIRect; class GrTextureOpList final : public GrOpList { public: - GrTextureOpList(GrTextureProxy*, GrGpu*, GrAuditTrail*); + GrTextureOpList(sk_sp, GrGpu*, GrAuditTrail*); ~GrTextureOpList() override;