\r
#include "main.h"\r
\r
+#include "libEGL.hpp"\r
+#include "Context.hpp"\r
+#include "Surface.h"\r
+\r
#include "resource.h"\r
#include "Common/Thread.hpp"\r
#include "Common/SharedLibrary.hpp"\r
#include "common/debug.h"\r
\r
+#define EGL_EGLEXT_PROTOTYPES\r
+#include <EGL/eglext.h>\r
+\r
static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;\r
\r
#if !defined(_MSC_VER)\r
\r
current->error = EGL_SUCCESS;\r
current->API = EGL_OPENGL_ES_API;\r
- current->display = EGL_NO_DISPLAY;\r
- current->drawSurface = EGL_NO_SURFACE;\r
- current->readSurface = EGL_NO_SURFACE;\r
- current->context = EGL_NO_CONTEXT;\r
+ current->display = nullptr;\r
+ current->context = nullptr;\r
+ current->drawSurface = nullptr;\r
+ current->readSurface = nullptr;\r
}\r
}\r
\r
}\r
}\r
\r
-CONSTRUCTOR static bool eglAttachProcess()\r
+CONSTRUCTOR static void eglAttachProcess()\r
{\r
TRACE("()");\r
\r
\r
if(currentTLS == TLS_OUT_OF_INDEXES)\r
{\r
- return false;\r
+ return;\r
}\r
\r
eglAttachThread();\r
-\r
- #if defined(_WIN32)\r
- const char *libGLES_CM_lib[] = {"libGLES_CM.dll", "libGLES_CM_translator.dll"};\r
- #elif defined(__ANDROID__)\r
- const char *libGLES_CM_lib[] = {"/vendor/lib/egl/libGLESv1_CM_swiftshader.so"};\r
- #elif defined(__LP64__)\r
- const char *libGLES_CM_lib[] = {"lib64GLES_CM_translator.so", "libGLES_CM.so.1", "libGLES_CM.so"};\r
- #else\r
- const char *libGLES_CM_lib[] = {"libGLES_CM_translator.so", "libGLES_CM.so.1", "libGLES_CM.so"};\r
- #endif\r
-\r
- libGLES_CM = loadLibrary(libGLES_CM_lib);\r
- es1::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*))getProcAddress(libGLES_CM, "glCreateContext");\r
- es1::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLES_CM, "glGetProcAddress");\r
-\r
- #if defined(_WIN32)\r
- const char *libGLESv2_lib[] = {"libGLESv2.dll", "libGLES_V2_translator.dll"};\r
- #elif defined(__ANDROID__)\r
- const char *libGLESv2_lib[] = {"/vendor/lib/egl/libGLESv2_swiftshader.so"};\r
- #elif defined(__LP64__)\r
- const char *libGLESv2_lib[] = {"lib64GLES_V2_translator.so", "libGLESv2.so.2", "libGLESv2.so"};\r
- #else\r
- const char *libGLESv2_lib[] = {"libGLES_V2_translator.so", "libGLESv2.so.2", "libGLESv2.so"};\r
- #endif\r
-\r
- libGLESv2 = loadLibrary(libGLESv2_lib);\r
- es2::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*, EGLint))getProcAddress(libGLESv2, "glCreateContext");\r
- es2::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLESv2, "glGetProcAddress");\r
-\r
- es::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLES_CM, "createBackBuffer");\r
- es::createDepthStencil = (egl::Image *(*)(unsigned int, unsigned int, sw::Format, int, bool))getProcAddress(libGLES_CM, "createDepthStencil");\r
- es::createFrameBuffer = (sw::FrameBuffer *(*)(EGLNativeDisplayType, EGLNativeWindowType, int, int))getProcAddress(libGLES_CM, "createFrameBuffer");\r
-\r
- if(!es::createBackBuffer)\r
- {\r
- es::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLESv2, "createBackBuffer");\r
- es::createDepthStencil = (egl::Image *(*)(unsigned int, unsigned int, sw::Format, int, bool))getProcAddress(libGLESv2, "createDepthStencil");\r
- es::createFrameBuffer = (sw::FrameBuffer *(*)(EGLNativeDisplayType, EGLNativeWindowType, int, int))getProcAddress(libGLESv2, "createFrameBuffer");\r
- }\r
-\r
- return libGLES_CM != 0 || libGLESv2 != 0;\r
}\r
\r
DESTRUCTOR static void eglDetachProcess()\r
\r
eglDetachThread();\r
sw::Thread::freeLocalStorageKey(currentTLS);\r
- freeLibrary(libGLESv2);\r
}\r
\r
#if defined(_WIN32)\r
#ifndef NDEBUG\r
WaitForDebugger(instance);\r
#endif\r
- return eglAttachProcess();\r
+ eglAttachProcess();\r
break;\r
case DLL_THREAD_ATTACH:\r
eglAttachThread();\r
return current->API;\r
}\r
\r
-void setCurrentDisplay(EGLDisplay dpy)\r
+void setCurrentDisplay(egl::Display *dpy)\r
{\r
Current *current = eglGetCurrent();\r
\r
current->display = dpy;\r
}\r
\r
-EGLDisplay getCurrentDisplay()\r
+egl::Display *getCurrentDisplay()\r
{\r
Current *current = eglGetCurrent();\r
\r
return current->display;\r
}\r
\r
-void setCurrentContext(EGLContext ctx)\r
+void setCurrentContext(egl::Context *ctx)\r
{\r
Current *current = eglGetCurrent();\r
\r
+ if(ctx)\r
+ {\r
+ ctx->addRef();\r
+ }\r
+\r
+ if(current->context)\r
+ {\r
+ current->context->release();\r
+ }\r
+\r
current->context = ctx;\r
}\r
\r
-EGLContext getCurrentContext()\r
+egl::Context *getCurrentContext()\r
{\r
Current *current = eglGetCurrent();\r
\r
return current->context;\r
}\r
\r
-void setCurrentDrawSurface(EGLSurface surface)\r
+void setCurrentDrawSurface(egl::Surface *surface)\r
{\r
Current *current = eglGetCurrent();\r
\r
+ if(surface)\r
+ {\r
+ surface->addRef();\r
+ }\r
+\r
+ if(current->drawSurface)\r
+ {\r
+ current->drawSurface->release();\r
+ }\r
+\r
current->drawSurface = surface;\r
}\r
\r
-EGLSurface getCurrentDrawSurface()\r
+egl::Surface *getCurrentDrawSurface()\r
{\r
Current *current = eglGetCurrent();\r
\r
return current->drawSurface;\r
}\r
\r
-void setCurrentReadSurface(EGLSurface surface)\r
+void setCurrentReadSurface(egl::Surface *surface)\r
{\r
Current *current = eglGetCurrent();\r
\r
+ if(surface)\r
+ {\r
+ surface->addRef();\r
+ }\r
+\r
+ if(current->readSurface)\r
+ {\r
+ current->readSurface->release();\r
+ }\r
+\r
current->readSurface = surface;\r
}\r
\r
-EGLSurface getCurrentReadSurface()\r
+egl::Surface *getCurrentReadSurface()\r
{\r
Current *current = eglGetCurrent();\r
\r
return current->readSurface;\r
}\r
-}\r
\r
void error(EGLint errorCode)\r
{\r
}\r
}\r
}\r
-\r
-extern "C"\r
-{\r
-EGLContext clientGetCurrentContext()\r
-{\r
- return egl::getCurrentContext();\r
-}\r
-\r
-EGLContext clientGetCurrentDisplay()\r
-{\r
- return egl::getCurrentDisplay();\r
-}\r
-}\r
-\r
-namespace es1\r
-{\r
- egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext) = 0;\r
- __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0;\r
}\r
\r
-namespace es2\r
+LibEGLexports::LibEGLexports()\r
{\r
- egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext, EGLint clientVersion) = 0;\r
- __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0;\r
+ this->eglGetError = ::eglGetError;\r
+ this->eglGetDisplay = ::eglGetDisplay;\r
+ this->eglInitialize = ::eglInitialize;\r
+ this->eglTerminate = ::eglTerminate;\r
+ this->eglQueryString = ::eglQueryString;\r
+ this->eglGetConfigs = ::eglGetConfigs;\r
+ this->eglChooseConfig = ::eglChooseConfig;\r
+ this->eglGetConfigAttrib = ::eglGetConfigAttrib;\r
+ this->eglCreateWindowSurface = ::eglCreateWindowSurface;\r
+ this->eglCreatePbufferSurface = ::eglCreatePbufferSurface;\r
+ this->eglCreatePixmapSurface = ::eglCreatePixmapSurface;\r
+ this->eglDestroySurface = ::eglDestroySurface;\r
+ this->eglQuerySurface = ::eglQuerySurface;\r
+ this->eglBindAPI = ::eglBindAPI;\r
+ this->eglQueryAPI = ::eglQueryAPI;\r
+ this->eglWaitClient = ::eglWaitClient;\r
+ this->eglReleaseThread = ::eglReleaseThread;\r
+ this->eglCreatePbufferFromClientBuffer = ::eglCreatePbufferFromClientBuffer;\r
+ this->eglSurfaceAttrib = ::eglSurfaceAttrib;\r
+ this->eglBindTexImage = ::eglBindTexImage;\r
+ this->eglReleaseTexImage = ::eglReleaseTexImage;\r
+ this->eglSwapInterval = ::eglSwapInterval;\r
+ this->eglCreateContext = ::eglCreateContext;\r
+ this->eglDestroyContext = ::eglDestroyContext;\r
+ this->eglMakeCurrent = ::eglMakeCurrent;\r
+ this->eglGetCurrentContext = ::eglGetCurrentContext;\r
+ this->eglGetCurrentSurface = ::eglGetCurrentSurface;\r
+ this->eglGetCurrentDisplay = ::eglGetCurrentDisplay;\r
+ this->eglQueryContext = ::eglQueryContext;\r
+ this->eglWaitGL = ::eglWaitGL;\r
+ this->eglWaitNative = ::eglWaitNative;\r
+ this->eglSwapBuffers = ::eglSwapBuffers;\r
+ this->eglCopyBuffers = ::eglCopyBuffers;\r
+ this->eglCreateImageKHR = ::eglCreateImageKHR;\r
+ this->eglDestroyImageKHR = ::eglDestroyImageKHR;\r
+ this->eglGetProcAddress = ::eglGetProcAddress;\r
+\r
+ this->clientGetCurrentContext = egl::getCurrentContext;\r
+ this->clientGetCurrentDisplay = egl::getCurrentDisplay;\r
}\r
\r
-namespace es\r
+extern "C" LibEGLexports *libEGL_swiftshader()\r
{\r
- egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config) = 0;\r
- egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard) = 0;\r
- sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height) = 0;\r
+ static LibEGLexports libEGL;\r
+ return &libEGL;\r
}\r
\r
-void *libGLES_CM = 0; // Handle to the libGLES_CM module\r
-void *libGLESv2 = 0; // Handle to the libGLESv2 module\r
+LibGLES_CM libGLES_CM;\r
+LibGLESv2 libGLESv2;\r