1d12a405cfc896f20b7a009015b3ef15556f9502
5 #include "eglcontext.h"
7 #include "eglglobals.h"
9 #include "eglsurface.h"
13 * Initialize the given _EGLContext object to defaults.
16 _eglInitContext(_EGLContext
*ctx
)
18 /* just init to zero for now */
19 memset(ctx
, 0, sizeof(_EGLContext
));
24 * Assign an EGLContext handle to the _EGLContext object then put it into
28 _eglSaveContext(_EGLContext
*ctx
)
31 ctx
->Handle
= _eglHashGenKey(_eglGlobal
.Contexts
);
32 _eglHashInsert(_eglGlobal
.Contexts
, ctx
->Handle
, ctx
);
37 * Remove the given _EGLContext object from the hash table.
40 _eglRemoveContext(_EGLContext
*ctx
)
42 _eglHashRemove(_eglGlobal
.Contexts
, ctx
->Handle
);
47 * Return the _EGLContext object that corresponds to the given
51 _eglLookupContext(EGLContext ctx
)
53 _EGLContext
*c
= (_EGLContext
*) _eglHashLookup(_eglGlobal
.Contexts
, ctx
);
59 * Return the currently bound _EGLContext object, or NULL.
62 _eglGetCurrentContext(void)
64 /* XXX this should be per-thread someday */
65 return _eglGlobal
.CurrentContext
;
70 * Just a placeholder/demo function. Real driver will never use this!
73 _eglCreateContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
, EGLContext share_list
, const EGLint
*attrib_list
)
75 _EGLConfig
*conf
= _eglLookupConfig(drv
, dpy
, config
);
77 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
78 return EGL_NO_CONTEXT
;
81 if (share_list
!= EGL_NO_CONTEXT
) {
82 _EGLContext
*shareCtx
= _eglLookupContext(share_list
);
84 _eglError(EGL_BAD_CONTEXT
, "eglCreateContext(share_list)");
85 return EGL_NO_CONTEXT
;
89 return EGL_NO_CONTEXT
;
94 * Default fallback routine - drivers should usually override this.
97 _eglDestroyContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
)
99 _EGLContext
*context
= _eglLookupContext(ctx
);
101 _eglHashRemove(_eglGlobal
.Contexts
, ctx
);
102 if (context
->IsBound
) {
103 context
->DeletePending
= EGL_TRUE
;
111 _eglError(EGL_BAD_CONTEXT
, "eglDestroyContext");
118 _eglQueryContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLContext ctx
, EGLint attribute
, EGLint
*value
)
120 _EGLContext
*c
= _eglLookupContext(ctx
);
126 _eglError(EGL_BAD_CONTEXT
, "eglQueryContext");
132 *value
= GET_CONFIG_ATTRIB(c
->Config
, EGL_CONFIG_ID
);
135 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryContext");
142 * Drivers will typically call this to do the error checking and
143 * update the various IsBound and DeletePending flags.
144 * Then, the driver will do its device-dependent Make-Current stuff.
147 _eglMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface d
, EGLSurface r
, EGLContext context
)
149 _EGLContext
*ctx
= _eglLookupContext(context
);
150 _EGLSurface
*draw
= _eglLookupSurface(d
);
151 _EGLSurface
*read
= _eglLookupSurface(r
);
153 _EGLContext
*oldContext
= _eglGetCurrentContext();
154 _EGLSurface
*oldDrawSurface
= _eglGetCurrentSurface(EGL_DRAW
);
155 _EGLSurface
*oldReadSurface
= _eglGetCurrentSurface(EGL_READ
);
159 if (draw
== NULL
|| read
== NULL
) {
160 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
163 if (draw
->Config
!= ctx
->Config
) {
164 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
167 if (read
->Config
!= ctx
->Config
) {
168 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
174 * check if the old context or surfaces need to be deleted
176 if (oldDrawSurface
!= NULL
) {
177 oldDrawSurface
->IsBound
= EGL_FALSE
;
178 if (oldDrawSurface
->DeletePending
) {
179 /* make sure we don't try to rebind a deleted surface */
180 if (draw
== oldDrawSurface
|| draw
== oldReadSurface
) {
183 /* really delete surface now */
184 drv
->DestroySurface(drv
, dpy
, oldDrawSurface
->Handle
);
187 if (oldReadSurface
!= NULL
&& oldReadSurface
!= oldDrawSurface
) {
188 oldReadSurface
->IsBound
= EGL_FALSE
;
189 if (oldReadSurface
->DeletePending
) {
190 /* make sure we don't try to rebind a deleted surface */
191 if (read
== oldDrawSurface
|| read
== oldReadSurface
) {
194 /* really delete surface now */
195 drv
->DestroySurface(drv
, dpy
, oldReadSurface
->Handle
);
198 if (oldContext
!= NULL
) {
199 oldContext
->IsBound
= EGL_FALSE
;
200 if (oldContext
->DeletePending
) {
201 /* make sure we don't try to rebind a deleted context */
202 if (ctx
== oldContext
) {
205 /* really delete context now */
206 drv
->DestroyContext(drv
, dpy
, oldContext
->Handle
);
211 /* check read/draw again, in case we deleted them above */
212 if (draw
== NULL
|| read
== NULL
) {
213 _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
216 ctx
->DrawSurface
= draw
;
217 ctx
->ReadSurface
= read
;
218 ctx
->IsBound
= EGL_TRUE
;
219 draw
->IsBound
= EGL_TRUE
;
220 read
->IsBound
= EGL_TRUE
;
223 _eglGlobal
.CurrentContext
= ctx
;