Remove GrResourceProvider & GrGpu pointers from GrRenderTargetOpList

Additional shrinking of GrRenderTargetOpList since there will soon be more of them.

Change-Id: Ib3e68fdf3462838baf7a5a2644e418be066cf79c
Reviewed-on: https://skia-review.googlesource.com/14363
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-04-26 11:53:10 -04:00 committed by Skia Commit-Bot
parent deca5c3af6
commit ee683655a9
7 changed files with 32 additions and 44 deletions

View File

@ -25,7 +25,8 @@
void GrDrawingManager::cleanup() {
for (int i = 0; i < fOpLists.count(); ++i) {
fOpLists[i]->makeClosed(); // no opList should receive a new command after this
// no opList should receive a new command after this
fOpLists[i]->makeClosed(*fContext->caps());
fOpLists[i]->clearTarget();
// We shouldn't need to do this, but it turns out some clients still hold onto opLists
@ -91,7 +92,7 @@ void GrDrawingManager::internalFlush(GrSurfaceProxy*, GrResourceCache::FlushType
// needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed
// but need to be flushed anyway. Closing such GrOpLists here will mean new
// GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again.
fOpLists[i]->makeClosed();
fOpLists[i]->makeClosed(*fContext->caps());
}
#ifdef ENABLE_MDB
@ -223,7 +224,6 @@ sk_sp<GrRenderTargetOpList> GrDrawingManager::newRTOpList(sk_sp<GrRenderTargetPr
sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(rtp,
fContext->getGpu(),
fContext->resourceProvider(),
fContext->getAuditTrail()));
SkASSERT(rtp->getLastOpList() == opList.get());

View File

@ -48,7 +48,7 @@ void GrOpList::addDependency(GrOpList* dependedOn) {
}
// Convert from a GrSurface-based dependency to a GrOpList one
void GrOpList::addDependency(GrSurfaceProxy* dependedOn) {
void GrOpList::addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps) {
if (dependedOn->getLastOpList()) {
// If it is still receiving dependencies, this GrOpList shouldn't be closed
SkASSERT(!this->isClosed());
@ -60,7 +60,7 @@ void GrOpList::addDependency(GrSurfaceProxy* dependedOn) {
this->addDependency(opList);
// Can't make it closed in the self-read case
opList->makeClosed();
opList->makeClosed(caps);
}
}
}

View File

@ -14,6 +14,7 @@
//#define ENABLE_MDB 1
class GrAuditTrail;
class GrCaps;
class GrOpFlushState;
class GrRenderTargetOpList;
class GrSurfaceProxy;
@ -28,7 +29,7 @@ public:
virtual void prepareOps(GrOpFlushState* flushState) = 0;
virtual bool executeOps(GrOpFlushState* flushState) = 0;
virtual void makeClosed() {
virtual void makeClosed(const GrCaps&) {
// We only close GrOpLists when MDB is enabled. When MDB is disabled there is only
// ever one GrOpLists and all calls will be funnelled into it.
#ifdef ENABLE_MDB
@ -53,7 +54,7 @@ public:
/*
* Notify this GrOpList that it relies on the contents of 'dependedOn'
*/
void addDependency(GrSurfaceProxy* dependedOn);
void addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps);
/*
* Does this opList depend on 'dependedOn'?

View File

@ -35,7 +35,6 @@ sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext
sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
sk_ref_sp(proxy->asRenderTargetProxy()),
fDrawingMgr->fContext->getGpu(),
fDrawingMgr->fContext->resourceProvider(),
fDrawingMgr->fContext->getAuditTrail()));
proxy->setLastOpList(opList.get());
@ -64,7 +63,6 @@ sk_sp<GrRenderTargetContext> GrPreFlushResourceProvider::makeRenderTargetContext
sk_sp<GrRenderTargetOpList> opList(new GrRenderTargetOpList(
sk_ref_sp(proxy->asRenderTargetProxy()),
fDrawingMgr->fContext->getGpu(),
fDrawingMgr->fContext->resourceProvider(),
fDrawingMgr->fContext->getAuditTrail()));
proxy->setLastOpList(opList.get());

View File

@ -26,21 +26,17 @@ static const int kMaxOpLookback = 10;
static const int kMaxOpLookahead = 10;
GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrRenderTargetProxy> proxy, GrGpu* gpu,
GrResourceProvider* resourceProvider,
GrAuditTrail* auditTrail)
: INHERITED(std::move(proxy), auditTrail)
, fGpu(SkRef(gpu))
, fResourceProvider(resourceProvider)
, fLastClipStackGenID(SK_InvalidUniqueID)
, fClipAllocator(fClipAllocatorStorage, sizeof(fClipAllocatorStorage),
sizeof(fClipAllocatorStorage)) {
if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
fInstancedRendering.reset(fGpu->createInstancedRendering());
if (GrCaps::InstancedSupport::kNone != gpu->caps()->instancedSupport()) {
fInstancedRendering.reset(gpu->createInstancedRendering());
}
}
GrRenderTargetOpList::~GrRenderTargetOpList() {
fGpu->unref();
}
////////////////////////////////////////////////////////////////////////////////
@ -161,10 +157,10 @@ bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) {
finish_command_buffer(commandBuffer.get());
currentRenderTarget = fRecordedOps[i].fRenderTarget.get();
commandBuffer = create_command_buffer(fGpu);
commandBuffer = create_command_buffer(flushState->gpu());
flushState->setCommandBuffer(commandBuffer.get());
} else if (!commandBuffer) {
commandBuffer = create_command_buffer(fGpu);
commandBuffer = create_command_buffer(flushState->gpu());
flushState->setCommandBuffer(commandBuffer.get());
}
@ -182,7 +178,7 @@ bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) {
finish_command_buffer(commandBuffer.get());
flushState->setCommandBuffer(nullptr);
fGpu->finishOpList();
flushState->gpu()->finishOpList();
return true;
}
@ -197,16 +193,14 @@ void GrRenderTargetOpList::reset() {
}
void GrRenderTargetOpList::abandonGpuResources() {
if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
InstancedRendering* ir = this->instancedRendering();
ir->resetGpuResources(InstancedRendering::ResetType::kAbandon);
if (fInstancedRendering) {
fInstancedRendering->resetGpuResources(InstancedRendering::ResetType::kAbandon);
}
}
void GrRenderTargetOpList::freeGpuResources() {
if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
InstancedRendering* ir = this->instancedRendering();
ir->resetGpuResources(InstancedRendering::ResetType::kDestroy);
if (fInstancedRendering) {
fInstancedRendering->resetGpuResources(InstancedRendering::ResetType::kDestroy);
}
}
@ -278,7 +272,8 @@ static inline bool can_reorder(const SkRect& a, const SkRect& b) {
bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b,
const GrAppliedClip* bClip,
const DstTexture* bDstTexture) {
const DstTexture* bDstTexture,
const GrCaps& caps) {
if (a.fAppliedClip) {
if (!bClip) {
return false;
@ -296,7 +291,7 @@ bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b,
} else if (a.fDstTexture.texture()) {
return false;
}
return a.fOp->combineIfPossible(b, *this->caps());
return a.fOp->combineIfPossible(b, caps);
}
GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
@ -309,6 +304,8 @@ GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
return nullptr;
}
const GrCaps* caps = renderTargetContext->caps();
// A closed GrOpList should never receive new/more ops
SkASSERT(!this->isClosed());
@ -340,7 +337,7 @@ GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
candidate.fOp->uniqueID());
break;
}
if (this->combineIfPossible(candidate, op.get(), clip, dstTexture)) {
if (this->combineIfPossible(candidate, op.get(), clip, dstTexture, *caps)) {
GrOP_INFO("\t\tBackward: Combining with (%s, opID: %u)\n", candidate.fOp->name(),
candidate.fOp->uniqueID());
GrOP_INFO("\t\t\tBackward: Combined op info:\n");
@ -375,7 +372,7 @@ GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
return fRecordedOps.back().fOp.get();
}
void GrRenderTargetOpList::forwardCombine() {
void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) {
SkASSERT(!this->isClosed());
for (int i = 0; i < fRecordedOps.count() - 1; ++i) {
@ -398,7 +395,7 @@ void GrRenderTargetOpList::forwardCombine() {
break;
}
if (this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(),
candidate.fAppliedClip, &candidate.fDstTexture)) {
candidate.fAppliedClip, &candidate.fDstTexture, caps)) {
GrOP_INFO("\t\tForward: Combining with (%s, opID: %u)\n", candidate.fOp->name(),
candidate.fOp->uniqueID());
GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get());

View File

@ -33,19 +33,19 @@ private:
using DstTexture = GrXferProcessor::DstTexture;
public:
GrRenderTargetOpList(sk_sp<GrRenderTargetProxy>, GrGpu*, GrResourceProvider*, GrAuditTrail*);
GrRenderTargetOpList(sk_sp<GrRenderTargetProxy>, GrGpu*, GrAuditTrail*);
~GrRenderTargetOpList() override;
void makeClosed() override {
void makeClosed(const GrCaps& caps) override {
if (this->isClosed()) {
return;
}
fLastFullClearOp = nullptr;
this->forwardCombine();
this->forwardCombine(caps);
INHERITED::makeClosed();
INHERITED::makeClosed(caps);
}
bool isEmpty() const { return fRecordedOps.empty(); }
@ -65,11 +65,6 @@ public:
void prepareOps(GrOpFlushState* flushState) override;
bool executeOps(GrOpFlushState* flushState) override;
/**
* Gets the capabilities of the draw target.
*/
const GrCaps* caps() const { return fGpu->caps(); }
uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
this->recordOp(std::move(op), renderTargetContext, nullptr, nullptr);
return this->uniqueID();
@ -138,19 +133,16 @@ private:
GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr,
const DstTexture* = nullptr);
void forwardCombine();
void forwardCombine(const GrCaps&);
// If this returns true then b has been merged into a's op.
bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip,
const DstTexture* bDstTexture);
const DstTexture* bDstTexture, const GrCaps&);
GrClearOp* fLastFullClearOp = nullptr;
GrGpuResource::UniqueID fLastFullClearResourceID = GrGpuResource::UniqueID::InvalidID();
GrSurfaceProxy::UniqueID fLastFullClearProxyID = GrSurfaceProxy::UniqueID::InvalidID();
GrGpu* fGpu;
GrResourceProvider* fResourceProvider;
std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
int32_t fLastClipStackGenID;

View File

@ -163,7 +163,7 @@ void InstancedOp::wasRecorded(GrRenderTargetOpList* opList) {
fIsTracked = true;
}
bool InstancedOp::onCombineIfPossible(GrOp* other, const GrCaps& caps) {
bool InstancedOp::onCombineIfPossible(GrOp* other, const GrCaps&) {
InstancedOp* that = static_cast<InstancedOp*>(other);
SkASSERT(!that->fInstancedRendering || (fInstancedRendering == that->fInstancedRendering));
SkASSERT(fTailDraw);