diff --git a/src/gpu/GrOpList.cpp b/src/gpu/GrOpList.cpp index d354e59405..1f90f431a5 100644 --- a/src/gpu/GrOpList.cpp +++ b/src/gpu/GrOpList.cpp @@ -11,17 +11,23 @@ #include "GrSurface.h" #include "GrSurfaceProxy.h" -GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail) - : fFlags(0) +uint32_t GrOpList::CreateUniqueID() { + static int32_t gUniqueID = SK_InvalidUniqueID; + uint32_t id; + // Loop in case our global wraps around, as we never want to return a 0. + do { + id = static_cast(sk_atomic_inc(&gUniqueID) + 1); + } while (id == SK_InvalidUniqueID); + return id; +} + +GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail) + : fUniqueID(CreateUniqueID()) + , fFlags(0) , fTarget(surfaceProxy) , fAuditTrail(auditTrail) { surfaceProxy->setLastOpList(this); - -#ifdef SK_DEBUG - static int debugID = 0; - fDebugID = debugID++; -#endif } GrOpList::~GrOpList() { @@ -62,10 +68,10 @@ void GrOpList::addDependency(GrSurface* dependedOn) { #ifdef SK_DEBUG void GrOpList::dump() const { SkDebugf("--------------------------------------------------------------\n"); - SkDebugf("node: %d -> RT: %d\n", fDebugID, fTarget ? fTarget->uniqueID().asUInt() : -1); + SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget ? fTarget->uniqueID().asUInt() : -1); SkDebugf("relies On (%d): ", fDependencies.count()); for (int i = 0; i < fDependencies.count(); ++i) { - SkDebugf("%d, ", fDependencies[i]->fDebugID); + SkDebugf("%d, ", fDependencies[i]->fUniqueID); } SkDebugf("\n"); } diff --git a/src/gpu/GrOpList.h b/src/gpu/GrOpList.h index 75fc5e63d1..557126681a 100644 --- a/src/gpu/GrOpList.h +++ b/src/gpu/GrOpList.h @@ -73,6 +73,8 @@ public: */ virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; } + int32_t uniqueID() const { return fUniqueID; } + /* * Dump out the GrOpList dependency DAG */ @@ -81,6 +83,8 @@ public: private: friend class GrDrawingManager; // for resetFlag & TopoSortTraits + static uint32_t CreateUniqueID(); + enum Flags { kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops @@ -126,15 +130,15 @@ private: void addDependency(GrOpList* dependedOn); - SkDEBUGCODE(int fDebugID;) - uint32_t fFlags; - GrSurfaceProxy* fTarget; + uint32_t fUniqueID; + uint32_t fFlags; + GrSurfaceProxy* fTarget; // 'this' GrOpList relies on the output of the GrOpLists in 'fDependencies' - SkTDArray fDependencies; + SkTDArray fDependencies; protected: - GrAuditTrail* fAuditTrail; + GrAuditTrail* fAuditTrail; typedef SkRefCnt INHERITED; }; diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index bae2ea6307..1d891df6b0 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -1673,10 +1673,13 @@ static void op_bounds(SkRect* bounds, const GrOp* op) { } } -void GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder, const GrClip& clip, - std::unique_ptr op) { +uint32_t GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder, + const GrClip& clip, + std::unique_ptr op) { ASSERT_SINGLE_OWNER - RETURN_IF_ABANDONED + if (this->drawingManager()->wasAbandoned()) { + return SK_InvalidUniqueID; + } SkDEBUGCODE(this->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::addDrawOp"); @@ -1686,21 +1689,21 @@ void GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder, GrAppliedClip appliedClip(bounds); if (!clip.apply(fContext, this, pipelineBuilder.isHWAntialias(), pipelineBuilder.hasUserStencilSettings(), &appliedClip)) { - return; + return SK_InvalidUniqueID; } // This forces instantiation of the render target. Pipeline creation is moving to flush time // by which point instantiation must have occurred anyway. GrRenderTarget* rt = this->accessRenderTarget(); if (!rt) { - return; + return SK_InvalidUniqueID; } GrResourceProvider* resourceProvider = fContext->resourceProvider(); if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) { if (!resourceProvider->attachStencilAttachment(this->accessRenderTarget())) { SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); - return; + return SK_InvalidUniqueID; } } @@ -1717,13 +1720,13 @@ void GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder, if (pipelineBuilder.willXPNeedDstTexture(*this->caps(), analysis)) { this->setupDstTexture(rt, clip, bounds, &args.fDstTexture); if (!args.fDstTexture.texture()) { - return; + return SK_InvalidUniqueID; } } op->initPipeline(args); // TODO: We need to add pipeline dependencies on textures, etc before recording this op. op->setClippedBounds(appliedClip.clippedDrawBounds()); - this->getOpList()->addOp(std::move(op), this); + return this->getOpList()->addOp(std::move(op), this); } void GrRenderTargetContext::setupDstTexture(GrRenderTarget* rt, const GrClip& clip, diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index d711c81456..1126c76aa2 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -473,8 +473,9 @@ private: size_t srcRowBytes, int x, int y, uint32_t flags) override; // This performs processing specific to GrDrawOp-derived ops before recording them into the - // op list. - void addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr); + // op list. It returns the id of the opList to which the op was added, or 0, if it was + // dropped (e.g., due to clipping). + uint32_t addDrawOp(const GrPipelineBuilder&, const GrClip&, std::unique_ptr); // Makes a copy of the dst if it is necessary for the draw and returns the texture that should // be used by GrXferProcessor to access the destination color. If the texture is nullptr then diff --git a/src/gpu/GrRenderTargetContextPriv.h b/src/gpu/GrRenderTargetContextPriv.h index 8a1061c0d0..842e23c066 100644 --- a/src/gpu/GrRenderTargetContextPriv.h +++ b/src/gpu/GrRenderTargetContextPriv.h @@ -108,11 +108,11 @@ public: return fRenderTargetContext->fRenderTargetProxy->uniqueID(); } - void testingOnly_addDrawOp(GrPaint&&, - GrAAType, - std::unique_ptr, - const GrUserStencilSettings* = nullptr, - bool snapToCenters = false); + uint32_t testingOnly_addDrawOp(GrPaint&&, + GrAAType, + std::unique_ptr, + const GrUserStencilSettings* = nullptr, + bool snapToCenters = false); bool refsWrappedObjects() const { return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects(); diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h index e232547f70..3929c5cb5a 100644 --- a/src/gpu/GrRenderTargetOpList.h +++ b/src/gpu/GrRenderTargetOpList.h @@ -67,8 +67,9 @@ public: */ const GrCaps* caps() const { return fGpu->caps(); } - void addOp(std::unique_ptr op, GrRenderTargetContext* renderTargetContext) { + uint32_t addOp(std::unique_ptr op, GrRenderTargetContext* renderTargetContext) { this->recordOp(std::move(op), renderTargetContext); + return this->uniqueID(); } /** Clears the entire render target */ diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index 55529d85e1..7e27583bd9 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -233,15 +233,16 @@ int GrResourceCache::countUniqueKeysWithTag(const char* tag) const { #define ASSERT_SINGLE_OWNER \ SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fRenderTargetContext->fSingleOwner);) -#define RETURN_IF_ABANDONED if (fRenderTargetContext->drawingManager()->wasAbandoned()) { return; } -void GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint, - GrAAType aaType, - std::unique_ptr op, - const GrUserStencilSettings* uss, - bool snapToCenters) { +uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint, + GrAAType aaType, + std::unique_ptr op, + const GrUserStencilSettings* uss, + bool snapToCenters) { ASSERT_SINGLE_OWNER - RETURN_IF_ABANDONED + if (fRenderTargetContext->drawingManager()->wasAbandoned()) { + return SK_InvalidUniqueID; + } SkDEBUGCODE(fRenderTargetContext->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(fRenderTargetContext->fAuditTrail, "GrRenderTargetContext::testingOnly_addDrawOp"); @@ -252,11 +253,10 @@ void GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint, } pipelineBuilder.setSnapVerticesToPixelCenters(snapToCenters); - fRenderTargetContext->addDrawOp(pipelineBuilder, GrNoClip(), std::move(op)); + return fRenderTargetContext->addDrawOp(pipelineBuilder, GrNoClip(), std::move(op)); } #undef ASSERT_SINGLE_OWNER -#undef RETURN_IF_ABANDONED ///////////////////////////////////////////////////////////////////////////////