Feature: IgnoreHostOpenGLErrors

bug: 71853717

If you use the emulator and the UI works fine, do this to make the UI
faster.

Change-Id: I044a46956eadb17021d6cf2c7b87c6423a328051
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 0e72478..a7ff5c1 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -73,6 +73,7 @@
     m_currMajorVersion = 2;
     m_currMinorVersion = 0;
     m_initialized = false;
+    m_noHostError = false;
     m_state = NULL;
     m_error = GL_NO_ERROR;
     m_num_compressedTextureFormats = 0;
@@ -365,7 +366,11 @@
         return err;
     }
 
-    return ctx->m_glGetError_enc(self);
+    if (ctx->m_noHostError) {
+        return GL_NO_ERROR;
+    } else {
+        return ctx->m_glGetError_enc(self);
+    }
 }
 
 class GL2Encoder::ErrorUpdater {
diff --git a/system/GLESv2_enc/GL2Encoder.h b/system/GLESv2_enc/GL2Encoder.h
index 0cb6630..06a07a9 100644
--- a/system/GLESv2_enc/GL2Encoder.h
+++ b/system/GLESv2_enc/GL2Encoder.h
@@ -27,6 +27,9 @@
 public:
     GL2Encoder(IOStream *stream, ChecksumCalculator* protocol);
     virtual ~GL2Encoder();
+    void setNoHostError(bool noHostError) {
+        m_noHostError = noHostError;
+    }
     void setClientState(GLClientState *state) {
         m_state = state;
     }
@@ -92,6 +95,7 @@
     std::string m_currExtensions;
 
     bool    m_initialized;
+    bool    m_noHostError;
     GLClientState *m_state;
     GLSharedGroupPtr m_shared;
     GLenum  m_error;
diff --git a/system/OpenglSystemCommon/HostConnection.cpp b/system/OpenglSystemCommon/HostConnection.cpp
index 0b5304f..34ddef4 100644
--- a/system/OpenglSystemCommon/HostConnection.cpp
+++ b/system/OpenglSystemCommon/HostConnection.cpp
@@ -37,7 +37,8 @@
     m_rcEnc(NULL),
     m_checksumHelper(),
     m_glExtensions(),
-    m_grallocOnly(true)
+    m_grallocOnly(true),
+    m_noHostError(false)
 {
 }
 
@@ -146,6 +147,7 @@
         m_gl2Enc = new GL2Encoder(m_stream, checksumHelper());
         DBG("HostConnection::gl2Encoder new encoder %p, tid %d", m_gl2Enc, gettid());
         m_gl2Enc->setContextAccessor(s_getGL2Context);
+        m_gl2Enc->setNoHostError(m_noHostError);
     }
     return m_gl2Enc;
 }
@@ -158,6 +160,7 @@
         queryAndSetSyncImpl(m_rcEnc);
         queryAndSetDmaImpl(m_rcEnc);
         queryAndSetGLESMaxVersion(m_rcEnc);
+        queryAndSetNoErrorState(m_rcEnc);
         processPipeInit(m_rcEnc);
     }
     return m_rcEnc;
@@ -272,3 +275,10 @@
         rcEnc->setGLESMaxVersion(GLES_MAX_VERSION_2);
     }
 }
+
+void HostConnection::queryAndSetNoErrorState(ExtendedRCEncoderContext* rcEnc) {
+    std::string glExtensions = queryGLExtensions(rcEnc);
+    if (glExtensions.find(kGLESNoHostError) != std::string::npos) {
+        m_noHostError = true;
+    }
+}
diff --git a/system/OpenglSystemCommon/HostConnection.h b/system/OpenglSystemCommon/HostConnection.h
index 0924cf9..2b49857 100644
--- a/system/OpenglSystemCommon/HostConnection.h
+++ b/system/OpenglSystemCommon/HostConnection.h
@@ -71,6 +71,9 @@
 static const char kGLESMaxVersion_3_1[] = "ANDROID_EMU_gles_max_version_3_1";
 static const char kGLESMaxVersion_3_2[] = "ANDROID_EMU_gles_max_version_3_2";
 
+// No querying errors from host extension
+static const char kGLESNoHostError[] = "ANDROID_EMU_gles_no_host_error";
+
 // ExtendedRCEncoderContext is an extended version of renderControl_encoder_context_t
 // that will be used to track SyncImpl.
 class ExtendedRCEncoderContext : public renderControl_encoder_context_t {
@@ -148,6 +151,7 @@
     void queryAndSetSyncImpl(ExtendedRCEncoderContext *rcEnc);
     void queryAndSetDmaImpl(ExtendedRCEncoderContext *rcEnc);
     void queryAndSetGLESMaxVersion(ExtendedRCEncoderContext *rcEnc);
+    void queryAndSetNoErrorState(ExtendedRCEncoderContext *rcEnc);
 
 private:
     IOStream *m_stream;
@@ -158,6 +162,7 @@
     std::string m_glExtensions;
     bool m_grallocOnly;
     int m_pipeFd;
+    bool m_noHostError;
 };
 
 #endif