Remove repeated host round trip in glBindSampler

bug: 117960593

glBindSampler was calling glGetIntegerv for the # of texture units which
was in turn calling glGetError, which resulted in lots of unnecessary
round trips. Caching the capability makes it so we compute that once
in the beginning and don't touch the host again.

Test: Profiling shows that glBindSampler no longer takes up most of
the runtime in a dEQP test (in gluStateReset)

Change-Id: Ibbbb5ddd93daae07bb4852fa34f3c5d8b187099d
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 2a265e0..c3389c5 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -77,6 +77,7 @@
     m_state = NULL;
     m_error = GL_NO_ERROR;
     m_num_compressedTextureFormats = 0;
+    m_max_combinedTextureImageUnits = 0;
     m_max_cubeMapTextureSize = 0;
     m_max_renderBufferSize = 0;
     m_max_textureSize = 0;
@@ -662,6 +663,13 @@
     }
 
     case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
+        if (ctx->m_max_combinedTextureImageUnits != 0) {
+            *ptr = ctx->m_max_combinedTextureImageUnits;
+        } else {
+            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_max_combinedTextureImageUnits = *ptr;
+        }
+        break;
     case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
     case GL_MAX_TEXTURE_IMAGE_UNITS:
         ctx->safe_glGetIntegerv(param, ptr);