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

Commit 83c17c18 authored by Yiwei Zhang's avatar Yiwei Zhang Committed by Android (Google) Code Review
Browse files

Merge "Nudge SurfaceControlFpsListener api to use task ID" into sc-dev

parents 50575cd1 2b54c82c
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -57,14 +57,14 @@ public abstract class SurfaceControlFpsListener {
    public abstract void onFpsReported(float fps);

    /**
     * Registers the sampling listener.
     * Registers the sampling listener for a particular task ID
     */
    public void register(@NonNull SurfaceControl layer) {
    public void register(int taskId) {
        if (mNativeListener == 0) {
            return;
        }

        nativeRegister(mNativeListener, layer.mNativeObject);
        nativeRegister(mNativeListener, taskId);
    }

    /**
@@ -82,12 +82,13 @@ public abstract class SurfaceControlFpsListener {
     *
     * Called from native code on a binder thread.
     */
    private static void dispatchOnFpsReported(SurfaceControlFpsListener listener, float fps) {
    private static void dispatchOnFpsReported(
            @NonNull SurfaceControlFpsListener listener, float fps) {
        listener.onFpsReported(fps);
    }

    private static native long nativeCreate(SurfaceControlFpsListener thiz);
    private static native void nativeDestroy(long ptr);
    private static native void nativeRegister(long ptr, long layerObject);
    private static native void nativeRegister(long ptr, int taskId);
    private static native void nativeUnregister(long ptr);
}
+3 −5
Original line number Diff line number Diff line
@@ -84,11 +84,9 @@ void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
    listener->decStrong((void*)nativeCreate);
}

void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jlong layerObj) {
void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jint taskId) {
    sp<SurfaceControlFpsListener> listener = reinterpret_cast<SurfaceControlFpsListener*>(ptr);
    auto layer = reinterpret_cast<SurfaceControl*>(layerObj);
    sp<IBinder> layerHandle = layer != nullptr ? layer->getHandle() : nullptr;
    if (SurfaceComposerClient::addFpsListener(layerHandle, listener) != OK) {
    if (SurfaceComposerClient::addFpsListener(taskId, listener) != OK) {
        constexpr auto error_msg = "Couldn't addFpsListener";
        ALOGE(error_msg);
        jniThrowRuntimeException(env, error_msg);
@@ -109,7 +107,7 @@ const JNINativeMethod gMethods[] = {
        /* name, signature, funcPtr */
        {"nativeCreate", "(Landroid/view/SurfaceControlFpsListener;)J", (void*)nativeCreate},
        {"nativeDestroy", "(J)V", (void*)nativeDestroy},
        {"nativeRegister", "(JJ)V", (void*)nativeRegister},
        {"nativeRegister", "(JI)V", (void*)nativeRegister},
        {"nativeUnregister", "(J)V", (void*)nativeUnregister}};

} // namespace
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public class SurfaceControlFpsListenerTest {
            }
        };

        listener.register(new SurfaceControl());
        listener.register(0);

        listener.unregister();
    }