opengl translator: added EGL_RENDERABLE_TYPE attrib

fixing bug in eglChooseConfig, there was no referer to
EGL_RENDERABLE_TYPE this caused the eglChooseConfig to fail
when an attribute EGL_RENDERABLE_TYPE was specified in
the attrib_list

Change-Id: Ib4635a55ef3cc0ff380e581d4a41602ddfd32f82
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp
index 609e231..9fcdf64 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp
@@ -27,6 +27,7 @@
                      EGLint     max_pbuffer_height,
                      EGLint     max_pbuffer_size,
                      EGLBoolean native_renderable,
+                     EGLint     renderable_type,
                      EGLint     native_visual_id,
                      EGLint     native_visual_type,
                      EGLint     samples_per_pixel,
@@ -55,6 +56,7 @@
                      m_max_swap_interval(MAX_SWAP_INTERVAL),
                      m_min_swap_interval(MIN_SWAP_INTERVAL),
                      m_native_renderable(native_renderable),
+                     m_renderable_type(renderable_type),
                      m_native_visual_id(native_visual_id),
                      m_native_visual_type(native_visual_type),
                      m_sample_buffers_num(samples_per_pixel > 0 ?1:0),
@@ -85,6 +87,7 @@
                                                 m_max_swap_interval(conf.m_max_swap_interval),
                                                 m_min_swap_interval(conf.m_min_swap_interval),
                                                 m_native_renderable(conf.m_native_renderable),
+                                                m_renderable_type(conf.m_renderable_type),
                                                 m_native_visual_id(conf.m_native_visual_id),
                                                 m_native_visual_type(conf.m_native_visual_type),
                                                 m_sample_buffers_num(conf.m_sample_buffers_num),
@@ -158,6 +161,8 @@
     case EGL_NATIVE_VISUAL_TYPE:
         *val = m_native_visual_type;
         break;
+    case EGL_RENDERABLE_TYPE:
+        *val = m_renderable_type;
     case EGL_SAMPLE_BUFFERS:
         *val = m_sample_buffers_num;
         break;
@@ -279,6 +284,9 @@
    if(dummy.m_surface_type != EGL_DONT_CARE &&
     ((dummy.m_surface_type & m_surface_type) != dummy.m_surface_type)) return false;
 
+   if(dummy.m_renderable_type != EGL_DONT_CARE &&
+    ((dummy.m_renderable_type & m_renderable_type) != dummy.m_renderable_type)) return false;
+
    //passed all checks
    return true;
 }
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h
index c77c334..e45681b 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h
@@ -45,6 +45,7 @@
               EGLint max_pbuffer_height,
               EGLint max_pbuffer_size,
               EGLBoolean native_renderable,
+              EGLint renderable_type,
               EGLint native_visual_id,
               EGLint native_visual_type,
               EGLint samples_per_pixel,
@@ -78,6 +79,7 @@
     const EGLint                    m_max_swap_interval;
     const EGLint                    m_min_swap_interval;
     const EGLBoolean                m_native_renderable;
+    const EGLint                    m_renderable_type;
     const EGLint                    m_native_visual_id;
     const EGLint                    m_native_visual_type;
     const EGLint                    m_sample_buffers_num;
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp
index 1ed7c59..9f3e8cc 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp
@@ -35,10 +35,10 @@
 
 EGLNativeDisplayType EglDisplay::nativeType(){return m_dpy;}
 
-void EglDisplay::initialize() {
+void EglDisplay::initialize(int renderableType) {
     android::Mutex::Autolock mutex(m_lock);
     m_initialized = true;
-    initConfigurations();
+    initConfigurations(renderableType);
     m_configInitialized = true;
 }
 
@@ -55,9 +55,9 @@
     return *first < *second ;
 }
 
-void EglDisplay::initConfigurations() {
+void EglDisplay::initConfigurations(int renderableType) {
     if(m_configInitialized) return;
-    EglOS::queryConfigs(m_dpy,m_configs);
+    EglOS::queryConfigs(m_dpy,renderableType,m_configs);
     m_configs.sort(compareEglConfigsPtrs);
 }
 
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h
index 81e82e1..28e4abe 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h
@@ -58,7 +58,7 @@
     ObjectNameManager* getManager(GLESVersion ver){ return &m_manager[ver];}
 
     ~EglDisplay();
-    void initialize();
+    void initialize(int renderableType);
     void terminate();
     bool isInitialize();
 
@@ -67,7 +67,7 @@
     bool destroyImageKHR(EGLImageKHR img);
 
 private:
-   void initConfigurations();
+   void initConfigurations(int renderableType);
 
    EGLNativeDisplayType   m_dpy;
    bool                   m_initialized;
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
index 431b1c9..8f3bc66 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
@@ -179,6 +179,7 @@
     if(minor) *minor = MINOR;
 
     __translator_getGLESIfaceFunc func  = NULL;
+    int renderableType = EGL_OPENGL_ES_BIT;
 
     if(!g_eglInfo->getIface(GLES_1_1)) {
         func  = loadIfaces(LIB_GLES_CM_NAME);
@@ -192,13 +193,13 @@
     if(!g_eglInfo->getIface(GLES_2_0)) {
         func  = loadIfaces(LIB_GLES_V2_NAME);
         if(func){
+            renderableType |= EGL_OPENGL_ES2_BIT;
             g_eglInfo->setIface(func(&s_eglIface),GLES_2_0);
         } else {
            fprintf(stderr,"could not find ifaces for GLES 2.0\n");
-           return EGL_FALSE;
         }
     }
-    dpy->initialize();
+    dpy->initialize(renderableType);
     return EGL_TRUE;
 }
 
@@ -253,6 +254,7 @@
 
         //selection defaults
         EGLint      surface_type       = EGL_WINDOW_BIT;
+        EGLint      renderable_type    = EGL_OPENGL_ES_BIT;
         EGLBoolean  bind_to_tex_rgb    = EGL_DONT_CARE;
         EGLBoolean  bind_to_tex_rgba   = EGL_DONT_CARE;
         EGLenum     caveat             = EGL_DONT_CARE;
@@ -362,6 +364,9 @@
             case EGL_NATIVE_RENDERABLE:
                 native_renderable = attrib_list[i+1];
                 break;
+            case EGL_RENDERABLE_TYPE:
+                renderable_type = attrib_list[i+1];
+                break;
             case EGL_NATIVE_VISUAL_TYPE:
                 native_visual_type = attrib_list[i+1];
                 break;
@@ -424,7 +429,7 @@
     }
     EGLNativePixelFormatType tmpfrmt = PIXEL_FORMAT_INITIALIZER;
     EglConfig dummy(red_size,green_size,blue_size,alpha_size,caveat,config_id,depth_size,
-                    frame_buffer_level,0,0,0,native_renderable,0,native_visual_type,
+                    frame_buffer_level,0,0,0,native_renderable,renderable_type,0,native_visual_type,
                     samples_per_pixel,stencil_size,surface_type,transparent_type,
                     trans_red_val,trans_green_val,trans_blue_val,tmpfrmt);
 
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
index 041309b..d658e12 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
@@ -26,11 +26,11 @@
     return false;
 }
 
-EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,EGLNativePixelFormatType* frmt){
+EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,int renderableType,EGLNativePixelFormatType* frmt){
     return NULL;
 }
 
-void queryConfigs(EGLNativeDisplayType dpy,ConfigsList& listOut) {
+void queryConfigs(EGLNativeDisplayType dpy,int renderableType,ConfigsList& listOut) {
 }
 
 bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeWindowType win) {
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h
index 09d29f3..3e00c58 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h
@@ -32,7 +32,7 @@
 
 namespace EglOS{
 
-    void queryConfigs(EGLNativeDisplayType dpy,ConfigsList& listOut);
+    void queryConfigs(EGLNativeDisplayType dpy,int renderable_type,ConfigsList& listOut);
     bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb);
     bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx);
     bool releaseDisplay(EGLNativeDisplayType dpy);
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp
index 8734e5c..a4b2cc6 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglValidate.cpp
@@ -34,6 +34,7 @@
     case EGL_MAX_PBUFFER_PIXELS:
     case EGL_MAX_SWAP_INTERVAL:
     case EGL_MIN_SWAP_INTERVAL:
+    case EGL_RENDERABLE_TYPE:
     case EGL_NATIVE_RENDERABLE:
     case EGL_NATIVE_VISUAL_ID:
     case EGL_NATIVE_VISUAL_TYPE:
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp
index ddaf2aa..11cce61 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp
@@ -224,7 +224,7 @@
 
 
 
-EglConfig* pixelFormatToConfig(EGLNativeDisplayType display,EGLNativePixelFormatType* frmt,int index){
+EglConfig* pixelFormatToConfig(EGLNativeDisplayType display,int renderableType,EGLNativePixelFormatType* frmt,int index){
 
     EGLint  red,green,blue,alpha,depth,stencil;
     EGLint  supportedSurfaces,visualType,visualId;
@@ -287,12 +287,12 @@
     alpha   = frmt->cAlphaBits;
     depth   = frmt->cDepthBits;
     stencil = frmt->cStencilBits;
-    return new EglConfig(red,green,blue,alpha,caveat,(EGLint)index,depth,level,pMaxWidth,pMaxHeight,pMaxPixels,renderable,
+    return new EglConfig(red,green,blue,alpha,caveat,(EGLint)index,depth,level,pMaxWidth,pMaxHeight,pMaxPixels,renderable,renderableType,
                          visualId,visualType,samples,stencil,supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt);
 }
 
 
-void queryConfigs(EGLNativeDisplayType display,ConfigsList& listOut) {
+void queryConfigs(EGLNativeDisplayType display,int renderableType,ConfigsList& listOut) {
     PIXELFORMATDESCRIPTOR  pfd;
     int  iPixelFormat = 1;
     HDC dpy = display->getCurrentDC();
@@ -304,7 +304,7 @@
     //inserting rest of formats
     for(iPixelFormat;iPixelFormat < nFormats; iPixelFormat++) {
          DescribePixelFormat(dpy, iPixelFormat,sizeof(PIXELFORMATDESCRIPTOR), &pfd);
-         EglConfig* pConfig = pixelFormatToConfig(display,&pfd,iPixelFormat);
+         EglConfig* pConfig = pixelFormatToConfig(display,renderableType,&pfd,iPixelFormat);
          if(pConfig) listOut.push_back(pConfig);
     }
 
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp
index c863f88..a695d37 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp
@@ -68,7 +68,7 @@
     return XCloseDisplay(dpy);
 }
 
-EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,EGLNativePixelFormatType* frmt){
+EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,int renderableType,EGLNativePixelFormatType* frmt){
 
     int  bSize,red,green,blue,alpha,depth,stencil;
     int  supportedSurfaces,visualType,visualId;
@@ -133,15 +133,15 @@
 
 
     return new EglConfig(red,green,blue,alpha,caveat,configId,depth,level,pMaxWidth,pMaxHeight,
-                              pMaxPixels,renderable,visualId,visualType,samples,stencil,
+                              pMaxPixels,renderable,renderableType,visualId,visualType,samples,stencil,
                               supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt);
 }
 
-void queryConfigs(EGLNativeDisplayType dpy,ConfigsList& listOut) {
+void queryConfigs(EGLNativeDisplayType dpy,int renderableType,ConfigsList& listOut) {
     int n;
     EGLNativePixelFormatType*  frmtList =  glXGetFBConfigs(dpy,0,&n);
     for(int i =0 ;i < n ; i++) {
-        EglConfig* conf = pixelFormatToConfig(dpy,&frmtList[i]);
+        EglConfig* conf = pixelFormatToConfig(dpy,renderableType,&frmtList[i]);
         if(conf) listOut.push_back(conf);
     }
     XFree(frmtList);