Index: src/gpu/GrContext.cpp |
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp |
index 3a93404af17832b421c94bc3f8df1ed08cb81a73..9a180ee6539ec487cb64191630c303994504f650 100755 |
--- a/src/gpu/GrContext.cpp |
+++ b/src/gpu/GrContext.cpp |
@@ -25,7 +25,6 @@ |
#include "GrOvalRenderer.h" |
#include "GrPathRenderer.h" |
#include "GrPathUtils.h" |
-#include "GrResourceCache.h" |
#include "GrResourceCache2.h" |
#include "GrSoftwarePathRenderer.h" |
#include "GrStencilBuffer.h" |
@@ -52,9 +51,6 @@ |
#define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
#endif |
-static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT; |
-static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT * 1024 * 1024; |
- |
static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
@@ -66,20 +62,6 @@ static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
// Glorified typedef to avoid including GrDrawState.h in GrContext.h |
class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; |
-class GrContext::AutoCheckFlush { |
-public: |
- AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } |
- |
- ~AutoCheckFlush() { |
- if (fContext->fFlushToReduceCacheSize) { |
- fContext->flush(); |
- } |
- } |
- |
-private: |
- GrContext* fContext; |
-}; |
- |
GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
const Options* opts) { |
GrContext* context; |
@@ -103,13 +85,11 @@ GrContext::GrContext(const Options& opts) : fOptions(opts) { |
fClip = NULL; |
fPathRendererChain = NULL; |
fSoftwarePathRenderer = NULL; |
- fResourceCache = NULL; |
fResourceCache2 = NULL; |
fFontCache = NULL; |
fDrawBuffer = NULL; |
fDrawBufferVBAllocPool = NULL; |
fDrawBufferIBAllocPool = NULL; |
- fFlushToReduceCacheSize = false; |
fAARectRenderer = NULL; |
fOvalRenderer = NULL; |
fViewMatrix.reset(); |
@@ -130,11 +110,8 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
void GrContext::initCommon() { |
fDrawState = SkNEW(GrDrawState); |
- fResourceCache = SkNEW_ARGS(GrResourceCache, (fGpu->caps(), |
- MAX_RESOURCE_CACHE_COUNT, |
- MAX_RESOURCE_CACHE_BYTES)); |
- fResourceCache->setOverbudgetCallback(OverbudgetCB, this); |
fResourceCache2 = SkNEW(GrResourceCache2); |
+ fResourceCache2->setOverBudgetCallback(OverBudgetCB, this); |
fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
@@ -160,9 +137,6 @@ GrContext::~GrContext() { |
} |
SkDELETE(fResourceCache2); |
- fResourceCache2 = NULL; |
- SkDELETE(fResourceCache); |
- fResourceCache = NULL; |
SkDELETE(fFontCache); |
SkDELETE(fDrawBuffer); |
SkDELETE(fDrawBufferVBAllocPool); |
@@ -201,8 +175,6 @@ void GrContext::abandonContext() { |
fAARectRenderer->reset(); |
fOvalRenderer->reset(); |
- fResourceCache->purgeAllUnlocked(); |
- |
fFontCache->freeAll(); |
fLayerCache->freeAll(); |
} |
@@ -221,7 +193,6 @@ void GrContext::freeGpuResources() { |
fAARectRenderer->reset(); |
fOvalRenderer->reset(); |
- fResourceCache->purgeAllUnlocked(); |
fFontCache->freeAll(); |
fLayerCache->freeAll(); |
// a path renderer may be holding onto resources |
@@ -230,12 +201,12 @@ void GrContext::freeGpuResources() { |
} |
void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
- if (resourceCount) { |
- *resourceCount = fResourceCache->getCachedResourceCount(); |
- } |
- if (resourceBytes) { |
- *resourceBytes = fResourceCache->getCachedResourceBytes(); |
- } |
+ if (resourceCount) { |
+ *resourceCount = fResourceCache2->getResourceCount(); |
+ } |
+ if (resourceBytes) { |
+ *resourceBytes = fResourceCache2->getResourceBytes(); |
+ } |
} |
GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
@@ -273,12 +244,13 @@ bool GrContext::isTextureInCache(const GrSurfaceDesc& desc, |
} |
void GrContext::addStencilBuffer(GrStencilBuffer* sb) { |
+ // TODO: Make GrStencilBuffers use the scratch mechanism rather than content keys. |
ASSERT_OWNED_RESOURCE(sb); |
GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), |
sb->height(), |
sb->numSamples()); |
- fResourceCache->addResource(resourceKey, sb); |
+ SkAssertResult(sb->cacheAccess().setContentKey(resourceKey)); |
} |
GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int sampleCnt) { |
@@ -420,25 +392,19 @@ GrTexture* GrContext::createTexture(const GrTextureParams* params, |
} |
if (texture) { |
- fResourceCache->addResource(resourceKey, texture); |
- |
- if (cacheKey) { |
- *cacheKey = resourceKey; |
+ if (texture->cacheAccess().setContentKey(resourceKey)) { |
+ if (cacheKey) { |
+ *cacheKey = resourceKey; |
+ } |
+ } else { |
+ texture->unref(); |
+ texture = NULL; |
} |
} |
return texture; |
} |
-GrTexture* GrContext::createNewScratchTexture(const GrSurfaceDesc& desc) { |
- GrTexture* texture = fGpu->createTexture(desc, NULL, 0); |
- if (!texture) { |
- return NULL; |
- } |
- fResourceCache->addResource(texture->cacheAccess().getScratchKey(), texture); |
- return texture; |
-} |
- |
GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexMatch match, |
bool calledDuringFlush) { |
// kNoStencil has no meaning if kRT isn't set. |
@@ -473,7 +439,6 @@ GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM |
} |
GrGpuResource* resource = fResourceCache2->findAndRefScratchResource(key, scratchFlags); |
if (resource) { |
- fResourceCache->makeResourceMRU(resource); |
return static_cast<GrSurface*>(resource)->asTexture(); |
} |
@@ -496,21 +461,17 @@ GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& inDesc, ScratchTexM |
desc.writable()->fFlags = origFlags; |
} |
- GrTexture* texture = this->createNewScratchTexture(*desc); |
+ GrTexture* texture = fGpu->createTexture(*desc, NULL, 0); |
SkASSERT(NULL == texture || |
texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScratchKey(*desc)); |
return texture; |
} |
-bool GrContext::OverbudgetCB(void* data) { |
+void GrContext::OverBudgetCB(void* data) { |
+ // Flush the InOrderDrawBuffer to possibly free up some textures |
SkASSERT(data); |
- |
GrContext* context = reinterpret_cast<GrContext*>(data); |
- |
- // Flush the InOrderDrawBuffer to possibly free up some textures |
- context->fFlushToReduceCacheSize = true; |
- |
- return true; |
+ context->flush(); |
} |
@@ -522,11 +483,16 @@ GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, |
} |
void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
- fResourceCache->getLimits(maxTextures, maxTextureBytes); |
+ if (maxTextures) { |
+ *maxTextures = fResourceCache2->getMaxResourceCount(); |
+ } |
+ if (maxTextureBytes) { |
+ *maxTextureBytes = fResourceCache2->getMaxResourceBytes(); |
+ } |
} |
void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
- fResourceCache->setLimits(maxTextures, maxTextureBytes); |
+ fResourceCache2->setLimits(maxTextures, maxTextureBytes); |
} |
int GrContext::getMaxTextureSize() const { |
@@ -582,9 +548,8 @@ void GrContext::clear(const SkIRect* rect, |
SkASSERT(renderTarget); |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
- GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(NULL, &are); |
if (NULL == target) { |
return; |
} |
@@ -716,8 +681,7 @@ void GrContext::drawRect(const GrPaint& paint, |
} |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -827,8 +791,7 @@ void GrContext::drawRectToRect(const GrPaint& paint, |
const SkRect& localRect, |
const SkMatrix* localMatrix) { |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -891,10 +854,9 @@ void GrContext::drawVertices(const GrPaint& paint, |
const uint16_t indices[], |
int indexCount) { |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scope |
+ GrDrawTarget::AutoReleaseGeometry geo; |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -954,8 +916,7 @@ void GrContext::drawRRect(const GrPaint& paint, |
} |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -981,8 +942,7 @@ void GrContext::drawDRRect(const GrPaint& paint, |
} |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
@@ -1014,8 +974,7 @@ void GrContext::drawOval(const GrPaint& paint, |
} |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -1102,8 +1061,7 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok |
SkPoint pts[2]; |
if (path.isLine(pts)) { |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -1139,8 +1097,7 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok |
// the writePixels that uploads to the scratch will perform a flush so we're |
// OK. |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(&paint, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(&paint, &are); |
if (NULL == target) { |
return; |
} |
@@ -1242,8 +1199,6 @@ void GrContext::flush(int flagsBitfield) { |
} else { |
fDrawBuffer->flush(); |
} |
- fResourceCache->purgeAsNeeded(); |
- fFlushToReduceCacheSize = false; |
} |
bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, |
@@ -1363,7 +1318,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, |
// drawing a rect to the render target. |
// The bracket ensures we pop the stack if we wind up flushing below. |
{ |
- GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL); |
+ GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL); |
GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::kReset_ASRInit, |
&matrix); |
GrDrawState* drawState = drawTarget->drawState(); |
@@ -1543,8 +1498,7 @@ void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
SkASSERT(renderTarget); |
ASSERT_OWNED_RESOURCE(renderTarget); |
AutoRestoreEffects are; |
- AutoCheckFlush acf(this); |
- GrDrawTarget* target = this->prepareToDraw(NULL, &are, &acf); |
+ GrDrawTarget* target = this->prepareToDraw(NULL, &are); |
if (NULL == target) { |
return; |
} |
@@ -1562,7 +1516,7 @@ void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe |
// Since we're going to the draw target and not GPU, no need to check kNoFlush |
// here. |
- GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL); |
+ GrDrawTarget* target = this->prepareToDraw(NULL, NULL); |
if (NULL == target) { |
return; |
} |
@@ -1581,9 +1535,7 @@ void GrContext::flushSurfaceWrites(GrSurface* surface) { |
//////////////////////////////////////////////////////////////////////////////// |
-GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
- AutoRestoreEffects* are, |
- AutoCheckFlush* acf) { |
+GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, AutoRestoreEffects* are) { |
// All users of this draw state should be freeing up all effects when they're done. |
// Otherwise effects that own resources may keep those resources alive indefinitely. |
SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageStages() && |
@@ -1596,7 +1548,6 @@ GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
if (paint) { |
SkASSERT(are); |
- SkASSERT(acf); |
are->set(fDrawState); |
fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
#if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
@@ -1696,7 +1647,7 @@ void GrContext::setupDrawBuffer() { |
} |
GrDrawTarget* GrContext::getTextTarget() { |
- return this->prepareToDraw(NULL, NULL, NULL); |
+ return this->prepareToDraw(NULL, NULL); |
} |
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
@@ -1746,15 +1697,11 @@ const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
} |
void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResource* resource) { |
- fResourceCache->addResource(resourceKey, resource); |
+ resource->cacheAccess().setContentKey(resourceKey); |
} |
GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) { |
- GrGpuResource* resource = fResourceCache2->findAndRefContentResource(resourceKey); |
- if (resource) { |
- fResourceCache->makeResourceMRU(resource); |
- } |
- return resource; |
+ return fResourceCache2->findAndRefContentResource(resourceKey); |
} |
void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
@@ -1774,7 +1721,7 @@ void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
/////////////////////////////////////////////////////////////////////////////// |
#if GR_CACHE_STATS |
void GrContext::printCacheStats() const { |
- fResourceCache->printStats(); |
+ fResourceCache2->printStats(); |
} |
#endif |