3

Bacground

I am developing an Android based application for a yet to be defined hardware platform (currently testing Ouya and MK802IV, all Android 4.1+) that involves displaying various content to an 1080p@60HZ output (big screens).

The application involves displaying a scroll, that is a piece of text that scrolls from right to left through the screen (as seen on TV news stations). I do have an working implementation (extending SurfaceView and drawing manually) that works perfectly at 60fps.

Problem

When the rest of the application starts performing more advanced fragment animations and the framerate of the scroll drops. For me this drop is perfectly normal (even after optimization), however even if the framerate drops to 30-40fps I would like for the scroll to retain its original speed and smoothness. This is very important as moving text smoothness is very visible to the user.

I have read up about Vsync and tipple buffering used in Android 4.1+, from what I see there are two feasible solutions:

Solution 1: slower VSYNC

It would be great to drop Vsync to ~30fps globally for the entire application or device. Unfortunately eglSwapInterval does not work on any of the tested devices.

  • Is there a way to force the entire application/device to render at a constant lower framerate?

Solution 2: knowing what frame am I rendering

Since the devices have Android 4.1+, my SurfaceView is rendered as a a part of triple buffering scheme, now if my implementation somehow knew what frame is it rendering it could draw the scroll text accordingly, especially that subpixel drawing is not a problem.

I have tried an naive implementation using SystemClock.uptimeMillis, however the timestamps obtained this way fluctuated way too much (even at 60fps the time deltas between frames were very far from being constant).

  • Is there a way to know, which frame am I rendering or how many frames have been skipped, so I can use this information to render the frame properly?

  • Do you have any other suggestions on how to approach the subject of the text scroll?

Additional information

Please keep in mind that the text may be long (1000 char+), displayed at ~20chars/screen, ~4pixels/second to a 1920x280px widget, font not monospaced. I have thought of using OpenGL and GlSurfaceView, however here the problem stays the same, during high system load I will still need to know, what am I currently rendering.

Platform depend solutions are also very welcome as I will have control over what platform may be supported (may be a very narrow and not mainstream range).

Thank you in advance for your help.

Karol
  • 31
  • 1
  • 2
  • 2
    tried this http://developer.android.com/reference/android/view/Choreographer.html ? – pskink Jun 05 '14 at 10:48
  • Tanks, this looks interesting. If I understand correctly I register a callback, then in the callback I increment a counter and register another callback, is this correct? – Karol Jun 05 '14 at 10:53
  • i have not used it but yes, it seems to work so, what counter do you mean? – pskink Jun 05 '14 at 11:02
  • My bad, did not notice that I do get the render time as a parameter. I've made some preliminary tests and this solution is far superior to obtaining time via other methods. However I have also noticed that sometimes during fragment transitions I manage to perform up to 3 lockCanvas/unlockCanvasAndPost calls without a single Choreographer callback - this is a problem. – Karol Jun 05 '14 at 13:32
  • as far as i understand it you have to perform your lock/draw/unlock in the callback – pskink Jun 05 '14 at 14:03
  • Thanks for the help, I have tried this but with no improvement. At this point my scroll retains it's speed however it is often jagged (pauses or skips a frame back). I still do not have any control over when the frame is displayed. Now according to http://source.android.com/devices/graphics/architecture.html if I miss the swap deadline a previous one is displayed. I do believe that this may be the root of my problems. Any idea how to solve this? – Karol Jun 06 '14 at 09:20
  • poat your cide, we will see – pskink Jun 06 '14 at 09:48
  • Did you read the "game loop" appendix? http://source.android.com/devices/graphics/architecture.html#loops See also the way Choreographer is used in Grafika's "Record GL app" activity (https://github.com/google/grafika) to achieve smooth animation. – fadden Jun 06 '14 at 17:44

0 Answers0