android 2.3: how to reduce fps to 60 (vsync) -


if run programm (canvas, surfaceview) under android 4.x.x stable 60 fps, under 2.3.3 fps increases 75-80. how make easier 60 fps (vsync) under android 2.3.3?

update (some drawing code):

public class game extends activity implements ontouchlistener  {           fastrenderview renderview;      @override        public void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);          renderview = new fastrenderview(this);         renderview.setontouchlistener(this);                     setcontentview(renderview);                  }            protected void onresume() {         super.onresume();         renderview.resume();     }      protected void onpause() {         super.onpause();                 renderview.pause();     }          class fastrenderview extends surfaceview implements runnable  {         thread renderthread = null;         surfaceholder holder;         volatile boolean running = false;          public fastrenderview(context context) {             super(context);                holder = getholder();               private void drawsurface(canvas canvas)          {         // draw                                                                             }          public void resume() {                       running = true;             renderthread = new thread(this);             renderthread.start();                 }          public void pause() {                     running = false;                                     while(true) {                 try {                     renderthread.join();                     break;                 } catch (interruptedexception e) {                     // retry                 }             }             renderthread = null;                 }          public void run() {             while(running) {                   if(!holder.getsurface().isvalid())                     continue;                  canvas canvas = holder.lockcanvas();                             drawsurface(canvas);                                                           holder.unlockcanvasandpost(canvas);                         }         }                     } 

update2: found simple solution (thx google):

int max_fps = 60; int frame_period = 1000/max_fps; long begintime; long timediff; int sleeptime;  public void run() {   sleeptime = 0;   while(running) {     if(!holder.getsurface().isvalid())    continue;    begintime = system.currenttimemillis();                   canvas canvas = holder.lockcanvas();               drawsurface(canvas);                                             holder.unlockcanvasandpost(canvas);   timediff = system.currenttimemillis() - begintime;                            sleeptime = (int)(frame_period - timediff); // calculate sleep time   if (sleeptime > 0) {     try { thread.sleep(sleeptime); } catch (interruptedexception e) {}   } } 

the vsync introduced jelly bean release (project butter). there no way on older android versions. if want full story take @ video: http://www.youtube.com/watch?v=q8m9shdyxne . worth watch!


Comments