Latch and relase buffers for offscreen layers on main thread.

The current code was calling fakeVsync, which was latching and releasing
buffers on a binder thread when a new frame arrived. This was causing a
race with the latchBuffer on the main thread. This change calls
latchAndReleaseBuffer on the main thread for offscreen layers to ensure
we don't block dequeueBuffer but also don't race the other latchBuffer
call.

Fixes: 139118508
Test: Race was only reproducible in monkey tests
Change-Id: Ie7d87aa775c215de3fb2322b73849402596cc3fc
diff --git a/services/surfaceflinger/BufferLayer.h b/services/surfaceflinger/BufferLayer.h
index 7a0f82b..fb8d7d0 100644
--- a/services/surfaceflinger/BufferLayer.h
+++ b/services/surfaceflinger/BufferLayer.h
@@ -103,6 +103,13 @@
     // Returns the current scaling mode, unless mOverrideScalingMode
     // is set, in which case, it returns mOverrideScalingMode
     uint32_t getEffectiveScalingMode() const override;
+
+    // Calls latchBuffer if the buffer has a frame queued and then releases the buffer.
+    // This is used if the buffer is just latched and releases to free up the buffer
+    // and will not be shown on screen.
+    // Should only be called on the main thread.
+    void latchAndReleaseBuffer() override;
+
     // -----------------------------------------------------------------------
 
     // -----------------------------------------------------------------------