I'm developing an android game and I'm using SurfaceView. I have a method that will be called every 16ms (I want to have 60fps)
public void myDraw(SurfaceHolder holder) {
Canvas c = null;
long start = System.currentMillis();
try {
synchronized(holder) {
c = holder.lockCanvas();
if (c != null) {
c.drawColor(Color.GREEN);
}
}
} finally {
if (c != null) {
holder.unlockCanvas(c);
}
}
Log.i(TAG, "total time:" + (System.currentMillis() - start));
}
When I run my app, the output from LogCat is:
total time:30
total time:23
total time:6
total time:39
total time:17
Why does the lock/unlock of canvas takes too much time? Are there any better approach to my problem? (that is, to have a 60 fps app)
Thanks!