From 52e21483fa48baeb4a88372d75e083bca2e92923 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 24 Sep 2012 18:07:21 -0700 Subject: [PATCH 1/2] handle EGL errors for now we just restart the runtime. bug: 7225248 Change-Id: I7638ffe82075a4db9e7e6f9e35cf48afcb5a387a --- services/surfaceflinger/DisplayDevice.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 81ce27e18..56852dae3 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -205,27 +205,34 @@ void DisplayDevice::flip(const Region& dirty) const } void DisplayDevice::swapBuffers(HWComposer& hwc) const { + EGLBoolean success = EGL_TRUE; if (hwc.initCheck() != NO_ERROR) { // no HWC, we call eglSwapBuffers() - eglSwapBuffers(mDisplay, mSurface); + success = eglSwapBuffers(mDisplay, mSurface); } else { // We have a valid HWC, but not all displays can use it, in particular // the virtual displays are on their own. // TODO: HWC 1.2 will allow virtual displays if (mType >= DisplayDevice::DISPLAY_VIRTUAL) { // always call eglSwapBuffers() for virtual displays - eglSwapBuffers(mDisplay, mSurface); + success = eglSwapBuffers(mDisplay, mSurface); } else if (hwc.supportsFramebufferTarget()) { // as of hwc 1.1 we always call eglSwapBuffers if we have some // GLES layers if (hwc.hasGlesComposition(mType)) { - eglSwapBuffers(mDisplay, mSurface); + success = eglSwapBuffers(mDisplay, mSurface); } } else { // HWC doesn't have the framebuffer target, we don't call // eglSwapBuffers(), since this is handled by HWComposer::commit(). } } + + // TODO: we should at least handle EGL_CONTEXT_LOST, by recreating the + // context and resetting our state. + LOG_ALWAYS_FATAL_IF(!success, + "eglSwapBuffers(%p, %p) failed with 0x%8x", + mDisplay, mSurface, eglGetError()); } void DisplayDevice::onSwapBuffersCompleted(HWComposer& hwc) const { From 2a23184e4109060ec772763e80dae2132cf9d2eb Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 24 Sep 2012 18:12:35 -0700 Subject: [PATCH 2/2] don't call eglMakeCurrent() before calling HWC commit() on HWC 1.1 this call is not needed and misleading on HWC 1.1; it can also have a negative performance impact when multiple displays are used. Bug: 7124069 Change-Id: I47cd25c9d6e69abcc9333b9ecd5044e8fb1919ec --- services/surfaceflinger/SurfaceFlinger.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 837269101..bc7552d7e 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -927,10 +927,13 @@ void SurfaceFlinger::postFramebuffer() HWComposer& hwc(getHwComposer()); if (hwc.initCheck() == NO_ERROR) { - // FIXME: EGL spec says: - // "surface must be bound to the calling thread's current context, - // for the current rendering API." - DisplayDevice::makeCurrent(mEGLDisplay, getDefaultDisplayDevice(), mEGLContext); + if (!hwc.supportsFramebufferTarget()) { + // EGL spec says: + // "surface must be bound to the calling thread's current context, + // for the current rendering API." + DisplayDevice::makeCurrent(mEGLDisplay, + getDefaultDisplayDevice(), mEGLContext); + } hwc.commit(); }