/* * 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 EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) { void* (*fpVGMakeCurrent)(void*) = NULL;//jcpark Bool(*fpVGSetSurfaceSize)(EGLint,EGLint) = NULL;//jcpark Bool(*fpVGSetDrawSurface)(void*) = NULL;//jcpark #if defined(PROVIDING_RUNTIME_BINDING) void (*fpMakeCurrent)(void*) = NULL; #endif struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy); if (pDisplay == NULL) { EGLINTER(SetError)(EGL_BAD_DISPLAY); return EGL_FALSE; } if (pDisplay->bInitialized == EGL_FALSE) { EGLINTER(SetError)(EGL_NOT_INITIALIZED); return EGL_FALSE; } struct SurfaceExtra* pDraw = NULL; if (draw != EGL_NO_SURFACE) { pDraw = EGLINTER(LookUpSurface)(draw); if (pDraw == NULL) { EGLINTER(SetError)(EGL_BAD_SURFACE); return EGL_FALSE; } } struct SurfaceExtra* pRead = NULL; if (read == draw) { pRead = pDraw; } else if (read != EGL_NO_SURFACE) { pRead = EGLINTER(LookUpSurface)(read); if (pRead == NULL) { EGLINTER(SetError)(EGL_BAD_SURFACE); return EGL_FALSE; } } struct ContextExtra* pContext = NULL; if (ctx != EGL_NO_CONTEXT) { if (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE) { EGLINTER(SetError)(EGL_BAD_MATCH); return EGL_FALSE; } pContext = EGLINTER(LookUpContext)(ctx); if (pContext == NULL) { EGLINTER(SetError)(EGL_BAD_CONTEXT); return EGL_FALSE; } } else { if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { EGLINTER(SetError)(EGL_BAD_MATCH); return EGL_FALSE; } } struct ContextExtra* pPrevious = NULL; GLXContext nativePrevious = FNPTR(GetCurrentContext)(); if (nativePrevious != NULL) { EGLContext uniquePrevious = (EGLContext)(nativePrevious); pPrevious = EGLINTER(LookUpContext)(uniquePrevious); } if (pPrevious != NULL) { switch (pPrevious->apiKind) { default: case EGL_OPENGL_API: break; #if defined(PROVIDING_RUNTIME_BINDING) case EGL_OPENGL_ES_API: if (pPrevious->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; } } fpMakeCurrent = dlsym(EGLINTER(global).dlES2, EGLCROSS_PREFIX "MakeCurrent"); // if (fpMakeCurrent != NULL) { // (*fpMakeCurrent)(NULL); // } } 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; } } fpMakeCurrent = dlsym(EGLINTER(global).dlES1, EGLCROSS_PREFIX "MakeCurrent"); // if (fpMakeCurrent != NULL) { // (*fpMakeCurrent)(NULL); // } } break; #else case EGL_OPENGL_ES_API: EGLCROSS(MakeCurrent)(NULL); 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; } } fpVGMakeCurrent = dlsym(EGLINTER(global).dlVG, "vg4egl_SetContext"); if (fpVGMakeCurrent != NULL) { (*fpVGMakeCurrent)(pContext->apiContext); } else { printf("No symbol found for vg4egl_SetContext\n"); } fpVGSetSurfaceSize = dlsym(EGLINTER(global).dlVG, "vg4egl_SetSurfaceSize"); if (fpVGSetSurfaceSize!= NULL) { fpVGSetSurfaceSize(320,320); } else { printf("No symbol found for vg4egl_SetSurfaceSize\n"); } fpVGSetDrawSurface = dlsym(EGLINTER(global).dlVG, " vg4egl_SetDrawSurface"); if (fpVGSetDrawSurface!= NULL) { fpVGSetDrawSurface(pContext->apiContext); } else { printf("No symbol found for vg4egl_SetDrawSurface\n"); } break; } } Bool check = FNPTR(MakeContextCurrent)(pDisplay->native, (pDraw == NULL) ? None : pDraw->native, (pRead == NULL) ? None : pRead->native, (pContext == NULL) ? NULL : pContext->native); if (check == False) { EGLINTER(SetError)(EGL_BAD_ALLOC); return EGL_FALSE; } if (pContext != NULL) { pContext->renderBuffer = pDraw->renderBuffer; } #if defined(PROVIDING_RUNTIME_BINDING) if (pContext != NULL) { switch (pContext->apiKind) { default: EGLINTER(ResetGLFnptrs)(&(EGLINTER(global))); break; case EGL_OPENGL_API: EGLINTER(BindGLFnptrs)(&(EGLINTER(global))); break; 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; } } fpMakeCurrent = dlsym(EGLINTER(global).dlES2, EGLCROSS_PREFIX "MakeCurrent"); if (fpMakeCurrent != NULL) { (*fpMakeCurrent)(pContext->apiContext); } EGLINTER(BindES2Fnptrs)(&(EGLINTER(global))); } 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; } } fpMakeCurrent = dlsym(EGLINTER(global).dlES1, EGLCROSS_PREFIX "MakeCurrent"); if (fpMakeCurrent != NULL) { (*fpMakeCurrent)(pContext->apiContext); } EGLINTER(BindES1Fnptrs)(&(EGLINTER(global))); } break; 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; } } fpMakeCurrent = dlsym(EGLINTER(global).dlVG, "vg4egl_SetContext"); if (fpMakeCurrent != NULL) { (*fpMakeCurrent)(pContext->apiContext); } fpVGSetSurfaceSize = dlsym(EGLINTER(global).dlVG, "vg4egl_SetSurfaceSize"); if (fpVGSetSurfaceSize!= NULL) { fpVGSetSurfaceSize(320,320); } else { printf("No symbol found for vg4egl_SetSurfaceSize\n"); } fpVGSetDrawSurface = dlsym(EGLINTER(global).dlVG, "vg4egl_SetDrawSurface"); if (fpVGSetDrawSurface!= NULL) { fpVGSetDrawSurface(pContext->apiContext); } else { printf("No symbol found for vg4egl_SetDrawSurface\n");//jcpark } EGLINTER(BindES1Fnptrs)(&(EGLINTER(global))); break; } } else { EGLINTER(ResetGLFnptrs)(&(EGLINTER(global))); } #else if (pContext != NULL) { switch (pContext->apiKind) { default: case EGL_OPENGL_API: break; case EGL_OPENGL_ES_API: EGLCROSS(MakeCurrent)(pContext->apiContext); break; case EGL_OPENVG_API: /* TODO: OpenVG may need some action here */ //jcpark I don't know what to do here! break; } } #endif /* Delete previous "current" if it was deleted */ if (pPrevious != NULL && pPrevious->deleted && pPrevious != pContext) EGLINTER(FreeContext)(pPrevious); return EGL_TRUE; }