From cb7a16280a25de52775bba84e0b9ccaa97c9a774 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Wed, 9 Feb 2022 18:05:02 -0800 Subject: SurfaceView: Avoid destination frame updates on multiple threads 1/2 The caller such as SurfaceView can optionally apply destination frame changes if they wish to synchronize buffer scale with other scales in the hierarchy. This is hard to synchronize if the buffer scale changes, since in fixed scaling mode we want the destination frame to be applied when a buffer of the new size is queued. This approach is brittle because SurfaceView does not have control over the buffer production and the app can get into a scenario where there is scaled incorrectly. Fix this by configuring BBQ to always apply destination frame changes or always defer to the caller. If the scaling mode is freeze, then BBQ will set a flag to ignore the destination frame. This allows us to synchronize destination frame changes with scale applied by a parent and avoid unwanted scaling if the scaling mode changes to freeze. Test: atest SurfaceViewTest Test: go/wm-smoke Bug: 217973491 Change-Id: I5226c304bae9dde890306f8528dfeabf6b015a32 --- graphics/java/android/graphics/BLASTBufferQueue.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'graphics/java') diff --git a/graphics/java/android/graphics/BLASTBufferQueue.java b/graphics/java/android/graphics/BLASTBufferQueue.java index 2678c79d1454..369f20fb52a7 100644 --- a/graphics/java/android/graphics/BLASTBufferQueue.java +++ b/graphics/java/android/graphics/BLASTBufferQueue.java @@ -27,13 +27,13 @@ public final class BLASTBufferQueue { // Note: This field is accessed by native code. public long mNativeObject; // BLASTBufferQueue* - private static native long nativeCreate(String name); + private static native long nativeCreate(String name, boolean updateDestinationFrame); private static native void nativeDestroy(long ptr); private static native Surface nativeGetSurface(long ptr, boolean includeSurfaceControlHandle); private static native void nativeSetSyncTransaction(long ptr, long transactionPtr, boolean acquireSingleBuffer); private static native void nativeUpdate(long ptr, long surfaceControl, long width, long height, - int format, long transactionPtr); + int format); private static native void nativeMergeWithNextTransaction(long ptr, long transactionPtr, long frameNumber); private static native long nativeGetLastAcquiredFrameNum(long ptr); @@ -45,12 +45,12 @@ public final class BLASTBufferQueue { /** Create a new connection with the surface flinger. */ public BLASTBufferQueue(String name, SurfaceControl sc, int width, int height, @PixelFormat.Format int format) { - this(name); + this(name, false /* updateDestinationFrame */); update(sc, width, height, format); } - public BLASTBufferQueue(String name) { - mNativeObject = nativeCreate(name); + public BLASTBufferQueue(String name, boolean updateDestinationFrame) { + mNativeObject = nativeCreate(name, updateDestinationFrame); } public void destroy() { @@ -101,15 +101,9 @@ public final class BLASTBufferQueue { * @param width The new width for the buffer. * @param height The new height for the buffer. * @param format The new format for the buffer. - * @param t Adds destination frame changes to the passed in transaction. */ - public void update(SurfaceControl sc, int width, int height, @PixelFormat.Format int format, - SurfaceControl.Transaction t) { - nativeUpdate(mNativeObject, sc.mNativeObject, width, height, format, t.mNativeObject); - } - public void update(SurfaceControl sc, int width, int height, @PixelFormat.Format int format) { - nativeUpdate(mNativeObject, sc.mNativeObject, width, height, format, 0); + nativeUpdate(mNativeObject, sc.mNativeObject, width, height, format); } @Override -- cgit v1.2.3-59-g8ed1b