summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/IWindowManager.aidl25
-rw-r--r--core/java/android/view/SurfaceControlFpsListener.java94
-rw-r--r--core/java/android/view/WindowManager.java28
-rw-r--r--core/java/android/view/WindowManagerImpl.java20
-rw-r--r--core/java/android/window/IOnFpsCallbackListener.aidl30
-rw-r--r--core/java/android/window/TaskFpsCallback.java86
6 files changed, 189 insertions, 94 deletions
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index 2c766bd6fd0d..4d24965a419e 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -66,6 +66,7 @@ import android.view.WindowManager;
import android.view.SurfaceControl;
import android.view.displayhash.DisplayHash;
import android.view.displayhash.VerifiedDisplayHash;
+import android.window.IOnFpsCallbackListener;
/**
* System private interface to the window manager.
@@ -922,4 +923,28 @@ interface IWindowManager
* reverts to using the default task transition with no spec changes.
*/
void clearTaskTransitionSpec();
+
+ /**
+ * Registers the frame rate per second count callback for one given task ID.
+ * Each callback can only register for receiving FPS callback for one task id until unregister
+ * is called. If there's no task associated with the given task id,
+ * {@link IllegalArgumentException} will be thrown. If a task id destroyed after a callback is
+ * registered, the registered callback will not be unregistered until
+ * {@link unregisterTaskFpsCallback()} is called
+ * @param taskId task id of the task.
+ * @param listener listener to be registered.
+ *
+ * @hide
+ */
+ void registerTaskFpsCallback(in int taskId, in IOnFpsCallbackListener listener);
+
+ /**
+ * Unregisters the frame rate per second count callback which was registered with
+ * {@link #registerTaskFpsCallback(int,TaskFpsCallback)}.
+ *
+ * @param listener listener to be unregistered.
+ *
+ * @hide
+ */
+ void unregisterTaskFpsCallback(in IOnFpsCallbackListener listener);
}
diff --git a/core/java/android/view/SurfaceControlFpsListener.java b/core/java/android/view/SurfaceControlFpsListener.java
deleted file mode 100644
index 20a511a090b5..000000000000
--- a/core/java/android/view/SurfaceControlFpsListener.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.view;
-
-import android.annotation.NonNull;
-
-/**
- * Listener for sampling the frames per second for a SurfaceControl and its children.
- * This should only be used by a system component that needs to listen to a SurfaceControl's
- * tree's FPS when it is not actively submitting transactions for that SurfaceControl.
- * Otherwise, ASurfaceTransaction_OnComplete callbacks should be used.
- *
- * @hide
- */
-public abstract class SurfaceControlFpsListener {
- private long mNativeListener;
-
- public SurfaceControlFpsListener() {
- mNativeListener = nativeCreate(this);
- }
-
- protected void destroy() {
- if (mNativeListener == 0) {
- return;
- }
- unregister();
- nativeDestroy(mNativeListener);
- mNativeListener = 0;
- }
-
- @Override
- protected void finalize() throws Throwable {
- try {
- destroy();
- } finally {
- super.finalize();
- }
- }
-
- /**
- * Reports the fps from the registered SurfaceControl
- */
- public abstract void onFpsReported(float fps);
-
- /**
- * Registers the sampling listener for a particular task ID
- */
- public void register(int taskId) {
- if (mNativeListener == 0) {
- return;
- }
-
- nativeRegister(mNativeListener, taskId);
- }
-
- /**
- * Unregisters the sampling listener.
- */
- public void unregister() {
- if (mNativeListener == 0) {
- return;
- }
- nativeUnregister(mNativeListener);
- }
-
- /**
- * Dispatch the collected sample.
- *
- * Called from native code on a binder thread.
- */
- 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, int taskId);
- private static native void nativeUnregister(long ptr);
-}
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 5be3a57e8527..ca7f90080c6c 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -118,6 +118,7 @@ import android.view.WindowInsets.Side.InsetsSide;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.accessibility.AccessibilityNodeInfo;
+import android.window.TaskFpsCallback;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -4858,4 +4859,31 @@ public interface WindowManager extends ViewManager {
default boolean isTaskSnapshotSupported() {
return false;
}
+
+ /**
+ * Registers the frame rate per second count callback for one given task ID.
+ * Each callback can only register for receiving FPS callback for one task id until unregister
+ * is called. If there's no task associated with the given task id,
+ * {@link IllegalArgumentException} will be thrown. If a task id destroyed after a callback is
+ * registered, the registered callback will not be unregistered until
+ * {@link #unregisterTaskFpsCallback(TaskFpsCallback))} is called
+ * @param taskId task id of the task.
+ * @param callback callback to be registered.
+ *
+ * @hide
+ */
+ @SystemApi
+ default void registerTaskFpsCallback(@IntRange(from = 0) int taskId,
+ @NonNull TaskFpsCallback callback) {}
+
+ /**
+ * Unregisters the frame rate per second count callback which was registered with
+ * {@link #registerTaskFpsCallback(int,TaskFpsCallback)}.
+ *
+ * @param callback callback to be unregistered.
+ *
+ * @hide
+ */
+ @SystemApi
+ default void unregisterTaskFpsCallback(@NonNull TaskFpsCallback callback) {}
}
diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java
index dd8041684c78..c16703ef50ef 100644
--- a/core/java/android/view/WindowManagerImpl.java
+++ b/core/java/android/view/WindowManagerImpl.java
@@ -24,6 +24,7 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
import static android.window.WindowProviderService.isWindowProviderService;
import android.annotation.CallbackExecutor;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiContext;
@@ -37,6 +38,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.StrictMode;
+import android.window.TaskFpsCallback;
import android.window.WindowContext;
import android.window.WindowProvider;
@@ -419,4 +421,22 @@ public final class WindowManagerImpl implements WindowManager {
}
return false;
}
+
+ @Override
+ public void registerTaskFpsCallback(@IntRange(from = 0) int taskId, TaskFpsCallback callback) {
+ try {
+ WindowManagerGlobal.getWindowManagerService().registerTaskFpsCallback(
+ taskId, callback.getListener());
+ } catch (RemoteException e) {
+ }
+ }
+
+ @Override
+ public void unregisterTaskFpsCallback(TaskFpsCallback callback) {
+ try {
+ WindowManagerGlobal.getWindowManagerService().unregisterTaskFpsCallback(
+ callback.getListener());
+ } catch (RemoteException e) {
+ }
+ }
}
diff --git a/core/java/android/window/IOnFpsCallbackListener.aidl b/core/java/android/window/IOnFpsCallbackListener.aidl
new file mode 100644
index 000000000000..3091df3b23a3
--- /dev/null
+++ b/core/java/android/window/IOnFpsCallbackListener.aidl
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.window;
+
+/**
+ * @hide
+ */
+oneway interface IOnFpsCallbackListener {
+
+ /**
+ * Reports the fps from the registered task
+ * @param fps The frame rate per second of the task that has the registered task id
+ * and its children.
+ */
+ void onFpsReported(in float fps);
+}
diff --git a/core/java/android/window/TaskFpsCallback.java b/core/java/android/window/TaskFpsCallback.java
new file mode 100644
index 000000000000..a8e01b6df4b8
--- /dev/null
+++ b/core/java/android/window/TaskFpsCallback.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.window;
+
+import android.annotation.BinderThread;
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+import android.os.RemoteException;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Callback for sampling the frames per second for a task and its children.
+ * This should only be used by a system component that needs to listen to a task's
+ * tree's FPS when it is not actively submitting transactions for that corresponding SurfaceControl.
+ * Otherwise, ASurfaceTransaction_OnComplete callbacks should be used.
+ *
+ * Each callback can only register for receiving FPS report for one task id until
+ * {@link WindowManager#unregister()} is called.
+ *
+ * @hide
+ */
+@SystemApi
+public final class TaskFpsCallback {
+
+ /**
+ * Listener interface to receive frame per second of a task.
+ */
+ public interface OnFpsCallbackListener {
+ /**
+ * Reports the fps from the registered task
+ * @param fps The frame per second of the task that has the registered task id
+ * and its children.
+ */
+ void onFpsReported(float fps);
+ }
+
+ private final IOnFpsCallbackListener mListener;
+
+ public TaskFpsCallback(@NonNull Executor executor, @NonNull OnFpsCallbackListener listener) {
+ mListener = new IOnFpsCallbackListener.Stub() {
+ @Override
+ public void onFpsReported(float fps) {
+ executor.execute(() -> {
+ listener.onFpsReported(fps);
+ });
+ }
+ };
+ }
+
+ /**
+ * @hide
+ */
+ public IOnFpsCallbackListener getListener() {
+ return mListener;
+ }
+
+ /**
+ * Dispatch the collected sample.
+ *
+ * Called from native code on a binder thread.
+ */
+ @BinderThread
+ private static void dispatchOnFpsReported(
+ @NonNull IOnFpsCallbackListener listener, float fps) {
+ try {
+ listener.onFpsReported(fps);
+ } catch (RemoteException e) {
+ /* ignore */
+ }
+ }
+}