diff --git a/core/java/android/view/SurfaceControlFpsListener.java b/core/java/android/view/SurfaceControlFpsListener.java index 517b0fb8ccd38..20a511a090b53 100644 --- a/core/java/android/view/SurfaceControlFpsListener.java +++ b/core/java/android/view/SurfaceControlFpsListener.java @@ -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); } diff --git a/core/jni/android_view_SurfaceControlFpsListener.cpp b/core/jni/android_view_SurfaceControlFpsListener.cpp index 6fa12e5104597..0b15acd776893 100644 --- a/core/jni/android_view_SurfaceControlFpsListener.cpp +++ b/core/jni/android_view_SurfaceControlFpsListener.cpp @@ -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 listener = reinterpret_cast(ptr); - auto layer = reinterpret_cast(layerObj); - sp 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 diff --git a/core/tests/coretests/src/android/view/SurfaceControlFpsListenerTest.java b/core/tests/coretests/src/android/view/SurfaceControlFpsListenerTest.java index 36104cf0f71d3..c15fc3a15112d 100644 --- a/core/tests/coretests/src/android/view/SurfaceControlFpsListenerTest.java +++ b/core/tests/coretests/src/android/view/SurfaceControlFpsListenerTest.java @@ -39,7 +39,7 @@ public class SurfaceControlFpsListenerTest { } }; - listener.register(new SurfaceControl()); + listener.register(0); listener.unregister(); }