Add support to dump font cache texture for debug purposes
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 2 Oct 2013 18:19:17 +0000 (18:19 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 2 Oct 2013 18:19:17 +0000 (18:19 +0000)
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

include/gpu/GrContext.h
src/gpu/GrAtlas.cpp
src/gpu/GrContext.cpp
src/gpu/GrTextContext.cpp
src/gpu/GrTextStrike.cpp
src/gpu/GrTextStrike.h
tools/render_pictures_main.cpp

index 7a42677..5b25fe4 100644 (file)
@@ -628,6 +628,10 @@ public:
      */
     void resolveRenderTarget(GrRenderTarget* target);
 
+#ifdef SK_DEVELOPER
+    void dumpFontCache() const;
+#endif
+
     ///////////////////////////////////////////////////////////////////////////
     // Helpers
 
index 70fe3e0..9784e83 100644 (file)
@@ -179,7 +179,13 @@ GrPlot* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
     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 @@ GrPlot* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
 }
 
 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;
index 9dfe761..6b1efbe 100644 (file)
@@ -642,6 +642,12 @@ void GrContext::drawPaint(const GrPaint& origPaint) {
     this->drawRect(*paint, r);
 }
 
+#ifdef SK_DEVELOPER
+void GrContext::dumpFontCache() const {
+    fFontCache->dump();
+}
+#endif
+
 ////////////////////////////////////////////////////////////////////////////////
 
 namespace {
index 1f25c90..5a61839 100644 (file)
 #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 @@ void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
             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();
index e399c91..7cab335 100644 (file)
@@ -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 @@ void GrFontCache::validate() const {
 }
 #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
index e311f3f..35d5008 100644 (file)
@@ -98,6 +98,10 @@ public:
     void validate() const {}
 #endif
 
+#ifdef SK_DEVELOPER
+    void dump() const;
+#endif
+
 private:
     friend class GrFontPurgeListener;
 
index bf82831..70bc221 100644 (file)
@@ -440,8 +440,10 @@ int tool_main(int argc, char** argv) {
 #if GR_CACHE_STATS
     if (renderer->isUsingGpuDevice()) {
         GrContext* ctx = renderer->getGrContext();
-
         ctx->printCacheStats();
+#ifdef SK_DEVELOPER
+        ctx->dumpFontCache();
+#endif
     }
 #endif
 #endif