GLES2Dbg: use liblzf for compressing images

liblzf is in external/liblzf

Change-Id: I5425529cbb24acaf5c41a9046784a8fa7c1791f9
Signed-off-by: David Li <davidxli@google.com>
diff --git a/tools/glesv2debugger/.classpath b/tools/glesv2debugger/.classpath
index 1ef2c20..b9ab621 100755
--- a/tools/glesv2debugger/.classpath
+++ b/tools/glesv2debugger/.classpath
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry exported="true" kind="lib" path="lib/host-libprotobuf-java-2.3.0-lite.jar"/>
+	<classpathentry kind="lib" path="lib/host-libprotobuf-java-2.3.0-lite.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="lib" path="lib/liblzf.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/tools/glesv2debugger/.gitignore b/tools/glesv2debugger/.gitignore
new file mode 100644
index 0000000..8c5987b
--- /dev/null
+++ b/tools/glesv2debugger/.gitignore
@@ -0,0 +1 @@
+lib/*.jar
diff --git a/tools/glesv2debugger/META-INF/MANIFEST.MF b/tools/glesv2debugger/META-INF/MANIFEST.MF
index 70b330f..8848a93 100644
--- a/tools/glesv2debugger/META-INF/MANIFEST.MF
+++ b/tools/glesv2debugger/META-INF/MANIFEST.MF
@@ -9,4 +9,5 @@
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-ClassPath: lib/host-libprotobuf-java-2.3.0-lite.jar,
+ lib/liblzf.jar,
  .
diff --git a/tools/glesv2debugger/build.properties b/tools/glesv2debugger/build.properties
index 6272a36..8d51909 100644
--- a/tools/glesv2debugger/build.properties
+++ b/tools/glesv2debugger/build.properties
@@ -5,4 +5,5 @@
                .,\

                icons/,\

                contexts.xml,\

-               lib/host-libprotobuf-java-2.3.0-lite.jar

+               lib/host-libprotobuf-java-2.3.0-lite.jar,\
+               lib/liblzf.jar
diff --git a/tools/glesv2debugger/lib/host-libprotobuf-java-2.3.0-lite.jar b/tools/glesv2debugger/lib/host-libprotobuf-java-2.3.0-lite.jar
deleted file mode 100644
index 667d407..0000000
--- a/tools/glesv2debugger/lib/host-libprotobuf-java-2.3.0-lite.jar
+++ /dev/null
Binary files differ
diff --git a/tools/glesv2debugger/src/com/android/glesv2debugger/MessageData.java b/tools/glesv2debugger/src/com/android/glesv2debugger/MessageData.java
index e622830..bd032d0 100644
--- a/tools/glesv2debugger/src/com/android/glesv2debugger/MessageData.java
+++ b/tools/glesv2debugger/src/com/android/glesv2debugger/MessageData.java
@@ -17,13 +17,14 @@
 package com.android.glesv2debugger;
 
 import com.android.glesv2debugger.DebuggerMessage.Message;
+import com.android.glesv2debugger.DebuggerMessage.Message.Function;
 
 import org.eclipse.swt.graphics.Device;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 
 public class MessageData {
-    public Message.Function function;
+    public final Message msg;
     public Image image; // texture
     public String shader; // shader source
     public String[] columns;
@@ -32,11 +33,12 @@
     public GLEnum dataType; // could be float, int; mainly for formatting use
     
     public MessageData(final Device device, final Message msg) {
+        this.msg = msg;
         image = null;
         shader = null;
         data = null;
         StringBuilder builder = new StringBuilder();
-        function = msg.getFunction();
+        final Function function = msg.getFunction();
         ImageData imageData = null;
         if (function != Message.Function.ACK)
             assert msg.hasTime();
diff --git a/tools/glesv2debugger/src/com/android/glesv2debugger/MessageProcessor.java b/tools/glesv2debugger/src/com/android/glesv2debugger/MessageProcessor.java
index da6a9b8..a8cdac1 100644
--- a/tools/glesv2debugger/src/com/android/glesv2debugger/MessageProcessor.java
+++ b/tools/glesv2debugger/src/com/android/glesv2debugger/MessageProcessor.java
@@ -30,35 +30,6 @@
         MessageDialog.openError(null, "MessageProcessor", message);
     }
 
-    static byte[] RLEDecode(final byte[] data) {
-        byte dataSize = data[0];
-        int a = data[1] & 0xff, b = data[2] & 0xff, c = data[3] & 0xff, d = data[4] & 0xff;
-        int count = (d << 24) | (c << 16) | (b << 8) | a;
-        byte[] buffer = new byte[count * dataSize];
-        int write = 0;
-        int i = 5;
-        for (i = 5; i < data.length;) {
-            byte flag = data[i];
-            int repeat = (flag & 0x7f) + 1;
-            assert 0 < repeat && repeat < 129;
-            i++;
-            if (0x80 == (flag & 0x80)) {
-                for (int j = 0; j < repeat; j++)
-                    for (int k = 0; k < dataSize; k++)
-                        buffer[write++] = data[i + k];
-                i += dataSize;
-            } else // literal runs
-            {
-                for (int j = 0; j < repeat; j++)
-                    for (int k = 0; k < dataSize; k++)
-                        buffer[write++] = data[i++];
-            }
-        }
-        assert write == count * dataSize;
-        assert i == data.length;
-        return buffer;
-    }
-
     public static ImageData ReceiveImage(int width, int height, int format,
             int type, byte[] data) {
         assert width > 0 && height > 0;
@@ -121,9 +92,12 @@
                 showError("unsupported texture format: " + format);
                 return null;
         }
-        // data = RLEDecode(data);
+        byte[] pixels = new byte[width * height * (bpp / 8)];
+        int decompressed = org.liblzf.CLZF.lzf_decompress(data, data.length, pixels, pixels.length);
+        assert decompressed == width * height * (bpp / 8);
+
         PaletteData palette = new PaletteData(redMask, greenMask, blueMask);
-        return new ImageData(width, height, bpp, palette, 1, data);
+        return new ImageData(width, height, bpp, palette, 1, pixels);
     }
 
     static public float[] ReceiveData(final GLEnum type, final ByteString data) {
diff --git a/tools/glesv2debugger/src/com/android/glesv2debugger/MessageQueue.java b/tools/glesv2debugger/src/com/android/glesv2debugger/MessageQueue.java
index 454fbf1..4a5a750 100644
--- a/tools/glesv2debugger/src/com/android/glesv2debugger/MessageQueue.java
+++ b/tools/glesv2debugger/src/com/android/glesv2debugger/MessageQueue.java
@@ -90,7 +90,8 @@
         DataOutputStream dos = null;
         HashMap<Integer, ArrayList<Message>> incoming = new HashMap<Integer, ArrayList<Message>>();
         try {
-            socket.connect(new java.net.InetSocketAddress("127.0.0.1", 5039));
+            socket.connect(new java.net.InetSocketAddress("127.0.0.1", Integer
+                    .parseInt(sampleView.actionPort.getText())));
             dis = new DataInputStream(socket.getInputStream());
             dos = new DataOutputStream(socket.getOutputStream());
         } catch (Exception e) {
diff --git a/tools/glesv2debugger/src/com/android/glesv2debugger/SampleView.java b/tools/glesv2debugger/src/com/android/glesv2debugger/SampleView.java
index 6905565..fe2e6e6 100644
--- a/tools/glesv2debugger/src/com/android/glesv2debugger/SampleView.java
+++ b/tools/glesv2debugger/src/com/android/glesv2debugger/SampleView.java
@@ -108,6 +108,7 @@
     Action actionAutoScroll;
     Action actionFilter;
     Action actionCapture;
+    Action actionPort;
 
     Point origin = new Point(0, 0); // for smooth scrolling canvas
     String[] filters = null;
@@ -473,6 +474,22 @@
                 manager.update(true);
             }
         });
+
+        actionPort = new Action("5039", Action.AS_DROP_DOWN_MENU)
+        {
+            @Override
+            public void run() {
+                org.eclipse.jface.dialogs.InputDialog dialog = new org.eclipse.jface.dialogs.InputDialog(
+                        shell, "Port",
+                        "Debugger port",
+                        actionPort.getText(), null);
+                if (Window.OK == dialog.open()) {
+                    actionPort.setText(dialog.getValue());
+                    manager.update(true);
+                }
+            }
+        };
+        manager.add(actionPort);
     }
 
     private void ConnectDisconnect() {
@@ -564,7 +581,7 @@
                         MessageData msgData = (MessageData) objects[i];
                         if (null == msgData)
                             continue;
-                        totalTime += Float.parseFloat(msgData.columns[1]);
+                        totalTime += msgData.msg.getTime();
                     }
                     viewer.getTable().getColumn(1).setText(Float.toString(totalTime));
                     return;