2 * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 * DongKyun Yun <dk77.yun@samsung.com>
6 * SangJin Kim <sangjin3.kim@samsung.com>
7 * HyunGoo Kang <hyungoo1.kang@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy of
10 * this software and associated documentation files (the "Software"), to deal in
11 * the Software without restriction, including without limitation the rights to
12 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13 * of the Software, and to permit persons to whom the Software is furnished to do
14 * so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include "implement.h"
36 EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
37 void (*fpVGReleaseContext)(void*) = NULL;//jcpark
38 #if defined(PROVIDING_RUNTIME_BINDING)
39 void (*fpReleaseContext)(void*) = NULL;
41 struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy);
42 if (pDisplay == NULL) {
43 EGLINTER(SetError)(EGL_BAD_DISPLAY);
46 if (pDisplay->bInitialized == EGL_FALSE) {
47 EGLINTER(SetError)(EGL_NOT_INITIALIZED);
52 struct ContextExtra* pContext = EGLINTER(LookUpContext)(ctx);
53 if (pContext == NULL) {
54 EGLINTER(SetError)(EGL_BAD_CONTEXT);
57 // switch (pContext->apiKind) {
59 // case EGL_OPENGL_API:
60 // assert(pContext->apiContext == NULL);
62 //#if defined(PROVIDING_RUNTIME_BINDING)
63 // case EGL_OPENGL_ES_API:
64 // if (pContext->apiVersion == 2) {
65 // if (EGLINTER(global).dlES2 == NULL) {
66 // if ((EGLINTER(global).dlES2 = dlopen(GL_ES2_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL))
68 // EGLINTER(SetError)(EGL_BAD_ACCESS);
72 // fpReleaseContext = dlsym(EGLINTER(global).dlES2, EGLCROSS_PREFIX "ReleaseContext");
73 // if (fpReleaseContext != NULL) {
74 // (*fpReleaseContext)(pContext->apiContext);
75 // pContext->apiContext = NULL;
78 // if (EGLINTER(global).dlES1 == NULL) {
79 // if ((EGLINTER(global).dlES1 = dlopen(GL_ES1_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL))
81 // EGLINTER(SetError)(EGL_BAD_ACCESS);
85 // fpReleaseContext = dlsym(EGLINTER(global).dlES1, EGLCROSS_PREFIX "ReleaseContext");
86 // if (fpReleaseContext != NULL) {
87 // (*fpReleaseContext)(pContext->apiContext);
88 // pContext->apiContext = NULL;
93 // case EGL_OPENGL_ES_API:
94 // if (pContext->apiContext != NULL) {
95 // EGLCROSS(ReleaseContext)(pContext->apiContext);
99 // case EGL_OPENVG_API:
100 // /* TODO: OpenVG may need some action here */
102 // if (EGLINTER(global).dlVG == NULL) { printf("==jcpark vg4egl_DestroyContext 2\n");
103 // if ((EGLINTER(global).dlVG = dlopen(VG_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL))
104 // == NULL) { printf("==jcpark vg4egl_DestroyContext 3\n");
105 // EGLINTER(SetError)(EGL_BAD_ACCESS);
109 // fpVGReleaseContext = dlsym(EGLINTER(global).dlVG, "vg4egl_DestroyContext");
110 // if (fpVGReleaseContext != NULL) {
111 // (*fpVGReleaseContext)(pContext->apiContext);
112 // pContext->apiContext = NULL;
113 // printf("==jcpark== vg4egl_DestroyContext working\n");
118 // FNPTR(DestroyContext)(pDisplay->native, pContext->native);
119 // EGLINTER(DeleteContext)(ctx);
122 /* Do not delete context that is current, but mark it and deleted it
123 * when change current in eglMakeCurrent
124 * TODO: Add refcount to track context, so can delete it when refcount
125 * reach 0 in eglDestroyContext/eglMakeCurrent
127 struct ContextExtra* pPrevious = NULL;
128 GLXContext nativePrevious = FNPTR(GetCurrentContext)();
129 if (nativePrevious != NULL) {
130 EGLContext uniquePrevious = (EGLContext)(nativePrevious);
131 pPrevious = EGLINTER(LookUpContext)(uniquePrevious);
133 if (pContext == pPrevious) {
134 pContext->deleted = EGL_TRUE;
138 return EGLINTER(FreeContext)(pContext);