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
{
public:
virtual void destroy() = 0;
virtual void makeCurrent(Surface *surface) = 0;
virtual void bindTexImage(Surface *surface) = 0;
virtual EGLenum validateSharedImage(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 @@
#include "Display.h"
#include "Texture2D.hpp"
#include "Image.hpp"
#include "Context.hpp"
#include "common/debug.h"
#include "Main/FrameBuffer.hpp"
......@@ -304,7 +305,7 @@ bool Surface::checkForResize()
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;
......
......@@ -868,7 +868,10 @@ EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurfac
egl::setCurrentReadSurface(read);
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);
}
......
......@@ -90,7 +90,6 @@ CONSTRUCTOR static bool eglAttachProcess()
libGLESv2 = loadLibrary(libGLESv2_lib);
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::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");
......@@ -261,7 +260,6 @@ void error(EGLint errorCode)
namespace gl2
{
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;
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;
......
......@@ -86,7 +86,6 @@ namespace sw
namespace gl2
{
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 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);
......
......@@ -174,17 +174,7 @@ Context::~Context()
mResourceManager->release();
}
void Context::destroy()
{
if(this == gl::getContext())
{
gl::makeCurrent(NULL, NULL, NULL);
}
delete this;
}
void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
void Context::makeCurrent(egl::Surface *surface)
{
if(!mHasBeenCurrent)
{
......@@ -227,6 +217,21 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
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.
void Context::markAllStateDirty()
{
......@@ -2316,9 +2321,4 @@ extern "C"
{
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
public:
Context(const egl::Config *config, const Context *shareContext);
virtual void makeCurrent(egl::Surface *surface);
virtual void destroy();
void makeCurrent(egl::Display *display, egl::Surface *surface);
virtual int getClientVersion();
void markAllStateDirty();
......
......@@ -147,7 +147,6 @@ EXPORTS
; EGL dependencies
glCreateContext @144
glMakeCurrent @146
glGetProcAddress @148
createFrameBuffer @172
......
......@@ -16,10 +16,9 @@
#include "Framebuffer.h"
#include "libEGL/Surface.h"
#include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
#include "common/debug.h"
static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#if !defined(_MSC_VER)
#define CONSTRUCTOR __attribute__((constructor))
#define DESTRUCTOR __attribute__((destructor))
......@@ -31,44 +30,30 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
static void glAttachThread()
{
TRACE("()");
gl::Current *current = new gl::Current;
if(current)
{
sw::Thread::setLocalStorage(currentTLS, current);
current->context = NULL;
current->display = NULL;
}
}
static void glDetachThread()
{
TRACE("()");
gl::Current *current = (gl::Current*)sw::Thread::getLocalStorage(currentTLS);
if(current)
{
delete current;
}
}
CONSTRUCTOR static bool glAttachProcess()
{
TRACE("()");
currentTLS = sw::Thread::allocateLocalStorageKey();
glAttachThread();
if(currentTLS == TLS_OUT_OF_INDEXES)
{
return false;
}
#if defined(_WIN32)
const char *libEGL_lib = "libEGL.dll";
#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()
......@@ -76,8 +61,7 @@ DESTRUCTOR static void glDetachProcess()
TRACE("()");
glDetachThread();
sw::Thread::freeLocalStorageKey(currentTLS);
freeLibrary(libEGL);
}
#if defined(_WIN32)
......@@ -107,43 +91,21 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
namespace gl
{
static gl::Current *getCurrent(void)
gl::Context *getContext()
{
Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS);
if(!current)
egl::Context *context = egl::getCurrentContext();
if(context && context->getClientVersion() == 1)
{
glAttachThread();
return static_cast<gl::Context*>(context);
}
return (Current*)sw::Thread::getLocalStorage(currentTLS);
}
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;
return 0;
}
egl::Display *getDisplay()
{
Current *current = getCurrent();
return current->display;
return egl::getCurrentDisplay();
}
Device *getDevice()
......@@ -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 @@
namespace gl
{
struct Current
{
Context *context;
egl::Display *display;
};
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface);
Context *getContext();
egl::Display *getDisplay();
Device *getDevice();
}
......@@ -50,4 +41,13 @@ const T &error(GLenum errorCode, const T &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_
......@@ -222,17 +222,7 @@ Context::~Context()
mResourceManager->release();
}
void Context::destroy()
{
if(this == gl2::getContext())
{
gl2::makeCurrent(NULL, NULL, NULL);
}
delete this;
}
void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
void Context::makeCurrent(egl::Surface *surface)
{
if(!mHasBeenCurrent)
{
......@@ -275,6 +265,21 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
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.
void Context::markAllStateDirty()
{
......@@ -3153,9 +3158,4 @@ extern "C"
{
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
public:
Context(const egl::Config *config, const Context *shareContext);
virtual void makeCurrent(egl::Surface *surface);
virtual void destroy();
void makeCurrent(egl::Display *display, egl::Surface *surface);
virtual int getClientVersion();
void markAllStateDirty();
......
......@@ -170,7 +170,6 @@ EXPORTS
; EGL dependencies
glCreateContext @144
glMakeCurrent @146
glGetProcAddress @148
createFrameBuffer @172
......
......@@ -16,10 +16,9 @@
#include "Framebuffer.h"
#include "libEGL/Surface.h"
#include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
#include "common/debug.h"
static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
#if !defined(_MSC_VER)
#define CONSTRUCTOR __attribute__((constructor))
#define DESTRUCTOR __attribute__((destructor))
......@@ -31,44 +30,30 @@ static sw::Thread::LocalStorageKey currentTLS = TLS_OUT_OF_INDEXES;
static void glAttachThread()
{
TRACE("()");
gl2::Current *current = new gl2::Current;
if(current)
{
sw::Thread::setLocalStorage(currentTLS, current);
current->context = NULL;
current->display = NULL;
}
}
static void glDetachThread()
{
TRACE("()");
gl2::Current *current = (gl2::Current*)sw::Thread::getLocalStorage(currentTLS);
if(current)
{
delete current;
}
}
CONSTRUCTOR static bool glAttachProcess()
{
TRACE("()");
currentTLS = sw::Thread::allocateLocalStorageKey();
glAttachThread();
if(currentTLS == TLS_OUT_OF_INDEXES)
{
return false;
}
#if defined(_WIN32)
const char *libEGL_lib = "libEGL.dll";
#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()
......@@ -76,8 +61,7 @@ DESTRUCTOR static void glDetachProcess()
TRACE("()");
glDetachThread();
sw::Thread::freeLocalStorageKey(currentTLS);
freeLibrary(libEGL);
}
#if defined(_WIN32)
......@@ -107,43 +91,21 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
namespace gl2
{
static gl2::Current *getCurrent(void)
gl2::Context *getContext()
{
Current *current = (Current*)sw::Thread::getLocalStorage(currentTLS);
if(!current)
egl::Context *context = egl::getCurrentContext();
if(context && context->getClientVersion() == 2)
{
glAttachThread();
return static_cast<gl2::Context*>(context);
}
return (Current*)sw::Thread::getLocalStorage(currentTLS);
}
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;
return 0;
}
egl::Display *getDisplay()
{
Current *current = getCurrent();
return current->display;
return egl::getCurrentDisplay();
}
Device *getDevice()
......@@ -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 @@
namespace gl2
{
struct Current
{
Context *context;
egl::Display *display;
};
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface);
Context *getContext();
egl::Display *getDisplay();
Device *getDevice();
}
......@@ -49,4 +40,13 @@ const T &error(GLenum errorCode, const T &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_
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