Paul Mennega Paul Mennega - 8 months ago 61
Android Question

Hardware acceleration not being enabled

Probably something silly going on, but I am trying to enable hardware acceleration in an app targeting 3.1, per this tutorial.

I've added the following to my manifest:

android:minSdkVersion="12" />


When I check the state of hardware acceleration after the View is attached (by calling
in an overriden
) I am returned true, so all looks great. The problem is that the SurfaceView's Canvas is NOT being accelerated, as
returns false. I am checking in
, and I get true there as well, so no idea whay the Canvas is losing this setting.

Any pointers?


Found this and this on the Google Developers group, but I am indeed checking after the View is attached if I am checking this in
, right? This is on a Lenovo Tablet running 3.1 BTW.


I have tried disabling acceleration via setting


And I am still seeing true returned from the View in
, so something is not right here. I am not explicitly chanbing hw accel from code, maybe a device specific issue?

Also, I am seeing the following line sporadically in LogCat when the SurfaceView is created:

surface (identity=524) is invalid, err=-19 (No such device)


Just thinking out loud here, but is there any chance that the Canvas is not being accelerated due to the fact that it is on it's own thread, via the typical SurfaceView implementation that uses a drawing loop, like Lunar Lander?

Answer Source

This is expected behavior. SurfaceView is not hardware accelerated. (link)

Since Android 4.0 there is a new TextureView (here is an example).
See also this SO question for pre-4.0 availablity.

Update: Just tested on a Transformer with Android 4.0 and the TextureView Canvas is not HW accelerated either. :-/

Update Android 6.0: there is a new method for hardware acceleration: