static void _glitz_egl_make_current (void *abstract_drawable, void *abstract_context) { glitz_egl_context_t *context = (glitz_egl_context_t *) abstract_context; glitz_egl_surface_t *drawable = (glitz_egl_surface_t *) abstract_drawable; glitz_egl_display_info_t *display_info = drawable->screen_info->display_info; if (drawable->base.width != drawable->width || drawable->base.height != drawable->height) _glitz_egl_drawable_update_size (drawable, drawable->base.width, drawable->base.height); if ((eglGetCurrentContext () != context->egl_context) || (eglGetCurrentSurface ( EGL_READ ) != drawable->egl_surface)) { if (display_info->thread_info->cctx) { glitz_context_t *ctx = display_info->thread_info->cctx; if (ctx->lose_current) ctx->lose_current (ctx->closure); } eglMakeCurrent (display_info->egl_display, drawable->egl_surface, drawable->egl_surface, context->egl_context); } display_info->thread_info->cctx = &context->base; }
static jlong jni_eglGetCurrentSurface(JNIEnv *_env, jobject _this, jint readdraw) { if ((readdraw != EGL_READ) && (readdraw != EGL_DRAW)) { jniThrowException(_env, "java/lang/IllegalArgumentException", NULL); return 0; } return reinterpret_cast<jlong>(eglGetCurrentSurface(readdraw)); }
int Java_org_yabause_android_YabauseRunnable_initViewport() { int error; char * buf; g_Display = eglGetCurrentDisplay(); g_Surface = eglGetCurrentSurface(EGL_READ); g_Context = eglGetCurrentContext(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0, 320, 224, 0, 1, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glDisable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); yprintf(glGetString(GL_VENDOR)); yprintf(glGetString(GL_RENDERER)); yprintf(glGetString(GL_VERSION)); yprintf(glGetString(GL_EXTENSIONS)); yprintf(eglQueryString(g_Display,EGL_EXTENSIONS)); eglSwapInterval(g_Display,0); eglMakeCurrent(g_Display,EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT); return 0; }
void CEGLGraphicsInterface::CopyBitmapL(CFbsBitmap* aPixMap, CFbsBitmap* ) { if (eglCopyBuffers(iEglDisplay, eglGetCurrentSurface(EGL_READ), aPixMap) == EGL_FALSE) { User::Leave(MapEGLErrorCodeToSymbian(eglGetError())); } aPixMap->SetDisplayMode(aPixMap->DisplayMode()); }
void EGLDisplayOpenVG::removeSurface(const EGLSurface& surface, bool destroySurface) { ASSERT(surface != EGL_NO_SURFACE); #if PLATFORM(OLYMPIA) if (destroySurface) { // Work around a bug in our EGL implementation where the VGImage // referenced by eglCreatePbufferFromClientBuffer is not released // when destroying the context, RIM Bug #1591. // The context that created the VGImage needs to be current for // it to be released. sharedPlatformSurface()->makeResourceCreationContextCurrent(); } else #endif if (eglGetCurrentSurface(EGL_DRAW) == surface) { eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); ASSERT_EGL_NO_ERROR(); } // Destroy the context associated to the surface, if we already created one. if (m_surfaceConfigIds.contains(surface)) { EGLint surfaceConfigId = m_surfaceConfigIds.take(surface); // take = get and remove bool isContextReferenced = false; if (m_compatibleConfigIds.contains(surfaceConfigId)) surfaceConfigId = m_compatibleConfigIds.get(surfaceConfigId); HashMap<EGLSurface, EGLint>::iterator end = m_surfaceConfigIds.end(); // ...but only if there's no other surfaces associated to that context. for (HashMap<EGLSurface, EGLint>::iterator it = m_surfaceConfigIds.begin(); it != end; ++it) { if ((*it).second == surfaceConfigId) { isContextReferenced = true; break; } } if (!isContextReferenced && m_contexts.contains(surfaceConfigId)) { EGLContext context = m_contexts.take(surfaceConfigId); eglDestroyContext(m_display, context); ASSERT_EGL_NO_ERROR(); } } m_platformSurfaces.remove(surface); HashMap<EGLNativeWindowType, EGLSurface>::iterator end = m_windowSurfaces.end(); for (HashMap<EGLNativeWindowType, EGLSurface>::iterator it = m_windowSurfaces.begin(); it != end; ++it) { if ((*it).second == surface) { m_windowSurfaces.remove(it); break; } } if (destroySurface) { eglDestroySurface(m_display, surface); ASSERT_EGL_NO_ERROR(); } }
bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface) { Q_ASSERT(surface->surface()->supportsOpenGL()); eglBindAPI(m_api); EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface); if (eglSurface == EGL_NO_SURFACE) return false; // shortcut: on some GPUs, eglMakeCurrent is not a cheap operation if (eglGetCurrentContext() == m_eglContext && eglGetCurrentDisplay() == m_eglDisplay && eglGetCurrentSurface(EGL_READ) == eglSurface && eglGetCurrentSurface(EGL_DRAW) == eglSurface) { return true; } const bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext); if (ok) { if (!m_swapIntervalEnvChecked) { m_swapIntervalEnvChecked = true; if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_SWAPINTERVAL")) { QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL"); bool intervalOk; const int swapInterval = swapIntervalString.toInt(&intervalOk); if (intervalOk) m_swapIntervalFromEnv = swapInterval; } } const int requestedSwapInterval = m_swapIntervalFromEnv >= 0 ? m_swapIntervalFromEnv : surface->format().swapInterval(); if (requestedSwapInterval >= 0 && m_swapInterval != requestedSwapInterval) { m_swapInterval = requestedSwapInterval; if (eglSurface != EGL_NO_SURFACE) // skip if using surfaceless context eglSwapInterval(eglDisplay(), m_swapInterval); } } else { qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); } return ok; }
/* EGLSurface eglGetCurrentSurface ( EGLint readdraw ) */ static jobject android_eglGetCurrentSurface (JNIEnv *_env, jobject _this, jint readdraw) { EGLSurface _returnValue = (EGLSurface) 0; _returnValue = eglGetCurrentSurface( (EGLint)readdraw ); return toEGLHandle(_env, eglsurfaceClass, eglsurfaceConstructor, _returnValue); }
bool SurfaceOpenVG::isCurrent() const { #if PLATFORM(EGL) return m_eglSurface == eglGetCurrentSurface(EGL_DRAW); #else ASSERT_NOT_REACHED(); return false; #endif }
static int evgl_eng_make_current(void *data, void *surface, void *ctxt, int flush) { Render_Engine *re; Outbuf *ob; EGLContext ctx; EGLSurface surf; int ret = 0; if (!(re = (Render_Engine *)data)) return 0; if (!(ob = eng_get_ob(re))) return 0; ctx = (EGLContext)ctxt; surf = (EGLSurface)surface; if ((!ctxt) && (!surface)) { ret = eglMakeCurrent(ob->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (!ret) { ERR("eglMakeCurrent Failed: %#x", eglGetError()); return 0; } return 1; } if ((eglGetCurrentContext() != ctx) || (eglGetCurrentSurface(EGL_READ) != surf) || (eglGetCurrentSurface(EGL_DRAW) != surf)) { if (flush) eng_window_use(NULL); ret = eglMakeCurrent(ob->egl_disp, surf, surf, ctx); if (!ret) { ERR("eglMakeCurrent Failed: %#x", eglGetError()); return 0; } } return 1; }
void TopCanvas::Resume() { #if defined(ANDROID) && defined(USE_EGL) surface = eglGetCurrentSurface(EGL_DRAW); #endif OpenGL::SetupContext(); OpenGL::SetupViewport(UnsignedPoint2D(size.cx, size.cy)); }
void EGLWindow::setVSyncEnabled(bool vsync) { mVSync = vsync; // we need to make our context current to set vsync // store previous context to restore when finished. ::EGLSurface oldRead = eglGetCurrentSurface(EGL_READ); EGL_CHECK_ERROR ::EGLSurface oldDraw = eglGetCurrentSurface(EGL_DRAW); EGL_CHECK_ERROR ::EGLContext oldContext = eglGetCurrentContext(); EGL_CHECK_ERROR ::EGLDisplay dpy = mGLSupport->getGLDisplay(); mContext->setCurrent(); if (! mIsExternalGLControl ) { eglSwapInterval(dpy, vsync ? mVSyncInterval : 0); EGL_CHECK_ERROR }
void recreate(void) { EGLContext currentContext = eglGetCurrentContext(); EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW); EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_READ); bool rebindDrawSurface = currentDrawSurface == surface; bool rebindReadSurface = currentReadSurface == surface; if (rebindDrawSurface || rebindReadSurface) { eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface(eglDisplay, surface); } const EglVisual * eglVisual = static_cast<const EglVisual *>(visual); ANativeWindow_setBuffersGeometry(window.get(), 0, 0, eglVisual->format); surface = eglCreateWindowSurface(eglDisplay, eglVisual->config, (EGLNativeWindowType)window.get(), NULL); if (rebindDrawSurface || rebindReadSurface) eglMakeCurrent(eglDisplay, surface, surface, currentContext); }
FScopeContext(FPlatformOpenGLContext* PlatformContext) { check(PlatformContext); LastContext = eglGetCurrentContext(); LastSurface = eglGetCurrentSurface(EGL_DRAW); bSameContextAndSurface = (LastContext == PlatformContext->eglContext) && (LastSurface == PlatformContext->eglSurface); if (!bSameContextAndSurface) { eglMakeCurrent(AndroidEGL::GetInstance()->GetDisplay(), PlatformContext->eglSurface, PlatformContext->eglSurface, PlatformContext->eglContext); } }
void TopCanvas::Create(PixelSize new_size, bool full_screen, bool resizable) { #ifdef USE_EGL display = eglGetDisplay(EGL_DEFAULT_DISPLAY); surface = eglGetCurrentSurface(EGL_DRAW); #endif OpenGL::SetupContext(); SetupViewport(new_size); }
/* ** GLimp_EndFrame */ void GLimp_EndFrame (void) { if (!androidSwapped) eglSwapBuffers( eglGetCurrentDisplay(), eglGetCurrentSurface( EGL_DRAW ) ); androidSwapped = false; // check logging QGL_EnableLogging( r_logFile->integer ); }
bool DiWin32EGLWindow::Create(uint32& width, uint32& height, const DiString& title, bool fullscreen) { ::EGLContext eglContext = 0; if (!mEglConfig) { uint32 samples = 0; int minAttribs[] = { EGL_LEVEL, 0, EGL_DEPTH_SIZE, 16, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NATIVE_RENDERABLE, EGL_FALSE, EGL_DEPTH_SIZE, EGL_DONT_CARE, EGL_NONE }; int maxAttribs[] = { EGL_SAMPLES, samples, EGL_STENCIL_SIZE, INT_MAX, EGL_NONE }; mEglConfig = mGLSupport->SelectGLConfig(minAttribs, maxAttribs); } bool ret = _Create(width, height, title, fullscreen); mContext = CreateEGLContext(); mContext->BeginContext(); ::EGLSurface oldDrawableDraw = eglGetCurrentSurface(EGL_DRAW); ::EGLSurface oldDrawableRead = eglGetCurrentSurface(EGL_READ); ::EGLContext oldContext = eglGetCurrentContext(); int glConfigID; mGLSupport->GetGLConfigAttrib(mEglConfig, EGL_CONFIG_ID, &glConfigID); DI_INFO("EGLWindow::create used FBConfigID = %d", glConfigID); return ret; }
/* private native int _getCurrentSurface ( int readdraw ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1getCurrentSurface() { jint readdraw = KNI_GetParameterAsInt(1); jint returnValue = (jint)eglGetCurrentSurface((EGLint)readdraw); #ifdef DEBUG printf("eglGetCurrentSurface(%d) = %d\n", readdraw, returnValue); #endif KNI_ReturnInt(returnValue); }
void recreate(void) { EGLContext currentContext = eglGetCurrentContext(); EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW); EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_READ); bool rebindDrawSurface = currentDrawSurface == surface; bool rebindReadSurface = currentReadSurface == surface; if (rebindDrawSurface || rebindReadSurface) { eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } eglDestroySurface(eglDisplay, surface); EGLConfig config = static_cast<const EglVisual *>(visual)->config; surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL); if (rebindDrawSurface || rebindReadSurface) { eglMakeCurrent(eglDisplay, surface, surface, currentContext); } }
bool GLEnv::InitWithCurrentContext() { if (IsInitialized()) return true; display_ = eglGetCurrentDisplay(); contexts_[0] = eglGetCurrentContext(); surfaces_[0] = SurfaceWindowPair(eglGetCurrentSurface(EGL_DRAW), NULL); return (context() != EGL_NO_CONTEXT) && (display() != EGL_NO_DISPLAY) && (surface() != EGL_NO_SURFACE); }
// Test a bug in our EGL TLS implementation. TEST_F(EGLThreadTest, ThreadInitCrash) { std::thread runner(&EGLThreadTest::threadingTest, this); // wait for signal from thread runner.join(); // crash, because the TLS value is NULL on main thread eglGetCurrentSurface(EGL_DRAW); eglGetCurrentContext(); eglTerminate(mDisplay); }
void eng_window_use(Evas_GL_Wl_Window *gw) { Eina_Bool force_use = EINA_FALSE; if (_evas_gl_wl_window) { if ((eglGetCurrentContext() != _evas_gl_wl_window->egl_context[0]) || (eglGetCurrentSurface(EGL_READ) != _evas_gl_wl_window->egl_surface[0]) || (eglGetCurrentSurface(EGL_DRAW) != _evas_gl_wl_window->egl_surface[0])) force_use = EINA_TRUE; } if ((_evas_gl_wl_window != gw) || (force_use)) { if (_evas_gl_wl_window) { evas_gl_common_context_use(_evas_gl_wl_window->gl_context); evas_gl_common_context_flush(_evas_gl_wl_window->gl_context); } _evas_gl_wl_window = gw; if (gw) { // EGL / GLES if (gw->egl_surface[0] != EGL_NO_SURFACE) { if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0], gw->egl_context[0]) == EGL_FALSE) { ERR("eglMakeCurrent() failed!"); } } } } if (gw) evas_gl_common_context_use(gw->gl_context); }
static jboolean android_view_HardwareRenderer_preserveBackBuffer(JNIEnv* env, jobject clazz) { EGLDisplay display = eglGetCurrentDisplay(); EGLSurface surface = eglGetCurrentSurface(EGL_DRAW); eglGetError(); eglSurfaceAttrib(display, surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); EGLint error = eglGetError(); if (error != EGL_SUCCESS) { RENDERER_LOGD("Could not enable buffer preserved swap behavior (%x)", error); } return error == EGL_SUCCESS; }
static void _egl_query_current_state (cairo_egl_context_t *ctx) { ctx->previous_surface = eglGetCurrentSurface (EGL_DRAW); ctx->previous_context = eglGetCurrentContext (); /* If any of the values were none, assume they are all none. Not all drivers seem well behaved when it comes to using these values across multiple threads. */ if (ctx->previous_surface == EGL_NO_SURFACE || ctx->previous_context == EGL_NO_CONTEXT) { ctx->previous_surface = EGL_NO_SURFACE; ctx->previous_context = EGL_NO_CONTEXT; } }
static jboolean android_view_HardwareRenderer_isBackBufferPreserved(JNIEnv* env, jobject clazz) { EGLDisplay display = eglGetCurrentDisplay(); EGLSurface surface = eglGetCurrentSurface(EGL_DRAW); EGLint value; eglGetError(); eglQuerySurface(display, surface, EGL_SWAP_BEHAVIOR, &value); EGLint error = eglGetError(); if (error != EGL_SUCCESS) { RENDERER_LOGD("Could not query buffer preserved swap behavior (%x)", error); } return error == EGL_SUCCESS && value == EGL_BUFFER_PRESERVED; }
void recreate(void) { EGLContext currentContext = eglGetCurrentContext(); EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW); EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_READ); bool rebindDrawSurface = currentDrawSurface == surface; bool rebindReadSurface = currentReadSurface == surface; if (rebindDrawSurface || rebindReadSurface) { eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } // XXX: Defer destruction to prevent getting the same surface as before, which seems to cause Mesa to crash EGLSurface oldSurface = surface; EGLConfig config = static_cast<const EglVisual *>(visual)->config; surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL); if (rebindDrawSurface || rebindReadSurface) { eglMakeCurrent(eglDisplay, surface, surface, currentContext); } eglDestroySurface(eglDisplay, oldSurface); }
SurfaceOpenVG* EGLDisplayOpenVG::currentSurface() { EGLDisplayManagerMap& managers = displayManagers(); EGLDisplay currentDisplay = eglGetCurrentDisplay(); if (currentDisplay == EGL_NO_DISPLAY || !managers.contains(currentDisplay)) return 0; EGLDisplayOpenVG* displayManager = managers.get(currentDisplay); EGLSurface currentSurface = eglGetCurrentSurface(EGL_DRAW); if (currentSurface == EGL_NO_SURFACE || !displayManager->m_platformSurfaces.contains(currentSurface)) return 0; return displayManager->m_platformSurfaces.get(currentSurface); }
bool GLEnv::Activate() { ALOGV("Activate()"); if (display() != eglGetCurrentDisplay() || context() != eglGetCurrentContext() || surface() != eglGetCurrentSurface(EGL_DRAW)) { // Make sure we are initialized if (context() == EGL_NO_CONTEXT || surface() == EGL_NO_SURFACE) return false; // Make our context current ALOGV("eglMakeCurrent"); eglMakeCurrent(display(), surface(), surface(), context()); return !CheckEGLMakeCurrentError(); } return true; }
void EGLDisplayOpenVG::destroySurface(const EGLSurface& surface) { ASSERT(surface != EGL_NO_SURFACE); if (eglGetCurrentSurface(EGL_DRAW) == surface) { eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); ASSERT_EGL_NO_ERROR(); } // Destroy the context associated to the surface, if we already created one. if (m_surfaceConfigIds.contains(surface)) { EGLint surfaceConfigId = m_surfaceConfigIds.take(surface); // take = get and remove bool isContextReferenced = false; if (m_compatibleConfigIds.contains(surfaceConfigId)) surfaceConfigId = m_compatibleConfigIds.get(surfaceConfigId); HashMap<EGLSurface, EGLint>::iterator end = m_surfaceConfigIds.end(); // ...but only if there's no other surfaces associated to that context. for (HashMap<EGLSurface, EGLint>::iterator it = m_surfaceConfigIds.begin(); it != end; ++it) { if ((*it).second == surfaceConfigId) { isContextReferenced = true; break; } } if (!isContextReferenced && m_contexts.contains(surfaceConfigId)) { EGLContext context = m_contexts.take(surfaceConfigId); eglDestroyContext(m_display, context); ASSERT_EGL_NO_ERROR(); } } m_platformSurfaces.remove(surface); HashMap<EGLNativeWindowType, EGLSurface>::iterator end = m_windowSurfaces.end(); for (HashMap<EGLNativeWindowType, EGLSurface>::iterator it = m_windowSurfaces.begin(); it != end; ++it) { if ((*it).second == surface) { m_windowSurfaces.remove(it); break; } } eglDestroySurface(m_display, surface); ASSERT_EGL_NO_ERROR(); }
static void _glitz_egl_context_update (glitz_egl_surface_t *drawable, glitz_constraint_t constraint) { EGLContext egl_context; drawable->base.flushed = drawable->base.finished = 0; switch (constraint) { case GLITZ_NONE: break; case GLITZ_ANY_CONTEXT_CURRENT: { glitz_egl_display_info_t *dinfo = drawable->screen_info->display_info; if (dinfo->thread_info->cctx) { _glitz_egl_context_make_current (drawable, 0); } else { egl_context = eglGetCurrentContext (); if (egl_context == (EGLContext) 0) _glitz_egl_context_make_current (drawable, 0); } } break; case GLITZ_CONTEXT_CURRENT: egl_context = eglGetCurrentContext (); if (egl_context != drawable->context->egl_context) _glitz_egl_context_make_current (drawable, (egl_context)? 1: 0); break; case GLITZ_DRAWABLE_CURRENT: if (drawable->base.width != drawable->width || drawable->base.height != drawable->height) _glitz_egl_drawable_update_size (drawable, drawable->base.width, drawable->base.height); egl_context = eglGetCurrentContext (); if ((egl_context != drawable->context->egl_context) || (eglGetCurrentSurface ( 0 ) != drawable->egl_surface)) _glitz_egl_context_make_current (drawable, (egl_context)? 1: 0); break; } }
static void android_view_HardwareRenderer_beginFrame(JNIEnv* env, jobject clazz, jintArray size) { EGLDisplay display = eglGetCurrentDisplay(); EGLSurface surface = eglGetCurrentSurface(EGL_DRAW); if (size) { EGLint value; jint* storage = env->GetIntArrayElements(size, NULL); eglQuerySurface(display, surface, EGL_WIDTH, &value); storage[0] = value; eglQuerySurface(display, surface, EGL_HEIGHT, &value); storage[1] = value; env->ReleaseIntArrayElements(size, storage, 0); } eglBeginFrame(display, surface); }