Improve layers debugging

Change-Id: Ia4950dd5f0e0a224ecb69c581d33aa4f32260a7c
diff --git a/libs/hwui/LayerCache.cpp b/libs/hwui/LayerCache.cpp
index 58c0fac..89c35da 100644
--- a/libs/hwui/LayerCache.cpp
+++ b/libs/hwui/LayerCache.cpp
@@ -112,17 +112,21 @@
         glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 
 #if DEBUG_LAYERS
-        size_t size = mCache.size();
-        for (size_t i = 0; i < size; i++) {
-            const LayerEntry& entry = mCache.itemAt(i);
-            LAYER_LOGD("  Layer size %dx%d", entry.mWidth, entry.mHeight);
-        }
+        dump();
 #endif
     }
 
     return layer;
 }
 
+void LayerCache::dump() {
+    size_t size = mCache.size();
+    for (size_t i = 0; i < size; i++) {
+        const LayerEntry& entry = mCache.itemAt(i);
+        LAYER_LOGD("  Layer size %dx%d", entry.mWidth, entry.mHeight);
+    }
+}
+
 bool LayerCache::resize(Layer* layer, const uint32_t width, const uint32_t height) {
     // TODO: We should be smarter and see if we have a texture of the appropriate
     //       size already in the cache, and reuse it instead of creating a new one
diff --git a/libs/hwui/LayerCache.h b/libs/hwui/LayerCache.h
index 81b8bf3..a0eae59 100644
--- a/libs/hwui/LayerCache.h
+++ b/libs/hwui/LayerCache.h
@@ -101,6 +101,11 @@
      */
     uint32_t getSize();
 
+    /**
+     * Prints out the content of the cache.
+     */
+    void dump();
+
 private:
     void deleteLayer(Layer* layer);
 
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index 1fa343b..81816f6 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -167,7 +167,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 Layer* LayerRenderer::createLayer(uint32_t width, uint32_t height, bool isOpaque) {
-    LAYER_RENDERER_LOGD("Creating new layer %dx%d", width, height);
+    LAYER_RENDERER_LOGD("Requesting new render layer %dx%d", width, height);
 
     GLuint fbo = Caches::getInstance().fboCache.get();
     if (!fbo) {
@@ -288,16 +288,22 @@
 
 void LayerRenderer::destroyLayer(Layer* layer) {
     if (layer) {
-        LAYER_RENDERER_LOGD("Destroying layer, fbo = %d", layer->getFbo());
+        LAYER_RENDERER_LOGD("Recycling layer, %dx%d fbo = %d",
+                layer->getWidth(), layer->getHeight(), layer->getFbo());
 
         if (layer->getFbo()) {
             Caches::getInstance().fboCache.put(layer->getFbo());
         }
 
         if (!Caches::getInstance().layerCache.put(layer)) {
+            LAYER_RENDERER_LOGD("  Destroyed!");
             layer->deleteTexture();
             delete layer;
         } else {
+            LAYER_RENDERER_LOGD("  Cached!");
+#if DEBUG_LAYERS
+            Caches::getInstance().layerCache.dump();
+#endif
             layer->region.clear();
         }
     }