I have a custom View that is drawn to on a background thread, simliar to the BallThread defined here.
In my particular application, I am drawing a line of pixels, each with a unique color. As the next set of data comes in, the curretn drawn pixels are shifted up, a new row is added, and everything is redrawn. The panel also supports panning and zooming.
My problem is that as time goes on and I have more pixels to track and be redrawn, the animation for panning and zooming becomes more bogged down. I feel that the amount of things I need to draw seems to exceed the limitations of what a Canvas can support in a timely fashion.
class DrawingThread extends Thread {
private SurfaceHolder _surfaceHolder;
private DrawingView _panel;
private boolean _run = false;
public DrawingThread(SurfaceHolder surfaceHolder, DrawingView panel) {
_surfaceHolder = surfaceHolder;
_panel = panel;
}
public void setRunning(boolean run) {
_run = run;
}
public SurfaceHolder getSurfaceHolder() {
return _surfaceHolder;
}
@Override
public void run() {
Canvas canvas;
while (_run) {
canvas = null;
try {
canvas = _surfaceHolder.lockCanvas(null);
synchronized (_surfaceHolder) {
_panel.doDraw(canvas);
}
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (canvas != null) {
_surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
Is there something else I can be doing that can process pixel draws (e.g. canvas.drawPixel()) faster than a Canvas?