/* * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * DongKyun Yun * SangJin Kim * HyunGoo Kang * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Contributors: * - S-Core Co., Ltd * */ #include "implement.h" #include EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) { void* (*fpVGCreateContext)(void*) = NULL;//jcpark #if defined(PROVIDING_RUNTIME_BINDING) void* (*fpCreateContext)(void) = NULL; #endif EGLint apiVersion = 1; struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy); if (pDisplay == NULL) { EGLINTER(SetError)(EGL_BAD_DISPLAY); return EGL_NO_CONTEXT; } if (pDisplay->bInitialized == EGL_FALSE) { EGLINTER(SetError)(EGL_NOT_INITIALIZED); return EGL_NO_CONTEXT; } struct ConfigExtra* pConfig = EGLINTER(LookUpConfig)(pDisplay, config); if (pConfig == NULL) { EGLINTER(SetError)(EGL_BAD_CONFIG); return EGL_NO_CONTEXT; } struct ContextExtra* pShare = NULL; if (share_context != EGL_NO_CONTEXT) { pShare = EGLINTER(LookUpContext)(share_context); if (pShare == NULL) { EGLINTER(SetError)(EGL_BAD_CONTEXT); return EGL_NO_CONTEXT; } } while ((attrib_list != NULL) && (*attrib_list != EGL_NONE)) { switch (*attrib_list) { case EGL_CONTEXT_CLIENT_VERSION: if (EGLINTER(global).currentAPI != EGL_OPENGL_ES_API) { EGLINTER(SetError)(EGL_BAD_ATTRIBUTE); return; } apiVersion = *(attrib_list + 1); switch (apiVersion) { default: EGLINTER(SetError)(EGL_BAD_ATTRIBUTE); return; case 1: if ((pConfig->renderableType & EGL_OPENGL_ES_BIT) == 0) { EGLINTER(SetError)(EGL_BAD_ATTRIBUTE); return; } break; case 2: if ((pConfig->renderableType & EGL_OPENGL_ES2_BIT) == 0) { EGLINTER(SetError)(EGL_BAD_ATTRIBUTE); return; } break; } attrib_list++; break; default: EGLINTER(SetError)(EGL_BAD_ATTRIBUTE); return EGL_NO_CONTEXT; } attrib_list++; } GLXContext native = FNPTR(CreateNewContext)(pDisplay->native, pConfig->native, GLX_RGBA_TYPE, (pShare == NULL) ? NULL : pShare->native, True); EGLContext unique = (EGLContext)(native); struct ContextExtra* pContext = EGLINTER(LookUpContext)(unique); if (pContext == NULL) { pContext = EGLINTER(InsertContext)(unique); if (pContext == NULL) { EGLINTER(SetError)(EGL_BAD_ALLOC); return EGL_NO_CONTEXT; } pContext->native = native; pContext->display = dpy; pContext->config = config; pContext->renderBuffer = EGL_NONE; pContext->apiKind = EGLINTER(global).currentAPI; pContext->apiVersion = apiVersion; pContext->deleted = EGL_FALSE; switch (pContext->apiKind) { default: case EGL_OPENGL_API: pContext->apiContext = NULL; break; #if defined(PROVIDING_RUNTIME_BINDING) case EGL_OPENGL_ES_API: if (pContext->apiVersion == 2) { if (EGLINTER(global).dlES2 == NULL) { if ((EGLINTER(global).dlES2 = dlopen(GL_ES2_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL)) == NULL) { EGLINTER(SetError)(EGL_BAD_ACCESS); return; } } fpCreateContext = dlsym(EGLINTER(global).dlES2, EGLCROSS_PREFIX "CreateContext"); if (fpCreateContext != NULL) { pContext->apiContext = (*fpCreateContext)(); } } else { if (EGLINTER(global).dlES1 == NULL) { if ((EGLINTER(global).dlES1 = dlopen(GL_ES1_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL)) == NULL) { EGLINTER(SetError)(EGL_BAD_ACCESS); return; } } fpCreateContext = dlsym(EGLINTER(global).dlES1, EGLCROSS_PREFIX "CreateContext"); if (fpCreateContext != NULL) { pContext->apiContext = (*fpCreateContext)(); } } break; #else case EGL_OPENGL_ES_API: pContext->apiContext = EGLCROSS(CreateContext)(); break; #endif case EGL_OPENVG_API: /* TODO: OpenVG may need some action here */ //jcpark if (EGLINTER(global).dlVG == NULL) { if ((EGLINTER(global).dlVG = dlopen(VG_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL)) == NULL) { EGLINTER(SetError)(EGL_BAD_ACCESS); return; } } fpVGCreateContext = dlsym(EGLINTER(global).dlVG, "vg4egl_CreateContext"); if (fpVGCreateContext != NULL) { pContext->apiContext = (*fpVGCreateContext)(NULL); } break; } } else { EGLINTER(SetError)(EGL_BAD_CONTEXT); return EGL_NO_CONTEXT; } return (EGLContext)(pContext->native); }