1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.window;
18 
19 import android.annotation.BinderThread;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.RemoteException;
23 
24 /**
25  * Callback for sampling the frames per second for a task and its children.
26  * This should only be used by a system component that needs to listen to a task's
27  * tree's FPS when it is not actively submitting transactions for that corresponding SurfaceControl.
28  * Otherwise, ASurfaceTransaction_OnComplete callbacks should be used.
29  *
30  * Each callback can only register for receiving FPS report for one task id until
31  * {@link WindowManager#unregisterTaskFpsCallback()} is called.
32  *
33  * @hide
34  */
35 @SystemApi
36 public abstract class TaskFpsCallback {
37 
38     /**
39      * Reports the fps from the registered task
40      * @param fps The frame per second of the task that has the registered task id
41      *            and its children.
42      */
onFpsReported(float fps)43     public abstract void onFpsReported(float fps);
44 
45     /**
46      * Dispatch the collected sample.
47      *
48      * Called from native code on a binder thread.
49      */
50     @BinderThread
dispatchOnFpsReported( @onNull ITaskFpsCallback listener, float fps)51     private static void dispatchOnFpsReported(
52             @NonNull ITaskFpsCallback listener, float fps) {
53         try {
54             listener.onFpsReported(fps);
55         } catch (RemoteException e) {
56             /* ignore */
57         }
58     }
59 }
60