+
+ if (conflict_api >= 0 && _eglGetAPIContext(conflict_api))
+ return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
+
+ return EGL_TRUE;
+}
+
+
+/**
+ * Bind the context to the current thread and given surfaces. Return the
+ * previously bound context and the surfaces it bound to. Each argument is
+ * both input and output.
+ */
+EGLBoolean
+_eglBindContext(_EGLContext **ctx, _EGLSurface **draw, _EGLSurface **read)
+{
+ _EGLThreadInfo *t = _eglGetCurrentThread();
+ _EGLContext *newCtx = *ctx, *oldCtx;
+
+ if (!_eglCheckMakeCurrent(newCtx, *draw, *read))
+ return EGL_FALSE;
+
+ /* bind the new context */
+ oldCtx = _eglBindContextToThread(newCtx, t);
+ *ctx = oldCtx;
+ if (newCtx)
+ _eglBindContextToSurfaces(newCtx, draw, read);
+
+ /* unbind the old context from its binding surfaces */
+ if (oldCtx && oldCtx != newCtx) {
+ /*
+ * If the new context replaces some old context, the new one should not
+ * be current before the replacement and it should not be bound to any
+ * surface.
+ */
+ if (newCtx)
+ assert(!*draw && !*read);
+
+ *draw = oldCtx->DrawSurface;
+ *read = oldCtx->ReadSurface;
+ assert(*draw && *read);
+
+ _eglBindContextToSurfaces(NULL, draw, read);