I draw a lot of rectangles in each frame in my game - this is a recreation of an old school pocket electronic game. Those that had a raw matrix display for the main game and custom images for text or some images.
I have 20x20 large pixels on the screen with a virtual dot matrix, I also draw 7-segment displays on the screen and some other things.
According to TraceView, most of the time is spent on drawLine and drawRectangle, because there are too many of them. I draw each “pixel” of the matrix display, and each segment of the 7-segment displays is displayed in each frame.
The optimization occurred to me that I would only repaint the pixels / segments that had changed, so I kept the previous state of the pixels / segments and tried to redraw only the changed ones. Basically this is a gross invalidity.
The behavior that I was expecting was that the Canvas would remain the same as after the last frame had finished drawing, and I would only redraw the necessary things.
Alas, my canvas flickered to black, and every time the state of my screen changed, only the pixels of the matrix display / segments flickered for the frame. And I made sure that I did not clean my canvas.
I draw a Canvas inside a SurfaceView, updating Thread, as described in the Lunar Lander Android example. In the Lunar Lander pattern, they redraw everything in every frame.
, , ?
paint()?