opengl Translator: adding type EGLNativeSurfaceType

for supporting & storing spesific OS data of the surfaces
for example on Windows platform it is needed to save for each windowSurface
the HWNDL & HDC of the native window, this change caused changes in the EglOsApi
interface
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
index a3db30c..17fb33e 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
@@ -515,7 +515,7 @@
         RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE);
     }
 
-    EGLNativePbufferType pb = EglOS::createPbuffer(dpy->nativeType(),cfg,tmpPbSurfacePtr);
+    EGLNativeSurfaceType pb = EglOS::createPbufferSurface(dpy->nativeType(),cfg,tmpPbSurfacePtr);
     if(!pb) {
         //TODO: RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_VALUE); dont have bad value
         RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE);
@@ -558,7 +558,7 @@
     EglContext* currCtx = static_cast<EglContext*>(thread->eglContext);
     if((!currCtx) || (currCtx && !currCtx->usingSurface(surface))){
         if(surface->type() == EglSurface::PBUFFER) {
-            EglOS::releasePbuffer(dpy->nativeType(),reinterpret_cast<EGLNativePbufferType>(surface->native()));
+            EglOS::releasePbuffer(dpy->nativeType(),surface->native());
         }
         return true;
     }
@@ -727,21 +727,21 @@
         }
 
          EGLNativeDisplayType nativeDisplay = dpy->nativeType();
-         void* nativeRead = newReadPtr->native();
-         void* nativeDraw = newDrawPtr->native();
+         EGLNativeSurfaceType nativeRead = newReadPtr->native();
+         EGLNativeSurfaceType nativeDraw = newDrawPtr->native();
         //checking native window validity
-        if(newReadPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(nativeRead))) {
+        if(newReadPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,nativeRead)) {
             RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW);
         }
-        if(newDrawPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(nativeDraw))) {
+        if(newDrawPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,nativeDraw)) {
             RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW);
         }
 
         //checking native pixmap validity
-        if(newReadPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(nativeRead))) {
+        if(newReadPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,nativeRead)) {
             RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP);
         }
-        if(newDrawPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(nativeDraw))) {
+        if(newDrawPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,nativeDraw)) {
             RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP);
         }
         if(prevCtx) {
@@ -811,11 +811,11 @@
         RETURN_ERROR(EGL_TRUE,EGL_SUCCESS);
     }
 
-    if(!currentCtx || !currentCtx->usingSurface(Srfc) || !EglOS::validNativeWin(dpy->nativeType(),reinterpret_cast<EGLNativeWindowType>(Srfc.Ptr()->native()))) {
+    if(!currentCtx || !currentCtx->usingSurface(Srfc) || !EglOS::validNativeWin(dpy->nativeType(),Srfc.Ptr()->native())) {
         RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
     }
 
-    EglOS::swapBuffers(dpy->nativeType(),reinterpret_cast<EGLNativeWindowType>(Srfc->native()));
+    EglOS::swapBuffers(dpy->nativeType(),Srfc->native());
     return EGL_TRUE;
 }
 
@@ -827,7 +827,7 @@
         if(!currCtx->read().Ptr() || !currCtx->draw().Ptr() || currCtx->draw()->type()!=EglSurface::WINDOW) {
             RETURN_ERROR(EGL_FALSE,EGL_BAD_CURRENT_SURFACE);
         }
-        EglOS::swapInterval(dpy->nativeType(),reinterpret_cast<EGLNativeWindowType>(currCtx->draw()->native()),interval);
+        EglOS::swapInterval(dpy->nativeType(),currCtx->draw()->native(),interval);
     } else {
             RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
     }
@@ -902,21 +902,21 @@
         EGLNativeDisplayType nativeDisplay = dpy->nativeType();
         if(read.Ptr()) {
             if(read->type() == EglSurface::WINDOW &&
-               !EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(read->native()))) {
+               !EglOS::validNativeWin(nativeDisplay,read->native())) {
                 RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
             }
             if(read->type() == EglSurface::PIXMAP &&
-               !EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(read->native()))) {
+               !EglOS::validNativePixmap(nativeDisplay,read->native())) {
                 RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
             }
         }
         if(draw.Ptr()) {
             if(draw->type() == EglSurface::WINDOW &&
-               !EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(draw->native()))) {
+               !EglOS::validNativeWin(nativeDisplay,draw->native())) {
                 RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
             }
             if(draw->type() == EglSurface::PIXMAP &&
-               !EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(draw->native()))) {
+               !EglOS::validNativePixmap(nativeDisplay,draw->native())) {
                 RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
             }
         }
@@ -990,7 +990,7 @@
               EGLNativePixmapType target) {
     VALIDATE_DISPLAY(display);
     VALIDATE_SURFACE(surface,srfc);
-    if(!EglOS::validNativePixmap(dpy->nativeType(),target)) {
+    if(!EglOS::validNativePixmap(dpy->nativeType(),NULL)) {
         RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP);
     }
 
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
index 492589d..10f3f4a 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
@@ -108,8 +108,12 @@
     return nsGetWinDims(win,&width,&height);
 }
 
+bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeSurfaceType win) {
+    return validNativeWin(dpy,(EGLNativeWindowType)win);
+}
+
 //no support for pixmap in mac
-bool validNativePixmap(EGLNativeDisplayType dpy, EGLNativePixmapType pix) {
+bool validNativePixmap(EGLNativeDisplayType dpy, EGLNativeSurfaceType pix) {
 
    return true;
 }
@@ -131,17 +135,17 @@
     return false;
 }
 
-EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
+EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
     EGLint width,height,hasMipmap,tmp;
     EGLint target,format;
     srfc->getDim(&width,&height,&tmp);
     srfc->getTexInfo(&format,&target);
     srfc->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap);
     EGLint maxMipmap = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0;
-    return nsCreatePBuffer(target,format,maxMipmap,width,height);
+    return (EGLNativeSurfaceType)nsCreatePBuffer(target,format,maxMipmap,width,height);
 }
 
-bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb) {
+bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb) {
     nsDestroyPBuffer(pb);
     return true;
 }
@@ -188,14 +192,24 @@
     return true;
 }
 
-void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win) {
+void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc){
     nsSwapBuffers();
 }
 
 void waitNative(){}
 
-void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval){
+void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval){
     nsSwapInterval(&interval);
 }
 
+EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){
+    return (EGLNativeSurfaceType)wnd;
+}
+
+EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){
+    return (EGLNativeSurfaceType)pix;
+}
+
+void destroySurface(EGLNativeSurfaceType srfc){
+}
 };
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h
index 33813ab..8ad5d52 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglOsApi.h
@@ -34,21 +34,25 @@
 namespace EglOS{
 
     void queryConfigs(EGLNativeDisplayType dpy,int renderable_type,ConfigsList& listOut);
-    bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb);
+    bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb);
     bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx);
     bool releaseDisplay(EGLNativeDisplayType dpy);
+    bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win);
     bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win);
-    bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativePixmapType pix);
+    bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix);
     bool checkWindowPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height);
     bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height);
     bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType);
-    void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win);
-    void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval);
+    void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc);
+    void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval);
     void waitNative();
 
     EGLNativeDisplayType getDefaultDisplay();
-    EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* pb);
+    EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* pb);
     EGLNativeContextType createContext(EGLNativeDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext);
+    EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd);
+    EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix);
+    void destroySurface(EGLNativeSurfaceType srfc);
 #ifdef _WIN32
     void initPtrToWglFunctions();
 #endif
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h
index 9706714..184cc47 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglPbufferSurface.h
@@ -24,11 +24,9 @@
                                          m_texFormat(EGL_NO_TEXTURE),
                                          m_texTarget(EGL_NO_TEXTURE),
                                          m_texMipmap(EGL_FALSE),
-                                         m_largest(EGL_FALSE),
-                                         m_nativePbuffer(0){};
+                                         m_largest(EGL_FALSE){};
 
-    void* native(){ return (void*)m_nativePbuffer;};
-    void  setNativePbuffer(EGLNativePbufferType pb){ m_nativePbuffer = pb;};
+    void  setNativePbuffer(EGLNativeSurfaceType srfc){ m_native = srfc;};
     bool  setAttrib(EGLint attrib,EGLint val);
     bool  getAttrib(EGLint attrib,EGLint* val);
     void  getDim(EGLint* width,EGLint* height,EGLint* largest){
@@ -44,6 +42,5 @@
     EGLint               m_texTarget;
     EGLint               m_texMipmap;
     EGLint               m_largest;
-    EGLNativePbufferType m_nativePbuffer;
 };
 #endif
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp
index 37fdc12..245e23f 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.cpp
@@ -14,6 +14,7 @@
 * limitations under the License.
 */
 #include "EglPixmapSurface.h"
+#include "EglOsApi.h"
 
 std::set<EGLNativePixmapType> EglPixmapSurface::s_associatedPixmaps;
 
@@ -24,6 +25,7 @@
 
 EglPixmapSurface::EglPixmapSurface(EGLNativePixmapType pix,EglConfig* config):EglSurface(PIXMAP,config,0,0),m_pixmap(pix) {
     s_associatedPixmaps.insert(pix);
+    m_native = EglOS::createPixmapSurface(pix);
 }
 
 EglPixmapSurface::~EglPixmapSurface() {
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h
index bd1c26b..eb42fab 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglPixmapSurface.h
@@ -25,7 +25,6 @@
     EglPixmapSurface(EGLNativePixmapType pix,EglConfig* config);
     ~EglPixmapSurface();
 
-    void* native(){ return (void*)m_pixmap;};
     bool getAttrib(EGLint attrib,EGLint* val);
 
     static bool alreadyAssociatedWithConfig(EGLNativePixmapType pix);
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp
index 2de2432..27455d3 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.cpp
@@ -14,9 +14,14 @@
 * limitations under the License.
 */
 #include "EglSurface.h"
+#include "EglOsApi.h"
 
 unsigned int EglSurface::s_nextSurfaceHndl = 0;
 
+EglSurface::~EglSurface(){ 
+    if(m_native) EglOS::destroySurface(m_native);
+}
+
 bool  EglSurface::setAttrib(EGLint attrib,EGLint val) {
     switch(attrib) {
     case EGL_WIDTH:
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h
index 29a8843..3fc4840 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h
@@ -17,9 +17,9 @@
 #define EGL_SURFACE_H
 
 #include <EGL/egl.h>
+#include <EGL/eglinternalplatform.h>
 #include <map>
 #include <GLcommon/SmartPtr.h>
-
 #include "EglConfig.h"
 
 class EglSurface;
@@ -34,7 +34,7 @@
                   PIXMAP  = 3
                  } ESurfaceType;
   ESurfaceType  type(){ return m_type;};
-  virtual void* native() = 0;
+  EGLNativeSurfaceType native(){return m_native;}
   virtual bool  setAttrib(EGLint attrib,EGLint val);
   virtual bool  getAttrib(EGLint attrib,EGLint* val) = 0;
   void          setDim(int width,int height){ m_width = width; m_height = height;};
@@ -42,7 +42,7 @@
   bool          destroy(){return m_destroy;};
   EglConfig*    getConfig(){return m_config;};
   unsigned int  getHndl(){return m_hndl;};
-  virtual       ~EglSurface(){};
+  virtual       ~EglSurface();
 
 private:
     static unsigned int   s_nextSurfaceHndl;
@@ -55,9 +55,11 @@
                                                                                m_destroy(false),
                                                                                m_config(config),
                                                                                m_width(width),
-                                                                               m_height(height){ m_hndl = ++s_nextSurfaceHndl;};
-    EglConfig*   m_config;
-    EGLint       m_width;
-    EGLint       m_height;
+                                                                               m_height(height),
+                                                                               m_native(NULL){ m_hndl = ++s_nextSurfaceHndl;};
+    EglConfig*            m_config;
+    EGLint                m_width;
+    EGLint                m_height;
+    EGLNativeSurfaceType  m_native;
 };
 #endif
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp
index 0e07522..f32cb18 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.cpp
@@ -14,6 +14,7 @@
 * limitations under the License.
 */
 #include "EglWindowSurface.h"
+#include "EglOsApi.h"
 
 std::set<EGLNativeWindowType> EglWindowSurface::s_associatedWins;
 
@@ -24,6 +25,7 @@
 
 EglWindowSurface::EglWindowSurface(EGLNativeWindowType win,EglConfig* config,unsigned int width,unsigned int height):EglSurface(WINDOW,config,width,height),m_win(win){
     s_associatedWins.insert(win);
+    m_native = EglOS::createWindowSurface(win);
 }
 
 EglWindowSurface:: ~EglWindowSurface() {
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h
index 1752241..17249e0 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowSurface.h
@@ -26,7 +26,6 @@
     EglWindowSurface(EGLNativeWindowType win,EglConfig* config,unsigned width,unsigned int height);
     ~EglWindowSurface();
     bool  getAttrib(EGLint attrib,EGLint* val);
-    void* native(){ return (void *)m_win;};
 
     static bool alreadyAssociatedWithConfig(EGLNativeWindowType win);
 private:
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp
index 1c77779..488f7b7 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglWindowsApi.cpp
@@ -22,8 +22,6 @@
         if(a != true) return false;
 
 
-
-
 struct DisplayInfo{
     DisplayInfo():dc(NULL),hwnd(NULL),isPixelFormatSet(false){};
     DisplayInfo(HDC hdc,HWND wnd):isPixelFormatSet(false){dc = hdc; hwnd = wnd;};
@@ -66,7 +64,6 @@
     m_map[configurationIndex] = info;
     m_current = configurationIndex;
 }
-namespace EglOS{
 
 struct WglExtProcs{
     PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB;
@@ -81,6 +78,62 @@
 
 static WglExtProcs* s_wglExtProcs = NULL;
 
+class SrfcInfo{
+public:
+    typedef enum {
+                 WINDOW  = 0,
+                 PBUFFER = 1,
+                 PIXMAP  = 2
+                 }SurfaceType;
+    explicit SrfcInfo(HWND wnd);
+    explicit SrfcInfo(HPBUFFERARB pb);
+    explicit SrfcInfo(HBITMAP bmap);
+    HWND getHwnd(){ return m_hwnd;};
+    HDC  getDC(){ return m_hdc;};
+    HBITMAP  getBmap(){ return m_bmap;};
+    HPBUFFERARB  getPbuffer(){ return m_pb;};
+    ~SrfcInfo();
+private:
+    HWND        m_hwnd;
+    HPBUFFERARB m_pb; 
+    HBITMAP     m_bmap;
+    HDC         m_hdc;
+    SurfaceType m_type;
+};
+
+SrfcInfo::SrfcInfo(HBITMAP bmap):m_hwnd(NULL),
+                                 m_pb(NULL),
+                                 m_hdc(NULL),
+                                 m_type(PIXMAP){
+    m_bmap = bmap;
+}
+
+SrfcInfo::SrfcInfo(HWND wnd):m_pb(NULL),
+                             m_bmap(NULL),
+                             m_type(WINDOW){
+    m_hwnd = wnd;
+    m_hdc = GetDC(wnd); 
+}
+
+SrfcInfo::SrfcInfo(HPBUFFERARB pb):m_hwnd(NULL),
+                                   m_bmap(NULL),
+                                   m_type(PBUFFER){
+    m_pb = pb;
+    if(s_wglExtProcs->wglGetPbufferDCARB){
+        m_hdc =  s_wglExtProcs->wglGetPbufferDCARB(pb);
+    }
+}
+
+SrfcInfo::~SrfcInfo(){
+    if(m_type == WINDOW){
+        ReleaseDC(m_hwnd,m_hdc);
+    }
+}
+
+namespace EglOS{
+
+
+
 PROC wglGetExtentionsProcAddress(HDC hdc,const char *extension_name,const char* proc_name)
 {
     // this is pointer to function which returns pointer to string with list of all wgl extensions
@@ -314,14 +367,17 @@
 
 }
 
-
 bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win) {
     return IsWindow(win);
 }
 
-bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativePixmapType pix) {
+bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win) {
+    return validNativeWin(dpy,win->getHwnd());
+}
+
+bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix) {
     BITMAP bm;
-    return GetObject(pix, sizeof(BITMAP), (LPSTR)&bm);
+    return GetObject(pix->getBmap(), sizeof(BITMAP), (LPSTR)&bm);
 }
 
 static bool setPixelFormat(HDC dc,EglConfig* cfg) {
@@ -382,7 +438,7 @@
     return true;
 }
 
-EGLNativePbufferType createPbuffer(EGLNativeDisplayType display,EglConfig* cfg,EglPbufferSurface* pbSurface) {
+EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType display,EglConfig* cfg,EglPbufferSurface* pbSurface) {
 
   //converting configuration into WGL pixel Format
    EGLint red,green,blue,alpha,depth,stencil;
@@ -445,13 +501,13 @@
         DWORD err = GetLastError();
         return NULL;
     }
-    return pb;
+    return new SrfcInfo(pb);
 }
 
-bool releasePbuffer(EGLNativeDisplayType display,EGLNativePbufferType pb) {
+bool releasePbuffer(EGLNativeDisplayType display,EGLNativeSurfaceType pb) {
     HDC  dis =  display->getCurrentDC();
     if(!s_wglExtProcs->wglReleasePbufferDCARB || !s_wglExtProcs->wglDestroyPbufferARB) return false;
-    if(!s_wglExtProcs->wglReleasePbufferDCARB(pb,dis) || !s_wglExtProcs->wglDestroyPbufferARB(pb)){
+    if(!s_wglExtProcs->wglReleasePbufferDCARB(pb->getPbuffer(),pb->getDC()) || !s_wglExtProcs->wglDestroyPbufferARB(pb->getPbuffer())){
         DWORD err = GetLastError();
         return false;
     }
@@ -495,39 +551,10 @@
 }
 
 
-HDC getSurfaceDC(EGLNativeDisplayType dpy,EglSurface* srfc){
-    switch(srfc->type()){
-    case EglSurface::WINDOW:
-        return GetDC(static_cast<EGLNativeWindowType>(srfc->native()));
-    case EglSurface::PBUFFER:
-        if(!s_wglExtProcs->wglGetPbufferDCARB) return NULL;
-        return s_wglExtProcs->wglGetPbufferDCARB(static_cast<EGLNativePbufferType>(srfc->native()));
-    case EglSurface::PIXMAP: //not supported;
-    default:
-        return NULL;
-    }
-}
-
-bool releaseSurfaceDC(EGLNativeDisplayType dpy,HDC dc,EglSurface*srfc){
-    if(!srfc) return true;
-    switch(srfc->type()){
-    case EglSurface::WINDOW:
-         ReleaseDC(static_cast<EGLNativeWindowType>(srfc->native()),dc);
-         return true;
-    case EglSurface::PBUFFER:
-        if(!s_wglExtProcs->wglReleasePbufferDCARB) return false;
-        s_wglExtProcs->wglReleasePbufferDCARB(static_cast<EGLNativePbufferType>(srfc->native()),dc);
-        return true;
-    case EglSurface::PIXMAP: //not supported;
-    default:
-        return false;
-    }
-}
-
 bool makeCurrent(EGLNativeDisplayType display,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx) {
 
-    HDC hdcRead = read ? getSurfaceDC(display,read):0;
-    HDC hdcDraw = draw ? getSurfaceDC(display,draw):0;
+    HDC hdcRead = read ? read->native()->getDC(): NULL;
+    HDC hdcDraw = draw ? draw->native()->getDC(): NULL;
     bool retVal = false;
 
 
@@ -535,33 +562,40 @@
             bool ret =  wglMakeCurrent(hdcDraw,ctx);
             return ret;
     } else if (!s_wglExtProcs->wglMakeContextCurrentARB ) {
+        printf("OS :1-:make current failed %d\n",GetLastError());
         return false;
     }
     retVal = s_wglExtProcs->wglMakeContextCurrentARB(hdcDraw,hdcRead,ctx);
+    printf("OS ::2-make current failed %d\n",GetLastError());
 
-    releaseSurfaceDC(display,hdcRead,read);
-    releaseSurfaceDC(display,hdcDraw,draw);
     return retVal;
 }
 
-void swapBuffers(EGLNativeDisplayType display,EGLNativeWindowType win) {
-
-    HDC dc  = GetDC(win);
-    if(!SwapBuffers(dc)) {
+void swapBuffers(EGLNativeDisplayType display,EGLNativeSurfaceType srfc){
+    if(!SwapBuffers(srfc->getDC())) {
         DWORD err = GetLastError();
     }
-    ReleaseDC(win,dc);
-
 }
 
 
 void waitNative(){}
 
-void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval) {
+void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval) {
 
     if (s_wglExtProcs->wglSwapIntervalEXT){
         s_wglExtProcs->wglSwapIntervalEXT(interval);
     }
 }
 
+EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){
+    return new SrfcInfo(wnd);
+}
+
+EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){
+    return new SrfcInfo(pix);
+}
+
+void destroySurface(EGLNativeSurfaceType srfc){
+    delete srfc;
+}
 };
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp
index 3aee4b4..e3b184a 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglX11Api.cpp
@@ -34,6 +34,20 @@
 
 };
 
+class SrfcInfo{
+public:
+    typedef enum{
+                 WINDOW  = 0,
+                 PBUFFER = 1, 
+                 PIXMAP
+                }SurfaceType;
+    SrfcInfo(GLXDrawable drawable,SurfaceType type):m_type(type),
+                                                    m_srfc(drawable){};
+    GLXDrawable srfc(){return m_srfc;};
+private: 
+    SurfaceType m_type;
+    GLXDrawable  m_srfc; 
+};
 
 int ErrorHandler::s_lastErrorCode = 0;
 android::Mutex ErrorHandler::s_lock;
@@ -160,12 +174,16 @@
    return handler.getLastError() == 0;
 }
 
-bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativePixmapType pix) {
+bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win) {
+    return validNativeWin(dpy,win->srfc());
+}
+
+bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix) {
    Window root;
    int tmp;
    unsigned int utmp;
    ErrorHandler handler(dpy);
-   if(!XGetGeometry(dpy,pix,&root,&tmp,&tmp,&utmp,&utmp,&utmp,&utmp)) return false;
+   if(!XGetGeometry(dpy,pix->srfc(),&root,&tmp,&tmp,&utmp,&utmp,&utmp,&utmp)) return false;
    return handler.getLastError() == 0;
 }
 
@@ -194,7 +212,7 @@
    return depth >= configDepth;
 }
 
-EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
+EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
     EGLint width,height,largest;
     srfc->getDim(&width,&height,&largest);
 
@@ -204,11 +222,12 @@
                      GLX_LARGEST_PBUFFER         ,largest,
                      None
                     };
-    return glXCreatePbuffer(dpy,cfg->nativeConfig(),attribs);
+    GLXPbuffer pb = glXCreatePbuffer(dpy,cfg->nativeConfig(),attribs);
+    return pb ? new SrfcInfo(pb,SrfcInfo::PBUFFER) : NULL;
 }
 
-bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb) {
-    glXDestroyPbuffer(dis,pb);
+bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb) {
+    glXDestroyPbuffer(dis,pb->srfc());
 
     return true;
 }
@@ -224,36 +243,29 @@
     return true;
 }
 
-GLXDrawable convertSurface(EglSurface* srfc) {
-    if(!srfc) return None;
-    switch(srfc->type()){
-    case EglSurface::PIXMAP:
-        return (GLXPixmap)srfc->native();
-    case EglSurface::PBUFFER:
-        return (GLXPbuffer)srfc->native();
-    case EglSurface::WINDOW:
-    default:
-        return (GLXWindow)srfc->native();
-    }
-}
-
-
 bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx){
 
     ErrorHandler handler(dpy);
-    bool retval = glXMakeContextCurrent(dpy,convertSurface(draw),convertSurface(read),ctx);
+    bool retval = false;
+    if (!ctx && !read && !draw) {
+        // unbind
+        retval = glXMakeContextCurrent(dpy, NULL, NULL, NULL);
+    }
+    else if (ctx && read && draw) {
+        retval = glXMakeContextCurrent(dpy,draw->native()->srfc(),read->native()->srfc(),ctx);
+    }
     return (handler.getLastError() == 0) && retval;
 }
 
-void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win) {
-    glXSwapBuffers(dpy,win);
+void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc){
+    glXSwapBuffers(dpy,srfc->srfc());
 }
 
 void waitNative() {
     glXWaitX();
 }
 
-void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval){
+void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval){
     const char* extensions = glXQueryExtensionsString(dpy,DefaultScreen(dpy));
     typedef void (*GLXSWAPINTERVALEXT)(Display*,GLXDrawable,int);
     GLXSWAPINTERVALEXT glXSwapIntervalEXT = NULL;
@@ -262,8 +274,17 @@
         glXSwapIntervalEXT = (GLXSWAPINTERVALEXT)glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT");
     }
     if(glXSwapIntervalEXT) {
-        glXSwapIntervalEXT(dpy,win,interval);
+        glXSwapIntervalEXT(dpy,win->srfc(),interval);
     }
 }
 
+EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){
+    return new SrfcInfo(wnd,SrfcInfo::WINDOW);
+}
+
+EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){
+    return new SrfcInfo(pix,SrfcInfo::PIXMAP);
+}
+
+void destroySurface(EGLNativeSurfaceType srfc){};
 };
diff --git a/tools/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h b/tools/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h
index 3137027..319e6f9 100644
--- a/tools/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h
+++ b/tools/emulator/opengl/host/libs/Translator/include/EGL/eglinternalplatform.h
@@ -17,6 +17,10 @@
 * limitations under the License.
 */
 
+class SrfcInfo; //defined in Egl{$platform}Api.cpp
+typedef SrfcInfo* SURFACE;
+typedef SURFACE EGLNativeSurfaceType;
+
 #if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN 1