Index: src/gpu/GrContext.cpp |
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp |
index dca58745d7d04f46cbc757b156ba7e23ff9dcc05..0ffdb87976f59fb7f08913a410743bd7197d86ae 100644 |
--- a/src/gpu/GrContext.cpp |
+++ b/src/gpu/GrContext.cpp |
@@ -56,6 +56,8 @@ SK_CONF_DECLARE(bool, c_Defer, "gpu.deferContext", true, |
static const size_t MAX_TEXTURE_CACHE_COUNT = 2048; |
static const size_t MAX_TEXTURE_CACHE_BYTES = GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT * 1024 * 1024; |
+static const size_t MAX_PATH_CACHE_COUNT = 2048; |
+static const size_t MAX_PATH_CACHE_BYTES = 1 * 1024 * 1024; |
static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
@@ -111,6 +113,7 @@ GrContext::GrContext() { |
fPathRendererChain = NULL; |
fSoftwarePathRenderer = NULL; |
fTextureCache = NULL; |
+ fPathCache = NULL; |
fFontCache = NULL; |
fDrawBuffer = NULL; |
fDrawBufferVBAllocPool = NULL; |
@@ -173,6 +176,8 @@ GrContext::~GrContext() { |
delete fTextureCache; |
fTextureCache = NULL; |
+ delete fPathCache; |
+ fPathCache = NULL; |
delete fFontCache; |
delete fDrawBuffer; |
delete fDrawBufferVBAllocPool; |
@@ -217,6 +222,10 @@ void GrContext::contextDestroyed() { |
fOvalRenderer->reset(); |
fTextureCache->purgeAllUnlocked(); |
+ if (fPathCache) { |
+ fPathCache->purgeAllUnlocked(); |
+ } |
+ |
fFontCache->freeAll(); |
fGpu->markContextDirty(); |
} |
@@ -234,6 +243,9 @@ void GrContext::freeGpuResources() { |
fOvalRenderer->reset(); |
fTextureCache->purgeAllUnlocked(); |
+ if (fPathCache) { |
+ fPathCache->purgeAllUnlocked(); |
+ } |
fFontCache->freeAll(); |
// a path renderer may be holding onto resources |
SkSafeSetNull(fPathRendererChain); |
@@ -582,6 +594,30 @@ int GrContext::getMaxSampleCount() const { |
return fGpu->caps()->maxSampleCount(); |
} |
+GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) { |
+ if (!fGpu->caps()->pathRenderingSupport()) { |
+ return NULL; |
+ } |
+ |
+ if (!fPathCache) { |
+ fPathCache = SkNEW_ARGS(GrResourceCache, |
+ (MAX_PATH_CACHE_COUNT, |
+ MAX_PATH_CACHE_BYTES)); |
+ fPathCache->setOverbudgetCallback(OverbudgetCB, this); |
+ } |
+ |
+ GrResourceKey resourceKey = GrPath::ComputeKey(inPath, stroke); |
+ GrPath* path = static_cast<GrPath*>(fPathCache->find(resourceKey)); |
+ if (NULL != path && path->isEqualTo(inPath, stroke)) { |
+ path->ref(); |
+ } else { |
+ path = fGpu->createPath(inPath, stroke); |
+ fPathCache->purgeAsNeeded(1, path->sizeInBytes()); |
+ fPathCache->addResource(resourceKey, path); |
+ } |
+ return path; |
+} |
+ |
/////////////////////////////////////////////////////////////////////////////// |
GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
@@ -1776,5 +1812,8 @@ const GrEffectRef* GrContext::createUPMToPMEffect(GrTexture* texture, |
#if GR_CACHE_STATS |
void GrContext::printCacheStats() const { |
fTextureCache->printStats(); |
+ if (fPathCache) { |
+ fPathCache->printStats(); |
+ } |
} |
#endif |