user3293494
user3293494

Reputation: 609

How to update surfaceview partially?

I have a surfaceview in my activity. Initially some circles are drawn using

Canvas c = SurfaceView.getHolder().lockCanvas();

and

SurfaceView.getHolder().unlockCanvasAndPost(c);

Later on I want to draw on a very small part of the surfaceview. I do not want to redraw the whole surfaceview. Is it possible to update just the required part?

Upvotes: 1

Views: 813

Answers (1)

fadden
fadden

Reputation: 52353

Use lockCanvas(Rect dirty) instead. Pass in the area you want to redraw.

Note that dirty is an in-out parameter. The Rect may be expanded to cover a larger area, and you need to set every pixel it covers. So if (for example) SurfaceView no longer has access to the previous pixels, it'll expand Rect to cover the entire surface.

Because SurfaceView is double- or triple-buffered, the implementation will copy chunks of pixels from the previous buffer. Since the Canvas you get from a SurfaceView is never hardware-accelerated, specifying a dirty rect is often a performance win.

Upvotes: 1

Related Questions