GLESv2 translator: don't delete EGLImage textures

Copy changes faaf1553cfa39c23ceb198ba7edbd46ff3a11f7a and
f37a7ed6c5c609a3afc33f81bf50893362917ae6 from the GLESv1 translator to
the GLESv2 translator. After this, both translators use the same logic
for glEGLImageTargetTexture2DOES().

Change-Id: I0a95bf2301df7b7428abc593f38170edf4cbda30
diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp
index f1833d8..8ba7234 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmImp.cpp
@@ -1682,6 +1682,7 @@
             texData->internalFormat = img->internalFormat;
             texData->sourceEGLImage = (unsigned int)image;
             texData->eglImageDetach = s_eglIface->eglDetachEGLImage;
+            texData->oldGlobal = oldGlobal;
         }
     }
 }
diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp
index 3c48a43..f547782 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp
@@ -1,7 +1,7 @@
 /*
-* Copyright(C) 2011 The Android Open Source Project
+* Copyright (C) 2011 The Android Open Source Project
 *
-* Licensed under the Apache License, Version 2.0(the "License"){    GET_CTX();}
+* Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
@@ -2017,15 +2017,22 @@
         if (ctx->shareGroup().Ptr()) {
             ObjectLocalName tex = TextureLocalName(target,ctx->getBindedTexture(target));
             unsigned int oldGlobal = ctx->shareGroup()->getGlobalName(TEXTURE, tex);
-            // Delete old texture object
+            // Delete old texture object but only if it is not a target of a EGLImage
             if (oldGlobal) {
-                ctx->dispatcher().glDeleteTextures(1, &oldGlobal);
+                TextureData* oldTexData = getTextureData(tex);
+                if (!oldTexData || oldTexData->sourceEGLImage == 0) {
+                    ctx->dispatcher().glDeleteTextures(1, &oldGlobal);
+                }
             }
             // replace mapping and bind the new global object
             ctx->shareGroup()->replaceGlobalName(TEXTURE, tex,img->globalTexName);
             ctx->dispatcher().glBindTexture(GL_TEXTURE_2D, img->globalTexName);
             TextureData *texData = getTextureTargetData(target);
             SET_ERROR_IF(texData==NULL,GL_INVALID_OPERATION);
+            texData->width = img->width;
+            texData->height = img->height;
+            texData->border = img->border;
+            texData->internalFormat = img->internalFormat;
             texData->sourceEGLImage = (unsigned int)image;
             texData->eglImageDetach = s_eglIface->eglDetachEGLImage;
             texData->oldGlobal = oldGlobal;