Skip to content

Commit

Permalink
Update FpsDebugFrameCallback to allow set target FPS instead of hard …
Browse files Browse the repository at this point in the history
…coded one (#41091)

Summary:
Pull Request resolved: #41091

Changelog:
[Android][Internal] - Allow configurable target FPS for debug frame callback

Reviewed By: javache

Differential Revision: D49895740

fbshipit-source-id: 3818b14a929cd40c64b6ad2811d373ebff5c3dfc
  • Loading branch information
Xin Chen authored and facebook-github-bot committed Oct 20, 2023
1 parent c05448b commit c47bef6
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public FpsInfo(
}
}

private static final double EXPECTED_FRAME_TIME = 16.9;
private static final double DEFAULT_FPS = 60.0;

private @Nullable Choreographer mChoreographer;
private final ReactContext mReactContext;
Expand All @@ -70,6 +70,7 @@ public FpsInfo(
private int m4PlusFrameStutters = 0;
private int mNumFrameCallbacksWithBatchDispatches = 0;
private boolean mIsRecordingFpsInfoAtEachFrame = false;
private double mTargetFps = DEFAULT_FPS;
private @Nullable TreeMap<Long, FpsInfo> mTimeToFps;

public FpsDebugFrameCallback(ReactContext reactContext) {
Expand Down Expand Up @@ -120,10 +121,15 @@ public void doFrame(long l) {
}

public void start() {
start(mTargetFps);
}

public void start(double targetFps) {
mReactContext
.getCatalystInstance()
.addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector);
mTargetFps = targetFps;
UiThreadUtil.runOnUiThread(
() -> {
mChoreographer = Choreographer.getInstance();
Expand Down Expand Up @@ -173,7 +179,7 @@ public int getNumJSFrames() {

public int getExpectedNumFrames() {
double totalTimeMS = getTotalTimeMS();
int expectedFrames = (int) (totalTimeMS / EXPECTED_FRAME_TIME + 1);
int expectedFrames = (int) (mTargetFps * totalTimeMS / 1000 + 1);
return expectedFrames;
}

Expand Down

0 comments on commit c47bef6

Please sign in to comment.