diff options
| -rw-r--r-- | core/java/android/view/SurfaceControl.java | 20 | ||||
| -rw-r--r-- | core/jni/android_view_SurfaceControl.cpp | 8 | ||||
| -rw-r--r-- | services/core/java/com/android/server/wm/WindowState.java | 2 |
3 files changed, 28 insertions, 2 deletions
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index bc6a3b540ce7..2fa03c5ba92e 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -220,6 +220,7 @@ public final class SurfaceControl implements Parcelable { long newParentNativeObject); private static native void nativeSetBuffer(long transactionObj, long nativeObject, HardwareBuffer buffer, long fencePtr, Consumer<SyncFence> releaseCallback); + private static native void nativeUnsetBuffer(long transactionObj, long nativeObject); private static native void nativeSetBufferTransform(long transactionObj, long nativeObject, int transform); private static native void nativeSetDataSpace(long transactionObj, long nativeObject, @@ -3664,6 +3665,22 @@ public final class SurfaceControl implements Parcelable { } /** + * Unsets the buffer for the SurfaceControl in the current Transaction. This will not clear + * the buffer being rendered, but resets the buffer state in the Transaction only. The call + * will also invoke the release callback. + * + * Note, this call is different from passing a null buffer to + * {@link SurfaceControl.Transaction#setBuffer} which will release the last displayed + * buffer. + * + * @hide + */ + public Transaction unsetBuffer(SurfaceControl sc) { + nativeUnsetBuffer(mNativeObject, sc.mNativeObject); + return this; + } + + /** * Updates the HardwareBuffer displayed for the SurfaceControl. * * Note that the buffer must be allocated with {@link HardwareBuffer#USAGE_COMPOSER_OVERLAY} @@ -3682,7 +3699,8 @@ public final class SurfaceControl implements Parcelable { * until all presentation fences have signaled, ensuring the transaction remains consistent. * * @param sc The SurfaceControl to update - * @param buffer The buffer to be displayed + * @param buffer The buffer to be displayed. Pass in a null buffer to release the last + * displayed buffer. * @param fence The presentation fence. If null or invalid, this is equivalent to * {@link #setBuffer(SurfaceControl, HardwareBuffer)} * @return this diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 8e96ac136370..193099baad48 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -616,6 +616,12 @@ static void nativeSetBuffer(JNIEnv* env, jclass clazz, jlong transactionObj, jlo genReleaseCallback(env, releaseCallback)); } +static void nativeUnsetBuffer(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject) { + auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); + SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject); + transaction->unsetBuffer(ctrl); +} + static void nativeSetBufferTransform(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, jint transform) { auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); @@ -2198,6 +2204,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*)nativeSetGeometry }, {"nativeSetBuffer", "(JJLandroid/hardware/HardwareBuffer;JLjava/util/function/Consumer;)V", (void*)nativeSetBuffer }, + {"nativeUnsetBuffer", "(JJ)V", (void*)nativeUnsetBuffer }, + {"nativeSetBufferTransform", "(JJI)V", (void*) nativeSetBufferTransform}, {"nativeSetDataSpace", "(JJI)V", (void*)nativeSetDataSpace }, diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index a29959297dc7..f3b338294393 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -5634,7 +5634,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP private void dropBufferFrom(Transaction t) { SurfaceControl viewSurface = getClientViewRootSurface(); if (viewSurface == null) return; - t.setBuffer(viewSurface, (android.hardware.HardwareBuffer) null); + t.unsetBuffer(viewSurface); } @Override |