Commit 6a7e8718 by Nicolas Capens

Return the requested GL context version.

BUG=18110152 Change-Id: Ia2a04777e6303cd9f2e53a735455c8c7921b1b13
parent afd1f9f6
......@@ -383,14 +383,38 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, const EGLint *attri
return success(surface);
}
EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *shareContext)
EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *shareContext, EGLint clientVersion)
{
const egl::Config *config = mConfigSet.get(configHandle);
egl::Context *context = 0;
egl::Context *context = gl2::createContext(config, shareContext);
mContextSet.insert(context);
if(clientVersion == 1 && config->mRenderableType & EGL_OPENGL_ES_BIT)
{
if(gl::createContext != 0)
{
context = gl::createContext(config, shareContext);
}
}
else if(clientVersion == 2 && config->mRenderableType & EGL_OPENGL_ES2_BIT)
{
if(gl2::createContext != 0)
{
context = gl2::createContext(config, shareContext);
}
}
else
{
return error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
}
if(!context)
{
return error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
}
mContextSet.insert(context);
return context;
return success(context);;
}
void Display::destroySurface(egl::Surface *surface)
......
......@@ -40,7 +40,7 @@ namespace egl
EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList);
EGLSurface createOffscreenSurface(EGLConfig config, const EGLint *attribList);
EGLContext createContext(EGLConfig configHandle, const Context *shareContext);
EGLContext createContext(EGLConfig configHandle, const Context *shareContext, EGLint clientVersion);
void destroySurface(Surface *surface);
void destroyContext(Context *context);
......
......@@ -765,15 +765,14 @@ EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLCon
try
{
// Get the requested client version (default is 1) and check it is two.
EGLint client_version = 1;
EGLint clientVersion = 1;
if(attrib_list)
{
for(const EGLint* attribute = attrib_list; attribute[0] != EGL_NONE; attribute += 2)
{
if(attribute[0] == EGL_CONTEXT_CLIENT_VERSION)
{
client_version = attribute[1];
clientVersion = attribute[1];
}
else
{
......@@ -781,12 +780,7 @@ EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLCon
}
}
}
if(client_version != 2)
{
return error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
}
egl::Display *display = static_cast<egl::Display*>(dpy);
if(!validateConfig(display, config))
......@@ -794,9 +788,7 @@ EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLCon
return EGL_NO_CONTEXT;
}
EGLContext context = display->createContext(config, static_cast<egl::Context*>(share_context));
return success(context);
return display->createContext(config, static_cast<egl::Context*>(share_context), clientVersion);
}
catch(std::bad_alloc&)
{
......
......@@ -83,6 +83,19 @@ CONSTRUCTOR static bool eglAttachProcess()
eglAttachThread();
#if defined(_WIN32)
const char *libGLES_CM_lib = "libGLES_CM.dll";
#else
const char *libGLES_CM_lib = "libGLES_CM.so.1";
#endif
libGLES_CM = loadLibrary(libGLES_CM_lib);
gl::createContext = (egl::Context *(*)(const egl::Config*, const egl::Context*))getProcAddress(libGLES_CM, "glCreateContext");
gl::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLES_CM, "glGetProcAddress");
gl::createBackBuffer = (egl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLES_CM, "createBackBuffer");
gl::createDepthStencil = (egl::Image *(*)(unsigned int, unsigned int, sw::Format, int, bool))getProcAddress(libGLES_CM, "createDepthStencil");
gl::createFrameBuffer = (sw::FrameBuffer *(*)(EGLNativeDisplayType, EGLNativeWindowType, int, int))getProcAddress(libGLES_CM, "createFrameBuffer");
#if defined(_WIN32)
const char *libGLESv2_lib = "libGLESv2.dll";
#else
const char *libGLESv2_lib = "libGLESv2.so.2";
......@@ -95,7 +108,7 @@ CONSTRUCTOR static bool eglAttachProcess()
gl2::createDepthStencil = (egl::Image *(*)(unsigned int, unsigned int, sw::Format, int, bool))getProcAddress(libGLESv2, "createDepthStencil");
gl2::createFrameBuffer = (sw::FrameBuffer *(*)(EGLNativeDisplayType, EGLNativeWindowType, int, int))getProcAddress(libGLESv2, "createFrameBuffer");
return libGLESv2 != 0;
return libGLES_CM != 0 || libGLESv2 != 0;
}
DESTRUCTOR static void eglDetachProcess()
......@@ -257,6 +270,15 @@ void error(EGLint errorCode)
}
}
namespace gl
{
egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext) = 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;
sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height) = 0;
}
namespace gl2
{
egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext) = 0;
......@@ -266,4 +288,5 @@ namespace gl2
sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height) = 0;
}
void *libGLES_CM = 0; // Handle to the libGLES_CM module
void *libGLESv2 = 0; // Handle to the libGLESv2 module
......@@ -82,6 +82,16 @@ namespace sw
enum Format : unsigned char;
}
// libGLES_CM dependencies
namespace gl
{
extern egl::Context *(*createContext)(const egl::Config *config, const egl::Context *shareContext);
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);
extern sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height);
}
// libGLESv2 dependencies
namespace gl2
{
......@@ -92,6 +102,7 @@ namespace gl2
extern sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height);
}
extern void *libGLESv2; // Handle to the libGLESv2 module
extern void *libGLES_CM; // Handle to the libGLES_CM module
extern void *libGLESv2; // Handle to the libGLESv2 module
#endif // LIBEGL_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