Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[Android] Add setPreferredFramesPerSecond for MapView #13498

Merged
merged 3 commits into from
Dec 12, 2018
Merged

Conversation

Chaoba
Copy link
Contributor

@Chaoba Chaoba commented Dec 4, 2018

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.

@LukasPaczos
Copy link
Member

Unfortunately, MapRenderer#updateFps is only responsible for providing a rough FPS count to the end user, as you can see, it is essentially called from the #onDraw and doesn't impact the actual rendering at all. In order to achieve what is proposed, we'd have to either limit core render requests, or ignore them and execute only every other (based on the desired max FPS). The latter might lead to a lot of undesired side effects though.

@LukasPaczos
Copy link
Member

Obviously, I'm wrong because you are halting the render thread! Let me give this another look.

Copy link
Member

@LukasPaczos LukasPaczos left a 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.

@Chaoba
Copy link
Contributor Author

Chaoba commented Dec 7, 2018

@LukasPaczos Thanks for your advise, updated.

Copy link
Member

@LukasPaczos LukasPaczos left a 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!

Copy link
Member

@tobrun tobrun left a 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

Copy link
Member

@LukasPaczos LukasPaczos left a 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!

@Chaoba Chaoba merged commit 2d527c2 into master Dec 12, 2018
@Chaoba Chaoba deleted the set_fps_mapview branch December 12, 2018 01:16
@tobrun tobrun added this to the android-v7.1.0 milestone Dec 12, 2018
tobrun pushed a commit that referenced this pull request Jan 10, 2019
* [Android] Add setPreferredFramesPerSecond for MapView
tobrun pushed a commit that referenced this pull request Jan 10, 2019
* [Android] Add setPreferredFramesPerSecond for MapView
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants