#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<uint32_t>(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() {
#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");
}
*/
virtual GrRenderTargetOpList* asRenderTargetOpList() { return nullptr; }
+ int32_t uniqueID() const { return fUniqueID; }
+
/*
* Dump out the GrOpList dependency DAG
*/
private:
friend class GrDrawingManager; // for resetFlag & TopoSortTraits
+ static uint32_t CreateUniqueID();
+
enum Flags {
kClosed_Flag = 0x01, //!< This GrOpList can't accept any more ops
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<GrOpList*> fDependencies;
+ SkTDArray<GrOpList*> fDependencies;
protected:
- GrAuditTrail* fAuditTrail;
+ GrAuditTrail* fAuditTrail;
typedef SkRefCnt INHERITED;
};
}
}
-void GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder, const GrClip& clip,
- std::unique_ptr<GrDrawOp> op) {
+uint32_t GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder,
+ const GrClip& clip,
+ std::unique_ptr<GrDrawOp> 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");
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;
}
}
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,
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<GrDrawOp>);
+ // 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<GrDrawOp>);
// 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
return fRenderTargetContext->fRenderTargetProxy->uniqueID();
}
- void testingOnly_addDrawOp(GrPaint&&,
- GrAAType,
- std::unique_ptr<GrDrawOp>,
- const GrUserStencilSettings* = nullptr,
- bool snapToCenters = false);
+ uint32_t testingOnly_addDrawOp(GrPaint&&,
+ GrAAType,
+ std::unique_ptr<GrDrawOp>,
+ const GrUserStencilSettings* = nullptr,
+ bool snapToCenters = false);
bool refsWrappedObjects() const {
return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects();
*/
const GrCaps* caps() const { return fGpu->caps(); }
- void addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
+ uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
this->recordOp(std::move(op), renderTargetContext);
+ return this->uniqueID();
}
/** Clears the entire render target */
#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<GrDrawOp> op,
- const GrUserStencilSettings* uss,
- bool snapToCenters) {
+uint32_t GrRenderTargetContextPriv::testingOnly_addDrawOp(GrPaint&& paint,
+ GrAAType aaType,
+ std::unique_ptr<GrDrawOp> 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");
}
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
///////////////////////////////////////////////////////////////////////////////