emulator opengl : unit-test renderer  GLESv2

Make the unit test renderer (ut_renderer) encode GLESv2 commands.
A rendering thread has both V1 & V2 decoder object, and tryies to decode
commands of the two protocols from the stream.
Context creating is taking into account the API version and creates context
accordingly.
Decoder data is shared between the V1 & V2 decoders and applied to both of
them on makeCurrent (regardless to the requested context version)

Change-Id: If78e84310e5dcd22108c19656051b138b22e3c9f
diff --git a/tools/emulator/opengl/tests/ut_renderer/Android.mk b/tools/emulator/opengl/tests/ut_renderer/Android.mk
index 28317e9..e4c43a2 100644
--- a/tools/emulator/opengl/tests/ut_renderer/Android.mk
+++ b/tools/emulator/opengl/tests/ut_renderer/Android.mk
@@ -22,7 +22,8 @@
 # is generated
 LOCAL_ADDITIONAL_DEPENDENCIES := \
 	$(HOST_OUT_SHARED_LIBRARIES)/libut_rendercontrol_dec$(HOST_SHLIB_SUFFIX) \
-	$(HOST_OUT_SHARED_LIBRARIES)/libGLESv1_dec$(HOST_SHLIB_SUFFIX)
+	$(HOST_OUT_SHARED_LIBRARIES)/libGLESv1_dec$(HOST_SHLIB_SUFFIX) \
+	$(HOST_OUT_SHARED_LIBRARIES)/libGLESv2_dec$(HOST_SHLIB_SUFFIX)
 
 LOCAL_SRC_FILES := ut_renderer.cpp \
         RenderingThread.cpp \
@@ -43,14 +44,18 @@
 #LOCAL_CFLAGS += -g -O0
 
 LOCAL_C_INCLUDES := $(emulatorOpengl)/shared/OpenglCodecCommon \
+	$(emulatorOpengl)/shared \
         $(emulatorOpengl)/host/include/libOpenglRender \
-		$(call intermediates-dir-for, SHARED_LIBRARIES, libut_rendercontrol_dec, HOST) \
-		$(call intermediates-dir-for, SHARED_LIBRARIES, libGLESv1_dec, HOST) \
+	$(call intermediates-dir-for, SHARED_LIBRARIES, libut_rendercontrol_dec, HOST) \
+	$(call intermediates-dir-for, SHARED_LIBRARIES, libGLESv1_dec, HOST) \
+	$(call intermediates-dir-for, SHARED_LIBRARIES, libGLESv2_dec, HOST) \
         $(emulatorOpengl)/host/libs/GLESv1_dec \
+        $(emulatorOpengl)/host/libs/GLESv2_dec \
         $(emulatorOpengl)/system/GLESv1_enc \
+        $(emulatorOpengl)/system/GLESv2_enc \
         $(emulatorOpengl)/tests/ut_rendercontrol_enc
 
-LOCAL_SHARED_LIBRARIES := libut_rendercontrol_dec libGLESv1_dec libEGL_host_wrapper
+LOCAL_SHARED_LIBRARIES := libut_rendercontrol_dec libGLESv1_dec libGLESv2_dec libEGL_host_wrapper
 LOCAL_STATIC_LIBRARIES := \
     libOpenglCodecCommon \
     libcutils
diff --git a/tools/emulator/opengl/tests/ut_renderer/Renderer.cpp b/tools/emulator/opengl/tests/ut_renderer/Renderer.cpp
index edfdd64..22afadb 100644
--- a/tools/emulator/opengl/tests/ut_renderer/Renderer.cpp
+++ b/tools/emulator/opengl/tests/ut_renderer/Renderer.cpp
@@ -147,6 +147,7 @@
             eglContext = c->second->eglContext();
             thread->setCurrentContext(c->second);
             thread->glDecoder().setContextData(&c->second->decoderContextData());
+            thread->gl2Decoder().setContextData(&c->second->decoderContextData());
         } else {
             // same context is already set
             eglContext = c->second->eglContext();
@@ -156,6 +157,7 @@
         if (currentContext != NULL) currentContext->unref();
         thread->setCurrentContext(NULL);
         thread->glDecoder().setContextData(NULL);
+        thread->gl2Decoder().setContextData(NULL);
     }
 
     EGLSurface draw = EGL_NO_SURFACE;
diff --git a/tools/emulator/opengl/tests/ut_renderer/RenderingThread.cpp b/tools/emulator/opengl/tests/ut_renderer/RenderingThread.cpp
index cf1d070..546c62d 100644
--- a/tools/emulator/opengl/tests/ut_renderer/RenderingThread.cpp
+++ b/tools/emulator/opengl/tests/ut_renderer/RenderingThread.cpp
@@ -312,6 +312,8 @@
     m_glDisableClientState = m_glDec.set_glDisableClientState(s_glDisableClientState);
 #endif
 
+    m_gl2Dec.initGL();
+
     m_utDec.set_swapBuffers(s_swapBuffers);
     m_utDec.set_createContext(s_createContext);
     m_utDec.set_destroyContext(s_destroyContext);
@@ -360,6 +362,14 @@
             }
 
             if (readBuf.validData() >= 8) {
+                size_t last = m_gl2Dec.decode(readBuf.buf(), readBuf.validData(), m_stream);
+                if (last > 0) {
+                    readBuf.consume(last);
+                    progress = true;
+                }
+            }
+
+            if (readBuf.validData() >= 8) {
                 size_t last = m_utDec.decode(readBuf.buf(), readBuf.validData(), m_stream);
                 if (last > 0) {
                     readBuf.consume(last);
diff --git a/tools/emulator/opengl/tests/ut_renderer/RenderingThread.h b/tools/emulator/opengl/tests/ut_renderer/RenderingThread.h
index 19b3060..ca8f6f4 100644
--- a/tools/emulator/opengl/tests/ut_renderer/RenderingThread.h
+++ b/tools/emulator/opengl/tests/ut_renderer/RenderingThread.h
@@ -18,6 +18,7 @@
 
 #include "TcpStream.h"
 #include "GLDecoder.h"
+#include "GL2Decoder.h"
 #include "ut_rendercontrol_dec.h"
 #include <pthread.h>
 
@@ -43,12 +44,15 @@
     RendererContext *currentContext() { return m_currentContext; }
     void setCurrentContext(RendererContext *ctx) { m_currentContext = ctx; }
     GLDecoder & glDecoder() { return m_glDec; }
+    GL2Decoder & gl2Decoder() { return m_gl2Dec; }
+
 private:
     void initBackendCaps();
 
 private:
     GLDecoder   m_glDec;
     ut_rendercontrol_decoder_context_t m_utDec;
+    GL2Decoder m_gl2Dec;
 
     TcpStream   *m_stream;
     pthread_t m_thread;