-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Android] Add setPreferredFramesPerSecond for MapView #13498
Conversation
Unfortunately, |
Obviously, I'm wrong because you are halting the render thread! Let me give this another look. |
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
Outdated
Show resolved
Hide resolved
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting idea @Chaoba, thanks for putting this together.
First of all, the whole logic that is impacting the rendering should be moved out of the updateFps
method into onDrawFrame
because updateFps
is only executed when the onFpsChangedListener
is registered, otherwise it's ignored.
Second, I think we can refactor this code to pause the render thread only if we were able to render the last frame faster than the FPS cap allows. Similarly to what you pushed now, but we can base the calcualtions on nanoseconds rather than FPS to limit the amount of divisions that are happening.
In order to achieve that, all we need is to measure the time before the frame, measure the time after the frame (effectively before and after nativeRender
call) and check if the delta is smaller than the minimum time required per frame. If it is, we need to sleep for the amount of time needed to fill this gap.
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
Outdated
Show resolved
Hide resolved
@LukasPaczos Thanks for your advise, updated. |
5b4ea29
to
c3f3223
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two notes, otherwise, LGTM!
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
Outdated
Show resolved
Hide resolved
...android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
Outdated
Show resolved
Hide resolved
e4b60b3
to
7b00bb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for picking up those changes. Two minor comments, will leave the final review to @LukasPaczos
platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
Outdated
Show resolved
Hide resolved
...orm/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
Outdated
Show resolved
Hide resolved
...orm/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java
Outdated
Show resolved
Hide resolved
platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
Outdated
Show resolved
Hide resolved
7b00bb2
to
3f0462d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Could you squash the commits before merging? Thanks!
* [Android] Add setPreferredFramesPerSecond for MapView
* [Android] Add setPreferredFramesPerSecond for MapView
iOS already added an API to let devs set FPS. It is essential in scenarios cpu load is heavy, so it will be better if we could add one on Android side.
I have tested it by myself, it can change the fps roughly, still need some discussions on it.