Reputation: 609
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
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