开发者

Controlling Display Refresh Rate on Android Device

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

What I need开发者_JAVA技巧:

Simple app that displays a full frame of a single color onscreen at a certain intensity at a fixed frequency! I need it for a synchronization purpose with as high a resolution as possible (achieved by changing an intensity in a known pattern with as high a fixed frequency as possible).

What questions I have:

  1. Does an android device run with a fixed display frequency or is there any way to set it to a fixed frequency of say 60fps?

  2. If the fixed frequency can be achieved, is there a vsync interrupt or something similar that lets me change the intensity on the screen at the right time.

  3. If the above two things can be achieved, which approach do I need to take. I'm thinking I need to look at OpenGL ES and perhaps NDK.... Could anyone please point me in the right direction....


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).


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜