add the ability to reject buffers in SurfaceTexture::updateTexImage

SurfaceFlinger is using this new feature to reject buffers that
don't have the right size.

Bug: 6498869
Change-Id: I8a7250a47db6c082a357b703feb3b9d0fc8d3443
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index 30c0d9b..55be4bc 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -176,6 +176,10 @@
 }
 
 status_t SurfaceTexture::updateTexImage() {
+    return SurfaceTexture::updateTexImage(NULL);
+}
+
+status_t SurfaceTexture::updateTexImage(BufferRejecter* rejecter) {
     ATRACE_CALL();
     ST_LOGV("updateTexImage");
     Mutex::Autolock lock(mMutex);
@@ -228,6 +232,16 @@
             mEGLSlots[buf].mGraphicBuffer = item.mGraphicBuffer;
         }
 
+        // we call the rejecter here, in case the caller has a reason to
+        // not accept this buffer. this is used by SurfaceFlinger to
+        // reject buffers which have the wrong size
+        if (rejecter && rejecter->reject(mEGLSlots[buf].mGraphicBuffer, item)) {
+            mBufferQueue->releaseBuffer(buf, dpy, mEGLSlots[buf].mFence);
+            mEGLSlots[buf].mFence = EGL_NO_SYNC_KHR;
+            glBindTexture(mTexTarget, mTexName);
+            return NO_ERROR;
+        }
+
         // Update the GL texture object. We may have to do this even when
         // item.mGraphicBuffer == NULL, if we destroyed the EGLImage when
         // detaching from a context but the buffer has not been re-allocated.