From daa281da189a12226869f3e981b8fb20619fbd84 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Tue, 28 Dec 2021 14:30:45 -0800 Subject: BBQ: Recreate BBQ when SurfaceControl changes 2/2 Alternative approach to fab15e55446080bdcfc05ba315e8ef914b0a6f65 which was racy because the disconnect callback is called without the BQ lock and the client can continue to modify the BQ state after disconnecting from the queue. This approach resets the BQ and BBQ states when the SurfaceControl is updated. This solves one concrete problem of not relying on the old SurfaceControl to be destroyed in order to release the currently presented buffer back to BQ. In addition this change resets the sync state in BBQ with the rationale the system does not want to sync on buffers presented on an older SurfaceControl. Bug: 197269223 Test: atest BLASTBufferQueueTest Test: labtest ag/16407859 cf-foldable * 3 (b/197269223#comment40) Change-Id: I137d3284c4e9216963f9c672f192afd334501ee5 --- graphics/java/android/graphics/BLASTBufferQueue.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'graphics/java') diff --git a/graphics/java/android/graphics/BLASTBufferQueue.java b/graphics/java/android/graphics/BLASTBufferQueue.java index 8d3eadb8496d..a9e730d58e65 100644 --- a/graphics/java/android/graphics/BLASTBufferQueue.java +++ b/graphics/java/android/graphics/BLASTBufferQueue.java @@ -27,8 +27,6 @@ public final class BLASTBufferQueue { // Note: This field is accessed by native code. public long mNativeObject; // BLASTBufferQueue* - private static native long nativeCreateAndUpdate(String name, long surfaceControl, long width, - long height, int format); private static native long nativeCreate(String name); private static native void nativeDestroy(long ptr); private static native Surface nativeGetSurface(long ptr, boolean includeSurfaceControlHandle); @@ -40,11 +38,13 @@ public final class BLASTBufferQueue { long frameNumber); private static native long nativeGetLastAcquiredFrameNum(long ptr); private static native void nativeApplyPendingTransactions(long ptr, long frameNumber); + private static native boolean nativeIsSameSurfaceControl(long ptr, long surfaceControlPtr); /** Create a new connection with the surface flinger. */ public BLASTBufferQueue(String name, SurfaceControl sc, int width, int height, @PixelFormat.Format int format) { - mNativeObject = nativeCreateAndUpdate(name, sc.mNativeObject, width, height, format); + this(name); + update(sc, width, height, format); } public BLASTBufferQueue(String name) { @@ -152,4 +152,11 @@ public final class BLASTBufferQueue { public long getLastAcquiredFrameNum() { return nativeGetLastAcquiredFrameNum(mNativeObject); } + + /** + * @return True if the associated SurfaceControl has the same handle as {@param sc}. + */ + public boolean isSameSurfaceControl(SurfaceControl sc) { + return nativeIsSameSurfaceControl(mNativeObject, sc.mNativeObject); + } } -- cgit v1.2.3-59-g8ed1b