summaryrefslogtreecommitdiff
path: root/libs/gui/ISurfaceComposer.cpp
diff options
context:
space:
mode:
author Alec Mouri <alecmouri@google.com> 2021-01-05 12:57:36 -0800
committer Alec Mouri <alecmouri@google.com> 2021-02-23 10:31:31 -0800
commitadebf5c63121f7986b2ee609ed4b6904e5290285 (patch)
treef53553e3e66657f270a208f9555023b24a8a0e87 /libs/gui/ISurfaceComposer.cpp
parentec1691271f4732807a21fd678bfddb3c7b25c3ae (diff)
Support streaming fps updates for a layer subtree to sysui via listener.
The supported flow is: * A binder listener is registered with SurfaceFlinger that is associated with a task's SurfaceControl. * Every frame, for every listener that is registered, the fps for each layer subtree is computed and reported back to each listener via onFpsUpdated. * Fps for the layer subtree is computed via FrameTimeline: the layer IDs for the subtree are gathered into a set, and FrameTimeline internally finds all DisplayFrames containing at least one layer, then obtains the present time for each of those frames, then computes the aggregated fps from those frames. Pragmatically, this should correspond with the last half second of activity for high refresh rate devices. No heuristics are used to select the "correct" layer from the layer subtree. If a game is rendering to two layers at a cadence of 30fps but offset by one 60hz vsync, then the reported fps will be 60fps because both layers will be counted on the same linear timeline. No rate limiting is applied in this patch either. The caller is able to hack in rate-limiting by immediately unregistering the listener after a FPS callback is dispatched, and then reregistered. Architecturally, it is not hard to add in rate-limiting at the SurfaceFlinger level, but that can be added in a follow-up patch since this patch is already large. Bug: 174956756 Test: libsurfaceflinger_unittest Test: E2E verification with custom listener outputting to logcat Change-Id: I792bc19cad18b6aee6c6e644bca9da40a0f15099
Diffstat (limited to 'libs/gui/ISurfaceComposer.cpp')
-rw-r--r--libs/gui/ISurfaceComposer.cpp65
1 files changed, 56 insertions, 9 deletions
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index 2e4f858a9d..45d210f4b9 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -17,15 +17,10 @@
// tag as surfaceflinger
#define LOG_TAG "SurfaceFlinger"
-#include <stdint.h>
-#include <sys/types.h>
-
#include <android/gui/ITransactionTraceListener.h>
-
-#include <binder/Parcel.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
-
+#include <binder/Parcel.h>
#include <gui/IDisplayEventConnection.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/IRegionSamplingListener.h>
@@ -33,16 +28,15 @@
#include <gui/ISurfaceComposerClient.h>
#include <gui/LayerDebugInfo.h>
#include <gui/LayerState.h>
-
+#include <stdint.h>
+#include <sys/types.h>
#include <system/graphics.h>
-
#include <ui/DisplayMode.h>
#include <ui/DisplayStatInfo.h>
#include <ui/DisplayState.h>
#include <ui/DynamicDisplayInfo.h>
#include <ui/HdrCapabilities.h>
#include <ui/StaticDisplayInfo.h>
-
#include <utils/Log.h>
// ---------------------------------------------------------------------------
@@ -796,6 +790,33 @@ public:
return error;
}
+ virtual status_t addFpsListener(const sp<IBinder>& layerHandle,
+ const sp<gui::IFpsListener>& listener) {
+ Parcel data, reply;
+ SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
+ SAFE_PARCEL(data.writeStrongBinder, layerHandle);
+ SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
+ const status_t error =
+ remote()->transact(BnSurfaceComposer::ADD_FPS_LISTENER, data, &reply);
+ if (error != OK) {
+ ALOGE("addFpsListener: Failed to transact");
+ }
+ return error;
+ }
+
+ virtual status_t removeFpsListener(const sp<gui::IFpsListener>& listener) {
+ Parcel data, reply;
+ SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
+ SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
+
+ const status_t error =
+ remote()->transact(BnSurfaceComposer::REMOVE_FPS_LISTENER, data, &reply);
+ if (error != OK) {
+ ALOGE("removeFpsListener: Failed to transact");
+ }
+ return error;
+ }
+
status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken,
ui::DisplayModeId defaultMode, bool allowGroupSwitching,
float primaryRefreshRateMin, float primaryRefreshRateMax,
@@ -1716,6 +1737,32 @@ status_t BnSurfaceComposer::onTransact(
}
return removeRegionSamplingListener(listener);
}
+ case ADD_FPS_LISTENER: {
+ CHECK_INTERFACE(ISurfaceComposer, data, reply);
+ sp<IBinder> layerHandle;
+ status_t result = data.readNullableStrongBinder(&layerHandle);
+ if (result != NO_ERROR) {
+ ALOGE("addFpsListener: Failed to read layer handle");
+ return result;
+ }
+ sp<gui::IFpsListener> listener;
+ result = data.readNullableStrongBinder(&listener);
+ if (result != NO_ERROR) {
+ ALOGE("addFpsListener: Failed to read listener");
+ return result;
+ }
+ return addFpsListener(layerHandle, listener);
+ }
+ case REMOVE_FPS_LISTENER: {
+ CHECK_INTERFACE(ISurfaceComposer, data, reply);
+ sp<gui::IFpsListener> listener;
+ status_t result = data.readNullableStrongBinder(&listener);
+ if (result != NO_ERROR) {
+ ALOGE("removeFpsListener: Failed to read listener");
+ return result;
+ }
+ return removeFpsListener(listener);
+ }
case SET_DESIRED_DISPLAY_MODE_SPECS: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
sp<IBinder> displayToken = data.readStrongBinder();