Initial commit
[profile/ivi/simulator-opengl.git] / egl_1_4 / 37DestroyContext.c
1 /* 
2  * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * Contact:
5  * DongKyun Yun <dk77.yun@samsung.com>
6  * SangJin Kim <sangjin3.kim@samsung.com>
7  * HyunGoo Kang <hyungoo1.kang@samsung.com>
8  *
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:
15  * 
16  * The above copyright notice and this permission notice shall be included in all
17  * copies or substantial portions of the Software.
18  * 
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
25  * SOFTWARE.
26  * 
27  * Contributors:
28  * - S-Core Co., Ltd
29  *
30  */
31
32 #include "implement.h"
33 #include <dlfcn.h>
34
35
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;
40 #endif
41         struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy);
42         if (pDisplay == NULL) {
43                 EGLINTER(SetError)(EGL_BAD_DISPLAY);
44                 return EGL_FALSE;
45         }
46         if (pDisplay->bInitialized == EGL_FALSE) {
47                 EGLINTER(SetError)(EGL_NOT_INITIALIZED);
48                 return EGL_FALSE;
49         }
50
51
52         struct ContextExtra* pContext = EGLINTER(LookUpContext)(ctx);
53         if (pContext == NULL) {
54                 EGLINTER(SetError)(EGL_BAD_CONTEXT);
55                 return EGL_FALSE;
56         }
57 //      switch (pContext->apiKind) {
58 //      default:
59 //      case EGL_OPENGL_API:
60 //              assert(pContext->apiContext == NULL);
61 //              break;
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))
67 //                                      == NULL) {
68 //                                      EGLINTER(SetError)(EGL_BAD_ACCESS);
69 //                                      return;
70 //                              }
71 //                      }
72 //                      fpReleaseContext = dlsym(EGLINTER(global).dlES2, EGLCROSS_PREFIX "ReleaseContext");
73 //                      if (fpReleaseContext != NULL) {
74 //                              (*fpReleaseContext)(pContext->apiContext);
75 //                              pContext->apiContext = NULL;
76 //                      }
77 //              } else { 
78 //                      if (EGLINTER(global).dlES1 == NULL) {
79 //                              if ((EGLINTER(global).dlES1 = dlopen(GL_ES1_SO_FILENAME, RTLD_NOW | RTLD_GLOBAL))
80 //                                      == NULL) {
81 //                                      EGLINTER(SetError)(EGL_BAD_ACCESS);
82 //                                      return;
83 //                              }
84 //                      }
85 //                      fpReleaseContext = dlsym(EGLINTER(global).dlES1, EGLCROSS_PREFIX "ReleaseContext");
86 //                      if (fpReleaseContext != NULL) {
87 //                              (*fpReleaseContext)(pContext->apiContext);
88 //                              pContext->apiContext = NULL;
89 //                      }
90 //              }
91 //              break;
92 //#else
93 //      case EGL_OPENGL_ES_API:
94 //              if (pContext->apiContext != NULL) {
95 //                      EGLCROSS(ReleaseContext)(pContext->apiContext);
96 //              }
97 //              break;
98 //#endif
99 //      case EGL_OPENVG_API:
100 //              /* TODO: OpenVG may need some action here */
101 //
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);
106 //                                      return;
107 //                      }
108 //              }
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");
114 //              }
115 //
116 //              break;
117 //      }
118 //      FNPTR(DestroyContext)(pDisplay->native, pContext->native);
119 //      EGLINTER(DeleteContext)(ctx);
120 //      
121 //      return EGL_TRUE;
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
126          */
127         struct ContextExtra* pPrevious = NULL;
128         GLXContext nativePrevious = FNPTR(GetCurrentContext)();
129         if (nativePrevious != NULL) {
130                 EGLContext uniquePrevious = (EGLContext)(nativePrevious);
131                 pPrevious = EGLINTER(LookUpContext)(uniquePrevious);
132         }
133         if (pContext == pPrevious) {
134                 pContext->deleted = EGL_TRUE;
135                 return EGL_TRUE;
136         }
137         
138         return EGLINTER(FreeContext)(pContext);
139 }