Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bcd152a authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Remove SurfaceControl#getHandle from JAVA apis 1/2

Holding on to a reference of the handle in Java will keep the server-side surface alive until
the reference is removed by GC. This may cause surfaces to be kept alive longer than necessary.
Instead hold on the surface control and call SurfaceControl#release which will release the local
reference to the server-side surface.

Bug: 136004147
Test: go/wm-smoke
Test: gesture nav sanity tests
Test: atest CompositionSamplingListenerTest

Change-Id: Iab33680746c8f48c28783e6a2a13c9ac7ae04980
parent 82e696d5
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.view;

import android.graphics.Rect;
import android.os.IBinder;

import com.android.internal.util.Preconditions;

@@ -58,11 +57,12 @@ public abstract class CompositionSamplingListener {
     * Registers a sampling listener.
     */
    public static void register(CompositionSamplingListener listener,
            int displayId, IBinder stopLayer, Rect samplingArea) {
            int displayId, SurfaceControl stopLayer, Rect samplingArea) {
        Preconditions.checkArgument(displayId == Display.DEFAULT_DISPLAY,
                "default display only for now");
        nativeRegister(listener.mNativeListener, stopLayer, samplingArea.left, samplingArea.top,
                samplingArea.right, samplingArea.bottom);
        long nativeStopLayerObject = stopLayer != null ? stopLayer.mNativeObject : 0;
        nativeRegister(listener.mNativeListener, nativeStopLayerObject, samplingArea.left,
                samplingArea.top, samplingArea.right, samplingArea.bottom);
    }

    /**
@@ -84,7 +84,7 @@ public abstract class CompositionSamplingListener {

    private static native long nativeCreate(CompositionSamplingListener thiz);
    private static native void nativeDestroy(long ptr);
    private static native void nativeRegister(long ptr, IBinder stopLayer,
    private static native void nativeRegister(long ptr, long stopLayerObject,
            int samplingAreaLeft, int top, int right, int bottom);
    private static native void nativeUnregister(long ptr);
}
+4 −4
Original line number Diff line number Diff line
@@ -87,11 +87,11 @@ void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
    listener->decStrong((void*)nativeCreate);
}

void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jobject stopLayerTokenObj,
void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jlong stopLayerObj,
        jint left, jint top, jint right, jint bottom) {
    sp<CompositionSamplingListener> listener = reinterpret_cast<CompositionSamplingListener*>(ptr);
    sp<IBinder> stopLayerHandle = ibinderForJavaObject(env, stopLayerTokenObj);

    auto stopLayer = reinterpret_cast<SurfaceControl*>(stopLayerObj);
    sp<IBinder> stopLayerHandle = stopLayer != nullptr ? stopLayer->getHandle() : nullptr;
    if (SurfaceComposerClient::addRegionSamplingListener(
            Rect(left, top, right, bottom), stopLayerHandle, listener) != OK) {
        constexpr auto error_msg = "Couldn't addRegionSamplingListener";
@@ -116,7 +116,7 @@ const JNINativeMethod gMethods[] = {
            (void*)nativeCreate },
    { "nativeDestroy", "(J)V",
            (void*)nativeDestroy },
    { "nativeRegister", "(JLandroid/os/IBinder;IIII)V",
    { "nativeRegister", "(JJIIII)V",
            (void*)nativeRegister },
    { "nativeUnregister", "(J)V",
            (void*)nativeUnregister }
+1 −2
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.view;
import static android.view.Display.DEFAULT_DISPLAY;

import android.graphics.Rect;
import android.os.Binder;
import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;
@@ -35,7 +34,7 @@ public class CompositionSamplingListenerTest {

    @Test
    public void testRegisterUnregister() {
        CompositionSamplingListener.register(mListener, DEFAULT_DISPLAY, new Binder(),
        CompositionSamplingListener.register(mListener, DEFAULT_DISPLAY, new SurfaceControl(),
                new Rect(1, 1, 10, 10));
        CompositionSamplingListener.unregister(mListener);
    }
+0 −7
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.shared.system;

import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.IBinder;
import android.view.Surface;
import android.view.SurfaceControl.Transaction;

@@ -87,12 +86,6 @@ public class TransactionCompat {
        return this;
    }

    public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
            IBinder handle, long frameNumber) {
        mTransaction.deferTransactionUntil(surfaceControl.mSurfaceControl, handle, frameNumber);
        return this;
    }

    public TransactionCompat deferTransactionUntil(SurfaceControlCompat surfaceControl,
            Surface barrier, long frameNumber) {
        mTransaction.deferTransactionUntilSurface(surfaceControl.mSurfaceControl, barrier,
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ public class NavBarTintController implements View.OnAttachStateChangeListener,
            }
            mSamplingListenerRegistered = true;
            CompositionSamplingListener.register(mSamplingListener, DEFAULT_DISPLAY,
                    mNavigationBarView.getViewRootImpl().getSurfaceControl().getHandle(),
                    mNavigationBarView.getViewRootImpl().getSurfaceControl(),
                    mSamplingBounds);
        }
    }
Loading