tags:

views:

58

answers:

1

Hi.

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

TIA,

Mathias

+1  A: 

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

Reuben Scratton
Thank you very much Reuben!
Mathias
Thank you very much for your answer Reuben! It makes good sense that the display is run at a fixed frequency at a hardware level and that I by using getRefreshRate () can get the displays refresh rate and use that in my synchronization, so the only question that remains is how do I know when the display has been rendered. Is there a vsync interrupt or something similar for me to control my frame counter that i can use in my intensity generation?
Mathias
It's nice to meet a fellow old-school programmer who clearly remembers the importance of doing as much as possible in the vertical blanking interval... :)
Reuben Scratton
Oops, didn't expect return key to submit. Basically you're worrying about something you don't need to worry about any more... the display refresh is sync'ed to framebuffer updates at the driver level. So you won't get any tearing or flicker by updating video memory mid-refresh.
Reuben Scratton
Thank You once again Reuben. I'm not intimidated from what I've found out. I'm a hardware engineer mainly doing low level VHDL stuff, so I mainly think at a hardware level, hence the "is it possible" part of my question, i'm a foreigner to software except for simple C :-) I still need to find out how to synchronize a frame_counter variable to the displays refresh rate. I need to do an intensity sweep on the display where every displayed frame needs to be different to the last to achieve as high a time-resolution as possible. I cannot have two frames in a row with the same intensity... Thanks
Mathias
Well you won't be able to sync in quite the way you mean, but providing your rendering thread hits the target - i.e. it updates the framebuffer the required number of times per second (at even intervals) - then the effect is the same. The order of events will be Update->Display->Update->Display->...
Reuben Scratton
Btw, I'd be happy to knock up a demo project to get you started, assuming you can wait until the weekend.
Reuben Scratton
Sorry for the late reply back, I just got back from vacation... I see what you mean. Get the refresh rate, sync a counter to that, and update the framebuffer within the timeframe of a frame, and it will update the next frame each time. That works for my purpose :-) - I would be very happy if you would help me in the way of an example. As you may understand I'm new to this and my experience with Java and Android is minimal... The simplest of examples that gets the refresh rate and de/increases the intensity each frame would be very interesting. Whenever You have the time. I'm in no rush ATM.
Mathias