Add support to dump font cache texture for debug purposes
R=robertphillips@google.com, bsalomon@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/25736002
git-svn-id: http://skia.googlecode.com/svn/trunk@11579 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 7a42677..5b25fe4 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -628,6 +628,10 @@
*/
void resolveRenderTarget(GrRenderTarget* target);
+#ifdef SK_DEVELOPER
+ void dumpFontCache() const;
+#endif
+
///////////////////////////////////////////////////////////////////////////
// Helpers
diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp
index 70fe3e0..9784e83 100644
--- a/src/gpu/GrAtlas.cpp
+++ b/src/gpu/GrAtlas.cpp
@@ -179,7 +179,13 @@
if (NULL == fTexture) {
// TODO: Update this to use the cache rather than directly creating a texture.
GrTextureDesc desc;
+#ifdef SK_DEVELOPER
+ // RenderTarget so we can read the pixels to dump them
+ desc.fFlags = kDynamicUpdate_GrTextureFlagBit|kRenderTarget_GrTextureFlagBit
+ |kNoStencil_GrTextureFlagBit;
+#else
desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
+#endif
desc.fWidth = GR_ATLAS_TEXTURE_WIDTH;
desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT;
desc.fConfig = fPixelConfig;
@@ -205,6 +211,7 @@
}
bool GrAtlasMgr::removeUnusedPlots(GrAtlas* atlas) {
+
// GrPlot** is used so that the head element can be easily
// modified when the first element is deleted
GrPlot** plotRef = &atlas->fPlots;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 9dfe761..6b1efbe 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -642,6 +642,12 @@
this->drawRect(*paint, r);
}
+#ifdef SK_DEVELOPER
+void GrContext::dumpFontCache() const {
+ fFontCache->dump();
+}
+#endif
+
////////////////////////////////////////////////////////////////////////////////
namespace {
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 1f25c90..5a61839 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -16,11 +16,15 @@
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"
#include "SkPath.h"
+#include "SkRTConf.h"
#include "SkStrokeRec.h"
#include "effects/GrCustomCoordsTextureEffect.h"
static const int kGlyphCoordsAttributeIndex = 1;
+SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
+ "Dump the contents of the font cache before every purge.");
+
void GrTextContext::flushGlyphs() {
if (NULL == fDrawTarget) {
return;
@@ -161,6 +165,12 @@
goto HAS_ATLAS;
}
+ if (c_DumpFontCache) {
+#ifdef SK_DEVELOPER
+ fContext->getFontCache()->dump();
+#endif
+ }
+
// before we purge the cache, we must flush any accumulated draws
this->flushGlyphs();
fContext->flush();
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index e399c91..7cab335 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -10,6 +10,7 @@
#include "GrRectanizer.h"
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"
+#include "SkString.h"
SK_DEFINE_INST_COUNT(GrFontScaler)
SK_DEFINE_INST_COUNT(GrKey)
@@ -170,6 +171,23 @@
}
#endif
+#ifdef SK_DEVELOPER
+void GrFontCache::dump() const {
+ static int gDumpCount = 0;
+ for (int i = 0; i < kMaskFormatCount; ++i) {
+ if (NULL != fAtlasMgr[i]) {
+ GrTexture* texture = fAtlasMgr[i]->getTexture();
+ if (NULL != texture) {
+ SkString filename;
+ filename.printf("fontcache_%d%d.png", gDumpCount, i);
+ texture->savePixels(filename.c_str());
+ }
+ }
+ }
+ ++gDumpCount;
+}
+#endif
+
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG
diff --git a/src/gpu/GrTextStrike.h b/src/gpu/GrTextStrike.h
index e311f3f..35d5008 100644
--- a/src/gpu/GrTextStrike.h
+++ b/src/gpu/GrTextStrike.h
@@ -98,6 +98,10 @@
void validate() const {}
#endif
+#ifdef SK_DEVELOPER
+ void dump() const;
+#endif
+
private:
friend class GrFontPurgeListener;
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index bf82831..70bc221 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -440,8 +440,10 @@
#if GR_CACHE_STATS
if (renderer->isUsingGpuDevice()) {
GrContext* ctx = renderer->getGrContext();
-
ctx->printCacheStats();
+#ifdef SK_DEVELOPER
+ ctx->dumpFontCache();
+#endif
}
#endif
#endif