Support GLES acceleration in 64bit emulator on device side

Support both 32bit and 64bit emulator GLES acceleration.

Change-Id: Ibd8b970d23937ae40732324706074ff00f433a14
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
diff --git a/opengl/system/GLESv1_enc/GLEncoder.cpp b/opengl/system/GLESv1_enc/GLEncoder.cpp
index 4414f24..989c26f 100644
--- a/opengl/system/GLESv1_enc/GLEncoder.cpp
+++ b/opengl/system/GLESv1_enc/GLEncoder.cpp
@@ -464,19 +464,19 @@
                 switch(i) {
                 case GLClientState::VERTEX_LOCATION:
                     this->glVertexPointerOffset(this, state->size, state->type, state->stride,
-                                                (GLuint)state->data + firstIndex);
+                                                (uintptr_t)state->data + firstIndex);
                     break;
                 case GLClientState::NORMAL_LOCATION:
                     this->glNormalPointerOffset(this, state->type, state->stride,
-                                                (GLuint) state->data + firstIndex);
+                                                (uintptr_t)state->data + firstIndex);
                     break;
                 case GLClientState::POINTSIZE_LOCATION:
                     this->glPointSizePointerOffset(this, state->type, state->stride,
-                                                   (GLuint) state->data + firstIndex);
+                                                   (uintptr_t)state->data + firstIndex);
                     break;
                 case GLClientState::COLOR_LOCATION:
                     this->glColorPointerOffset(this, state->size, state->type, state->stride,
-                                               (GLuint) state->data + firstIndex);
+                                               (uintptr_t)state->data + firstIndex);
                     break;
                 case GLClientState::TEXCOORD0_LOCATION:
                 case GLClientState::TEXCOORD1_LOCATION:
@@ -487,17 +487,17 @@
                 case GLClientState::TEXCOORD6_LOCATION:
                 case GLClientState::TEXCOORD7_LOCATION:
                     this->glTexCoordPointerOffset(this, state->size, state->type, state->stride,
-                                                  (GLuint) state->data + firstIndex);
+                                                  (uintptr_t)state->data + firstIndex);
                     break;
                 case GLClientState::WEIGHT_LOCATION:
                     this->glWeightPointerOffset(this,state->size,state->type,state->stride,
-                                                (GLuint)state->data+firstIndex);
+                                                (uintptr_t)state->data+firstIndex);
                     break;
                 case GLClientState::MATRIXINDEX_LOCATION:
                     this->glMatrixIndexPointerOffset(this,state->size,state->type,state->stride,
-                                              (GLuint)state->data+firstIndex);
+                                              (uintptr_t)state->data+firstIndex);
                     break;
-                }                
+                }
                 this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, m_state->currentArrayVbo());
             }
         } else {
@@ -545,14 +545,14 @@
         if (!has_immediate_arrays) {
             ctx->sendVertexData(0, count);
             ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, ctx->m_state->currentIndexVbo());
-            ctx->glDrawElementsOffset(ctx, mode, count, type, (GLuint)indices);
+            ctx->glDrawElementsOffset(ctx, mode, count, type, (uintptr_t)indices);
             adjustIndices = false;
         } else {
             BufferData * buf = ctx->m_shared->getBufferData(ctx->m_state->currentIndexVbo());
             ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, 0);
             indices = (void*)((GLintptr)buf->m_fixedBuffer.ptr() + (GLintptr)indices);
         }
-    } 
+    }
     if (adjustIndices) {
         void *adjustedIndices = (void*)indices;
         int minIndex = 0, maxIndex = 0;
diff --git a/opengl/system/GLESv2_enc/GL2Encoder.cpp b/opengl/system/GLESv2_enc/GL2Encoder.cpp
index 7fc32b5..0f5abdd 100644
--- a/opengl/system/GLESv2_enc/GL2Encoder.cpp
+++ b/opengl/system/GLESv2_enc/GL2Encoder.cpp
@@ -430,7 +430,7 @@
             } else {
                 this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, state->bufferObject);
                 this->glVertexAttribPointerOffset(this, i, state->size, state->type, state->normalized, state->stride,
-                                                  (GLuint) state->data + firstIndex);
+                                                  (uintptr_t) state->data + firstIndex);
                 this->m_glBindBuffer_enc(this, GL_ARRAY_BUFFER, m_state->currentArrayVbo());
             }
         } else {
@@ -479,7 +479,7 @@
         if (!has_immediate_arrays) {
             ctx->sendVertexAttributes(0, count);
             ctx->m_glBindBuffer_enc(self, GL_ELEMENT_ARRAY_BUFFER, ctx->m_state->currentIndexVbo());
-            ctx->glDrawElementsOffset(ctx, mode, count, type, (GLuint)indices);
+            ctx->glDrawElementsOffset(ctx, mode, count, type, (uintptr_t)indices);
             adjustIndices = false;
         } else {
             BufferData * buf = ctx->m_shared->getBufferData(ctx->m_state->currentIndexVbo());
diff --git a/opengl/system/OpenglSystemCommon/ThreadInfo.h b/opengl/system/OpenglSystemCommon/ThreadInfo.h
index 0328733..f59ce2a 100644
--- a/opengl/system/OpenglSystemCommon/ThreadInfo.h
+++ b/opengl/system/OpenglSystemCommon/ThreadInfo.h
@@ -40,10 +40,10 @@
     // We have a dedicated TLS slot in bionic
     inline EGLThreadInfo* getEGLThreadInfo() {
         EGLThreadInfo *tInfo =
-             (EGLThreadInfo *)(((unsigned *)__get_tls())[TLS_SLOT_OPENGL]);
+             (EGLThreadInfo *)(((uintptr_t *)__get_tls())[TLS_SLOT_OPENGL]);
         if (!tInfo) {
             tInfo = slow_getEGLThreadInfo();
-            ((uint32_t *)__get_tls())[TLS_SLOT_OPENGL] = (uint32_t)tInfo;
+            ((uintptr_t *)__get_tls())[TLS_SLOT_OPENGL] = (uintptr_t)tInfo;
         }
         return tInfo;
     }
diff --git a/opengl/system/OpenglSystemCommon/gralloc_cb.h b/opengl/system/OpenglSystemCommon/gralloc_cb.h
index fd35473..c138964 100644
--- a/opengl/system/OpenglSystemCommon/gralloc_cb.h
+++ b/opengl/system/OpenglSystemCommon/gralloc_cb.h
@@ -96,7 +96,7 @@
     int glType;             // OpenGL type enum used when uploading to host
     int ashmemSize;         // ashmem region size for the buffer (0 unless is HW_FB buffer or
                             //                                    s/w access is needed)
-    int ashmemBase;         // CPU address of the mapped ashmem region
+    intptr_t ashmemBase;         // CPU address of the mapped ashmem region
     int ashmemBasePid;      // process id which mapped the ashmem region
     int mappedPid;          // process id which succeeded gralloc_register call
     int lockedLeft;         // region of buffer locked for s/w write
diff --git a/opengl/system/egl/egl.cpp b/opengl/system/egl/egl.cpp
index cf3df52..72e0037 100644
--- a/opengl/system/egl/egl.cpp
+++ b/opengl/system/egl/egl.cpp
@@ -86,7 +86,7 @@
 #endif //LOG_EGL_ERRORS
 
 #define VALIDATE_CONFIG(cfg,ret) \
-    if(((int)cfg<0)||((int)cfg>s_display.getNumConfigs())) { \
+    if(((intptr_t)cfg<0)||((intptr_t)cfg>s_display.getNumConfigs())) { \
         RETURN_ERROR(ret,EGL_BAD_CONFIG); \
     }
 
@@ -268,7 +268,7 @@
     }
 
     DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
-    rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uint32_t)config,
+    rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uintptr_t)config,
             getWidth(), getHeight());
     if (!rcSurface) {
         ALOGE("rcCreateWindowSurface returned 0");
@@ -371,7 +371,7 @@
 {
     DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
 
-    rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uint32_t)config,
+    rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uintptr_t)config,
             getWidth(), getHeight());
     if (!rcSurface) {
         ALOGE("rcCreateWindowSurface returned 0");
@@ -563,7 +563,7 @@
         return EGL_TRUE;
     }
 
-    int i=0;
+    uintptr_t i=0;
     for (i=0 ; i<numConfigs && i<config_size ; i++) {
         *configs++ = (EGLConfig)i;
     }
@@ -585,8 +585,15 @@
         attribs_size++; //for the terminating EGL_NONE
     }
 
+    uint32_t* tempConfigs[config_size];
     DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
-    *num_config = rcEnc->rcChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size * sizeof(EGLint), (uint32_t*)configs, config_size);
+    *num_config = rcEnc->rcChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size * sizeof(EGLint), (uint32_t*)tempConfigs, config_size);
+    if (configs!=NULL) {
+        EGLint i=0;
+        for (i=0;i<(*num_config);i++) {
+             *((uintptr_t*)configs+i) = *((uint32_t*)tempConfigs+i);
+        }
+    }
 
     if (*num_config <= 0)
         return EGL_FALSE;
@@ -875,7 +882,7 @@
     }
 
     DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_NO_CONTEXT);
-    uint32_t rcContext = rcEnc->rcCreateContext(rcEnc, (uint32_t)config, rcShareCtx, version);
+    uint32_t rcContext = rcEnc->rcCreateContext(rcEnc, (uintptr_t)config, rcShareCtx, version);
     if (!rcContext) {
         ALOGE("rcCreateContext returned 0");
         setErrorReturn(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
diff --git a/opengl/system/egl/eglDisplay.cpp b/opengl/system/egl/eglDisplay.cpp
index bcb0d4b..96540aa 100644
--- a/opengl/system/egl/eglDisplay.cpp
+++ b/opengl/system/egl/eglDisplay.cpp
@@ -84,9 +84,15 @@
         //
         // load GLES client API
         //
+#if __LP64__
+        m_gles_iface = loadGLESClientAPI("/system/lib64/egl/libGLESv1_CM_emulation.so",
+                                         eglIface,
+                                         &s_gles_lib);
+#else
         m_gles_iface = loadGLESClientAPI("/system/lib/egl/libGLESv1_CM_emulation.so",
                                          eglIface,
                                          &s_gles_lib);
+#endif
         if (!m_gles_iface) {
             pthread_mutex_unlock(&m_lock);
             ALOGE("Failed to load gles1 iface");
@@ -94,9 +100,15 @@
         }
 
 #ifdef WITH_GLES2
+#if __LP64__
+        m_gles2_iface = loadGLESClientAPI("/system/lib64/egl/libGLESv2_emulation.so",
+                                          eglIface,
+                                          &s_gles2_lib);
+#else
         m_gles2_iface = loadGLESClientAPI("/system/lib/egl/libGLESv2_emulation.so",
                                           eglIface,
                                           &s_gles2_lib);
+#endif
         // Note that if loading gles2 failed, we can still run with no
         // GLES2 support, having GLES2 is not mandatory.
 #endif
@@ -189,7 +201,7 @@
 
 void eglDisplay::processConfigs()
 {
-    for (int i=0; i<m_numConfigs; i++) {
+    for (intptr_t i=0; i<m_numConfigs; i++) {
         EGLConfig config = (EGLConfig)i;
         //Setup the EGL_NATIVE_VISUAL_ID attribute
         PixelFormat format;
@@ -401,7 +413,7 @@
         ALOGE("[%s] Bad attribute idx\n", __FUNCTION__);
         return EGL_FALSE;
     }
-    *value = *(m_configs + (int)config*m_numConfigAttribs + attribIdx);
+    *value = *(m_configs + (intptr_t)config*m_numConfigAttribs + attribIdx);
     return EGL_TRUE;
 }
 
@@ -434,7 +446,7 @@
         ALOGE("[%s] Bad attribute idx\n", __FUNCTION__);
         return EGL_FALSE;
     }
-    *(m_configs + (int)config*m_numConfigAttribs + attribIdx) = value;
+    *(m_configs + (intptr_t)config*m_numConfigAttribs + attribIdx) = value;
     return EGL_TRUE;
 }
 
diff --git a/opengl/system/gralloc/gralloc.cpp b/opengl/system/gralloc/gralloc.cpp
index 75909bd..2bdf8da 100644
--- a/opengl/system/gralloc/gralloc.cpp
+++ b/opengl/system/gralloc/gralloc.cpp
@@ -446,7 +446,7 @@
     DEFINE_AND_VALIDATE_HOST_CONNECTION;
 
     // increment the post count of the buffer
-    uint32_t *postCountPtr = (uint32_t *)cb->ashmemBase;
+    intptr_t *postCountPtr = (intptr_t *)cb->ashmemBase;
     if (!postCountPtr) {
         // This should not happen
         return -EINVAL;
@@ -638,7 +638,7 @@
         return -EINVAL;
     }
 
-    EGLint postCount = 0;
+    intptr_t postCount = 0;
     void *cpu_addr = NULL;
 
     //
@@ -652,8 +652,8 @@
         }
 
         if (cb->canBePosted()) {
-            postCount = *((int *)cb->ashmemBase);
-            cpu_addr = (void *)(cb->ashmemBase + sizeof(int));
+            postCount = *((intptr_t *)cb->ashmemBase);
+            cpu_addr = (void *)(cb->ashmemBase + sizeof(intptr_t));
         }
         else {
             cpu_addr = (void *)(cb->ashmemBase);