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

Android has no frame rate limit #2396

Closed

Description

@ljbade

If you enable debug mode in the test app to show the FPS counter you will see that when using gestures the frame rate jumps way above 60.

This means we are rendering far more freshness than necessary increasing CPU and GPU usage and battery drain.

It also results in stuttering such as seen in #2290

I think this happened after the invalidate loop was changed.

We need to enable vsync.

Activity

  1. added
    Android
    on Sep 23, 2015
  2. ljbade commented on Sep 23, 2015

    @ljbade
    ContributorAuthor

    Possibly eglSwapInterval or the Android view invalidate process.

  3. ljbade commented on Sep 23, 2015

    @ljbade
    ContributorAuthor
  4. ljbade commented on Sep 23, 2015

    @ljbade
    ContributorAuthor

    Did some testing. Currently pans and animations are mostly limited to 60fps I assume because of the touch input update rate. However with two finger rotate it jumps towards 200fps.

    I found on TextureView that postInvalidate and onDraw to not work.

    However postOnAnimation seems promising but only on API 16.

  5. ljbade commented on Sep 23, 2015

    @ljbade
    ContributorAuthor

    postAnimation makes panning rather janky whereas currently it is smooth. It does lower the rotation frame rate but it seems to still spike rather high.

  6. ljbade commented on Sep 23, 2015

    @ljbade
    ContributorAuthor

    I wonder if the problem is that two finger touch activates both rotate and zoom gesture listeners which set two different map properties and this then generates two render frames.

    @jfirebaugh If map.scaleBy and map.zoomBy are both called at 60 times per second, do I get two frames rendered thus 120 FPS?

  7. jfirebaugh commented on Sep 23, 2015

    @jfirebaugh
    Contributor

    The frequency of calling scaleBy and zoomBy doesn't directly translate to a frame rate. These calls post updates via uv_async which has a built in form of deduplication.

  8. ljbade commented on Sep 23, 2015

    @ljbade
    ContributorAuthor

    @mikemorris It appears so. The frame rate for rotation gestures is much higher than for pan gestures.

  9. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    Also noting that my Samsung S6 is currently flagging Mapbox GL as slowing the phone down and recommending I delete it.

    Not good for customer's apps.

  10. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    @jfirebaugh Is that dedupe reliable? What happens if we manage to process one render frame so quickly the second frame isn't a dupe?

  11. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    Confirmed disabling the zoom gesture drops frame rate to 60. Seems to be a result of updating the map twice per frame.

  12. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    @kkaefer What would be the best way to limit how many times the map redraws per frame?

    I might be able to work around this specific problem by combining scale and rotate updates into one call.

  13. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    Worked out the behaviour TextureView:

    • It creates a SurfaceTextre we use with EGL to render too.
    • Every time we finish a render and eglSwapBuffers() it will return us a recycled Surface buffer to render into. It will keep providing new buffers as fast as we call eglSwapBuffers(). Basically we cannot rely on eglSwapBuffers() for frame limiting.
    • When TextureView.draw() is called each vsync frame, it grabs whatever buffer is the latest, and draws this to the View. It then calls invalidate() to trigger a new draw() on the next vsync, then calls SurfaceTextureListener.onSurfaceTextureUpdated(). Currently our onSurfaceTextureUpdated() does nothing.

    It seems we need to use onSurfaceTextureUpdated() as a signal when our previous frame made it to the screen, and should be the basis of our draw timing.

  14. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    I ended up using postOnAnimate() as it gives good results. I created a dirty flag in the Android side and removed the dirty flag that was in NativeMapView C++ side.

    Going to need alternative to postOnAnimate() for pre-Jellybean devices. Likely one of the timer based methods.

  15. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    At some stage we should look at plumping Choreographer's frame times into the map animation system to get smoother animations.

    Will also look at fixing GPS dot sync.

  16. added this to the milestone on Sep 24, 2015
  17. self-assigned this
    on Sep 24, 2015
  18. ljbade commented on Sep 24, 2015

    @ljbade
    ContributorAuthor

    Creating PR

  19. added a commit that references this issue on Nov 6, 2015
    8c75234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Androidbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions