Using Hardware Layer in Custom View onDraw

后端 未结 2 1490
礼貌的吻别
礼貌的吻别 2021-02-15 12:19

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

相关标签:
2条回答
  • 2021-02-15 13:21

    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 :)

    0 讨论(0)
  • 2021-02-15 13:22

    You can use Android's Tracer for OpenGL ES to see if your view issue OpenGL commands.

    From developer.android.com

    Tracer is a tool for analyzing OpenGL for Embedded Systems (ES) code in your Android application. The tool allows you to capture OpenGL ES commands and frame by frame images to help you understand how your graphics commands are being executed.

    There is also a tutorial about Android Performance Study by Romain Guy which describes its use almost step by step.

    0 讨论(0)
提交回复
热议问题