Commit afd1f9f6 by Nicolas Capens Committed by Nicolas Capens

Retrieve the current context and display from EGL.

BUG=18110152 Change-Id: Iedddab96b5958b1daef6a41bb968af358afd6561 Reviewed-on: https://swiftshader-review.googlesource.com/1254Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent f9b76a8b
...@@ -15,9 +15,11 @@ class Context ...@@ -15,9 +15,11 @@ class Context
{ {
public: public:
virtual void destroy() = 0; virtual void destroy() = 0;
virtual void makeCurrent(Surface *surface) = 0;
virtual void bindTexImage(Surface *surface) = 0; virtual void bindTexImage(Surface *surface) = 0;
virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel) = 0; virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel) = 0;
virtual Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel) = 0; virtual Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel) = 0;
virtual int getClientVersion() = 0;
}; };
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "Display.h" #include "Display.h"
#include "Texture2D.hpp" #include "Texture2D.hpp"
#include "Image.hpp" #include "Image.hpp"
#include "Context.hpp"
#include "common/debug.h" #include "common/debug.h"
#include "Main/FrameBuffer.hpp" #include "Main/FrameBuffer.hpp"
...@@ -304,7 +305,7 @@ bool Surface::checkForResize() ...@@ -304,7 +305,7 @@ bool Surface::checkForResize()
if(static_cast<egl::Surface*>(getCurrentDrawSurface()) == this) if(static_cast<egl::Surface*>(getCurrentDrawSurface()) == this)
{ {
gl2::makeCurrent(static_cast<egl::Context*>(getCurrentContext()), static_cast<egl::Display*>(getCurrentDisplay()), this); static_cast<egl::Context*>(getCurrentContext())->makeCurrent(this);
} }
return true; return true;
......
...@@ -868,7 +868,10 @@ EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurfac ...@@ -868,7 +868,10 @@ EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurfac
egl::setCurrentReadSurface(read); egl::setCurrentReadSurface(read);
egl::setCurrentContext(ctx); egl::setCurrentContext(ctx);
gl2::makeCurrent(context, display, static_cast<egl::Surface*>(draw)); if(context)
{
context->makeCurrent(static_cast<egl::Surface*>(draw));
}
return success(EGL_TRUE); return success(EGL_TRUE);
} }
......
...@@ -90,7 +90,6 @@ CONSTRUCTOR static bool eglAttachProcess() ...@@ -90,7 +90,6 @@ CONSTRUCTOR static bool eglAttachProcess()
libGLESv2 = loadLibrary(libGLESv2_lib); libGLESv2 = loadLibrary(libGLESv2_lib);
gl2::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*))getProcAddress(libGLESv2, "glCreateContext"); gl2::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*))getProcAddress(libGLESv2, "glCreateContext");
gl2::makeCurrent = (void (*)(egl::Context*, egl::Display*, egl::Surface*))getProcAddress(libGLESv2, "glMakeCurrent");
gl2::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLESv2, "glGetProcAddress"); gl2::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLESv2, "glGetProcAddress");
gl2::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLESv2, "createBackBuffer"); gl2::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLESv2, "createBackBuffer");
gl2::createDepthStencil = (egl::Image *(*)(unsigned int, unsigned int, sw::Format, int, bool))getProcAddress(libGLESv2, "createDepthStencil"); gl2::createDepthStencil = (egl::Image *(*)(unsigned int, unsigned int, sw::Format, int, bool))getProcAddress(libGLESv2, "createDepthStencil");
...@@ -261,7 +260,6 @@ void error(EGLint errorCode) ...@@ -261,7 +260,6 @@ void error(EGLint errorCode)
namespace gl2 namespace gl2
{ {
egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext) = 0; egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext) = 0;
void (*makeCurrent)(egl::Context *context, egl::Display *display, egl::Surface *surface) = 0;
__eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0; __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0;
egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config) = 0; egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config) = 0;
egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard) = 0; egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard) = 0;
......
...@@ -86,7 +86,6 @@ namespace sw ...@@ -86,7 +86,6 @@ namespace sw
namespace gl2 namespace gl2
{ {
extern egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext); extern egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext);
extern void (*makeCurrent)(egl::Context *context, egl::Display *display, egl::Surface *surface);
extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname); extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname);
extern egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config); extern egl::Image *(*createBackBuffer)(int width, int height, const egl::Config *config);
extern egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard); extern egl::Image *(*createDepthStencil)(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
......
...@@ -174,17 +174,7 @@ Context::~Context() ...@@ -174,17 +174,7 @@ Context::~Context()
mResourceManager->release(); mResourceManager->release();
} }
void Context::destroy() void Context::makeCurrent(egl::Surface *surface)
{
if(this == gl::getContext())
{
gl::makeCurrent(NULL, NULL, NULL);
}
delete this;
}
void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{ {
if(!mHasBeenCurrent) if(!mHasBeenCurrent)
{ {
...@@ -227,6 +217,21 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -227,6 +217,21 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
markAllStateDirty(); markAllStateDirty();
} }
void Context::destroy()
{
if(this == getContext())
{
makeCurrent(0);
}
delete this;
}
int Context::getClientVersion()
{
return 1;
}
// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw. // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
void Context::markAllStateDirty() void Context::markAllStateDirty()
{ {
...@@ -2316,9 +2321,4 @@ extern "C" ...@@ -2316,9 +2321,4 @@ extern "C"
{ {
return new gl::Context(config, shareContext); return new gl::Context(config, shareContext);
} }
void glMakeCurrent(gl::Context *context, egl::Display *display, egl::Surface *surface)
{
gl::makeCurrent(context, display, surface);
}
} }
...@@ -224,9 +224,9 @@ class Context : public egl::Context ...@@ -224,9 +224,9 @@ class Context : public egl::Context
public: public:
Context(const egl::Config *config, const Context *shareContext); Context(const egl::Config *config, const Context *shareContext);
virtual void makeCurrent(egl::Surface *surface);
virtual void destroy(); virtual void destroy();
virtual int getClientVersion();
void makeCurrent(egl::Display *display, egl::Surface *surface);
void markAllStateDirty(); void markAllStateDirty();
......
...@@ -147,7 +147,6 @@ EXPORTS ...@@ -147,7 +147,6 @@ EXPORTS
; EGL dependencies ; EGL dependencies
glCreateContext @144 glCreateContext @144
glMakeCurrent @146
glGetProcAddress @148 glGetProcAddress @148
createFrameBuffer @172 createFrameBuffer @172
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
#include "Framebuffer.h" #include "Framebuffer.h"
#include "libEGL/Surface.h" #include "libEGL/Surface.h"
#include "Common/Thread.hpp" #include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
#include "common/debug.h" #include "common/debug.h"
static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
#define CONSTRUCTOR __attribute__((constructor)) #define CONSTRUCTOR __attribute__((constructor))
#define DESTRUCTOR __attribute__((destructor)) #define DESTRUCTOR __attribute__((destructor))
...@@ -31,44 +30,30 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES; ...@@ -31,44 +30,30 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
static void glAttachThread() static void glAttachThread()
{ {
TRACE("()"); TRACE("()");
gl::Current *current = new gl::Current;
if(current)
{
sw::Thread::setLocalStorage(currentTLS, current);
current->context = NULL;
current->display = NULL;
}
} }
static void glDetachThread() static void glDetachThread()
{ {
TRACE("()"); TRACE("()");
gl::Current *current = (gl::Current*)sw::Thread::getLocalStorage(currentTLS);
if(current)
{
delete current;
}
} }
CONSTRUCTOR static bool glAttachProcess() CONSTRUCTOR static bool glAttachProcess()
{ {
TRACE("()"); TRACE("()");
currentTLS = sw::Thread::allocateLocalStorageKey(); glAttachThread();
if(currentTLS == TLS_OUT_OF_INDEXES) #if defined(_WIN32)
{ const char *libEGL_lib = "libEGL.dll";
return false; #else
} const char *libEGL_lib = "libEGL.so.1";
#endif
glAttachThread(); libEGL = loadLibrary(libEGL_lib);
egl::getCurrentContext = (egl::Context *(*)())getProcAddress(libEGL, "eglGetCurrentContext");
egl::getCurrentDisplay = (egl::Display *(*)())getProcAddress(libEGL, "eglGetCurrentDisplay");
return true; return libEGL != 0;
} }
DESTRUCTOR static void glDetachProcess() DESTRUCTOR static void glDetachProcess()
...@@ -76,8 +61,7 @@ DESTRUCTOR static void glDetachProcess() ...@@ -76,8 +61,7 @@ DESTRUCTOR static void glDetachProcess()
TRACE("()"); TRACE("()");
glDetachThread(); glDetachThread();
freeLibrary(libEGL);
sw::Thread::freeLocalStorageKey(currentTLS);
} }
#if defined(_WIN32) #if defined(_WIN32)
...@@ -107,43 +91,21 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved ...@@ -107,43 +91,21 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
namespace gl namespace gl
{ {
static gl::Current *getCurrent(void) gl::Context *getContext()
{ {
Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS); egl::Context *context = egl::getCurrentContext();
if(!current) if(context && context->getClientVersion() == 1)
{ {
glAttachThread(); return static_cast<gl::Context*>(context);
} }
return (Current*)sw::Thread::getLocalStorage(currentTLS); return 0;
}
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface)
{
Current *current = getCurrent();
current->context = context;
current->display = display;
if(context && display && surface)
{
context->makeCurrent(display, surface);
}
}
Context *getContext()
{
Current *current = getCurrent();
return current->context;
} }
egl::Display *getDisplay() egl::Display *getDisplay()
{ {
Current *current = getCurrent(); return egl::getCurrentDisplay();
return current->display;
} }
Device *getDevice() Device *getDevice()
...@@ -187,3 +149,11 @@ void error(GLenum errorCode) ...@@ -187,3 +149,11 @@ void error(GLenum errorCode)
} }
} }
} }
namespace egl
{
egl::Context *(*getCurrentContext)() = 0;
egl::Display *(*getCurrentDisplay)() = 0;
}
void *libEGL = 0; // Handle to the libEGL module
\ No newline at end of file
...@@ -26,17 +26,8 @@ ...@@ -26,17 +26,8 @@
namespace gl namespace gl
{ {
struct Current
{
Context *context;
egl::Display *display;
};
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface);
Context *getContext(); Context *getContext();
egl::Display *getDisplay(); egl::Display *getDisplay();
Device *getDevice(); Device *getDevice();
} }
...@@ -50,4 +41,13 @@ const T &error(GLenum errorCode, const T &returnValue) ...@@ -50,4 +41,13 @@ const T &error(GLenum errorCode, const T &returnValue)
return returnValue; return returnValue;
} }
// libEGL dependencies
namespace egl
{
extern egl::Context *(*getCurrentContext)();
extern egl::Display *(*getCurrentDisplay)();
}
extern void *libEGL; // Handle to the libEGL module
#endif // LIBGLES_CM_MAIN_H_ #endif // LIBGLES_CM_MAIN_H_
...@@ -222,17 +222,7 @@ Context::~Context() ...@@ -222,17 +222,7 @@ Context::~Context()
mResourceManager->release(); mResourceManager->release();
} }
void Context::destroy() void Context::makeCurrent(egl::Surface *surface)
{
if(this == gl2::getContext())
{
gl2::makeCurrent(NULL, NULL, NULL);
}
delete this;
}
void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{ {
if(!mHasBeenCurrent) if(!mHasBeenCurrent)
{ {
...@@ -275,6 +265,21 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface) ...@@ -275,6 +265,21 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
markAllStateDirty(); markAllStateDirty();
} }
void Context::destroy()
{
if(this == getContext())
{
makeCurrent(0);
}
delete this;
}
int Context::getClientVersion()
{
return 2;
}
// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw. // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
void Context::markAllStateDirty() void Context::markAllStateDirty()
{ {
...@@ -3153,9 +3158,4 @@ extern "C" ...@@ -3153,9 +3158,4 @@ extern "C"
{ {
return new gl2::Context(config, shareContext); return new gl2::Context(config, shareContext);
} }
void glMakeCurrent(gl2::Context *context, egl::Display *display, egl::Surface *surface)
{
gl2::makeCurrent(context, display, surface);
}
} }
...@@ -242,9 +242,9 @@ class Context : public egl::Context ...@@ -242,9 +242,9 @@ class Context : public egl::Context
public: public:
Context(const egl::Config *config, const Context *shareContext); Context(const egl::Config *config, const Context *shareContext);
virtual void makeCurrent(egl::Surface *surface);
virtual void destroy(); virtual void destroy();
virtual int getClientVersion();
void makeCurrent(egl::Display *display, egl::Surface *surface);
void markAllStateDirty(); void markAllStateDirty();
......
...@@ -170,7 +170,6 @@ EXPORTS ...@@ -170,7 +170,6 @@ EXPORTS
; EGL dependencies ; EGL dependencies
glCreateContext @144 glCreateContext @144
glMakeCurrent @146
glGetProcAddress @148 glGetProcAddress @148
createFrameBuffer @172 createFrameBuffer @172
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
#include "Framebuffer.h" #include "Framebuffer.h"
#include "libEGL/Surface.h" #include "libEGL/Surface.h"
#include "Common/Thread.hpp" #include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
#include "common/debug.h" #include "common/debug.h"
static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
#define CONSTRUCTOR __attribute__((constructor)) #define CONSTRUCTOR __attribute__((constructor))
#define DESTRUCTOR __attribute__((destructor)) #define DESTRUCTOR __attribute__((destructor))
...@@ -31,44 +30,30 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES; ...@@ -31,44 +30,30 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
static void glAttachThread() static void glAttachThread()
{ {
TRACE("()"); TRACE("()");
gl2::Current *current = new gl2::Current;
if(current)
{
sw::Thread::setLocalStorage(currentTLS, current);
current->context = NULL;
current->display = NULL;
}
} }
static void glDetachThread() static void glDetachThread()
{ {
TRACE("()"); TRACE("()");
gl2::Current *current = (gl2::Current*)sw::Thread::getLocalStorage(currentTLS);
if(current)
{
delete current;
}
} }
CONSTRUCTOR static bool glAttachProcess() CONSTRUCTOR static bool glAttachProcess()
{ {
TRACE("()"); TRACE("()");
currentTLS = sw::Thread::allocateLocalStorageKey(); glAttachThread();
if(currentTLS == TLS_OUT_OF_INDEXES) #if defined(_WIN32)
{ const char *libEGL_lib = "libEGL.dll";
return false; #else
} const char *libEGL_lib = "libEGL.so.1";
#endif
glAttachThread(); libEGL = loadLibrary(libEGL_lib);
egl::getCurrentContext = (egl::Context *(*)())getProcAddress(libEGL, "eglGetCurrentContext");
egl::getCurrentDisplay = (egl::Display *(*)())getProcAddress(libEGL, "eglGetCurrentDisplay");
return true; return libEGL != 0;
} }
DESTRUCTOR static void glDetachProcess() DESTRUCTOR static void glDetachProcess()
...@@ -76,8 +61,7 @@ DESTRUCTOR static void glDetachProcess() ...@@ -76,8 +61,7 @@ DESTRUCTOR static void glDetachProcess()
TRACE("()"); TRACE("()");
glDetachThread(); glDetachThread();
freeLibrary(libEGL);
sw::Thread::freeLocalStorageKey(currentTLS);
} }
#if defined(_WIN32) #if defined(_WIN32)
...@@ -107,43 +91,21 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved ...@@ -107,43 +91,21 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
namespace gl2 namespace gl2
{ {
static gl2::Current *getCurrent(void) gl2::Context *getContext()
{ {
Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS); egl::Context *context = egl::getCurrentContext();
if(!current) if(context && context->getClientVersion() == 2)
{ {
glAttachThread(); return static_cast<gl2::Context*>(context);
} }
return (Current*)sw::Thread::getLocalStorage(currentTLS); return 0;
}
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface)
{
Current *current = getCurrent();
current->context = context;
current->display = display;
if(context && display && surface)
{
context->makeCurrent(display, surface);
}
}
Context *getContext()
{
Current *current = getCurrent();
return current->context;
} }
egl::Display *getDisplay() egl::Display *getDisplay()
{ {
Current *current = getCurrent(); return egl::getCurrentDisplay();
return current->display;
} }
Device *getDevice() Device *getDevice()
...@@ -187,3 +149,11 @@ void error(GLenum errorCode) ...@@ -187,3 +149,11 @@ void error(GLenum errorCode)
} }
} }
} }
namespace egl
{
egl::Context *(*getCurrentContext)() = 0;
egl::Display *(*getCurrentDisplay)() = 0;
}
void *libEGL = 0; // Handle to the libEGL module
\ No newline at end of file
...@@ -25,17 +25,8 @@ ...@@ -25,17 +25,8 @@
namespace gl2 namespace gl2
{ {
struct Current
{
Context *context;
egl::Display *display;
};
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface);
Context *getContext(); Context *getContext();
egl::Display *getDisplay(); egl::Display *getDisplay();
Device *getDevice(); Device *getDevice();
} }
...@@ -49,4 +40,13 @@ const T &error(GLenum errorCode, const T &returnValue) ...@@ -49,4 +40,13 @@ const T &error(GLenum errorCode, const T &returnValue)
return returnValue; return returnValue;
} }
// libEGL dependencies
namespace egl
{
extern egl::Context *(*getCurrentContext)();
extern egl::Display *(*getCurrentDisplay)();
}
extern void *libEGL; // Handle to the libEGL module
#endif // LIBGLESV2_MAIN_H_ #endif // LIBGLESV2_MAIN_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment