I am implementing a SurfaceView subclass where I run a separate thread to draw on SurfaceHolders canvas. I measure the time before and after the lockCanvas() call, and I get from about 70 ms to 100 ms. Can anyone tell me why I get such high timings? Here's the relevant piece of code:
public class TestView extends SurfaceView implements SurfaceHolder.Callback { .... boolean created; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { mThread = new DrawingThread(mHolder, true); mThread.onWindowResize(width, height); mThread.start(); } public void surfaceCreated(SurfaceHolder holder) { created = true; } public void surfaceDestroyed(SurfaceHolder holder) { created = false; } class DrawingThread extends Thread { public void run() { while(created) { Canvas canvas = null; try { long t0 = System.currentTimeMillis(); canvas = holder.lockCanvas(null); long t1 = System.currentTimeMillis(); Log.i(TAG, "Timing: " + ( t1 - t0) ); } finally { holder.unlockCanvasAndPost(canvas); } }
source share