Android TextureView hardware acceleration with lockCanvas()

≯℡__Kan透↙ 提交于 2019-11-27 22:52:53

TextureView works only when the application is hardware accelerated, but the Canvas it returns from lockCanvas() is currently never hardware accelerated. This means that you will draw inside the TextureView's Canvas in software, but TextureView itself will be drawn using the GPU. Currently, the only way to get a hardware accelerated Canvas is to use the onDraw(Canvas) method of a View.

Check the Hardware Acceleration article.

Basically if you want your TextureView to be hardware accelerated you must make sure that hardware acceleration is enabled at some level in the context of your TextureView, i.e one of the following:

  • At application level: <application android:hardwareAccelerated="true" ...>
  • At activity level: <activity android:hardwareAccelerated="true" />
  • At window level:

getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

Note that hardware acceleration is actually mandatory to use a TextureView:

TextureView can only be used in a hardware accelerated window. When rendered in software, TextureView will draw nothing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!