Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: src/gpu/GrContext.cpp

Issue 726913002: Revert of Replace GrResourceCache with GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | src/gpu/GrGpuResource.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrContext.cpp
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 80fdace9bab731f04b3756683efee8a163b90182..3a93404af17832b421c94bc3f8df1ed08cb81a73 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -25,6 +25,7 @@
#include "GrOvalRenderer.h"
#include "GrPathRenderer.h"
#include "GrPathUtils.h"
+#include "GrResourceCache.h"
#include "GrResourceCache2.h"
#include "GrSoftwarePathRenderer.h"
#include "GrStencilBuffer.h"
@@ -51,6 +52,9 @@
#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;
@@ -99,6 +103,7 @@
fClip = NULL;
fPathRendererChain = NULL;
fSoftwarePathRenderer = NULL;
+ fResourceCache = NULL;
fResourceCache2 = NULL;
fFontCache = NULL;
fDrawBuffer = NULL;
@@ -125,8 +130,11 @@
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));
@@ -152,6 +160,9 @@
}
SkDELETE(fResourceCache2);
+ fResourceCache2 = NULL;
+ SkDELETE(fResourceCache);
+ fResourceCache = NULL;
SkDELETE(fFontCache);
SkDELETE(fDrawBuffer);
SkDELETE(fDrawBufferVBAllocPool);
@@ -190,6 +201,8 @@
fAARectRenderer->reset();
fOvalRenderer->reset();
+ fResourceCache->purgeAllUnlocked();
+
fFontCache->freeAll();
fLayerCache->freeAll();
}
@@ -208,6 +221,7 @@
fAARectRenderer->reset();
fOvalRenderer->reset();
+ fResourceCache->purgeAllUnlocked();
fFontCache->freeAll();
fLayerCache->freeAll();
// a path renderer may be holding onto resources
@@ -216,12 +230,12 @@
}
void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
- if (resourceCount) {
- *resourceCount = fResourceCache2->getResourceCount();
- }
- if (resourceBytes) {
- *resourceBytes = fResourceCache2->getResourceBytes();
- }
+ if (resourceCount) {
+ *resourceCount = fResourceCache->getCachedResourceCount();
+ }
+ if (resourceBytes) {
+ *resourceBytes = fResourceCache->getCachedResourceBytes();
+ }
}
GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
@@ -259,13 +273,12 @@
}
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());
- SkAssertResult(sb->cacheAccess().setContentKey(resourceKey));
+ fResourceCache->addResource(resourceKey, sb);
}
GrStencilBuffer* GrContext::findAndRefStencilBuffer(int width, int height, int sampleCnt) {
@@ -407,16 +420,22 @@
}
if (texture) {
- if (texture->cacheAccess().setContentKey(resourceKey)) {
- if (cacheKey) {
- *cacheKey = resourceKey;
- }
- } else {
- texture->unref();
- texture = NULL;
- }
- }
-
+ fResourceCache->addResource(resourceKey, texture);
+
+ if (cacheKey) {
+ *cacheKey = resourceKey;
+ }
+ }
+
+ 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;
}
@@ -454,6 +473,7 @@
}
GrGpuResource* resource = fResourceCache2->findAndRefScratchResource(key, scratchFlags);
if (resource) {
+ fResourceCache->makeResourceMRU(resource);
return static_cast<GrSurface*>(resource)->asTexture();
}
@@ -476,19 +496,21 @@
desc.writable()->fFlags = origFlags;
}
- GrTexture* texture = fGpu->createTexture(*desc, NULL, 0);
+ GrTexture* texture = this->createNewScratchTexture(*desc);
SkASSERT(NULL == texture ||
texture->cacheAccess().getScratchKey() == GrTexturePriv::ComputeScratchKey(*desc));
return texture;
}
-void GrContext::OverBudgetCB(void* data) {
+bool GrContext::OverbudgetCB(void* data) {
SkASSERT(data);
GrContext* context = reinterpret_cast<GrContext*>(data);
// Flush the InOrderDrawBuffer to possibly free up some textures
context->fFlushToReduceCacheSize = true;
+
+ return true;
}
@@ -500,16 +522,11 @@
}
void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const {
- if (maxTextures) {
- *maxTextures = fResourceCache2->getMaxResourceCount();
- }
- if (maxTextureBytes) {
- *maxTextureBytes = fResourceCache2->getMaxResourceBytes();
- }
+ fResourceCache->getLimits(maxTextures, maxTextureBytes);
}
void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
- fResourceCache2->setLimits(maxTextures, maxTextureBytes);
+ fResourceCache->setLimits(maxTextures, maxTextureBytes);
}
int GrContext::getMaxTextureSize() const {
@@ -1225,6 +1242,7 @@
} else {
fDrawBuffer->flush();
}
+ fResourceCache->purgeAsNeeded();
fFlushToReduceCacheSize = false;
}
@@ -1728,11 +1746,15 @@
}
void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResource* resource) {
- resource->cacheAccess().setContentKey(resourceKey);
+ fResourceCache->addResource(resourceKey, resource);
}
GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) {
- return fResourceCache2->findAndRefContentResource(resourceKey);
+ GrGpuResource* resource = fResourceCache2->findAndRefContentResource(resourceKey);
+ if (resource) {
+ fResourceCache->makeResourceMRU(resource);
+ }
+ return resource;
}
void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
@@ -1752,7 +1774,7 @@
///////////////////////////////////////////////////////////////////////////////
#if GR_CACHE_STATS
void GrContext::printCacheStats() const {
- fResourceCache2->printStats();
+ fResourceCache->printStats();
}
#endif
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | src/gpu/GrGpuResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698