Controlling Display Refresh Rate on Android Device

前端 未结 2 475
星月不相逢
星月不相逢 2021-02-06 00:00

Not yet a developer, just trying to find out if an android app can do what I need..

What I need:

Simple app that displays a full frame of a sing

相关标签:
2条回答
  • 2021-02-06 00:15

    I would expect the refresh rate to be fixed at hardware or display driver level. There is an API for finding out what it is, but I doubt if you can set it.

    I wrote a game which implemented a fixed framerate of 40fps. The basic technique was to draw everything to an off-screen buffer... something which happens automatically with GL but which has to be done by hand if using Canvas.

    When the expensive and variable-length work of drawing your scene off-screen is completed, you can then block your rendering thread (or do other work) until it's time to render. Doing this will ensure each frame displays at even intervals. This gets you nice smooth motion with the bonus that you're not burning your battery by drawing too much (something a lot of GL-based apps do cos they use RENDERMODE_CONTINUOUSLY for no good reason).

    0 讨论(0)
  • 2021-02-06 00:34

    Mathias,

    So, if you want to synchronize with the display on android, simply let android tell you when the view needs to be drawn - which is the most basic thing one does on android. You will derive a class from the android provided View class. You will override the View classes onDraw() method which android will call each time the view needs to be refreshed.

    If you want to ensure that each frame you display is of a pre-determined length of time, then you will probably want to set up a new Thread. In the new thread you will enter a timing loop - start by capturing the System.nanoTime() (billionth of a second resolution) into a variable, then loop until your desired frame length is reached, then update a global static boolean variable. This global static boolean can be checked in your onDraw() method to determine when it is time to change the intensity.

    0 讨论(0)
提交回复
热议问题