So I\'m trying to understand how I can properly use hardware acceleration (when available) in a custom View
that is persistently animating. This is the basic premis
On what view(s) are you setting View.LAYER_TYPE_HARDWARE
exactly? If you are setting a hardware layer on the view that contains the drawing code shown above, you are causing the system to do a lot more work than necessary. Since you are only drawing bitmaps you don't need to do anything here. If you call Canvas.drawBitmap()
the framework will cache the resulting OpenGL texture on your behalf.
You could however optimize your code a little more. Instead of calling drawBitmap()
, you could use child views. If you move these children using the offset*()
methods (or setX()
/setY()
) the framework will apply further optimizations to avoid calling the draw()
methods again.
In general, hardware layers should be set on views that are expensive to draw and whose content won't change often (so pretty much the opposite of what you're doing :)