goldfish-opengl: update to 4153dd9ab6a14
am: 9b2d1c3cee  -s ours

Change-Id: I67009a173e9f627082fdb0abfb9e41ade83660df
diff --git a/Android.mk b/Android.mk
index ae2ae52..d598d71 100644
--- a/Android.mk
+++ b/Android.mk
@@ -32,7 +32,7 @@
 EMUGL_COMMON_CFLAGS += -DGOLDFISH_HIDL_GRALLOC
 endif
 
-ifdef IS_AT_LEAST_PPD1
+ifdef IS_AT_LEAST_OPD1
     EMUGL_COMMON_CFLAGS += -DEMULATOR_OPENGL_POST_O=1
 endif
 
diff --git a/common.mk b/common.mk
index 2583a13..c15812e 100644
--- a/common.mk
+++ b/common.mk
@@ -106,7 +106,7 @@
     STATIC_LIBRARIES \
     ADDITIONAL_DEPENDENCIES
 
-ifdef IS_AT_LEAST_PPD1
+ifdef IS_AT_LEAST_OPD1
 EMUGL_EXPORT_TYPES += HEADER_LIBRARIES
 endif
 
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 39e4cda..3c37a82 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -285,8 +285,6 @@
 
     OVERRIDE(glGetIntegeri_v);
     OVERRIDE(glGetInteger64i_v);
-    OVERRIDE(glGetInteger64v);
-    OVERRIDE(glGetBooleani_v);
 
     OVERRIDE(glGetShaderiv);
 
@@ -358,112 +356,12 @@
     GL2Encoder *ctx = (GL2Encoder *)self;
     GLenum err = ctx->getError();
     if(err != GL_NO_ERROR) {
-        ctx->m_glGetError_enc(ctx); // also clear host error
         ctx->setError(GL_NO_ERROR);
         return err;
     }
 
     return ctx->m_glGetError_enc(self);
-}
 
-class GL2Encoder::ErrorUpdater {
-public:
-    ErrorUpdater(GL2Encoder* ctx) :
-        mCtx(ctx),
-        guest_error(ctx->getError()),
-        host_error(ctx->m_glGetError_enc(ctx)) {
-            // Preserve any existing GL error in the guest:
-            // OpenGL ES 3.0.5 spec:
-            // The command enum GetError( void ); is used to obtain error information.
-            // Each detectable error is assigned a numeric code. When an error is
-            // detected, a flag is set and the code is recorded. Further errors, if
-            // they occur, do not affect this recorded code. When GetError is called,
-            // the code is returned and the flag is cleared, so that a further error
-            // will again record its code. If a call to GetError returns NO_ERROR, then
-            // there has been no detectable error since the last call to GetError (or
-            // since the GL was initialized).
-            if (guest_error == GL_NO_ERROR) {
-                guest_error = host_error;
-            }
-        }
-
-    GLenum getHostErrorAndUpdate() {
-        host_error = mCtx->m_glGetError_enc(mCtx);
-        if (guest_error == GL_NO_ERROR) {
-            guest_error = host_error;
-        }
-        return host_error;
-    }
-
-    void updateGuestErrorState() {
-        mCtx->setError(guest_error);
-    }
-
-private:
-    GL2Encoder* mCtx;
-    GLenum guest_error;
-    GLenum host_error;
-};
-
-template<class T>
-class GL2Encoder::ScopedQueryUpdate {
-public:
-    ScopedQueryUpdate(GL2Encoder* ctx, uint32_t bytes, T* target) :
-        mCtx(ctx),
-        mBuf(bytes, 0),
-        mTarget(target),
-        mErrorUpdater(ctx) {
-    }
-    T* hostStagingBuffer() {
-        return (T*)&mBuf[0];
-    }
-    ~ScopedQueryUpdate() {
-        GLint hostError = mErrorUpdater.getHostErrorAndUpdate();
-        if (hostError == GL_NO_ERROR) {
-            memcpy(mTarget, &mBuf[0], mBuf.size());
-        }
-        mErrorUpdater.updateGuestErrorState();
-    }
-private:
-    GL2Encoder* mCtx;
-    std::vector<char> mBuf;
-    T* mTarget;
-    ErrorUpdater mErrorUpdater;
-};
-
-void GL2Encoder::safe_glGetBooleanv(GLenum param, GLboolean* val) {
-    ScopedQueryUpdate<GLboolean> query(this, glUtilsParamSize(param) * sizeof(GLboolean), val);
-    m_glGetBooleanv_enc(this, param, query.hostStagingBuffer());
-}
-
-void GL2Encoder::safe_glGetFloatv(GLenum param, GLfloat* val) {
-    ScopedQueryUpdate<GLfloat> query(this, glUtilsParamSize(param) * sizeof(GLfloat), val);
-    m_glGetFloatv_enc(this, param, query.hostStagingBuffer());
-}
-
-void GL2Encoder::safe_glGetIntegerv(GLenum param, GLint* val) {
-    ScopedQueryUpdate<GLint> query(this, glUtilsParamSize(param) * sizeof(GLint), val);
-    m_glGetIntegerv_enc(this, param, query.hostStagingBuffer());
-}
-
-void GL2Encoder::safe_glGetInteger64v(GLenum param, GLint64* val) {
-    ScopedQueryUpdate<GLint64> query(this, glUtilsParamSize(param) * sizeof(GLint64), val);
-    m_glGetInteger64v_enc(this, param, query.hostStagingBuffer());
-}
-
-void GL2Encoder::safe_glGetIntegeri_v(GLenum param, GLuint index, GLint* val) {
-    ScopedQueryUpdate<GLint> query(this, sizeof(GLint), val);
-    m_glGetIntegeri_v_enc(this, param, index, query.hostStagingBuffer());
-}
-
-void GL2Encoder::safe_glGetInteger64i_v(GLenum param, GLuint index, GLint64* val) {
-    ScopedQueryUpdate<GLint64> query(this, sizeof(GLint64), val);
-    m_glGetInteger64i_v_enc(this, param, index, query.hostStagingBuffer());
-}
-
-void GL2Encoder::safe_glGetBooleani_v(GLenum param, GLuint index, GLboolean* val) {
-    ScopedQueryUpdate<GLboolean> query(this, sizeof(GLboolean), val);
-    m_glGetBooleani_v_enc(this, param, index, query.hostStagingBuffer());
 }
 
 void GL2Encoder::s_glFlush(void *self)
@@ -655,7 +553,7 @@
     case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
     case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
     case GL_MAX_TEXTURE_IMAGE_UNITS:
-        ctx->safe_glGetIntegerv(param, ptr);
+        ctx->m_glGetIntegerv_enc(self, param, ptr);
         *ptr = MIN(*ptr, GLClientState::MAX_TEXTURE_UNITS);
         break;
 
@@ -668,7 +566,7 @@
 
     case GL_MAX_VERTEX_ATTRIBS:
         if (!ctx->m_state->getClientStateParameter<GLint>(param, ptr)) {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_state->setMaxVertexAttribs(*ptr);
         }
         break;
@@ -676,7 +574,7 @@
         if (ctx->m_max_vertexAttribStride != 0) {
             *ptr = ctx->m_max_vertexAttribStride;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_max_vertexAttribStride = *ptr;
         }
         break;
@@ -684,7 +582,7 @@
         if (ctx->m_max_cubeMapTextureSize != 0) {
             *ptr = ctx->m_max_cubeMapTextureSize;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_max_cubeMapTextureSize = *ptr;
         }
         break;
@@ -692,7 +590,7 @@
         if (ctx->m_max_renderBufferSize != 0) {
             *ptr = ctx->m_max_renderBufferSize;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_max_renderBufferSize = *ptr;
         }
         break;
@@ -700,7 +598,7 @@
         if (ctx->m_max_textureSize != 0) {
             *ptr = ctx->m_max_textureSize;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_max_textureSize = *ptr;
         }
         break;
@@ -708,7 +606,7 @@
         if (ctx->m_max_3d_textureSize != 0) {
             *ptr = ctx->m_max_3d_textureSize;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_max_3d_textureSize = *ptr;
         }
         break;
@@ -716,7 +614,7 @@
         if (ctx->m_ssbo_offset_align != 0) {
             *ptr = ctx->m_ssbo_offset_align;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_ssbo_offset_align = *ptr;
         }
         break;
@@ -724,7 +622,7 @@
         if (ctx->m_ubo_offset_align != 0) {
             *ptr = ctx->m_ubo_offset_align;
         } else {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
             ctx->m_ubo_offset_align = *ptr;
         }
         break;
@@ -736,31 +634,9 @@
     case GL_MAX_DEPTH_TEXTURE_SAMPLES:
         *ptr = 4;
         break;
-    // Checks for version-incompatible enums.
-    // Not allowed in vanilla ES 2.0.
-    case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
-    case GL_MAX_UNIFORM_BUFFER_BINDINGS:
-        SET_ERROR_IF(ctx->majorVersion() < 3, GL_INVALID_ENUM);
-        ctx->safe_glGetIntegerv(param, ptr);
-        break;
-    case GL_MAX_COLOR_ATTACHMENTS:
-    case GL_MAX_DRAW_BUFFERS:
-        SET_ERROR_IF(ctx->majorVersion() < 3 &&
-                     !ctx->hasExtension("GL_EXT_draw_buffers"), GL_INVALID_ENUM);
-        ctx->safe_glGetIntegerv(param, ptr);
-        break;
-    // Not allowed in ES 3.0.
-    case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
-    case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
-    case GL_MAX_VERTEX_ATTRIB_BINDINGS:
-        SET_ERROR_IF(ctx->majorVersion() < 3 ||
-                     (ctx->majorVersion() == 3 &&
-                      ctx->minorVersion() == 0), GL_INVALID_ENUM);
-        ctx->safe_glGetIntegerv(param, ptr);
-        break;
     default:
         if (!ctx->m_state->getClientStateParameter<GLint>(param, ptr)) {
-            ctx->safe_glGetIntegerv(param, ptr);
+            ctx->m_glGetIntegerv_enc(self, param, ptr);
         }
         break;
     }
@@ -795,7 +671,7 @@
     case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
     case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
     case GL_MAX_TEXTURE_IMAGE_UNITS:
-        ctx->safe_glGetFloatv(param, ptr);
+        ctx->m_glGetFloatv_enc(self, param, ptr);
         *ptr = MIN(*ptr, (GLfloat)GLClientState::MAX_TEXTURE_UNITS);
         break;
 
@@ -808,7 +684,7 @@
 
     default:
         if (!ctx->m_state->getClientStateParameter<GLfloat>(param, ptr)) {
-            ctx->safe_glGetFloatv(param, ptr);
+            ctx->m_glGetFloatv_enc(self, param, ptr);
         }
         break;
     }
@@ -850,7 +726,7 @@
 
     default:
         if (!ctx->m_state->getClientStateParameter<GLboolean>(param, ptr)) {
-            ctx->safe_glGetBooleanv(param, ptr);
+            ctx->m_glGetBooleanv_enc(self, param, ptr);
         }
         *ptr = (*ptr != 0) ? GL_TRUE : GL_FALSE;
         break;
@@ -1437,7 +1313,7 @@
     ctx->m_glLinkProgram_enc(self, program);
 
     GLint linkStatus = 0;
-    ctx->glGetProgramiv(self, program, GL_LINK_STATUS, &linkStatus);
+    ctx->glGetProgramiv(self,program,GL_LINK_STATUS,&linkStatus);
     if (!linkStatus) {
         return;
     }
@@ -4264,7 +4140,7 @@
         break;
     }
 
-    ctx->safe_glGetIntegeri_v(target, index, params);
+    ctx->m_glGetIntegeri_v_enc(self, target, index, params);
 }
 
 void GL2Encoder::s_glGetInteger64i_v(void* self, GLenum target, GLuint index, GLint64* params) {
@@ -4313,17 +4189,7 @@
         break;
     }
 
-    ctx->safe_glGetInteger64i_v(target, index, params);
-}
-
-void GL2Encoder::s_glGetInteger64v(void* self, GLenum param, GLint64* val) {
-    GL2Encoder *ctx = (GL2Encoder *)self;
-    ctx->safe_glGetInteger64v(param, val);
-}
-
-void GL2Encoder::s_glGetBooleani_v(void* self, GLenum param, GLuint index, GLboolean* val) {
-    GL2Encoder *ctx = (GL2Encoder *)self;
-    ctx->safe_glGetBooleani_v(param, index, val);
+    ctx->m_glGetInteger64i_v_enc(self, target, index, params);
 }
 
 void GL2Encoder::s_glGetShaderiv(void* self, GLuint shader, GLenum pname, GLint* params) {
@@ -4394,7 +4260,7 @@
     ctx->m_shared->associateGLShaderProgram(res, spDataId);
 
     GLint numUniforms = 0;
-    ctx->glGetProgramiv(self, res, GL_ACTIVE_UNIFORMS, &numUniforms);
+    ctx->glGetProgramiv(ctx, res, GL_ACTIVE_UNIFORMS, &numUniforms);
     ctx->m_shared->initShaderProgramData(res, numUniforms);
 
     GLint maxLength=0;
diff --git a/system/GLESv2_enc/GL2Encoder.h b/system/GLESv2_enc/GL2Encoder.h
index 3084713..11162ee 100644
--- a/system/GLESv2_enc/GL2Encoder.h
+++ b/system/GLESv2_enc/GL2Encoder.h
@@ -30,13 +30,6 @@
     void setClientState(GLClientState *state) {
         m_state = state;
     }
-    void setVersion(int major, int minor,
-                    int deviceMajor, int deviceMinor) {
-        m_currMajorVersion = major;
-        m_currMinorVersion = minor;
-        m_deviceMajorVersion = deviceMajor;
-        m_deviceMinorVersion = deviceMinor;
-    }
     void setClientStateMakeCurrent(GLClientState *state,
                                    int majorVersion,
                                    int minorVersion,
@@ -135,21 +128,6 @@
     bool isCompleteFbo(GLenum target, const GLClientState* state, GLenum attachment) const;
     bool checkFramebufferCompleteness(GLenum target, const GLClientState* state) const;
 
-    // Utility classes for safe queries that
-    // need access to private class members
-    class ErrorUpdater;
-    template<class T> class ScopedQueryUpdate;
-    
-    // General queries
-    void safe_glGetBooleanv(GLenum param, GLboolean *val);
-    void safe_glGetFloatv(GLenum param, GLfloat *val);
-    void safe_glGetIntegerv(GLenum param, GLint *val);
-    void safe_glGetInteger64v(GLenum param, GLint64 *val);
-    void safe_glGetIntegeri_v(GLenum param, GLuint index, GLint *val);
-    void safe_glGetInteger64i_v(GLenum param, GLuint index, GLint64 *val);
-    void safe_glGetBooleani_v(GLenum param, GLuint index, GLboolean *val);
-
-    // API implementation
     glGetError_client_proc_t    m_glGetError_enc;
     static GLenum s_glGetError(void * self);
 
@@ -183,6 +161,7 @@
     glDrawElements_client_proc_t m_glDrawElements_enc;
     static void s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices);
 
+
     glGetIntegerv_client_proc_t m_glGetIntegerv_enc;
     static void s_glGetIntegerv(void *self, GLenum pname, GLint *ptr);
 
@@ -192,12 +171,6 @@
     glGetBooleanv_client_proc_t m_glGetBooleanv_enc;
     static void s_glGetBooleanv(void *self, GLenum pname, GLboolean *ptr);
 
-    glGetInteger64v_client_proc_t m_glGetInteger64v_enc;
-    static void s_glGetInteger64v(void* self, GLenum param, GLint64* val);
-
-    glGetBooleani_v_client_proc_t m_glGetBooleani_v_enc;
-    static void s_glGetBooleani_v(void* self, GLenum param, GLuint index, GLboolean* val);
-
     glVertexAttribPointer_client_proc_t m_glVertexAttribPointer_enc;
     static void s_glVertexAttribPointer(void *self, GLuint indx, GLint size, GLenum type,
                                         GLboolean normalized, GLsizei stride, const GLvoid * ptr);
diff --git a/system/OpenglSystemCommon/Android.mk b/system/OpenglSystemCommon/Android.mk
index 45b37a2..9305119 100644
--- a/system/OpenglSystemCommon/Android.mk
+++ b/system/OpenglSystemCommon/Android.mk
@@ -11,13 +11,13 @@
     QemuPipeStream.cpp \
     ThreadInfo.cpp
 
-ifdef IS_AT_LEAST_PPD1
+ifdef IS_AT_LEAST_OPD1
 LOCAL_HEADER_LIBRARIES += libnativebase_headers
 
 $(call emugl-export,HEADER_LIBRARIES,libnativebase_headers)
 endif
 
-ifdef IS_AT_LEAST_PPD1
+ifdef IS_AT_LEAST_OPD1
 LOCAL_HEADER_LIBRARIES += libhardware_headers
 $(call emugl-export,HEADER_LIBRARIES,libhardware_headers)
 endif
diff --git a/system/egl/Android.mk b/system/egl/Android.mk
index bafc310..2d7a559 100644
--- a/system/egl/Android.mk
+++ b/system/egl/Android.mk
@@ -13,13 +13,14 @@
     egl.cpp \
     ClientAPIExts.cpp
 
-ifdef IS_AT_LEAST_PPD1
+ifdef IS_AT_LEAST_OPD1
 LOCAL_SHARED_LIBRARIES += libdl libnativewindow
 else
 LOCAL_SHARED_LIBRARIES += libdl
 endif
 
-ifdef IS_AT_LEAST_PPD1
+ifdef IS_AT_LEAST_OPD1
+LOCAL_SHARED_LIBRARIES += libui
 LOCAL_HEADER_LIBRARIES += libnativebase_headers
 endif
 
diff --git a/system/egl/egl.cpp b/system/egl/egl.cpp
index 185fbc9..66a8a45 100644
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -1561,13 +1561,6 @@
             ClientAPIExts::initClientFuncs(s_display.gles2_iface(), 1);
         }
         if (contextState->needsInitFromCaps()) {
-            // Need to set the version first if
-            // querying caps, or validation will trip incorrectly.
-            hostCon->gl2Encoder()->setVersion(
-                context->majorVersion,
-                context->minorVersion,
-                context->deviceMajorVersion,
-                context->deviceMinorVersion);
             // Get caps for indexed buffers from host.
             // Some need a current context.
             int max_transform_feedback_separate_attribs = 0;
@@ -1605,7 +1598,7 @@
                     max_draw_buffers);
         }
 
-        // update the client state, share group, and version
+        // set the client state and share group
         if (context->majorVersion > 1) {
             hostCon->gl2Encoder()->setClientStateMakeCurrent(
                     contextState,
diff --git a/system/gralloc/gralloc.cpp b/system/gralloc/gralloc.cpp
index 7c51667..0b6785e 100644
--- a/system/gralloc/gralloc.cpp
+++ b/system/gralloc/gralloc.cpp
@@ -27,7 +27,6 @@
 #include "HostConnection.h"
 #include "ProcessPipe.h"
 #include "glUtils.h"
-#include <utils/CallStack.h>
 #include <cutils/log.h>
 #include <cutils/properties.h>
 
@@ -605,11 +604,7 @@
         }
     }
 
-    // API26 always expect at least one file descriptor is associated with
-    // one color buffer
-    // BUG: 37719038
-    if (PLATFORM_SDK_VERSION >= 26 ||
-        sw_read || sw_write || hw_cam_write || hw_vid_enc_read) {
+    if (sw_read || sw_write || hw_cam_write || hw_vid_enc_read) {
         // keep space for image on guest memory if SW access is needed
         // or if the camera is doing writing
         if (yuv_format) {
@@ -1486,15 +1481,6 @@
  *
  * If not, then load gralloc.default instead as a fallback.
  */
-
-#if __LP64__
-static const char kGrallocDefaultSystemPath[] = "/system/lib64/hw/gralloc.default.so";
-static const char kGrallocDefaultVendorPath[] = "/vendor/lib64/hw/gralloc.default.so";
-#else
-static const char kGrallocDefaultSystemPath[] = "/system/lib/hw/gralloc.default.so";
-static const char kGrallocDefaultVendorPath[] = "/vendor/lib/hw/gralloc.default.so";
-#endif
-
 static void
 fallback_init(void)
 {
@@ -1508,17 +1494,12 @@
     if (atoi(prop) == 1) {
         return;
     }
-    ALOGD("Emulator without host-side GPU emulation detected. "
-          "Loading gralloc.default.so from %s...",
-          kGrallocDefaultVendorPath);
-    module = dlopen(kGrallocDefaultVendorPath, RTLD_LAZY | RTLD_LOCAL);
-    if (!module) {
-        // vendor folder didn't work. try system
-        ALOGD("gralloc.default.so not found in /vendor. Trying %s...",
-              kGrallocDefaultSystemPath);
-        module = dlopen(kGrallocDefaultSystemPath, RTLD_LAZY | RTLD_LOCAL);
-    }
-
+    ALOGD("Emulator without host-side GPU emulation detected.");
+#if __LP64__
+    module = dlopen("/vendor/lib64/hw/gralloc.default.so", RTLD_LAZY|RTLD_LOCAL);
+#else
+    module = dlopen("/vendor/lib/hw/gralloc.default.so", RTLD_LAZY|RTLD_LOCAL);
+#endif
     if (module != NULL) {
         sFallback = reinterpret_cast<gralloc_module_t*>(dlsym(module, HAL_MODULE_INFO_SYM_AS_STR));
         if (sFallback == NULL) {
@@ -1526,6 +1507,6 @@
         }
     }
     if (sFallback == NULL) {
-        ALOGE("FATAL: Could not find gralloc.default.so!");
+        ALOGE("Could not find software fallback module!?");
     }
 }