Add debug only code to dump the contents of a transaction
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2012 22:30:01 +0000 (22:30 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Nov 2012 22:30:01 +0000 (22:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=101991

Reviewed by Andreas Kling.

* Shared/mac/RemoteLayerTreeTransaction.h:
* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::writeIndent):
(WebKit::dumpChangedLayers):
(WebKit::RemoteLayerTreeTransaction::dump):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@134307 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.h
Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.mm

index 877bcc5..fccf2f2 100644 (file)
@@ -1,5 +1,18 @@
 2012-11-12  Anders Carlsson  <andersca@apple.com>
 
+        Add debug only code to dump the contents of a transaction
+        https://bugs.webkit.org/show_bug.cgi?id=101991
+
+        Reviewed by Andreas Kling.
+
+        * Shared/mac/RemoteLayerTreeTransaction.h:
+        * Shared/mac/RemoteLayerTreeTransaction.mm:
+        (WebKit::writeIndent):
+        (WebKit::dumpChangedLayers):
+        (WebKit::RemoteLayerTreeTransaction::dump):
+
+2012-11-12  Anders Carlsson  <andersca@apple.com>
+
         Store name changes in the layer transaction
         https://bugs.webkit.org/show_bug.cgi?id=101981
 
index 87f3879..07f45d7 100644 (file)
@@ -53,6 +53,10 @@ public:
 
     void layerPropertiesChanged(const RemoteGraphicsLayer*, unsigned changedProperties);
 
+#ifndef NDEBUG
+    void dump() const;
+#endif
+
 private:
     HashMap<uint64_t, LayerProperties> m_changedLayerProperties;
 };
index fdb9aed..8c8c00c 100644 (file)
@@ -27,6 +27,8 @@
 #include "RemoteLayerTreeTransaction.h"
 
 #include "RemoteGraphicsLayer.h"
+#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebKit {
 
@@ -53,4 +55,57 @@ void RemoteLayerTreeTransaction::layerPropertiesChanged(const RemoteGraphicsLaye
         layerProperties.name = graphicsLayer->name();
 }
 
+#ifndef NDEBUG
+
+static void writeIndent(StringBuilder& builder, int indent)
+{
+    for (int i = 0; i < indent; ++i)
+        builder.append(' ');
+}
+
+static void dumpChangedLayers(StringBuilder& builder, const HashMap<uint64_t, RemoteLayerTreeTransaction::LayerProperties>& changedLayerProperties)
+{
+    if (changedLayerProperties.isEmpty())
+        return;
+
+    writeIndent(builder, 1);
+    builder.append("(changed-layers\n");
+
+    // Dump the layer properties sorted by layer ID.
+    Vector<uint64_t> layerIDs;
+    copyKeysToVector(changedLayerProperties, layerIDs);
+    std::sort(layerIDs.begin(), layerIDs.end());
+
+    for (uint64_t layerID: layerIDs) {
+        const RemoteLayerTreeTransaction::LayerProperties& layerProperties = changedLayerProperties.get(layerID);
+
+        writeIndent(builder, 2);
+        builder.append("(layer ");
+        builder.appendNumber(layerID);
+
+        if (layerProperties.changedProperties & RemoteLayerTreeTransaction::NameChanged) {
+            builder.append('\n');
+            writeIndent(builder, 3);
+            builder.append("(name \"");
+            builder.append(layerProperties.name);
+            builder.append("\")");
+        }
+
+        builder.append(")\n");
+    }
+}
+
+void RemoteLayerTreeTransaction::dump() const
+{
+    StringBuilder builder;
+
+    builder.append("(\n");
+    dumpChangedLayers(builder, m_changedLayerProperties);
+    builder.append(")\n");
+
+    fprintf(stderr, "%s", builder.toString().utf8().data());
+}
+
+#endif // NDEBUG
+
 } // namespace WebKit