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

This commit is contained in:
Yiwei Zhang
2021-03-07 03:44:19 +00:00
committed by Android (Google) Code Review
3 changed files with 10 additions and 11 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -39,7 +39,7 @@ public class SurfaceControlFpsListenerTest {
}
};
listener.register(new SurfaceControl());
listener.register(0);
listener.unregister();
}