Skip to content

Commit c47bef6

Browse files
Xin Chenfacebook-github-bot
authored andcommitted
Update FpsDebugFrameCallback to allow set target FPS instead of hard coded one (facebook#41091)
Summary: Pull Request resolved: facebook#41091 Changelog: [Android][Internal] - Allow configurable target FPS for debug frame callback Reviewed By: javache Differential Revision: D49895740 fbshipit-source-id: 3818b14a929cd40c64b6ad2811d373ebff5c3dfc
1 parent c05448b commit c47bef6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public FpsInfo(
5656
}
5757
}
5858

59-
private static final double EXPECTED_FRAME_TIME = 16.9;
59+
private static final double DEFAULT_FPS = 60.0;
6060

6161
private @Nullable Choreographer mChoreographer;
6262
private final ReactContext mReactContext;
@@ -70,6 +70,7 @@ public FpsInfo(
7070
private int m4PlusFrameStutters = 0;
7171
private int mNumFrameCallbacksWithBatchDispatches = 0;
7272
private boolean mIsRecordingFpsInfoAtEachFrame = false;
73+
private double mTargetFps = DEFAULT_FPS;
7374
private @Nullable TreeMap<Long, FpsInfo> mTimeToFps;
7475

7576
public FpsDebugFrameCallback(ReactContext reactContext) {
@@ -120,10 +121,15 @@ public void doFrame(long l) {
120121
}
121122

122123
public void start() {
124+
start(mTargetFps);
125+
}
126+
127+
public void start(double targetFps) {
123128
mReactContext
124129
.getCatalystInstance()
125130
.addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector);
126131
mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector);
132+
mTargetFps = targetFps;
127133
UiThreadUtil.runOnUiThread(
128134
() -> {
129135
mChoreographer = Choreographer.getInstance();
@@ -173,7 +179,7 @@ public int getNumJSFrames() {
173179

174180
public int getExpectedNumFrames() {
175181
double totalTimeMS = getTotalTimeMS();
176-
int expectedFrames = (int) (totalTimeMS / EXPECTED_FRAME_TIME + 1);
182+
int expectedFrames = (int) (mTargetFps * totalTimeMS / 1000 + 1);
177183
return expectedFrames;
178184
}
179185

0 commit comments

Comments
 (0)