Handle repeated swapBuffer errors

Changed eglSwapBuffers to actually signal an error when swapBuffers
fails. This was hiding an error log at the SurfaceFlinger callsite.

When eglSwapBuffers is called after a prior error, we should not try to
enqueue a NULL buffer which was causing a segfault that takes down
SurfaceFlinger.

Bug: 33432596
Change-Id: I72f3301e0adbc4ea75266c9c1c9e01d9169036e7
diff --git a/system/egl/egl.cpp b/system/egl/egl.cpp
index db256c0..ea0ac2e 100644
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -454,6 +454,11 @@
 
     int presentFenceFd = -1;
 
+    if (buffer == NULL) {
+        ALOGE("egl_window_surface_t::swapBuffers called with NULL buffer");
+        setErrorReturn(EGL_BAD_SURFACE, EGL_FALSE);
+    }
+
 #if PLATFORM_SDK_VERSION <= 16
     rcEnc->rcFlushWindowColorBuffer(rcEnc, rcSurface);
     // equivalent to glFinish if no native sync
@@ -1527,10 +1532,10 @@
         setErrorReturn(EGL_BAD_DISPLAY, EGL_FALSE);
 
     // post the surface
-    d->swapBuffers();
+    EGLBoolean ret = d->swapBuffers();
 
     hostCon->flush();
-    return EGL_TRUE;
+    return ret;
 }
 
 EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)