GLES2Debugger: Added DbgContext and vertex data capturing.

Send VBO related commands to client, which tracks the state.
Maintain index buffer content and vertex attrib pointer/buffer state on server.
During glDrawArrays/Elements, send user memory data to client.

Change-Id: Ia920e90479329b301ae4b5735e833eeb20293c94
Signed-off-by: David Li <davidxli@google.com>
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 55b5436..2502f15 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -30,6 +30,7 @@
 #include "egl_impl.h"
 
 #include "Loader.h"
+#include "glesv2dbg.h"
 
 // ----------------------------------------------------------------------------
 namespace android {
@@ -114,7 +115,6 @@
 
 Loader::~Loader()
 {
-    extern void StopDebugServer();
     StopDebugServer();
 }
 
diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp
index 8e4b0ee..861d7ac 100644
--- a/opengl/libs/EGL/egl.cpp
+++ b/opengl/libs/EGL/egl.cpp
@@ -45,6 +45,7 @@
 #include "hooks.h"
 #include "egl_impl.h"
 #include "Loader.h"
+#include "glesv2dbg.h"
 
 #define setError(_e, _r) setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
 
@@ -223,9 +224,15 @@
     egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
             int impl, egl_connection_t const* cnx, int version) 
     : dpy(dpy), context(context), config(config), read(0), draw(0), impl(impl),
-      cnx(cnx), version(version)
+      cnx(cnx), version(version), dbg(NULL)
     {
     }
+    ~egl_context_t()
+    {
+        if (dbg)
+            DestroyDbgContext(dbg);
+        dbg = NULL;
+    }
     EGLDisplay                  dpy;
     EGLContext                  context;
     EGLConfig                   config;
@@ -234,6 +241,7 @@
     int                         impl;
     egl_connection_t const*     cnx;
     int                         version;
+    DbgContext *                dbg;
 };
 
 struct egl_image_t : public egl_object_t
@@ -325,14 +333,12 @@
         char cmdline[256] = {};
         if (fgets(cmdline, sizeof(cmdline) - 1, file))
         {
-            LOGD("\n*\n*\n* initEglTraceLevel cmdline='%s' \n*\n*", cmdline);
             if (!strcmp(value, cmdline))
                 gEGLDebugLevel = 1;
         }    
         fclose(file);
     }
     
-    extern void StartDebugServer();
     if (gEGLDebugLevel > 0)
         StartDebugServer();
 }
@@ -341,7 +347,7 @@
     if (gEGLTraceLevel > 0) {
         setGlTraceThreadSpecific(value);
         setGlThreadSpecific(&gHooksTrace);
-    } else if (gEGLDebugLevel > 0) {
+    } else if (gEGLDebugLevel > 0 && value != &gHooksNoContext) {
         setGlTraceThreadSpecific(value);
         setGlThreadSpecific(&gHooksDebug);
         LOGD("\n* setGLHooksThreadSpecific gHooksDebug");
@@ -586,6 +592,11 @@
     return egl_to_native_cast<egl_context_t>(context);
 }
 
+DbgContext * getDbgContextThreadSpecific()
+{
+    return get_context(getContext())->dbg;
+}
+
 static inline
 egl_image_t* get_image(EGLImageKHR image) {
     return egl_to_native_cast<egl_image_t>(image);
@@ -1393,6 +1404,8 @@
         loseCurrent(cur_c);
 
         if (ctx != EGL_NO_CONTEXT) {
+            if (!c->dbg && gEGLDebugLevel > 0)
+                c->dbg = CreateDbgContext(c->version, c->cnx->hooks[c->version]);
             setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
             setContext(ctx);
             _c.acquire();
diff --git a/opengl/libs/EGL/trace.cpp b/opengl/libs/EGL/trace.cpp
index 3a1ae21..f3e101b 100644
--- a/opengl/libs/EGL/trace.cpp
+++ b/opengl/libs/EGL/trace.cpp
@@ -376,7 +376,7 @@
 
 // declare all Debug_gl* functions
 #define GL_ENTRY(_r, _api, ...) _r Debug_##_api ( __VA_ARGS__ );
-#include "../GLES2_dbg/include/glesv2_dbg.h"
+#include "glesv2dbg_functions.h"
 #undef GL_ENTRY
 
 #define GL_ENTRY(_r, _api, ...) Debug_ ## _api,