Expose functionality to purge the GPU texture cache while running SampleApp.
Press 'p' to purge the cache. A summary of the number of bytes of video memory
released is output to the command prompt.
Review URL: https://codereview.appspot.com/5587045
git-svn-id: http://skia.googlecode.com/svn/trunk@3097 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index d27b963..ca440a6 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -75,6 +75,11 @@
*/
void freeGpuResources();
+ /**
+ * Returns the number of bytes of GPU memory hosted by the texture cache.
+ */
+ size_t getGpuTextureCacheBytes() const;
+
///////////////////////////////////////////////////////////////////////////
// Textures
@@ -858,4 +863,3 @@
};
#endif
-
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index d3d2aa7..898bda0 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -1537,6 +1537,17 @@
this->updateTitle();
}
return true;
+ case 'p':
+ {
+ GrContext* grContext = this->getGrContext();
+ if (grContext) {
+ size_t cacheBytes = grContext->getGpuTextureCacheBytes();
+ grContext->freeGpuResources();
+ SkDebugf("Purged %d bytes from the GPU resource cache.\n",
+ cacheBytes);
+ }
+ }
+ return true;
case 's':
fScale = !fScale;
this->inval(NULL);
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 2132ed6..975f6d0 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -115,6 +115,10 @@
GrSafeSetNull(fPathRendererChain);
}
+size_t GrContext::getGpuTextureCacheBytes() const {
+ return fTextureCache->getCachedResourceBytes();
+}
+
////////////////////////////////////////////////////////////////////////////////
int GrContext::PaintStageVertexLayoutBits(
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index e21c605..f86fcd2 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -209,6 +209,11 @@
void setLimits(int maxResource, size_t maxResourceBytes);
/**
+ * Returns the number of bytes consumed by cached resources.
+ */
+ size_t getCachedResourceBytes() const { return fEntryBytes; }
+
+ /**
* Controls whether locks should be nestable or not.
*/
enum LockType {
@@ -315,4 +320,3 @@
#endif
#endif
-