Don't purge resources for trivial GrContext flushes
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2298003003 Review-Url: https://codereview.chromium.org/2298003003
This commit is contained in:
parent
bcdc405ea0
commit
dc43898bbb
@ -228,13 +228,15 @@ void GrContext::TextBlobCacheOverBudgetCB(void* data) {
|
||||
void GrContext::flush(int flagsBitfield) {
|
||||
ASSERT_SINGLE_OWNER
|
||||
RETURN_IF_ABANDONED
|
||||
|
||||
bool flushed = false;
|
||||
if (kDiscard_FlushBit & flagsBitfield) {
|
||||
fDrawingManager->reset();
|
||||
} else {
|
||||
fDrawingManager->flush();
|
||||
flushed = fDrawingManager->flush();
|
||||
}
|
||||
if (flushed) {
|
||||
fResourceCache->notifyFlushOccurred();
|
||||
}
|
||||
fResourceCache->notifyFlushOccurred();
|
||||
fFlushToReduceCacheSize = false;
|
||||
}
|
||||
|
||||
|
@ -221,9 +221,9 @@ void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) {
|
||||
}
|
||||
}
|
||||
|
||||
void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) {
|
||||
bool GrDrawTarget::drawBatches(GrBatchFlushState* flushState) {
|
||||
if (0 == fRecordedBatches.count()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// Draw all the generated geometry.
|
||||
SkRandom random;
|
||||
@ -286,6 +286,7 @@ void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) {
|
||||
}
|
||||
|
||||
fGpu->finishDrawTarget();
|
||||
return true;
|
||||
}
|
||||
|
||||
void GrDrawTarget::reset() {
|
||||
|
@ -96,10 +96,11 @@ public:
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Together these two functions flush all queued up draws to the Gpu.
|
||||
* Together these two functions flush all queued up draws to GrCommandBuffer. The return value
|
||||
* of drawBatches() indicates whether any commands were actually issued to the GPU.
|
||||
*/
|
||||
void prepareBatches(GrBatchFlushState* flushState);
|
||||
void drawBatches(GrBatchFlushState* flushState);
|
||||
bool drawBatches(GrBatchFlushState* flushState);
|
||||
|
||||
/**
|
||||
* Gets the capabilities of the draw target.
|
||||
|
@ -74,12 +74,12 @@ void GrDrawingManager::reset() {
|
||||
fFlushState.reset();
|
||||
}
|
||||
|
||||
void GrDrawingManager::flush() {
|
||||
bool GrDrawingManager::flush() {
|
||||
if (fFlushing || this->wasAbandoned()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
fFlushing = true;
|
||||
|
||||
bool flushed = false;
|
||||
SkDEBUGCODE(bool result =)
|
||||
SkTTopoSort<GrDrawTarget, GrDrawTarget::TopoSortTraits>(&fDrawTargets);
|
||||
SkASSERT(result);
|
||||
@ -99,7 +99,9 @@ void GrDrawingManager::flush() {
|
||||
fFlushState.preIssueDraws();
|
||||
|
||||
for (int i = 0; i < fDrawTargets.count(); ++i) {
|
||||
fDrawTargets[i]->drawBatches(&fFlushState);
|
||||
if (fDrawTargets[i]->drawBatches(&fFlushState)) {
|
||||
flushed = true;
|
||||
}
|
||||
}
|
||||
|
||||
SkASSERT(fFlushState.nextDrawToken() == fFlushState.nextTokenToFlush());
|
||||
@ -125,6 +127,7 @@ void GrDrawingManager::flush() {
|
||||
|
||||
fFlushState.reset();
|
||||
fFlushing = false;
|
||||
return flushed;
|
||||
}
|
||||
|
||||
GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) {
|
||||
|
@ -68,7 +68,8 @@ private:
|
||||
void abandon();
|
||||
void cleanup();
|
||||
void reset();
|
||||
void flush();
|
||||
/** Returns true if there was anything to flush and false otherwise */
|
||||
bool flush();
|
||||
|
||||
friend class GrContext; // for access to: ctor, abandon, reset & flush
|
||||
|
||||
|
@ -1195,6 +1195,22 @@ static void test_flush(skiatest::Reporter* reporter) {
|
||||
}
|
||||
|
||||
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
||||
|
||||
// Verify that calling flush() on a GrContext with nothing to do will not trigger resource
|
||||
// eviction.
|
||||
context->flush();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
TestResource* r = new TestResource(context->getGpu());
|
||||
GrUniqueKey k;
|
||||
make_unique_key<1>(&k, i);
|
||||
r->resourcePriv().setUniqueKey(k);
|
||||
r->unref();
|
||||
}
|
||||
REPORTER_ASSERT(reporter, 10 == cache->getResourceCount());
|
||||
for (int i = 0; i < 10 * kFlushCount; ++i) {
|
||||
context->flush();
|
||||
}
|
||||
REPORTER_ASSERT(reporter, 10 == cache->getResourceCount());
|
||||
}
|
||||
|
||||
static void test_large_resource_count(skiatest::Reporter* reporter) {
|
||||
|
Loading…
Reference in New Issue
Block a user